static int asf_read_picture(AVFormatContext *s, int len)

{

    ASFContext *asf       = s->priv_data;

    AVPacket pkt          = { 0 };

    const CodecMime *mime = ff_id3v2_mime_tags;

    enum  AVCodecID id    = AV_CODEC_ID_NONE;

    char mimetype[64];

    uint8_t  *desc = NULL;

    AVStream   *st = NULL;

    int ret, type, picsize, desc_len;

    ASFStream *asf_st;



    /* type + picsize + mime + desc */

    if (len < 1 + 4 + 2 + 2) {

        av_log(s, AV_LOG_ERROR, "Invalid attached picture size: %d.\n", len);

        return AVERROR_INVALIDDATA;

    }



    /* picture type */

    type = avio_r8(s->pb);

    len--;

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

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

        type = 0;

    }



    /* picture data size */

    picsize = avio_rl32(s->pb);

    len    -= 4;



    /* picture MIME type */

    len -= avio_get_str16le(s->pb, len, mimetype, sizeof(mimetype));

    while (mime->id != AV_CODEC_ID_NONE) {

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

            id = mime->id;

            break;

        }

        mime++;

    }

    if (id == AV_CODEC_ID_NONE) {

        av_log(s, AV_LOG_ERROR, "Unknown attached picture mimetype: %s.\n",

               mimetype);

        return 0;

    }



    if (picsize >= len) {

        av_log(s, AV_LOG_ERROR, "Invalid attached picture data size: %d >= %d.\n",

               picsize, len);

        return AVERROR_INVALIDDATA;

    }



    /* picture description */

    desc_len = (len - picsize) * 2 + 1;

    desc     = av_malloc(desc_len);

    if (!desc)

        return AVERROR(ENOMEM);

    len -= avio_get_str16le(s->pb, len - picsize, desc, desc_len);



    ret = av_get_packet(s->pb, &pkt, picsize);

    if (ret < 0)

        goto fail;



    st  = avformat_new_stream(s, NULL);

    if (!st) {

        ret = AVERROR(ENOMEM);

        goto fail;

    }

    asf->asf_st[asf->nb_streams] = av_mallocz(sizeof(*asf_st));

    asf_st = asf->asf_st[asf->nb_streams];

    if (!asf_st)

        return AVERROR(ENOMEM);



    st->disposition              |= AV_DISPOSITION_ATTACHED_PIC;

    st->codec->codec_type         = asf_st->type = AVMEDIA_TYPE_VIDEO;

    st->codec->codec_id           = id;

    st->attached_pic              = pkt;

    st->attached_pic.stream_index = asf_st->index = st->index;

    st->attached_pic.flags       |= AV_PKT_FLAG_KEY;



    asf->nb_streams++;



    if (*desc) {

        if (av_dict_set(&st->metadata, "title", desc, AV_DICT_DONT_STRDUP_VAL) < 0)

            av_log(s, AV_LOG_WARNING, "av_dict_set failed.\n");

    } else

        av_freep(&desc);



    if (av_dict_set(&st->metadata, "comment", ff_id3v2_picture_types[type], 0) < 0)

        av_log(s, AV_LOG_WARNING, "av_dict_set failed.\n");



    return 0;



fail:

    av_freep(&desc);

    av_free_packet(&pkt);

    return ret;

}

static int asf_read_picture(AVFormatContext *s, int len)

