From acd7010576c742c932863e76ff7b7db6a4501d7b Mon Sep 17 00:00:00 2001 From: =?utf8?q?Sebastian=20Dr=C3=B6ge?= Date: Mon, 17 Dec 2018 19:41:26 +0200 Subject: [PATCH] videotimecode: Set the DROP_FRAME flag when parsing timecodes with a ,/; from a string And also add a test for parsing a few valid and invalid timecodes --- gst-libs/gst/video/gstvideotimecode.c | 16 +++++++----- tests/check/libs/videotimecode.c | 47 +++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 6 deletions(-) diff --git a/gst-libs/gst/video/gstvideotimecode.c b/gst-libs/gst/video/gstvideotimecode.c index e0b2439..6ec9b5e 100644 --- a/gst-libs/gst/video/gstvideotimecode.c +++ b/gst-libs/gst/video/gstvideotimecode.c @@ -694,19 +694,23 @@ gst_video_time_code_new_from_string (const gchar * tc_str) if (sscanf (tc_str, "%02u:%02u:%02u:%02u", &hours, &minutes, &seconds, &frames) == 4 - || sscanf (tc_str, "%02u:%02u:%02u;%02u", &hours, &minutes, &seconds, - &frames) - == 4 || sscanf (tc_str, "%02u:%02u:%02u.%02u", &hours, &minutes, &seconds, &frames) - == 4 - || sscanf (tc_str, "%02u:%02u:%02u,%02u", &hours, &minutes, &seconds, - &frames) == 4) { tc = gst_video_time_code_new (0, 1, NULL, GST_VIDEO_TIME_CODE_FLAGS_NONE, hours, minutes, seconds, frames, 0); return tc; + } else if (sscanf (tc_str, "%02u:%02u:%02u;%02u", &hours, &minutes, &seconds, + &frames) + == 4 || sscanf (tc_str, "%02u:%02u:%02u,%02u", &hours, &minutes, &seconds, + &frames) + == 4) { + tc = gst_video_time_code_new (0, 1, NULL, + GST_VIDEO_TIME_CODE_FLAGS_DROP_FRAME, hours, minutes, seconds, frames, + 0); + + return tc; } else { GST_ERROR ("Warning: Could not parse timecode %s. " "Please input a timecode in the form 00:00:00:00", tc_str); diff --git a/tests/check/libs/videotimecode.c b/tests/check/libs/videotimecode.c index 38726f6..6e01548 100644 --- a/tests/check/libs/videotimecode.c +++ b/tests/check/libs/videotimecode.c @@ -670,6 +670,50 @@ GST_START_TEST (videotimecode_from_date_time) GST_END_TEST; +static void +test_timecode_from_string (const gchar * str, gboolean success, guint hours, + guint minutes, guint seconds, guint frames, gboolean drop_frame) +{ + GstVideoTimeCode *tc; + gchar *s; + + tc = gst_video_time_code_new_from_string (str); + + if (success) { + fail_unless (tc); + } else { + fail_if (tc); + return; + } + + fail_unless_equals_int (tc->hours, hours); + fail_unless_equals_int (tc->minutes, minutes); + fail_unless_equals_int (tc->seconds, seconds); + fail_unless_equals_int (tc->frames, frames); + + if (drop_frame) + fail_unless (tc->config.flags & GST_VIDEO_TIME_CODE_FLAGS_DROP_FRAME); + else + fail_if (tc->config.flags & GST_VIDEO_TIME_CODE_FLAGS_DROP_FRAME); + + s = gst_video_time_code_to_string (tc); + fail_unless_equals_string (s, str); + + gst_video_time_code_free (tc); + g_free (s); +} + +GST_START_TEST (videotimecode_from_to_string) +{ + test_timecode_from_string ("11:12:13:14", TRUE, 11, 12, 13, 14, FALSE); + test_timecode_from_string ("11:12:13;14", TRUE, 11, 12, 13, 14, TRUE); + test_timecode_from_string ("11:12:13:", FALSE, 0, 0, 0, 0, FALSE); + test_timecode_from_string ("11:12:13:ab", FALSE, 0, 0, 0, 0, FALSE); + test_timecode_from_string ("a 11:12:13:14", FALSE, 0, 0, 0, 0, FALSE); +} + +GST_END_TEST; + static Suite * gst_videotimecode_suite (void) { @@ -708,6 +752,9 @@ gst_videotimecode_suite (void) tcase_add_test (tc, videotimecode_from_date_time_1s); tcase_add_test (tc, videotimecode_from_date_time_halfsecond); tcase_add_test (tc, videotimecode_from_date_time); + + tcase_add_test (tc, videotimecode_from_to_string); + return s; } -- 2.7.4