static void read_apic(AVFormatContext *s, AVIOContext *pb, int taglen, char *tag, ID3v2ExtraMeta **extra_meta)

{

    int enc, pic_type;

    char             mimetype[64];

    const CodecMime     *mime = ff_id3v2_mime_tags;

    enum AVCodecID           id = AV_CODEC_ID_NONE;

    ID3v2ExtraMetaAPIC  *apic = NULL;

    ID3v2ExtraMeta *new_extra = NULL;

    int64_t               end = avio_tell(pb) + taglen;



    if (taglen <= 4)

        goto fail;



    new_extra = av_mallocz(sizeof(*new_extra));

    apic      = av_mallocz(sizeof(*apic));

    if (!new_extra || !apic)

        goto fail;



    enc = avio_r8(pb);

    taglen--;



    /* mimetype */

    taglen -= avio_get_str(pb, taglen, mimetype, sizeof(mimetype));

    while (mime->id != AV_CODEC_ID_NONE) {

        if (!av_strncasecmp(mime->str, mimetype, sizeof(mimetype))) {

            id = mime->id;

            break;

        }

        mime++;

    }

    if (id == AV_CODEC_ID_NONE) {

        av_log(s, AV_LOG_WARNING, "Unknown attached picture mimetype: %s, skipping.\n", mimetype);

        goto fail;

    }

    apic->id = id;



    /* picture type */

    pic_type = avio_r8(pb);

    taglen--;

    if (pic_type < 0 || pic_type >= FF_ARRAY_ELEMS(ff_id3v2_picture_types)) {

        av_log(s, AV_LOG_WARNING, "Unknown attached picture type %d.\n", pic_type);

        pic_type = 0;

    }

    apic->type = ff_id3v2_picture_types[pic_type];



    /* description and picture data */

    if (decode_str(s, pb, enc, &apic->description, &taglen) < 0) {

        av_log(s, AV_LOG_ERROR, "Error decoding attached picture description.\n");

        goto fail;

    }



    apic->buf = av_buffer_alloc(taglen);

    if (!apic->buf || !taglen || avio_read(pb, apic->buf->data, taglen) != taglen)

        goto fail;



    new_extra->tag    = "APIC";

    new_extra->data   = apic;

    new_extra->next   = *extra_meta;

    *extra_meta       = new_extra;



    return;



fail:

    if (apic)

        free_apic(apic);

    av_freep(&new_extra);

    avio_seek(pb, end, SEEK_SET);

}

static void read_apic(AVFormatContext *s, AVIOContext *pb, int taglen, char *tag, ID3v2ExtraMeta **extra_meta)

{

    int enc, pic_type;

    char             mimetype[64];

    const CodecMime     *mime = ff_id3v2_mime_tags;

    enum AVCodecID           id = AV_CODEC_ID_NONE;

    ID3v2ExtraMetaAPIC  *apic = NULL;

    ID3v2ExtraMeta *new_extra = NULL;

    int64_t               end = avio_tell(pb) + taglen;



    if (taglen <= 4)

        goto fail;



    new_extra = av_mallocz(sizeof(*new_extra));

    apic      = av_mallocz(sizeof(*apic));

    if (!new_extra || !apic)

        goto fail;



    enc = avio_r8(pb);

    taglen--;



    

    taglen -= avio_get_str(pb, taglen, mimetype, sizeof(mimetype));

    while (mime->id != AV_CODEC_ID_NONE) {

        if (!av_strncasecmp(mime->str, mimetype, sizeof(mimetype))) {

            id = mime->id;

            break;

        }

        mime++;

    }

    if (id == AV_CODEC_ID_NONE) {

        av_log(s, AV_LOG_WARNING, "Unknown attached picture mimetype: %s, skipping.\n", mimetype);

        goto fail;

    }

    apic->id = id;



    

    pic_type = avio_r8(pb);

    taglen--;

    if (pic_type < 0 || pic_type >= FF_ARRAY_ELEMS(ff_id3v2_picture_types)) {

        av_log(s, AV_LOG_WARNING, "Unknown attached picture type %d.\n", pic_type);

        pic_type = 0;

    }

    apic->type = ff_id3v2_picture_types[pic_type];



    

    if (decode_str(s, pb, enc, &apic->description, &taglen) < 0) {

        av_log(s, AV_LOG_ERROR, "Error decoding attached picture description.\n");

        goto fail;

    }



    apic->buf = av_buffer_alloc(taglen);

    if (!apic->buf || !taglen || avio_read(pb, apic->buf->data, taglen) != taglen)

        goto fail;



    new_extra->tag    = "APIC";

    new_extra->data   = apic;

    new_extra->next   = *extra_meta;

    *extra_meta       = new_extra;



    return;



fail:

    if (apic)

        free_apic(apic);

    av_freep(&new_extra);

    avio_seek(pb, end, SEEK_SET);

}

    apic->buf = av_buffer_alloc(taglen);
static void FUNC_0(AVFormatContext *VAR_0, AVIOContext *VAR_1, int VAR_2, char *VAR_3, ID3v2ExtraMeta **VAR_4)

