static int yop_read_packet(AVFormatContext *s, AVPacket *pkt)

{

    YopDecContext *yop = s->priv_data;

    AVIOContext *pb  = s->pb;



    int ret;

    int actual_video_data_size = yop->frame_size -

                                 yop->audio_block_length - yop->palette_size;



    yop->video_packet.stream_index = 1;



    if (yop->video_packet.data) {

        *pkt                   =  yop->video_packet;

        yop->video_packet.data =  NULL;

        yop->video_packet.size =  0;

        pkt->data[0]           =  yop->odd_frame;

        pkt->flags             |= AV_PKT_FLAG_KEY;

        yop->odd_frame         ^= 1;

        return pkt->size;

    }

    ret = av_new_packet(&yop->video_packet,

                        yop->frame_size - yop->audio_block_length);

    if (ret < 0)

        return ret;



    yop->video_packet.pos = avio_tell(pb);



    ret = avio_read(pb, yop->video_packet.data, yop->palette_size);

    if (ret < 0) {

        goto err_out;

    }else if (ret < yop->palette_size) {

        ret = AVERROR_EOF;

        goto err_out;

    }



    ret = av_get_packet(pb, pkt, 920);

    if (ret < 0)

        goto err_out;



    // Set position to the start of the frame

    pkt->pos = yop->video_packet.pos;



    avio_skip(pb, yop->audio_block_length - ret);



    ret = avio_read(pb, yop->video_packet.data + yop->palette_size,

                     actual_video_data_size);

    if (ret < 0)

        goto err_out;

    else if (ret < actual_video_data_size)

        av_shrink_packet(&yop->video_packet, yop->palette_size + ret);



    // Arbitrarily return the audio data first

    return yop->audio_block_length;



err_out:

    av_free_packet(&yop->video_packet);

    return ret;

}

static int yop_read_packet(AVFormatContext *s, AVPacket *pkt)

{

    YopDecContext *yop = s->priv_data;

    AVIOContext *pb  = s->pb;



    int ret;

    int actual_video_data_size = yop->frame_size -

                                 yop->audio_block_length - yop->palette_size;



    yop->video_packet.stream_index = 1;



    if (yop->video_packet.data) {

        *pkt                   =  yop->video_packet;

        yop->video_packet.data =  NULL;

        yop->video_packet.size =  0;

        pkt->data[0]           =  yop->odd_frame;

        pkt->flags             |= AV_PKT_FLAG_KEY;

        yop->odd_frame         ^= 1;

        return pkt->size;

    }

    ret = av_new_packet(&yop->video_packet,

                        yop->frame_size - yop->audio_block_length);

    if (ret < 0)

        return ret;



    yop->video_packet.pos = avio_tell(pb);



    ret = avio_read(pb, yop->video_packet.data, yop->palette_size);

    if (ret < 0) {

        goto err_out;

    }else if (ret < yop->palette_size) {

        ret = AVERROR_EOF;

        goto err_out;

    }



    ret = av_get_packet(pb, pkt, 920);

    if (ret < 0)

        goto err_out;



    

    pkt->pos = yop->video_packet.pos;



    avio_skip(pb, yop->audio_block_length - ret);



    ret = avio_read(pb, yop->video_packet.data + yop->palette_size,

                     actual_video_data_size);

    if (ret < 0)

        goto err_out;

    else if (ret < actual_video_data_size)

        av_shrink_packet(&yop->video_packet, yop->palette_size + ret);



    

    return yop->audio_block_length;



err_out:

    av_free_packet(&yop->video_packet);

    return ret;

}

        yop->video_packet.data =  NULL;         yop->video_packet.size =  0;
static int FUNC_0(AVFormatContext *VAR_0, AVPacket *VAR_1)

{

    YopDecContext *yop = VAR_0->priv_data;

    AVIOContext *pb  = VAR_0->pb;



    int VAR_2;

    int VAR_3 = yop->frame_size -

                                 yop->audio_block_length - yop->palette_size;



    yop->video_packet.stream_index = 1;



    if (yop->video_packet.data) {

        *VAR_1                   =  yop->video_packet;

        yop->video_packet.data =  NULL;

        yop->video_packet.size =  0;

        VAR_1->data[0]           =  yop->odd_frame;

        VAR_1->flags             |= AV_PKT_FLAG_KEY;

        yop->odd_frame         ^= 1;

        return VAR_1->size;

    }

    VAR_2 = av_new_packet(&yop->video_packet,

                        yop->frame_size - yop->audio_block_length);

    if (VAR_2 < 0)

        return VAR_2;



    yop->video_packet.pos = avio_tell(pb);



    VAR_2 = avio_read(pb, yop->video_packet.data, yop->palette_size);

    if (VAR_2 < 0) {

        goto err_out;

    }else if (VAR_2 < yop->palette_size) {

        VAR_2 = AVERROR_EOF;

        goto err_out;

    }



    VAR_2 = av_get_packet(pb, VAR_1, 920);

    if (VAR_2 < 0)

        goto err_out;



    

    VAR_1->pos = yop->video_packet.pos;



    avio_skip(pb, yop->audio_block_length - VAR_2);



    VAR_2 = avio_read(pb, yop->video_packet.data + yop->palette_size,

                     VAR_3);

    if (VAR_2 < 0)

        goto err_out;

    else if (VAR_2 < VAR_3)

        av_shrink_packet(&yop->video_packet, yop->palette_size + VAR_2);



    

    return yop->audio_block_length;



err_out:

    av_free_packet(&yop->video_packet);

    return VAR_2;

}

static int FUNC_0(AVFormatContext *VAR_0, AVPacket *VAR_1)
{ YopDecContext *yop = VAR_0->priv_data; AVIOContext *pb  = VAR_0->pb; int VAR_2; int VAR_3 = yop->frame_size -
yop->audio_block_length - yop->palette_size; yop->video_packet.stream_index = 1; if (yop->video_packet.data) { *VAR_1                   =  yop->video_packet; yop->video_packet.data =  NULL; yop->video_packet.size =  0; VAR_1->data[0]           =  yop->odd_frame; VAR_1->flags             |= AV_PKT_FLAG_KEY; yop->odd_frame         ^= 1; return VAR_1->size; } VAR_2 = av_new_packet(&yop->video_packet,
yop->frame_size - yop->audio_block_length); if (VAR_2 < 0)
return VAR_2; yop->video_packet.pos = avio_tell(pb); VAR_2 = avio_read(pb, yop->video_packet.data, yop->palette_size); if (VAR_2 < 0) { goto err_out; }else if (VAR_2 < yop->palette_size) { VAR_2 = AVERROR_EOF; goto err_out; } VAR_2 = av_get_packet(pb, VAR_1, 920); if (VAR_2 < 0)
goto err_out; VAR_1->pos = yop->video_packet.pos; avio_skip(pb, yop->audio_block_length - VAR_2); VAR_2 = avio_read(pb, yop->video_packet.data + yop->palette_size,
VAR_3); if (VAR_2 < 0)
goto err_out; else if (VAR_2 < VAR_3)
av_shrink_packet(&yop->video_packet, yop->palette_size + VAR_2); return yop->audio_block_length; err_out:
av_free_packet(&yop->video_packet); return VAR_2; }