From patchwork Sat Oct 1 17:27:30 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlos Fernandez Sanz X-Patchwork-Id: 808 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.140.66 with SMTP id o63csp822193vsd; Sat, 1 Oct 2016 10:30:07 -0700 (PDT) X-Received: by 10.28.23.210 with SMTP id 201mr2645496wmx.58.1475343007500; Sat, 01 Oct 2016 10:30:07 -0700 (PDT) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id r125si10870437wmr.63.2016.10.01.10.30.06; Sat, 01 Oct 2016 10:30:07 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@nisupu-com.20150623.gappssmtp.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 2039D68A0A8; Sat, 1 Oct 2016 20:29:44 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pa0-f67.google.com (mail-pa0-f67.google.com [209.85.220.67]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 5D9BB689F82 for ; Sat, 1 Oct 2016 20:29:37 +0300 (EEST) Received: by mail-pa0-f67.google.com with SMTP id r9so5565798paz.1 for ; Sat, 01 Oct 2016 10:29:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nisupu-com.20150623.gappssmtp.com; s=20150623; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=KARsh04kXT9sCWI8dIt+DG5SmRtoum4ccon3jVMdz0w=; b=G6ZNOaIJEedycI/N0U3YdwVCCWHj3VWtUJI+ul+1hCesgHMbq5oKNjUWmLAUV77tZS ceZShbEqyLuKjHYOyGlrn3Gzn36l/0mkln98O+6Bc4p/88LtSsRRYNEeM/bZcc7Vb92b ywf6sPfiyOmvaWZXwLQbWwlMj6t1lixJb96QVgGX1o/Qojmw0snC9bcSa8wisqq0fn5a P0SU/6vVWZsWmz1Bd75jrUOucKZddj+FAmxYt+OTGyUE77P1RXHfLtO3NmBsxtBAldnC 5aFq2uu7aP7IAxZwuvP2h6hMqDucgPi72G1TAxjd9AqJmL1blG9rehdde3IY36M8RJWm /eLw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=KARsh04kXT9sCWI8dIt+DG5SmRtoum4ccon3jVMdz0w=; b=fqJJ57sTKVihulHnuwIOGz226yrlhSWLBgyka7QmS38Qo8cUPTwNvX59StmYd0SR0m IR41WpI6wTDZLjvUIpxD1pA4DihlioD33gUb+PLd6KT16946/VxyTEqBTu0OQsf+/4Im 5/rvJCi0tVZfrDMqBPFCZLLYz1ZdG9wxFoBPcfQfU3xBIJGAZe8voMIg2FGJEEFigIS3 30aiEwmfLwWpCfLZCgaTZB3dPMfo9TrLFsoGZrHBx3UtoXL9SQdhFQDhJp2dwZk+KyGU AfFypIsmaEIWH33n5fbRoQEIfObppz51BM1j6ccL03iTVzJsGceKl3rgA/ptMKBoNwTF wVPw== X-Gm-Message-State: AA6/9RmiR9NBk+LLdbdcDRnjWvCGsvhsxrDa3Tr3ICHp1FfyDvQbU0shKalyoMpIELa7fQ== X-Received: by 10.66.55.9 with SMTP id n9mr3209374pap.153.1475342989406; Sat, 01 Oct 2016 10:29:49 -0700 (PDT) Received: from carlos-linux-dev.monkeybrains.net (162-245-20-150.PUBLIC.monkeybrains.net. [162.245.20.150]) by smtp.gmail.com with ESMTPSA id 27sm36243720pfr.29.2016.10.01.10.29.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 01 Oct 2016 10:29:49 -0700 (PDT) From: Carlos Fernandez Sanz To: ffmpeg-devel@ffmpeg.org Date: Sat, 1 Oct 2016 10:27:30 -0700 Message-Id: <1475342852-19156-3-git-send-email-carlos@ccextractor.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1475342852-19156-1-git-send-email-carlos@ccextractor.org> References: <1475342852-19156-1-git-send-email-carlos@ccextractor.org> Subject: [FFmpeg-devel] [PATCH 2/4] V12 - SCTE-35 extraction from mpegts X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Carlos Fernandez MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: Carlos Fernandez Signed-off-by: Carlos Fernandez --- libavformat/mpegts.c | 48 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c index b31d233..c13d6d8 100644 --- a/libavformat/mpegts.c +++ b/libavformat/mpegts.c @@ -725,6 +725,12 @@ static const StreamType HDMV_types[] = { { 0 }, }; +/* SCTE types */ +static const StreamType SCTE_types[] = { + { 0x86, AVMEDIA_TYPE_DATA, AV_CODEC_ID_SCTE_35 }, + { 0 }, +}; + /* ATSC ? */ static const StreamType MISC_types[] = { { 0x81, AVMEDIA_TYPE_AUDIO, AV_CODEC_ID_AC3 }, @@ -872,6 +878,13 @@ static void reset_pes_packet_state(PESContext *pes) av_buffer_unref(&pes->buffer); } +static void new_data_packet(const uint8_t *buffer, int len, AVPacket *pkt) +{ + av_init_packet(pkt); + pkt->data = buffer; + pkt->size = len; +} + static int new_pes_packet(PESContext *pes, AVPacket *pkt) { char *sd; @@ -1590,6 +1603,28 @@ static void m4sl_cb(MpegTSFilter *filter, const uint8_t *section, av_free(mp4_descr[i].dec_config_descr); } +static void scte_data_cb(MpegTSFilter *filter, const uint8_t *section, + int section_len) +{ + AVProgram *prg = NULL; + MpegTSContext *ts = filter->u.section_filter.opaque; + + int idx = ff_find_stream_index(ts->stream, filter->pid); + if (idx < 0) + return; + + new_data_packet(section, section_len, ts->pkt); + ts->pkt->stream_index = idx; + prg = av_find_program_from_stream(ts->stream, NULL, idx); + if (prg && prg->pcr_pid != -1 && prg->discard != AVDISCARD_ALL) { + MpegTSFilter *f = ts->pids[prg->pcr_pid]; + if (f && f->last_pcr != -1) + ts->pkt->pts = ts->pkt->dts = f->last_pcr/300; + } + ts->stop_parse = 1; + +} + static const uint8_t opus_coupled_stream_cnt[9] = { 1, 0, 1, 1, 2, 2, 2, 3, 3 }; @@ -1868,6 +1903,12 @@ int ff_parse_mpeg2_descriptor(AVFormatContext *fc, AVStream *st, int stream_type return 0; } +static int is_pes_stream(int stream_type, uint32_t prog_reg_desc) +{ + return !(stream_type == 0x13 || + (stream_type == 0x86 && prog_reg_desc == AV_RL32("CUEI")) ); +} + static void pmt_cb(MpegTSFilter *filter, const uint8_t *section, int section_len) { MpegTSContext *ts = filter->u.section_filter.opaque; @@ -1975,7 +2016,8 @@ static void pmt_cb(MpegTSFilter *filter, const uint8_t *section, int section_len pes->st->id = pes->pid; } st = pes->st; - } else if (stream_type != 0x13) { + + } else if (is_pes_stream(stream_type, prog_reg_desc)) { if (ts->pids[pid]) mpegts_close_filter(ts, ts->pids[pid]); // wrongly added sdt filter probably pes = add_pes_stream(ts, pid, pcr_pid); @@ -1995,6 +2037,10 @@ static void pmt_cb(MpegTSFilter *filter, const uint8_t *section, int section_len goto out; st->id = pid; st->codecpar->codec_type = AVMEDIA_TYPE_DATA; + if (stream_type == 0x86 && prog_reg_desc == AV_RL32("CUEI")) { + mpegts_find_stream_type(st, stream_type, SCTE_types); + mpegts_open_section_filter(ts, pid, scte_data_cb, ts, 1); + } } }