]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/avienc.c
Cosmetics: Re-indent after last commit.
[ffmpeg] / libavformat / avienc.c
index 72aa8ea7da39c4bb35019f3d7bcd33cdd097e1a0..c9476d5b9f2e1b487b901c9196350a3d06fd0c4b 100644 (file)
@@ -21,6 +21,7 @@
 #include "avformat.h"
 #include "avi.h"
 #include "riff.h"
+#include "libavutil/intreadwrite.h"
 
 /*
  * TODO:
@@ -50,6 +51,7 @@ typedef struct  {
     int64_t frames_hdr_strm;
     int audio_strm_length;
     int packet_count;
+    int entry;
 
     AVIIndex indexes;
 } AVIStream ;
@@ -81,14 +83,14 @@ static int64_t avi_start_new_riff(AVFormatContext *s, ByteIOContext *pb,
     return loff;
 }
 
-static char* avi_stream2fourcc(char* tag, int index, enum CodecType type)
+static char* avi_stream2fourcc(char* tag, int index, enum AVMediaType type)
 {
     tag[0] = '0';
     tag[1] = '0' + index;
-    if (type == CODEC_TYPE_VIDEO) {
+    if (type == AVMEDIA_TYPE_VIDEO) {
         tag[2] = 'd';
         tag[3] = 'c';
-    } else if (type == CODEC_TYPE_SUBTITLE) {
+    } else if (type == AVMEDIA_TYPE_SUBTITLE) {
         // note: this is not an official code
         tag[2] = 's';
         tag[3] = 'b';
@@ -113,15 +115,6 @@ static void avi_write_info_tag(ByteIOContext *pb, const char *tag, const char *s
     }
 }
 
-static void avi_write_info_tag2(AVFormatContext *s, const char *fourcc, const char *key1, const char *key2)
-{
-    AVMetadataTag *tag= av_metadata_get(s->metadata, key1, NULL, 0);
-    if(!tag && key2)
-        tag= av_metadata_get(s->metadata, key2, NULL, 0);
-    if(tag)
-        avi_write_info_tag(s->pb, fourcc, tag->value);
-}
-
 static int avi_write_counters(AVFormatContext* s, int riff_id)
 {
     ByteIOContext *pb = s->pb;
@@ -143,7 +136,7 @@ static int avi_write_counters(AVFormatContext* s, int riff_id)
         } else {
             put_le32(pb, avist->audio_strm_length / au_ssize);
         }
-        if(stream->codec_type == CODEC_TYPE_VIDEO)
+        if(stream->codec_type == AVMEDIA_TYPE_VIDEO)
             nb_frames = FFMAX(nb_frames, avist->packet_count);
     }
     if(riff_id == 1) {
@@ -163,6 +156,7 @@ static int avi_write_header(AVFormatContext *s)
     int bitrate, n, i, nb_frames, au_byterate, au_ssize, au_scale;
     AVCodecContext *stream, *video_enc;
     int64_t list1, list2, strh, strf;
+    AVMetadataTag *t = NULL;
 
     for(n=0;n<s->nb_streams;n++) {
         s->streams[n]->priv_data= av_mallocz(sizeof(AVIStream));
@@ -183,7 +177,7 @@ static int avi_write_header(AVFormatContext *s)
     for(n=0;n<s->nb_streams;n++) {
         stream = s->streams[n]->codec;
         bitrate += stream->bit_rate;
-        if (stream->codec_type == CODEC_TYPE_VIDEO)
+        if (stream->codec_type == AVMEDIA_TYPE_VIDEO)
             video_enc = stream;
     }
 
@@ -228,16 +222,19 @@ static int avi_write_header(AVFormatContext *s)
         /* stream generic header */
         strh = ff_start_tag(pb, "strh");
         switch(stream->codec_type) {
-        case CODEC_TYPE_SUBTITLE:
+        case AVMEDIA_TYPE_SUBTITLE:
             // XSUB subtitles behave like video tracks, other subtitles
             // are not (yet) supported.
-            if (stream->codec_id != CODEC_ID_XSUB) break;
-        case CODEC_TYPE_VIDEO: put_tag(pb, "vids"); break;
-        case CODEC_TYPE_AUDIO: put_tag(pb, "auds"); break;
-//        case CODEC_TYPE_TEXT : put_tag(pb, "txts"); break;
-        case CODEC_TYPE_DATA : put_tag(pb, "dats"); break;
+            if (stream->codec_id != CODEC_ID_XSUB) {
+                av_log(s, AV_LOG_ERROR, "Subtitle streams other than DivX XSUB are not supported by the AVI muxer.\n");
+                return AVERROR_PATCHWELCOME;
+            }
+        case AVMEDIA_TYPE_VIDEO: put_tag(pb, "vids"); break;
+        case AVMEDIA_TYPE_AUDIO: put_tag(pb, "auds"); break;
+//        case AVMEDIA_TYPE_TEXT : put_tag(pb, "txts"); break;
+        case AVMEDIA_TYPE_DATA : put_tag(pb, "dats"); break;
         }
-        if(stream->codec_type == CODEC_TYPE_VIDEO ||
+        if(stream->codec_type == AVMEDIA_TYPE_VIDEO ||
            stream->codec_id == CODEC_ID_XSUB)
             put_le32(pb, stream->codec_tag);
         else
@@ -261,9 +258,9 @@ static int avi_write_header(AVFormatContext *s)
             put_le32(pb, 0); /* length, XXX: filled later */
 
         /* suggested buffer size */ //FIXME set at the end to largest chunk
-        if(stream->codec_type == CODEC_TYPE_VIDEO)
+        if(stream->codec_type == AVMEDIA_TYPE_VIDEO)
             put_le32(pb, 1024 * 1024);
-        else if(stream->codec_type == CODEC_TYPE_AUDIO)
+        else if(stream->codec_type == AVMEDIA_TYPE_AUDIO)
             put_le32(pb, 12 * 1024);
         else
             put_le32(pb, 0);
@@ -274,17 +271,17 @@ static int avi_write_header(AVFormatContext *s)
         put_le16(pb, stream->height);
         ff_end_tag(pb, strh);
 
-      if(stream->codec_type != CODEC_TYPE_DATA){
+      if(stream->codec_type != AVMEDIA_TYPE_DATA){
         strf = ff_start_tag(pb, "strf");
         switch(stream->codec_type) {
-        case CODEC_TYPE_SUBTITLE:
+        case AVMEDIA_TYPE_SUBTITLE:
             // XSUB subtitles behave like video tracks, other subtitles
             // are not (yet) supported.
             if (stream->codec_id != CODEC_ID_XSUB) break;
-        case CODEC_TYPE_VIDEO:
+        case AVMEDIA_TYPE_VIDEO:
             ff_put_bmp_header(pb, stream, ff_codec_bmp_tags, 0);
             break;
-        case CODEC_TYPE_AUDIO:
+        case AVMEDIA_TYPE_AUDIO:
             if (ff_put_wav_header(pb, stream) < 0) {
                 return -1;
             }
@@ -293,6 +290,10 @@ static int avi_write_header(AVFormatContext *s)
             return -1;
         }
         ff_end_tag(pb, strf);
+        if ((t = av_metadata_get(s->streams[i]->metadata, "title", NULL, 0))) {
+            avi_write_info_tag(s->pb, "strn", t->value);
+            t = NULL;
+        }
       }
 
         if (!url_is_streamed(pb)) {
@@ -319,7 +320,7 @@ static int avi_write_header(AVFormatContext *s)
             ff_end_tag(pb, avist->indexes.indx_start);
         }
 
-        if(   stream->codec_type == CODEC_TYPE_VIDEO
+        if(   stream->codec_type == AVMEDIA_TYPE_VIDEO
            && s->streams[i]->sample_aspect_ratio.num>0
            && s->streams[i]->sample_aspect_ratio.den>0){
             int vprp= ff_start_tag(pb, "vprp");
@@ -369,15 +370,11 @@ static int avi_write_header(AVFormatContext *s)
 
     list2 = ff_start_tag(pb, "LIST");
     put_tag(pb, "INFO");
-    avi_write_info_tag2(s, "INAM", "Title", NULL);
-    avi_write_info_tag2(s, "IART", "Artist", "Author");
-    avi_write_info_tag2(s, "ICOP", "Copyright", NULL);
-    avi_write_info_tag2(s, "ICMT", "Comment", NULL);
-    avi_write_info_tag2(s, "IPRD", "Album", NULL);
-    avi_write_info_tag2(s, "IGNR", "Genre", NULL);
-    avi_write_info_tag2(s, "IPRT", "Track", NULL);
-    if(!(s->streams[0]->codec->flags & CODEC_FLAG_BITEXACT))
-        avi_write_info_tag(pb, "ISFT", LIBAVFORMAT_IDENT);
+    ff_metadata_conv(&s->metadata, ff_avi_metadata_conv, NULL);
+    for (i = 0; *ff_avi_tags[i]; i++) {
+        if ((t = av_metadata_get(s->metadata, ff_avi_tags[i], NULL, AV_METADATA_MATCH_CASE)))
+            avi_write_info_tag(s->pb, t->key, t->value);
+    }
     ff_end_tag(pb, list2);
 
     /* some padding for easier tag editing */
@@ -461,20 +458,24 @@ static int avi_write_idx1(AVFormatContext *s)
     char tag[5];
 
     if (!url_is_streamed(pb)) {
+        AVIStream *avist;
         AVIIentry* ie = 0, *tie;
-        int entry[MAX_STREAMS];
         int empty, stream_id = -1;
 
         idx_chunk = ff_start_tag(pb, "idx1");
-        memset(&entry[0], 0, sizeof(entry));
+        for(i=0; i<s->nb_streams; i++){
+            avist= s->streams[i]->priv_data;
+            avist->entry=0;
+        }
+
         do {
             empty = 1;
             for (i=0; i<s->nb_streams; i++) {
-                AVIStream *avist= s->streams[i]->priv_data;
-                 if (avist->indexes.entry <= entry[i])
+                avist= s->streams[i]->priv_data;
+                 if (avist->indexes.entry <= avist->entry)
                      continue;
 
-                 tie = avi_get_ientry(&avist->indexes, entry[i]);
+                 tie = avi_get_ientry(&avist->indexes, avist->entry);
                  if (empty || tie->pos < ie->pos) {
                      ie = tie;
                      stream_id = i;
@@ -482,13 +483,14 @@ static int avi_write_idx1(AVFormatContext *s)
                  empty = 0;
             }
             if (!empty) {
+                avist= s->streams[stream_id]->priv_data;
                 avi_stream2fourcc(&tag[0], stream_id,
                                   s->streams[stream_id]->codec->codec_type);
                 put_tag(pb, &tag[0]);
                 put_le32(pb, ie->flags);
                 put_le32(pb, ie->pos);
                 put_le32(pb, ie->len);
-                entry[stream_id]++;
+                avist->entry++;
             }
         } while (!empty);
         ff_end_tag(pb, idx_chunk);
@@ -537,9 +539,9 @@ static int avi_write_packet(AVFormatContext *s, AVPacket *pkt)
     }
 
     avi_stream2fourcc(&tag[0], stream_index, enc->codec_type);
-    if(pkt->flags&PKT_FLAG_KEY)
+    if(pkt->flags&AV_PKT_FLAG_KEY)
         flags = 0x10;
-    if (enc->codec_type == CODEC_TYPE_AUDIO) {
+    if (enc->codec_type == AVMEDIA_TYPE_AUDIO) {
        avist->audio_strm_length += size;
     }
 
@@ -600,7 +602,7 @@ static int avi_write_trailer(AVFormatContext *s)
                 AVCodecContext *stream = s->streams[n]->codec;
                 AVIStream *avist= s->streams[n]->priv_data;
 
-                if (stream->codec_type == CODEC_TYPE_VIDEO) {
+                if (stream->codec_type == AVMEDIA_TYPE_VIDEO) {
                     if (nb_frames < avist->packet_count)
                         nb_frames = avist->packet_count;
                 } else {