]> git.sesse.net Git - nageru/commitdiff
Send the audio format explicitly down, not just the ID.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Sat, 27 Feb 2016 15:08:01 +0000 (16:08 +0100)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Sat, 27 Feb 2016 15:08:01 +0000 (16:08 +0100)
bmusb
decklink_capture.cpp
mixer.cpp
mixer.h

diff --git a/bmusb b/bmusb
index b3aaee8df3039891d79f4f673e6a8050d3fb65b5..30a75fd8110601c89ecc7c1a0832a96878917cd4 160000 (submodule)
--- a/bmusb
+++ b/bmusb
@@ -1 +1 @@
-Subproject commit b3aaee8df3039891d79f4f673e6a8050d3fb65b5
+Subproject commit 30a75fd8110601c89ecc7c1a0832a96878917cd4
index e7f8eba0a16531c7341619be0cb2e8f7541b583a..6680de1c57be8467b42077939eab1ba5535c8ce5 100644 (file)
@@ -149,6 +149,7 @@ HRESULT STDMETHODCALLTYPE DeckLinkCapture::VideoInputFrameArrived(
 
        FrameAllocator::Frame current_video_frame, current_audio_frame;
        VideoFormat video_format;
+       AudioFormat audio_format;
 
        if (video_frame) {
                video_format.has_signal = !(video_frame->GetFlags() & bmdFrameHasNoInputSource);
@@ -174,12 +175,27 @@ HRESULT STDMETHODCALLTYPE DeckLinkCapture::VideoInputFrameArrived(
                }
        }
 
+       if (audio_frame) {
+               int num_samples = audio_frame->GetSampleFrameCount();
+
+               current_audio_frame = audio_frame_allocator->alloc_frame();
+               if (current_audio_frame.data != nullptr) {
+                       const uint8_t *frame_bytes;
+                       audio_frame->GetBytes((void **)&frame_bytes);
+
+                       memcpy(current_audio_frame.data, frame_bytes, sizeof(int32_t) * 2 * num_samples);
+
+                       audio_format.bits_per_sample = 32;
+                       audio_format.num_channels = 2;
+               }
+       }
+
        if (current_video_frame.data != nullptr || current_audio_frame.data != nullptr) {
                // TODO: Put into a queue and put into a dequeue thread, if the
                // BlackMagic drivers don't already do that for us?
                frame_callback(timecode,
                        current_video_frame, /*video_offset=*/0, video_format,
-                       current_audio_frame, /*audio_offset=*/0, 0x0000);
+                       current_audio_frame, /*audio_offset=*/0, audio_format);
        }
 
        timecode++;
index 3b602bfb07597d41fefc0e213b66d496799a5a23..e8c9a758ad4f6c25bd6fb144cc565c1234ff7999 100644 (file)
--- a/mixer.cpp
+++ b/mixer.cpp
@@ -310,7 +310,7 @@ void deinterleave_samples(const vector<float> &in, vector<float> *out_l, vector<
 
 void Mixer::bm_frame(unsigned card_index, uint16_t timecode,
                      FrameAllocator::Frame video_frame, size_t video_offset, VideoFormat video_format,
-                    FrameAllocator::Frame audio_frame, size_t audio_offset, uint16_t audio_format)
+                    FrameAllocator::Frame audio_frame, size_t audio_offset, AudioFormat audio_format)
 {
        CaptureCard *card = &cards[card_index];
 
@@ -339,7 +339,14 @@ void Mixer::bm_frame(unsigned card_index, uint16_t timecode,
        // Convert the audio to stereo fp32 and add it.
        vector<float> audio;
        audio.resize(num_samples * 2);
-       convert_fixed24_to_fp32(&audio[0], 2, audio_frame.data + audio_offset, 8, num_samples);
+       switch (audio_format.bits_per_sample) {
+       case 24:
+               convert_fixed24_to_fp32(&audio[0], 2, audio_frame.data + audio_offset, audio_format.num_channels, num_samples);
+               break;
+       default:
+               fprintf(stderr, "Cannot handle audio with %u bits per sample\n", audio_format.bits_per_sample);
+               assert(false);
+       }
 
        // Add the audio.
        {
diff --git a/mixer.h b/mixer.h
index 8f37f3840db6ff60ec06c16385424972a7e3889e..00b10f8c5a056ee77ed5c7e13000f83ec32414e8 100644 (file)
--- a/mixer.h
+++ b/mixer.h
@@ -245,7 +245,7 @@ private:
        void configure_card(unsigned card_index, const QSurfaceFormat &format, CaptureInterface *capture);
        void bm_frame(unsigned card_index, uint16_t timecode,
                FrameAllocator::Frame video_frame, size_t video_offset, VideoFormat video_format,
-               FrameAllocator::Frame audio_frame, size_t audio_offset, uint16_t audio_format);
+               FrameAllocator::Frame audio_frame, size_t audio_offset, AudioFormat audio_format);
        void place_rectangle(movit::Effect *resample_effect, movit::Effect *padding_effect, float x0, float y0, float x1, float y1);
        void thread_func();
        void audio_thread_func();