static void ff_id3v2_parse(AVFormatContext *s, int len, uint8_t version, uint8_t flags)

{

    int isv34, tlen, unsync;

    char tag[5];

    int64_t next, end = avio_tell(s->pb) + len;

    int taghdrlen;

    const char *reason = NULL;

    AVIOContext pb;

    unsigned char *buffer = NULL;

    int buffer_size = 0;



    switch (version) {

    case 2:

        if (flags & 0x40) {

            reason = "compression";

            goto error;

        }

        isv34 = 0;

        taghdrlen = 6;

        break;



    case 3:

    case 4:

        isv34 = 1;

        taghdrlen = 10;

        break;



    default:

        reason = "version";

        goto error;

    }



    unsync = flags & 0x80;



    if (isv34 && flags & 0x40) /* Extended header present, just skip over it */

        avio_skip(s->pb, get_size(s->pb, 4));



    while (len >= taghdrlen) {

        unsigned int tflags;

        int tunsync = 0;



        if (isv34) {

            avio_read(s->pb, tag, 4);

            tag[4] = 0;

            if(version==3){

                tlen = avio_rb32(s->pb);

            }else

                tlen = get_size(s->pb, 4);

            tflags = avio_rb16(s->pb);

            tunsync = tflags & ID3v2_FLAG_UNSYNCH;

        } else {

            avio_read(s->pb, tag, 3);

            tag[3] = 0;

            tlen = avio_rb24(s->pb);

        }

        len -= taghdrlen + tlen;



        if (len < 0)

            break;



        next = avio_tell(s->pb) + tlen;



        if (tflags & ID3v2_FLAG_DATALEN) {

            avio_rb32(s->pb);

            tlen -= 4;

        }



        if (tflags & (ID3v2_FLAG_ENCRYPTION | ID3v2_FLAG_COMPRESSION)) {

            av_log(s, AV_LOG_WARNING, "Skipping encrypted/compressed ID3v2 frame %s.\n", tag);

            avio_skip(s->pb, tlen);

        } else if (tag[0] == 'T') {

            if (unsync || tunsync) {

                int i, j;

                av_fast_malloc(&buffer, &buffer_size, tlen);

                for (i = 0, j = 0; i < tlen; i++, j++) {

                    buffer[j] = avio_r8(s->pb);

                    if (j > 0 && !buffer[j] && buffer[j - 1] == 0xff) {

                        /* Unsynchronised byte, skip it */

                        j--;

                    }

                }

                ffio_init_context(&pb, buffer, j, 0, NULL, NULL, NULL, NULL);

                read_ttag(s, &pb, j, tag);

            } else {

                read_ttag(s, s->pb, tlen, tag);

            }

        }

        else if (!tag[0]) {

            if (tag[1])

                av_log(s, AV_LOG_WARNING, "invalid frame id, assuming padding");

            avio_skip(s->pb, tlen);

            break;

        }

        /* Skip to end of tag */

        avio_seek(s->pb, next, SEEK_SET);

    }



    if (version == 4 && flags & 0x10) /* Footer preset, always 10 bytes, skip over it */

        end += 10;



  error:

    if (reason)

        av_log(s, AV_LOG_INFO, "ID3v2.%d tag skipped, cannot handle %s\n", version, reason);

    avio_seek(s->pb, end, SEEK_SET);

    av_free(buffer);

    return;

}

static void ff_id3v2_parse(AVFormatContext *s, int len, uint8_t version, uint8_t flags)

