WPILibC++ 2027.0.0-alpha-4
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#include "wpi/util/json_fwd.hpp"
16
17namespace wpi::cs {
18
19class VideoEvent;
20
21/**
22 * A sink for video that accepts a sequence of frames.
23 */
24class VideoSink {
25 friend class VideoEvent;
26 friend class VideoSource;
27
28 public:
29 enum Kind {
30 /// Unknown sink type.
32 /// MJPEG video sink.
34 /// CV video sink.
36 /// Raw video sink.
38 };
39
40 VideoSink() noexcept = default;
41
42 VideoSink(const VideoSink& sink)
43 : m_handle(sink.m_handle == 0 ? 0 : CopySink(sink.m_handle, &m_status)) {}
44
45 VideoSink(VideoSink&& other) noexcept : VideoSink() { swap(*this, other); }
46
47 VideoSink& operator=(VideoSink other) noexcept {
48 swap(*this, other);
49 return *this;
50 }
51
53 m_status = 0;
54 if (m_handle != 0) {
56 }
57 }
58
59 /**
60 * Returns true if the VideoSink is valid.
61 *
62 * @return True if the VideoSink is valid.
63 */
64 explicit operator bool() const { return m_handle != 0; }
65
66 /**
67 * Returns the VideoSink handle.
68 *
69 * @return The VideoSink handle.
70 */
71 int GetHandle() const { return m_handle; }
72
73 bool operator==(const VideoSink& other) const {
74 return m_handle == other.m_handle;
75 }
76
77 /**
78 * Get the kind of the sink.
79 */
80 Kind GetKind() const {
81 m_status = 0;
82 return static_cast<VideoSink::Kind>(GetSinkKind(m_handle, &m_status));
83 }
84
85 /**
86 * Get the name of the sink. The name is an arbitrary identifier
87 * provided when the sink is created, and should be unique.
88 */
89 std::string GetName() const {
90 m_status = 0;
92 }
93
94 /**
95 * Get the sink description. This is sink-kind specific.
96 */
97 std::string GetDescription() const {
98 m_status = 0;
100 }
101
102 /**
103 * Get a property of the sink.
104 *
105 * @param name Property name
106 * @return Property (kind Property::kNone if no property with
107 * the given name exists)
108 */
109 VideoProperty GetProperty(std::string_view name) {
110 m_status = 0;
112 }
113
114 /**
115 * Enumerate all properties of this sink.
116 */
117 std::vector<VideoProperty> EnumerateProperties() const;
118
119 /**
120 * Set properties from a JSON configuration string.
121 *
122 * The format of the JSON input is:
123 *
124 * <pre>
125 * {
126 * "properties": [
127 * {
128 * "name": property name
129 * "value": property value
130 * }
131 * ]
132 * }
133 * </pre>
134 *
135 * @param config configuration
136 * @return True if set successfully
137 */
138 bool SetConfigJson(std::string_view config) {
139 m_status = 0;
140 return SetSinkConfigJson(m_handle, config, &m_status);
141 }
142
143 /**
144 * Set properties from a JSON configuration object.
145 *
146 * @param config configuration
147 * @return True if set successfully
148 */
149 bool SetConfigJson(const wpi::util::json& config) {
150 m_status = 0;
151 return SetSinkConfigJson(m_handle, config, &m_status);
152 }
153
154 /**
155 * Get a JSON configuration string.
156 *
157 * @return JSON configuration string
158 */
159 std::string GetConfigJson() const {
160 m_status = 0;
162 }
163
164 /**
165 * Get a JSON configuration object.
166 *
167 * @return JSON configuration object
168 */
169 wpi::util::json GetConfigJsonObject() const;
170
171 /**
172 * Configure which source should provide frames to this sink. Each sink
173 * can accept frames from only a single source, but a single source can
174 * provide frames to multiple clients.
175 *
176 * @param source Source
177 */
179 m_status = 0;
180 if (!source) {
182 } else {
184 }
185 }
186
187 /**
188 * Get the connected source.
189 *
190 * @return Connected source (empty if none connected).
191 */
193 m_status = 0;
194 auto handle = GetSinkSource(m_handle, &m_status);
195 return VideoSource{handle == 0 ? 0 : CopySource(handle, &m_status)};
196 }
197
198 /**
199 * Get a property of the associated source.
200 *
201 * @param name Property name
202 * @return Property (kind Property::kNone if no property with
203 * the given name exists or no source connected)
204 */
209
210 CS_Status GetLastStatus() const { return m_status; }
211
212 /**
213 * Enumerate all existing sinks.
214 *
215 * @return Vector of sinks.
216 */
217 static std::vector<VideoSink> EnumerateSinks();
218
219 friend void swap(VideoSink& first, VideoSink& second) noexcept {
220 using std::swap;
221 swap(first.m_status, second.m_status);
222 swap(first.m_handle, second.m_handle);
223 }
224
225 protected:
226 explicit VideoSink(CS_Sink handle) : m_handle(handle) {}
227
228 mutable CS_Status m_status = 0;
230};
231
232} // 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:123
@ 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:80
void SetSource(VideoSource source)
Configure which source should provide frames to this sink.
Definition VideoSink.hpp:178
VideoProperty GetProperty(std::string_view name)
Get a property of the sink.
Definition VideoSink.hpp:109
CS_Status GetLastStatus() const
Definition VideoSink.hpp:210
friend void swap(VideoSink &first, VideoSink &second) noexcept
Definition VideoSink.hpp:219
bool SetConfigJson(const wpi::util::json &config)
Set properties from a JSON configuration object.
Definition VideoSink.hpp:149
~VideoSink()
Definition VideoSink.hpp:52
int GetHandle() const
Returns the VideoSink handle.
Definition VideoSink.hpp:71
CS_Sink m_handle
Definition VideoSink.hpp:229
VideoSink(VideoSink &&other) noexcept
Definition VideoSink.hpp:45
CS_Status m_status
Definition VideoSink.hpp:228
VideoProperty GetSourceProperty(std::string_view name)
Get a property of the associated source.
Definition VideoSink.hpp:205
VideoSource GetSource() const
Get the connected source.
Definition VideoSink.hpp:192
Kind
Definition VideoSink.hpp:29
@ kMjpeg
MJPEG video sink.
Definition VideoSink.hpp:33
@ kCv
CV video sink.
Definition VideoSink.hpp:35
@ kUnknown
Unknown sink type.
Definition VideoSink.hpp:31
@ kRaw
Raw video sink.
Definition VideoSink.hpp:37
std::string GetName() const
Get the name of the sink.
Definition VideoSink.hpp:89
VideoSink & operator=(VideoSink other) noexcept
Definition VideoSink.hpp:47
std::string GetDescription() const
Get the sink description.
Definition VideoSink.hpp:97
bool operator==(const VideoSink &other) const
Definition VideoSink.hpp:73
std::vector< VideoProperty > EnumerateProperties() const
Enumerate all properties of this sink.
VideoSink(CS_Sink handle)
Definition VideoSink.hpp:226
friend class VideoEvent
Definition VideoSink.hpp:25
friend class VideoSource
Definition VideoSink.hpp:26
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:138
std::string GetConfigJson() const
Get a JSON configuration string.
Definition VideoSink.hpp:159
@ 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