Re: [FFmpeg-devel] [PATCH 3/8] decklink: Introduce support for capture of multiple audio streams

2018-01-05 Thread Devin Heitmueller
Hello Matthias,

Thanks for the feedback.  Comments inline:

> On Jan 2, 2018, at 4:52 AM, Matthias Hunstock  wrote:
> 
> Am 29.12.2017 um 19:12 schrieb Devin Heitmueller:
>> To support the existing use case where multi-channel audio can be
>> captured (i.e. 7.1)
> 
> Just to be clear, the current use case is NOT to capture multi-channel
> audio like 7.1. It's just to capture all of the mono SDI channels into
> one FFmpeg-internal audio stream and FFmpeg calls 8 channels "7.1”.

Right.  The existing capture module can capture 2, 8, or 16 mono channels IIRC, 
and they’re all bundled as a single stream.  The underlying channel map is 
unspecified and has to be tweaked through a filter if needed.
> 
> As you already noticed, the audio mapping is far from standardized and
> has to be adapted anyway in most use cases... having said that, I find
> the option value "discrete" misleading. I would expect every channel to
> be in a separate stream when reading that, but I'm not a native english
> speaker. What about e.g. "bundled”?

No objection here.  The term “discrete” is just what the broadcast industry 
uses when sending uncompressed multi-channel audio over SDI (e.g. when dealing 
with 5.1 or 7.1).  That said, even in the “pairs” model I’m introducing it’s 
entirely possible that some of those pairs will be components to a 5.1, so I 
have no objection to using the vague term “bundled” since it boils down to all 
the possible audio channels available from the card.

> 
> Last but not least, I cannot find an update to the documentation in this
> patch ;)

Yup, that is indeed needed.  Will include in next patch.

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


Re: [FFmpeg-devel] [PATCH 3/8] decklink: Introduce support for capture of multiple audio streams

2018-01-05 Thread Devin Heitmueller

