]> git.sesse.net Git - bmusb/blob - main.cpp
Set libusb timeout to one second, to help shutdown if the thread is started with...
[bmusb] / main.cpp
1 #include <stdio.h>
2 #include <unistd.h>
3 #include "bmusb/bmusb.h"
4
5 using namespace std;
6 using namespace bmusb;
7         
8 BMUSBCapture *usb;
9
10 void check_frame_stability(uint16_t timecode,
11                            FrameAllocator::Frame video_frame, size_t video_offset, VideoFormat video_format,
12                            FrameAllocator::Frame audio_frame, size_t audio_offset, AudioFormat audio_format)
13 {
14         //printf("0x%04x: %d video bytes (format 0x%04x), %d audio bytes (format 0x%04x)\n",
15         //      timecode, video_end - video_start, video_format.id, audio_end - audio_start, audio_format.id);
16
17         static uint16_t last_timecode = 0;
18         static size_t last_video_bytes = 0;
19         static size_t last_audio_bytes = 0;
20
21         if (!(last_timecode == 0 && last_video_bytes == 0 && last_audio_bytes == 0)) {
22                 if (timecode != (uint16_t)(last_timecode + 1)) {
23                         printf("0x%04x: Dropped %d frames\n", timecode, timecode - last_timecode - 1);
24                 } else if (last_video_bytes != video_frame.len - video_offset) {
25                         printf("0x%04x: Video frame size changed (old=%ld, cur=%ld)\n", timecode,
26                                 last_video_bytes, video_frame.len - video_offset);
27                 } else if (last_audio_bytes != audio_frame.len - audio_offset) {
28                         printf("0x%04x: Audio block size changed (old=%ld, cur=%ld)\n", timecode,
29                                 last_audio_bytes, audio_frame.len - audio_offset);
30                 }
31         }
32         last_timecode = timecode;
33         last_video_bytes = video_frame.len - video_offset;
34         last_audio_bytes = audio_frame.len - audio_offset;
35
36         usb->get_video_frame_allocator()->release_frame(video_frame);
37         usb->get_audio_frame_allocator()->release_frame(audio_frame);
38 }
39
40 int main(int argc, char **argv)
41 {
42         usb = new BMUSBCapture(0);  // First card.
43         usb->set_frame_callback(check_frame_stability);
44         usb->configure_card();
45         BMUSBCapture::start_bm_thread();
46         usb->start_bm_capture();
47         sleep(1000000);
48 }
49