Browse code

lavu/timecode: add av_timecode_check_frame_rate().

Clément Bœsch authored on 2012/08/03 22:40:15
Showing 3 changed files
... ...
@@ -146,6 +146,17 @@ char *av_timecode_make_mpeg_tc_string(char *buf, uint32_t tc25bit)
146 146
     return buf;
147 147
 }
148 148
 
149
+static int check_fps(int fps)
150
+{
151
+    int i;
152
+    static const int supported_fps[] = {24, 25, 30, 50, 60};
153
+
154
+    for (i = 0; i < FF_ARRAY_ELEMS(supported_fps); i++)
155
+        if (fps == supported_fps[i])
156
+            return 0;
157
+    return -1;
158
+}
159
+
149 160
 static int check_timecode(void *log_ctx, AVTimecode *tc)
150 161
 {
151 162
     if (tc->fps <= 0) {
... ...
@@ -156,18 +167,12 @@ static int check_timecode(void *log_ctx, AVTimecode *tc)
156 156
         av_log(log_ctx, AV_LOG_ERROR, "Drop frame is only allowed with 30000/1001 FPS\n");
157 157
         return AVERROR(EINVAL);
158 158
     }
159
-    switch (tc->fps) {
160
-    case 24:
161
-    case 25:
162
-    case 30:
163
-    case 50:
164
-    case 60: return  0;
165
-
166
-    default:
159
+    if (check_fps(tc->fps) < 0) {
167 160
         av_log(log_ctx, AV_LOG_ERROR, "Timecode frame rate %d/%d not supported\n",
168 161
                tc->rate.num, tc->rate.den);
169 162
         return AVERROR_PATCHWELCOME;
170 163
     }
164
+    return 0;
171 165
 }
172 166
 
173 167
 static int fps_from_frame_rate(AVRational rate)
... ...
@@ -177,6 +182,11 @@ static int fps_from_frame_rate(AVRational rate)
177 177
     return (rate.num + rate.den/2) / rate.den;
178 178
 }
179 179
 
180
+int av_timecode_check_frame_rate(AVRational rate)
181
+{
182
+    return check_fps(fps_from_frame_rate(rate));
183
+}
184
+
180 185
 int av_timecode_init(AVTimecode *tc, AVRational rate, int flags, int frame_start, void *log_ctx)
181 186
 {
182 187
     memset(tc, 0, sizeof(*tc));
... ...
@@ -140,4 +140,11 @@ int av_timecode_init(AVTimecode *tc, AVRational rate, int flags, int frame_start
140 140
  */
141 141
 int av_timecode_init_from_string(AVTimecode *tc, AVRational rate, const char *str, void *log_ctx);
142 142
 
143
+/**
144
+ * Check if the timecode feature is available for the given frame rate
145
+ *
146
+ * @return 0 if supported, <0 otherwise
147
+ */
148
+int av_timecode_check_frame_rate(AVRational rate);
149
+
143 150
 #endif /* AVUTIL_TIMECODE_H */
... ...
@@ -39,8 +39,8 @@
39 39
  */
40 40
 
41 41
 #define LIBAVUTIL_VERSION_MAJOR 51
42
-#define LIBAVUTIL_VERSION_MINOR 66
43
-#define LIBAVUTIL_VERSION_MICRO 101
42
+#define LIBAVUTIL_VERSION_MINOR 67
43
+#define LIBAVUTIL_VERSION_MICRO 100
44 44
 
45 45
 #define LIBAVUTIL_VERSION_INT   AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
46 46
                                                LIBAVUTIL_VERSION_MINOR, \