WPILibC++ 2027.0.0-alpha-4
Loading...
Searching...
No Matches
HttpCamera.hpp
Go to the documentation of this file.
1// Copyright (c) FIRST and other WPILib contributors.
2// Open Source Software; you can modify and/or share it under the terms of
3// the WPILib BSD license file in the root directory of this project.
4
5#pragma once
6
7#include <initializer_list>
8#include <span>
9#include <string>
10#include <string_view>
11#include <vector>
12
14#include "wpi/cs/cscore_cpp.hpp"
15
16namespace wpi::cs {
17
18/**
19 * A source that represents a MJPEG-over-HTTP (IP) camera.
20 */
21class HttpCamera : public VideoCamera {
22 public:
23 /**
24 * HTTP camera kind.
25 */
27 /// Unknown camera kind.
29 /// MJPG Streamer camera.
31 /// CS Core camera.
33 };
34
35 /**
36 * Create a source for a MJPEG-over-HTTP (IP) camera.
37 *
38 * @param name Source name (arbitrary unique identifier)
39 * @param url Camera URL (e.g. "http://10.x.y.11/video/stream.mjpg")
40 * @param kind Camera kind (e.g. kAxis)
41 */
42 HttpCamera(std::string_view name, std::string_view url,
43 HttpCameraKind kind = kUnknown) {
45 name, url, static_cast<CS_HttpCameraKind>(static_cast<int>(kind)),
46 &m_status);
47 }
48
49 /**
50 * Create a source for a MJPEG-over-HTTP (IP) camera.
51 *
52 * @param name Source name (arbitrary unique identifier)
53 * @param url Camera URL (e.g. "http://10.x.y.11/video/stream.mjpg")
54 * @param kind Camera kind (e.g. kAxis)
55 */
56 HttpCamera(std::string_view name, const char* url,
57 HttpCameraKind kind = kUnknown) {
59 name, url, static_cast<CS_HttpCameraKind>(static_cast<int>(kind)),
60 &m_status);
61 }
62
63 /**
64 * Create a source for a MJPEG-over-HTTP (IP) camera.
65 *
66 * @param name Source name (arbitrary unique identifier)
67 * @param url Camera URL (e.g. "http://10.x.y.11/video/stream.mjpg")
68 * @param kind Camera kind (e.g. kAxis)
69 */
70 HttpCamera(std::string_view name, const std::string& url,
72 : HttpCamera(name, std::string_view{url}, kind) {}
73
74 /**
75 * Create a source for a MJPEG-over-HTTP (IP) camera.
76 *
77 * @param name Source name (arbitrary unique identifier)
78 * @param urls Array of Camera URLs
79 * @param kind Camera kind (e.g. kAxis)
80 */
81 HttpCamera(std::string_view name, std::span<const std::string> urls,
82 HttpCameraKind kind = kUnknown) {
84 name, urls, static_cast<CS_HttpCameraKind>(static_cast<int>(kind)),
85 &m_status);
86 }
87
88 /**
89 * Create a source for a MJPEG-over-HTTP (IP) camera.
90 *
91 * @param name Source name (arbitrary unique identifier)
92 * @param urls Array of Camera URLs
93 * @param kind Camera kind (e.g. kAxis)
94 */
95 template <typename T>
96 HttpCamera(std::string_view name, std::initializer_list<T> urls,
97 HttpCameraKind kind = kUnknown) {
98 std::vector<std::string> vec;
99 vec.reserve(urls.size());
100 for (const auto& url : urls) {
101 vec.emplace_back(url);
102 }
104 name, vec, static_cast<CS_HttpCameraKind>(static_cast<int>(kind)),
105 &m_status);
106 }
107
108 /**
109 * Get the kind of HTTP camera.
110 *
111 * <p>Autodetection can result in returning a different value than the camera
112 * was created with.
113 */
115 m_status = 0;
116 return static_cast<HttpCameraKind>(
117 static_cast<int>(::wpi::cs::GetHttpCameraKind(m_handle, &m_status)));
118 }
119
120 /**
121 * Change the URLs used to connect to the camera.
122 */
123 void SetUrls(std::span<const std::string> urls) {
124 m_status = 0;
126 }
127
128 /**
129 * Change the URLs used to connect to the camera.
130 */
131 template <typename T>
132 void SetUrls(std::initializer_list<T> urls) {
133 std::vector<std::string> vec;
134 vec.reserve(urls.size());
135 for (const auto& url : urls) {
136 vec.emplace_back(url);
137 }
138 m_status = 0;
140 }
141
142 /**
143 * Get the URLs used to connect to the camera.
144 */
145 std::vector<std::string> GetUrls() const {
146 m_status = 0;
147 return ::wpi::cs::GetHttpCameraUrls(m_handle, &m_status);
148 }
149};
150
151} // namespace wpi::cs
basic_string_view< char > string_view
Definition base.h:620
@ name
Definition base.h:690
HttpCamera(std::string_view name, std::span< const std::string > urls, HttpCameraKind kind=kUnknown)
Create a source for a MJPEG-over-HTTP (IP) camera.
Definition HttpCamera.hpp:81
HttpCameraKind
HTTP camera kind.
Definition HttpCamera.hpp:26
@ kUnknown
Unknown camera kind.
Definition HttpCamera.hpp:28
@ kMJPGStreamer
MJPG Streamer camera.
Definition HttpCamera.hpp:30
@ kCSCore
CS Core camera.
Definition HttpCamera.hpp:32
void SetUrls(std::span< const std::string > urls)
Change the URLs used to connect to the camera.
Definition HttpCamera.hpp:123
std::vector< std::string > GetUrls() const
Get the URLs used to connect to the camera.
Definition HttpCamera.hpp:145
HttpCamera(std::string_view name, const char *url, HttpCameraKind kind=kUnknown)
Create a source for a MJPEG-over-HTTP (IP) camera.
Definition HttpCamera.hpp:56
HttpCamera(std::string_view name, const std::string &url, HttpCameraKind kind=kUnknown)
Create a source for a MJPEG-over-HTTP (IP) camera.
Definition HttpCamera.hpp:70
void SetUrls(std::initializer_list< T > urls)
Change the URLs used to connect to the camera.
Definition HttpCamera.hpp:132
HttpCamera(std::string_view name, std::initializer_list< T > urls, HttpCameraKind kind=kUnknown)
Create a source for a MJPEG-over-HTTP (IP) camera.
Definition HttpCamera.hpp:96
HttpCamera(std::string_view name, std::string_view url, HttpCameraKind kind=kUnknown)
Create a source for a MJPEG-over-HTTP (IP) camera.
Definition HttpCamera.hpp:42
HttpCameraKind GetHttpCameraKind() const
Get the kind of HTTP camera.
Definition HttpCamera.hpp:114
CS_Status m_status
Definition VideoSource.hpp:372
CS_Source m_handle
Video source handle.
Definition VideoSource.hpp:375
CS_HttpCameraKind
HTTP Camera kinds.
Definition cscore_c.h:119
@ CS_HTTP_MJPGSTREAMER
Definition cscore_c.h:121
@ CS_HTTP_CSCORE
Definition cscore_c.h:122
@ CS_HTTP_UNKNOWN
Definition cscore_c.h:120
void SetHttpCameraUrls(CS_Source source, std::span< const std::string > urls, CS_Status *status)
CS_HttpCameraKind GetHttpCameraKind(CS_Source source, CS_Status *status)
CS_Source CreateHttpCamera(std::string_view name, std::string_view url, CS_HttpCameraKind kind, CS_Status *status)
Definition StringMap.hpp:773
CameraServer (cscore) namespace.
Definition CvSource.hpp:15