Commit 3ec5d8fe authored by Aman Gupta's avatar Aman Gupta Committed by Michael Niedermayer

libavcodec/ccaption_dec: rewrite packet handler as case statement; remove COR3 macro

Signed-off-by: 's avatarMichael Niedermayer <michael@niedermayer.cc>
parent 55ca79f5
...@@ -453,54 +453,69 @@ static void handle_char(CCaptionSubContext *ctx, char hi, char lo, int64_t pts) ...@@ -453,54 +453,69 @@ static void handle_char(CCaptionSubContext *ctx, char hi, char lo, int64_t pts)
static int process_cc608(CCaptionSubContext *ctx, int64_t pts, uint8_t hi, uint8_t lo) static int process_cc608(CCaptionSubContext *ctx, int64_t pts, uint8_t hi, uint8_t lo)
{ {
int ret = 0; int ret = 0;
#define COR3(var, with1, with2, with3) ( (var) == (with1) || (var) == (with2) || (var) == (with3) )
if (hi == ctx->prev_cmd[0] && lo == ctx->prev_cmd[1]) { if (hi == ctx->prev_cmd[0] && lo == ctx->prev_cmd[1]) {
/* ignore redundant command */ /* ignore redundant command */
} else if ( (hi == 0x10 && (lo >= 0x40 || lo <= 0x5f)) || } else if ( (hi == 0x10 && (lo >= 0x40 || lo <= 0x5f)) ||
( (hi >= 0x11 && hi <= 0x17) && (lo >= 0x40 && lo <= 0x7f) ) ) { ( (hi >= 0x11 && hi <= 0x17) && (lo >= 0x40 && lo <= 0x7f) ) ) {
handle_pac(ctx, hi, lo); handle_pac(ctx, hi, lo);
} else if ( ( hi == 0x11 && lo >= 0x20 && lo <= 0x2f ) || } else if ( ( hi == 0x11 && lo >= 0x20 && lo <= 0x2f ) ||
( hi == 0x17 && lo >= 0x2e && lo <= 0x2f) ) { ( hi == 0x17 && lo >= 0x2e && lo <= 0x2f) ) {
handle_textattr(ctx, hi, lo); handle_textattr(ctx, hi, lo);
} else if ( COR3(hi, 0x14, 0x15, 0x1C) && lo == 0x20 ) { } else if (hi == 0x14 || hi == 0x15 || hi == 0x1c) {
/* resume caption loading */ switch (lo) {
ctx->mode = CCMODE_POPON; case 0x20:
} else if ( COR3(hi, 0x14, 0x15, 0x1C) && lo == 0x24 ) { /* resume caption loading */
handle_delete_end_of_row(ctx, hi, lo); ctx->mode = CCMODE_POPON;
} else if ( COR3(hi, 0x14, 0x15, 0x1C) && lo == 0x25 ) { break;
ctx->rollup = 2; case 0x24:
ctx->mode = CCMODE_ROLLUP_2; handle_delete_end_of_row(ctx, hi, lo);
} else if ( COR3(hi, 0x14, 0x15, 0x1C) && lo == 0x26 ) { break;
ctx->rollup = 3; case 0x25:
ctx->mode = CCMODE_ROLLUP_3; ctx->rollup = 2;
} else if ( COR3(hi, 0x14, 0x15, 0x1C) && lo == 0x27 ) { ctx->mode = CCMODE_ROLLUP_2;
ctx->rollup = 4; break;
ctx->mode = CCMODE_ROLLUP_4; case 0x26:
} else if ( COR3(hi, 0x14, 0x15, 0x1C) && lo == 0x29 ) { ctx->rollup = 3;
/* resume direct captioning */ ctx->mode = CCMODE_ROLLUP_3;
ctx->mode = CCMODE_PAINTON; break;
} else if ( COR3(hi, 0x14, 0x15, 0x1C) && lo == 0x2B ) { case 0x27:
/* resume text display */ ctx->rollup = 4;
ctx->mode = CCMODE_TEXT; ctx->mode = CCMODE_ROLLUP_4;
} else if ( COR3(hi, 0x14, 0x15, 0x1C) && lo == 0x2C ) { break;
/* erase display memory */ case 0x29:
ret = handle_edm(ctx, pts); /* resume direct captioning */
} else if ( COR3(hi, 0x14, 0x15, 0x1C) && lo == 0x2D ) { ctx->mode = CCMODE_PAINTON;
/* carriage return */ break;
ff_dlog(ctx, "carriage return\n"); case 0x2b:
reap_screen(ctx, pts); /* resume text display */
roll_up(ctx); ctx->mode = CCMODE_TEXT;
ctx->screen_changed = 1; break;
ctx->cursor_column = 0; case 0x2c:
} else if ( COR3(hi, 0x14, 0x15, 0x1C) && lo == 0x2F ) { /* erase display memory */
/* end of caption */ ret = handle_edm(ctx, pts);
ff_dlog(ctx, "handle_eoc\n"); break;
ret = handle_eoc(ctx, pts); case 0x2d:
/* carriage return */
ff_dlog(ctx, "carriage return\n");
reap_screen(ctx, pts);
roll_up(ctx);
ctx->screen_changed = 1;
ctx->cursor_column = 0;
break;
case 0x2f:
/* end of caption */
ff_dlog(ctx, "handle_eoc\n");
ret = handle_eoc(ctx, pts);
break;
default:
ff_dlog(ctx, "Unknown command 0x%hhx 0x%hhx\n", hi, lo);
break;
}
} else if (hi>=0x20) { } else if (hi>=0x20) {
/* Standard characters (always in pairs) */ /* Standard characters (always in pairs) */
handle_char(ctx, hi, lo, pts); handle_char(ctx, hi, lo, pts);
} else { } else {
/* Ignoring all other non data code */ /* Ignoring all other non data code */
ff_dlog(ctx, "Unknown command 0x%hhx 0x%hhx\n", hi, lo); ff_dlog(ctx, "Unknown command 0x%hhx 0x%hhx\n", hi, lo);
} }
...@@ -508,7 +523,6 @@ static int process_cc608(CCaptionSubContext *ctx, int64_t pts, uint8_t hi, uint8 ...@@ -508,7 +523,6 @@ static int process_cc608(CCaptionSubContext *ctx, int64_t pts, uint8_t hi, uint8
ctx->prev_cmd[0] = hi; ctx->prev_cmd[0] = hi;
ctx->prev_cmd[1] = lo; ctx->prev_cmd[1] = lo;
#undef COR3
return ret; return ret;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment