]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/nutenc.c
rv34: use ff_MPV_common_frame_size_change()
[ffmpeg] / libavformat / nutenc.c
index df5dc6fdf73fb2f740ca1ade7b813a2ed234cba9..df0301b5e74c08bbb84f818a610dea8c585f24e2 100644 (file)
@@ -20,7 +20,9 @@
  */
 
 #include "libavutil/intreadwrite.h"
+#include "libavutil/mathematics.h"
 #include "libavutil/tree.h"
+#include "libavutil/dict.h"
 #include "libavcodec/mpegaudiodata.h"
 #include "nut.h"
 #include "internal.h"
@@ -34,20 +36,20 @@ static int find_expected_header(AVCodecContext *c, int size, int key_frame, uint
 
     AV_WB24(out, 1);
 
-    if(c->codec_id == CODEC_ID_MPEG4){
+    if(c->codec_id == AV_CODEC_ID_MPEG4){
         if(key_frame){
             return 3;
         }else{
             out[3]= 0xB6;
             return 4;
         }
-    }else if(c->codec_id == CODEC_ID_MPEG1VIDEO || c->codec_id == CODEC_ID_MPEG2VIDEO){
+    }else if(c->codec_id == AV_CODEC_ID_MPEG1VIDEO || c->codec_id == AV_CODEC_ID_MPEG2VIDEO){
         return 3;
-    }else if(c->codec_id == CODEC_ID_H264){
+    }else if(c->codec_id == AV_CODEC_ID_H264){
         return 3;
-    }else if(c->codec_id == CODEC_ID_MP3 || c->codec_id == CODEC_ID_MP2){
+    }else if(c->codec_id == AV_CODEC_ID_MP3 || c->codec_id == AV_CODEC_ID_MP2){
         int lsf, mpeg25, sample_rate_index, bitrate_index, frame_size;
-        int layer= c->codec_id == CODEC_ID_MP3 ? 3 : 2;
+        int layer= c->codec_id == AV_CODEC_ID_MP3 ? 3 : 2;
         unsigned int header= 0xFFF00000;
 
         lsf     = sample_rate < (24000+32000)/2;
@@ -57,10 +59,10 @@ static int find_expected_header(AVCodecContext *c, int size, int key_frame, uint
         else if(sample_rate < (44100 + 48000)/2) sample_rate_index=0;
         else                                     sample_rate_index=1;
 
-        sample_rate= ff_mpa_freq_tab[sample_rate_index] >> (lsf + mpeg25);
+        sample_rate= avpriv_mpa_freq_tab[sample_rate_index] >> (lsf + mpeg25);
 
         for(bitrate_index=2; bitrate_index<30; bitrate_index++){
-            frame_size = ff_mpa_bitrate_tab[lsf][layer-1][bitrate_index>>1];
+            frame_size = avpriv_mpa_bitrate_tab[lsf][layer-1][bitrate_index>>1];
             frame_size = (frame_size * 144000) / (sample_rate << lsf) + (bitrate_index&1);
 
             if(frame_size == size)
@@ -206,7 +208,7 @@ static void build_frame_code(AVFormatContext *s){
             pred_table[2]=1;
             pred_table[3]=3;
             pred_table[4]=4;
-        }else if(codec->codec_id == CODEC_ID_VORBIS){
+        }else if(codec->codec_id == AV_CODEC_ID_VORBIS){
             pred_count=3;
             pred_table[0]=2;
             pred_table[1]=9;
@@ -430,7 +432,7 @@ static int add_info(AVIOContext *bc, const char *type, const char *value){
 
 static int write_globalinfo(NUTContext *nut, AVIOContext *bc){
     AVFormatContext *s= nut->avf;
-    AVMetadataTag *t = NULL;
+    AVDictionaryEntry *t = NULL;
     AVIOContext *dyn_bc;
     uint8_t *dyn_buf=NULL;
     int count=0, dyn_size;
@@ -438,7 +440,7 @@ static int write_globalinfo(NUTContext *nut, AVIOContext *bc){
     if(ret < 0)
         return ret;
 
-    while ((t = av_metadata_get(s->metadata, "", t, AV_METADATA_IGNORE_SUFFIX)))
+    while ((t = av_dict_get(s->metadata, "", t, AV_DICT_IGNORE_SUFFIX)))
         count += add_info(dyn_bc, t->key, t->value);
 
     ff_put_v(bc, 0); //stream_if_plus1
@@ -489,7 +491,7 @@ static int write_chapter(NUTContext *nut, AVIOContext *bc, int id)
 {
     AVIOContext *dyn_bc;
     uint8_t *dyn_buf = NULL;
-    AVMetadataTag *t = NULL;
+    AVDictionaryEntry *t = NULL;
     AVChapter *ch    = nut->avf->chapters[id];
     int ret, dyn_size, count = 0;
 
@@ -502,7 +504,7 @@ static int write_chapter(NUTContext *nut, AVIOContext *bc, int id)
     put_tt(nut, nut->chapter[id].time_base, bc, ch->start); // chapter_start
     ff_put_v(bc, ch->end - ch->start);                      // chapter_len
 
-    while ((t = av_metadata_get(ch->metadata, "", t, AV_METADATA_IGNORE_SUFFIX)))
+    while ((t = av_dict_get(ch->metadata, "", t, AV_DICT_IGNORE_SUFFIX)))
         count += add_info(dyn_bc, t->key, t->value);
 
     ff_put_v(bc, count);
@@ -576,7 +578,7 @@ static int write_headers(AVFormatContext *avctx, AVIOContext *bc){
     return 0;
 }
 
-static int write_header(AVFormatContext *s){
+static int nut_write_header(AVFormatContext *s){
     NUTContext *nut = s->priv_data;
     AVIOContext *bc = s->pb;
     int i, j, ret;
@@ -584,9 +586,16 @@ static int write_header(AVFormatContext *s){
     nut->avf= s;
 
     nut->stream   = av_mallocz(sizeof(StreamContext)*s->nb_streams);
-    nut->chapter  = av_mallocz(sizeof(ChapterContext)*s->nb_chapters);
+    if (s->nb_chapters)
+        nut->chapter  = av_mallocz(sizeof(ChapterContext)*s->nb_chapters);
     nut->time_base= av_mallocz(sizeof(AVRational   )*(s->nb_streams +
                                                       s->nb_chapters));
+    if (!nut->stream || (s->nb_chapters && !nut->chapter) || !nut->time_base) {
+        av_freep(&nut->stream);
+        av_freep(&nut->chapter);
+        av_freep(&nut->time_base);
+        return AVERROR(ENOMEM);
+    }
 
     for(i=0; i<s->nb_streams; i++){
         AVStream *st= s->streams[i];
@@ -594,7 +603,7 @@ static int write_header(AVFormatContext *s){
         AVRational time_base;
         ff_parse_specific_params(st->codec, &time_base.den, &ssize, &time_base.num);
 
-        av_set_pts_info(st, 64, time_base.num, time_base.den);
+        avpriv_set_pts_info(st, 64, time_base.num, time_base.den);
 
         for(j=0; j<nut->time_base_count; j++){
             if(!memcmp(&time_base, &nut->time_base[j], sizeof(AVRational))){
@@ -682,7 +691,7 @@ static int find_best_header_idx(NUTContext *nut, AVPacket *pkt){
     return best_i;
 }
 
-static int write_packet(AVFormatContext *s, AVPacket *pkt){
+static int nut_write_packet(AVFormatContext *s, AVPacket *pkt){
     NUTContext *nut = s->priv_data;
     StreamContext *nus= &nut->stream[pkt->stream_index];
     AVIOContext *bc = s->pb, *dyn_bc;
@@ -836,13 +845,13 @@ static int write_packet(AVFormatContext *s, AVPacket *pkt){
     return 0;
 }
 
-static int write_trailer(AVFormatContext *s){
+static int nut_write_trailer(AVFormatContext *s){
     NUTContext *nut= s->priv_data;
     AVIOContext *bc= s->pb;
 
     while(nut->header_count<3)
         write_headers(s, bc);
-    avio_flush(bc);
+
     ff_nut_free_sp(nut);
     av_freep(&nut->stream);
     av_freep(&nut->chapter);
@@ -852,22 +861,20 @@ static int write_trailer(AVFormatContext *s){
 }
 
 AVOutputFormat ff_nut_muxer = {
-    "nut",
-    NULL_IF_CONFIG_SMALL("NUT format"),
-    "video/x-nut",
-    "nut",
-    sizeof(NUTContext),
-#if   CONFIG_LIBVORBIS
-    CODEC_ID_VORBIS,
-#elif CONFIG_LIBMP3LAME
-    CODEC_ID_MP3,
-#else
-    CODEC_ID_MP2,
-#endif
-    CODEC_ID_MPEG4,
-    write_header,
-    write_packet,
-    write_trailer,
-    .flags = AVFMT_GLOBALHEADER | AVFMT_VARIABLE_FPS,
-    .codec_tag = (const AVCodecTag * const []){ ff_codec_bmp_tags, ff_nut_video_tags, ff_codec_wav_tags, ff_nut_subtitle_tags, 0 },
+    .name           = "nut",
+    .long_name      = NULL_IF_CONFIG_SMALL("NUT"),
+    .mime_type      = "video/x-nut",
+    .extensions     = "nut",
+    .priv_data_size = sizeof(NUTContext),
+    .audio_codec    = CONFIG_LIBVORBIS ? AV_CODEC_ID_VORBIS :
+                      CONFIG_LIBMP3LAME ? AV_CODEC_ID_MP3 : AV_CODEC_ID_MP2,
+    .video_codec    = AV_CODEC_ID_MPEG4,
+    .write_header   = nut_write_header,
+    .write_packet   = nut_write_packet,
+    .write_trailer  = nut_write_trailer,
+    .flags          = AVFMT_GLOBALHEADER | AVFMT_VARIABLE_FPS,
+    .codec_tag      = (const AVCodecTag * const []){
+        ff_codec_bmp_tags, ff_nut_video_tags, ff_codec_wav_tags,
+        ff_nut_subtitle_tags, 0
+    },
 };