@@ -194,7 +194,7 @@ static int decode_audio(struct audio_buffer *audio_buf, s16 **data, int *size)
194194 AVIOContext *avio_ctx;
195195 AVStream *stream;
196196 AVCodecContext *codec;
197- AVPacket packet;
197+ AVPacket * packet;
198198 AVFrame *frame;
199199 struct SwrContext *swr;
200200 u8 *avio_ctx_buffer;
@@ -279,7 +279,11 @@ static int decode_audio(struct audio_buffer *audio_buf, s16 **data, int *size)
279279 return -1 ;
280280 }
281281
282- av_init_packet (&packet);
282+ packet=av_packet_alloc ();
283+ if (!packet) {
284+ LOG (" Error allocating the packet\n " );
285+ return -1 ;
286+ }
283287 frame = av_frame_alloc ();
284288 if (!frame) {
285289 LOG (" Error allocating the frame\n " );
@@ -289,8 +293,8 @@ static int decode_audio(struct audio_buffer *audio_buf, s16 **data, int *size)
289293 /* iterate through frames */
290294 *data = NULL ;
291295 *size = 0 ;
292- while (av_read_frame (fmt_ctx, & packet) >= 0 ) {
293- avcodec_send_packet (codec, & packet);
296+ while (av_read_frame (fmt_ctx, packet) >= 0 ) {
297+ avcodec_send_packet (codec, packet);
294298
295299 err = avcodec_receive_frame (codec, frame);
296300 if (err == AVERROR (EAGAIN))
@@ -301,10 +305,11 @@ static int decode_audio(struct audio_buffer *audio_buf, s16 **data, int *size)
301305 /* Flush any remaining conversion buffers... */
302306 convert_frame (swr, codec, frame, data, size, true );
303307
308+ av_packet_free (&packet);
304309 av_frame_free (&frame);
305310 swr_free (&swr);
306311 // avio_context_free(); // todo?
307- avcodec_close ( codec);
312+ avcodec_free_context (& codec);
308313 avformat_close_input (&fmt_ctx);
309314 avformat_free_context (fmt_ctx);
310315
0 commit comments