static int dvdsub_parse(AVCodecParserContext *s,

                        AVCodecContext *avctx,

                        const uint8_t **poutbuf, int *poutbuf_size,

                        const uint8_t *buf, int buf_size)

{

    DVDSubParseContext *pc = s->priv_data;



    if (pc->packet_index == 0) {

        if (buf_size < 2)

            return buf_size;

        pc->packet_len = AV_RB16(buf);

        if (pc->packet_len == 0) /* HD-DVD subpicture packet */

            pc->packet_len = AV_RB32(buf+2);

        av_freep(&pc->packet);

        pc->packet = av_malloc(pc->packet_len);

    }

    if (pc->packet) {

        if (pc->packet_index + buf_size <= pc->packet_len) {

            memcpy(pc->packet + pc->packet_index, buf, buf_size);

            pc->packet_index += buf_size;

            if (pc->packet_index >= pc->packet_len) {

                *poutbuf = pc->packet;

                *poutbuf_size = pc->packet_len;

                pc->packet_index = 0;

                return buf_size;

            }

        } else {

            /* erroneous size */

            pc->packet_index = 0;

        }

    }

    *poutbuf = NULL;

    *poutbuf_size = 0;

    return buf_size;

}

static int dvdsub_parse(AVCodecParserContext *s,

                        AVCodecContext *avctx,

                        const uint8_t **poutbuf, int *poutbuf_size,

                        const uint8_t *buf, int buf_size)

{

    DVDSubParseContext *pc = s->priv_data;



    if (pc->packet_index == 0) {

        if (buf_size < 2)

            return buf_size;

        pc->packet_len = AV_RB16(buf);

        if (pc->packet_len == 0) 

            pc->packet_len = AV_RB32(buf+2);

        av_freep(&pc->packet);

        pc->packet = av_malloc(pc->packet_len);

    }

    if (pc->packet) {

        if (pc->packet_index + buf_size <= pc->packet_len) {

            memcpy(pc->packet + pc->packet_index, buf, buf_size);

            pc->packet_index += buf_size;

            if (pc->packet_index >= pc->packet_len) {

                *poutbuf = pc->packet;

                *poutbuf_size = pc->packet_len;

                pc->packet_index = 0;

                return buf_size;

            }

        } else {

            

            pc->packet_index = 0;

        }

    }

    *poutbuf = NULL;

    *poutbuf_size = 0;

    return buf_size;

}

static int FUNC_0(AVCodecParserContext *VAR_0,

                        AVCodecContext *VAR_1,

                        const uint8_t **VAR_2, int *VAR_3,

                        const uint8_t *VAR_4, int VAR_5)

{

    DVDSubParseContext *pc = VAR_0->priv_data;



    if (pc->packet_index == 0) {

        if (VAR_5 < 2)

            return VAR_5;

        pc->packet_len = AV_RB16(VAR_4);

        if (pc->packet_len == 0) 

            pc->packet_len = AV_RB32(VAR_4+2);

        av_freep(&pc->packet);

        pc->packet = av_malloc(pc->packet_len);

    }

    if (pc->packet) {

        if (pc->packet_index + VAR_5 <= pc->packet_len) {

            memcpy(pc->packet + pc->packet_index, VAR_4, VAR_5);

            pc->packet_index += VAR_5;

            if (pc->packet_index >= pc->packet_len) {

                *VAR_2 = pc->packet;

                *VAR_3 = pc->packet_len;

                pc->packet_index = 0;

                return VAR_5;

            }

        } else {

            

            pc->packet_index = 0;

        }

    }

    *VAR_2 = NULL;

    *VAR_3 = 0;

    return VAR_5;

}

static int FUNC_0(AVCodecParserContext *VAR_0,
AVCodecContext *VAR_1,
const uint8_t **VAR_2, int *VAR_3,
const uint8_t *VAR_4, int VAR_5)
{ DVDSubParseContext *pc = VAR_0->priv_data; if (pc->packet_index == 0) { if (VAR_5 < 2)
return VAR_5; pc->packet_len = AV_RB16(VAR_4); if (pc->packet_len == 0)
pc->packet_len = AV_RB32(VAR_4+2); av_freep(&pc->packet); pc->packet = av_malloc(pc->packet_len); } if (pc->packet) { if (pc->packet_index + VAR_5 <= pc->packet_len) { memcpy(pc->packet + pc->packet_index, VAR_4, VAR_5); pc->packet_index += VAR_5; if (pc->packet_index >= pc->packet_len) { *VAR_2 = pc->packet; *VAR_3 = pc->packet_len; pc->packet_index = 0; return VAR_5; } } else { pc->packet_index = 0; } } *VAR_2 = NULL; *VAR_3 = 0; return VAR_5; }