static int dvdsub_decode(AVCodecContext *avctx,

                         void *data, int *data_size,

                         AVPacket *avpkt)

{

    DVDSubContext *ctx = avctx->priv_data;

    const uint8_t *buf = avpkt->data;

    int buf_size = avpkt->size;

    AVSubtitle *sub = data;

    int is_menu;



    if (ctx->buf_size) {

        int ret = append_to_cached_buf(avctx, buf, buf_size);

        if (ret < 0) {

            *data_size = 0;

            return ret;

        }

        buf = ctx->buf;

        buf_size = ctx->buf_size;

    }



    is_menu = decode_dvd_subtitles(ctx, sub, buf, buf_size);

    if (is_menu == AVERROR(EAGAIN)) {

        *data_size = 0;

        return append_to_cached_buf(avctx, buf, buf_size);

    }



    if (is_menu < 0) {

    no_subtitle:

        reset_rects(sub);

        *data_size = 0;



        return buf_size;

    }

    if (!is_menu && find_smallest_bounding_rectangle(sub) == 0)

        goto no_subtitle;



    if (ctx->forced_subs_only && !(sub->rects[0]->flags & AV_SUBTITLE_FLAG_FORCED))

        goto no_subtitle;



#if defined(DEBUG)

    {

    char ppm_name[32];



    snprintf(ppm_name, sizeof(ppm_name), "/tmp/%05d.ppm", ctx->sub_id++);

    ff_dlog(NULL, "start=%d ms end =%d ms\n",

            sub->start_display_time,

            sub->end_display_time);

    ppm_save(ppm_name, sub->rects[0]->pict.data[0],

             sub->rects[0]->w, sub->rects[0]->h, (uint32_t*) sub->rects[0]->pict.data[1]);

    }

#endif



    ctx->buf_size = 0;

    *data_size = 1;

    return buf_size;

}

static int dvdsub_decode(AVCodecContext *avctx,

                         void *data, int *data_size,

                         AVPacket *avpkt)

{

    DVDSubContext *ctx = avctx->priv_data;

    const uint8_t *buf = avpkt->data;

    int buf_size = avpkt->size;

    AVSubtitle *sub = data;

    int is_menu;



    if (ctx->buf_size) {

        int ret = append_to_cached_buf(avctx, buf, buf_size);

        if (ret < 0) {

            *data_size = 0;

            return ret;

        }

        buf = ctx->buf;

        buf_size = ctx->buf_size;

    }



    is_menu = decode_dvd_subtitles(ctx, sub, buf, buf_size);

    if (is_menu == AVERROR(EAGAIN)) {

        *data_size = 0;

        return append_to_cached_buf(avctx, buf, buf_size);

    }



    if (is_menu < 0) {

    no_subtitle:

        reset_rects(sub);

        *data_size = 0;



        return buf_size;

    }

    if (!is_menu && find_smallest_bounding_rectangle(sub) == 0)

        goto no_subtitle;



    if (ctx->forced_subs_only && !(sub->rects[0]->flags & AV_SUBTITLE_FLAG_FORCED))

        goto no_subtitle;



#if defined(DEBUG)

    {

    char ppm_name[32];



    snprintf(ppm_name, sizeof(ppm_name), "/tmp/%05d.ppm", ctx->sub_id++);

    ff_dlog(NULL, "start=%d ms end =%d ms\n",

            sub->start_display_time,

            sub->end_display_time);

    ppm_save(ppm_name, sub->rects[0]->pict.data[0],

             sub->rects[0]->w, sub->rects[0]->h, (uint32_t*) sub->rects[0]->pict.data[1]);

    }

#endif



    ctx->buf_size = 0;

    *data_size = 1;

    return buf_size;

}

static int FUNC_0(AVCodecContext *VAR_0,

                         void *VAR_1, int *VAR_2,

                         AVPacket *VAR_3)

{

    DVDSubContext *ctx = VAR_0->priv_data;

    const uint8_t *VAR_4 = VAR_3->VAR_1;

    int VAR_5 = VAR_3->size;

    AVSubtitle *sub = VAR_1;

    int VAR_6;



    if (ctx->VAR_5) {

        int VAR_7 = append_to_cached_buf(VAR_0, VAR_4, VAR_5);

        if (VAR_7 < 0) {

            *VAR_2 = 0;

            return VAR_7;

        }

        VAR_4 = ctx->VAR_4;

        VAR_5 = ctx->VAR_5;

    }



    VAR_6 = decode_dvd_subtitles(ctx, sub, VAR_4, VAR_5);

    if (VAR_6 == AVERROR(EAGAIN)) {

        *VAR_2 = 0;

        return append_to_cached_buf(VAR_0, VAR_4, VAR_5);

    }



    if (VAR_6 < 0) {

    no_subtitle:

        reset_rects(sub);

        *VAR_2 = 0;



        return VAR_5;

    }

    if (!VAR_6 && find_smallest_bounding_rectangle(sub) == 0)

        goto no_subtitle;



    if (ctx->forced_subs_only && !(sub->rects[0]->flags & AV_SUBTITLE_FLAG_FORCED))

        goto no_subtitle;



#if defined(DEBUG)

    {

    char ppm_name[32];



    snprintf(ppm_name, sizeof(ppm_name), "/tmp/%05d.ppm", ctx->sub_id++);

    ff_dlog(NULL, "start=%d ms end =%d ms\n",

            sub->start_display_time,

            sub->end_display_time);

    ppm_save(ppm_name, sub->rects[0]->pict.VAR_1[0],

             sub->rects[0]->w, sub->rects[0]->h, (uint32_t*) sub->rects[0]->pict.VAR_1[1]);

    }

#endif



    ctx->VAR_5 = 0;

    *VAR_2 = 1;

    return VAR_5;

}

static int FUNC_0(AVCodecContext *VAR_0,
void *VAR_1, int *VAR_2,
AVPacket *VAR_3)
{ DVDSubContext *ctx = VAR_0->priv_data; const uint8_t *VAR_4 = VAR_3->VAR_1; int VAR_5 = VAR_3->size; AVSubtitle *sub = VAR_1; int VAR_6; if (ctx->VAR_5) { int VAR_7 = append_to_cached_buf(VAR_0, VAR_4, VAR_5); if (VAR_7 < 0) { *VAR_2 = 0; return VAR_7; } VAR_4 = ctx->VAR_4; VAR_5 = ctx->VAR_5; } VAR_6 = decode_dvd_subtitles(ctx, sub, VAR_4, VAR_5); if (VAR_6 == AVERROR(EAGAIN)) { *VAR_2 = 0; return append_to_cached_buf(VAR_0, VAR_4, VAR_5); } if (VAR_6 < 0) { no_subtitle:
reset_rects(sub); *VAR_2 = 0; return VAR_5; } if (!VAR_6 && find_smallest_bounding_rectangle(sub) == 0)
goto no_subtitle; if (ctx->forced_subs_only && !(sub->rects[0]->flags & AV_SUBTITLE_FLAG_FORCED))
goto no_subtitle; #if defined(DEBUG)
{ char ppm_name[32]; snprintf(ppm_name, sizeof(ppm_name), "/tmp/%05d.ppm", ctx->sub_id++); ff_dlog(NULL, "start=%d ms end =%d ms\n",
sub->start_display_time,
sub->end_display_time); ppm_save(ppm_name, sub->rects[0]->pict.VAR_1[0],
sub->rects[0]->w, sub->rects[0]->h, (uint32_t*) sub->rects[0]->pict.VAR_1[1]); } #endif
ctx->VAR_5 = 0; *VAR_2 = 1; return VAR_5; }