/src/ffmpeg/libavutil/timecode_internal.c
Line | Count | Source |
1 | | /* |
2 | | * Copyright (c) 2006 Smartjog S.A.S, Baptiste Coudurier <baptiste.coudurier@gmail.com> |
3 | | * Copyright (c) 2011-2012 Smartjog S.A.S, Clément Bœsch <clement.boesch@smartjog.com> |
4 | | * |
5 | | * This file is part of FFmpeg. |
6 | | * |
7 | | * FFmpeg is free software; you can redistribute it and/or |
8 | | * modify it under the terms of the GNU Lesser General Public |
9 | | * License as published by the Free Software Foundation; either |
10 | | * version 2.1 of the License, or (at your option) any later version. |
11 | | * |
12 | | * FFmpeg is distributed in the hope that it will be useful, |
13 | | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
15 | | * Lesser General Public License for more details. |
16 | | * |
17 | | * You should have received a copy of the GNU Lesser General Public |
18 | | * License along with FFmpeg; if not, write to the Free Software |
19 | | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
20 | | */ |
21 | | |
22 | | #include "timecode_internal.h" |
23 | | |
24 | | static unsigned bcd2uint(uint8_t bcd) |
25 | 0 | { |
26 | 0 | unsigned low = bcd & 0xf; |
27 | 0 | unsigned high = bcd >> 4; |
28 | 0 | if (low > 9 || high > 9) |
29 | 0 | return 0; |
30 | 0 | return low + 10*high; |
31 | 0 | } |
32 | | |
33 | | void ff_timecode_set_smpte(unsigned *drop, unsigned *hh, unsigned *mm, unsigned *ss, unsigned *ff, |
34 | | AVRational rate, uint32_t tcsmpte, int prevent_df, int skip_field) |
35 | 0 | { |
36 | 0 | *hh = bcd2uint(tcsmpte & 0x3f); // 6-bit hours |
37 | 0 | *mm = bcd2uint(tcsmpte>>8 & 0x7f); // 7-bit minutes |
38 | 0 | *ss = bcd2uint(tcsmpte>>16 & 0x7f); // 7-bit seconds |
39 | 0 | *ff = bcd2uint(tcsmpte>>24 & 0x3f); // 6-bit frames |
40 | 0 | *drop = tcsmpte & 1<<30 && !prevent_df; // 1-bit drop if not arbitrary bit |
41 | |
|
42 | 0 | if (av_cmp_q(rate, (AVRational) {30, 1}) == 1) { |
43 | 0 | *ff <<= 1; |
44 | 0 | if (!skip_field) { |
45 | 0 | if (av_cmp_q(rate, (AVRational) {50, 1}) == 0) |
46 | 0 | *ff += !!(tcsmpte & 1 << 7); |
47 | 0 | else |
48 | 0 | *ff += !!(tcsmpte & 1 << 23); |
49 | 0 | } |
50 | 0 | } |
51 | 0 | } |