Skip to content

Commit

Permalink
fix timestamp bug (#999)
Browse files Browse the repository at this point in the history
  • Loading branch information
disa6302 authored Apr 12, 2023
1 parent e609e6d commit 63537aa
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions src/gstreamer/gstkvssink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ void create_kinesis_video_stream(GstKvsSink *kvssink) {
// (i.e. starting from 0)
if (kvssink->streaming_type == STREAMING_TYPE_OFFLINE && kvssink->file_start_time != 0) {
kvssink->absolute_fragment_times = TRUE;
data->pts_base = (uint64_t) duration_cast<nanoseconds>(milliseconds(kvssink->file_start_time)).count();
data->pts_base = (uint64_t) duration_cast<nanoseconds>(seconds(kvssink->file_start_time)).count();
}

switch (data->media_type) {
Expand Down Expand Up @@ -651,8 +651,8 @@ gst_kvs_sink_class_init(GstKvsSinkClass *klass) {

g_object_class_install_property (gobject_class, PROP_FILE_START_TIME,
g_param_spec_uint64 ("file-start-time", "File Start Time",
"Epoch time that the file starts in kinesis video stream. By default, current time is used. Unit: Milliseconds",
0, G_MAXUINT64, 0, (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
"Epoch time that the file starts in kinesis video stream. By default, current time is used. Unit: Seconds",
0, G_MAXULONG, 0, (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));

g_object_class_install_property (gobject_class, PROP_DISABLE_BUFFER_CLIPPING,
g_param_spec_boolean ("disable-buffer-clipping", "Disable Buffer Clipping",
Expand Down Expand Up @@ -743,7 +743,7 @@ gst_kvs_sink_init(GstKvsSink *kvssink) {
kvssink->service_connection_timeout = DEFAULT_SERVICE_CONNECTION_TIMEOUT_SEC;
kvssink->service_completion_timeout = DEFAULT_SERVICE_COMPLETION_TIMEOUT_SEC;
kvssink->credential_file_path = g_strdup (DEFAULT_CREDENTIAL_FILE_PATH);
kvssink->file_start_time = (uint64_t) chrono::duration_cast<milliseconds>(
kvssink->file_start_time = (uint64_t) chrono::duration_cast<seconds>(
systemCurrentTime().time_since_epoch()).count();
kvssink->track_info_type = MKV_TRACK_INFO_TYPE_VIDEO;
kvssink->audio_codec_id = g_strdup (DEFAULT_AUDIO_CODEC_ID_AAC);
Expand All @@ -757,7 +757,7 @@ gst_kvs_sink_init(GstKvsSink *kvssink) {
GST_OBJECT_FLAG_SET (kvssink, GST_ELEMENT_FLAG_SINK);

LOGGER_TAG("com.amazonaws.kinesis.video.gstkvs");
LOG_CONFIGURE_STDOUT("DEBUG")
LOG_CONFIGURE_STDOUT("DEBUG");
}

static void
Expand Down Expand Up @@ -1295,8 +1295,13 @@ gst_kvs_sink_handle_buffer (GstCollectPads * pads,
// timestamp. Therefore in here we add the file_start_time to frame pts to create absolute timestamp.
// If user did not specify file_start_time, file_start_time will be 0 and has no effect.
if (IS_OFFLINE_STREAMING_MODE(kvssink->streaming_type)) {
buf->dts = 0; // if offline mode, i.e. streaming a file, the dts from gstreamer is undefined.
buf->pts += data->pts_base;
if(!data->use_original_pts) {
buf->dts = 0; // if offline mode, i.e. streaming a file, the dts from gstreamer is undefined.
buf->pts += data->pts_base;
}
else {
buf->pts = buf->dts;
}
} else if (!GST_BUFFER_DTS_IS_VALID(buf)) {
buf->dts = data->last_dts + DEFAULT_FRAME_DURATION_MS * HUNDREDS_OF_NANOS_IN_A_MILLISECOND * DEFAULT_TIME_UNIT_IN_NANOS;
}
Expand Down Expand Up @@ -1334,6 +1339,12 @@ gst_kvs_sink_handle_buffer (GstCollectPads * pads,
data->producer_start_time = (uint64_t) chrono::duration_cast<nanoseconds>(
systemCurrentTime().time_since_epoch()).count();
}
if(!data->use_original_pts) {
buf->pts += data->producer_start_time - data->first_pts;
}
else {
buf->pts = buf->dts;
}
}

put_frame(kvssink->data, info.data, info.size,
Expand Down Expand Up @@ -1630,4 +1641,4 @@ GST_PLUGIN_DEFINE (
"Proprietary",
"GStreamer",
"http://gstreamer.net/"
)
)

0 comments on commit 63537aa

Please sign in to comment.