[FFmpeg-devel] [PATCH 2/3] timecode: add ff_timecode_to_string().

Clément Bœsch ubitux at gmail.com
Wed Dec 7 11:09:50 CET 2011


On Tue, Dec 06, 2011 at 07:57:08PM +0100, Michael Niedermayer wrote:
> On Tue, Dec 06, 2011 at 11:37:38AM +0100, Clément Bœsch wrote:
> > From: Clément Bœsch <clement.boesch at smartjog.com>
> > 
> > ---
> >  libavcodec/timecode.c |   16 ++++++++++++++++
> >  libavcodec/timecode.h |   11 +++++++++++
> >  2 files changed, 27 insertions(+), 0 deletions(-)
> > 
> > diff --git a/libavcodec/timecode.c b/libavcodec/timecode.c
> > index 4148f32..4bfb529 100644
> > --- a/libavcodec/timecode.c
> > +++ b/libavcodec/timecode.c
> > @@ -78,6 +78,22 @@ static int ff_check_timecode_rate(void *avcl, AVRational rate, int drop)
> >      }
> >  }
> >  
> > +char *ff_timecode_to_string(char *buf, const struct ff_timecode *tc, unsigned frame)
> 
> if this is supposed to be used in other libs than libavcodec then it
> needs a prefix listed in libavcodec.v
> like avpriv_
> 

Mmh ok. I added ff_timecode_to_string in libavcodec.v. Also, new patch
attached (to be applied on top of that current patchset) to rename the
internal timecode functions (no bump needed, right?).

-- 
Clément B.
-------------- next part --------------
From d709ff71c55422652e2cd0cbbe7e487f85dd695d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Cl=C3=A9ment=20B=C5=93sch?= <clement.boesch at smartjog.com>
Date: Wed, 7 Dec 2011 10:44:50 +0100
Subject: [PATCH 4/4] timecode: rename internal ff_* symbols to avpriv_*.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Those functions are shared between libs.

Also fix a typo in function names: smtpe → smpte.
---
 libavcodec/libavcodec.v   |    4 ----
 libavcodec/mpeg12enc.c    |    4 ++--
 libavcodec/timecode.c     |   10 +++++-----
 libavcodec/timecode.h     |    8 ++++----
 libavfilter/vf_drawtext.c |    4 ++--
 libavformat/dvenc.c       |    8 ++++----
 libavformat/mxfenc.c      |    8 ++++----
 7 files changed, 21 insertions(+), 25 deletions(-)

