diff options
author | Andreas Rheinhardt <andreas.rheinhardt@outlook.com> | 2021-03-29 07:58:56 +0200 |
---|---|---|
committer | Andreas Rheinhardt <andreas.rheinhardt@outlook.com> | 2021-04-01 18:23:13 +0200 |
commit | 39ecb63d0f082ee3b2ac2ac65577170deb245ec4 (patch) | |
tree | dec03fe40d01b51e21929d00c3e45732163447a5 /libavformat/utils.c | |
parent | b7b73e83e3d5c78a5fea96a6bcae02e1f0a5c45f (diff) |
avformat: Add and use helper function to add attachment streams
All instances of adding attached pictures to a stream or adding
a stream and an attached packet to said stream have several things
in common like setting the index and flags of the packet, setting
the stream disposition etc. This commit therefore factors this out.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Diffstat (limited to 'libavformat/utils.c')
-rw-r--r-- | libavformat/utils.c | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/libavformat/utils.c b/libavformat/utils.c index 92695c3f2b..c2200d0403 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -474,6 +474,36 @@ int avformat_queue_attached_pictures(AVFormatContext *s) return 0; } +int ff_add_attached_pic(AVFormatContext *s, AVStream *st, AVIOContext *pb, + AVBufferRef **buf, int size) +{ + 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) + return ret; + } + 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; +} + static int update_stream_avctx(AVFormatContext *s) { int i, ret; |