>> +if (ctx->max_audio_channels > DECKLINK_MAX_AUDIO_CHANNELS) {
>> +av_log(avctx, AV_LOG_WARNING, "Decklink card reported support for 
>> more channels than ffmpeg supports\n");
> 
> "Decklink" -> "DeckLink", "ffmpeg" -> "FFmpeg".  Also, I think it is 
> preferable to not state "FFmpeg" in this log message, as technically this is 
> in libavdevice.  If, say, libav were to merge your changes into their 
> codebase, then this particular log message would make that annoying.  Could 
> be something as simple as "Max audio channels for DeckLink reduced from %d to 
> %d.\n”.

Ok, no objection

>>  class decklink_output_callback;
>>  class decklink_input_callback;
>>  @@ -71,6 +75,7 @@ struct decklink_ctx {
>>  int bmd_height;
>>  int bmd_field_dominance;
>>  int supports_vanc;
>> +int64_t max_audio_channels;
> 
> Rationale for using an int64_t here when an int would likely be sufficient?  
> I understand that GetInt() takes an int64_t as input, but you could use a 
> temporary int64_t with GetInt() and store the value in a int 
> max_audio_channels.

I was just trying to avoid an intermediate variable and a cast.  Figured the 
added code wasn’t worth the trouble just to save eight bytes on a structure 
that there will likely only ever be one instance of.  No objection to doing 
what you’ve proposed though.

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


Re: [FFmpeg-devel] [PATCH 3/8] decklink: Introduce support for capture of multiple audio streams

2018-01-02 Thread Matthias Hunstock
Am 29.12.2017 um 19:12 schrieb Devin Heitmueller:
> To support the existing use case where multi-channel audio can be
> captured (i.e. 7.1)

Just to be clear, the current use case is NOT to capture multi-channel
audio like 7.1. It's just to capture all of the mono SDI channels into
one FFmpeg-internal audio stream and FFmpeg calls 8 channels "7.1".

As you already noticed, the audio mapping is far from standardized and
has to be adapted anyway in most use cases... having said that, I find
the option value "discrete" misleading. I would expect every channel to
be in a separate stream when reading that, but I'm not a native english
speaker. What about e.g. "bundled"?

Last but not least, I cannot find an update to the documentation in this
patch ;)

Regards
Matthias

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


Re: [FFmpeg-devel] [PATCH 3/8] decklink: Introduce support for capture of multiple audio streams

2017-12-29 Thread Aaron Levinson

On 12/29/2017 10:12 AM, Devin Heitmueller wrote:

Add support for the ability to capture all audio pairs available
to the capture hardware.  Each pair is exposed as a different audio
stream, which matches up with the most common use cases for the
broadcast space (i.e. where there is one stereo pair per audio
language).

To support the existing use case where multi-channel audio can be
captured (i.e. 7.1), we introduced a new configuration option, which
defaults to the existing behavior.
---
  libavdevice/decklink_common.cpp |   9 +++
  libavdevice/decklink_common.h   |   8 ++-
  libavdevice/decklink_common_c.h |   6 ++
  libavdevice/decklink_dec.cpp| 134 +++-
  libavdevice/decklink_dec_c.c|   3 +
  5 files changed, 130 insertions(+), 30 deletions(-)

diff --git a/libavdevice/decklink_common.cpp b/libavdevice/decklink_common.cpp
index ba091dadea..91a626221d 100644
--- a/libavdevice/decklink_common.cpp
+++ b/libavdevice/decklink_common.cpp
@@ -480,5 +480,14 @@ int ff_decklink_init_device(AVFormatContext *avctx, const 
char* name)
  return AVERROR_EXTERNAL;
  }
  
+if (ctx->attr->GetInt(BMDDeckLinkMaximumAudioChannels, >max_audio_channels) != S_OK) {

+av_log(avctx, AV_LOG_WARNING, "Could not determine number of audio 
channels\n");
+ctx->max_audio_channels = 0;
+}
+if (ctx->max_audio_channels > DECKLINK_MAX_AUDIO_CHANNELS) {
+av_log(avctx, AV_LOG_WARNING, "Decklink card reported support for more 
channels than ffmpeg supports\n");


"Decklink" -> "DeckLink", "ffmpeg" -> "FFmpeg".  Also, I think it is 
preferable to not state "FFmpeg" in this log message, as technically 
this is in libavdevice.  If, say, libav were to merge your changes into 
their codebase, then this particular log message would make that 
annoying.  Could be something as simple as "Max audio channels for 
DeckLink reduced from %d to %d.\n".



+ctx->max_audio_channels = DECKLINK_MAX_AUDIO_CHANNELS;
+}
+
  return 0;
  }
diff --git a/libavdevice/decklink_common.h b/libavdevice/decklink_common.h
index 143bbb951a..06b241029e 100644
--- a/libavdevice/decklink_common.h
+++ b/libavdevice/decklink_common.h
@@ -37,6 +37,10 @@
  #define DECKLINK_BOOL bool
  #endif
  
+/* Maximum number of channels possible across variants of Blackmagic cards.

+   Actual number for any particular model of card may be lower */
+#define DECKLINK_MAX_AUDIO_CHANNELS 32
+
  class decklink_output_callback;
  class decklink_input_callback;
  
@@ -71,6 +75,7 @@ struct decklink_ctx {

  int bmd_height;
  int bmd_field_dominance;
  int supports_vanc;
+int64_t max_audio_channels;


Rationale for using an int64_t here when an int would likely be 
sufficient?  I understand that GetInt() takes an int64_t as input, but 
you could use a temporary int64_t with GetInt() and store the value in a 
int max_audio_channels.


  
  /* Capture buffer queue */

  AVPacketQueue queue;
@@ -85,7 +90,8 @@ struct decklink_ctx {
  int64_t last_pts;
  unsigned long frameCount;
  unsigned int dropped;
-AVStream *audio_st;
+AVStream *audio_st[DECKLINK_MAX_AUDIO_CHANNELS];
+int num_audio_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 368ac259e4..02011ed53b 100644
--- a/libavdevice/decklink_common_c.h
+++ b/libavdevice/decklink_common_c.h
@@ -30,6 +30,11 @@ typedef enum DecklinkPtsSource {
  PTS_SRC_WALLCLOCK = 4,
  } DecklinkPtsSource;
  
+typedef enum DecklinkAudioMode {

+AUDIO_MODE_DISCRETE = 0,
+AUDIO_MODE_PAIRS = 1,
+} DecklinkAudioMode;
>   struct decklink_cctx {
  const AVClass *cclass;
  
@@ -42,6 +47,7 @@ struct decklink_cctx {

  double preroll;
  int v210;
  int audio_channels;
+int audio_mode;
  int audio_depth;
  int duplex_mode;
  DecklinkPtsSource audio_pts_source;
diff --git a/libavdevice/decklink_dec.cpp b/libavdevice/decklink_dec.cpp
index 94dae26003..8d4070eecd 100644
--- a/libavdevice/decklink_dec.cpp
+++ b/libavdevice/decklink_dec.cpp
@@ -627,9 +627,54 @@ static int64_t get_pkt_pts(IDeckLinkVideoInputFrame 
*videoFrame,
  return pts;
  }
  
+static int setup_audio(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->audio_mode == AUDIO_MODE_DISCRETE) {
+st = avformat_new_stream(avctx, NULL);
+if (!st) {
+av_log(avctx, AV_LOG_ERROR, "Cannot add stream\n");
+ret = AVERROR(ENOMEM);
+goto error;
+}
+st->codecpar->codec_type  = AVMEDIA_TYPE_AUDIO;
+st->codecpar->codec_id= ctx->audio_depth == 32 ? 
AV_CODEC_ID_PCM_S32LE : AV_CODEC_ID_PCM_S16LE;
+st->codecpar->sample_rate = bmdAudioSampleRate48kHz;
+ 

Re: [FFmpeg-devel] [PATCH 3/8] decklink: Introduce support for capture of multiple audio streams

2017-12-29 Thread Devin Heitmueller

> On Dec 29, 2017, at 4:17 PM, Carl Eugen Hoyos  wrote:
> 
> 2017-12-29 22:14 GMT+01:00 Devin Heitmueller :
>> Hi Carl,
>> 
>>> On Dec 29, 2017, at 3:55 PM, Carl Eugen Hoyos  wrote:
>>> 
>>> 2017-12-29 19:12 GMT+01:00 Devin Heitmueller :
>>> 
 +for (int i = 0; i < ctx->max_audio_channels / 2; i++) {
 +st = avformat_new_stream(avctx, NULL);
 +if (!st) {
 +av_log(avctx, AV_LOG_ERROR, "Cannot add stream %d\n", i);
 +ret = AVERROR(ENOMEM);
 +goto error;
 +}
 +st->codecpar->codec_type  = AVMEDIA_TYPE_AUDIO;
 +st->codecpar->codec_id= ctx->audio_depth == 32 ?
 AV_CODEC_ID_PCM_S32LE : AV_CODEC_ID_PCM_S16LE;
 +st->codecpar->sample_rate = bmdAudioSampleRate48kHz;
 +st->codecpar->channels= 2;
 +avpriv_set_pts_info(st, 64, 1, 100);  /* 64 bits pts in 
 us */
 +ctx->audio_st[i] = st;
 +ctx->num_audio_streams++;
 +}
>>> 
>>> I would have expected that the channel_layout is set to STEREO in
>>> this case, is that not always true?
>> 
>> I’m not sure I understand your comment.  Is there some channel layout
>> property of the codec parameters I should be setting?
> 
> Yes, AVCodecParameters->channel_layout.

Ah, ok.  I will fix that and resubmit in the next series.

Thanks,

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


Re: [FFmpeg-devel] [PATCH 3/8] decklink: Introduce support for capture of multiple audio streams

2017-12-29 Thread Carl Eugen Hoyos
2017-12-29 22:14 GMT+01:00 Devin Heitmueller :
> Hi Carl,
>
>> On Dec 29, 2017, at 3:55 PM, Carl Eugen Hoyos  wrote:
>>
>> 2017-12-29 19:12 GMT+01:00 Devin Heitmueller :
>>
>>> +for (int i = 0; i < ctx->max_audio_channels / 2; i++) {
>>> +st = avformat_new_stream(avctx, NULL);
>>> +if (!st) {
>>> +av_log(avctx, AV_LOG_ERROR, "Cannot add stream %d\n", i);
>>> +ret = AVERROR(ENOMEM);
>>> +goto error;
>>> +}
>>> +st->codecpar->codec_type  = AVMEDIA_TYPE_AUDIO;
>>> +st->codecpar->codec_id= ctx->audio_depth == 32 ?
>>> AV_CODEC_ID_PCM_S32LE : AV_CODEC_ID_PCM_S16LE;
>>> +st->codecpar->sample_rate = bmdAudioSampleRate48kHz;
>>> +st->codecpar->channels= 2;
>>> +avpriv_set_pts_info(st, 64, 1, 100);  /* 64 bits pts in us 
>>> */
>>> +ctx->audio_st[i] = st;
>>> +ctx->num_audio_streams++;
>>> +}
>>
>> I would have expected that the channel_layout is set to STEREO in
>> this case, is that not always true?
>
> I’m not sure I understand your comment.  Is there some channel layout
> property of the codec parameters I should be setting?

Yes, AVCodecParameters->channel_layout.

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


Re: [FFmpeg-devel] [PATCH 3/8] decklink: Introduce support for capture of multiple audio streams

2017-12-29 Thread Devin Heitmueller
Hi Carl,

> On Dec 29, 2017, at 3:55 PM, Carl Eugen Hoyos  wrote:
> 
> 2017-12-29 19:12 GMT+01:00 Devin Heitmueller :
> 
>> +for (int i = 0; i < ctx->max_audio_channels / 2; i++) {
>> +st = avformat_new_stream(avctx, NULL);
>> +if (!st) {
>> +av_log(avctx, AV_LOG_ERROR, "Cannot add stream %d\n", i);
>> +ret = AVERROR(ENOMEM);
>> +goto error;
>> +}
>> +st->codecpar->codec_type  = AVMEDIA_TYPE_AUDIO;
>> +st->codecpar->codec_id= ctx->audio_depth == 32 ?
>> AV_CODEC_ID_PCM_S32LE : AV_CODEC_ID_PCM_S16LE;
>> +st->codecpar->sample_rate = bmdAudioSampleRate48kHz;
>> +st->codecpar->channels= 2;
>> +avpriv_set_pts_info(st, 64, 1, 100);  /* 64 bits pts in us 
>> */
>> +ctx->audio_st[i] = st;
>> +ctx->num_audio_streams++;
>> +}
> 
> I would have expected that the channel_layout is set to STEREO in
> this case, is that not always true?

I’m not sure I understand your comment.  Is there some channel layout property 
of the codec parameters I should be setting?

For the moment, it’s true that we’re only supporting capturing stereo pairs.  
But coming down the pipe is support for compressed audio over SDI pairs, as 
well as more complex layouts which involve discrete 5.1 or 7.1 channels.  This 
patch is a stepping stone to that (I’ve designed it with those use cases in 
mind, even though I haven’t implemented them yet).

For example, it’s not uncommon to have a series of SDI pairs such as the 
following:

SDI channels 1-6 contain discrete 5.1 audio as PCM
SDI channels 7-8 contain a stereo PCM pair with a second language
SDI channels 9-10 contain a compressed 5.1 AC-3 stream.

This patch doesn’t let you do the above, but it’s working in that direction.

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


Re: [FFmpeg-devel] [PATCH 3/8] decklink: Introduce support for capture of multiple audio streams

2017-12-29 Thread Carl Eugen Hoyos
2017-12-29 19:12 GMT+01:00 Devin Heitmueller :

> +for (int i = 0; i < ctx->max_audio_channels / 2; i++) {
> +st = avformat_new_stream(avctx, NULL);
> +if (!st) {
> +av_log(avctx, AV_LOG_ERROR, "Cannot add stream %d\n", i);
> +ret = AVERROR(ENOMEM);
> +goto error;
> +}
> +st->codecpar->codec_type  = AVMEDIA_TYPE_AUDIO;
> +st->codecpar->codec_id= ctx->audio_depth == 32 ?
> AV_CODEC_ID_PCM_S32LE : AV_CODEC_ID_PCM_S16LE;
> +st->codecpar->sample_rate = bmdAudioSampleRate48kHz;
> +st->codecpar->channels= 2;
> +avpriv_set_pts_info(st, 64, 1, 100);  /* 64 bits pts in us */
> +ctx->audio_st[i] = st;
> +ctx->num_audio_streams++;
> +}

I would have expected that the channel_layout is set to STEREO in
this case, is that not always true?

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