[FFmpeg-cvslog] mov: Use defines for tfhd flags

Martin Storsjö git at videolan.org
Sun Feb 19 02:19:08 CET 2012


ffmpeg | branch: master | Martin Storsjö <martin at martin.st> | Thu Feb 16 20:48:30 2012 +0100| [73328f24fae92eeed907a4908ca3147d874ff674] | committer: Martin Storsjö

mov: Use defines for tfhd flags

Signed-off-by: Martin Storsjö <martin at martin.st>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=73328f24fae92eeed907a4908ca3147d874ff674
---

 libavformat/isom.h   |    7 +++++++
 libavformat/mov.c    |   18 ++++++++++--------
 libavformat/movenc.c |   18 +++++++++---------
 3 files changed, 26 insertions(+), 17 deletions(-)

diff --git a/libavformat/isom.h b/libavformat/isom.h
index e74a552..88eb44a 100644
--- a/libavformat/isom.h
+++ b/libavformat/isom.h
@@ -157,6 +157,13 @@ void ff_mp4_parse_es_descr(AVIOContext *pb, int *es_id);
 #define MP4DecSpecificDescrTag          0x05
 #define MP4SLDescrTag                   0x06
 
+#define MOV_TFHD_BASE_DATA_OFFSET       0x01
+#define MOV_TFHD_STSD_ID                0x02
+#define MOV_TFHD_DEFAULT_DURATION       0x08
+#define MOV_TFHD_DEFAULT_SIZE           0x10
+#define MOV_TFHD_DEFAULT_FLAGS          0x20
+#define MOV_TFHD_DURATION_IS_EMPTY  0x010000
+
 int ff_mov_read_esds(AVFormatContext *fc, AVIOContext *pb, MOVAtom atom);
 enum CodecID ff_mov_get_lpcm_codec_id(int bps, int flags);
 
diff --git a/libavformat/mov.c b/libavformat/mov.c
index 690cd1e..74b2f2a 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -2167,14 +2167,16 @@ static int mov_read_tfhd(MOVContext *c, AVIOContext *pb, MOVAtom atom)
         return AVERROR_INVALIDDATA;
     }
 
-    if (flags & 0x01) frag->base_data_offset = avio_rb64(pb);
-    else              frag->base_data_offset = frag->moof_offset;
-    if (flags & 0x02) frag->stsd_id          = avio_rb32(pb);
-    else              frag->stsd_id          = trex->stsd_id;
-
-    frag->duration = flags & 0x08 ? avio_rb32(pb) : trex->duration;
-    frag->size     = flags & 0x10 ? avio_rb32(pb) : trex->size;
-    frag->flags    = flags & 0x20 ? avio_rb32(pb) : trex->flags;
+    frag->base_data_offset = flags & MOV_TFHD_BASE_DATA_OFFSET ?
+                             avio_rb64(pb) : frag->moof_offset;
+    frag->stsd_id  = flags & MOV_TFHD_STSD_ID ? avio_rb32(pb) : trex->stsd_id;
+
+    frag->duration = flags & MOV_TFHD_DEFAULT_DURATION ?
+                     avio_rb32(pb) : trex->duration;
+    frag->size     = flags & MOV_TFHD_DEFAULT_SIZE ?
+                     avio_rb32(pb) : trex->size;
+    frag->flags    = flags & MOV_TFHD_DEFAULT_FLAGS ?
+                     avio_rb32(pb) : trex->flags;
     av_dlog(c->fc, "frag flags 0x%x\n", frag->flags);
     return 0;
 }
diff --git a/libavformat/movenc.c b/libavformat/movenc.c
index 612bdcb..6c17e5a 100644
--- a/libavformat/movenc.c
+++ b/libavformat/movenc.c
@@ -2179,19 +2179,19 @@ static int mov_write_tfhd_tag(AVIOContext *pb, MOVTrack *track,
                               int64_t moof_offset)
 {
     int64_t pos = avio_tell(pb);
-    /* default-sample-size + default-sample-duration + base-data-offset */
-    uint32_t flags = 0x19;
+    uint32_t flags = MOV_TFHD_DEFAULT_SIZE | MOV_TFHD_DEFAULT_DURATION |
+                     MOV_TFHD_BASE_DATA_OFFSET;
     if (!track->entry) {
-        flags |= 0x010000; /* duration-is-empty */
+        flags |= MOV_TFHD_DURATION_IS_EMPTY;
     } else {
-        flags |= 0x20; /* default-sample-flags-present */
+        flags |= MOV_TFHD_DEFAULT_FLAGS;
     }
 
     /* Don't set a default sample size, the silverlight player refuses
      * to play files with that set. Don't set a default sample duration,
      * WMP freaks out if it is set. */
     if (track->mode == MODE_ISM)
-        flags &= ~0x18;
+        flags &= ~(MOV_TFHD_DEFAULT_SIZE | MOV_TFHD_DEFAULT_DURATION);
 
     avio_wb32(pb, 0); /* size placeholder */
     ffio_wfourcc(pb, "tfhd");
@@ -2199,19 +2199,19 @@ static int mov_write_tfhd_tag(AVIOContext *pb, MOVTrack *track,
     avio_wb24(pb, flags);
 
     avio_wb32(pb, track->track_id); /* track-id */
-    if (flags & 0x01)
+    if (flags & MOV_TFHD_BASE_DATA_OFFSET)
         avio_wb64(pb, moof_offset);
-    if (flags & 0x08) {
+    if (flags & MOV_TFHD_DEFAULT_DURATION) {
         track->default_duration = track->audio_vbr ? track->enc->frame_size : 1;
         avio_wb32(pb, track->default_duration);
     }
-    if (flags & 0x10) {
+    if (flags & MOV_TFHD_DEFAULT_SIZE) {
         track->default_size = track->entry ? track->cluster[0].size : 1;
         avio_wb32(pb, track->default_size);
     } else
         track->default_size = -1;
 
-    if (flags & 0x20) {
+    if (flags & MOV_TFHD_DEFAULT_FLAGS) {
         track->default_sample_flags =
             track->enc->codec_type == AVMEDIA_TYPE_VIDEO ?
             0x01010000 : 0x02000000;



More information about the ffmpeg-cvslog mailing list