From 8f9a53fa859ae48cadbe88fe9ae1f53432fb91f6 Mon Sep 17 00:00:00 2001 From: Seungha Yang Date: Thu, 8 Aug 2024 06:23:47 +0900 Subject: [PATCH] timecodestamper: Add running-time source mode Add a new source mode "running-time". This mode will convert buffer running time into timecode Part-of: --- .../docs/plugins/gst_plugins_cache.json | 5 ++++ .../gst/timecode/gsttimecodestamper.c | 26 +++++++++++++++++++ .../gst/timecode/gsttimecodestamper.h | 1 + 3 files changed, 32 insertions(+) diff --git a/subprojects/gst-plugins-bad/docs/plugins/gst_plugins_cache.json b/subprojects/gst-plugins-bad/docs/plugins/gst_plugins_cache.json index 1235eb86e4..2c503a6fe2 100644 --- a/subprojects/gst-plugins-bad/docs/plugins/gst_plugins_cache.json +++ b/subprojects/gst-plugins-bad/docs/plugins/gst_plugins_cache.json @@ -240879,6 +240879,11 @@ "desc": "Timecode from real time clock", "name": "rtc", "value": "5" + }, + { + "desc": "Buffer running time as timecode", + "name": "running-time", + "value": "6" } ] } diff --git a/subprojects/gst-plugins-bad/gst/timecode/gsttimecodestamper.c b/subprojects/gst-plugins-bad/gst/timecode/gsttimecodestamper.c index c1440b83df..6de15b3ccc 100644 --- a/subprojects/gst-plugins-bad/gst/timecode/gsttimecodestamper.c +++ b/subprojects/gst-plugins-bad/gst/timecode/gsttimecodestamper.c @@ -189,6 +189,15 @@ gst_timecodestamper_source_get_type (void) "Linear timecode from an audio device", "ltc"}, {GST_TIME_CODE_STAMPER_SOURCE_RTC, "Timecode from real time clock", "rtc"}, + /** + * GstTimeCodeStamperSource::running-time: + * + * Buffer running time as timecode + * + * Since: 1.26 + */ + {GST_TIME_CODE_STAMPER_SOURCE_RUNNING_TIME, + "Buffer running time as timecode", "running-time"}, {0, NULL, NULL}, }; @@ -1581,6 +1590,23 @@ gst_timecodestamper_transform_ip (GstBaseTransform * vfilter, case GST_TIME_CODE_STAMPER_SOURCE_RTC: tc = timecodestamper->rtc_tc; break; + case GST_TIME_CODE_STAMPER_SOURCE_RUNNING_TIME: + if (GST_CLOCK_TIME_IS_VALID (running_time)) { + guint64 num_frames = gst_util_uint64_scale (running_time, + timecodestamper->fps_n, timecodestamper->fps_d * GST_SECOND); + guint field_count = 0; + + if (timecodestamper->interlace_mode != + GST_VIDEO_INTERLACE_MODE_PROGRESSIVE) { + field_count = 1; + } + + tc = gst_video_time_code_new (timecodestamper->fps_n, + timecodestamper->fps_d, NULL, tc_flags, 0, 0, 0, 0, field_count); + gst_video_time_code_add_frames (tc, num_frames); + free_tc = TRUE; + } + break; } switch (timecodestamper->tc_set) { diff --git a/subprojects/gst-plugins-bad/gst/timecode/gsttimecodestamper.h b/subprojects/gst-plugins-bad/gst/timecode/gsttimecodestamper.h index 47232565cc..1779f670d1 100644 --- a/subprojects/gst-plugins-bad/gst/timecode/gsttimecodestamper.h +++ b/subprojects/gst-plugins-bad/gst/timecode/gsttimecodestamper.h @@ -52,6 +52,7 @@ typedef enum GstTimeCodeStamperSource GST_TIME_CODE_STAMPER_SOURCE_LAST_KNOWN_OR_ZERO, GST_TIME_CODE_STAMPER_SOURCE_LTC, GST_TIME_CODE_STAMPER_SOURCE_RTC, + GST_TIME_CODE_STAMPER_SOURCE_RUNNING_TIME, } GstTimeCodeStamperSource; typedef enum GstTimeCodeStamperSet {