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

{

    int ret;

    unsigned int size;

    uint8_t *startmarker_ptr, *end, *search_end, marker;

    MXGContext *mxg = s->priv_data;



    while (!avio_feof(s->pb) && !s->pb->error){

        if (mxg->cache_size <= OVERREAD_SIZE) {

            /* update internal buffer */

            ret = mxg_update_cache(s, DEFAULT_PACKET_SIZE + OVERREAD_SIZE);

            if (ret < 0)

                return ret;

        }

        end = mxg->buffer_ptr + mxg->cache_size;



        /* find start marker - 0xff */

        if (mxg->cache_size > OVERREAD_SIZE) {

            search_end = end - OVERREAD_SIZE;

            startmarker_ptr = mxg_find_startmarker(mxg->buffer_ptr, search_end);

        } else {

            search_end = end;

            startmarker_ptr = mxg_find_startmarker(mxg->buffer_ptr, search_end);

            if (startmarker_ptr >= search_end - 1 ||

                *(startmarker_ptr + 1) != EOI) break;

        }



        if (startmarker_ptr != search_end) { /* start marker found */

            marker = *(startmarker_ptr + 1);

            mxg->buffer_ptr = startmarker_ptr + 2;

            mxg->cache_size = end - mxg->buffer_ptr;



            if (marker == SOI) {

                mxg->soi_ptr = startmarker_ptr;

            } else if (marker == EOI) {

                if (!mxg->soi_ptr) {

                    av_log(s, AV_LOG_WARNING, "Found EOI before SOI, skipping\n");

                    continue;

                }



                pkt->pts = pkt->dts = mxg->dts;

                pkt->stream_index = 0;

#if FF_API_DESTRUCT_PACKET

FF_DISABLE_DEPRECATION_WARNINGS

                pkt->destruct = NULL;

FF_ENABLE_DEPRECATION_WARNINGS

#endif

                pkt->buf  = NULL;

                pkt->size = mxg->buffer_ptr - mxg->soi_ptr;

                pkt->data = mxg->soi_ptr;



                if (mxg->soi_ptr - mxg->buffer > mxg->cache_size) {

                    if (mxg->cache_size > 0) {

                        memcpy(mxg->buffer, mxg->buffer_ptr, mxg->cache_size);

                    }



                    mxg->buffer_ptr = mxg->buffer;

                }

                mxg->soi_ptr = 0;



                return pkt->size;

            } else if ( (SOF0 <= marker && marker <= SOF15) ||

                        (SOS  <= marker && marker <= COM) ) {

                /* all other markers that start marker segment also contain

                   length value (see specification for JPEG Annex B.1) */

                size = AV_RB16(mxg->buffer_ptr);

                if (size < 2)

                    return AVERROR(EINVAL);



                if (mxg->cache_size < size) {

                    ret = mxg_update_cache(s, size);

                    if (ret < 0)

                        return ret;

                    startmarker_ptr = mxg->buffer_ptr - 2;

                    mxg->cache_size = 0;

                } else {

                    mxg->cache_size -= size;

                }



                mxg->buffer_ptr += size;



                if (marker == APP13 && size >= 16) { /* audio data */

                    /* time (GMT) of first sample in usec since 1970, little-endian */

                    pkt->pts = pkt->dts = AV_RL64(startmarker_ptr + 8);

                    pkt->stream_index = 1;

#if FF_API_DESTRUCT_PACKET

FF_DISABLE_DEPRECATION_WARNINGS

                    pkt->destruct = NULL;

FF_ENABLE_DEPRECATION_WARNINGS

#endif

                    pkt->buf  = NULL;

                    pkt->size = size - 14;

                    pkt->data = startmarker_ptr + 16;



                    if (startmarker_ptr - mxg->buffer > mxg->cache_size) {

                        if (mxg->cache_size > 0) {

                            memcpy(mxg->buffer, mxg->buffer_ptr, mxg->cache_size);

                        }

                        mxg->buffer_ptr = mxg->buffer;

                    }



                    return pkt->size;

                } else if (marker == COM && size >= 18 &&

                           !strncmp(startmarker_ptr + 4, "MXF", 3)) {

                    /* time (GMT) of video frame in usec since 1970, little-endian */

                    mxg->dts = AV_RL64(startmarker_ptr + 12);

                }

            }

        } else {

            /* start marker not found */

            mxg->buffer_ptr = search_end;

            mxg->cache_size = OVERREAD_SIZE;

        }

    }



    return AVERROR_EOF;

}

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

