static int dvbsub_decode(AVCodecContext *avctx,

                         void *data, int *data_size,

                         AVPacket *avpkt)

{

    const uint8_t *buf = avpkt->data;

    int buf_size = avpkt->size;

    DVBSubContext *ctx = avctx->priv_data;

    AVSubtitle *sub = data;

    const uint8_t *p, *p_end;

    int segment_type;

    int page_id;

    int segment_length;

    int i;



    av_dlog(avctx, "DVB sub packet:\n");



    for (i=0; i < buf_size; i++) {

        av_dlog(avctx, "%02x ", buf[i]);

        if (i % 16 == 15)

            av_dlog(avctx, "\n");

    }



    if (i % 16)

        av_dlog(avctx, "\n");



    if (buf_size <= 6 || *buf != 0x0f) {

        av_dlog(avctx, "incomplete or broken packet");

        return -1;

    }



    p = buf;

    p_end = buf + buf_size;



    while (p_end - p >= 6 && *p == 0x0f) {

        p += 1;

        segment_type = *p++;

        page_id = AV_RB16(p);

        p += 2;

        segment_length = AV_RB16(p);

        p += 2;



        if (p_end - p < segment_length) {

            av_dlog(avctx, "incomplete or broken packet");

            return -1;

        }



        if (page_id == ctx->composition_id || page_id == ctx->ancillary_id ||

            ctx->composition_id == -1 || ctx->ancillary_id == -1) {

            switch (segment_type) {

            case DVBSUB_PAGE_SEGMENT:

                dvbsub_parse_page_segment(avctx, p, segment_length);

                break;

            case DVBSUB_REGION_SEGMENT:

                dvbsub_parse_region_segment(avctx, p, segment_length);

                break;

            case DVBSUB_CLUT_SEGMENT:

                dvbsub_parse_clut_segment(avctx, p, segment_length);

                break;

            case DVBSUB_OBJECT_SEGMENT:

                dvbsub_parse_object_segment(avctx, p, segment_length);

                break;

            case DVBSUB_DISPLAYDEFINITION_SEGMENT:

                dvbsub_parse_display_definition_segment(avctx, p, segment_length);

                break;

            case DVBSUB_DISPLAY_SEGMENT:

                *data_size = dvbsub_display_end_segment(avctx, p, segment_length, sub);

                break;

            default:

                av_dlog(avctx, "Subtitling segment type 0x%x, page id %d, length %d\n",

                        segment_type, page_id, segment_length);

                break;

            }

        }



        p += segment_length;

    }



    return p - buf;

}

static int dvbsub_decode(AVCodecContext *avctx,

                         void *data, int *data_size,

                         AVPacket *avpkt)

{

    const uint8_t *buf = avpkt->data;

    int buf_size = avpkt->size;

    DVBSubContext *ctx = avctx->priv_data;

    AVSubtitle *sub = data;

    const uint8_t *p, *p_end;

    int segment_type;

    int page_id;

    int segment_length;

    int i;



    av_dlog(avctx, "DVB sub packet:\n");



    for (i=0; i < buf_size; i++) {

        av_dlog(avctx, "%02x ", buf[i]);

        if (i % 16 == 15)

            av_dlog(avctx, "\n");

    }



    if (i % 16)

        av_dlog(avctx, "\n");



    if (buf_size <= 6 || *buf != 0x0f) {

        av_dlog(avctx, "incomplete or broken packet");

        return -1;

    }



    p = buf;

    p_end = buf + buf_size;



    while (p_end - p >= 6 && *p == 0x0f) {

        p += 1;

        segment_type = *p++;

        page_id = AV_RB16(p);

        p += 2;

        segment_length = AV_RB16(p);

        p += 2;



        if (p_end - p < segment_length) {

            av_dlog(avctx, "incomplete or broken packet");

            return -1;

        }



        if (page_id == ctx->composition_id || page_id == ctx->ancillary_id ||

            ctx->composition_id == -1 || ctx->ancillary_id == -1) {

            switch (segment_type) {

            case DVBSUB_PAGE_SEGMENT:

                dvbsub_parse_page_segment(avctx, p, segment_length);

                break;

            case DVBSUB_REGION_SEGMENT:

                dvbsub_parse_region_segment(avctx, p, segment_length);

                break;

            case DVBSUB_CLUT_SEGMENT:

                dvbsub_parse_clut_segment(avctx, p, segment_length);

                break;

            case DVBSUB_OBJECT_SEGMENT:

                dvbsub_parse_object_segment(avctx, p, segment_length);

                break;

            case DVBSUB_DISPLAYDEFINITION_SEGMENT:

                dvbsub_parse_display_definition_segment(avctx, p, segment_length);

                break;

            case DVBSUB_DISPLAY_SEGMENT:

                *data_size = dvbsub_display_end_segment(avctx, p, segment_length, sub);

                break;

            default:

                av_dlog(avctx, "Subtitling segment type 0x%x, page id %d, length %d\n",

                        segment_type, page_id, segment_length);

                break;

            }

        }



        p += segment_length;

    }



    return p - buf;

}

static int FUNC_0(AVCodecContext *VAR_0,

                         void *VAR_1, int *VAR_2,

                         AVPacket *VAR_3)

