From c7b4084ed7b6bf5d4cad0309a3adde68a153b7b2 Mon Sep 17 00:00:00 2001
From: tvv <tvv@ws-066.(none)>
Date: Fri, 17 May 2013 14:37:43 +0300
Subject: [PATCH] Fixed processing with teletext descriptor and packets
---
libavformat/mpegts.c | 7 +++++++
libavformat/mpegtsenc.c | 33 ++++++++++++++++++++++++++++++---
2 files changed, 37 insertions(+), 3 deletions(-)
diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c
index 85b5146..da8bba8 100644
|
a
|
b
|
int ff_parse_mpeg2_descriptor(AVFormatContext *fc, AVStream *st, int stream_type
|
| 1365 | 1365 | } |
| 1366 | 1366 | break; |
| 1367 | 1367 | case 0x56: /* DVB teletext descriptor */ |
| | 1368 | /* copy all descriptor's data (ETSI EN 300 468 - 6.2.43) */ |
| | 1369 | if (!st->codec->extradata) { |
| | 1370 | st->codec->extradata = av_malloc(desc_len + FF_INPUT_BUFFER_PADDING_SIZE); |
| | 1371 | st->codec->extradata_size = desc_len; |
| | 1372 | memcpy(st->codec->extradata, *pp, desc_len); |
| | 1373 | } |
| | 1374 | /* parse language in first descriptor */ |
| 1368 | 1375 | language[0] = get8(pp, desc_end); |
| 1369 | 1376 | language[1] = get8(pp, desc_end); |
| 1370 | 1377 | language[2] = get8(pp, desc_end); |
diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c
index 0ddae65..c143619 100644
|
a
|
b
|
static void mpegts_write_pmt(AVFormatContext *s, MpegTSService *service)
|
| 372 | 372 | { |
| 373 | 373 | const char *language; |
| 374 | 374 | language = lang && strlen(lang->value)==3 ? lang->value : "eng"; |
| 375 | | *q++ = 0x59; |
| 376 | | *q++ = 8; |
| | 375 | |
| | 376 | /* write teletext descriptors (ETSI EN 300 468 - 6.2.43) */ |
| | 377 | if (st->codec->codec_id == AV_CODEC_ID_DVB_TELETEXT) { |
| | 378 | if (st->codec->extradata_size != 0) { |
| | 379 | *q++ = 0x56; |
| | 380 | *q++ = st->codec->extradata_size; |
| | 381 | |
| | 382 | memcpy(q, st->codec->extradata, st->codec->extradata_size); |
| | 383 | q += st->codec->extradata_size; |
| | 384 | } |
| | 385 | break; |
| | 386 | } else { |
| | 387 | *q++ = 0x59; |
| | 388 | *q++ = 8; |
| | 389 | } |
| 377 | 390 | *q++ = language[0]; |
| 378 | 391 | *q++ = language[1]; |
| 379 | 392 | *q++ = language[2]; |
| … |
… |
static void mpegts_write_pes(AVFormatContext *s, AVStream *st,
|
| 910 | 923 | } |
| 911 | 924 | if (is_start) { |
| 912 | 925 | int pes_extension = 0; |
| | 926 | int pes_header_stuffing_bytes = 0; |
| 913 | 927 | /* write PES header */ |
| 914 | 928 | *q++ = 0x00; |
| 915 | 929 | *q++ = 0x00; |
| … |
… |
static void mpegts_write_pes(AVFormatContext *s, AVStream *st,
|
| 931 | 945 | *q++ = 0xfd; |
| 932 | 946 | } else { |
| 933 | 947 | *q++ = 0xbd; |
| 934 | | if (st->codec->codec_type == AVMEDIA_TYPE_SUBTITLE) { |
| | 948 | if ((st->codec->codec_type == AVMEDIA_TYPE_SUBTITLE) && |
| | 949 | (st->codec->codec_id != AV_CODEC_ID_DVB_TELETEXT)) { |
| 935 | 950 | private_code = 0x20; |
| 936 | 951 | } |
| 937 | 952 | } |
| … |
… |
static void mpegts_write_pes(AVFormatContext *s, AVStream *st,
|
| 982 | 997 | val |= 0x04; |
| 983 | 998 | *q++ = val; |
| 984 | 999 | *q++ = flags; |
| | 1000 | /* PES header length is always fixed (set to 0x24) for teletext streams (ETSI EN 300 472 - 4.1) */ |
| | 1001 | if ((st->codec->codec_type == AVMEDIA_TYPE_SUBTITLE) && |
| | 1002 | (st->codec->codec_id == AV_CODEC_ID_DVB_TELETEXT)) { |
| | 1003 | pes_header_stuffing_bytes = 0x24 - header_len; |
| | 1004 | header_len = 0x24; |
| | 1005 | } |
| 985 | 1006 | *q++ = header_len; |
| 986 | 1007 | if (pts != AV_NOPTS_VALUE) { |
| 987 | 1008 | write_pts(q, flags >> 6, pts); |
| … |
… |
static void mpegts_write_pes(AVFormatContext *s, AVStream *st,
|
| 1011 | 1032 | *q++ = 0x00 | 0x71; /* for AC3 Audio (specifically on blue-rays) */ |
| 1012 | 1033 | } |
| 1013 | 1034 | |
| | 1035 | if ((st->codec->codec_type == AVMEDIA_TYPE_SUBTITLE) && |
| | 1036 | (st->codec->codec_id == AV_CODEC_ID_DVB_TELETEXT)) { |
| | 1037 | int i; |
| | 1038 | for (i = 0; i < pes_header_stuffing_bytes; i++) |
| | 1039 | *q++ = 0xff; |
| | 1040 | } |
| 1014 | 1041 | |
| 1015 | 1042 | if (private_code != 0) |
| 1016 | 1043 | *q++ = private_code; |