static int dvbsub_parse_page_segment(AVCodecContext *avctx,
                                     const uint8_t *buf, int buf_size, AVSubtitle *sub, int *got_output)
{
    DVBSubContext *ctx = avctx->priv_data;
    DVBSubRegionDisplay *display;
    DVBSubRegionDisplay *tmp_display_list, **tmp_ptr;
    const uint8_t *buf_end = buf + buf_size;
    int region_id;
    int page_state;
    int timeout;
    int version;
    if (buf_size < 1)
        return AVERROR_INVALIDDATA;
    timeout = *buf++;
    version = ((*buf)>>4) & 15;
    page_state = ((*buf++) >> 2) & 3;
    if (ctx->version == version) {
        return 0;
    ctx->time_out = timeout;
    ctx->version = version;
    ff_dlog(avctx, "Page time out %ds, state %d\n", ctx->time_out, page_state);
    if(ctx->compute_edt == 1)
        save_subtitle_set(avctx, sub, got_output);
    if (page_state == 1 || page_state == 2) {
        delete_regions(ctx);
        delete_objects(ctx);
        delete_cluts(ctx);
    tmp_display_list = ctx->display_list;
    ctx->display_list = NULL;
    while (buf + 5 < buf_end) {
        region_id = *buf++;
        buf += 1;
        display = tmp_display_list;
        tmp_ptr = &tmp_display_list;
            tmp_ptr = &display->next;
        if (!display) {
            display = av_mallocz(sizeof(DVBSubRegionDisplay));
            if (!display)
                return AVERROR(ENOMEM);
        display->region_id = region_id;
        display->x_pos = AV_RB16(buf);
        buf += 2;
        display->y_pos = AV_RB16(buf);
        buf += 2;
        *tmp_ptr = display->next;
        display->next = ctx->display_list;
        ctx->display_list = display;
        ff_dlog(avctx, "Region %d, (%d,%d)\n", region_id, display->x_pos, display->y_pos);
    while (tmp_display_list) {
        display = tmp_display_list;
        tmp_display_list = display->next;
        av_freep(&display);
    return 0;
static int dvbsub_parse_page_segment(AVCodecContext *avctx,
                                     const uint8_t *buf, int buf_size, AVSubtitle *sub, int *got_output)
{
    DVBSubContext *ctx = avctx->priv_data;
    DVBSubRegionDisplay *display;
    DVBSubRegionDisplay *tmp_display_list, **tmp_ptr;
    const uint8_t *buf_end = buf + buf_size;
    int region_id;
    int page_state;
    int timeout;
    int version;
    if (buf_size < 1)
        return AVERROR_INVALIDDATA;
    timeout = *buf++;
    version = ((*buf)>>4) & 15;
    page_state = ((*buf++) >> 2) & 3;
    if (ctx->version == version) {
        return 0;
    ctx->time_out = timeout;
    ctx->version = version;
    ff_dlog(avctx, "Page time out %ds, state %d\n", ctx->time_out, page_state);
    if(ctx->compute_edt == 1)
        save_subtitle_set(avctx, sub, got_output);
    if (page_state == 1 || page_state == 2) {
        delete_regions(ctx);
        delete_objects(ctx);
        delete_cluts(ctx);
    tmp_display_list = ctx->display_list;
    ctx->display_list = NULL;
    while (buf + 5 < buf_end) {
        region_id = *buf++;
        buf += 1;
        display = tmp_display_list;
        tmp_ptr = &tmp_display_list;
            tmp_ptr = &display->next;
        if (!display) {
            display = av_mallocz(sizeof(DVBSubRegionDisplay));
            if (!display)
                return AVERROR(ENOMEM);
        display->region_id = region_id;
        display->x_pos = AV_RB16(buf);
        buf += 2;
        display->y_pos = AV_RB16(buf);
        buf += 2;
        *tmp_ptr = display->next;
        display->next = ctx->display_list;
        ctx->display_list = display;
        ff_dlog(avctx, "Region %d, (%d,%d)\n", region_id, display->x_pos, display->y_pos);
    while (tmp_display_list) {
        display = tmp_display_list;
        tmp_display_list = display->next;
        av_freep(&display);
    return 0;
static int FUNC_0(AVCodecContext *VAR_0,
                                     const uint8_t *VAR_1, int VAR_2, AVSubtitle *VAR_3, int *VAR_4)
{
    DVBSubContext *ctx = VAR_0->priv_data;
    DVBSubRegionDisplay *display;
    DVBSubRegionDisplay *tmp_display_list, **tmp_ptr;
    const uint8_t *VAR_5 = VAR_1 + VAR_2;
    int VAR_6;
    int VAR_7;
    int VAR_8;
    int VAR_9;
    if (VAR_2 < 1)
        return AVERROR_INVALIDDATA;
    VAR_8 = *VAR_1++;
    VAR_9 = ((*VAR_1)>>4) & 15;
    VAR_7 = ((*VAR_1++) >> 2) & 3;
    if (ctx->VAR_9 == VAR_9) {
        return 0;
    ctx->time_out = VAR_8;
    ctx->VAR_9 = VAR_9;
    ff_dlog(VAR_0, "Page time out %ds, state %d\n", ctx->time_out, VAR_7);
    if(ctx->compute_edt == 1)
        save_subtitle_set(VAR_0, VAR_3, VAR_4);
    if (VAR_7 == 1 || VAR_7 == 2) {
        delete_regions(ctx);
        delete_objects(ctx);
        delete_cluts(ctx);
    tmp_display_list = ctx->display_list;
    ctx->display_list = NULL;
    while (VAR_1 + 5 < VAR_5) {
        VAR_6 = *VAR_1++;
        VAR_1 += 1;
        display = tmp_display_list;
        tmp_ptr = &tmp_display_list;
            tmp_ptr = &display->next;
        if (!display) {
            display = av_mallocz(sizeof(DVBSubRegionDisplay));
            if (!display)
                return AVERROR(ENOMEM);
        display->VAR_6 = VAR_6;
        display->x_pos = AV_RB16(VAR_1);
        VAR_1 += 2;
        display->y_pos = AV_RB16(VAR_1);
        VAR_1 += 2;
        *tmp_ptr = display->next;
        display->next = ctx->display_list;
        ctx->display_list = display;
        ff_dlog(VAR_0, "Region %d, (%d,%d)\n", VAR_6, display->x_pos, display->y_pos);
    while (tmp_display_list) {
        display = tmp_display_list;
        tmp_display_list = display->next;
        av_freep(&display);
    return 0;
static int FUNC_0(AVCodecContext *VAR_0,
const uint8_t *VAR_1, int VAR_2, AVSubtitle *VAR_3, int *VAR_4)
{ DVBSubContext *ctx = VAR_0->priv_data; DVBSubRegionDisplay *display; DVBSubRegionDisplay *tmp_display_list, **tmp_ptr; const uint8_t *VAR_5 = VAR_1 + VAR_2; int VAR_6; int VAR_7; int VAR_8; int VAR_9; if (VAR_2 < 1)
return AVERROR_INVALIDDATA; VAR_8 = *VAR_1++; VAR_9 = ((*VAR_1)>>4) & 15; VAR_7 = ((*VAR_1++) >> 2) & 3; if (ctx->VAR_9 == VAR_9) { return 0; ctx->time_out = VAR_8; ctx->VAR_9 = VAR_9; ff_dlog(VAR_0, "Page time out %ds, state %d\n", ctx->time_out, VAR_7); if(ctx->compute_edt == 1)
save_subtitle_set(VAR_0, VAR_3, VAR_4); if (VAR_7 == 1 || VAR_7 == 2) { delete_regions(ctx); delete_objects(ctx); delete_cluts(ctx); tmp_display_list = ctx->display_list; ctx->display_list = NULL; while (VAR_1 + 5 < VAR_5) { VAR_6 = *VAR_1++; VAR_1 += 1; display = tmp_display_list; tmp_ptr = &tmp_display_list; tmp_ptr = &display->next; if (!display) { display = av_mallocz(sizeof(DVBSubRegionDisplay)); if (!display)
return AVERROR(ENOMEM); display->VAR_6 = VAR_6; display->x_pos = AV_RB16(VAR_1); VAR_1 += 2; display->y_pos = AV_RB16(VAR_1); VAR_1 += 2; *tmp_ptr = display->next; display->next = ctx->display_list; ctx->display_list = display; ff_dlog(VAR_0, "Region %d, (%d,%d)\n", VAR_6, display->x_pos, display->y_pos); while (tmp_display_list) { display = tmp_display_list; tmp_display_list = display->next; av_freep(&display); return 0;