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

{

    CinDemuxContext *cin = s->priv_data;

    ByteIOContext *pb = s->pb;

    CinFrameHeader *hdr = &cin->frame_header;

    int rc, palette_type, pkt_size;



    if (cin->audio_buffer_size == 0) {

        rc = cin_read_frame_header(cin, pb);

        if (rc)

            return rc;



        if ((int16_t)hdr->pal_colors_count < 0) {

            hdr->pal_colors_count = -(int16_t)hdr->pal_colors_count;

            palette_type = 1;

        } else {

            palette_type = 0;

        }



        /* palette and video packet */

        pkt_size = (palette_type + 3) * hdr->pal_colors_count + hdr->video_frame_size;



        if (av_new_packet(pkt, 4 + pkt_size))

            return AVERROR(ENOMEM);



        pkt->stream_index = cin->video_stream_index;

        pkt->pts = cin->video_stream_pts++;



        pkt->data[0] = palette_type;

        pkt->data[1] = hdr->pal_colors_count & 0xFF;

        pkt->data[2] = hdr->pal_colors_count >> 8;

        pkt->data[3] = hdr->video_frame_type;



        if (get_buffer(pb, &pkt->data[4], pkt_size) != pkt_size)

            return AVERROR(EIO);



        /* sound buffer will be processed on next read_packet() call */

        cin->audio_buffer_size = hdr->audio_frame_size;

        return 0;

    }



    /* audio packet */

    if (av_new_packet(pkt, cin->audio_buffer_size))

        return AVERROR(ENOMEM);



    pkt->stream_index = cin->audio_stream_index;

    pkt->pts = cin->audio_stream_pts;

    cin->audio_stream_pts += cin->audio_buffer_size * 2 / cin->file_header.audio_frame_size;



    if (get_buffer(pb, pkt->data, cin->audio_buffer_size) != cin->audio_buffer_size)

        return AVERROR(EIO);



    cin->audio_buffer_size = 0;

    return 0;

}

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

{

    CinDemuxContext *cin = s->priv_data;

    ByteIOContext *pb = s->pb;

    CinFrameHeader *hdr = &cin->frame_header;

    int rc, palette_type, pkt_size;



    if (cin->audio_buffer_size == 0) {

        rc = cin_read_frame_header(cin, pb);

        if (rc)

            return rc;



        if ((int16_t)hdr->pal_colors_count < 0) {

            hdr->pal_colors_count = -(int16_t)hdr->pal_colors_count;

            palette_type = 1;

        } else {

            palette_type = 0;

        }



        

        pkt_size = (palette_type + 3) * hdr->pal_colors_count + hdr->video_frame_size;



        if (av_new_packet(pkt, 4 + pkt_size))

            return AVERROR(ENOMEM);



        pkt->stream_index = cin->video_stream_index;

        pkt->pts = cin->video_stream_pts++;



        pkt->data[0] = palette_type;

        pkt->data[1] = hdr->pal_colors_count & 0xFF;

        pkt->data[2] = hdr->pal_colors_count >> 8;

        pkt->data[3] = hdr->video_frame_type;



        if (get_buffer(pb, &pkt->data[4], pkt_size) != pkt_size)

            return AVERROR(EIO);



        

        cin->audio_buffer_size = hdr->audio_frame_size;

        return 0;

    }



    

    if (av_new_packet(pkt, cin->audio_buffer_size))

        return AVERROR(ENOMEM);



    pkt->stream_index = cin->audio_stream_index;

    pkt->pts = cin->audio_stream_pts;

    cin->audio_stream_pts += cin->audio_buffer_size * 2 / cin->file_header.audio_frame_size;



    if (get_buffer(pb, pkt->data, cin->audio_buffer_size) != cin->audio_buffer_size)

        return AVERROR(EIO);



    cin->audio_buffer_size = 0;

    return 0;

}

        if (av_new_packet(pkt, 4 + pkt_size))             return AVERROR(ENOMEM);         if (get_buffer(pb, &pkt->data[4], pkt_size) != pkt_size)             return AVERROR(EIO);     if (av_new_packet(pkt, cin->audio_buffer_size))         return AVERROR(ENOMEM);     if (get_buffer(pb, pkt->data, cin->audio_buffer_size) != cin->audio_buffer_size)         return AVERROR(EIO);
