From patchwork Tue Aug 16 20:10:38 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: 200 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.140.67 with SMTP id o64csp2308159vsd; Tue, 16 Aug 2016 13:15:02 -0700 (PDT) X-Received: by 10.28.125.5 with SMTP id y5mr23099575wmc.103.1471378502319; Tue, 16 Aug 2016 13:15:02 -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 f9si22311204wmg.96.2016.08.16.13.15.01; Tue, 16 Aug 2016 13:15:02 -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 18E87689B6F; Tue, 16 Aug 2016 23:14:49 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pf0-f193.google.com (mail-pf0-f193.google.com [209.85.192.193]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2DF7B689B55 for ; Tue, 16 Aug 2016 23:14:32 +0300 (EEST) Received: by mail-pf0-f193.google.com with SMTP id h186so5947083pfg.2 for ; Tue, 16 Aug 2016 13:14:34 -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=LOmfRq2tNnKFhBuiJ2v4na8CF2MSfnWrMG7CTWWfxjE=; b=N51XxP2tRpScpnA/nzMm6EE/bgxI96oMJbtySiV2OTjct3EGUc3+aVYPzhlAVWs3lW OYj6h4BSJdZpnx3pbdU0DoMHL9nZ1DtYkmv8afPBNNbIaLiC7UCK3TSbQ0AUYvWPB0Cy N0VLMQU92ahAovghJGn5Z2gadbYbAlMIbXf8Lzy65kc3ajl6WKnT0nZnv0Pl3fLUf2ko 1kWfx3W04unF/yfxaYL4CS/NitzdEUDU8ClTuZoj/ZFzdjcHGM12GvJ6f5+LrvjmRSJa vMo0M9sEeYjIRzYDqKHkYnVl+d3fWEX6PzI/bFjYMVsfH6tYMhiAR/aj4q1ipivwARI8 Xabg== 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=LOmfRq2tNnKFhBuiJ2v4na8CF2MSfnWrMG7CTWWfxjE=; b=i/hPFFTuatGkjoVbwJGkudxknwmTo4JPrKFvqBCZo81/cCwYwGyvKvzkwKqlRbn55C bj3Mz2ngGOPEC5bG5hE2e+Cv6TyCdrVxZicw9bqBBV3D3i/xNN1rIWMexx39JNl8pH05 NQajf/t5EFHOJrajcDyB1UUkeDmsEJT4NXpPSXswNePksfDzH8+rMesK7eNeRuZ+Zrh4 kEJK91N65tnen2z2EyGGhyhU5//OiSMEXseXGlVL2LwuC1T1ZzgjNgvmHTJhCWP76NEM IgN8hP++TwCt9nROiIkF9Gy5JCT162UxoMMsSAxB0aN1b2MeX9ucYvxMJAQeXUApSsYL jdAw== X-Gm-Message-State: AEkoousXHB68INrhzZZ3sv0F73ANPHJVMnOx0UdgFXLVop7jZsfxLh3OZbnpKCToa16piA== X-Received: by 10.98.66.209 with SMTP id h78mr15119226pfd.11.1471378472777; Tue, 16 Aug 2016 13:14:32 -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 f84sm41307166pfd.87.2016.08.16.13.14.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 16 Aug 2016 13:14:32 -0700 (PDT) From: Carlos Fernandez Sanz To: ffmpeg-devel@ffmpeg.org Date: Tue, 16 Aug 2016 13:10:38 -0700 Message-Id: <1471378240-22654-3-git-send-email-carlos@ccextractor.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1471378240-22654-1-git-send-email-carlos@ccextractor.org> References: <1471378240-22654-1-git-send-email-carlos@ccextractor.org> Subject: [FFmpeg-devel] [PATCH 2/4] v6 - 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 | 43 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c index b31d233..4185af0 100644 --- a/libavformat/mpegts.c +++ b/libavformat/mpegts.c @@ -57,6 +57,7 @@ enum MpegTSFilterType { MPEGTS_PES, MPEGTS_SECTION, MPEGTS_PCR, + MPEGTS_DATA, }; typedef struct MpegTSFilter MpegTSFilter; @@ -510,6 +511,11 @@ static MpegTSFilter *mpegts_open_pcr_filter(MpegTSContext *ts, unsigned int pid) return mpegts_open_filter(ts, pid, MPEGTS_PCR); } +static MpegTSFilter *mpegts_open_data_filter(MpegTSContext *ts, unsigned int pid) +{ + return mpegts_open_filter(ts, pid, MPEGTS_DATA); +} + static void mpegts_close_filter(MpegTSContext *ts, MpegTSFilter *filter) { int pid; @@ -725,6 +731,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 +884,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; @@ -1975,6 +1994,19 @@ 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 == 0x86 && prog_reg_desc == AV_RL32("CUEI")) { + int idx = ff_find_stream_index(ts->stream, pid); + if (idx >= 0) { + st = ts->stream->streams[idx]; + } else { + st = avformat_new_stream(ts->stream, NULL); + if (!st) + goto out; + st->id = pid; + st->codecpar->codec_type = AVMEDIA_TYPE_DATA; + mpegts_find_stream_type(st, stream_type, SCTE_types); + mpegts_open_data_filter(ts, pid); + } } else if (stream_type != 0x13) { if (ts->pids[pid]) mpegts_close_filter(ts, ts->pids[pid]); // wrongly added sdt filter probably @@ -2317,7 +2349,14 @@ static int handle_packet(MpegTSContext *ts, const uint8_t *packet) } } } - + } else if (tss->type == MPEGTS_DATA) { + int idx = ff_find_stream_index(ts->stream, pid); + p++; + new_data_packet(p,p_end - p, ts->pkt); + if (idx >= 0) { + ts->pkt->stream_index = idx; + } + ts->stop_parse = 1; } else { int ret; // Note: The position here points actually behind the current packet. @@ -2730,6 +2769,8 @@ static int mpegts_read_packet(AVFormatContext *s, AVPacket *pkt) ret = 0; break; } + } else if (ts->pids[i] && ts->pids[i]->type == MPEGTS_DATA) { + return ret; } }