changeset 4824:ef55a8830c20 libavformat

split mov_find_codec_tag in separate per format functions
author bcoudurier
date Tue, 07 Apr 2009 22:19:58 +0000
parents 4b571224b361
children b2eef653b7e4
files movenc.c
diffstat 1 files changed, 56 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/movenc.c	Tue Apr 07 21:25:02 2009 +0000
+++ b/movenc.c	Tue Apr 07 22:19:58 2009 +0000
@@ -580,10 +580,9 @@
     { CODEC_ID_NONE, 0 },
 };
 
-static int mov_find_codec_tag(AVFormatContext *s, MOVTrack *track)
+static int mp4_get_codec_tag(AVFormatContext *s, MOVTrack *track)
 {
     int tag = track->enc->codec_tag;
-    if (track->mode == MODE_MP4 || track->mode == MODE_PSP) {
         if (!codec_get_tag(ff_mp4_obj_type, track->enc->codec_id))
             return 0;
         if      (track->enc->codec_id == CODEC_ID_H264)      tag = MKTAG('a','v','c','1');
@@ -592,7 +591,14 @@
         else if (track->enc->codec_id == CODEC_ID_MOV_TEXT)  tag = MKTAG('t','x','3','g');
         else if (track->enc->codec_type == CODEC_TYPE_VIDEO) tag = MKTAG('m','p','4','v');
         else if (track->enc->codec_type == CODEC_TYPE_AUDIO) tag = MKTAG('m','p','4','a');
-    } else if (track->mode == MODE_IPOD) {
+
+    return tag;
+}
+
+static int ipod_get_codec_tag(AVFormatContext *s, MOVTrack *track)
+{
+    int tag = track->enc->codec_tag;
+
         if (track->enc->codec_type == CODEC_TYPE_SUBTITLE &&
             (tag == MKTAG('t','x','3','g') ||
              tag == MKTAG('t','e','x','t')))
@@ -602,20 +608,27 @@
         if (!match_ext(s->filename, "m4a") && !match_ext(s->filename, "m4v"))
             av_log(s, AV_LOG_WARNING, "Warning, extension is not .m4a nor .m4v "
                    "Quicktime/Ipod might not play the file\n");
-    } else if (track->mode & MODE_3GP) {
-        tag = codec_get_tag(codec_3gp_tags, track->enc->codec_id);
-    } else if (!tag || (track->enc->strict_std_compliance >= FF_COMPLIANCE_NORMAL &&
-                        (tag == MKTAG('d','v','c','p') ||
-                         track->enc->codec_id == CODEC_ID_RAWVIDEO ||
-                         av_get_bits_per_sample(track->enc->codec_id)))) { // pcm audio
-        if (track->enc->codec_id == CODEC_ID_DVVIDEO) {
+
+    return tag;
+}
+
+static int mov_get_dv_codec_tag(AVFormatContext *s, MOVTrack *track)
+{
+    int tag;
+
             if (track->enc->height == 480) /* NTSC */
                 if  (track->enc->pix_fmt == PIX_FMT_YUV422P) tag = MKTAG('d','v','5','n');
                 else                                         tag = MKTAG('d','v','c',' ');
             else if (track->enc->pix_fmt == PIX_FMT_YUV422P) tag = MKTAG('d','v','5','p');
             else if (track->enc->pix_fmt == PIX_FMT_YUV420P) tag = MKTAG('d','v','c','p');
             else                                             tag = MKTAG('d','v','p','p');
-        } else if (track->enc->codec_id == CODEC_ID_RAWVIDEO) {
+
+    return tag;
+}
+
+static int mov_get_rawvideo_codec_tag(AVFormatContext *s, MOVTrack *track)
+{
+    int tag = track->enc->codec_tag;
             int i;
             for (i = 0; i < FF_ARRAY_ELEMS(mov_pix_fmt_tags); i++) {
                 if (track->enc->pix_fmt == mov_pix_fmt_tags[i].pix_fmt) {
@@ -626,6 +639,22 @@
             }
             if (!tag) // restore tag
                 tag = track->enc->codec_tag;
+
+    return tag;
+}
+
+static int mov_get_codec_tag(AVFormatContext *s, MOVTrack *track)
+{
+    int tag = track->enc->codec_tag;
+
+    if (!tag || (track->enc->strict_std_compliance >= FF_COMPLIANCE_NORMAL &&
+                 (tag == MKTAG('d','v','c','p') ||
+                  track->enc->codec_id == CODEC_ID_RAWVIDEO ||
+                  av_get_bits_per_sample(track->enc->codec_id)))) { // pcm audio
+        if (track->enc->codec_id == CODEC_ID_DVVIDEO) {
+            tag = mov_get_dv_codec_tag(s, track);
+        } else if (track->enc->codec_id == CODEC_ID_RAWVIDEO) {
+            tag = mov_get_rawvideo_codec_tag(s, track);
         } else {
             if (track->enc->codec_type == CODEC_TYPE_VIDEO) {
                 tag = codec_get_tag(codec_movvideo_tags, track->enc->codec_id);
@@ -653,6 +682,22 @@
     return tag;
 }
 
+static int mov_find_codec_tag(AVFormatContext *s, MOVTrack *track)
+{
+    int tag = track->enc->codec_tag;
+
+    if (track->mode == MODE_MP4 || track->mode == MODE_PSP)
+        tag = mp4_get_codec_tag(s, track);
+    else if (track->mode == MODE_IPOD)
+        tag = ipod_get_codec_tag(s, track);
+    else if (track->mode & MODE_3GP)
+        tag = codec_get_tag(codec_3gp_tags, track->enc->codec_id);
+    else
+        tag = mov_get_codec_tag(s, track);
+
+    return tag;
+}
+
 /** Write uuid atom.
  * Needed to make file play in iPods running newest firmware
  * goes after avcC atom in moov.trak.mdia.minf.stbl.stsd.avc1