diff --git a/cameraserver.gradle b/cameraserver.gradle index 626f672df9..73b0eb8f20 100644 --- a/cameraserver.gradle +++ b/cameraserver.gradle @@ -51,6 +51,68 @@ def cameraserverSetupModel = { project -> } } +def cameraserverSetupExamplesModel = { project -> + project.model { + components { + enum_usb(NativeExecutableSpec) { + if (project.isArm) { + targetPlatform 'arm' + } else { + targetPlatform 'x86' + targetPlatform 'x64' + } + setupDefines(project, binaries) + binaries.all { + tasks.withType(CppCompile) { + project.addWpiUtilLibraryLinks(it, linker, targetPlatform) + } + } + sources { + cpp { + source { + srcDir "${rootDir}/examples/enum_usb" + include '**/*.cpp' + } + exportedHeaders { + srcDirs = ["${rootDir}/include", "${rootDir}/wpiutil/include"] + include '**/*.h' + } + lib library: 'cameraserver', linkage: 'static' + } + } + } + + usbstream(NativeExecutableSpec) { + if (project.isArm) { + targetPlatform 'arm' + } else { + targetPlatform 'x86' + targetPlatform 'x64' + } + setupDefines(project, binaries) + binaries.all { + tasks.withType(CppCompile) { + project.addWpiUtilLibraryLinks(it, linker, targetPlatform) + } + } + sources { + cpp { + source { + srcDir "${rootDir}/examples/usbstream" + include '**/*.cpp' + } + exportedHeaders { + srcDirs = ["${rootDir}/include", "${rootDir}/wpiutil/include"] + include '**/*.h' + } + lib library: 'cameraserver', linkage: 'static' + } + } + } + } + } +} + def cameraserverZipTask = { project -> project.ext.cameraserverZip = project.tasks.create("${project.isArm ? 'arm' : 'native'}CameraserverZip", Zip) { description = 'Creates platform-specific zip of the desktop cameraserver libraries.' @@ -116,6 +178,7 @@ if (buildArm) { } cameraserverSetupModel(project) + cameraserverSetupExamplesModel(project) cameraserverZipTask(project) useWpiUtil(project) } @@ -126,15 +189,16 @@ project(':native') { apply from: "${rootDir}/toolchains/native.gradle" - if (!project.hasProperty("withoutTests")) { - apply from: "${rootDir}/test/tests.gradle" - } + //if (!project.hasProperty("withoutTests")) { + // apply from: "${rootDir}/test/tests.gradle" + //} if (includeJava) { apply from: "${rootDir}/java/java.gradle" } cameraserverSetupModel(project) + cameraserverSetupExamplesModel(project) cameraserverZipTask(project) useWpiUtil(project) } diff --git a/examples/enum_usb/enum_usb.cpp b/examples/enum_usb/enum_usb.cpp new file mode 100644 index 0000000000..7b5a605444 --- /dev/null +++ b/examples/enum_usb/enum_usb.cpp @@ -0,0 +1,60 @@ +#include "cameraserver.h" + +#include "llvm/SmallString.h" +#include "llvm/raw_ostream.h" + +int main() { + CS_Status status = 0; + llvm::SmallString<64> buf; + + for (const auto& caminfo : cs::EnumerateUSBCameras(&status)) { + llvm::outs() << caminfo.dev << ": " << caminfo.path << " (" << caminfo.name + << ")\n"; + cs::USBCamera camera{"usbcam", caminfo.dev}; + + llvm::outs() << "Properties:\n"; + for (const auto& prop : camera.EnumerateProperties()) { + llvm::outs() << " " << prop.GetName() << ": "; + switch (prop.type()) { + case cs::VideoProperty::kBoolean: + llvm::outs() << "value=" << prop.Get() + << " default=" << prop.GetDefault(); + break; + case cs::VideoProperty::kInteger: + llvm::outs() << "value=" << prop.Get() << " min=" << prop.GetMin() + << " max=" << prop.GetMax() << " step=" << prop.GetStep() + << " default=" << prop.GetDefault(); + break; + case cs::VideoProperty::kString: + llvm::outs() << prop.GetString(buf); + break; + case cs::VideoProperty::kEnum: { + llvm::outs() << "value=" << prop.Get(); + auto choices = prop.GetChoices(); + for (size_t i = 0; i < choices.size(); ++i) { + if (choices[i].empty()) continue; + llvm::outs() << "\n " << i << ": " << choices[i]; + } + break; + } + default: + break; + } + llvm::outs() << '\n'; + } + + llvm::outs() << "Video Modes:\n"; + for (const auto& mode : camera.EnumerateVideoModes()) { + llvm::outs() << " PixelFormat:"; + switch (mode.pixelFormat) { + case cs::VideoMode::kMJPEG: llvm::outs() << "MJPEG"; break; + case cs::VideoMode::kYUYV: llvm::outs() << "YUYV"; break; + case cs::VideoMode::kRGB565: llvm::outs() << "RGB565"; break; + default: llvm::outs() << "Unknown"; break; + } + llvm::outs() << " Width:" << mode.width; + llvm::outs() << " Height:" << mode.height; + llvm::outs() << " FPS:" << mode.fps << '\n'; + } + } +} diff --git a/examples/usbstream/usbstream.cpp b/examples/usbstream/usbstream.cpp new file mode 100644 index 0000000000..6ea0ee43ae --- /dev/null +++ b/examples/usbstream/usbstream.cpp @@ -0,0 +1,11 @@ +#include "cameraserver.h" + +#include + +int main() { + cs::USBCamera camera{"usbcam", 1}; + camera.SetVideoMode(cs::VideoMode::kMJPEG, 320, 240, 30); + cs::HTTPSink httpServer{"httpserver", 8080}; + httpServer.SetSource(camera); + for (;;) std::this_thread::sleep_for(std::chrono::seconds(1)); +}