avformat/bonk: add support for ID3 metadata

pull/388/head
Paul B Mahol 2 years ago
parent 5852682dbd
commit cc2b1a3251
  1. 34
      libavformat/bonk.c

@ -20,9 +20,11 @@
*/ */
#include "libavutil/intreadwrite.h" #include "libavutil/intreadwrite.h"
#include "avio_internal.h"
#include "avformat.h" #include "avformat.h"
#include "demux.h" #include "demux.h"
#include "internal.h" #include "internal.h"
#include "id3v2.h"
#include "rawdec.h" #include "rawdec.h"
static int bonk_probe(const AVProbeData *p) static int bonk_probe(const AVProbeData *p)
@ -45,8 +47,6 @@ static int bonk_probe(const AVProbeData *p)
if (AV_RL16(p->buf + i + 20) == 0) if (AV_RL16(p->buf + i + 20) == 0)
return 0; return 0;
return AVPROBE_SCORE_MAX; return AVPROBE_SCORE_MAX;
} else if (!p->buf[i]) {
break;
} }
} }
@ -55,15 +55,35 @@ static int bonk_probe(const AVProbeData *p)
static int bonk_read_header(AVFormatContext *s) static int bonk_read_header(AVFormatContext *s)
{ {
ID3v2ExtraMeta *extra_meta;
AVStream *st; AVStream *st;
int ret; int ret;
for (int i = 0; !avio_feof(s->pb); i++) { for (int i = 0; !avio_feof(s->pb); i++) {
int b = avio_r8(s->pb); const int b = avio_r8(s->pb);
if (!b && avio_rl32(s->pb) == MKTAG('B','O','N','K')) if (!b) {
break; uint32_t t;
else if (!b) int ret = ffio_ensure_seekback(s->pb, 3);
return AVERROR_INVALIDDATA;
if (ret < 0)
return ret;
t = avio_rl32(s->pb);
if (t == MKTAG('B','O','N','K')) {
break;
} else if (t == MKTAG(' ','I','D','3')) {
avio_seek(s->pb, -3, SEEK_CUR);
ff_id3v2_read(s, ID3v2_DEFAULT_MAGIC, &extra_meta, 0);
if (extra_meta) {
ff_id3v2_parse_apic(s, extra_meta);
ff_id3v2_parse_priv(s, extra_meta);
ff_id3v2_free_extra_meta(&extra_meta);
}
avio_skip(s->pb, 8);
} else {
return AVERROR_INVALIDDATA;
}
}
} }
st = avformat_new_stream(s, NULL); st = avformat_new_stream(s, NULL);

Loading…
Cancel
Save