]> git.sesse.net Git - nageru/blobdiff - mixer.cpp
Make the implausible audio length check work with lower frame rates.
[nageru] / mixer.cpp
index 936a070129352c4b10a80747e740be1e1ebb2dd0..2eb037c4b6d2903ae60399e4c5cba95a34fb2aab 100644 (file)
--- a/mixer.cpp
+++ b/mixer.cpp
@@ -107,7 +107,7 @@ Mixer::Mixer(const QSurfaceFormat &format, unsigned num_cards)
                CaptureCard *card = &cards[card_index];
                card->usb = new BMUSBCapture(card_index);
                card->usb->set_frame_callback(bind(&Mixer::bm_frame, this, card_index, _1, _2, _3, _4, _5, _6, _7));
-               card->frame_allocator.reset(new PBOFrameAllocator(WIDTH * (HEIGHT+EXTRAHEIGHT) * 2 + 44, WIDTH, HEIGHT));
+               card->frame_allocator.reset(new PBOFrameAllocator(WIDTH * (HEIGHT+EXTRAHEIGHT) * 2 + 44 + 1, WIDTH, HEIGHT));
                card->usb->set_video_frame_allocator(card->frame_allocator.get());
                card->surface = create_surface(format);
                card->usb->set_dequeue_thread_callbacks(
@@ -273,7 +273,8 @@ void Mixer::bm_frame(unsigned card_index, uint16_t timecode,
 
        int64_t frame_length = find_frame_length(video_format);
 
-       if (audio_frame.len - audio_offset > 30000) {
+       size_t num_samples = (audio_frame.len >= audio_offset) ? (audio_frame.len - audio_offset) / 8 / 3 : 0;
+       if (num_samples > OUTPUT_FREQUENCY / 10) {
                printf("Card %d: Dropping frame with implausible audio length (len=%d, offset=%d) [timecode=0x%04x video_len=%d video_offset=%d video_format=%x)\n",
                        card_index, int(audio_frame.len), int(audio_offset),
                        timecode, int(video_frame.len), int(video_offset), video_format);
@@ -294,7 +295,6 @@ void Mixer::bm_frame(unsigned card_index, uint16_t timecode,
        card->last_timecode = timecode;
 
        // Convert the audio to stereo fp32 and add it.
-       size_t num_samples = (audio_frame.len >= audio_offset) ? (audio_frame.len - audio_offset) / 8 / 3 : 0;
        vector<float> audio;
        audio.resize(num_samples * 2);
        convert_fixed24_to_fp32(&audio[0], 2, audio_frame.data + audio_offset, 8, num_samples);