From patchwork Fri Aug 19 17:45:28 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: 223 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.140.134 with SMTP id o128csp503193vsd; Fri, 19 Aug 2016 10:48:58 -0700 (PDT) X-Received: by 10.28.14.68 with SMTP id 65mr5345519wmo.68.1471628938377; Fri, 19 Aug 2016 10:48:58 -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 u1si7246642wjx.280.2016.08.19.10.48.55; Fri, 19 Aug 2016 10:48:58 -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 D0FC7689C26; Fri, 19 Aug 2016 20:48:44 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pf0-f196.google.com (mail-pf0-f196.google.com [209.85.192.196]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 4F785689B64 for ; Fri, 19 Aug 2016 20:48:02 +0300 (EEST) Received: by mail-pf0-f196.google.com with SMTP id y134so1771791pfg.3 for ; Fri, 19 Aug 2016 10:48:02 -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=cTTvn0A/2nqN/5NpdeCC1YLO1w78Lx/GHPJJTQ1Py1cYgfj8Ckc98xX5h0ylidWhNb vAETlRLE9J5wrqS3XJPlMPgDWAEYwdFZAncU5qODpogi1Ilmlv+4xQ1HOgrogqOQzmoT 0oT7ONhd+DdDbuy9mJfKCdPlxRITjwUaXB8/uMSI//n0Yr3LK7RhI7FJiNWWK4S/LuHA iUaZ15KIXtIFWZPBqcW5J55nEdRoHowS7rYSOQn2VWC7sTs+zvuaxH8j6rf3g4nhVmyP ZtzvRuhbX6R3dH82Bhv8fIiSOPua42PM7//xMZg856glm8VTqPR7OWY8EkSGqyW0oUpk P2+A== 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=TNxx/OfmwEVY9kUPqSq0FyhY2LK+464IpNHuV5zQN+AbKMMHkFFfuBF8/1WR5nCB2e 30tvxTeL6rn4hHH9vBHndEYJzu9qzbqLWadTBA9IhJpqM18VmjqfqOfFwiQ9NcywZbWa lqelFdxqbMMff1KH3QGMQpOtw/TLCjK4s00NQYO2ZbA8SVaQykLjC8jNbJ+RGFQHsy+f tZHGBj6OwX/JTcL+EdSejnEq4k88a6Erw/evFSZtixALSz2Ko9YYVxou3D8gA44Msngs miy8EqJEa2/XpfHVzETx7EndOzo7iibMww3UrCcumDaSrwD7VU/0kocKHttR6aI/gIDx XgRQ== X-Gm-Message-State: AEkoouum4eSfYtOTvJL6sFBxWL7pJAob5V3934mvgeIgGf9c/cYu1/BpC5wfZiJGGiz49Q== X-Received: by 10.98.219.132 with SMTP id f126mr12555174pfg.41.1471628881407; Fri, 19 Aug 2016 10:48:01 -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 m78sm8059448pfj.66.2016.08.19.10.48.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 19 Aug 2016 10:48:00 -0700 (PDT) From: Carlos Fernandez Sanz To: ffmpeg-devel@ffmpeg.org Date: Fri, 19 Aug 2016 10:45:28 -0700 Message-Id: <1471628730-20632-3-git-send-email-carlos@ccextractor.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1471628730-20632-1-git-send-email-carlos@ccextractor.org> References: <1471628730-20632-1-git-send-email-carlos@ccextractor.org> Subject: [FFmpeg-devel] [PATCH 2/4] V7 - 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; } }