mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-04-23 17:14:23 +00:00
avaudenc: Fix leak of AVBufferRef
AVPacket contains AVBufferRef which may leak unless unreffed properly. https://bugzilla.gnome.org/show_bug.cgi?id=726814
This commit is contained in:
parent
245be56510
commit
6d92f18d1b
1 changed files with 15 additions and 7 deletions
|
@ -406,6 +406,12 @@ gst_ffmpegaudenc_set_format (GstAudioEncoder * encoder, GstAudioInfo * info)
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
gst_ffmpegaudenc_free_avpacket (gpointer pkt)
|
||||||
|
{
|
||||||
|
av_packet_unref ((AVPacket *) pkt);
|
||||||
|
g_slice_free (AVPacket, pkt);
|
||||||
|
}
|
||||||
|
|
||||||
static GstFlowReturn
|
static GstFlowReturn
|
||||||
gst_ffmpegaudenc_encode_audio (GstFFMpegAudEnc * ffmpegaudenc,
|
gst_ffmpegaudenc_encode_audio (GstFFMpegAudEnc * ffmpegaudenc,
|
||||||
|
@ -416,7 +422,7 @@ gst_ffmpegaudenc_encode_audio (GstFFMpegAudEnc * ffmpegaudenc,
|
||||||
gint res;
|
gint res;
|
||||||
GstFlowReturn ret;
|
GstFlowReturn ret;
|
||||||
GstAudioInfo *info;
|
GstAudioInfo *info;
|
||||||
AVPacket pkt;
|
AVPacket *pkt;
|
||||||
AVFrame frame;
|
AVFrame frame;
|
||||||
gboolean planar;
|
gboolean planar;
|
||||||
|
|
||||||
|
@ -427,7 +433,7 @@ gst_ffmpegaudenc_encode_audio (GstFFMpegAudEnc * ffmpegaudenc,
|
||||||
GST_LOG_OBJECT (ffmpegaudenc, "encoding buffer %p size:%u", audio_in,
|
GST_LOG_OBJECT (ffmpegaudenc, "encoding buffer %p size:%u", audio_in,
|
||||||
in_size);
|
in_size);
|
||||||
|
|
||||||
memset (&pkt, 0, sizeof (pkt));
|
pkt = g_slice_new0 (AVPacket);
|
||||||
|
|
||||||
if (audio_in != NULL) {
|
if (audio_in != NULL) {
|
||||||
memset (&frame, 0, sizeof (frame));
|
memset (&frame, 0, sizeof (frame));
|
||||||
|
@ -514,7 +520,7 @@ gst_ffmpegaudenc_encode_audio (GstFFMpegAudEnc * ffmpegaudenc,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* we have a frame to feed the encoder */
|
/* we have a frame to feed the encoder */
|
||||||
res = avcodec_encode_audio2 (ctx, &pkt, &frame, have_data);
|
res = avcodec_encode_audio2 (ctx, pkt, &frame, have_data);
|
||||||
|
|
||||||
if (planar && info->channels > 1)
|
if (planar && info->channels > 1)
|
||||||
g_free (frame.data[0]);
|
g_free (frame.data[0]);
|
||||||
|
@ -523,12 +529,13 @@ gst_ffmpegaudenc_encode_audio (GstFFMpegAudEnc * ffmpegaudenc,
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
/* flushing the encoder */
|
/* flushing the encoder */
|
||||||
res = avcodec_encode_audio2 (ctx, &pkt, NULL, have_data);
|
res = avcodec_encode_audio2 (ctx, pkt, NULL, have_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (res < 0) {
|
if (res < 0) {
|
||||||
char error_str[128] = { 0, };
|
char error_str[128] = { 0, };
|
||||||
|
|
||||||
|
g_slice_free (AVPacket, pkt);
|
||||||
av_strerror (res, error_str, sizeof (error_str));
|
av_strerror (res, error_str, sizeof (error_str));
|
||||||
GST_ERROR_OBJECT (enc, "Failed to encode buffer: %d - %s", res, error_str);
|
GST_ERROR_OBJECT (enc, "Failed to encode buffer: %d - %s", res, error_str);
|
||||||
return GST_FLOW_OK;
|
return GST_FLOW_OK;
|
||||||
|
@ -539,11 +546,11 @@ gst_ffmpegaudenc_encode_audio (GstFFMpegAudEnc * ffmpegaudenc,
|
||||||
GstBuffer *outbuf;
|
GstBuffer *outbuf;
|
||||||
const AVCodec *codec;
|
const AVCodec *codec;
|
||||||
|
|
||||||
GST_LOG_OBJECT (ffmpegaudenc, "pushing size %d", pkt.size);
|
GST_LOG_OBJECT (ffmpegaudenc, "pushing size %d", pkt->size);
|
||||||
|
|
||||||
outbuf =
|
outbuf =
|
||||||
gst_buffer_new_wrapped_full (0, pkt.data, pkt.size, 0, pkt.size,
|
gst_buffer_new_wrapped_full (0, pkt->data, pkt->size, 0, pkt->size,
|
||||||
pkt.data, av_free);
|
pkt, gst_ffmpegaudenc_free_avpacket);
|
||||||
|
|
||||||
codec = ffmpegaudenc->context->codec;
|
codec = ffmpegaudenc->context->codec;
|
||||||
if ((codec->capabilities & CODEC_CAP_VARIABLE_FRAME_SIZE)) {
|
if ((codec->capabilities & CODEC_CAP_VARIABLE_FRAME_SIZE)) {
|
||||||
|
@ -553,6 +560,7 @@ gst_ffmpegaudenc_encode_audio (GstFFMpegAudEnc * ffmpegaudenc,
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
GST_LOG_OBJECT (ffmpegaudenc, "no output produced");
|
GST_LOG_OBJECT (ffmpegaudenc, "no output produced");
|
||||||
|
g_slice_free (AVPacket, pkt);
|
||||||
ret = GST_FLOW_OK;
|
ret = GST_FLOW_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue