]> git.sesse.net Git - nageru/blobdiff - mixer.cpp
Adapt to the new decode_video_format() prototype.
[nageru] / mixer.cpp
index e305376e9a86febcd9f044be95d9a159c80d7b42..44425455aef52e78993aa1992acf1850be4b0f97 100644 (file)
--- a/mixer.cpp
+++ b/mixer.cpp
@@ -220,10 +220,11 @@ void Mixer::bm_frame(unsigned card_index, uint16_t timecode,
 {
        CaptureCard *card = &cards[card_index];
 
-       int width, height, frame_rate_nom, frame_rate_den;
+       int width, height, frame_rate_nom, frame_rate_den, extra_lines_top, extra_lines_bottom;
        bool interlaced;
 
-       decode_video_format(video_format, &width, &height, &frame_rate_nom, &frame_rate_den, &interlaced);  // Ignore return value for now.
+       decode_video_format(video_format, &width, &height, &extra_lines_top, &extra_lines_bottom,
+                           &frame_rate_nom, &frame_rate_den, &interlaced);  // Ignore return value for now.
        int64_t frame_length = TIMEBASE * frame_rate_den / frame_rate_nom;
 
        size_t num_samples = (audio_frame.len >= audio_offset) ? (audio_frame.len - audio_offset) / 8 / 3 : 0;
@@ -263,6 +264,7 @@ void Mixer::bm_frame(unsigned card_index, uint16_t timecode,
                        fprintf(stderr, "Card %d lost more than two seconds (or time code jumping around; from 0x%04x to 0x%04x), resetting resampler\n",
                                card_index, card->last_timecode, timecode);
                        card->resampling_queue.reset(new ResamplingQueue(OUTPUT_FREQUENCY, OUTPUT_FREQUENCY, 2));
+                       dropped_frames = 0;
                } else if (dropped_frames > 0) {
                        // Insert silence as needed.
                        fprintf(stderr, "Card %d dropped %d frame(s) (before timecode 0x%04x), inserting silence.\n",
@@ -333,13 +335,18 @@ void Mixer::bm_frame(unsigned card_index, uint16_t timecode,
        //check_error();
 
        // Upload the textures.
-       glBindTexture(GL_TEXTURE_2D, userdata->tex_y);
+       size_t skipped_lines = 25;
+       size_t cbcr_width = WIDTH / 2;
+       size_t cbcr_offset = video_offset / 2;
+       size_t y_offset = cbcr_offset + cbcr_width * (HEIGHT + EXTRAHEIGHT) * sizeof(uint16_t) + video_offset / 2;
+
+       glBindTexture(GL_TEXTURE_2D, userdata->tex_cbcr);
        check_error();
-       glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, WIDTH, HEIGHT, GL_RED, GL_UNSIGNED_BYTE, BUFFER_OFFSET((WIDTH * (HEIGHT+EXTRAHEIGHT) * 2 + 44) / 2 + WIDTH * 25 + 22));
+       glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, cbcr_width, HEIGHT, GL_RG, GL_UNSIGNED_BYTE, BUFFER_OFFSET(cbcr_offset + cbcr_width * skipped_lines * sizeof(uint16_t)));
        check_error();
-       glBindTexture(GL_TEXTURE_2D, userdata->tex_cbcr);
+       glBindTexture(GL_TEXTURE_2D, userdata->tex_y);
        check_error();
-       glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, WIDTH/2, HEIGHT, GL_RG, GL_UNSIGNED_BYTE, BUFFER_OFFSET(WIDTH * 25 + 22));
+       glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, WIDTH, HEIGHT, GL_RED, GL_UNSIGNED_BYTE, BUFFER_OFFSET(y_offset + WIDTH * skipped_lines));
        check_error();
        glBindTexture(GL_TEXTURE_2D, 0);
        check_error();
@@ -398,6 +405,7 @@ void Mixer::thread_func()
                                int num_samples_times_timebase = OUTPUT_FREQUENCY * card->new_frame_length + card->fractional_samples;
                                num_samples[card_index] = num_samples_times_timebase / TIMEBASE;
                                card->fractional_samples = num_samples_times_timebase % TIMEBASE;
+                               assert(num_samples[card_index] >= 0);
                        }
                }