From patchwork Thu Nov 16 18:34:17 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Devin Heitmueller X-Patchwork-Id: 6127 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.161.94 with SMTP id m30csp6150159jah; Thu, 16 Nov 2017 10:35:32 -0800 (PST) X-Google-Smtp-Source: AGs4zMZPOVK+qsSsR6p6Kv4HWyx8gRr6wiSNufJ63ks1UHQFg7HeIgtS74jqKZpF1MRioAt6v4wf X-Received: by 10.223.135.121 with SMTP id 54mr2257388wrz.160.1510857332861; Thu, 16 Nov 2017 10:35:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510857332; cv=none; d=google.com; s=arc-20160816; b=p5SZPlbCkL+FQI9yPqfmwpVKS9xczDATfCHFMeshvnq4NuaZQ9LlS1igg/gVJqcL7z /J3B+TfHp004aBKrljZE5UPcAHV5Mh1TLDX9+sO8ARjmOROe8K+0Crf6YkJ3omIyAVWp 5iEIEjagBdHdDYdOyGQlZtY5X+9wd+gUOes8kLsdIPlwdsKVSqpYZeahFaKa2BwkI0Ge 5rtmOuLSek9A03Zk2GGyYM25MkRTmwE1AD5aQubPC2YNaXlOLuGRAzfxQ755qtDWL3IF MYyKIop1EPDooqzkcpKLG9e1GxbizpJ9qC7frnIA+FRltjM/zfGKQ4sPYQS6f0STVLpN tC1g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:message-id:date :to:from:delivered-to:arc-authentication-results; bh=FASxWQVZuH4nZWBQ/pHFqzXI4uj7/FUaDHd1QUKOWeU=; b=1Fg+ZVnGtv8Z0tOVrzHTVHkMFOP/agWcKnywLrz2RGyN6nJW/UleSvlV3QI95ulC8F mt5hP9UBR0m/ZnqnlroFWKYSWTaOHvLFjLTOf13yQSos/oQCLkMzI7XXERVW8K7R4uVh 9pzfWIUQ9lpH5o1ReCh58+R/ZiamkIMGvmCU6MFnfBpdbdP5uPSyujBfxFlv422g96tw NAwRP3NJdGBT2rLnfiiOZFwkL8aezErK+0xPiGcqQJw8pqvXn9Elm5VxheSq6j3Hhyqo Yr16DapOspKHi2rnyqsGocDK8AlhUYonUFaBisx9yMXc4+8QNCXy9Ulw+SvqDOnrXuF/ +DOQ== ARC-Authentication-Results: i=1; mx.google.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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id k1si1286245wrh.398.2017.11.16.10.35.32; Thu, 16 Nov 2017 10:35:32 -0800 (PST) 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; 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 802C168A08E; Thu, 16 Nov 2017 20:34:24 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from was-smtp1.livetimenet.net (50-206-97-56-static.hfc.comcastbusiness.net [50.206.97.56]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id B1BBB680670 for ; Thu, 16 Nov 2017 20:34:17 +0200 (EET) Received: by was-smtp1.livetimenet.net with esmtpsa (TLSv1:AES128-SHA:128) (Exim 4.84_2) (envelope-from ) id 1eFOzf-0002o7-QY; Thu, 16 Nov 2017 13:34:32 -0500 From: Devin Heitmueller To: ffmpeg-devel@ffmpeg.org Date: Thu, 16 Nov 2017 13:34:17 -0500 Message-Id: <20171116183417.93073-7-dheitmueller@ltnglobal.com> X-Mailer: git-send-email 2.13.2 In-Reply-To: <20171116183417.93073-1-dheitmueller@ltnglobal.com> References: <20171116183417.93073-1-dheitmueller@ltnglobal.com> X-Spam-Score: -1.9 (-) Subject: [FFmpeg-devel] [PATCH 6/6] decklink: Add support for SCTE-104 to decklink capture 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: jgreen@ltnglobal.com, Devin Heitmueller MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Make use of libklvanc to parse SCTE-104 packets and announce them as a new stream. Right now we just pass the payload straight through, but once this is hoooked into libklscte35 we'll be able to generate SCTE-35 messages in the MPEG TS stream. Note that this feature needs to be explicitly enabled by the user through the "-enable_scte_104" option, since we cannot autodetect the presence of SCTE-104 (because unlike with 708/AFD messages are not set except when trigger occurs, thus the stream wouldn't get created during the read_header phase). Signed-off-by: Devin Heitmueller --- libavcodec/avcodec.h | 1 + libavcodec/codec_desc.c | 6 ++++ libavdevice/decklink_common.h | 6 ++++ libavdevice/decklink_common_c.h | 1 + libavdevice/decklink_dec.cpp | 64 ++++++++++++++++++++++++++++++++++++++++- libavdevice/decklink_dec_c.c | 1 + 6 files changed, 78 insertions(+), 1 deletion(-) diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index 6981f07..453b6be 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -667,6 +667,7 @@ enum AVCodecID { AV_CODEC_ID_TTF = 0x18000, AV_CODEC_ID_SCTE_35, ///< Contain timestamp estimated through PCR of program stream. + AV_CODEC_ID_SCTE_104, AV_CODEC_ID_BINTEXT = 0x18800, AV_CODEC_ID_XBIN, AV_CODEC_ID_IDF, diff --git a/libavcodec/codec_desc.c b/libavcodec/codec_desc.c index c3688de..e198985 100644 --- a/libavcodec/codec_desc.c +++ b/libavcodec/codec_desc.c @@ -3103,6 +3103,12 @@ static const AVCodecDescriptor codec_descriptors[] = { .name = "scte_35", .long_name = NULL_IF_CONFIG_SMALL("SCTE 35 Message Queue"), }, + { + .id = AV_CODEC_ID_SCTE_104, + .type = AVMEDIA_TYPE_DATA, + .name = "scte_104", + .long_name = NULL_IF_CONFIG_SMALL("SCTE 104 Digital Program Insertion"), + }, /* deprecated codec ids */ }; diff --git a/libavdevice/decklink_common.h b/libavdevice/decklink_common.h index bbe4deb..3ecdb19 100644 --- a/libavdevice/decklink_common.h +++ b/libavdevice/decklink_common.h @@ -35,6 +35,10 @@ Actual number for any particular model of card may be lower */ #define DECKLINK_MAX_AUDIO_CHANNELS 32 +/* This isn't actually tied to the Blackmagic hardware - it's an arbitrary + number used to size the array of streams */ +#define DECKLINK_MAX_DATA_STREAMS 16 + class decklink_output_callback; class decklink_input_callback; @@ -86,6 +90,8 @@ struct decklink_ctx { unsigned int dropped; AVStream *audio_st[DECKLINK_MAX_AUDIO_CHANNELS]; int num_audio_streams; + AVStream *data_st[DECKLINK_MAX_DATA_STREAMS]; + int num_data_streams; AVStream *video_st; AVStream *teletext_st; uint16_t cdp_sequence_num; diff --git a/libavdevice/decklink_common_c.h b/libavdevice/decklink_common_c.h index 02011ed..cb73ec9 100644 --- a/libavdevice/decklink_common_c.h +++ b/libavdevice/decklink_common_c.h @@ -58,6 +58,7 @@ struct decklink_cctx { char *format_code; int raw_format; int64_t queue_size; + int enable_scte_104; }; #endif /* AVDEVICE_DECKLINK_COMMON_C_H */ diff --git a/libavdevice/decklink_dec.cpp b/libavdevice/decklink_dec.cpp index bea9213..47323b1 100644 --- a/libavdevice/decklink_dec.cpp +++ b/libavdevice/decklink_dec.cpp @@ -670,6 +670,33 @@ error: return ret; } +static int setup_data(AVFormatContext *avctx) +{ + struct decklink_cctx *cctx = (struct decklink_cctx *)avctx->priv_data; + struct decklink_ctx *ctx = (struct decklink_ctx *)cctx->ctx; + AVStream *st; + int ret = 0; + + if (cctx->enable_scte_104) { + st = avformat_new_stream(avctx, NULL); + if (!st) { + av_log(avctx, AV_LOG_ERROR, "Cannot add data stream\n"); + ret = AVERROR(ENOMEM); + goto error; + } + st->codecpar->codec_type = AVMEDIA_TYPE_DATA; + st->time_base.den = ctx->bmd_tb_den; + st->time_base.num = ctx->bmd_tb_num; + st->codecpar->codec_id = AV_CODEC_ID_SCTE_104; + avpriv_set_pts_info(st, 64, 1, 1000000); /* 64 bits pts in us */ + ctx->data_st[ctx->num_data_streams] = st; + ctx->num_data_streams++; + } + +error: + return ret; +} + #if CONFIG_LIBKLVANC /* VANC Callbacks */ struct vanc_cb_ctx { @@ -735,12 +762,44 @@ static int cb_EIA_708B(void *callback_context, struct klvanc_context_s *ctx, return 0; } +static int cb_SCTE_104(void *callback_context, struct klvanc_context_s *ctx, + struct klvanc_packet_scte_104_s *pkt) +{ + struct vanc_cb_ctx *cb_ctx = (struct vanc_cb_ctx *)callback_context; + decklink_cctx *decklink_cctx = (struct decklink_cctx *)cb_ctx->avctx->priv_data; + struct decklink_ctx *decklink_ctx = (struct decklink_ctx *)decklink_cctx->ctx; + AVPacket avpkt; + av_init_packet(&avpkt); + + avpkt.stream_index = -1; + for (int i = 0; i < decklink_ctx->num_data_streams; i++) { + if (decklink_ctx->data_st[i]->codecpar->codec_id = AV_CODEC_ID_SCTE_104) { + avpkt.stream_index = decklink_ctx->data_st[i]->index; + break; + } + } + if (avpkt.stream_index == -1) { + /* SCTE-104 packet received but forwarding is disabled */ + return 0; + } + + avpkt.pts = cb_ctx->pkt->pts; + avpkt.dts = cb_ctx->pkt->dts; + avpkt.data = pkt->payload; + avpkt.size = pkt->payloadLengthBytes; + if (avpacket_queue_put(&decklink_ctx->queue, &avpkt) < 0) { + ++decklink_ctx->dropped; + } + + return 0; +} + static struct klvanc_callbacks_s callbacks = { .afd = cb_AFD, .eia_708b = cb_EIA_708B, .eia_608 = NULL, - .scte_104 = NULL, + .scte_104 = cb_SCTE_104, .all = NULL, .kl_i64le_counter = NULL, }; @@ -1224,6 +1283,9 @@ av_cold int ff_decklink_read_header(AVFormatContext *avctx) ctx->teletext_st = st; } + /* Setup streams. */ + setup_data(avctx); + if (cctx->audio_mode == AUDIO_MODE_DISCRETE) { av_log(avctx, AV_LOG_VERBOSE, "Using %d input audio channels\n", ctx->audio_st[0]->codecpar->channels); result = ctx->dli->EnableAudioInput(bmdAudioSampleRate48kHz, diff --git a/libavdevice/decklink_dec_c.c b/libavdevice/decklink_dec_c.c index d3d8c84..122da08 100644 --- a/libavdevice/decklink_dec_c.c +++ b/libavdevice/decklink_dec_c.c @@ -76,6 +76,7 @@ static const AVOption options[] = { { "draw_bars", "draw bars on signal loss" , OFFSET(draw_bars), AV_OPT_TYPE_BOOL, { .i64 = 1}, 0, 1, DEC }, { "queue_size", "input queue buffer size", OFFSET(queue_size), AV_OPT_TYPE_INT64, { .i64 = (1024 * 1024 * 1024)}, 0, INT64_MAX, DEC }, { "audio_depth", "audio bitdepth (16 or 32)", OFFSET(audio_depth), AV_OPT_TYPE_INT, { .i64 = 16}, 16, 32, DEC }, + { "enable_scte_104", "capture SCTE-104 VANC", OFFSET(enable_scte_104), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, DEC, "enable_scte_104"}, { NULL }, };