{

    int ret;

    unsigned int size;

    uint8_t *startmarker_ptr, *end, *search_end, marker;

    MXGContext *mxg = s->priv_data;



    while (!avio_feof(s->pb) && !s->pb->error){

        if (mxg->cache_size <= OVERREAD_SIZE) {

            

            ret = mxg_update_cache(s, DEFAULT_PACKET_SIZE + OVERREAD_SIZE);

            if (ret < 0)

                return ret;

        }

        end = mxg->buffer_ptr + mxg->cache_size;



        

        if (mxg->cache_size > OVERREAD_SIZE) {

            search_end = end - OVERREAD_SIZE;

            startmarker_ptr = mxg_find_startmarker(mxg->buffer_ptr, search_end);

        } else {

            search_end = end;

            startmarker_ptr = mxg_find_startmarker(mxg->buffer_ptr, search_end);

            if (startmarker_ptr >= search_end - 1 ||

                *(startmarker_ptr + 1) != EOI) break;

        }



        if (startmarker_ptr != search_end) { 

            marker = *(startmarker_ptr + 1);

            mxg->buffer_ptr = startmarker_ptr + 2;

            mxg->cache_size = end - mxg->buffer_ptr;



            if (marker == SOI) {

                mxg->soi_ptr = startmarker_ptr;

            } else if (marker == EOI) {

                if (!mxg->soi_ptr) {

                    av_log(s, AV_LOG_WARNING, "Found EOI before SOI, skipping\n");

                    continue;

                }



                pkt->pts = pkt->dts = mxg->dts;

                pkt->stream_index = 0;

#if FF_API_DESTRUCT_PACKET

FF_DISABLE_DEPRECATION_WARNINGS

                pkt->destruct = NULL;

FF_ENABLE_DEPRECATION_WARNINGS

#endif

                pkt->buf  = NULL;

                pkt->size = mxg->buffer_ptr - mxg->soi_ptr;

                pkt->data = mxg->soi_ptr;



                if (mxg->soi_ptr - mxg->buffer > mxg->cache_size) {

                    if (mxg->cache_size > 0) {

                        memcpy(mxg->buffer, mxg->buffer_ptr, mxg->cache_size);

                    }



                    mxg->buffer_ptr = mxg->buffer;

                }

                mxg->soi_ptr = 0;



                return pkt->size;

            } else if ( (SOF0 <= marker && marker <= SOF15) ||

                        (SOS  <= marker && marker <= COM) ) {

                



                size = AV_RB16(mxg->buffer_ptr);

                if (size < 2)

                    return AVERROR(EINVAL);



                if (mxg->cache_size < size) {

                    ret = mxg_update_cache(s, size);

                    if (ret < 0)

                        return ret;

                    startmarker_ptr = mxg->buffer_ptr - 2;

                    mxg->cache_size = 0;

                } else {

                    mxg->cache_size -= size;

                }



                mxg->buffer_ptr += size;



                if (marker == APP13 && size >= 16) { 

                    

                    pkt->pts = pkt->dts = AV_RL64(startmarker_ptr + 8);

                    pkt->stream_index = 1;

#if FF_API_DESTRUCT_PACKET

FF_DISABLE_DEPRECATION_WARNINGS

                    pkt->destruct = NULL;

FF_ENABLE_DEPRECATION_WARNINGS

#endif

                    pkt->buf  = NULL;

                    pkt->size = size - 14;

                    pkt->data = startmarker_ptr + 16;



                    if (startmarker_ptr - mxg->buffer > mxg->cache_size) {

                        if (mxg->cache_size > 0) {

                            memcpy(mxg->buffer, mxg->buffer_ptr, mxg->cache_size);

                        }

                        mxg->buffer_ptr = mxg->buffer;

                    }



                    return pkt->size;

                } else if (marker == COM && size >= 18 &&

                           !strncmp(startmarker_ptr + 4, "MXF", 3)) {

                    

                    mxg->dts = AV_RL64(startmarker_ptr + 12);

                }

            }

        } else {

            

            mxg->buffer_ptr = search_end;

            mxg->cache_size = OVERREAD_SIZE;

        }

    }



    return AVERROR_EOF;

}

                        memcpy(mxg->buffer, mxg->buffer_ptr, mxg->cache_size);
