From 931856a26761ae817f1cc60f73346ae718a38b1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Reimar=20D=C3=B6ffinger?= Date: Sat, 6 Nov 2010 16:46:03 +0000 Subject: [PATCH] Improve PGS parsing: the "state" field is not relevant to us, the object number is, it determines whether we should continue parsing the presentation description and whether we should clear the subtitles on the next display command. Based on patch by Mark Goodman [mark goodman gmail com] Originally committed as revision 25682 to svn://svn.ffmpeg.org/ffmpeg/trunk --- libavcodec/pgssubdec.c | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/libavcodec/pgssubdec.c b/libavcodec/pgssubdec.c index 4b41d6daa3..fb0d56f980 100644 --- a/libavcodec/pgssubdec.c +++ b/libavcodec/pgssubdec.c @@ -46,6 +46,7 @@ typedef struct PGSSubPresentation { int x; int y; int id_number; + int object_number; } PGSSubPresentation; typedef struct PGSSubPicture { @@ -255,7 +256,6 @@ static void parse_palette_segment(AVCodecContext *avctx, * @param buf_size size of packet to process * @todo TODO: Implement cropping * @todo TODO: Implement forcing of subtitles - * @todo TODO: Blanking of subtitle */ static void parse_presentation_segment(AVCodecContext *avctx, const uint8_t *buf, int buf_size) @@ -263,7 +263,6 @@ static void parse_presentation_segment(AVCodecContext *avctx, PGSSubContext *ctx = avctx->priv_data; int x, y; - uint8_t block; int w = bytestream_get_be16(&buf); int h = bytestream_get_be16(&buf); @@ -278,19 +277,25 @@ static void parse_presentation_segment(AVCodecContext *avctx, ctx->presentation.id_number = bytestream_get_be16(&buf); - /* Next byte is the state. */ - block = bytestream_get_byte(&buf);; - if (block == 0x80) { /* - * Skip 7 bytes of unknown: + * Skip 3 bytes of unknown: + * state * palette_update_flag (0x80), * palette_id_to_use, - * Object Number (if > 0 determines if more data to process), + */ + buf += 3; + + ctx->presentation.object_number = bytestream_get_byte(&buf); + if (!ctx->presentation.object_number) + return; + + /* + * Skip 4 bytes of unknown: * object_id_ref (2 bytes), * window_id_ref, * composition_flag (0x80 - object cropped, 0x40 - object forced) */ - buf += 7; + buf += 4; x = bytestream_get_be16(&buf); y = bytestream_get_be16(&buf); @@ -308,13 +313,6 @@ static void parse_presentation_segment(AVCodecContext *avctx, /* Fill in dimensions */ ctx->presentation.x = x; ctx->presentation.y = y; - } else if (block == 0x00) { - /* TODO: Blank context as subtitle should not be displayed. - * If the subtitle is blanked now the subtitle is not - * on screen long enough to read, due to a delay in - * initial display timing. - */ - } } /** @@ -345,6 +343,10 @@ static int display_end_segment(AVCodecContext *avctx, void *data, */ memset(sub, 0, sizeof(*sub)); + // Blank if last object_number was 0. + // Note that this may be wrong for more complex subtitles. + if (!ctx->presentation.object_number) + return 1; sub->start_display_time = 0; sub->end_display_time = 20000; sub->format = 0;