{

    int isv34, tlen, unsync;

    char tag[5];

    int64_t next, end = avio_tell(s->pb) + len;

    int taghdrlen;

    const char *reason = NULL;

    AVIOContext pb;

    unsigned char *buffer = NULL;

    int buffer_size = 0;



    switch (version) {

    case 2:

        if (flags & 0x40) {

            reason = "compression";

            goto error;

        }

        isv34 = 0;

        taghdrlen = 6;

        break;



    case 3:

    case 4:

        isv34 = 1;

        taghdrlen = 10;

        break;



    default:

        reason = "version";

        goto error;

    }



    unsync = flags & 0x80;



    if (isv34 && flags & 0x40) 

        avio_skip(s->pb, get_size(s->pb, 4));



    while (len >= taghdrlen) {

        unsigned int tflags;

        int tunsync = 0;



        if (isv34) {

            avio_read(s->pb, tag, 4);

            tag[4] = 0;

            if(version==3){

                tlen = avio_rb32(s->pb);

            }else

                tlen = get_size(s->pb, 4);

            tflags = avio_rb16(s->pb);

            tunsync = tflags & ID3v2_FLAG_UNSYNCH;

        } else {

            avio_read(s->pb, tag, 3);

            tag[3] = 0;

            tlen = avio_rb24(s->pb);

        }

        len -= taghdrlen + tlen;



        if (len < 0)

            break;



        next = avio_tell(s->pb) + tlen;



        if (tflags & ID3v2_FLAG_DATALEN) {

            avio_rb32(s->pb);

            tlen -= 4;

        }



        if (tflags & (ID3v2_FLAG_ENCRYPTION | ID3v2_FLAG_COMPRESSION)) {

            av_log(s, AV_LOG_WARNING, "Skipping encrypted/compressed ID3v2 frame %s.\n", tag);

            avio_skip(s->pb, tlen);

        } else if (tag[0] == 'T') {

            if (unsync || tunsync) {

                int i, j;

                av_fast_malloc(&buffer, &buffer_size, tlen);

                for (i = 0, j = 0; i < tlen; i++, j++) {

                    buffer[j] = avio_r8(s->pb);

                    if (j > 0 && !buffer[j] && buffer[j - 1] == 0xff) {

                        

                        j--;

                    }

                }

                ffio_init_context(&pb, buffer, j, 0, NULL, NULL, NULL, NULL);

                read_ttag(s, &pb, j, tag);

            } else {

                read_ttag(s, s->pb, tlen, tag);

            }

        }

        else if (!tag[0]) {

            if (tag[1])

                av_log(s, AV_LOG_WARNING, "invalid frame id, assuming padding");

            avio_skip(s->pb, tlen);

            break;

        }

        

        avio_seek(s->pb, next, SEEK_SET);

    }



    if (version == 4 && flags & 0x10) 

        end += 10;



  error:

    if (reason)

        av_log(s, AV_LOG_INFO, "ID3v2.%d tag skipped, cannot handle %s\n", version, reason);

    avio_seek(s->pb, end, SEEK_SET);

    av_free(buffer);

    return;

}

static void FUNC_0(AVFormatContext *VAR_0, int VAR_1, uint8_t VAR_2, uint8_t VAR_3)

{

    int VAR_4, VAR_5, VAR_6;

    char VAR_7[5];

    int64_t next, end = avio_tell(VAR_0->pb) + VAR_1;

    int VAR_8;

    const char *VAR_9 = NULL;

    AVIOContext pb;

    unsigned char *VAR_10 = NULL;

    int VAR_11 = 0;



    switch (VAR_2) {

    case 2:

        if (VAR_3 & 0x40) {

            VAR_9 = "compression";

            goto error;

        }

        VAR_4 = 0;

        VAR_8 = 6;

        break;



    case 3:

    case 4:

        VAR_4 = 1;

        VAR_8 = 10;

        break;



    default:

        VAR_9 = "VAR_2";

        goto error;

    }



    VAR_6 = VAR_3 & 0x80;



    if (VAR_4 && VAR_3 & 0x40) 

        avio_skip(VAR_0->pb, get_size(VAR_0->pb, 4));



    while (VAR_1 >= VAR_8) {

        unsigned int VAR_12;

        int VAR_13 = 0;



        if (VAR_4) {

            avio_read(VAR_0->pb, VAR_7, 4);

            VAR_7[4] = 0;

            if(VAR_2==3){

                VAR_5 = avio_rb32(VAR_0->pb);

            }else

                VAR_5 = get_size(VAR_0->pb, 4);

            VAR_12 = avio_rb16(VAR_0->pb);

            VAR_13 = VAR_12 & ID3v2_FLAG_UNSYNCH;

        } else {

            avio_read(VAR_0->pb, VAR_7, 3);

            VAR_7[3] = 0;

            VAR_5 = avio_rb24(VAR_0->pb);

        }

        VAR_1 -= VAR_8 + VAR_5;



        if (VAR_1 < 0)

            break;



        next = avio_tell(VAR_0->pb) + VAR_5;



        if (VAR_12 & ID3v2_FLAG_DATALEN) {

            avio_rb32(VAR_0->pb);

            VAR_5 -= 4;

        }



        if (VAR_12 & (ID3v2_FLAG_ENCRYPTION | ID3v2_FLAG_COMPRESSION)) {

            av_log(VAR_0, AV_LOG_WARNING, "Skipping encrypted/compressed ID3v2 frame %VAR_0.\n", VAR_7);

            avio_skip(VAR_0->pb, VAR_5);

        } else if (VAR_7[0] == 'T') {

            if (VAR_6 || VAR_13) {

                int VAR_14, VAR_15;

                av_fast_malloc(&VAR_10, &VAR_11, VAR_5);

                for (VAR_14 = 0, VAR_15 = 0; VAR_14 < VAR_5; VAR_14++, VAR_15++) {

                    VAR_10[VAR_15] = avio_r8(VAR_0->pb);

                    if (VAR_15 > 0 && !VAR_10[VAR_15] && VAR_10[VAR_15 - 1] == 0xff) {

                        

                        VAR_15--;

                    }

                }

                ffio_init_context(&pb, VAR_10, VAR_15, 0, NULL, NULL, NULL, NULL);

                read_ttag(VAR_0, &pb, VAR_15, VAR_7);

            } else {

                read_ttag(VAR_0, VAR_0->pb, VAR_5, VAR_7);

            }

        }

        else if (!VAR_7[0]) {

            if (VAR_7[1])

                av_log(VAR_0, AV_LOG_WARNING, "invalid frame id, assuming padding");

            avio_skip(VAR_0->pb, VAR_5);

            break;

        }

        

        avio_seek(VAR_0->pb, next, SEEK_SET);

    }



    if (VAR_2 == 4 && VAR_3 & 0x10) 

        end += 10;



  error:

    if (VAR_9)

        av_log(VAR_0, AV_LOG_INFO, "ID3v2.%d VAR_7 skipped, cannot handle %VAR_0\n", VAR_2, VAR_9);

    avio_seek(VAR_0->pb, end, SEEK_SET);

    av_free(VAR_10);

    return;

}

