| 266 | } |
| 267 | |
| 268 | static int decklink_setup_audio(AVFormatContext *avctx, AVStream *st) |
| 269 | { |
| 270 | struct decklink_cctx *cctx = (struct decklink_cctx *)avctx->priv_data; |
| 271 | struct decklink_ctx *ctx = (struct decklink_ctx *)cctx->ctx; |
| 272 | AVCodecParameters *c = st->codecpar; |
| 273 | |
| 274 | if (ctx->audio) { |
| 275 | av_log(avctx, AV_LOG_ERROR, "Only one audio stream is supported!\n"); |
| 276 | return -1; |
| 277 | } |
| 278 | |
| 279 | if (c->codec_id == AV_CODEC_ID_AC3) { |
| 280 | /* Regardless of the number of channels in the codec, we're only |
| 281 | using 2 SDI audio channels at 48000Hz */ |
| 282 | ctx->channels = 2; |
| 283 | } else if (c->codec_id == AV_CODEC_ID_PCM_S16LE) { |
| 284 | if (c->sample_rate != 48000) { |
| 285 | av_log(avctx, AV_LOG_ERROR, "Unsupported sample rate!" |
| 286 | " Only 48kHz is supported.\n"); |
| 287 | return -1; |
| 288 | } |
| 289 | if (c->ch_layout.nb_channels != 2 && c->ch_layout.nb_channels != 8 && c->ch_layout.nb_channels != 16) { |
| 290 | av_log(avctx, AV_LOG_ERROR, "Unsupported number of channels!" |
| 291 | " Only 2, 8 or 16 channels are supported.\n"); |
| 292 | return -1; |
| 293 | } |
| 294 | ctx->channels = c->ch_layout.nb_channels; |
| 295 | } else { |
| 296 | av_log(avctx, AV_LOG_ERROR, "Unsupported codec specified!" |
| 297 | " Only PCM_S16LE and AC-3 are supported.\n"); |
| 298 | return -1; |
| 299 | } |
| 300 | |
| 301 | if (ctx->dlo->EnableAudioOutput(bmdAudioSampleRate48kHz, |
| 302 | bmdAudioSampleType16bitInteger, |
| 303 | ctx->channels, |
| 304 | bmdAudioOutputStreamTimestamped) != S_OK) { |
| 305 | av_log(avctx, AV_LOG_ERROR, "Could not enable audio output!\n"); |
| 306 | return -1; |
| 307 | } |
| 308 | if (ctx->dlo->BeginAudioPreroll() != S_OK) { |
| 309 | av_log(avctx, AV_LOG_ERROR, "Could not begin audio preroll!\n"); |
| 310 | return -1; |
| 311 | } |
| 312 | |
| 313 | /* The device expects the sample rate to be fixed. */ |
| 314 | avpriv_set_pts_info(st, 64, 1, 48000); |
| 315 | |
| 316 | ctx->audio = 1; |
| 317 | |
| 318 | return 0; |
| 319 | } |
| 320 | |
| 321 | /* Wrap the AC-3 packet into an S337 payload that is in S16LE format which can be easily |
| 322 | injected into the PCM stream. Note: despite the function name, only AC-3 is implemented */ |
no test coverage detected