Commit e9c37236 authored by Michael Niedermayer's avatar Michael Niedermayer

id3v2: restructure compressed and unsync code

This should fix the interaction between the 2.
Signed-off-by: 's avatarMichael Niedermayer <michaelni@gmx.at>
parent 0560b28f
...@@ -584,8 +584,8 @@ static void ff_id3v2_parse(AVFormatContext *s, int len, uint8_t version, uint8_t ...@@ -584,8 +584,8 @@ static void ff_id3v2_parse(AVFormatContext *s, int len, uint8_t version, uint8_t
unsigned char *buffer = NULL; unsigned char *buffer = NULL;
int buffer_size = 0; int buffer_size = 0;
const ID3v2EMFunc *extra_func = NULL; const ID3v2EMFunc *extra_func = NULL;
unsigned char *compressed_buffer = NULL; unsigned char *uncompressed_buffer = NULL;
int compressed_buffer_size = 0; int uncompressed_buffer_size = 0;
av_log(s, AV_LOG_DEBUG, "id3v2 ver:%d flags:%02X len:%d\n", version, flags, len); av_log(s, AV_LOG_DEBUG, "id3v2 ver:%d flags:%02X len:%d\n", version, flags, len);
...@@ -690,61 +690,63 @@ static void ff_id3v2_parse(AVFormatContext *s, int len, uint8_t version, uint8_t ...@@ -690,61 +690,63 @@ static void ff_id3v2_parse(AVFormatContext *s, int len, uint8_t version, uint8_t
avio_skip(s->pb, tlen); avio_skip(s->pb, tlen);
/* check for text tag or supported special meta tag */ /* check for text tag or supported special meta tag */
} else if (tag[0] == 'T' || (extra_meta && (extra_func = get_extra_meta_func(tag, isv34)))) { } else if (tag[0] == 'T' || (extra_meta && (extra_func = get_extra_meta_func(tag, isv34)))) {
if (unsync || tunsync || tcomp) { pbx = s->pb;
int64_t end = avio_tell(s->pb) + tlen;
uint8_t *b;
av_fast_malloc(&buffer, &buffer_size, dlen); if (unsync || tunsync || tcomp) {
av_fast_malloc(&buffer, &buffer_size, tlen);
if (!buffer) { if (!buffer) {
av_log(s, AV_LOG_ERROR, "Failed to alloc %ld bytes\n", dlen); av_log(s, AV_LOG_ERROR, "Failed to alloc %d bytes\n", tlen);
goto seek; goto seek;
} }
}
if (unsync || tunsync) {
int64_t end = avio_tell(s->pb) + tlen;
uint8_t *b;
b = buffer; b = buffer;
while (avio_tell(s->pb) < end) {
*b++ = avio_r8(s->pb);
if (*(b - 1) == 0xff && avio_tell(s->pb) < end - 1) {
uint8_t val = avio_r8(s->pb);
*b++ = val ? val : avio_r8(s->pb);
}
}
ffio_init_context(&pb, buffer, b - buffer, 0, NULL, NULL, NULL, NULL);
tlen = b - buffer;
pbx = &pb; // read from sync buffer
}
#if CONFIG_ZLIB #if CONFIG_ZLIB
if (tcomp) { if (tcomp) {
int n, err; int err;
av_log(s, AV_LOG_DEBUG, "Compresssed frame %s tlen=%d dlen=%ld\n", tag, tlen, dlen); av_log(s, AV_LOG_DEBUG, "Compresssed frame %s tlen=%d dlen=%ld\n", tag, tlen, dlen);
av_fast_malloc(&compressed_buffer, &compressed_buffer_size, tlen); av_fast_malloc(&uncompressed_buffer, &uncompressed_buffer_size, dlen);
if (!compressed_buffer) { if (!uncompressed_buffer) {
av_log(s, AV_LOG_ERROR, "Failed to alloc %d bytes\n", tlen); av_log(s, AV_LOG_ERROR, "Failed to alloc %ld bytes\n", dlen);
goto seek; goto seek;
} }
n = avio_read(s->pb, compressed_buffer, tlen); if (!(unsync || tunsync)) {
if (n < 0) { err = avio_read(s->pb, buffer, tlen);
av_log(s, AV_LOG_ERROR, "Failed to read compressed tag\n"); if (err < 0) {
goto seek; av_log(s, AV_LOG_ERROR, "Failed to read compressed tag\n");
goto seek;
}
tlen = err;
} }
err = uncompress(buffer, &dlen, compressed_buffer, n); err = uncompress(uncompressed_buffer, &dlen, buffer, tlen);
if (err != Z_OK) { if (err != Z_OK) {
av_log(s, AV_LOG_ERROR, "Failed to uncompress tag: %d\n", err); av_log(s, AV_LOG_ERROR, "Failed to uncompress tag: %d\n", err);
goto seek; goto seek;
} }
b += dlen; ffio_init_context(&pb, uncompressed_buffer, dlen, 0, NULL, NULL, NULL, NULL);
tlen = dlen;
pbx = &pb; // read from sync buffer
} }
#endif #endif
if (unsync || tunsync) {
if (tcomp) {
av_log_ask_for_sample(s, "tcomp with unsync\n");
goto seek;
}
while (avio_tell(s->pb) < end) {
*b++ = avio_r8(s->pb);
if (*(b - 1) == 0xff && avio_tell(s->pb) < end - 1) {
uint8_t val = avio_r8(s->pb);
*b++ = val ? val : avio_r8(s->pb);
}
}
}
ffio_init_context(&pb, buffer, b - buffer, 0, NULL, NULL, NULL, NULL);
tlen = b - buffer;
pbx = &pb; // read from sync buffer
} else {
pbx = s->pb; // read straight from input
}
if (tag[0] == 'T') if (tag[0] == 'T')
/* parse text tag */ /* parse text tag */
read_ttag(s, pbx, tlen, tag); read_ttag(s, pbx, tlen, tag);
...@@ -771,7 +773,7 @@ seek: ...@@ -771,7 +773,7 @@ seek:
av_log(s, AV_LOG_INFO, "ID3v2.%d tag skipped, cannot handle %s\n", version, reason); av_log(s, AV_LOG_INFO, "ID3v2.%d tag skipped, cannot handle %s\n", version, reason);
avio_seek(s->pb, end, SEEK_SET); avio_seek(s->pb, end, SEEK_SET);
av_free(buffer); av_free(buffer);
av_free(compressed_buffer); av_free(uncompressed_buffer);
return; return;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment