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

@ -26,6 +26,7 @@
#include "avformat.h"
#include "avio_internal.h"
#include "apetag.h"
#include "demux.h"
#include "internal.h"
#include "mux.h"

View File

@ -19,6 +19,7 @@
*/
#include "asf.h"
#include "demux.h"
#include "id3v2.h"
#include "internal.h"

View File

@ -187,4 +187,20 @@ void avpriv_stream_set_need_parsing(AVStream *st, enum AVStreamParseType type);
AVChapter *avpriv_new_chapter(AVFormatContext *s, int64_t id, AVRational time_base,
int64_t start, int64_t end, const char *title);
/**
* Add an attached pic to an AVStream.
*
* @param st if set, the stream to add the attached pic to;
* if unset, a new stream will be added to s.
* @param pb AVIOContext to read data from if buf is unset.
* @param buf if set, it contains the data and size information to be used
* for the attached pic; if unset, data is read from pb.
* @param size the size of the data to read if buf is unset.
*
* @return 0 on success, < 0 on error. On error, this function removes
* the stream it has added (if any).
*/
int ff_add_attached_pic(AVFormatContext *s, AVStream *st, AVIOContext *pb,
AVBufferRef **buf, int size);
#endif /* AVFORMAT_DEMUX_H */

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

View File

@ -23,6 +23,7 @@
#include "libavcodec/bytestream.h"
#include "libavcodec/png.h"
#include "avformat.h"
#include "demux.h"
#include "flac_picture.h"
#include "id3v2.h"
#include "internal.h"

View File

@ -598,22 +598,6 @@ int ff_add_param_change(AVPacket *pkt, int32_t channels,
*/
int ff_framehash_write_header(AVFormatContext *s);
/**
* Add an attached pic to an AVStream.
*
* @param st if set, the stream to add the attached pic to;
* if unset, a new stream will be added to s.
* @param pb AVIOContext to read data from if buf is unset.
* @param buf if set, it contains the data and size information to be used
* for the attached pic; if unset, data is read from pb.
* @param size the size of the data to read if buf is unset.
*
* @return 0 on success, < 0 on error. On error, this function removes
* the stream it has added (if any).
*/
int ff_add_attached_pic(AVFormatContext *s, AVStream *st, AVIOContext *pb,
AVBufferRef **buf, int size);
/**
* Frees a stream without modifying the corresponding AVFormatContext.
* Must only be called if the latter doesn't matter or if the stream

View File

@ -175,41 +175,6 @@ int av_filename_number_test(const char *filename)
(av_get_frame_filename(buf, sizeof(buf), filename, 1) >= 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;
}
/**********************************************************/
int ff_is_intra_only(enum AVCodecID id)