Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Subject: [PATCH 1/2] [WIP] timecode: use flags in the timecode context
- ---
- libavcodec/timecode.c | 22 +++++++++++++---------
- libavcodec/timecode.h | 12 +++++++++---
- 2 files changed, 22 insertions(+), 12 deletions(-)
- diff --git a/libavcodec/timecode.c b/libavcodec/timecode.c
- index 2e0f4a4..d8316b1 100644
- --- a/libavcodec/timecode.c
- +++ b/libavcodec/timecode.c
- @@ -37,8 +37,9 @@ int avpriv_framenum_to_drop_timecode(int frame_num)
- return frame_num + 18 * d + 2 * ((m - 2) / 1798);
- }
- -uint32_t avpriv_framenum_to_smpte_timecode(unsigned frame, int fps, int drop)
- +uint32_t avpriv_framenum_to_smpte_timecode(unsigned frame, int fps, int flags)
- {
- + int drop = (flags && TIMECODE_DROP_FRAME);
- return (0 << 31) | // color frame flag
- (drop << 30) | // drop frame flag
- ( ((frame % fps) / 10) << 28) | // tens of frames
- @@ -55,9 +56,11 @@ uint32_t avpriv_framenum_to_smpte_timecode(unsigned frame, int fps, int drop)
- ( (frame / (fps * 3600) % 24)) % 10; // units of hours
- }
- -int avpriv_check_timecode_rate(void *avcl, AVRational rate, int drop)
- +int avpriv_check_timecode_rate(void *avcl, const struct ff_timecode *tc)
- {
- int fps;
- + AVRational rate = tc->rate;
- + int drop = tc->flags && TIMECODE_DROP_FRAME;
- if (!rate.num || !rate.den) {
- av_log(avcl, AV_LOG_ERROR, "Timecode frame rate must be specified\n");
- @@ -85,7 +88,7 @@ char *avpriv_timecode_to_string(char *buf, const struct ff_timecode *tc, unsigne
- int fps = (tc->rate.num + tc->rate.den/2) / tc->rate.den;
- int hh, mm, ss, ff, neg = 0;
- - if (tc->drop)
- + if (tc->flags && TIMECODE_DROP_FRAME)
- frame_num = avpriv_framenum_to_drop_timecode(frame_num);
- if (frame_num < 0) {
- frame_num = -frame_num;
- @@ -97,7 +100,7 @@ char *avpriv_timecode_to_string(char *buf, const struct ff_timecode *tc, unsigne
- hh = frame_num / (fps*3600);
- snprintf(buf, 16, "%s%02d:%02d:%02d%c%02d",
- neg ? "-" : "",
- - hh, mm, ss, tc->drop ? ';' : ':', ff);
- + hh, mm, ss, (tc->flags && TIMECODE_DROP_FRAME) ? ';' : ':', ff);
- return buf;
- }
- @@ -112,16 +115,17 @@ int avpriv_init_smpte_timecode(void *avcl, struct ff_timecode *tc)
- return -1;
- }
- - tc->drop = c != ':'; // drop if ';', '.', ...
- + if(c != ':') // drop if ';', '.', ...
- + tc->flags &= TIMECODE_DROP_FRAME;
- - ret = avpriv_check_timecode_rate(avcl, tc->rate, tc->drop);
- + ret = avpriv_check_timecode_rate(avcl, tc);
- 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;
- - if (tc->drop) { /* adjust frame number */
- + if (tc->flags && TIMECODE_DROP_FRAME) { /* adjust frame number */
- int tmins = 60*hh + mm;
- tc->start -= 2 * (tmins - tmins/10);
- }
- @@ -134,9 +138,9 @@ int ff_framenum_to_drop_timecode(int frame_num)
- return avpriv_framenum_to_drop_timecode(frame_num);
- }
- -uint32_t ff_framenum_to_smtpe_timecode(unsigned frame, int fps, int drop)
- +uint32_t ff_framenum_to_smtpe_timecode(unsigned frame, int fps, int flags)
- {
- - return avpriv_framenum_to_smpte_timecode(frame, fps, drop);
- + return avpriv_framenum_to_smpte_timecode(frame, fps, flags);
- }
- int ff_init_smtpe_timecode(void *avcl, struct ff_timecode *tc)
- diff --git a/libavcodec/timecode.h b/libavcodec/timecode.h
- index bcfb0fa..63a4ae0 100644
- --- a/libavcodec/timecode.h
- +++ b/libavcodec/timecode.h
- @@ -31,6 +31,12 @@
- #include "avcodec.h"
- #include "libavutil/rational.h"
- +/* timecode flags */
- +#define TIMECODE_DROP_FRAME 0x0001 ///< Drop Frame
- +#define TIMECODE_MAX_24H 0x0002 ///< Timecode wraps after 24h
- +#define TIMECODE_NEG_TIMES 0x0004 ///< Negative timecode allowed
- +#define TIMECODE_COUNTER 0x0008 ///< Time value corresponds to a tape counter value
- +
- #define TIMECODE_OPT(ctx, flags) \
- "timecode", "set timecode value following hh:mm:ss[:;.]ff format, " \
- "use ';' or '.' before frame number for drop frame", \
- @@ -40,7 +46,7 @@
- struct ff_timecode {
- char *str; ///< string following the hh:mm:ss[:;.]ff format
- int start; ///< timecode frame start
- - int drop; ///< drop flag (1 if drop, else 0)
- + int flags; ///< TIMECODE_* flags
- AVRational rate; ///< Frame rate in rational form
- };
- @@ -79,7 +85,7 @@ char *avpriv_timecode_to_string(char *buf, const struct ff_timecode *tc, unsigne
- *
- * @return 0 on success, negative value on failure
- */
- -int avpriv_check_timecode_rate(void *avcl, AVRational rate, int drop);
- +int avpriv_check_timecode_rate(void *avcl, const struct ff_timecode *tc);
- /**
- * Parse SMTPE 12M time representation (hh:mm:ss[:;.]ff). str and rate fields
- @@ -95,7 +101,7 @@ int avpriv_init_smpte_timecode(void *avcl, struct ff_timecode *tc);
- #if FF_API_OLD_TIMECODE
- attribute_deprecated int ff_framenum_to_drop_timecode(int frame_num);
- -attribute_deprecated uint32_t ff_framenum_to_smtpe_timecode(unsigned frame, int fps, int drop);
- +attribute_deprecated uint32_t ff_framenum_to_smtpe_timecode(unsigned frame, int fps, int flags);
- attribute_deprecated int ff_init_smtpe_timecode(void *avcl, struct ff_timecode *tc);
- #endif
- --
- 1.7.8.3
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement