summaryrefslogtreecommitdiff
path: root/libavformat/id3v2.c
diff options
context:
space:
mode:
authorAndreas Rheinhardt <andreas.rheinhardt@outlook.com>2021-03-29 07:58:56 +0200
committerAndreas Rheinhardt <andreas.rheinhardt@outlook.com>2021-04-01 18:23:13 +0200
commit39ecb63d0f082ee3b2ac2ac65577170deb245ec4 (patch)
treedec03fe40d01b51e21929d00c3e45732163447a5 /libavformat/id3v2.c
parentb7b73e83e3d5c78a5fea96a6bcae02e1f0a5c45f (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/id3v2.c')
-rw-r--r--libavformat/id3v2.c21
1 files changed, 6 insertions, 15 deletions
diff --git a/libavformat/id3v2.c b/libavformat/id3v2.c
index f33b7ba93a..863709abbf 100644
--- a/libavformat/id3v2.c
+++ b/libavformat/id3v2.c
@@ -1142,34 +1142,25 @@ int ff_id3v2_parse_apic(AVFormatContext *s, ID3v2ExtraMeta *extra_meta)
for (cur = extra_meta; cur; cur = cur->next) {
ID3v2ExtraMetaAPIC *apic;
AVStream *st;
+ int ret;
if (strcmp(cur->tag, "APIC"))
continue;
apic = &cur->data.apic;
- if (!(st = avformat_new_stream(s, NULL)))
- return AVERROR(ENOMEM);
-
- st->disposition |= AV_DISPOSITION_ATTACHED_PIC;
- st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
+ ret = ff_add_attached_pic(s, NULL, NULL, &apic->buf, 0);
+ if (ret < 0)
+ return ret;
+ st = s->streams[s->nb_streams - 1];
st->codecpar->codec_id = apic->id;
- if (AV_RB64(apic->buf->data) == PNGSIG)
+ if (AV_RB64(st->attached_pic.data) == PNGSIG)
st->codecpar->codec_id = AV_CODEC_ID_PNG;
if (apic->description[0])
av_dict_set(&st->metadata, "title", apic->description, 0);
av_dict_set(&st->metadata, "comment", apic->type, 0);
-
- av_packet_unref(&st->attached_pic);
- st->attached_pic.buf = apic->buf;
- st->attached_pic.data = apic->buf->data;
- st->attached_pic.size = apic->buf->size - AV_INPUT_BUFFER_PADDING_SIZE;
- st->attached_pic.stream_index = st->index;
- st->attached_pic.flags |= AV_PKT_FLAG_KEY;
-
- apic->buf = NULL;
}
return 0;