]> git.sesse.net Git - nageru/blobdiff - mixer.cpp
Rename a local variable for clarity.
[nageru] / mixer.cpp
index 936a070129352c4b10a80747e740be1e1ebb2dd0..c023e2007b6f2e102e474c94cc233ad489ccd143 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);
@@ -410,7 +410,7 @@ void Mixer::thread_func()
        clock_gettime(CLOCK_MONOTONIC, &start);
 
        int frame = 0;
-       int dropped_frames = 0;
+       int stats_dropped_frames = 0;
 
        while (!should_quit) {
                CaptureCard card_copy[MAX_CARDS];
@@ -452,7 +452,7 @@ void Mixer::thread_func()
                                // For dropped frames, increase the pts. Note that if the format changed
                                // in the meantime, we have no way of detecting that; we just have to
                                // assume the frame length is always the same.
-                               ++dropped_frames;
+                               ++stats_dropped_frames;
                                pts_int += card_copy[0].new_frame_length;
                        }
                }
@@ -481,7 +481,7 @@ void Mixer::thread_func()
                // If the first card is reporting a corrupted or otherwise dropped frame,
                // just increase the pts (skipping over this frame) and don't try to compute anything new.
                if (card_copy[0].new_frame->len == 0) {
-                       ++dropped_frames;
+                       ++stats_dropped_frames;
                        pts_int += card_copy[0].new_frame_length;
                        continue;
                }
@@ -582,7 +582,7 @@ void Mixer::thread_func()
                        1e-9 * (now.tv_nsec - start.tv_nsec);
                if (frame % 100 == 0) {
                        printf("%d frames (%d dropped) in %.3f seconds = %.1f fps (%.1f ms/frame)\n",
-                               frame, dropped_frames, elapsed, frame / elapsed,
+                               frame, stats_dropped_frames, elapsed, frame / elapsed,
                                1e3 * elapsed / frame);
                //      chain->print_phase_timing();
                }