From patchwork Mon Sep 26 17:59:45 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: 735 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.140.66 with SMTP id o63csp2056913vsd; Mon, 26 Sep 2016 11:22:16 -0700 (PDT) X-Received: by 10.194.93.8 with SMTP id cq8mr18759386wjb.10.1474914135845; Mon, 26 Sep 2016 11:22:15 -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 f65si6662010wmi.4.2016.09.26.11.22.14; Mon, 26 Sep 2016 11:22:15 -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 8FC92689C66; Mon, 26 Sep 2016 21:21:55 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pa0-f68.google.com (mail-pa0-f68.google.com [209.85.220.68]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D1598689B45 for ; Mon, 26 Sep 2016 21:21:48 +0300 (EEST) Received: by mail-pa0-f68.google.com with SMTP id my20so9103418pab.3 for ; Mon, 26 Sep 2016 11:22:06 -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=ndAZIAnZ05JzZZLbeWC5s0nZax5xRga4Taw0IXuMWro=; b=Z2EECDr5Tvi1e+u/qIQj3A5qdXtJPXRPBSbhYhC34x7p2NXNBttxrhKmRhPkmHNv6v 8LooJhfDUFU4Ms3xAe76ETSjRHLmU+Hi/lfjrrM+DvXK7g+BNC5hYYxMvSCxasEWKtMr oDAeoqbbmw3t9w0lm+mQhPNJL9lq2MailhrArDboJWcoBoM6rqVlxx0cXJwCc8scZZwP qlQF3G6nZMrGSN7JhfqstNdFvhlZVGWTNkLfKfbJR+7nG7FLm9lB/iRLxMnjUCDuruK+ Q1k+pu0Yc/EtvW/Z8aON/JxwUHxdBPMM9tgOdIFoSZdqZtVM/yMphRsFG6Sa8rur0GTs 9kjA== 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=ndAZIAnZ05JzZZLbeWC5s0nZax5xRga4Taw0IXuMWro=; b=B7aArFUEgv9mazoXiyR2AgS6fkhU2/gKQ+GiHqnnoOrDPsUstb21zsJMxmpCg5UpRb seYp41w5/JZ6CvQC/sKF5ZZaNK300nMUild+amXXGpaZ33eiLcuG21mgrBH4JgHnyblo knktG3oubGBB9XFHrGZqYEGevTSLsnNAaGCF3hyMMFGUu10kFBb+ctBFyPG9dlIuNE7p em5z+j8egYomo0FlGabc3aDU0Kfg7F+vJCpocl9JXk/75nX7Egv3qs55Ee2rxjNUlSyq L2W3IcQoEtH4F6BDhhyPaNvvqsKbEgfB62TusgR3BIxcLR8i3ilYPU8sQnkEmypAvM+Y DYyA== X-Gm-Message-State: AE9vXwOymZolhWzbe4cMd9iFXv6/D4ZV3we5Hot1lgXoEMHDH65A1yl6OXWR65utXgvUsg== X-Received: by 10.67.23.201 with SMTP id ic9mr40437130pad.143.1474913079436; Mon, 26 Sep 2016 11:04:39 -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 f16sm32586760pfd.84.2016.09.26.11.04.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 26 Sep 2016 11:04:39 -0700 (PDT) From: Carlos Fernandez Sanz To: ffmpeg-devel@ffmpeg.org Date: Mon, 26 Sep 2016 10:59:45 -0700 Message-Id: <1474912787-2952-3-git-send-email-carlos@ccextractor.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1474912787-2952-1-git-send-email-carlos@ccextractor.org> References: <1474912787-2952-1-git-send-email-carlos@ccextractor.org> Subject: [FFmpeg-devel] [PATCH 2/4] V10 - 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 | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 62 insertions(+), 2 deletions(-) diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c index b31d233..ad6f141 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,27 @@ 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); + new_data_packet(section, section_len, ts->pkt); + if (idx >= 0) { + 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) + 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 +1902,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 +2015,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); @@ -1994,7 +2035,9 @@ static void pmt_cb(MpegTSFilter *filter, const uint8_t *section, int section_len if (!st) goto out; st->id = pid; + mpegts_find_stream_type(st, stream_type, SCTE_types); st->codecpar->codec_type = AVMEDIA_TYPE_DATA; + mpegts_open_section_filter(ts, pid, scte_data_cb, ts, 1); } } @@ -2317,7 +2360,22 @@ static int handle_packet(MpegTSContext *ts, const uint8_t *packet) } } } - + if(0) { + 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 +2788,8 @@ static int mpegts_read_packet(AVFormatContext *s, AVPacket *pkt) ret = 0; break; } + } else if (ts->pids[i] && ts->pids[i]->type == MPEGTS_SECTION) { + return ret; } }