static int get_video_private_data(struct VideoFile *vf, AVCodecContext *codec)

{

    AVIOContext *io = NULL;

    uint16_t sps_size, pps_size;

    int err = AVERROR(EINVAL);



    if (codec->codec_id == AV_CODEC_ID_VC1)

        return get_private_data(vf, codec);



    avio_open_dyn_buf(&io);

    if (codec->extradata_size < 11 || codec->extradata[0] != 1)

        goto fail;

    sps_size = AV_RB16(&codec->extradata[6]);

    if (11 + sps_size > codec->extradata_size)

        goto fail;

    avio_wb32(io, 0x00000001);

    avio_write(io, &codec->extradata[8], sps_size);

    pps_size = AV_RB16(&codec->extradata[9 + sps_size]);

    if (11 + sps_size + pps_size > codec->extradata_size)

        goto fail;

    avio_wb32(io, 0x00000001);

    avio_write(io, &codec->extradata[11 + sps_size], pps_size);

    err = 0;



fail:

    vf->codec_private_size = avio_close_dyn_buf(io, &vf->codec_private);

    return err;

}

static int get_video_private_data(struct VideoFile *vf, AVCodecContext *codec)

{

    AVIOContext *io = NULL;

    uint16_t sps_size, pps_size;

    int err = AVERROR(EINVAL);



    if (codec->codec_id == AV_CODEC_ID_VC1)

        return get_private_data(vf, codec);



    avio_open_dyn_buf(&io);

    if (codec->extradata_size < 11 || codec->extradata[0] != 1)

        goto fail;

    sps_size = AV_RB16(&codec->extradata[6]);

    if (11 + sps_size > codec->extradata_size)

        goto fail;

    avio_wb32(io, 0x00000001);

    avio_write(io, &codec->extradata[8], sps_size);

    pps_size = AV_RB16(&codec->extradata[9 + sps_size]);

    if (11 + sps_size + pps_size > codec->extradata_size)

        goto fail;

    avio_wb32(io, 0x00000001);

    avio_write(io, &codec->extradata[11 + sps_size], pps_size);

    err = 0;



fail:

    vf->codec_private_size = avio_close_dyn_buf(io, &vf->codec_private);

    return err;

}

static int FUNC_0(struct VideoFile *VAR_0, AVCodecContext *VAR_1)

{

    AVIOContext *io = NULL;

    uint16_t sps_size, pps_size;

    int VAR_2 = AVERROR(EINVAL);



    if (VAR_1->codec_id == AV_CODEC_ID_VC1)

        return get_private_data(VAR_0, VAR_1);



    avio_open_dyn_buf(&io);

    if (VAR_1->extradata_size < 11 || VAR_1->extradata[0] != 1)

        goto fail;

    sps_size = AV_RB16(&VAR_1->extradata[6]);

    if (11 + sps_size > VAR_1->extradata_size)

        goto fail;

    avio_wb32(io, 0x00000001);

    avio_write(io, &VAR_1->extradata[8], sps_size);

    pps_size = AV_RB16(&VAR_1->extradata[9 + sps_size]);

    if (11 + sps_size + pps_size > VAR_1->extradata_size)

        goto fail;

    avio_wb32(io, 0x00000001);

    avio_write(io, &VAR_1->extradata[11 + sps_size], pps_size);

    VAR_2 = 0;



fail:

    VAR_0->codec_private_size = avio_close_dyn_buf(io, &VAR_0->codec_private);

    return VAR_2;

}

static int FUNC_0(struct VideoFile *VAR_0, AVCodecContext *VAR_1)
{ AVIOContext *io = NULL; uint16_t sps_size, pps_size; int VAR_2 = AVERROR(EINVAL); if (VAR_1->codec_id == AV_CODEC_ID_VC1)
return get_private_data(VAR_0, VAR_1); avio_open_dyn_buf(&io); if (VAR_1->extradata_size < 11 || VAR_1->extradata[0] != 1)
goto fail; sps_size = AV_RB16(&VAR_1->extradata[6]); if (11 + sps_size > VAR_1->extradata_size)
goto fail; avio_wb32(io, 0x00000001); avio_write(io, &VAR_1->extradata[8], sps_size); pps_size = AV_RB16(&VAR_1->extradata[9 + sps_size]); if (11 + sps_size + pps_size > VAR_1->extradata_size)
goto fail; avio_wb32(io, 0x00000001); avio_write(io, &VAR_1->extradata[11 + sps_size], pps_size); VAR_2 = 0; fail:
VAR_0->codec_private_size = avio_close_dyn_buf(io, &VAR_0->codec_private); return VAR_2; }