ffmpeg decoder plugin: do not allocate an AVFrame on stack.
AVFrame must be allocated with avcodec_alloc_frame().
This commit is contained in:
parent
6f2e1c2415
commit
8becbb8b08
@ -270,7 +270,8 @@ static enum decoder_command
|
|||||||
ffmpeg_send_packet(struct decoder *decoder, struct input_stream *is,
|
ffmpeg_send_packet(struct decoder *decoder, struct input_stream *is,
|
||||||
const AVPacket *packet,
|
const AVPacket *packet,
|
||||||
AVCodecContext *codec_context,
|
AVCodecContext *codec_context,
|
||||||
const AVRational *time_base)
|
const AVRational *time_base,
|
||||||
|
AVFrame *frame)
|
||||||
{
|
{
|
||||||
if (packet->pts >= 0 && packet->pts != (int64_t)AV_NOPTS_VALUE)
|
if (packet->pts >= 0 && packet->pts != (int64_t)AV_NOPTS_VALUE)
|
||||||
decoder_timestamp(decoder,
|
decoder_timestamp(decoder,
|
||||||
@ -293,14 +294,13 @@ ffmpeg_send_packet(struct decoder *decoder, struct input_stream *is,
|
|||||||
cmd == DECODE_COMMAND_NONE) {
|
cmd == DECODE_COMMAND_NONE) {
|
||||||
int audio_size = buffer_size;
|
int audio_size = buffer_size;
|
||||||
#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(53,25,0)
|
#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(53,25,0)
|
||||||
AVFrame frame;
|
|
||||||
int got_frame = 0;
|
int got_frame = 0;
|
||||||
int len = avcodec_decode_audio4(codec_context,
|
int len = avcodec_decode_audio4(codec_context,
|
||||||
&frame, &got_frame,
|
frame, &got_frame,
|
||||||
&packet2);
|
&packet2);
|
||||||
if (len >= 0 && got_frame) {
|
if (len >= 0 && got_frame) {
|
||||||
audio_size = copy_interleave_frame(codec_context,
|
audio_size = copy_interleave_frame(codec_context,
|
||||||
&frame,
|
frame,
|
||||||
aligned_buffer,
|
aligned_buffer,
|
||||||
buffer_size);
|
buffer_size);
|
||||||
if (audio_size < 0)
|
if (audio_size < 0)
|
||||||
@ -528,6 +528,18 @@ ffmpeg_decode(struct decoder *decoder, struct input_stream *input)
|
|||||||
decoder_initialized(decoder, &audio_format,
|
decoder_initialized(decoder, &audio_format,
|
||||||
input->seekable, total_time);
|
input->seekable, total_time);
|
||||||
|
|
||||||
|
AVFrame *frame = avcodec_alloc_frame();
|
||||||
|
if (!frame) {
|
||||||
|
g_warning("Could not allocate frame\n");
|
||||||
|
#if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(53,17,0)
|
||||||
|
avformat_close_input(&format_context);
|
||||||
|
#else
|
||||||
|
av_close_input_stream(format_context);
|
||||||
|
#endif
|
||||||
|
mpd_ffmpeg_stream_close(stream);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
enum decoder_command cmd;
|
enum decoder_command cmd;
|
||||||
do {
|
do {
|
||||||
AVPacket packet;
|
AVPacket packet;
|
||||||
@ -538,7 +550,8 @@ ffmpeg_decode(struct decoder *decoder, struct input_stream *input)
|
|||||||
if (packet.stream_index == audio_stream)
|
if (packet.stream_index == audio_stream)
|
||||||
cmd = ffmpeg_send_packet(decoder, input,
|
cmd = ffmpeg_send_packet(decoder, input,
|
||||||
&packet, codec_context,
|
&packet, codec_context,
|
||||||
&av_stream->time_base);
|
&av_stream->time_base,
|
||||||
|
frame);
|
||||||
else
|
else
|
||||||
cmd = decoder_get_command(decoder);
|
cmd = decoder_get_command(decoder);
|
||||||
|
|
||||||
@ -559,6 +572,12 @@ ffmpeg_decode(struct decoder *decoder, struct input_stream *input)
|
|||||||
}
|
}
|
||||||
} while (cmd != DECODE_COMMAND_STOP);
|
} while (cmd != DECODE_COMMAND_STOP);
|
||||||
|
|
||||||
|
#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(54, 28, 0)
|
||||||
|
avcodec_free_frame(&frame);
|
||||||
|
#else
|
||||||
|
av_freep(&frame);
|
||||||
|
#endif
|
||||||
|
|
||||||
avcodec_close(codec_context);
|
avcodec_close(codec_context);
|
||||||
#if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(53,17,0)
|
#if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(53,17,0)
|
||||||
avformat_close_input(&format_context);
|
avformat_close_input(&format_context);
|
||||||
|
Loading…
Reference in New Issue
Block a user