diff options
| author | s-ol <s-ol@users.noreply.github.com> | 2018-07-21 16:37:26 +0000 |
|---|---|---|
| committer | s-ol <s-ol@users.noreply.github.com> | 2018-07-21 16:37:26 +0000 |
| commit | 2bade2b88db494fba56c815d3f0259c6afab4726 (patch) | |
| tree | a2b5bc06252a5654c78c71f0388fd9a9da88c034 | |
| parent | initial commit - WIP (diff) | |
| download | obs-bmusb-2bade2b88db494fba56c815d3f0259c6afab4726.tar.gz obs-bmusb-2bade2b88db494fba56c815d3f0259c6afab4726.zip | |
progress
| -rw-r--r-- | bmusb-source.cpp | 74 |
1 files changed, 63 insertions, 11 deletions
diff --git a/bmusb-source.cpp b/bmusb-source.cpp index 47ec09b..174d039 100644 --- a/bmusb-source.cpp +++ b/bmusb-source.cpp @@ -1,9 +1,9 @@ #include <stdlib.h> #include <obs.h> +#include <util/platform.h> #include <obs-module.h> #include <bmusb/bmusb.h> - -#include <stdio.h> +#include <iostream> using bmusb::BMUSBCapture; using bmusb::FrameAllocator; @@ -11,9 +11,9 @@ using bmusb::VideoFormat; using bmusb::AudioFormat; struct bmusb_inst { - obs_source_t *source; - BMUSBCapture *capture; - bool initialized; + obs_source_t *source; + BMUSBCapture *capture; + bool initialized; }; static const char *bmusb_getname(void *unused) @@ -28,8 +28,8 @@ static void bmusb_destroy(void *data) if (rt) { if (rt->initialized) { - BMUSBCapture::stop_bm_thread(); delete rt->capture; + BMUSBCapture::stop_bm_thread(); } bfree(rt); @@ -48,11 +48,59 @@ static void *bmusb_create(obs_data_t *settings, obs_source_t *source) FrameAllocator::Frame video_frame, size_t video_offset, VideoFormat video_format, FrameAllocator::Frame audio_frame, size_t audio_offset, AudioFormat audio_format ) { - printf("got fraem %d\n", timecode); - UNUSED_PARAMETER(video_format); - UNUSED_PARAMETER(audio_format); - rt->capture->get_video_frame_allocator()->release_frame(video_frame); - rt->capture->get_audio_frame_allocator()->release_frame(audio_frame); + uint64_t cur_time = os_gettime_ns(); + + if (!video_format.has_signal) { + std::cerr << "scanning" << std::endl; + video_frame.owner->release_frame(video_frame); + audio_frame.owner->release_frame(audio_frame); + return; + } + + uint8_t num_fields = video_format.interlaced ? 2 : 1; + if (video_format.interlaced) { + std::cerr << "oh no, video is interlaced" << std::endl; + video_frame.owner->release_frame(video_frame); + audio_frame.owner->release_frame(audio_frame); + return; + } + + if (video_frame.interleaved) { + std::cerr << "oh no, video is interleaved" << std::endl; + video_frame.owner->release_frame(video_frame); + audio_frame.owner->release_frame(audio_frame); + return; + } + struct obs_source_frame frame; + frame.width = video_format.width; + frame.height = video_format.height; + frame.format = VIDEO_FORMAT_UYVY; + frame.linesize[0] = frame.width * 2; + frame.data[0] = video_frame.data + video_offset; + frame.timestamp = cur_time; + obs_source_output_video(rt->source, &frame); + video_frame.owner->release_frame(video_frame); + +#ifdef BMUSB_AUDIO + struct obs_source_audio audio; + audio.samples_per_sec = audio_format.sample_rate; + audio.frames = (audio_frame.len > audio_offset) ? (audio_frame.len - audio_offset) / audio_format.num_channels / (audio_format.bits_per_sample / 8) : 0; + audio.format = AUDIO_FORMAT_32BIT; + audio.data[0] = audio_frame.data + audio_offset; + audio.timestamp = cur_time; + switch (audio_format.num_channels) { + case 1: audio.speakers = SPEAKERS_MONO; break; + case 2: audio.speakers = SPEAKERS_STEREO; break; + case 3: audio.speakers = SPEAKERS_2POINT1; break; + case 4: audio.speakers = SPEAKERS_4POINT0; break; + case 5: audio.speakers = SPEAKERS_4POINT1; break; + case 6: audio.speakers = SPEAKERS_5POINT1; break; + case 8: audio.speakers = SPEAKERS_7POINT1; break; + default: audio.speakers = SPEAKERS_UNKNOWN; break; + } + obs_source_output_audio(rt->source, &audio); +#endif + audio_frame.owner->release_frame(audio_frame); } ); rt->capture->configure_card(); @@ -69,7 +117,11 @@ static void *bmusb_create(obs_data_t *settings, obs_source_t *source) struct obs_source_info bmusb_source_info = { .id = "bmusb", .type = OBS_SOURCE_TYPE_INPUT, +#ifdef BMUSB_AUDIO + .output_flags = OBS_SOURCE_ASYNC_VIDEO | OBS_SOURCE_AUDIO, +#else .output_flags = OBS_SOURCE_ASYNC_VIDEO, +#endif .get_name = bmusb_getname, .create = bmusb_create, .destroy = bmusb_destroy, |
