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
This commit is contained in:
Sebastian Dröge 2018-12-17 19:41:26 +02:00 committed by Mathieu Duponchelle
parent 571e0abd8a
commit acd7010576
2 changed files with 57 additions and 6 deletions

View file

@ -694,18 +694,22 @@ 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. "

View file

@ -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;
}