{

    ASFContext *asf       = s->priv_data;

    AVPacket pkt          = { 0 };

    const CodecMime *mime = ff_id3v2_mime_tags;

    enum  AVCodecID id    = AV_CODEC_ID_NONE;

    char mimetype[64];

    uint8_t  *desc = NULL;

    AVStream   *st = NULL;

    int ret, type, picsize, desc_len;

    ASFStream *asf_st;



    

    if (len < 1 + 4 + 2 + 2) {

        av_log(s, AV_LOG_ERROR, "Invalid attached picture size: %d.\n", len);

        return AVERROR_INVALIDDATA;

    }



    

    type = avio_r8(s->pb);

    len--;

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

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

        type = 0;

    }



    

    picsize = avio_rl32(s->pb);

    len    -= 4;



    

    len -= avio_get_str16le(s->pb, len, mimetype, sizeof(mimetype));

    while (mime->id != AV_CODEC_ID_NONE) {

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

            id = mime->id;

            break;

        }

        mime++;

    }

    if (id == AV_CODEC_ID_NONE) {

        av_log(s, AV_LOG_ERROR, "Unknown attached picture mimetype: %s.\n",

               mimetype);

        return 0;

    }



    if (picsize >= len) {

        av_log(s, AV_LOG_ERROR, "Invalid attached picture data size: %d >= %d.\n",

               picsize, len);

        return AVERROR_INVALIDDATA;

    }



    

    desc_len = (len - picsize) * 2 + 1;

    desc     = av_malloc(desc_len);

    if (!desc)

        return AVERROR(ENOMEM);

    len -= avio_get_str16le(s->pb, len - picsize, desc, desc_len);



    ret = av_get_packet(s->pb, &pkt, picsize);

    if (ret < 0)

        goto fail;



    st  = avformat_new_stream(s, NULL);

    if (!st) {

        ret = AVERROR(ENOMEM);

        goto fail;

    }

    asf->asf_st[asf->nb_streams] = av_mallocz(sizeof(*asf_st));

    asf_st = asf->asf_st[asf->nb_streams];

    if (!asf_st)

        return AVERROR(ENOMEM);



    st->disposition              |= AV_DISPOSITION_ATTACHED_PIC;

    st->codec->codec_type         = asf_st->type = AVMEDIA_TYPE_VIDEO;

    st->codec->codec_id           = id;

    st->attached_pic              = pkt;

    st->attached_pic.stream_index = asf_st->index = st->index;

    st->attached_pic.flags       |= AV_PKT_FLAG_KEY;



    asf->nb_streams++;



    if (*desc) {

        if (av_dict_set(&st->metadata, "title", desc, AV_DICT_DONT_STRDUP_VAL) < 0)

            av_log(s, AV_LOG_WARNING, "av_dict_set failed.\n");

    } else

        av_freep(&desc);



    if (av_dict_set(&st->metadata, "comment", ff_id3v2_picture_types[type], 0) < 0)

        av_log(s, AV_LOG_WARNING, "av_dict_set failed.\n");



    return 0;



fail:

    av_freep(&desc);

    av_free_packet(&pkt);

    return ret;

}

    if (!asf_st)         return AVERROR(ENOMEM);
static int FUNC_0(AVFormatContext *VAR_0, int VAR_1)

{

    ASFContext *asf       = VAR_0->priv_data;

    AVPacket pkt          = { 0 };

    const CodecMime *VAR_2 = ff_id3v2_mime_tags;

    enum  AVCodecID VAR_3    = AV_CODEC_ID_NONE;

    char VAR_4[64];

    uint8_t  *desc = NULL;

    AVStream   *st = NULL;

    int VAR_5, VAR_6, VAR_7, VAR_8;

    ASFStream *asf_st;



    

    if (VAR_1 < 1 + 4 + 2 + 2) {

        av_log(VAR_0, AV_LOG_ERROR, "Invalid attached picture size: %d.\n", VAR_1);

        return AVERROR_INVALIDDATA;

    }



    

    VAR_6 = avio_r8(VAR_0->pb);

    VAR_1--;

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

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

        VAR_6 = 0;

    }



    

    VAR_7 = avio_rl32(VAR_0->pb);

    VAR_1    -= 4;



    

    VAR_1 -= avio_get_str16le(VAR_0->pb, VAR_1, VAR_4, sizeof(VAR_4));

    while (VAR_2->VAR_3 != AV_CODEC_ID_NONE) {

        if (!strncmp(VAR_2->str, VAR_4, sizeof(VAR_4))) {

            VAR_3 = VAR_2->VAR_3;

            break;

        }

        VAR_2++;

    }

    if (VAR_3 == AV_CODEC_ID_NONE) {

        av_log(VAR_0, AV_LOG_ERROR, "Unknown attached picture VAR_4: %VAR_0.\n",

               VAR_4);

        return 0;

    }



    if (VAR_7 >= VAR_1) {

        av_log(VAR_0, AV_LOG_ERROR, "Invalid attached picture data size: %d >= %d.\n",

               VAR_7, VAR_1);

        return AVERROR_INVALIDDATA;

    }



    

    VAR_8 = (VAR_1 - VAR_7) * 2 + 1;

    desc     = av_malloc(VAR_8);

    if (!desc)

        return AVERROR(ENOMEM);

    VAR_1 -= avio_get_str16le(VAR_0->pb, VAR_1 - VAR_7, desc, VAR_8);



    VAR_5 = av_get_packet(VAR_0->pb, &pkt, VAR_7);

    if (VAR_5 < 0)

        goto fail;



    st  = avformat_new_stream(VAR_0, NULL);

    if (!st) {

        VAR_5 = AVERROR(ENOMEM);

        goto fail;

    }

    asf->asf_st[asf->nb_streams] = av_mallocz(sizeof(*asf_st));

    asf_st = asf->asf_st[asf->nb_streams];

    if (!asf_st)

        return AVERROR(ENOMEM);



    st->disposition              |= AV_DISPOSITION_ATTACHED_PIC;

    st->codec->codec_type         = asf_st->VAR_6 = AVMEDIA_TYPE_VIDEO;

    st->codec->codec_id           = VAR_3;

    st->attached_pic              = pkt;

    st->attached_pic.stream_index = asf_st->index = st->index;

    st->attached_pic.flags       |= AV_PKT_FLAG_KEY;



    asf->nb_streams++;



    if (*desc) {

        if (av_dict_set(&st->metadata, "title", desc, AV_DICT_DONT_STRDUP_VAL) < 0)

            av_log(VAR_0, AV_LOG_WARNING, "av_dict_set failed.\n");

    } else

        av_freep(&desc);



    if (av_dict_set(&st->metadata, "comment", ff_id3v2_picture_types[VAR_6], 0) < 0)

        av_log(VAR_0, AV_LOG_WARNING, "av_dict_set failed.\n");



    return 0;



