Re: [FFmpeg-devel] [PATCH 6/6] decklink: Add support for SCTE-104 to decklink capture

2017-11-16 Thread Devin Heitmueller

> On Nov 16, 2017, at 7:35 PM, Derek Buitenhuis  
> wrote:
> 
> On 11/16/2017 6:34 PM, Devin Heitmueller wrote:
>> ---
>> 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(-)
> 
> Needs a version bump.
> 
>> +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;
>> +}
> 
> This is the only error path in the function, so the goto is superfluous.

Yeah, the goto was a product of some refactoring.  I will get rid of it for the 
V2 series.

Thanks,

Devin

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 6/6] decklink: Add support for SCTE-104 to decklink capture

2017-11-16 Thread Derek Buitenhuis
On 11/16/2017 6:34 PM, Devin Heitmueller wrote:
> ---
>  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(-)

Needs a version bump.

> +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;
> +}

This is the only error path in the function, so the goto is superfluous.

- Derek
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH 6/6] decklink: Add support for SCTE-104 to decklink capture

2017-11-16 Thread Devin Heitmueller
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, 100);  /* 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.stream_index = -1;
+for (int i = 0; i <