You've already forked FFmpeg
mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-08-15 14:13:16 +02:00
avcodec/mpeg4_unpack_bframes: reduce code duplication
Also fixes one potential leak of side data in out if the av_packet_from_data() call fails. Reviewed-by: Michael Niedermayer <michael@niedermayer.cc> Signed-off-by: James Almer <jamrial@gmail.com>
This commit is contained in:
@@ -108,8 +108,8 @@ static int mpeg4_unpack_bframes_filter(AVBSFContext *ctx, AVPacket *out)
|
|||||||
s->b_frame_buf = create_new_buffer(in->data + pos_vop2, s->b_frame_buf_size);
|
s->b_frame_buf = create_new_buffer(in->data + pos_vop2, s->b_frame_buf_size);
|
||||||
if (!s->b_frame_buf) {
|
if (!s->b_frame_buf) {
|
||||||
s->b_frame_buf_size = 0;
|
s->b_frame_buf_size = 0;
|
||||||
av_packet_free(&in);
|
ret = AVERROR(ENOMEM);
|
||||||
return AVERROR(ENOMEM);
|
goto fail;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -122,14 +122,12 @@ static int mpeg4_unpack_bframes_filter(AVBSFContext *ctx, AVPacket *out)
|
|||||||
/* use frame from BSFContext */
|
/* use frame from BSFContext */
|
||||||
ret = av_packet_copy_props(out, in);
|
ret = av_packet_copy_props(out, in);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
av_packet_free(&in);
|
goto fail;
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = av_packet_from_data(out, s->b_frame_buf, s->b_frame_buf_size);
|
ret = av_packet_from_data(out, s->b_frame_buf, s->b_frame_buf_size);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
av_packet_free(&in);
|
goto fail;
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
if (in->size <= MAX_NVOP_SIZE) {
|
if (in->size <= MAX_NVOP_SIZE) {
|
||||||
/* N-VOP */
|
/* N-VOP */
|
||||||
@@ -142,9 +140,8 @@ static int mpeg4_unpack_bframes_filter(AVBSFContext *ctx, AVPacket *out)
|
|||||||
s->b_frame_buf = create_new_buffer(in->data, in->size);
|
s->b_frame_buf = create_new_buffer(in->data, in->size);
|
||||||
if (!s->b_frame_buf) {
|
if (!s->b_frame_buf) {
|
||||||
s->b_frame_buf_size = 0;
|
s->b_frame_buf_size = 0;
|
||||||
av_packet_unref(out);
|
ret = AVERROR(ENOMEM);
|
||||||
av_packet_free(&in);
|
goto fail;
|
||||||
return AVERROR(ENOMEM);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (nb_vop >= 2) {
|
} else if (nb_vop >= 2) {
|
||||||
@@ -161,9 +158,12 @@ static int mpeg4_unpack_bframes_filter(AVBSFContext *ctx, AVPacket *out)
|
|||||||
av_packet_move_ref(out, in);
|
av_packet_move_ref(out, in);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fail:
|
||||||
|
if (ret < 0)
|
||||||
|
av_packet_unref(out);
|
||||||
av_packet_free(&in);
|
av_packet_free(&in);
|
||||||
|
|
||||||
return 0;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int mpeg4_unpack_bframes_init(AVBSFContext *ctx)
|
static int mpeg4_unpack_bframes_init(AVBSFContext *ctx)
|
||||||
|
Reference in New Issue
Block a user