diff options
author | Andreas Rheinhardt <andreas.rheinhardt@outlook.com> | 2022-05-06 20:53:12 +0200 |
---|---|---|
committer | Andreas Rheinhardt <andreas.rheinhardt@outlook.com> | 2022-05-10 07:42:22 +0200 |
commit | 92a43ad3842b8422dd0e88cfd66cf0f284e5015a (patch) | |
tree | 994bd0d8d5f3ca073603f603c93e3b30ce52a793 /libavformat/demux_utils.c | |
parent | 3c3c13e67b72d9c4e0615e744ef2c1cdf8b2701e (diff) | |
download | ffmpeg-92a43ad3842b8422dd0e88cfd66cf0f284e5015a.tar.gz |
avformat/utils: Move ff_add_attached_pic to demux_utils.c
It is demuxer-only: It potentially adds an AVStream and it sets
AVStream.attached_pic.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Diffstat (limited to 'libavformat/demux_utils.c')
-rw-r--r-- | libavformat/demux_utils.c | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/libavformat/demux_utils.c b/libavformat/demux_utils.c index ca5750d1ef..1fd634d1a2 100644 --- a/libavformat/demux_utils.c +++ b/libavformat/demux_utils.c @@ -19,6 +19,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#include "libavutil/avassert.h" #include "libavcodec/packet_internal.h" #include "avformat.h" #include "demux.h" @@ -107,3 +108,38 @@ int avformat_queue_attached_pictures(AVFormatContext *s) } return 0; } + +int ff_add_attached_pic(AVFormatContext *s, AVStream *st0, AVIOContext *pb, + AVBufferRef **buf, int size) +{ + AVStream *st = st0; + AVPacket *pkt; + int ret; + + if (!st && !(st = avformat_new_stream(s, NULL))) + return AVERROR(ENOMEM); + pkt = &st->attached_pic; + if (buf) { + av_assert1(*buf); + av_packet_unref(pkt); + pkt->buf = *buf; + pkt->data = (*buf)->data; + pkt->size = (*buf)->size - AV_INPUT_BUFFER_PADDING_SIZE; + *buf = NULL; + } else { + ret = av_get_packet(pb, pkt, size); + if (ret < 0) + goto fail; + } + st->disposition |= AV_DISPOSITION_ATTACHED_PIC; + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + + pkt->stream_index = st->index; + pkt->flags |= AV_PKT_FLAG_KEY; + + return 0; +fail: + if (!st0) + ff_remove_stream(s, st); + return ret; +} |