fail:

    av_freep(&desc);

    av_free_packet(&pkt);

    return VAR_5;

}

static int FUNC_0(AVFormatContext *VAR_0, int VAR_1)
{ ASFContext *asf       = VAR_0->priv_data; AVPacket pkt          = { 0 }; const CodecMime *VAR_2 = ff_id3v2_mime_tags; enum  AVCodecID VAR_3    = AV_CODEC_ID_NONE; char VAR_4[64]; uint8_t  *desc = NULL; AVStream   *st = NULL; int VAR_5, VAR_6, VAR_7, VAR_8; ASFStream *asf_st; if (VAR_1 < 1 + 4 + 2 + 2) { av_log(VAR_0, AV_LOG_ERROR, "Invalid attached picture size: %d.\n", VAR_1); return AVERROR_INVALIDDATA; } VAR_6 = avio_r8(VAR_0->pb); VAR_1--; if (VAR_6 >= FF_ARRAY_ELEMS(ff_id3v2_picture_types) || VAR_6 < 0) { av_log(VAR_0, AV_LOG_WARNING, "Unknown attached picture VAR_6: %d.\n", VAR_6); VAR_6 = 0; } VAR_7 = avio_rl32(VAR_0->pb); VAR_1    -= 4; VAR_1 -= avio_get_str16le(VAR_0->pb, VAR_1, VAR_4, sizeof(VAR_4)); while (VAR_2->VAR_3 != AV_CODEC_ID_NONE) { if (!strncmp(VAR_2->str, VAR_4, sizeof(VAR_4))) { VAR_3 = VAR_2->VAR_3; break; } VAR_2++; } if (VAR_3 == AV_CODEC_ID_NONE) { av_log(VAR_0, AV_LOG_ERROR, "Unknown attached picture VAR_4: %VAR_0.\n",
VAR_4); return 0; } if (VAR_7 >= VAR_1) { av_log(VAR_0, AV_LOG_ERROR, "Invalid attached picture data size: %d >= %d.\n",
VAR_7, VAR_1); return AVERROR_INVALIDDATA; } VAR_8 = (VAR_1 - VAR_7) * 2 + 1; desc     = av_malloc(VAR_8); if (!desc)
return AVERROR(ENOMEM); VAR_1 -= avio_get_str16le(VAR_0->pb, VAR_1 - VAR_7, desc, VAR_8); VAR_5 = av_get_packet(VAR_0->pb, &pkt, VAR_7); if (VAR_5 < 0)
goto fail; st  = avformat_new_stream(VAR_0, NULL); if (!st) { VAR_5 = AVERROR(ENOMEM); goto fail; } asf->asf_st[asf->nb_streams] = av_mallocz(sizeof(*asf_st)); asf_st = asf->asf_st[asf->nb_streams]; if (!asf_st)
return AVERROR(ENOMEM); st->disposition              |= AV_DISPOSITION_ATTACHED_PIC; st->codec->codec_type         = asf_st->VAR_6 = AVMEDIA_TYPE_VIDEO; st->codec->codec_id           = VAR_3; st->attached_pic              = pkt; st->attached_pic.stream_index = asf_st->index = st->index; st->attached_pic.flags       |= AV_PKT_FLAG_KEY; asf->nb_streams++; if (*desc) { if (av_dict_set(&st->metadata, "title", desc, AV_DICT_DONT_STRDUP_VAL) < 0)
av_log(VAR_0, AV_LOG_WARNING, "av_dict_set failed.\n"); } else av_freep(&desc); if (av_dict_set(&st->metadata, "comment", ff_id3v2_picture_types[VAR_6], 0) < 0)
av_log(VAR_0, AV_LOG_WARNING, "av_dict_set failed.\n"); return 0; fail:
av_freep(&desc); av_free_packet(&pkt); return VAR_5; }