static int FUNC_0(AVFormatContext *VAR_0, AVPacket *VAR_1)

{

    int VAR_2;

    unsigned int VAR_3;

    uint8_t *startmarker_ptr, *end, *search_end, marker;

    MXGContext *mxg = VAR_0->priv_data;



    while (!avio_feof(VAR_0->pb) && !VAR_0->pb->error){

        if (mxg->cache_size <= OVERREAD_SIZE) {

            

            VAR_2 = mxg_update_cache(VAR_0, DEFAULT_PACKET_SIZE + OVERREAD_SIZE);

            if (VAR_2 < 0)

                return VAR_2;

        }

        end = mxg->buffer_ptr + mxg->cache_size;



        

        if (mxg->cache_size > OVERREAD_SIZE) {

            search_end = end - OVERREAD_SIZE;

            startmarker_ptr = mxg_find_startmarker(mxg->buffer_ptr, search_end);

        } else {

            search_end = end;

            startmarker_ptr = mxg_find_startmarker(mxg->buffer_ptr, search_end);

            if (startmarker_ptr >= search_end - 1 ||

                *(startmarker_ptr + 1) != EOI) break;

        }



        if (startmarker_ptr != search_end) { 

            marker = *(startmarker_ptr + 1);

            mxg->buffer_ptr = startmarker_ptr + 2;

            mxg->cache_size = end - mxg->buffer_ptr;



            if (marker == SOI) {

                mxg->soi_ptr = startmarker_ptr;

            } else if (marker == EOI) {

                if (!mxg->soi_ptr) {

                    av_log(VAR_0, AV_LOG_WARNING, "Found EOI before SOI, skipping\n");

                    continue;

                }



                VAR_1->pts = VAR_1->dts = mxg->dts;

                VAR_1->stream_index = 0;

#if FF_API_DESTRUCT_PACKET

FF_DISABLE_DEPRECATION_WARNINGS

                VAR_1->destruct = NULL;

FF_ENABLE_DEPRECATION_WARNINGS

#endif

                VAR_1->buf  = NULL;

                VAR_1->VAR_3 = mxg->buffer_ptr - mxg->soi_ptr;

                VAR_1->data = mxg->soi_ptr;



                if (mxg->soi_ptr - mxg->buffer > mxg->cache_size) {

                    if (mxg->cache_size > 0) {

                        memcpy(mxg->buffer, mxg->buffer_ptr, mxg->cache_size);

                    }



                    mxg->buffer_ptr = mxg->buffer;

                }

                mxg->soi_ptr = 0;



                return VAR_1->VAR_3;

            } else if ( (SOF0 <= marker && marker <= SOF15) ||

                        (SOS  <= marker && marker <= COM) ) {

                



                VAR_3 = AV_RB16(mxg->buffer_ptr);

                if (VAR_3 < 2)

                    return AVERROR(EINVAL);



                if (mxg->cache_size < VAR_3) {

                    VAR_2 = mxg_update_cache(VAR_0, VAR_3);

                    if (VAR_2 < 0)

                        return VAR_2;

                    startmarker_ptr = mxg->buffer_ptr - 2;

                    mxg->cache_size = 0;

                } else {

                    mxg->cache_size -= VAR_3;

                }



                mxg->buffer_ptr += VAR_3;



                if (marker == APP13 && VAR_3 >= 16) { 

                    

                    VAR_1->pts = VAR_1->dts = AV_RL64(startmarker_ptr + 8);

                    VAR_1->stream_index = 1;

#if FF_API_DESTRUCT_PACKET

FF_DISABLE_DEPRECATION_WARNINGS

                    VAR_1->destruct = NULL;

FF_ENABLE_DEPRECATION_WARNINGS

#endif

                    VAR_1->buf  = NULL;

                    VAR_1->VAR_3 = VAR_3 - 14;

                    VAR_1->data = startmarker_ptr + 16;



                    if (startmarker_ptr - mxg->buffer > mxg->cache_size) {

                        if (mxg->cache_size > 0) {

                            memcpy(mxg->buffer, mxg->buffer_ptr, mxg->cache_size);

                        }

                        mxg->buffer_ptr = mxg->buffer;

                    }



                    return VAR_1->VAR_3;

                } else if (marker == COM && VAR_3 >= 18 &&

                           !strncmp(startmarker_ptr + 4, "MXF", 3)) {

                    

                    mxg->dts = AV_RL64(startmarker_ptr + 12);

                }

            }

        } else {

            

            mxg->buffer_ptr = search_end;

            mxg->cache_size = OVERREAD_SIZE;

        }

    }



    return AVERROR_EOF;

}

