git.s-ol.nu obs-bmusb / master
progress s-ol 1 year, 2 months ago
1 changed file(s) with 63 addition(s) and 11 deletion(s). Raw diff Collapse all Expand all
11 #include <stdlib.h>
22 #include <obs.h>
3 #include <util/platform.h>
34 #include <obs-module.h>
45 #include <bmusb/bmusb.h>
5
6 #include <stdio.h>
6 #include <iostream>
77
88 using bmusb::BMUSBCapture;
99 using bmusb::FrameAllocator;
1111 using bmusb::AudioFormat;
1212
1313 struct bmusb_inst {
14 obs_source_t *source;
15 BMUSBCapture *capture;
16 bool initialized;
14 obs_source_t *source;
15 BMUSBCapture *capture;
16 bool initialized;
1717 };
1818
1919 static const char *bmusb_getname(void *unused)
2828
2929 if (rt) {
3030 if (rt->initialized) {
31 delete rt->capture;
3132 BMUSBCapture::stop_bm_thread();
32 delete rt->capture;
3333 }
3434
3535 bfree(rt);
4848 FrameAllocator::Frame video_frame, size_t video_offset, VideoFormat video_format,
4949 FrameAllocator::Frame audio_frame, size_t audio_offset, AudioFormat audio_format
5050 ) {
51 printf("got fraem %d\n", timecode);
52 UNUSED_PARAMETER(video_format);
53 UNUSED_PARAMETER(audio_format);
54 rt->capture->get_video_frame_allocator()->release_frame(video_frame);
55 rt->capture->get_audio_frame_allocator()->release_frame(audio_frame);
51 uint64_t cur_time = os_gettime_ns();
52
53 if (!video_format.has_signal) {
54 std::cerr << "scanning" << std::endl;
55 video_frame.owner->release_frame(video_frame);
56 audio_frame.owner->release_frame(audio_frame);
57 return;
58 }
59
60 uint8_t num_fields = video_format.interlaced ? 2 : 1;
61 if (video_format.interlaced) {
62 std::cerr << "oh no, video is interlaced" << std::endl;
63 video_frame.owner->release_frame(video_frame);
64 audio_frame.owner->release_frame(audio_frame);
65 return;
66 }
67
68 if (video_frame.interleaved) {
69 std::cerr << "oh no, video is interleaved" << std::endl;
70 video_frame.owner->release_frame(video_frame);
71 audio_frame.owner->release_frame(audio_frame);
72 return;
73 }
74 struct obs_source_frame frame;
75 frame.width = video_format.width;
76 frame.height = video_format.height;
77 frame.format = VIDEO_FORMAT_UYVY;
78 frame.linesize[0] = frame.width * 2;
79 frame.data[0] = video_frame.data + video_offset;
80 frame.timestamp = cur_time;
81 obs_source_output_video(rt->source, &frame);
82 video_frame.owner->release_frame(video_frame);
83
84 #ifdef BMUSB_AUDIO
85 struct obs_source_audio audio;
86 audio.samples_per_sec = audio_format.sample_rate;
87 audio.frames = (audio_frame.len > audio_offset) ? (audio_frame.len - audio_offset) / audio_format.num_channels / (audio_format.bits_per_sample / 8) : 0;
88 audio.format = AUDIO_FORMAT_32BIT;
89 audio.data[0] = audio_frame.data + audio_offset;
90 audio.timestamp = cur_time;
91 switch (audio_format.num_channels) {
92 case 1: audio.speakers = SPEAKERS_MONO; break;
93 case 2: audio.speakers = SPEAKERS_STEREO; break;
94 case 3: audio.speakers = SPEAKERS_2POINT1; break;
95 case 4: audio.speakers = SPEAKERS_4POINT0; break;
96 case 5: audio.speakers = SPEAKERS_4POINT1; break;
97 case 6: audio.speakers = SPEAKERS_5POINT1; break;
98 case 8: audio.speakers = SPEAKERS_7POINT1; break;
99 default: audio.speakers = SPEAKERS_UNKNOWN; break;
100 }
101 obs_source_output_audio(rt->source, &audio);
102 #endif
103 audio_frame.owner->release_frame(audio_frame);
56104 }
57105 );
58106 rt->capture->configure_card();
69117 struct obs_source_info bmusb_source_info = {
70118 .id = "bmusb",
71119 .type = OBS_SOURCE_TYPE_INPUT,
120 #ifdef BMUSB_AUDIO
121 .output_flags = OBS_SOURCE_ASYNC_VIDEO | OBS_SOURCE_AUDIO,
122 #else
72123 .output_flags = OBS_SOURCE_ASYNC_VIDEO,
124 #endif
73125 .get_name = bmusb_getname,
74126 .create = bmusb_create,
75127 .destroy = bmusb_destroy,