Ticket #2223: 0001-Fixed-processing-with-teletext-descriptor-and-packet-2.patch

File 0001-Fixed-processing-with-teletext-descriptor-and-packet-2.patch, 4.2 KB (added by Dzmitry, 13 years ago)
  • libavformat/mpegts.c

    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  
    13651365        }
    13661366        break;
    13671367    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 */
    13681375        language[0] = get8(pp, desc_end);
    13691376        language[1] = get8(pp, desc_end);
    13701377        language[2] = get8(pp, desc_end);
  • libavformat/mpegtsenc.c

    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)  
    372372            {
    373373                const char *language;
    374374                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                }
    377390                *q++ = language[0];
    378391                *q++ = language[1];
    379392                *q++ = language[2];
    static void mpegts_write_pes(AVFormatContext *s, AVStream *st,  
    910923        }
    911924        if (is_start) {
    912925            int pes_extension = 0;
     926            int pes_header_stuffing_bytes = 0;
    913927            /* write PES header */
    914928            *q++ = 0x00;
    915929            *q++ = 0x00;
    static void mpegts_write_pes(AVFormatContext *s, AVStream *st,  
    931945                *q++ = 0xfd;
    932946            } else {
    933947                *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)) {
    935950                    private_code = 0x20;
    936951                }
    937952            }
    static void mpegts_write_pes(AVFormatContext *s, AVStream *st,  
    982997                val |= 0x04;
    983998            *q++ = val;
    984999            *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            }
    9851006            *q++ = header_len;
    9861007            if (pts != AV_NOPTS_VALUE) {
    9871008                write_pts(q, flags >> 6, pts);
    static void mpegts_write_pes(AVFormatContext *s, AVStream *st,  
    10111032                      *q++ = 0x00 | 0x71; /* for AC3 Audio (specifically on blue-rays) */
    10121033              }
    10131034
     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            }
    10141041
    10151042            if (private_code != 0)
    10161043                *q++ = private_code;