summaryrefslogtreecommitdiff
path: root/libavcodec/timecode.c
diff options
context:
space:
mode:
authorClément Bœsch <clement.boesch@smartjog.com>2011-12-06 11:17:37 +0100
committerClément Bœsch <ubitux@gmail.com>2011-12-12 17:49:34 +0100
commit98aca4bbef6818bbc8209a801425c3a6f1ff41a9 (patch)
tree220cc6a020a042f8a3371984d04a5c7746f11b73 /libavcodec/timecode.c
parent66160bdb0140586c44e494336c3c05f5928a6367 (diff)
downloadffmpeg-98aca4bbef6818bbc8209a801425c3a6f1ff41a9.tar.gz
timecode: better input checks in init function.
Diffstat (limited to 'libavcodec/timecode.c')
-rw-r--r--libavcodec/timecode.c38
1 files changed, 31 insertions, 7 deletions
diff --git a/libavcodec/timecode.c b/libavcodec/timecode.c
index 7f3b1d5ab8..8cd1bec941 100644
--- a/libavcodec/timecode.c
+++ b/libavcodec/timecode.c
@@ -55,9 +55,33 @@ uint32_t ff_framenum_to_smtpe_timecode(unsigned frame, int fps, int drop)
( (frame / (fps * 3600) % 24)) % 10; // units of hours
}
+static int check_timecode_rate(void *avcl, AVRational rate, int drop)
+{
+ int fps;
+
+ if (!rate.num || !rate.den) {
+ av_log(avcl, AV_LOG_ERROR, "Timecode frame rate must be specified\n");
+ return -1;
+ }
+ fps = (rate.num + rate.den/2) / rate.den;
+ if (drop && (rate.den != 1001 || fps != 30)) {
+ av_log(avcl, AV_LOG_ERROR, "Drop frame is only allowed with 30000/1001 FPS\n");
+ return -2;
+ }
+ switch (fps) {
+ case 24:
+ case 25:
+ case 30: return 0;
+
+ default:
+ av_log(avcl, AV_LOG_ERROR, "Timecode frame rate not supported\n");
+ return -3;
+ }
+}
+
int ff_init_smtpe_timecode(void *avcl, struct ff_timecode *tc)
{
- int hh, mm, ss, ff, fps;
+ int hh, mm, ss, ff, fps, ret;
char c;
if (sscanf(tc->str, "%d:%d:%d%c%d", &hh, &mm, &ss, &c, &ff) != 5) {
@@ -66,17 +90,17 @@ int ff_init_smtpe_timecode(void *avcl, struct ff_timecode *tc)
return -1;
}
+ tc->drop = c != ':'; // drop if ';', '.', ...
+
+ ret = check_timecode_rate(avcl, tc->rate, tc->drop);
+ if (ret < 0)
+ return ret;
+
fps = (tc->rate.num + tc->rate.den/2) / tc->rate.den;
tc->start = (hh*3600 + mm*60 + ss) * fps + ff;
- tc->drop = c != ':'; // drop if ';', '.', ...
if (tc->drop) { /* adjust frame number */
int tmins = 60*hh + mm;
- if (tc->rate.den != 1001 || fps != 30) {
- av_log(avcl, AV_LOG_ERROR, "error: drop frame is only allowed with"
- "30000/1001 FPS");
- return -2;
- }
tc->start -= 2 * (tmins - tmins/10);
}
return 0;