avcodec/mmaldec: Avoid creating unnecessary reference, simplify code

ffmal_add_packet() basically duplicated the logic in
av_packet_make_refcounted() with the added twist that it always
created a reference even if one is already available.
This commit stops doing this.

Tested-by: Cameron Gutman <aicommander@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
pull/376/head
Andreas Rheinhardt 3 years ago
parent dd779749f0
commit 9644ee224f
  1. 23
      libavcodec/mmaldec.c

@ -485,29 +485,19 @@ static int ffmmal_add_packet(AVCodecContext *avctx, AVPacket *avpkt,
int is_extradata) int is_extradata)
{ {
MMALDecodeContext *ctx = avctx->priv_data; MMALDecodeContext *ctx = avctx->priv_data;
AVBufferRef *buf = NULL; const AVBufferRef *buf = NULL;
int size = 0; int size = 0;
uint8_t *data = (uint8_t *)""; uint8_t *data = (uint8_t *)"";
uint8_t *start; uint8_t *start;
int ret = 0; int ret = 0;
if (avpkt->size) { if (avpkt->size) {
if (avpkt->buf) { ret = av_packet_make_refcounted(avpkt);
buf = av_buffer_ref(avpkt->buf); if (ret < 0)
size = avpkt->size;
data = avpkt->data;
} else {
buf = av_buffer_alloc(avpkt->size);
if (buf) {
memcpy(buf->data, avpkt->data, avpkt->size);
size = buf->size;
data = buf->data;
}
}
if (!buf) {
ret = AVERROR(ENOMEM);
goto done; goto done;
} buf = avpkt->buf;
data = avpkt->data;
size = avpkt->size;
if (!is_extradata) if (!is_extradata)
ctx->packets_sent++; ctx->packets_sent++;
} else { } else {
@ -573,7 +563,6 @@ static int ffmmal_add_packet(AVCodecContext *avctx, AVPacket *avpkt,
} while (size); } while (size);
done: done:
av_buffer_unref(&buf);
av_packet_unref(avpkt); av_packet_unref(avpkt);
return ret; return ret;
} }

Loading…
Cancel
Save