From patchwork Wed Aug 31 17:39:37 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: 377 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.140.134 with SMTP id o128csp498642vsd; Wed, 31 Aug 2016 10:42:13 -0700 (PDT) X-Received: by 10.28.65.84 with SMTP id o81mr10433662wma.83.1472665333406; Wed, 31 Aug 2016 10:42:13 -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 dj10si1002671wjc.294.2016.08.31.10.42.12; Wed, 31 Aug 2016 10:42:13 -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 857EF689BA3; Wed, 31 Aug 2016 20:41:55 +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 0BC38689B97 for ; Wed, 31 Aug 2016 20:41:49 +0300 (EEST) Received: by mail-pf0-f196.google.com with SMTP id i6so3064341pfe.0 for ; Wed, 31 Aug 2016 10:41:56 -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=uVN2isz+4pmmIbMLzD7OA4jw4+WQKrgVUmOX+v5G7gc=; b=LoDTDXQCbjfG8lOjfZcxwAx7C7PJRA0VQ6A6Gry83Tr3ScOIYpa9bAbCRncWUIJweM hAGWXveCXUWAIjih5+a4EgAwsr1Q3vR3jrHzc2n+TXT3puz9l443i/pgW/q59aywtMQh tFyaXPKwOmyizQP+uaTXUoOH6FI+/8BalJ8w3/mGm0qg519aXgnDPS9n31hGNY8oU8Ky vFBEpGfKTcZkXvgfV30jZFoMqnQMY5eiwJG+14BG80W2uKhW96nMS1WHox/+O2KAKAC+ J3oOgZ24KIzgIASO4zrMj9x5xE6rEmjZS0gy5bXpNZ0teCXGYYqp4Au/IlTeEBte523h NDmg== 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=uVN2isz+4pmmIbMLzD7OA4jw4+WQKrgVUmOX+v5G7gc=; b=K5/y56U54FoYGhYUZvLpT4lzv6PBaz3KXQRYnG2rErLfmEnWuzpRrFBpZ8MgABwRy5 BIN0ulM0bwyT0pnyjRmxizGH7MBtAPwWJ+8cJQJOt+zR+279QYPWzDhVT9ZUIlqfDtAp eSonzYiE7pE5h0LtFU5pyR8DVY1/dDoawaL8elThQn1eWJnG+nmV7rOcPIHhAehYs37+ fLkoWkl+HJS1J0iX4BKq3rZ6AF6OQWKPWyuef5Gfi+O9/6ZBKrlA/uq7ZSrbeyxgf7RS oy52DocnInf15N1VtIs6yDITFQC9kiCgA/AaSktjLyU7NNrJNKT5c5jv56PoOtD1FiTV dUCQ== X-Gm-Message-State: AE9vXwNXqwxr+nGfE90kj5KjC2Bd618lGhxAzMcHQmFHIk4klncwLiG3ssMwNZhFgYKl2Q== X-Received: by 10.98.19.214 with SMTP id 83mr19149891pft.117.1472665314155; Wed, 31 Aug 2016 10:41:54 -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 dz13sm1121256pac.44.2016.08.31.10.41.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 31 Aug 2016 10:41:53 -0700 (PDT) From: Carlos Fernandez Sanz To: ffmpeg-devel@ffmpeg.org Date: Wed, 31 Aug 2016 10:39:37 -0700 Message-Id: <1472665179-1373-3-git-send-email-carlos@ccextractor.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1472665179-1373-1-git-send-email-carlos@ccextractor.org> References: <1472665179-1373-1-git-send-email-carlos@ccextractor.org> Subject: [FFmpeg-devel] [PATCH 2/4] V8 - 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 | 50 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c index b31d233..d000269 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,21 @@ static int handle_packet(MpegTSContext *ts, const uint8_t *packet) } } } - + } else if (tss->type == MPEGTS_DATA) { + AVProgram *prg = NULL; + 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; + } + prg = av_find_program_from_stream(ts->stream, prg, idx); + if (prg->pcr_pid != -1 && prg->discard != AVDISCARD_ALL) { + MpegTSFilter *f = ts->pids[prg->pcr_pid]; + if(f) + ts->pkt->pts = ts->pkt->dts = f->last_pcr/300; + } + ts->stop_parse = 1; } else { int ret; // Note: The position here points actually behind the current packet. @@ -2730,6 +2776,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; } }