diff --git a/libavcodec/libavcodec.v b/libavcodec/libavcodec.v
index 6cc83cb..a1ed872 100644
--- a/libavcodec/libavcodec.v
+++ b/libavcodec/libavcodec.v
@@ -6,11 +6,7 @@ LIBAVCODEC_$MAJOR {
                 img_get_alpha_info;
                 dsputil_init;
                 ff_find_pix_fmt;
-                ff_framenum_to_drop_timecode;
-                ff_framenum_to_smtpe_timecode;
                 ff_raw_pix_fmt_tags;
-                ff_init_smtpe_timecode;
-                ff_timecode_to_string;
                 ff_fft*;
                 ff_mdct*;
                 ff_dct*;
diff --git a/libavcodec/mpeg12enc.c b/libavcodec/mpeg12enc.c
index 3cfe733..195d14e 100644
--- a/libavcodec/mpeg12enc.c
+++ b/libavcodec/mpeg12enc.c
@@ -182,7 +182,7 @@ static av_cold int encode_init(AVCodecContext *avctx)
 
     if (s->tc.str) {
         s->tc.rate = avpriv_frame_rate_tab[s->frame_rate_index];
-        if (ff_init_smtpe_timecode(s, &s->tc) < 0)
+        if (avpriv_init_smpte_timecode(s, &s->tc) < 0)
             return -1;
         s->avctx->timecode_frame_start = s->tc.start;
     } else {
@@ -303,7 +303,7 @@ static void mpeg1_encode_sequence_header(MpegEncContext *s)
             s->gop_picture_number = s->current_picture_ptr->f.coded_picture_number;
             av_assert0(s->drop_frame_timecode == s->tc.drop);
             if (s->tc.drop)
-                time_code = ff_framenum_to_drop_timecode(time_code);
+                time_code = avpriv_framenum_to_drop_timecode(time_code);
             put_bits(&s->pb, 5, (uint32_t)((time_code / (fps * 3600)) % 24));
             put_bits(&s->pb, 6, (uint32_t)((time_code / (fps * 60)) % 60));
             put_bits(&s->pb, 1, 1);
diff --git a/libavcodec/timecode.c b/libavcodec/timecode.c
index 354fc00..6e2e3af 100644
--- a/libavcodec/timecode.c
+++ b/libavcodec/timecode.c
@@ -28,7 +28,7 @@
 #include "timecode.h"
 #include "libavutil/log.h"
 
-int ff_framenum_to_drop_timecode(int frame_num)
+int avpriv_framenum_to_drop_timecode(int frame_num)
 {
     /* only works for NTSC 29.97 */
     int d = frame_num / 17982;
@@ -37,7 +37,7 @@ int ff_framenum_to_drop_timecode(int frame_num)
     return frame_num + 18 * d + 2 * ((m - 2) / 1798);
 }
 
-uint32_t ff_framenum_to_smtpe_timecode(unsigned frame, int fps, int drop)
+uint32_t avpriv_framenum_to_smpte_timecode(unsigned frame, int fps, int drop)
 {
     return (0                                    << 31) | // color frame flag
            (drop                                 << 30) | // drop  frame flag
@@ -79,7 +79,7 @@ static int check_timecode_rate(void *avcl, AVRational rate, int drop)
     }
 }
 
-char *ff_timecode_to_string(char *buf, const struct ff_timecode *tc, unsigned frame)
+char *avpriv_timecode_to_string(char *buf, const struct ff_timecode *tc, unsigned frame)
 {
     int frame_num = tc->start + frame;
     int fps = (tc->rate.num + tc->rate.den/2) / tc->rate.den;
@@ -89,13 +89,13 @@ char *ff_timecode_to_string(char *buf, const struct ff_timecode *tc, unsigned fr
     int hh  = frame_num / (fps*3600) % 24;
 
     if (tc->drop)
-        frame_num = ff_framenum_to_drop_timecode(frame_num);
+        frame_num = avpriv_framenum_to_drop_timecode(frame_num);
     snprintf(buf, sizeof("hh:mm:ss.ff"), "%02d:%02d:%02d%c%02d",
              hh, mm, ss, tc->drop ? ';' : ':', ff);
     return buf;
 }
 
-int ff_init_smtpe_timecode(void *avcl, struct ff_timecode *tc)
+int avpriv_init_smpte_timecode(void *avcl, struct ff_timecode *tc)
 {
     int hh, mm, ss, ff, fps, ret;
     char c;
diff --git a/libavcodec/timecode.h b/libavcodec/timecode.h
index b1bb5c7..3757d1c 100644
--- a/libavcodec/timecode.h
+++ b/libavcodec/timecode.h
@@ -49,7 +49,7 @@ struct ff_timecode {
  * @return          Adjusted frame number
  * @warning         Adjustment is only valid in NTSC 29.97
  */
-int ff_framenum_to_drop_timecode(int frame_num);
+int avpriv_framenum_to_drop_timecode(int frame_num);
 
 /**
  * @brief       Convert frame id (timecode) to SMPTE 12M binary representation
@@ -58,7 +58,7 @@ int ff_framenum_to_drop_timecode(int frame_num);
  * @param drop  Drop flag
  * @return      The actual binary representation
  */
-uint32_t ff_framenum_to_smtpe_timecode(unsigned frame, int fps, int drop);
+uint32_t avpriv_framenum_to_smpte_timecode(unsigned frame, int fps, int drop);
 
 /**
  * @brief       Load timecode string in buf
@@ -69,7 +69,7 @@ uint32_t ff_framenum_to_smtpe_timecode(unsigned frame, int fps, int drop);
  * @note  buf must have enough space to store the timecode representation
  *        (sizeof("hh:mm:ss.ff"))
  */
-char *ff_timecode_to_string(char *buf, const struct ff_timecode *tc, unsigned frame);
+char *avpriv_timecode_to_string(char *buf, const struct ff_timecode *tc, unsigned frame);
 
 /**
  * Parse SMTPE 12M time representation (hh:mm:ss[:;.]ff). str and rate fields
@@ -81,6 +81,6 @@ char *ff_timecode_to_string(char *buf, const struct ff_timecode *tc, unsigned fr
  * @return     0 on success, negative value on failure
  * @warning    Adjustement is only valid in NTSC 29.97
  */
-int ff_init_smtpe_timecode(void *avcl, struct ff_timecode *tc);
+int avpriv_init_smpte_timecode(void *avcl, struct ff_timecode *tc);
 
 #endif /* AVCODEC_TIMECODE_H */
diff --git a/libavfilter/vf_drawtext.c b/libavfilter/vf_drawtext.c
index 525d5f5..c838111 100644
--- a/libavfilter/vf_drawtext.c
+++ b/libavfilter/vf_drawtext.c
@@ -319,7 +319,7 @@ static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque)
     }
 
     if (dtext->tc.str) {
-        if (ff_init_smtpe_timecode(ctx, &dtext->tc) < 0)
+        if (avpriv_init_smpte_timecode(ctx, &dtext->tc) < 0)
             return AVERROR(EINVAL);
         if (!dtext->text)
             dtext->text = av_strdup("");
@@ -697,7 +697,7 @@ static int draw_text(AVFilterContext *ctx, AVFilterBufferRef *picref,
 
     if (dtext->tc.str) {
         char tcbuf[sizeof("hh:mm:ss.ff")];
-        ff_timecode_to_string(tcbuf, &dtext->tc, dtext->frame_id++);
+        avpriv_timecode_to_string(tcbuf, &dtext->tc, dtext->frame_id++);
         buf = av_asprintf("%s%s", dtext->text, tcbuf);
     }
 
diff --git a/libavformat/dvenc.c b/libavformat/dvenc.c
index ce6568b..049bb7b 100644
--- a/libavformat/dvenc.c
+++ b/libavformat/dvenc.c
@@ -92,9 +92,9 @@ static int dv_write_pack(enum dv_pack_type pack_id, DVMuxContext *c, uint8_t* bu
          */
         ltc_frame = c->tc.start + c->frames;
         if (c->tc.drop)
-            ltc_frame = ff_framenum_to_drop_timecode(ltc_frame);
-        timecode = ff_framenum_to_smtpe_timecode(ltc_frame, c->sys->ltc_divisor,
-                                                 c->tc.drop);
+            ltc_frame = avpriv_framenum_to_drop_timecode(ltc_frame);
+        timecode = avpriv_framenum_to_smpte_timecode(ltc_frame, c->sys->ltc_divisor,
+                                                     c->tc.drop);
         timecode |= 1<<23 | 1<<15 | 1<<7 | 1<<6; // biphase and binary group flags
         AV_WB32(buf + 1, timecode);
         break;
@@ -378,7 +378,7 @@ static int dv_write_header(AVFormatContext *s)
     if (dvc->tc.str) {
         dvc->tc.rate.num = dvc->sys->time_base.den;
         dvc->tc.rate.den = dvc->sys->time_base.num;
-        if (ff_init_smtpe_timecode(s, &dvc->tc) < 0)
+        if (avpriv_init_smpte_timecode(s, &dvc->tc) < 0)
             return -1;
     }
     return 0;
diff --git a/libavformat/mxfenc.c b/libavformat/mxfenc.c
index 0b62a5a..05b53cd 100644
--- a/libavformat/mxfenc.c
+++ b/libavformat/mxfenc.c
@@ -1432,7 +1432,7 @@ static int mxf_write_header(AVFormatContext *s)
             if (mxf->tc.str) {
                 mxf->tc.rate.num = mxf->time_base.den;
                 mxf->tc.rate.den = mxf->time_base.num;
-                if (ff_init_smtpe_timecode(s, &mxf->tc) < 0)
+                if (avpriv_init_smpte_timecode(s, &mxf->tc) < 0)
                     return -1;
             }
             if (s->oformat == &ff_mxf_d10_muxer) {
@@ -1572,9 +1572,9 @@ static void mxf_write_system_item(AVFormatContext *s)
     avio_w8(pb, 0x81); // SMPTE 12M time code
     time_code = frame;
     if (mxf->tc.drop)
-        time_code = ff_framenum_to_drop_timecode(time_code);
-    time_code = ff_framenum_to_smtpe_timecode(time_code, mxf->timecode_base,
-                                              mxf->tc.drop);
+        time_code = avpriv_framenum_to_drop_timecode(time_code);
+    time_code = avpriv_framenum_to_smpte_timecode(time_code, mxf->timecode_base,
+                                                  mxf->tc.drop);
     avio_wb32(pb, time_code);
     avio_wb32(pb, 0); // binary group data
     avio_wb64(pb, 0);
-- 
1.7.7.3

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 490 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20111207/f9ebd5db/attachment.asc>


More information about the ffmpeg-devel mailing list