{

    int VAR_5, VAR_6;

    char             VAR_7[64];

    const CodecMime     *VAR_8 = ff_id3v2_mime_tags;

    enum AVCodecID           VAR_9 = AV_CODEC_ID_NONE;

    ID3v2ExtraMetaAPIC  *apic = NULL;

    ID3v2ExtraMeta *new_extra = NULL;

    int64_t               end = avio_tell(VAR_1) + VAR_2;



    if (VAR_2 <= 4)

        goto fail;



    new_extra = av_mallocz(sizeof(*new_extra));

    apic      = av_mallocz(sizeof(*apic));

    if (!new_extra || !apic)

        goto fail;



    VAR_5 = avio_r8(VAR_1);

    VAR_2--;



    

    VAR_2 -= avio_get_str(VAR_1, VAR_2, VAR_7, sizeof(VAR_7));

    while (VAR_8->VAR_9 != AV_CODEC_ID_NONE) {

        if (!av_strncasecmp(VAR_8->str, VAR_7, sizeof(VAR_7))) {

            VAR_9 = VAR_8->VAR_9;

            break;

        }

        VAR_8++;

    }

    if (VAR_9 == AV_CODEC_ID_NONE) {

        av_log(VAR_0, AV_LOG_WARNING, "Unknown attached picture VAR_7: %VAR_0, skipping.\n", VAR_7);

        goto fail;

    }

    apic->VAR_9 = VAR_9;



    

    VAR_6 = avio_r8(VAR_1);

    VAR_2--;

    if (VAR_6 < 0 || VAR_6 >= FF_ARRAY_ELEMS(ff_id3v2_picture_types)) {

        av_log(VAR_0, AV_LOG_WARNING, "Unknown attached picture type %d.\n", VAR_6);

        VAR_6 = 0;

    }

    apic->type = ff_id3v2_picture_types[VAR_6];



    

    if (decode_str(VAR_0, VAR_1, VAR_5, &apic->description, &VAR_2) < 0) {

        av_log(VAR_0, AV_LOG_ERROR, "Error decoding attached picture description.\n");

        goto fail;

    }



    apic->buf = av_buffer_alloc(VAR_2);

    if (!apic->buf || !VAR_2 || avio_read(VAR_1, apic->buf->data, VAR_2) != VAR_2)

        goto fail;



    new_extra->VAR_3    = "APIC";

    new_extra->data   = apic;

    new_extra->next   = *VAR_4;

    *VAR_4       = new_extra;



    return;



fail:

    if (apic)

        free_apic(apic);

    av_freep(&new_extra);

    avio_seek(VAR_1, end, SEEK_SET);

}

static void FUNC_0(AVFormatContext *VAR_0, AVIOContext *VAR_1, int VAR_2, char *VAR_3, ID3v2ExtraMeta **VAR_4)
{ int VAR_5, VAR_6; char             VAR_7[64]; const CodecMime     *VAR_8 = ff_id3v2_mime_tags; enum AVCodecID           VAR_9 = AV_CODEC_ID_NONE; ID3v2ExtraMetaAPIC  *apic = NULL; ID3v2ExtraMeta *new_extra = NULL; int64_t               end = avio_tell(VAR_1) + VAR_2; if (VAR_2 <= 4)
goto fail; new_extra = av_mallocz(sizeof(*new_extra)); apic      = av_mallocz(sizeof(*apic)); if (!new_extra || !apic)
goto fail; VAR_5 = avio_r8(VAR_1); VAR_2--; VAR_2 -= avio_get_str(VAR_1, VAR_2, VAR_7, sizeof(VAR_7)); while (VAR_8->VAR_9 != AV_CODEC_ID_NONE) { if (!av_strncasecmp(VAR_8->str, VAR_7, sizeof(VAR_7))) { VAR_9 = VAR_8->VAR_9; break; } VAR_8++; } if (VAR_9 == AV_CODEC_ID_NONE) { av_log(VAR_0, AV_LOG_WARNING, "Unknown attached picture VAR_7: %VAR_0, skipping.\n", VAR_7); goto fail; } apic->VAR_9 = VAR_9; VAR_6 = avio_r8(VAR_1); VAR_2--; if (VAR_6 < 0 || VAR_6 >= FF_ARRAY_ELEMS(ff_id3v2_picture_types)) { av_log(VAR_0, AV_LOG_WARNING, "Unknown attached picture type %d.\n", VAR_6); VAR_6 = 0; } apic->type = ff_id3v2_picture_types[VAR_6]; if (decode_str(VAR_0, VAR_1, VAR_5, &apic->description, &VAR_2) < 0) { av_log(VAR_0, AV_LOG_ERROR, "Error decoding attached picture description.\n"); goto fail; } apic->buf = av_buffer_alloc(VAR_2); if (!apic->buf || !VAR_2 || avio_read(VAR_1, apic->buf->data, VAR_2) != VAR_2)
goto fail; new_extra->VAR_3    = "APIC"; new_extra->data   = apic; new_extra->next   = *VAR_4; *VAR_4       = new_extra; return; fail:
if (apic)
free_apic(apic); av_freep(&new_extra); avio_seek(VAR_1, end, SEEK_SET); }