{

    const uint8_t *VAR_4 = VAR_3->VAR_1;

    int VAR_5 = VAR_3->size;

    DVBSubContext *ctx = VAR_0->priv_data;

    AVSubtitle *sub = VAR_1;

    const uint8_t *VAR_6, *p_end;

    int VAR_7;

    int VAR_8;

    int VAR_9;

    int VAR_10;



    av_dlog(VAR_0, "DVB sub packet:\n");



    for (VAR_10=0; VAR_10 < VAR_5; VAR_10++) {

        av_dlog(VAR_0, "%02x ", VAR_4[VAR_10]);

        if (VAR_10 % 16 == 15)

            av_dlog(VAR_0, "\n");

    }



    if (VAR_10 % 16)

        av_dlog(VAR_0, "\n");



    if (VAR_5 <= 6 || *VAR_4 != 0x0f) {

        av_dlog(VAR_0, "incomplete or broken packet");

        return -1;

    }



    VAR_6 = VAR_4;

    p_end = VAR_4 + VAR_5;



    while (p_end - VAR_6 >= 6 && *VAR_6 == 0x0f) {

        VAR_6 += 1;

        VAR_7 = *VAR_6++;

        VAR_8 = AV_RB16(VAR_6);

        VAR_6 += 2;

        VAR_9 = AV_RB16(VAR_6);

        VAR_6 += 2;



        if (p_end - VAR_6 < VAR_9) {

            av_dlog(VAR_0, "incomplete or broken packet");

            return -1;

        }



        if (VAR_8 == ctx->composition_id || VAR_8 == ctx->ancillary_id ||

            ctx->composition_id == -1 || ctx->ancillary_id == -1) {

            switch (VAR_7) {

            case DVBSUB_PAGE_SEGMENT:

                dvbsub_parse_page_segment(VAR_0, VAR_6, VAR_9);

                break;

            case DVBSUB_REGION_SEGMENT:

                dvbsub_parse_region_segment(VAR_0, VAR_6, VAR_9);

                break;

            case DVBSUB_CLUT_SEGMENT:

                dvbsub_parse_clut_segment(VAR_0, VAR_6, VAR_9);

                break;

            case DVBSUB_OBJECT_SEGMENT:

                dvbsub_parse_object_segment(VAR_0, VAR_6, VAR_9);

                break;

            case DVBSUB_DISPLAYDEFINITION_SEGMENT:

                dvbsub_parse_display_definition_segment(VAR_0, VAR_6, VAR_9);

                break;

            case DVBSUB_DISPLAY_SEGMENT:

                *VAR_2 = dvbsub_display_end_segment(VAR_0, VAR_6, VAR_9, sub);

                break;

            default:

                av_dlog(VAR_0, "Subtitling segment type 0x%x, page id %d, length %d\n",

                        VAR_7, VAR_8, VAR_9);

                break;

            }

        }



        VAR_6 += VAR_9;

    }



    return VAR_6 - VAR_4;

}

static int FUNC_0(AVCodecContext *VAR_0,
void *VAR_1, int *VAR_2,
AVPacket *VAR_3)
{ const uint8_t *VAR_4 = VAR_3->VAR_1; int VAR_5 = VAR_3->size; DVBSubContext *ctx = VAR_0->priv_data; AVSubtitle *sub = VAR_1; const uint8_t *VAR_6, *p_end; int VAR_7; int VAR_8; int VAR_9; int VAR_10; av_dlog(VAR_0, "DVB sub packet:\n"); for (VAR_10=0; VAR_10 < VAR_5; VAR_10++) { av_dlog(VAR_0, "%02x ", VAR_4[VAR_10]); if (VAR_10 % 16 == 15)
av_dlog(VAR_0, "\n"); } if (VAR_10 % 16)
av_dlog(VAR_0, "\n"); if (VAR_5 <= 6 || *VAR_4 != 0x0f) { av_dlog(VAR_0, "incomplete or broken packet"); return -1; } VAR_6 = VAR_4; p_end = VAR_4 + VAR_5; while (p_end - VAR_6 >= 6 && *VAR_6 == 0x0f) { VAR_6 += 1; VAR_7 = *VAR_6++; VAR_8 = AV_RB16(VAR_6); VAR_6 += 2; VAR_9 = AV_RB16(VAR_6); VAR_6 += 2; if (p_end - VAR_6 < VAR_9) { av_dlog(VAR_0, "incomplete or broken packet"); return -1; } if (VAR_8 == ctx->composition_id || VAR_8 == ctx->ancillary_id ||
ctx->composition_id == -1 || ctx->ancillary_id == -1) { switch (VAR_7) { case DVBSUB_PAGE_SEGMENT:
dvbsub_parse_page_segment(VAR_0, VAR_6, VAR_9); break; case DVBSUB_REGION_SEGMENT:
dvbsub_parse_region_segment(VAR_0, VAR_6, VAR_9); break; case DVBSUB_CLUT_SEGMENT:
dvbsub_parse_clut_segment(VAR_0, VAR_6, VAR_9); break; case DVBSUB_OBJECT_SEGMENT:
dvbsub_parse_object_segment(VAR_0, VAR_6, VAR_9); break; case DVBSUB_DISPLAYDEFINITION_SEGMENT:
dvbsub_parse_display_definition_segment(VAR_0, VAR_6, VAR_9); break; case DVBSUB_DISPLAY_SEGMENT:
*VAR_2 = dvbsub_display_end_segment(VAR_0, VAR_6, VAR_9, sub); break; default:
av_dlog(VAR_0, "Subtitling segment type 0x%x, page id %d, length %d\n",
VAR_7, VAR_8, VAR_9); break; } } VAR_6 += VAR_9; } return VAR_6 - VAR_4; }