diff options
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; +} |