summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Dröge <sebastian@centricular.com>2018-12-14 13:56:28 +0200
committerTim-Philipp Müller <tim@centricular.com>2019-05-01 17:27:43 +0100
commit4b3f146c42ad519b5ef50f98de070138dec0201a (patch)
tree0ab1bee51dbdc3626e2fbad72890b54e1aebcedd
parentbe1d1caeab8b055d41720784ae6990fe5c044f13 (diff)
downloadgstreamer-plugins-base-4b3f146c42ad519b5ef50f98de070138dec0201a.tar.gz
videotimecode: Fix division by zero in timecode validation function
And add some comments about what exactly we're testing in the non-trivial cases.
-rw-r--r--gst-libs/gst/video/gstvideotimecode.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/gst-libs/gst/video/gstvideotimecode.c b/gst-libs/gst/video/gstvideotimecode.c
index e7955782b..73ab27f96 100644
--- a/gst-libs/gst/video/gstvideotimecode.c
+++ b/gst-libs/gst/video/gstvideotimecode.c
@@ -66,7 +66,8 @@ gst_video_time_code_is_valid (const GstVideoTimeCode * tc)
g_return_val_if_fail (tc != NULL, FALSE);
- fr = (tc->config.fps_n + (tc->config.fps_d >> 1)) / tc->config.fps_d;
+ if (tc->config.fps_d == 0)
+ return FALSE;
if (tc->hours >= 24)
return FALSE;
@@ -74,10 +75,14 @@ gst_video_time_code_is_valid (const GstVideoTimeCode * tc)
return FALSE;
if (tc->seconds >= 60)
return FALSE;
- if (tc->config.fps_d == 0)
- return FALSE;
+
+ /* We can't have more frames than rounded up frames per second */
+ fr = (tc->config.fps_n + (tc->config.fps_d >> 1)) / tc->config.fps_d;
if (tc->frames >= fr && (tc->config.fps_n != 0 || tc->config.fps_d != 1))
return FALSE;
+
+ /* We either need a specific X/1001 framerate or otherwise an integer
+ * framerate */
if (tc->config.fps_d == 1001) {
if (tc->config.fps_n != 30000 && tc->config.fps_n != 60000 &&
tc->config.fps_n != 24000)
@@ -85,6 +90,10 @@ gst_video_time_code_is_valid (const GstVideoTimeCode * tc)
} else if (tc->config.fps_n % tc->config.fps_d != 0) {
return FALSE;
}
+
+ /* Drop-frame framerates require skipping over the first two
+ * timecodes every minutes except for every tenth minute in case
+ * of 30000/1001 and the first four timecodes for 60000/1001 */
if ((tc->config.flags & GST_VIDEO_TIME_CODE_FLAGS_DROP_FRAME) &&
tc->minutes % 10 && tc->seconds == 0 && tc->frames < fr / 15) {
return FALSE;