From 0cdb8062afff6bd50c028bb46bfe91c2bf56b52c Mon Sep 17 00:00:00 2001 From: Martin Pulec Date: Tue, 20 May 2014 10:52:00 +0200 Subject: [PATCH] Decklink audio playback: fixed channel multiplication --- src/audio/playback/decklink.cpp | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/src/audio/playback/decklink.cpp b/src/audio/playback/decklink.cpp index 0b24ecf6e..cc0479270 100644 --- a/src/audio/playback/decklink.cpp +++ b/src/audio/playback/decklink.cpp @@ -423,28 +423,34 @@ void decklink_put_frame(void *state, struct audio_frame *frame) #else unsigned int sampleFramesWritten; #endif + char *data = frame->data; + // tmp_frame is used if we need to perform 1->2 channel multiplication + struct audio_frame tmp_frame; + tmp_frame.data = NULL; - /* we got probably count that cannot be played directly (probably 1) */ + /* we got probably channel count that cannot be played directly (probably 1) */ if(s->output_audio_channel_count != s->audio_desc.ch_count) { - assert(s->audio_desc.ch_count == 1); /* only reasonable value so far */ - if (sampleFrameCount * s->output_audio_channel_count - * frame->bps > frame->max_size) { - fprintf(stderr, "[decklink] audio buffer overflow!\n"); - sampleFrameCount = frame->max_size / - (s->output_audio_channel_count * frame->bps); - frame->data_len = sampleFrameCount * - (frame->ch_count * frame->bps); - } + assert(s->audio_desc.ch_count == 1); /* only supported value so far */ + memcpy(&tmp_frame, frame, sizeof(tmp_frame)); + // allocate enough space to hold resulting data + tmp_frame.max_size = sampleFrameCount * s->output_audio_channel_count + * frame->bps; + tmp_frame.data = (char *) malloc(tmp_frame.max_size); + memcpy(tmp_frame.data, frame->data, frame->data_len); - audio_frame_multiply_channel(frame, + audio_frame_multiply_channel(&tmp_frame, s->output_audio_channel_count); + + data = tmp_frame.data; } - s->deckLinkOutput->ScheduleAudioSamples (frame->data, sampleFrameCount, 0, + s->deckLinkOutput->ScheduleAudioSamples (data, sampleFrameCount, 0, 0, &sampleFramesWritten); if(sampleFramesWritten != sampleFrameCount) fprintf(stderr, "[decklink] audio buffer underflow!\n"); + free(tmp_frame.data); + } int decklink_reconfigure(void *state, int quant_samples, int channels,