WPILibC++ 2027.0.0-alpha-5
Loading...
Searching...
No Matches
VideoSink.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 <string>
8#include <string_view>
9#include <utility>
10#include <vector>
11
14#include "wpi/cs/cscore_cpp.hpp"
15
16namespace wpi::util {
17class json;
18} // namespace wpi::util
19
20namespace wpi::cs {
21
22class VideoEvent;
23
24/**
25 * A sink for video that accepts a sequence of frames.
26 */
27class VideoSink {
28 friend class VideoEvent;
29 friend class VideoSource;
30
31 public:
32 enum Kind {
33 /// Unknown sink type.
35 /// MJPEG video sink.
37 /// CV video sink.
39 /// Raw video sink.
41 };
42
43 VideoSink() noexcept = default;
44
45 VideoSink(const VideoSink& sink)
46 : m_handle(sink.m_handle == 0 ? 0 : CopySink(sink.m_handle, &m_status)) {}
47
48 VideoSink(VideoSink&& other) noexcept : VideoSink() { swap(*this, other); }
49
50 VideoSink& operator=(VideoSink other) noexcept {
51 swap(*this, other);
52 return *this;
53 }
54
56 m_status = 0;
57 if (m_handle != 0) {
59 }
60 }
61
62 /**
63 * Returns true if the VideoSink is valid.
64 *
65 * @return True if the VideoSink is valid.
66 */
67 explicit operator bool() const { return m_handle != 0; }
68
69 /**
70 * Returns the VideoSink handle.
71 *
72 * @return The VideoSink handle.
73 */
74 int GetHandle() const { return m_handle; }
75
76 bool operator==(const VideoSink& other) const {
77 return m_handle == other.m_handle;
78 }
79
80 /**
81 * Get the kind of the sink.
82 */
83 Kind GetKind() const {
84 m_status = 0;
85 return static_cast<VideoSink::Kind>(GetSinkKind(m_handle, &m_status));
86 }
87
88 /**
89 * Get the name of the sink. The name is an arbitrary identifier
90 * provided when the sink is created, and should be unique.
91 */
92 std::string GetName() const {
93 m_status = 0;
95 }
96
97 /**
98 * Get the sink description. This is sink-kind specific.
99 */
100 std::string GetDescription() const {
101 m_status = 0;
103 }
104
105 /**
106 * Get a property of the sink.
107 *
108 * @param name Property name
109 * @return Property (kind Property::kNone if no property with
110 * the given name exists)
111 */
112 VideoProperty GetProperty(std::string_view name) {
113 m_status = 0;
115 }
116
117 /**
118 * Enumerate all properties of this sink.
119 */
120 std::vector<VideoProperty> EnumerateProperties() const;
121
122 /**
123 * Set properties from a JSON configuration string.
124 *
125 * The format of the JSON input is:
126 *
127 * <pre>
128 * {
129 * "properties": [
130 * {
131 * "name": property name
132 * "value": property value
133 * }
134 * ]
135 * }
136 * </pre>
137 *
138 * @param config configuration
139 * @return True if set successfully
140 */
141 bool SetConfigJson(std::string_view config) {
142 m_status = 0;
143 return SetSinkConfigJson(m_handle, config, &m_status);
144 }
145
146 /**
147 * Set properties from a JSON configuration object.
148 *
149 * @param config configuration
150 * @return True if set successfully
151 */
152 bool SetConfigJson(const wpi::util::json& config) {
153 m_status = 0;
154 return SetSinkConfigJson(m_handle, config, &m_status);
155 }
156
157 /**
158 * Get a JSON configuration string.
159 *
160 * @return JSON configuration string
161 */
162 std::string GetConfigJson() const {
163 m_status = 0;
165 }
166
167 /**
168 * Get a JSON configuration object.
169 *
170 * @return JSON configuration object
171 */
173
174 /**
175 * Configure which source should provide frames to this sink. Each sink
176 * can accept frames from only a single source, but a single source can
177 * provide frames to multiple clients.
178 *
179 * @param source Source
180 */
182 m_status = 0;
183 if (!source) {
185 } else {
187 }
188 }
189
190 /**
191 * Get the connected source.
192 *
193 * @return Connected source (empty if none connected).
194 */
196 m_status = 0;
197 auto handle = GetSinkSource(m_handle, &m_status);
198 return VideoSource{handle == 0 ? 0 : CopySource(handle, &m_status)};
199 }
200
201 /**
202 * Get a property of the associated source.
203 *
204 * @param name Property name
205 * @return Property (kind Property::kNone if no property with
206 * the given name exists or no source connected)
207 */
212
213 CS_Status GetLastStatus() const { return m_status; }
214
215 /**
216 * Enumerate all existing sinks.
217 *
218 * @return Vector of sinks.
219 */
220 static std::vector<VideoSink> EnumerateSinks();
221
222 friend void swap(VideoSink& first, VideoSink& second) noexcept {
223 using std::swap;
224 swap(first.m_status, second.m_status);
225 swap(first.m_handle, second.m_handle);
226 }
227
228 protected:
229 explicit VideoSink(CS_Sink handle) : m_handle(handle) {}
230
231 mutable CS_Status m_status = 0;
233};
234
235} // namespace wpi::cs
and restrictions which apply to each piece of software is included later in this file and or inside of the individual applicable source files The disclaimer of warranty in the WPILib license above applies to all code in and nothing in any of the other licenses gives permission to use the names of FIRST nor the names of the WPILib contributors to endorse or promote products derived from this software The following pieces of software have additional or alternate and or glfw and nanopb were modified for use in Google Inc All rights reserved Redistribution and use in source and binary with or without are permitted provided that the following conditions are this list of conditions and the following disclaimer *Redistributions in binary form must reproduce the above copyright this list of conditions and the following disclaimer in the documentation and or other materials provided with the distribution *Neither the name of Google Inc nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY EXPRESS OR IMPLIED BUT NOT LIMITED THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY OR CONSEQUENTIAL WHETHER IN STRICT OR EVEN IF ADVISED OF THE POSSIBILITY OF SUCH January AND DISTRIBUTION Definitions License shall mean the terms and conditions for and distribution as defined by Sections through of this document Licensor shall mean the copyright owner or entity authorized by the copyright owner that is granting the License Legal Entity shall mean the union of the acting entity and all other entities that control are controlled by or are under common control with that entity For the purposes of this definition control direct or to cause the direction or management of such whether by contract or including but not limited to software source documentation source
Definition ThirdPartyNotices.txt:119
@ name
Definition base.h:690
An event generated by the library and provided to event listeners.
Definition VideoEvent.hpp:17
A source or sink property.
Definition VideoProperty.hpp:34
wpi::util::json GetConfigJsonObject() const
Get a JSON configuration object.
VideoSink() noexcept=default
Kind GetKind() const
Get the kind of the sink.
Definition VideoSink.hpp:83
void SetSource(VideoSource source)
Configure which source should provide frames to this sink.
Definition VideoSink.hpp:181
VideoProperty GetProperty(std::string_view name)
Get a property of the sink.
Definition VideoSink.hpp:112
CS_Status GetLastStatus() const
Definition VideoSink.hpp:213
friend void swap(VideoSink &first, VideoSink &second) noexcept
Definition VideoSink.hpp:222
bool SetConfigJson(const wpi::util::json &config)
Set properties from a JSON configuration object.
Definition VideoSink.hpp:152
~VideoSink()
Definition VideoSink.hpp:55
int GetHandle() const
Returns the VideoSink handle.
Definition VideoSink.hpp:74
CS_Sink m_handle
Definition VideoSink.hpp:232
VideoSink(VideoSink &&other) noexcept
Definition VideoSink.hpp:48
CS_Status m_status
Definition VideoSink.hpp:231
VideoProperty GetSourceProperty(std::string_view name)
Get a property of the associated source.
Definition VideoSink.hpp:208
VideoSource GetSource() const
Get the connected source.
Definition VideoSink.hpp:195
Kind
Definition VideoSink.hpp:32
@ kMjpeg
MJPEG video sink.
Definition VideoSink.hpp:36
@ kCv
CV video sink.
Definition VideoSink.hpp:38
@ kUnknown
Unknown sink type.
Definition VideoSink.hpp:34
@ kRaw
Raw video sink.
Definition VideoSink.hpp:40
std::string GetName() const
Get the name of the sink.
Definition VideoSink.hpp:92
VideoSink & operator=(VideoSink other) noexcept
Definition VideoSink.hpp:50
std::string GetDescription() const
Get the sink description.
Definition VideoSink.hpp:100
bool operator==(const VideoSink &other) const
Definition VideoSink.hpp:76
std::vector< VideoProperty > EnumerateProperties() const
Enumerate all properties of this sink.
VideoSink(CS_Sink handle)
Definition VideoSink.hpp:229
friend class VideoEvent
Definition VideoSink.hpp:28
friend class VideoSource
Definition VideoSink.hpp:29
static std::vector< VideoSink > EnumerateSinks()
Enumerate all existing sinks.
bool SetConfigJson(std::string_view config)
Set properties from a JSON configuration string.
Definition VideoSink.hpp:141
std::string GetConfigJson() const
Get a JSON configuration string.
Definition VideoSink.hpp:162
Definition json.hpp:85
@ CS_SINK_MJPEG
Definition cscore_c.h:130
@ CS_SINK_RAW
Definition cscore_c.h:132
@ CS_SINK_CV
Definition cscore_c.h:131
@ CS_SINK_UNKNOWN
Definition cscore_c.h:129
CS_Property GetSinkSourceProperty(CS_Sink sink, std::string_view name, CS_Status *status)
CS_Property GetSinkProperty(CS_Sink sink, std::string_view name, CS_Status *status)
std::string GetSinkConfigJson(CS_Sink sink, CS_Status *status)
void SetSinkSource(CS_Sink sink, CS_Source source, CS_Status *status)
CS_SinkKind GetSinkKind(CS_Sink sink, CS_Status *status)
std::string GetSinkDescription(CS_Sink sink, CS_Status *status)
bool SetSinkConfigJson(CS_Sink sink, std::string_view config, CS_Status *status)
CS_Sink CopySink(CS_Sink sink, CS_Status *status)
std::string GetSinkName(CS_Sink sink, CS_Status *status)
void ReleaseSink(CS_Sink sink, CS_Status *status)
CS_Source GetSinkSource(CS_Sink sink, CS_Status *status)
CS_Source CopySource(CS_Source source, CS_Status *status)
int CS_Status
Definition cscore_c.h:41
CS_Handle CS_Sink
Definition cscore_c.h:47
void swap(wpi::util::StringMap< T > &lhs, wpi::util::StringMap< T > &rhs)
Definition StringMap.hpp:775
CameraServer (cscore) namespace.
Definition CvSource.hpp:15
Definition raw_os_ostream.hpp:19