#include <thread>
#include <vector>
-#include "bmusb.h"
+#include "bmusb/bmusb.h"
#include "context.h"
#include "h264encode.h"
#include "pbo_frame_allocator.h"
#include "ref_counted_gl_sync.h"
+#include "timebase.h"
class QOpenGLContext;
display_chain->set_dither_bits(0); // Don't bother.
display_chain->finalize();
- h264_encoder.reset(new H264Encoder(h264_encoder_surface, WIDTH, HEIGHT, "test.mkv"));
+ h264_encoder.reset(new H264Encoder(h264_encoder_surface, WIDTH, HEIGHT, "test.mp4"));
for (int card_index = 0; card_index < NUM_CARDS; ++card_index) {
printf("Configuring card %d...\n", card_index);
BMUSBCapture::stop_bm_thread();
for (int card_index = 0; card_index < NUM_CARDS; ++card_index) {
- cards[card_index].new_data_ready = false; // Unblock thread.
- cards[card_index].new_data_ready_changed.notify_all();
+ {
+ std::unique_lock<std::mutex> lock(bmusb_mutex);
+ cards[card_index].should_quit = true; // Unblock thread.
+ cards[card_index].new_data_ready_changed.notify_all();
+ }
cards[card_index].usb->stop_dequeue_thread();
}
}
if (video_frame.len - video_offset != 1280 * 750 * 2) {
printf("dropping frame with wrong length (%ld)\n", video_frame.len - video_offset);
- FILE *fp = fopen("frame.raw", "wb");
- fwrite(video_frame.data, video_frame.len, 1, fp);
- fclose(fp);
- //exit(1);
card->usb->get_video_frame_allocator()->release_frame(video_frame);
card->usb->get_audio_frame_allocator()->release_frame(audio_frame);
return;
}
+ if (audio_frame.len - audio_offset > 30000) {
+ printf("dropping frame with implausible audio length (%ld)\n", audio_frame.len - audio_offset);
+ card->usb->get_video_frame_allocator()->release_frame(video_frame);
+ card->usb->get_audio_frame_allocator()->release_frame(audio_frame);
+ return;
+ }
+
{
// Wait until the previous frame was consumed.
std::unique_lock<std::mutex> lock(bmusb_mutex);
- card->new_data_ready_changed.wait(lock, [card]{ return !card->new_data_ready; });
+ card->new_data_ready_changed.wait(lock, [card]{ return !card->new_data_ready || card->should_quit; });
+ if (card->should_quit) return;
}
const PBOFrameAllocator::Userdata *userdata = (const PBOFrameAllocator::Userdata *)video_frame.userdata;
GLuint pbo = userdata->pbo;
for (int card_index = 0; card_index < NUM_CARDS; ++card_index) {
input_frames.push_back(bmusb_current_rendering_frame[card_index]);
}
- h264_encoder->end_frame(fence, move(samples_out), input_frames);
+ h264_encoder->end_frame(fence, frame * (TIMEBASE / 60), move(samples_out), input_frames);
// The live frame just shows the RGBA texture we just rendered.
// It owns rgba_tex now.