From patchwork Mon Aug 8 18:45: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: 121 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.140.67 with SMTP id o64csp278465vsd; Mon, 8 Aug 2016 11:51:33 -0700 (PDT) X-Received: by 10.28.27.143 with SMTP id b137mr18836083wmb.12.1470682293760; Mon, 08 Aug 2016 11:51:33 -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 vc6si31341860wjb.157.2016.08.08.11.51.33; Mon, 08 Aug 2016 11:51:33 -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 37E5768A2B8; Mon, 8 Aug 2016 21:51:21 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pa0-f65.google.com (mail-pa0-f65.google.com [209.85.220.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 60DBD68A179 for ; Mon, 8 Aug 2016 21:50:34 +0300 (EEST) Received: by mail-pa0-f65.google.com with SMTP id vy10so5902692pac.0 for ; Mon, 08 Aug 2016 11:50:42 -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=ftOZI5A0f5rV4zV649uHB7r9TdeOgfbe7qcmurqIQAM=; b=LC2a3ELDPncm4r+8l5Mm3qQzcjmL6EZEUilNdxNOIQcTDRxZ7WCqKRPVESYcYIvKLj q6C6T0smRLJ180CpWagKRXWYAySp0pLxXJSdhGvM+a+tnZSsHLApETvXrIUL98H1zBG3 Pxi8Yd3ARZ2acFBbyr0N8+IHxCIPUU614YxYzZ3XZk0oJ8jrnoWHLsF/P2PkG88caOph 5TYwG32X1DDjrFbIjAPsUpQpuxRRCSvNf2yfe5nA63Zo2eMmD1Z9ADoHydq17u6tFSpo ja+D98CUMLvJWm+6W+Vs9eXDgpnjhcBidW3oHiusz4HaNY6f1lgJZM58bAjaP7GNh2eP 8pHQ== 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=ftOZI5A0f5rV4zV649uHB7r9TdeOgfbe7qcmurqIQAM=; b=iHtvt9+XwDZ7fz71KNChyBoyxhcKtEX/Oz/pQ9ynZP2RCPmnGKhrAdwU2fmKc4aOoS 6JourwcZrPQfcOC/i5sVs5ucWuWx6FIBaL95XkooTChPKuP3OcBIhRmBas283rSMHk5h 8D9BZr+IRrAsNwGBFB0KkuZGAq4nJbnWeP0u2Lm/o5C8KEveEy1RAKGCIUbojbR1avT2 1EY84iX4nteyyttylfbV6zo4zGCih8mrL+ap6HEM3s5PcBbcLUalwF2rIoglZszTWQU3 5WGo6AIcu3aBLj1kly4EJqiKjrbxdT7UldKjP3Yv1Pq0ReldCioOADOa2tPo51e/8R4U 4ckA== X-Gm-Message-State: AEkoousF/+3qqwNA9NXu49AnNtHVn5rp7kO9fuBwMsgggHJEpCKUTdJfTvotoNO28UdXfw== X-Received: by 10.66.74.103 with SMTP id s7mr163169760pav.1.1470682240679; Mon, 08 Aug 2016 11:50:40 -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 m24sm49890673pfi.34.2016.08.08.11.50.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 08 Aug 2016 11:50:40 -0700 (PDT) From: Carlos Fernandez Sanz To: ffmpeg-devel@ffmpeg.org Date: Mon, 8 Aug 2016 11:45:37 -0700 Message-Id: <1470681938-18345-2-git-send-email-carlos@ccextractor.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1470681938-18345-1-git-send-email-carlos@ccextractor.org> References: <1470681938-18345-1-git-send-email-carlos@ccextractor.org> Subject: [FFmpeg-devel] [PATCH 1/2] v4 - SCTE 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 MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: Carlos Signed-off-by: carlos --- libavcodec/avcodec.h | 1 + libavcodec/codec_desc.c | 6 ++++++ libavformat/mpegts.c | 43 ++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 49 insertions(+), 1 deletion(-) diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index 3b21537..601ee5c 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -630,6 +630,7 @@ enum AVCodecID { /* other specific kind of codecs (generally used for attachments) */ AV_CODEC_ID_FIRST_UNKNOWN = 0x18000, ///< A dummy ID pointing at the start of various fake codecs. AV_CODEC_ID_TTF = 0x18000, + AV_CODEC_ID_SCTE_35, AV_CODEC_ID_BINTEXT = 0x18800, AV_CODEC_ID_XBIN, diff --git a/libavcodec/codec_desc.c b/libavcodec/codec_desc.c index dea17c9..5c00be0 100644 --- a/libavcodec/codec_desc.c +++ b/libavcodec/codec_desc.c @@ -2950,6 +2950,12 @@ static const AVCodecDescriptor codec_descriptors[] = { .long_name = NULL_IF_CONFIG_SMALL("binary data"), .mime_types= MT("application/octet-stream"), }, + { + .id = AV_CODEC_ID_SCTE_35, + .type = AVMEDIA_TYPE_DATA, + .name = "scte_35", + .long_name = NULL_IF_CONFIG_SMALL("SCTE 35 Message Queue"), + }, /* deprecated codec ids */ }; 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; } }