... | ... |
@@ -34,6 +34,7 @@ |
34 | 34 |
#include "libavcodec/dvdata.h" |
35 | 35 |
#include "libavutil/intreadwrite.h" |
36 | 36 |
#include "libavutil/mathematics.h" |
37 |
+#include "libavutil/timecode.h" |
|
37 | 38 |
#include "dv.h" |
38 | 39 |
#include "libavutil/avassert.h" |
39 | 40 |
|
... | ... |
@@ -275,42 +276,19 @@ static int dv_extract_video_info(DVDemuxContext *c, uint8_t* frame) |
275 | 275 |
return size; |
276 | 276 |
} |
277 | 277 |
|
278 |
-static int bcd2int(uint8_t bcd) |
|
278 |
+static int dv_extract_timecode(DVDemuxContext* c, uint8_t* frame, char *tc) |
|
279 | 279 |
{ |
280 |
- int low = bcd & 0xf; |
|
281 |
- int high = bcd >> 4; |
|
282 |
- if (low > 9 || high > 9) |
|
283 |
- return -1; |
|
284 |
- return low + 10*high; |
|
285 |
-} |
|
286 |
- |
|
287 |
-static int dv_extract_timecode(DVDemuxContext* c, uint8_t* frame, char tc[32]) |
|
288 |
-{ |
|
289 |
- int hh, mm, ss, ff, drop_frame; |
|
290 | 280 |
const uint8_t *tc_pack; |
291 | 281 |
|
292 |
- tc_pack = dv_extract_pack(frame, dv_timecode); |
|
293 |
- if (!tc_pack) |
|
294 |
- return 0; |
|
295 |
- |
|
296 |
- ff = bcd2int(tc_pack[1] & 0x3f); |
|
297 |
- ss = bcd2int(tc_pack[2] & 0x7f); |
|
298 |
- mm = bcd2int(tc_pack[3] & 0x7f); |
|
299 |
- hh = bcd2int(tc_pack[4] & 0x3f); |
|
300 |
- drop_frame = tc_pack[1] >> 6 & 0x1; |
|
301 |
- |
|
302 |
- if (ff < 0 || ss < 0 || mm < 0 || hh < 0) |
|
303 |
- return -1; |
|
304 |
- |
|
305 | 282 |
// For PAL systems, drop frame bit is replaced by an arbitrary |
306 | 283 |
// bit so its value should not be considered. Drop frame timecode |
307 | 284 |
// is only relevant for NTSC systems. |
308 |
- if(c->sys->ltc_divisor == 25 || c->sys->ltc_divisor == 50) { |
|
309 |
- drop_frame = 0; |
|
310 |
- } |
|
285 |
+ int prevent_df = c->sys->ltc_divisor == 25 || c->sys->ltc_divisor == 50; |
|
311 | 286 |
|
312 |
- snprintf(tc, 32, "%02d:%02d:%02d%c%02d", |
|
313 |
- hh, mm, ss, drop_frame ? ';' : ':', ff); |
|
287 |
+ tc_pack = dv_extract_pack(frame, dv_timecode); |
|
288 |
+ if (!tc_pack) |
|
289 |
+ return 0; |
|
290 |
+ av_timecode_make_smpte_tc_string(tc, AV_RB32(tc_pack + 1), prevent_df); |
|
314 | 291 |
return 1; |
315 | 292 |
} |
316 | 293 |
|
... | ... |
@@ -454,7 +432,7 @@ typedef struct RawDVContext { |
454 | 454 |
|
455 | 455 |
static int dv_read_timecode(AVFormatContext *s) { |
456 | 456 |
int ret; |
457 |
- char timecode[32]; |
|
457 |
+ char timecode[AV_TIMECODE_STR_SIZE]; |
|
458 | 458 |
int64_t pos = avio_tell(s->pb); |
459 | 459 |
|
460 | 460 |
// Read 3 DIF blocks: Header block and 2 Subcode blocks. |