static int FUNC_0(AVFormatContext *VAR_0, AVPacket *VAR_1)
{ int VAR_2; unsigned int VAR_3; uint8_t *startmarker_ptr, *end, *search_end, marker; MXGContext *mxg = VAR_0->priv_data; while (!avio_feof(VAR_0->pb) && !VAR_0->pb->error){ if (mxg->cache_size <= OVERREAD_SIZE) { VAR_2 = mxg_update_cache(VAR_0, DEFAULT_PACKET_SIZE + OVERREAD_SIZE); if (VAR_2 < 0)
return VAR_2; } end = mxg->buffer_ptr + mxg->cache_size; if (mxg->cache_size > OVERREAD_SIZE) { search_end = end - OVERREAD_SIZE; startmarker_ptr = mxg_find_startmarker(mxg->buffer_ptr, search_end); } else { search_end = end; startmarker_ptr = mxg_find_startmarker(mxg->buffer_ptr, search_end); if (startmarker_ptr >= search_end - 1 ||
*(startmarker_ptr + 1) != EOI) break; } if (startmarker_ptr != search_end) { marker = *(startmarker_ptr + 1); mxg->buffer_ptr = startmarker_ptr + 2; mxg->cache_size = end - mxg->buffer_ptr; if (marker == SOI) { mxg->soi_ptr = startmarker_ptr; } else if (marker == EOI) { if (!mxg->soi_ptr) { av_log(VAR_0, AV_LOG_WARNING, "Found EOI before SOI, skipping\n"); continue; } VAR_1->pts = VAR_1->dts = mxg->dts; VAR_1->stream_index = 0; #if FF_API_DESTRUCT_PACKET
FF_DISABLE_DEPRECATION_WARNINGS
VAR_1->destruct = NULL; FF_ENABLE_DEPRECATION_WARNINGS
#endif
VAR_1->buf  = NULL; VAR_1->VAR_3 = mxg->buffer_ptr - mxg->soi_ptr; VAR_1->data = mxg->soi_ptr; if (mxg->soi_ptr - mxg->buffer > mxg->cache_size) { if (mxg->cache_size > 0) { memcpy(mxg->buffer, mxg->buffer_ptr, mxg->cache_size); } mxg->buffer_ptr = mxg->buffer; } mxg->soi_ptr = 0; return VAR_1->VAR_3; } else if ( (SOF0 <= marker && marker <= SOF15) || (SOS  <= marker && marker <= COM) ) { VAR_3 = AV_RB16(mxg->buffer_ptr); if (VAR_3 < 2)
return AVERROR(EINVAL); if (mxg->cache_size < VAR_3) { VAR_2 = mxg_update_cache(VAR_0, VAR_3); if (VAR_2 < 0)
return VAR_2; startmarker_ptr = mxg->buffer_ptr - 2; mxg->cache_size = 0; } else { mxg->cache_size -= VAR_3; } mxg->buffer_ptr += VAR_3; if (marker == APP13 && VAR_3 >= 16) { VAR_1->pts = VAR_1->dts = AV_RL64(startmarker_ptr + 8); VAR_1->stream_index = 1; #if FF_API_DESTRUCT_PACKET
FF_DISABLE_DEPRECATION_WARNINGS
VAR_1->destruct = NULL; FF_ENABLE_DEPRECATION_WARNINGS
#endif
VAR_1->buf  = NULL; VAR_1->VAR_3 = VAR_3 - 14; VAR_1->data = startmarker_ptr + 16; if (startmarker_ptr - mxg->buffer > mxg->cache_size) { if (mxg->cache_size > 0) { memcpy(mxg->buffer, mxg->buffer_ptr, mxg->cache_size); } mxg->buffer_ptr = mxg->buffer; } return VAR_1->VAR_3; } else if (marker == COM && VAR_3 >= 18 && !strncmp(startmarker_ptr + 4, "MXF", 3)) { mxg->dts = AV_RL64(startmarker_ptr + 12); } } } else { mxg->buffer_ptr = search_end; mxg->cache_size = OVERREAD_SIZE; } } return AVERROR_EOF; }