Commit aed032c2 authored by Nicolas George's avatar Nicolas George

dvbsub: fix encoding of termination packets.

The old code generates a termination packet with the same regions as the
start packet and page_state set to "only what changed"; the result is
that the termination packet is decoded as identical to the start packet.

The new code does as found in some DVB broadcasts: produce a packet with
no regions. This is done by expecting num_rects to be 0 rather than
using a flip-flop. ffmpeg.c is updated accordingly.
parent cc650cf0
...@@ -703,6 +703,8 @@ static void do_subtitle_out(AVFormatContext *s, ...@@ -703,6 +703,8 @@ static void do_subtitle_out(AVFormatContext *s,
sub->pts += av_rescale_q(sub->start_display_time, (AVRational){ 1, 1000 }, AV_TIME_BASE_Q); sub->pts += av_rescale_q(sub->start_display_time, (AVRational){ 1, 1000 }, AV_TIME_BASE_Q);
sub->end_display_time -= sub->start_display_time; sub->end_display_time -= sub->start_display_time;
sub->start_display_time = 0; sub->start_display_time = 0;
if (i == 1)
sub->num_rects = 0;
subtitle_out_size = avcodec_encode_subtitle(enc, subtitle_out, subtitle_out_size = avcodec_encode_subtitle(enc, subtitle_out,
subtitle_out_max_size, sub); subtitle_out_max_size, sub);
if (subtitle_out_size < 0) { if (subtitle_out_size < 0) {
......
...@@ -23,7 +23,6 @@ ...@@ -23,7 +23,6 @@
#include "libavutil/colorspace.h" #include "libavutil/colorspace.h"
typedef struct DVBSubtitleContext { typedef struct DVBSubtitleContext {
int hide_state;
int object_version; int object_version;
} DVBSubtitleContext; } DVBSubtitleContext;
...@@ -259,7 +258,7 @@ static int encode_dvb_subtitles(DVBSubtitleContext *s, ...@@ -259,7 +258,7 @@ static int encode_dvb_subtitles(DVBSubtitleContext *s,
page_id = 1; page_id = 1;
if (h->num_rects == 0 || h->rects == NULL) if (h->num_rects && h->rects == NULL)
return -1; return -1;
*q++ = 0x00; /* subtitle_stream_id */ *q++ = 0x00; /* subtitle_stream_id */
...@@ -272,10 +271,7 @@ static int encode_dvb_subtitles(DVBSubtitleContext *s, ...@@ -272,10 +271,7 @@ static int encode_dvb_subtitles(DVBSubtitleContext *s,
pseg_len = q; pseg_len = q;
q += 2; /* segment length */ q += 2; /* segment length */
*q++ = 30; /* page_timeout (seconds) */ *q++ = 30; /* page_timeout (seconds) */
if (s->hide_state) page_state = 2; /* mode change */
page_state = 0; /* normal case */
else
page_state = 2; /* mode change */
/* page_version = 0 + page_state */ /* page_version = 0 + page_state */
*q++ = (s->object_version << 4) | (page_state << 2) | 3; *q++ = (s->object_version << 4) | (page_state << 2) | 3;
...@@ -288,7 +284,7 @@ static int encode_dvb_subtitles(DVBSubtitleContext *s, ...@@ -288,7 +284,7 @@ static int encode_dvb_subtitles(DVBSubtitleContext *s,
bytestream_put_be16(&pseg_len, q - pseg_len - 2); bytestream_put_be16(&pseg_len, q - pseg_len - 2);
if (!s->hide_state) { if (h->num_rects) {
for (clut_id = 0; clut_id < h->num_rects; clut_id++) { for (clut_id = 0; clut_id < h->num_rects; clut_id++) {
/* CLUT segment */ /* CLUT segment */
...@@ -366,18 +362,17 @@ static int encode_dvb_subtitles(DVBSubtitleContext *s, ...@@ -366,18 +362,17 @@ static int encode_dvb_subtitles(DVBSubtitleContext *s,
*q++ = 0; /* 8 bit fill colors */ *q++ = 0; /* 8 bit fill colors */
*q++ = 0x03; /* 4 bit and 2 bit fill colors */ *q++ = 0x03; /* 4 bit and 2 bit fill colors */
if (!s->hide_state) { /* TODO reindent */
bytestream_put_be16(&q, region_id); /* object_id == region_id */ bytestream_put_be16(&q, region_id); /* object_id == region_id */
*q++ = (0 << 6) | (0 << 4); *q++ = (0 << 6) | (0 << 4);
*q++ = 0; *q++ = 0;
*q++ = 0xf0; *q++ = 0xf0;
*q++ = 0; *q++ = 0;
}
bytestream_put_be16(&pseg_len, q - pseg_len - 2); bytestream_put_be16(&pseg_len, q - pseg_len - 2);
} }
if (!s->hide_state) { if (h->num_rects) {
for (object_id = 0; object_id < h->num_rects; object_id++) { for (object_id = 0; object_id < h->num_rects; object_id++) {
void (*dvb_encode_rle)(uint8_t **pq, void (*dvb_encode_rle)(uint8_t **pq,
...@@ -446,7 +441,6 @@ static int encode_dvb_subtitles(DVBSubtitleContext *s, ...@@ -446,7 +441,6 @@ static int encode_dvb_subtitles(DVBSubtitleContext *s,
*q++ = 0xff; /* end of PES data */ *q++ = 0xff; /* end of PES data */
s->object_version = (s->object_version + 1) & 0xf; s->object_version = (s->object_version + 1) & 0xf;
s->hide_state = !s->hide_state;
return q - outbuf; return q - outbuf;
} }
......
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