#include <thread>
#include <vector>
-#include "bmusb.h"
+#include "bmusb/bmusb.h"
#include "context.h"
#include "h264encode.h"
#include "pbo_frame_allocator.h"
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;