diff mbox

[FFmpeg-devel,08/37] avformat/matroskadec: Don't copy attached pictures

Message ID 20190516223018.30827-9-andreas.rheinhardt@gmail.com
State Accepted
Headers show

Commit Message

Andreas Rheinhardt May 16, 2019, 10:29 p.m. UTC
This commit replaces copying attached pictures by using references to
the already existing buffers.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
---
 libavformat/matroskadec.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

Comments

James Almer June 23, 2019, 2:42 a.m. UTC | #1
On 5/16/2019 7:29 PM, Andreas Rheinhardt wrote:
> This commit replaces copying attached pictures by using references to
> the already existing buffers.
> 
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
> ---
>  libavformat/matroskadec.c | 16 ++++++++++------
>  1 file changed, 10 insertions(+), 6 deletions(-)
> 
> diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c
> index 1cda5d5b76..0f9d55566f 100644
> --- a/libavformat/matroskadec.c
> +++ b/libavformat/matroskadec.c
> @@ -2713,15 +2713,19 @@ static int matroska_read_header(AVFormatContext *s)
>              attachments[j].stream = st;
>  
>              if (st->codecpar->codec_id != AV_CODEC_ID_NONE) {
> +                AVPacket *pkt = &st->attached_pic;
> +
>                  st->disposition         |= AV_DISPOSITION_ATTACHED_PIC;
>                  st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
>  
> -                av_init_packet(&st->attached_pic);
> -                if ((res = av_new_packet(&st->attached_pic, attachments[j].bin.size)) < 0)
> -                    return res;
> -                memcpy(st->attached_pic.data, attachments[j].bin.data, attachments[j].bin.size);
> -                st->attached_pic.stream_index = st->index;
> -                st->attached_pic.flags       |= AV_PKT_FLAG_KEY;
> +                av_init_packet(pkt);
> +                pkt->buf = av_buffer_ref(attachments[j].bin.buf);
> +                if (!pkt->buf)
> +                    return AVERROR(ENOMEM);
> +                pkt->data         = attachments[j].bin.data;
> +                pkt->size         = attachments[j].bin.size;
> +                pkt->stream_index = st->index;
> +                pkt->flags       |= AV_PKT_FLAG_KEY;
>              } else {
>                  st->codecpar->codec_type = AVMEDIA_TYPE_ATTACHMENT;
>                  if (ff_alloc_extradata(st->codecpar, attachments[j].bin.size))

Applied, thanks.
diff mbox

Patch

diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c
index 1cda5d5b76..0f9d55566f 100644
--- a/libavformat/matroskadec.c
+++ b/libavformat/matroskadec.c
@@ -2713,15 +2713,19 @@  static int matroska_read_header(AVFormatContext *s)
             attachments[j].stream = st;
 
             if (st->codecpar->codec_id != AV_CODEC_ID_NONE) {
+                AVPacket *pkt = &st->attached_pic;
+
                 st->disposition         |= AV_DISPOSITION_ATTACHED_PIC;
                 st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
 
-                av_init_packet(&st->attached_pic);
-                if ((res = av_new_packet(&st->attached_pic, attachments[j].bin.size)) < 0)
-                    return res;
-                memcpy(st->attached_pic.data, attachments[j].bin.data, attachments[j].bin.size);
-                st->attached_pic.stream_index = st->index;
-                st->attached_pic.flags       |= AV_PKT_FLAG_KEY;
+                av_init_packet(pkt);
+                pkt->buf = av_buffer_ref(attachments[j].bin.buf);
+                if (!pkt->buf)
+                    return AVERROR(ENOMEM);
+                pkt->data         = attachments[j].bin.data;
+                pkt->size         = attachments[j].bin.size;
+                pkt->stream_index = st->index;
+                pkt->flags       |= AV_PKT_FLAG_KEY;
             } else {
                 st->codecpar->codec_type = AVMEDIA_TYPE_ATTACHMENT;
                 if (ff_alloc_extradata(st->codecpar, attachments[j].bin.size))