static void FUNC_0(AVFormatContext *VAR_0, int VAR_1, uint8_t VAR_2, uint8_t VAR_3)
{ int VAR_4, VAR_5, VAR_6; char VAR_7[5]; int64_t next, end = avio_tell(VAR_0->pb) + VAR_1; int VAR_8; const char *VAR_9 = NULL; AVIOContext pb; unsigned char *VAR_10 = NULL; int VAR_11 = 0; switch (VAR_2) { case 2:
if (VAR_3 & 0x40) { VAR_9 = "compression"; goto error; } VAR_4 = 0; VAR_8 = 6; break; case 3:
case 4:
VAR_4 = 1; VAR_8 = 10; break; default:
VAR_9 = "VAR_2"; goto error; } VAR_6 = VAR_3 & 0x80; if (VAR_4 && VAR_3 & 0x40)
avio_skip(VAR_0->pb, get_size(VAR_0->pb, 4)); while (VAR_1 >= VAR_8) { unsigned int VAR_12; int VAR_13 = 0; if (VAR_4) { avio_read(VAR_0->pb, VAR_7, 4); VAR_7[4] = 0; if(VAR_2==3){ VAR_5 = avio_rb32(VAR_0->pb); }else VAR_5 = get_size(VAR_0->pb, 4); VAR_12 = avio_rb16(VAR_0->pb); VAR_13 = VAR_12 & ID3v2_FLAG_UNSYNCH; } else { avio_read(VAR_0->pb, VAR_7, 3); VAR_7[3] = 0; VAR_5 = avio_rb24(VAR_0->pb); } VAR_1 -= VAR_8 + VAR_5; if (VAR_1 < 0)
break; next = avio_tell(VAR_0->pb) + VAR_5; if (VAR_12 & ID3v2_FLAG_DATALEN) { avio_rb32(VAR_0->pb); VAR_5 -= 4; } if (VAR_12 & (ID3v2_FLAG_ENCRYPTION | ID3v2_FLAG_COMPRESSION)) { av_log(VAR_0, AV_LOG_WARNING, "Skipping encrypted/compressed ID3v2 frame %VAR_0.\n", VAR_7); avio_skip(VAR_0->pb, VAR_5); } else if (VAR_7[0] == 'T') { if (VAR_6 || VAR_13) { int VAR_14, VAR_15; av_fast_malloc(&VAR_10, &VAR_11, VAR_5); for (VAR_14 = 0, VAR_15 = 0; VAR_14 < VAR_5; VAR_14++, VAR_15++) { VAR_10[VAR_15] = avio_r8(VAR_0->pb); if (VAR_15 > 0 && !VAR_10[VAR_15] && VAR_10[VAR_15 - 1] == 0xff) { VAR_15--; } } ffio_init_context(&pb, VAR_10, VAR_15, 0, NULL, NULL, NULL, NULL); read_ttag(VAR_0, &pb, VAR_15, VAR_7); } else { read_ttag(VAR_0, VAR_0->pb, VAR_5, VAR_7); } } else if (!VAR_7[0]) { if (VAR_7[1])
av_log(VAR_0, AV_LOG_WARNING, "invalid frame id, assuming padding"); avio_skip(VAR_0->pb, VAR_5); break; } avio_seek(VAR_0->pb, next, SEEK_SET); } if (VAR_2 == 4 && VAR_3 & 0x10)
end += 10; error:
if (VAR_9)
av_log(VAR_0, AV_LOG_INFO, "ID3v2.%d VAR_7 skipped, cannot handle %VAR_0\n", VAR_2, VAR_9); avio_seek(VAR_0->pb, end, SEEK_SET); av_free(VAR_10); return; }