forked from Green-Sky/tomato
fan out camera devices
This commit is contained in:
@ -181,21 +181,57 @@ MainScreen::MainScreen(SimpleConfigModel&& conf_, SDL_Renderer* renderer_, Theme
|
||||
}
|
||||
|
||||
if (SDL_InitSubSystem(SDL_INIT_CAMERA)) {
|
||||
{ // video in
|
||||
ObjectHandle vsrc {os.registry(), os.registry().create()};
|
||||
try {
|
||||
vsrc.emplace<Components::FrameStream2Source<SDLVideoFrame>>(
|
||||
std::make_unique<SDLVideo2InputDevice>()
|
||||
);
|
||||
std::cout << "MS: SDL Camera Driver: " << SDL_GetCurrentCameraDriver() << "\n";
|
||||
|
||||
vsrc.emplace<Components::StreamSource>(Components::StreamSource::create<SDLVideoFrame>("SDL Video Default Recording Device"));
|
||||
vsrc.emplace<Components::TagDefaultTarget>();
|
||||
int devcount {0};
|
||||
SDL_CameraID *devices = SDL_GetCameras(&devcount);
|
||||
|
||||
os.throwEventConstruct(vsrc);
|
||||
} catch (...) {
|
||||
std::cerr << "MS error: failed constructing default video input source\n";
|
||||
os.registry().destroy(vsrc);
|
||||
std::cout << "MS: found cameras:\n";
|
||||
if (devices != nullptr) {
|
||||
ObjectHandle last_src{};
|
||||
for (int i = 0; i < devcount; i++) {
|
||||
const SDL_CameraID device = devices[i];
|
||||
|
||||
const char *name = SDL_GetCameraName(device);
|
||||
std::cout << " - Camera #" << i << ": " << name << "\n";
|
||||
|
||||
int speccount {0};
|
||||
SDL_CameraSpec** specs = SDL_GetCameraSupportedFormats(device, &speccount);
|
||||
if (specs == nullptr) {
|
||||
std::cout << " - no supported spec\n";
|
||||
} else {
|
||||
for (int spec_i = 0; spec_i < speccount; spec_i++) {
|
||||
std::cout << " - " << specs[spec_i]->width << "x" << specs[spec_i]->height << "@" << float(specs[spec_i]->framerate_numerator)/specs[spec_i]->framerate_denominator << "fps " << SDL_GetPixelFormatName(specs[spec_i]->format) << "\n";
|
||||
|
||||
}
|
||||
SDL_free(specs);
|
||||
|
||||
// create sink for device
|
||||
ObjectHandle vsrc {os.registry(), os.registry().create()};
|
||||
try {
|
||||
vsrc.emplace<Components::FrameStream2Source<SDLVideoFrame>>(
|
||||
std::make_unique<SDLVideo2InputDevice>(device)
|
||||
);
|
||||
|
||||
vsrc.emplace<Components::StreamSource>(Components::StreamSource::create<SDLVideoFrame>("SDL Video '" + std::string(name) + "'"));
|
||||
//vsrc.emplace<Components::TagDefaultTarget>();
|
||||
|
||||
os.throwEventConstruct(vsrc);
|
||||
last_src = vsrc;
|
||||
} catch (...) {
|
||||
std::cerr << "MS error: failed constructing video input source\n";
|
||||
os.registry().destroy(vsrc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//if (static_cast<bool>(last_src)) {
|
||||
// last_src.emplace<Components::TagDefaultTarget>();
|
||||
//}
|
||||
|
||||
SDL_free(devices);
|
||||
} else {
|
||||
std::cout << " none\n";
|
||||
}
|
||||
} else {
|
||||
std::cerr << "MS warning: no sdl camera: " << SDL_GetError() << "\n";
|
||||
|
Reference in New Issue
Block a user