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>
This commit is contained in:
Andreas Rheinhardt 2022-05-06 20:53:12 +02:00
parent 3c3c13e67b
commit 92a43ad384
7 changed files with 55 additions and 51 deletions

View file

@ -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;
}