]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/yop.c
avformat/yop: alloc codecpar extradata only once
[ffmpeg] / libavformat / yop.c
index 9b77f6e30e0fbc100a4038276aedcc8eb339054a..e6fd896668cf579aafae161be9b90c74ba21fc1c 100644 (file)
@@ -58,7 +58,7 @@ static int yop_read_header(AVFormatContext *s)
     YopDecContext *yop = s->priv_data;
     AVIOContext *pb  = s->pb;
 
-    AVCodecContext *audio_dec, *video_dec;
+    AVCodecParameters *audio_par, *video_par;
     AVStream *audio_stream, *video_stream;
 
     int frame_rate, ret;
@@ -69,39 +69,39 @@ static int yop_read_header(AVFormatContext *s)
         return AVERROR(ENOMEM);
 
     // Extra data that will be passed to the decoder
-    if (ff_alloc_extradata(video_stream->codec, 8))
+    if (ff_alloc_extradata(video_stream->codecpar, 8))
         return AVERROR(ENOMEM);
 
     // Audio
-    audio_dec               = audio_stream->codec;
-    audio_dec->codec_type   = AVMEDIA_TYPE_AUDIO;
-    audio_dec->codec_id     = AV_CODEC_ID_ADPCM_IMA_APC;
-    audio_dec->channels     = 1;
-    audio_dec->channel_layout = AV_CH_LAYOUT_MONO;
-    audio_dec->sample_rate  = 22050;
+    audio_par                 = audio_stream->codecpar;
+    audio_par->codec_type     = AVMEDIA_TYPE_AUDIO;
+    audio_par->codec_id       = AV_CODEC_ID_ADPCM_IMA_APC;
+    audio_par->channels       = 1;
+    audio_par->channel_layout = AV_CH_LAYOUT_MONO;
+    audio_par->sample_rate    = 22050;
 
     // Video
-    video_dec               = video_stream->codec;
-    video_dec->codec_type   = AVMEDIA_TYPE_VIDEO;
-    video_dec->codec_id     = AV_CODEC_ID_YOP;
+    video_par               = video_stream->codecpar;
+    video_par->codec_type   = AVMEDIA_TYPE_VIDEO;
+    video_par->codec_id     = AV_CODEC_ID_YOP;
 
     avio_skip(pb, 6);
 
     frame_rate              = avio_r8(pb);
     yop->frame_size         = avio_r8(pb) * 2048;
-    video_dec->width        = avio_rl16(pb);
-    video_dec->height       = avio_rl16(pb);
+    video_par->width        = avio_rl16(pb);
+    video_par->height       = avio_rl16(pb);
 
     video_stream->sample_aspect_ratio = (AVRational){1, 2};
 
-    ret = avio_read(pb, video_dec->extradata, 8);
+    ret = avio_read(pb, video_par->extradata, 8);
     if (ret < 8)
         return ret < 0 ? ret : AVERROR_EOF;
 
-    yop->palette_size       = video_dec->extradata[0] * 3 + 4;
-    yop->audio_block_length = AV_RL16(video_dec->extradata + 6);
+    yop->palette_size       = video_par->extradata[0] * 3 + 4;
+    yop->audio_block_length = AV_RL16(video_par->extradata + 6);
 
-    video_dec->bit_rate     = 8 * (yop->frame_size - yop->audio_block_length) * frame_rate;
+    video_par->bit_rate     = 8 * (yop->frame_size - yop->audio_block_length) * frame_rate;
 
     // 1840 samples per frame, 1 nibble per sample; hence 1840/2 = 920
     if (yop->audio_block_length < 920 ||