static int FUNC_0(AVFormatContext *VAR_0, AVPacket *VAR_1)

{

    CinDemuxContext *cin = VAR_0->priv_data;

    ByteIOContext *pb = VAR_0->pb;

    CinFrameHeader *hdr = &cin->frame_header;

    int VAR_2, VAR_3, VAR_4;



    if (cin->audio_buffer_size == 0) {

        VAR_2 = cin_read_frame_header(cin, pb);

        if (VAR_2)

            return VAR_2;



        if ((int16_t)hdr->pal_colors_count < 0) {

            hdr->pal_colors_count = -(int16_t)hdr->pal_colors_count;

            VAR_3 = 1;

        } else {

            VAR_3 = 0;

        }



        

        VAR_4 = (VAR_3 + 3) * hdr->pal_colors_count + hdr->video_frame_size;



        if (av_new_packet(VAR_1, 4 + VAR_4))

            return AVERROR(ENOMEM);



        VAR_1->stream_index = cin->video_stream_index;

        VAR_1->pts = cin->video_stream_pts++;



        VAR_1->data[0] = VAR_3;

        VAR_1->data[1] = hdr->pal_colors_count & 0xFF;

        VAR_1->data[2] = hdr->pal_colors_count >> 8;

        VAR_1->data[3] = hdr->video_frame_type;



        if (get_buffer(pb, &VAR_1->data[4], VAR_4) != VAR_4)

            return AVERROR(EIO);



        

        cin->audio_buffer_size = hdr->audio_frame_size;

        return 0;

    }



    

    if (av_new_packet(VAR_1, cin->audio_buffer_size))

        return AVERROR(ENOMEM);



    VAR_1->stream_index = cin->audio_stream_index;

    VAR_1->pts = cin->audio_stream_pts;

    cin->audio_stream_pts += cin->audio_buffer_size * 2 / cin->file_header.audio_frame_size;



    if (get_buffer(pb, VAR_1->data, cin->audio_buffer_size) != cin->audio_buffer_size)

        return AVERROR(EIO);



    cin->audio_buffer_size = 0;

    return 0;

}

static int FUNC_0(AVFormatContext *VAR_0, AVPacket *VAR_1)
{ CinDemuxContext *cin = VAR_0->priv_data; ByteIOContext *pb = VAR_0->pb; CinFrameHeader *hdr = &cin->frame_header; int VAR_2, VAR_3, VAR_4; if (cin->audio_buffer_size == 0) { VAR_2 = cin_read_frame_header(cin, pb); if (VAR_2)
return VAR_2; if ((int16_t)hdr->pal_colors_count < 0) { hdr->pal_colors_count = -(int16_t)hdr->pal_colors_count; VAR_3 = 1; } else { VAR_3 = 0; } VAR_4 = (VAR_3 + 3) * hdr->pal_colors_count + hdr->video_frame_size; if (av_new_packet(VAR_1, 4 + VAR_4))
return AVERROR(ENOMEM); VAR_1->stream_index = cin->video_stream_index; VAR_1->pts = cin->video_stream_pts++; VAR_1->data[0] = VAR_3; VAR_1->data[1] = hdr->pal_colors_count & 0xFF; VAR_1->data[2] = hdr->pal_colors_count >> 8; VAR_1->data[3] = hdr->video_frame_type; if (get_buffer(pb, &VAR_1->data[4], VAR_4) != VAR_4)
return AVERROR(EIO); cin->audio_buffer_size = hdr->audio_frame_size; return 0; } if (av_new_packet(VAR_1, cin->audio_buffer_size))
return AVERROR(ENOMEM); VAR_1->stream_index = cin->audio_stream_index; VAR_1->pts = cin->audio_stream_pts; cin->audio_stream_pts += cin->audio_buffer_size * 2 / cin->file_header.audio_frame_size; if (get_buffer(pb, VAR_1->data, cin->audio_buffer_size) != cin->audio_buffer_size)
return AVERROR(EIO); cin->audio_buffer_size = 0; return 0; }