Files
allwpilib/cscore/examples/usbstream/usbstream.cpp

32 lines
1.0 KiB
C++
Raw Normal View History

// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
2017-08-25 17:48:06 -07:00
#include <cstdio>
2025-11-07 19:56:21 -05:00
#include "wpi/cs/cscore.h"
2025-11-07 19:57:55 -05:00
#include "wpi/util/print.hpp"
int main() {
2025-11-07 20:00:05 -05:00
wpi::util::print("hostname: {}\n", wpi::cs::GetHostname());
std::puts("IPv4 network addresses:");
2025-11-07 20:00:05 -05:00
for (const auto& addr : wpi::cs::GetNetworkInterfaces()) {
wpi::util::print(" {}\n", addr);
}
2025-11-07 20:00:05 -05:00
wpi::cs::UsbCamera camera{"usbcam", 0};
camera.SetVideoMode(wpi::cs::VideoMode::kMJPEG, 320, 240, 30);
wpi::cs::MjpegServer mjpegServer{"httpserver", 8081};
2016-10-15 22:44:26 -07:00
mjpegServer.SetSource(camera);
CS_Status status = 0;
2025-11-07 20:00:05 -05:00
wpi::cs::AddListener(
[&](const wpi::cs::RawEvent& event) {
wpi::util::print("FPS={} MBPS={}\n", camera.GetActualFPS(),
(camera.GetActualDataRate() / 1000000.0));
2018-03-07 01:14:21 -08:00
},
2025-11-07 20:00:05 -05:00
wpi::cs::RawEvent::kTelemetryUpdated, false, &status);
wpi::cs::SetTelemetryPeriod(1.0);
2017-08-25 17:48:06 -07:00
std::getchar();
}