WPILibC++ 2025.3.1
Loading...
Searching...
No Matches
cscore_oo.h
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#ifndef CSCORE_CSCORE_OO_H_
6#define CSCORE_CSCORE_OO_H_
7
8#include <functional>
9#include <initializer_list>
10#include <span>
11#include <string>
12#include <string_view>
13#include <utility>
14#include <vector>
15
16#include <wpi/deprecated.h>
17
18#include "cscore_cpp.h"
19
20namespace cs {
21
22/**
23 * @defgroup cscore_oo cscore C++ object-oriented API
24 *
25 * Recommended interface for C++, identical to Java API.
26 *
27 * <p>The classes are RAII and handle reference counting internally.
28 *
29 * @{
30 */
31
32// Forward declarations so friend declarations work correctly
33class ImageSource;
34class VideoEvent;
35class VideoSink;
36class VideoSource;
37
38/**
39 * A source or sink property.
40 */
42 friend class ImageSource;
43 friend class VideoEvent;
44 friend class VideoSink;
45 friend class VideoSource;
46
47 public:
48 enum Kind {
49 /// No specific property.
51 /// Boolean property.
53 /// Integer property.
55 /// String property.
57 /// Enum property.
59 };
60
61 VideoProperty() = default;
62
63 /**
64 * Returns property name.
65 *
66 * @return Property name.
67 */
68 std::string GetName() const {
69 m_status = 0;
70 return GetPropertyName(m_handle, &m_status);
71 }
72
73 /**
74 * Returns property kind.
75 *
76 * @return Property kind.
77 */
78 Kind GetKind() const { return m_kind; }
79
80 /**
81 * Returns true if property is valid.
82 *
83 * @return True if property is valid.
84 */
85 explicit operator bool() const { return m_kind != kNone; }
86
87 /**
88 * Returns true if property is a boolean.
89 *
90 * @return True if property is a boolean.
91 */
92 bool IsBoolean() const { return m_kind == kBoolean; }
93
94 /**
95 * Returns true if property is an integer.
96 *
97 * @return True if property is an integer.
98 */
99 bool IsInteger() const { return m_kind == kInteger; }
100
101 /**
102 * Returns true if property is a string.
103 *
104 * @return True if property is a string.
105 */
106 bool IsString() const { return m_kind == kString; }
107
108 /**
109 * Returns true if property is an enum.
110 *
111 * @return True if property is an enum.
112 */
113 bool IsEnum() const { return m_kind == kEnum; }
114
115 /**
116 * Returns property value.
117 *
118 * @return Property value.
119 */
120 int Get() const {
121 m_status = 0;
122 return GetProperty(m_handle, &m_status);
123 }
124
125 /**
126 * Sets property value.
127 *
128 * @param value Property value.
129 */
130 void Set(int value) {
131 m_status = 0;
132 SetProperty(m_handle, value, &m_status);
133 }
134
135 /**
136 * Returns property minimum value.
137 *
138 * @return Property minimum value.
139 */
140 int GetMin() const {
141 m_status = 0;
142 return GetPropertyMin(m_handle, &m_status);
143 }
144
145 /**
146 * Returns property maximum value.
147 *
148 * @return Property maximum value.
149 */
150 int GetMax() const {
151 m_status = 0;
152 return GetPropertyMax(m_handle, &m_status);
153 }
154
155 /**
156 * Returns property step size.
157 *
158 * @return Property step size.
159 */
160 int GetStep() const {
161 m_status = 0;
162 return GetPropertyStep(m_handle, &m_status);
163 }
164
165 /**
166 * Returns property default value.
167 *
168 * @return Property default value.
169 */
170 int GetDefault() const {
171 m_status = 0;
172 return GetPropertyDefault(m_handle, &m_status);
173 }
174
175 /**
176 * Returns the string property value.
177 *
178 * <p>This function is string-specific.
179 *
180 * @return The string property value.
181 */
182 std::string GetString() const {
183 m_status = 0;
184 return GetStringProperty(m_handle, &m_status);
185 }
186
187 /**
188 * Returns the string property value as a reference to the given buffer.
189 *
190 * This function is string-specific.
191 *
192 * @param buf The backing storage to which to write the property value.
193 * @return The string property value as a reference to the given buffer.
194 */
195 std::string_view GetString(wpi::SmallVectorImpl<char>& buf) const {
196 m_status = 0;
197 return GetStringProperty(m_handle, buf, &m_status);
198 }
199
200 /**
201 * Sets the string property value.
202 *
203 * This function is string-specific.
204 *
205 * @param value String property value.
206 */
207 void SetString(std::string_view value) {
208 m_status = 0;
209 SetStringProperty(m_handle, value, &m_status);
210 }
211
212 /**
213 * Returns the possible values for the enum property value.
214 *
215 * This function is enum-specific.
216 *
217 * @return The possible values for the enum property value.
218 */
219 std::vector<std::string> GetChoices() const {
220 m_status = 0;
221 return GetEnumPropertyChoices(m_handle, &m_status);
222 }
223
224 /**
225 * Returns the last status.
226 *
227 * @return The last status.
228 */
229 CS_Status GetLastStatus() const { return m_status; }
230
231 private:
232 explicit VideoProperty(CS_Property handle) : m_handle(handle) {
233 m_status = 0;
234 if (handle == 0) {
235 m_kind = kNone;
236 } else {
237 m_kind = static_cast<Kind>(
238 static_cast<int>(GetPropertyKind(handle, &m_status)));
239 }
240 }
241
242 VideoProperty(CS_Property handle, Kind kind)
243 : m_handle(handle), m_kind(kind) {}
244
245 mutable CS_Status m_status{0};
246 CS_Property m_handle{0};
247 Kind m_kind{kNone};
248};
249
250/**
251 * A source for video that provides a sequence of frames.
252 */
254 friend class VideoEvent;
255 friend class VideoSink;
256
257 public:
258 /**
259 * Video source kind.
260 */
261 enum Kind {
262 /// Unknown video source.
264 /// USB video source.
266 /// HTTP video source.
268 /// CV video source.
270 /// Raw video source.
272 };
273
274 /** Connection strategy. Used for SetConnectionStrategy(). */
276 /**
277 * Automatically connect or disconnect based on whether any sinks are
278 * connected to this source. This is the default behavior.
279 */
281
282 /**
283 * Try to keep the connection open regardless of whether any sinks are
284 * connected.
285 */
287
288 /**
289 * Never open the connection. If this is set when the connection is open,
290 * close the connection.
291 */
293 };
294
295 VideoSource() noexcept = default;
296
301
302 VideoSource(VideoSource&& other) noexcept : VideoSource() {
303 swap(*this, other);
304 }
305
307 swap(*this, other);
308 return *this;
309 }
310
312 m_status = 0;
313 if (m_handle != 0) {
315 }
316 }
317
318 explicit operator bool() const { return m_handle != 0; }
319
320 int GetHandle() const { return m_handle; }
321
322 bool operator==(const VideoSource& other) const {
323 return m_handle == other.m_handle;
324 }
325
326 /**
327 * Get the kind of the source.
328 */
329 Kind GetKind() const {
330 m_status = 0;
331 return static_cast<VideoSource::Kind>(GetSourceKind(m_handle, &m_status));
332 }
333
334 /**
335 * Get the name of the source. The name is an arbitrary identifier
336 * provided when the source is created, and should be unique.
337 */
338 std::string GetName() const {
339 m_status = 0;
341 }
342
343 /**
344 * Get the source description. This is source-kind specific.
345 */
346 std::string GetDescription() const {
347 m_status = 0;
349 }
350
351 /**
352 * Get the last time a frame was captured.
353 * This uses the same time base as wpi::Now().
354 *
355 * @return Time in 1 us increments.
356 */
357 uint64_t GetLastFrameTime() const {
358 m_status = 0;
360 }
361
362 /**
363 * Sets the connection strategy. By default, the source will automatically
364 * connect or disconnect based on whether any sinks are connected.
365 *
366 * <p>This function is non-blocking; look for either a connection open or
367 * close event or call IsConnected() to determine the connection state.
368 *
369 * @param strategy connection strategy (auto, keep open, or force close)
370 */
372 m_status = 0;
374 m_handle,
375 static_cast<CS_ConnectionStrategy>(static_cast<int>(strategy)),
376 &m_status);
377 }
378
379 /**
380 * Is the source currently connected to whatever is providing the images?
381 */
382 bool IsConnected() const {
383 m_status = 0;
385 }
386
387 /**
388 * Gets source enable status. This is determined with a combination of
389 * connection strategy and the number of sinks connected.
390 *
391 * @return True if enabled, false otherwise.
392 */
393 bool IsEnabled() const {
394 m_status = 0;
396 }
397
398 /** Get a property.
399 *
400 * @param name Property name
401 * @return Property contents (of kind Property::kNone if no property with
402 * the given name exists)
403 */
404 VideoProperty GetProperty(std::string_view name) {
405 m_status = 0;
407 }
408
409 /**
410 * Enumerate all properties of this source.
411 */
412 std::vector<VideoProperty> EnumerateProperties() const;
413
414 /**
415 * Get the current video mode.
416 */
418 m_status = 0;
420 }
421
422 /**
423 * Set the video mode.
424 *
425 * @param mode Video mode
426 */
427 bool SetVideoMode(const VideoMode& mode) {
428 m_status = 0;
429 return SetSourceVideoMode(m_handle, mode, &m_status);
430 }
431
432 /**
433 * Set the video mode.
434 *
435 * @param pixelFormat desired pixel format
436 * @param width desired width
437 * @param height desired height
438 * @param fps desired FPS
439 * @return True if set successfully
440 */
441 bool SetVideoMode(VideoMode::PixelFormat pixelFormat, int width, int height,
442 int fps) {
443 m_status = 0;
444 return SetSourceVideoMode(
445 m_handle, VideoMode{pixelFormat, width, height, fps}, &m_status);
446 }
447
448 /**
449 * Set the pixel format.
450 *
451 * @param pixelFormat desired pixel format
452 * @return True if set successfully
453 */
455 m_status = 0;
456 return SetSourcePixelFormat(m_handle, pixelFormat, &m_status);
457 }
458
459 /**
460 * Set the resolution.
461 *
462 * @param width desired width
463 * @param height desired height
464 * @return True if set successfully
465 */
466 bool SetResolution(int width, int height) {
467 m_status = 0;
468 return SetSourceResolution(m_handle, width, height, &m_status);
469 }
470
471 /**
472 * Set the frames per second (FPS).
473 *
474 * @param fps desired FPS
475 * @return True if set successfully
476 */
477 bool SetFPS(int fps) {
478 m_status = 0;
479 return SetSourceFPS(m_handle, fps, &m_status);
480 }
481
482 /**
483 * Set video mode and properties from a JSON configuration string.
484 *
485 * The format of the JSON input is:
486 *
487 * <pre>
488 * {
489 * "pixel format": "MJPEG", "YUYV", etc
490 * "width": video mode width
491 * "height": video mode height
492 * "fps": video mode fps
493 * "brightness": percentage brightness
494 * "white balance": "auto", "hold", or value
495 * "exposure": "auto", "hold", or value
496 * "properties": [
497 * {
498 * "name": property name
499 * "value": property value
500 * }
501 * ]
502 * }
503 * </pre>
504 *
505 * @param config configuration
506 * @return True if set successfully
507 */
508 bool SetConfigJson(std::string_view config) {
509 m_status = 0;
510 return SetSourceConfigJson(m_handle, config, &m_status);
511 }
512
513 /**
514 * Set video mode and properties from a JSON configuration object.
515 *
516 * @param config configuration
517 * @return True if set successfully
518 */
519 bool SetConfigJson(const wpi::json& config) {
520 m_status = 0;
521 return SetSourceConfigJson(m_handle, config, &m_status);
522 }
523
524 /**
525 * Get a JSON configuration string.
526 *
527 * @return JSON configuration string
528 */
529 std::string GetConfigJson() const {
530 m_status = 0;
532 }
533
534 /**
535 * Get a JSON configuration object.
536 *
537 * @return JSON configuration object
538 */
539 wpi::json GetConfigJsonObject() const;
540
541 /**
542 * Get the actual FPS.
543 *
544 * <p>SetTelemetryPeriod() must be called for this to be valid.
545 *
546 * @return Actual FPS averaged over the telemetry period.
547 */
553
554 /**
555 * Get the data rate (in bytes per second).
556 *
557 * <p>SetTelemetryPeriod() must be called for this to be valid.
558 *
559 * @return Data rate averaged over the telemetry period.
560 */
566
567 /**
568 * Enumerate all known video modes for this source.
569 */
570 std::vector<VideoMode> EnumerateVideoModes() const {
571 CS_Status status = 0;
572 return EnumerateSourceVideoModes(m_handle, &status);
573 }
574
575 CS_Status GetLastStatus() const { return m_status; }
576
577 /**
578 * Enumerate all sinks connected to this source.
579 *
580 * @return Vector of sinks.
581 */
582 std::vector<VideoSink> EnumerateSinks();
583
584 /**
585 * Enumerate all existing sources.
586 *
587 * @return Vector of sources.
588 */
589 static std::vector<VideoSource> EnumerateSources();
590
591 friend void swap(VideoSource& first, VideoSource& second) noexcept {
592 using std::swap;
593 swap(first.m_status, second.m_status);
594 swap(first.m_handle, second.m_handle);
595 }
596
597 protected:
598 explicit VideoSource(CS_Source handle) : m_handle(handle) {}
599
600 mutable CS_Status m_status = 0;
601
602 /// Video source handle.
604};
605
606/**
607 * A source that represents a video camera.
608 */
609class VideoCamera : public VideoSource {
610 public:
611 /**
612 * White balance.
613 */
615 /// Fixed indoor white balance.
617 /// Fixed outdoor white balance 1.
619 /// Fixed outdoor white balance 2.
621 /// Fixed fluorescent white balance 1.
623 /// Fixed fluorescent white balance 2.
624 kFixedFlourescent2 = 5200
625 };
626
627 VideoCamera() = default;
628
629 /**
630 * Set the brightness, as a percentage (0-100).
631 */
632 void SetBrightness(int brightness) {
633 m_status = 0;
635 }
636
637 /**
638 * Get the brightness, as a percentage (0-100).
639 */
641 m_status = 0;
643 }
644
645 /**
646 * Set the white balance to auto.
647 */
652
653 /**
654 * Set the white balance to hold current.
655 */
660
661 /**
662 * Set the white balance to manual, with specified color temperature.
663 */
664 void SetWhiteBalanceManual(int value) {
665 m_status = 0;
667 }
668
669 /**
670 * Set the exposure to auto aperture.
671 */
676
677 /**
678 * Set the exposure to hold current.
679 */
684
685 /**
686 * Set the exposure to manual, as a percentage (0-100).
687 */
688 void SetExposureManual(int value) {
689 m_status = 0;
691 }
692
693 protected:
694 explicit VideoCamera(CS_Source handle) : VideoSource(handle) {}
695};
696
697/**
698 * A source that represents a USB camera.
699 */
700class UsbCamera : public VideoCamera {
701 public:
702 UsbCamera() = default;
703
704 /**
705 * Create a source for a USB camera based on device number.
706 *
707 * @param name Source name (arbitrary unique identifier)
708 * @param dev Device number (e.g. 0 for /dev/video0)
709 */
710 UsbCamera(std::string_view name, int dev) {
711 m_handle = CreateUsbCameraDev(name, dev, &m_status);
712 }
713
714 /**
715 * Create a source for a USB camera based on device path.
716 *
717 * @param name Source name (arbitrary unique identifier)
718 * @param path Path to device (e.g. "/dev/video0" on Linux)
719 */
720 UsbCamera(std::string_view name, std::string_view path) {
721 m_handle = CreateUsbCameraPath(name, path, &m_status);
722 }
723
724 /**
725 * Enumerate USB cameras on the local system.
726 *
727 * @return Vector of USB camera information (one for each camera)
728 */
729 static std::vector<UsbCameraInfo> EnumerateUsbCameras() {
730 CS_Status status = 0;
731 return ::cs::EnumerateUsbCameras(&status);
732 }
733
734 /**
735 * Change the path to the device.
736 */
737 void SetPath(std::string_view path) {
738 m_status = 0;
739 return ::cs::SetUsbCameraPath(m_handle, path, &m_status);
740 }
741
742 /**
743 * Get the path to the device.
744 */
745 std::string GetPath() const {
746 m_status = 0;
747 return ::cs::GetUsbCameraPath(m_handle, &m_status);
748 }
749
750 /**
751 * Get the full camera information for the device.
752 */
754 m_status = 0;
755 return ::cs::GetUsbCameraInfo(m_handle, &m_status);
756 }
757
758 /**
759 * Set how verbose the camera connection messages are.
760 *
761 * @param level 0=don't display Connecting message, 1=do display message
762 */
763 void SetConnectVerbose(int level) {
764 m_status = 0;
765 SetProperty(GetSourceProperty(m_handle, "connect_verbose", &m_status),
766 level, &m_status);
767 }
768};
769
770/**
771 * A source that represents a MJPEG-over-HTTP (IP) camera.
772 */
773class HttpCamera : public VideoCamera {
774 public:
775 /**
776 * HTTP camera kind.
777 */
779 /// Unknown camera kind.
781 /// MJPG Streamer camera.
783 /// CS Core camera.
785 /// Axis camera.
787 };
788
789 /**
790 * Create a source for a MJPEG-over-HTTP (IP) camera.
791 *
792 * @param name Source name (arbitrary unique identifier)
793 * @param url Camera URL (e.g. "http://10.x.y.11/video/stream.mjpg")
794 * @param kind Camera kind (e.g. kAxis)
795 */
796 HttpCamera(std::string_view name, std::string_view url,
797 HttpCameraKind kind = kUnknown) {
799 name, url, static_cast<CS_HttpCameraKind>(static_cast<int>(kind)),
800 &m_status);
801 }
802
803 /**
804 * Create a source for a MJPEG-over-HTTP (IP) camera.
805 *
806 * @param name Source name (arbitrary unique identifier)
807 * @param url Camera URL (e.g. "http://10.x.y.11/video/stream.mjpg")
808 * @param kind Camera kind (e.g. kAxis)
809 */
810 HttpCamera(std::string_view name, const char* url,
811 HttpCameraKind kind = kUnknown) {
813 name, url, static_cast<CS_HttpCameraKind>(static_cast<int>(kind)),
814 &m_status);
815 }
816
817 /**
818 * Create a source for a MJPEG-over-HTTP (IP) camera.
819 *
820 * @param name Source name (arbitrary unique identifier)
821 * @param url Camera URL (e.g. "http://10.x.y.11/video/stream.mjpg")
822 * @param kind Camera kind (e.g. kAxis)
823 */
824 HttpCamera(std::string_view name, const std::string& url,
826 : HttpCamera(name, std::string_view{url}, kind) {}
827
828 /**
829 * Create a source for a MJPEG-over-HTTP (IP) camera.
830 *
831 * @param name Source name (arbitrary unique identifier)
832 * @param urls Array of Camera URLs
833 * @param kind Camera kind (e.g. kAxis)
834 */
835 HttpCamera(std::string_view name, std::span<const std::string> urls,
836 HttpCameraKind kind = kUnknown) {
838 name, urls, static_cast<CS_HttpCameraKind>(static_cast<int>(kind)),
839 &m_status);
840 }
841
842 /**
843 * Create a source for a MJPEG-over-HTTP (IP) camera.
844 *
845 * @param name Source name (arbitrary unique identifier)
846 * @param urls Array of Camera URLs
847 * @param kind Camera kind (e.g. kAxis)
848 */
849 template <typename T>
850 HttpCamera(std::string_view name, std::initializer_list<T> urls,
851 HttpCameraKind kind = kUnknown) {
852 std::vector<std::string> vec;
853 vec.reserve(urls.size());
854 for (const auto& url : urls) {
855 vec.emplace_back(url);
856 }
858 name, vec, static_cast<CS_HttpCameraKind>(static_cast<int>(kind)),
859 &m_status);
860 }
861
862 /**
863 * Get the kind of HTTP camera.
864 *
865 * <p>Autodetection can result in returning a different value than the camera
866 * was created with.
867 */
869 m_status = 0;
870 return static_cast<HttpCameraKind>(
871 static_cast<int>(::cs::GetHttpCameraKind(m_handle, &m_status)));
872 }
873
874 /**
875 * Change the URLs used to connect to the camera.
876 */
877 void SetUrls(std::span<const std::string> urls) {
878 m_status = 0;
880 }
881
882 /**
883 * Change the URLs used to connect to the camera.
884 */
885 template <typename T>
886 void SetUrls(std::initializer_list<T> urls) {
887 std::vector<std::string> vec;
888 vec.reserve(urls.size());
889 for (const auto& url : urls) {
890 vec.emplace_back(url);
891 }
892 m_status = 0;
894 }
895
896 /**
897 * Get the URLs used to connect to the camera.
898 */
899 std::vector<std::string> GetUrls() const {
900 m_status = 0;
901 return ::cs::GetHttpCameraUrls(m_handle, &m_status);
902 }
903};
904
905/**
906 * A source that represents an Axis IP camera.
907 *
908 * @deprecated Use HttpCamera instead.
909 */
910class [[deprecated("Use HttpCamera instead.")]] AxisCamera : public HttpCamera {
911 static std::string HostToUrl(std::string_view host);
912
913 static std::vector<std::string> HostToUrl(
914 std::span<const std::string> hosts) {
915 std::vector<std::string> rv;
916 rv.reserve(hosts.size());
917 for (const auto& host : hosts) {
918 rv.emplace_back(HostToUrl(std::string_view{host}));
919 }
920 return rv;
921 }
922
923 template <typename T>
924 static std::vector<std::string> HostToUrl(std::initializer_list<T> hosts) {
925 std::vector<std::string> rv;
926 rv.reserve(hosts.size());
927 for (const auto& host : hosts) {
928 rv.emplace_back(HostToUrl(std::string_view{host}));
929 }
930 return rv;
931 }
932
933 public:
934 /**
935 * Create a source for an Axis IP camera.
936 *
937 * @param name Source name (arbitrary unique identifier)
938 * @param host Camera host IP or DNS name (e.g. "10.x.y.11")
939 */
940 AxisCamera(std::string_view name, std::string_view host)
941 : HttpCamera(name, HostToUrl(host), kAxis) {}
942
943 /**
944 * Create a source for an Axis IP camera.
945 *
946 * @param name Source name (arbitrary unique identifier)
947 * @param host Camera host IP or DNS name (e.g. "10.x.y.11")
948 */
949 AxisCamera(std::string_view name, const char* host)
950 : HttpCamera(name, HostToUrl(host), kAxis) {}
951
952 /**
953 * Create a source for an Axis IP camera.
954 *
955 * @param name Source name (arbitrary unique identifier)
956 * @param host Camera host IP or DNS name (e.g. "10.x.y.11")
957 */
958 AxisCamera(std::string_view name, const std::string& host)
959 : HttpCamera(name, HostToUrl(std::string_view{host}), kAxis) {}
960
961 /**
962 * Create a source for an Axis IP camera.
963 *
964 * @param name Source name (arbitrary unique identifier)
965 * @param hosts Array of Camera host IPs/DNS names
966 */
967 AxisCamera(std::string_view name, std::span<const std::string> hosts)
968 : HttpCamera(name, HostToUrl(hosts), kAxis) {}
969
970 /**
971 * Create a source for an Axis IP camera.
972 *
973 * @param name Source name (arbitrary unique identifier)
974 * @param hosts Array of Camera host IPs/DNS names
975 */
976 template <typename T>
977 AxisCamera(std::string_view name, std::initializer_list<T> hosts)
978 : HttpCamera(name, HostToUrl(hosts), kAxis) {}
979};
980
981/**
982 * A base class for single image providing sources.
983 */
984class ImageSource : public VideoSource {
985 protected:
986 ImageSource() = default;
987
988 public:
989 /**
990 * Signal sinks that an error has occurred. This should be called instead
991 * of NotifyFrame when an error occurs.
992 *
993 * @param msg Notification message.
994 */
995 void NotifyError(std::string_view msg) {
996 m_status = 0;
998 }
999
1000 /**
1001 * Set source connection status. Defaults to true.
1002 *
1003 * @param connected True for connected, false for disconnected
1004 */
1005 void SetConnected(bool connected) {
1006 m_status = 0;
1007 SetSourceConnected(m_handle, connected, &m_status);
1008 }
1009
1010 /**
1011 * Set source description.
1012 *
1013 * @param description Description
1014 */
1015 void SetDescription(std::string_view description) {
1016 m_status = 0;
1017 SetSourceDescription(m_handle, description, &m_status);
1018 }
1019
1020 /**
1021 * Create a property.
1022 *
1023 * @param name Property name
1024 * @param kind Property kind
1025 * @param minimum Minimum value
1026 * @param maximum Maximum value
1027 * @param step Step value
1028 * @param defaultValue Default value
1029 * @param value Current value
1030 * @return Property
1031 */
1033 int minimum, int maximum, int step,
1034 int defaultValue, int value) {
1035 m_status = 0;
1037 m_handle, name, static_cast<CS_PropertyKind>(static_cast<int>(kind)),
1038 minimum, maximum, step, defaultValue, value, &m_status)};
1039 }
1040
1041 /**
1042 * Create an integer property.
1043 *
1044 * @param name Property name
1045 * @param minimum Minimum value
1046 * @param maximum Maximum value
1047 * @param step Step value
1048 * @param defaultValue Default value
1049 * @param value Current value
1050 * @return Property
1051 */
1052 VideoProperty CreateIntegerProperty(std::string_view name, int minimum,
1053 int maximum, int step, int defaultValue,
1054 int value) {
1055 m_status = 0;
1057 m_handle, name,
1058 static_cast<CS_PropertyKind>(
1059 static_cast<int>(VideoProperty::Kind::kInteger)),
1060 minimum, maximum, step, defaultValue, value, &m_status)};
1061 }
1062
1063 /**
1064 * Create a boolean property.
1065 *
1066 * @param name Property name
1067 * @param defaultValue Default value
1068 * @param value Current value
1069 * @return Property
1070 */
1071 VideoProperty CreateBooleanProperty(std::string_view name, bool defaultValue,
1072 bool value) {
1073 m_status = 0;
1075 m_handle, name,
1076 static_cast<CS_PropertyKind>(
1077 static_cast<int>(VideoProperty::Kind::kBoolean)),
1078 0, 1, 1, defaultValue ? 1 : 0, value ? 1 : 0, &m_status)};
1079 }
1080
1081 /**
1082 * Create a string property.
1083 *
1084 * @param name Property name
1085 * @param value Current value
1086 * @return Property
1087 */
1089 std::string_view value) {
1090 m_status = 0;
1092 m_handle, name,
1093 static_cast<CS_PropertyKind>(
1094 static_cast<int>(VideoProperty::Kind::kString)),
1095 0, 0, 0, 0, 0, &m_status)};
1096 prop.SetString(value);
1097 return prop;
1098 }
1099
1100 /**
1101 * Configure enum property choices.
1102 *
1103 * @param property Property
1104 * @param choices Choices
1105 */
1107 std::span<const std::string> choices) {
1108 m_status = 0;
1109 SetSourceEnumPropertyChoices(m_handle, property.m_handle, choices,
1110 &m_status);
1111 }
1112
1113 /**
1114 * Configure enum property choices.
1115 *
1116 * @param property Property
1117 * @param choices Choices
1118 */
1119 template <typename T>
1121 std::initializer_list<T> choices) {
1122 std::vector<std::string> vec;
1123 vec.reserve(choices.size());
1124 for (const auto& choice : choices) {
1125 vec.emplace_back(choice);
1126 }
1127 m_status = 0;
1128 SetSourceEnumPropertyChoices(m_handle, property.m_handle, vec, &m_status);
1129 }
1130};
1131
1132/**
1133 * A sink for video that accepts a sequence of frames.
1134 */
1136 friend class VideoEvent;
1137 friend class VideoSource;
1138
1139 public:
1140 enum Kind {
1141 /// Unknown sink type.
1143 /// MJPEG video sink.
1145 /// CV video sink.
1147 /// Raw video sink.
1149 };
1150
1151 VideoSink() noexcept = default;
1152
1154 : m_handle(sink.m_handle == 0 ? 0 : CopySink(sink.m_handle, &m_status)) {}
1155
1156 VideoSink(VideoSink&& other) noexcept : VideoSink() { swap(*this, other); }
1157
1158 VideoSink& operator=(VideoSink other) noexcept {
1159 swap(*this, other);
1160 return *this;
1161 }
1162
1164 m_status = 0;
1165 if (m_handle != 0) {
1167 }
1168 }
1169
1170 /**
1171 * Returns true if the VideoSink is valid.
1172 *
1173 * @return True if the VideoSink is valid.
1174 */
1175 explicit operator bool() const { return m_handle != 0; }
1176
1177 /**
1178 * Returns the VideoSink handle.
1179 *
1180 * @return The VideoSink handle.
1181 */
1182 int GetHandle() const { return m_handle; }
1183
1184 bool operator==(const VideoSink& other) const {
1185 return m_handle == other.m_handle;
1186 }
1187
1188 /**
1189 * Get the kind of the sink.
1190 */
1191 Kind GetKind() const {
1192 m_status = 0;
1193 return static_cast<VideoSink::Kind>(GetSinkKind(m_handle, &m_status));
1194 }
1195
1196 /**
1197 * Get the name of the sink. The name is an arbitrary identifier
1198 * provided when the sink is created, and should be unique.
1199 */
1200 std::string GetName() const {
1201 m_status = 0;
1202 return GetSinkName(m_handle, &m_status);
1203 }
1204
1205 /**
1206 * Get the sink description. This is sink-kind specific.
1207 */
1208 std::string GetDescription() const {
1209 m_status = 0;
1211 }
1212
1213 /**
1214 * Get a property of the sink.
1215 *
1216 * @param name Property name
1217 * @return Property (kind Property::kNone if no property with
1218 * the given name exists)
1219 */
1220 VideoProperty GetProperty(std::string_view name) {
1221 m_status = 0;
1223 }
1224
1225 /**
1226 * Enumerate all properties of this sink.
1227 */
1228 std::vector<VideoProperty> EnumerateProperties() const;
1229
1230 /**
1231 * Set properties from a JSON configuration string.
1232 *
1233 * The format of the JSON input is:
1234 *
1235 * <pre>
1236 * {
1237 * "properties": [
1238 * {
1239 * "name": property name
1240 * "value": property value
1241 * }
1242 * ]
1243 * }
1244 * </pre>
1245 *
1246 * @param config configuration
1247 * @return True if set successfully
1248 */
1249 bool SetConfigJson(std::string_view config) {
1250 m_status = 0;
1251 return SetSinkConfigJson(m_handle, config, &m_status);
1252 }
1253
1254 /**
1255 * Set properties from a JSON configuration object.
1256 *
1257 * @param config configuration
1258 * @return True if set successfully
1259 */
1260 bool SetConfigJson(const wpi::json& config) {
1261 m_status = 0;
1262 return SetSinkConfigJson(m_handle, config, &m_status);
1263 }
1264
1265 /**
1266 * Get a JSON configuration string.
1267 *
1268 * @return JSON configuration string
1269 */
1270 std::string GetConfigJson() const {
1271 m_status = 0;
1273 }
1274
1275 /**
1276 * Get a JSON configuration object.
1277 *
1278 * @return JSON configuration object
1279 */
1280 wpi::json GetConfigJsonObject() const;
1281
1282 /**
1283 * Configure which source should provide frames to this sink. Each sink
1284 * can accept frames from only a single source, but a single source can
1285 * provide frames to multiple clients.
1286 *
1287 * @param source Source
1288 */
1290 m_status = 0;
1291 if (!source) {
1293 } else {
1295 }
1296 }
1297
1298 /**
1299 * Get the connected source.
1300 *
1301 * @return Connected source (empty if none connected).
1302 */
1304 m_status = 0;
1305 auto handle = GetSinkSource(m_handle, &m_status);
1306 return VideoSource{handle == 0 ? 0 : CopySource(handle, &m_status)};
1307 }
1308
1309 /**
1310 * Get a property of the associated source.
1311 *
1312 * @param name Property name
1313 * @return Property (kind Property::kNone if no property with
1314 * the given name exists or no source connected)
1315 */
1316 VideoProperty GetSourceProperty(std::string_view name) {
1317 m_status = 0;
1319 }
1320
1322
1323 /**
1324 * Enumerate all existing sinks.
1325 *
1326 * @return Vector of sinks.
1327 */
1328 static std::vector<VideoSink> EnumerateSinks();
1329
1330 friend void swap(VideoSink& first, VideoSink& second) noexcept {
1331 using std::swap;
1332 swap(first.m_status, second.m_status);
1333 swap(first.m_handle, second.m_handle);
1334 }
1335
1336 protected:
1337 explicit VideoSink(CS_Sink handle) : m_handle(handle) {}
1338
1339 mutable CS_Status m_status = 0;
1341};
1342
1343/**
1344 * A sink that acts as a MJPEG-over-HTTP network server.
1345 */
1346class MjpegServer : public VideoSink {
1347 public:
1348 MjpegServer() = default;
1349
1350 /**
1351 * Create a MJPEG-over-HTTP server sink.
1352 *
1353 * @param name Sink name (arbitrary unique identifier)
1354 * @param listenAddress TCP listen address (empty string for all addresses)
1355 * @param port TCP port number
1356 */
1357 MjpegServer(std::string_view name, std::string_view listenAddress, int port) {
1358 m_handle = CreateMjpegServer(name, listenAddress, port, &m_status);
1359 }
1360
1361 /**
1362 * Create a MJPEG-over-HTTP server sink.
1363 *
1364 * @param name Sink name (arbitrary unique identifier)
1365 * @param port TCP port number
1366 */
1367 MjpegServer(std::string_view name, int port) : MjpegServer(name, "", port) {}
1368
1369 /**
1370 * Get the listen address of the server.
1371 */
1372 std::string GetListenAddress() const {
1373 m_status = 0;
1375 }
1376
1377 /**
1378 * Get the port number of the server.
1379 */
1380 int GetPort() const {
1381 m_status = 0;
1383 }
1384
1385 /**
1386 * Set the stream resolution for clients that don't specify it.
1387 *
1388 * <p>It is not necessary to set this if it is the same as the source
1389 * resolution.
1390 *
1391 * <p>Setting this different than the source resolution will result in
1392 * increased CPU usage, particularly for MJPEG source cameras, as it will
1393 * decompress, resize, and recompress the image, instead of using the
1394 * camera's MJPEG image directly.
1395 *
1396 * @param width width, 0 for unspecified
1397 * @param height height, 0 for unspecified
1398 */
1399 void SetResolution(int width, int height) {
1400 m_status = 0;
1401 SetProperty(GetSinkProperty(m_handle, "width", &m_status), width,
1402 &m_status);
1403 SetProperty(GetSinkProperty(m_handle, "height", &m_status), height,
1404 &m_status);
1405 }
1406
1407 /**
1408 * Set the stream frames per second (FPS) for clients that don't specify it.
1409 *
1410 * <p>It is not necessary to set this if it is the same as the source FPS.
1411 *
1412 * @param fps FPS, 0 for unspecified
1413 */
1414 void SetFPS(int fps) {
1415 m_status = 0;
1417 }
1418
1419 /**
1420 * Set the compression for clients that don't specify it.
1421 *
1422 * <p>Setting this will result in increased CPU usage for MJPEG source cameras
1423 * as it will decompress and recompress the image instead of using the
1424 * camera's MJPEG image directly.
1425 *
1426 * @param quality JPEG compression quality (0-100), -1 for unspecified
1427 */
1428 void SetCompression(int quality) {
1429 m_status = 0;
1430 SetProperty(GetSinkProperty(m_handle, "compression", &m_status), quality,
1431 &m_status);
1432 }
1433
1434 /**
1435 * Set the default compression used for non-MJPEG sources. If not set,
1436 * 80 is used. This function has no effect on MJPEG source cameras; use
1437 * SetCompression() instead to force recompression of MJPEG source images.
1438 *
1439 * @param quality JPEG compression quality (0-100)
1440 */
1441 void SetDefaultCompression(int quality) {
1442 m_status = 0;
1443 SetProperty(GetSinkProperty(m_handle, "default_compression", &m_status),
1444 quality, &m_status);
1445 }
1446};
1447
1448/**
1449 * A base class for single image reading sinks.
1450 */
1451class ImageSink : public VideoSink {
1452 protected:
1453 ImageSink() = default;
1454
1455 public:
1456 /**
1457 * Set sink description.
1458 *
1459 * @param description Description
1460 */
1461 void SetDescription(std::string_view description) {
1462 m_status = 0;
1463 SetSinkDescription(m_handle, description, &m_status);
1464 }
1465
1466 /**
1467 * Get error string. Call this if WaitForFrame() returns 0 to determine
1468 * what the error is.
1469 */
1470 std::string GetError() const {
1471 m_status = 0;
1472 return GetSinkError(m_handle, &m_status);
1473 }
1474
1475 /**
1476 * Enable or disable getting new frames.
1477 *
1478 * <p>Disabling will cause processFrame (for callback-based CvSinks) to not
1479 * be called and WaitForFrame() to not return. This can be used to save
1480 * processor resources when frames are not needed.
1481 */
1482 void SetEnabled(bool enabled) {
1483 m_status = 0;
1484 SetSinkEnabled(m_handle, enabled, &m_status);
1485 }
1486};
1487
1488/**
1489 * An event generated by the library and provided to event listeners.
1490 */
1491class VideoEvent : public RawEvent {
1492 public:
1493 /**
1494 * Returns the source associated with the event (if any).
1495 *
1496 * @return The source associated with the event (if any).
1497 */
1499 CS_Status status = 0;
1500 return VideoSource{sourceHandle == 0 ? 0
1501 : CopySource(sourceHandle, &status)};
1502 }
1503
1504 /**
1505 * Returns the sink associated with the event (if any).
1506 *
1507 * @return The sink associated with the event (if any).
1508 */
1510 CS_Status status = 0;
1511 return VideoSink{sinkHandle == 0 ? 0 : CopySink(sinkHandle, &status)};
1512 }
1513
1514 /**
1515 * Returns the property associated with the event (if any).
1516 *
1517 * @return The property associated with the event (if any).
1518 */
1521 static_cast<VideoProperty::Kind>(propertyKind)};
1522 }
1523};
1524
1525/**
1526 * An event listener. This calls back to a designated callback function when
1527 * an event matching the specified mask is generated by the library.
1528 */
1530 public:
1531 VideoListener() = default;
1532
1533 /**
1534 * Create an event listener.
1535 *
1536 * @param callback Callback function
1537 * @param eventMask Bitmask of VideoEvent::Kind values
1538 * @param immediateNotify Whether callback should be immediately called with
1539 * a representative set of events for the current library state.
1540 */
1541 VideoListener(std::function<void(const VideoEvent& event)> callback,
1542 int eventMask, bool immediateNotify) {
1543 CS_Status status = 0;
1544 m_handle = AddListener(
1545 [=](const RawEvent& event) {
1546 callback(static_cast<const VideoEvent&>(event));
1547 },
1548 eventMask, immediateNotify, &status);
1549 }
1550
1553
1555 swap(*this, other);
1556 }
1557
1559 swap(*this, other);
1560 return *this;
1561 }
1562
1564 CS_Status status = 0;
1565 if (m_handle != 0) {
1566 RemoveListener(m_handle, &status);
1567 }
1568 }
1569
1570 friend void swap(VideoListener& first, VideoListener& second) noexcept {
1571 using std::swap;
1572 swap(first.m_handle, second.m_handle);
1573 }
1574
1575 private:
1576 CS_Listener m_handle{0};
1577};
1578
1579/** @} */
1580
1581} // namespace cs
1582
1583#endif // CSCORE_CSCORE_OO_H_
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 and nanopb were all 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:124
A source that represents an Axis IP camera.
Definition cscore_oo.h:910
AxisCamera(std::string_view name, std::initializer_list< T > hosts)
Create a source for an Axis IP camera.
Definition cscore_oo.h:977
AxisCamera(std::string_view name, std::string_view host)
Create a source for an Axis IP camera.
Definition cscore_oo.h:940
AxisCamera(std::string_view name, const std::string &host)
Create a source for an Axis IP camera.
Definition cscore_oo.h:958
AxisCamera(std::string_view name, std::span< const std::string > hosts)
Create a source for an Axis IP camera.
Definition cscore_oo.h:967
AxisCamera(std::string_view name, const char *host)
Create a source for an Axis IP camera.
Definition cscore_oo.h:949
A source that represents a MJPEG-over-HTTP (IP) camera.
Definition cscore_oo.h:773
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 cscore_oo.h:835
HttpCamera(std::string_view name, std::string_view url, HttpCameraKind kind=kUnknown)
Create a source for a MJPEG-over-HTTP (IP) camera.
Definition cscore_oo.h:796
HttpCamera(std::string_view name, const char *url, HttpCameraKind kind=kUnknown)
Create a source for a MJPEG-over-HTTP (IP) camera.
Definition cscore_oo.h:810
std::vector< std::string > GetUrls() const
Get the URLs used to connect to the camera.
Definition cscore_oo.h:899
HttpCameraKind GetHttpCameraKind() const
Get the kind of HTTP camera.
Definition cscore_oo.h:868
void SetUrls(std::initializer_list< T > urls)
Change the URLs used to connect to the camera.
Definition cscore_oo.h:886
void SetUrls(std::span< const std::string > urls)
Change the URLs used to connect to the camera.
Definition cscore_oo.h:877
HttpCameraKind
HTTP camera kind.
Definition cscore_oo.h:778
@ kMJPGStreamer
MJPG Streamer camera.
Definition cscore_oo.h:782
@ kCSCore
CS Core camera.
Definition cscore_oo.h:784
@ kAxis
Axis camera.
Definition cscore_oo.h:786
@ kUnknown
Unknown camera kind.
Definition cscore_oo.h:780
HttpCamera(std::string_view name, const std::string &url, HttpCameraKind kind=kUnknown)
Create a source for a MJPEG-over-HTTP (IP) camera.
Definition cscore_oo.h:824
HttpCamera(std::string_view name, std::initializer_list< T > urls, HttpCameraKind kind=kUnknown)
Create a source for a MJPEG-over-HTTP (IP) camera.
Definition cscore_oo.h:850
A base class for single image reading sinks.
Definition cscore_oo.h:1451
void SetEnabled(bool enabled)
Enable or disable getting new frames.
Definition cscore_oo.h:1482
std::string GetError() const
Get error string.
Definition cscore_oo.h:1470
void SetDescription(std::string_view description)
Set sink description.
Definition cscore_oo.h:1461
ImageSink()=default
A base class for single image providing sources.
Definition cscore_oo.h:984
VideoProperty CreateBooleanProperty(std::string_view name, bool defaultValue, bool value)
Create a boolean property.
Definition cscore_oo.h:1071
ImageSource()=default
void SetDescription(std::string_view description)
Set source description.
Definition cscore_oo.h:1015
void SetEnumPropertyChoices(const VideoProperty &property, std::initializer_list< T > choices)
Configure enum property choices.
Definition cscore_oo.h:1120
VideoProperty CreateIntegerProperty(std::string_view name, int minimum, int maximum, int step, int defaultValue, int value)
Create an integer property.
Definition cscore_oo.h:1052
VideoProperty CreateProperty(std::string_view name, VideoProperty::Kind kind, int minimum, int maximum, int step, int defaultValue, int value)
Create a property.
Definition cscore_oo.h:1032
void SetConnected(bool connected)
Set source connection status.
Definition cscore_oo.h:1005
VideoProperty CreateStringProperty(std::string_view name, std::string_view value)
Create a string property.
Definition cscore_oo.h:1088
void NotifyError(std::string_view msg)
Signal sinks that an error has occurred.
Definition cscore_oo.h:995
void SetEnumPropertyChoices(const VideoProperty &property, std::span< const std::string > choices)
Configure enum property choices.
Definition cscore_oo.h:1106
A sink that acts as a MJPEG-over-HTTP network server.
Definition cscore_oo.h:1346
void SetFPS(int fps)
Set the stream frames per second (FPS) for clients that don't specify it.
Definition cscore_oo.h:1414
void SetResolution(int width, int height)
Set the stream resolution for clients that don't specify it.
Definition cscore_oo.h:1399
MjpegServer(std::string_view name, std::string_view listenAddress, int port)
Create a MJPEG-over-HTTP server sink.
Definition cscore_oo.h:1357
MjpegServer()=default
std::string GetListenAddress() const
Get the listen address of the server.
Definition cscore_oo.h:1372
MjpegServer(std::string_view name, int port)
Create a MJPEG-over-HTTP server sink.
Definition cscore_oo.h:1367
void SetDefaultCompression(int quality)
Set the default compression used for non-MJPEG sources.
Definition cscore_oo.h:1441
void SetCompression(int quality)
Set the compression for clients that don't specify it.
Definition cscore_oo.h:1428
int GetPort() const
Get the port number of the server.
Definition cscore_oo.h:1380
A source that represents a USB camera.
Definition cscore_oo.h:700
UsbCameraInfo GetInfo() const
Get the full camera information for the device.
Definition cscore_oo.h:753
static std::vector< UsbCameraInfo > EnumerateUsbCameras()
Enumerate USB cameras on the local system.
Definition cscore_oo.h:729
std::string GetPath() const
Get the path to the device.
Definition cscore_oo.h:745
UsbCamera(std::string_view name, std::string_view path)
Create a source for a USB camera based on device path.
Definition cscore_oo.h:720
void SetConnectVerbose(int level)
Set how verbose the camera connection messages are.
Definition cscore_oo.h:763
void SetPath(std::string_view path)
Change the path to the device.
Definition cscore_oo.h:737
UsbCamera(std::string_view name, int dev)
Create a source for a USB camera based on device number.
Definition cscore_oo.h:710
UsbCamera()=default
A source that represents a video camera.
Definition cscore_oo.h:609
VideoCamera(CS_Source handle)
Definition cscore_oo.h:694
void SetExposureAuto()
Set the exposure to auto aperture.
Definition cscore_oo.h:672
void SetWhiteBalanceManual(int value)
Set the white balance to manual, with specified color temperature.
Definition cscore_oo.h:664
void SetWhiteBalanceAuto()
Set the white balance to auto.
Definition cscore_oo.h:648
int GetBrightness()
Get the brightness, as a percentage (0-100).
Definition cscore_oo.h:640
void SetBrightness(int brightness)
Set the brightness, as a percentage (0-100).
Definition cscore_oo.h:632
void SetWhiteBalanceHoldCurrent()
Set the white balance to hold current.
Definition cscore_oo.h:656
VideoCamera()=default
void SetExposureManual(int value)
Set the exposure to manual, as a percentage (0-100).
Definition cscore_oo.h:688
WhiteBalance
White balance.
Definition cscore_oo.h:614
@ kFixedOutdoor1
Fixed outdoor white balance 1.
Definition cscore_oo.h:618
@ kFixedFlourescent2
Fixed fluorescent white balance 2.
Definition cscore_oo.h:624
@ kFixedIndoor
Fixed indoor white balance.
Definition cscore_oo.h:616
@ kFixedFluorescent1
Fixed fluorescent white balance 1.
Definition cscore_oo.h:622
@ kFixedOutdoor2
Fixed outdoor white balance 2.
Definition cscore_oo.h:620
void SetExposureHoldCurrent()
Set the exposure to hold current.
Definition cscore_oo.h:680
An event generated by the library and provided to event listeners.
Definition cscore_oo.h:1491
VideoSink GetSink() const
Returns the sink associated with the event (if any).
Definition cscore_oo.h:1509
VideoProperty GetProperty() const
Returns the property associated with the event (if any).
Definition cscore_oo.h:1519
VideoSource GetSource() const
Returns the source associated with the event (if any).
Definition cscore_oo.h:1498
An event listener.
Definition cscore_oo.h:1529
friend void swap(VideoListener &first, VideoListener &second) noexcept
Definition cscore_oo.h:1570
VideoListener & operator=(VideoListener &&other) noexcept
Definition cscore_oo.h:1558
~VideoListener()
Definition cscore_oo.h:1563
VideoListener(std::function< void(const VideoEvent &event)> callback, int eventMask, bool immediateNotify)
Create an event listener.
Definition cscore_oo.h:1541
VideoListener & operator=(const VideoListener &)=delete
VideoListener()=default
VideoListener(VideoListener &&other) noexcept
Definition cscore_oo.h:1554
VideoListener(const VideoListener &)=delete
A source or sink property.
Definition cscore_oo.h:41
int GetMin() const
Returns property minimum value.
Definition cscore_oo.h:140
int Get() const
Returns property value.
Definition cscore_oo.h:120
bool IsInteger() const
Returns true if property is an integer.
Definition cscore_oo.h:99
std::string_view GetString(wpi::SmallVectorImpl< char > &buf) const
Returns the string property value as a reference to the given buffer.
Definition cscore_oo.h:195
VideoProperty()=default
void SetString(std::string_view value)
Sets the string property value.
Definition cscore_oo.h:207
bool IsEnum() const
Returns true if property is an enum.
Definition cscore_oo.h:113
std::string GetName() const
Returns property name.
Definition cscore_oo.h:68
int GetDefault() const
Returns property default value.
Definition cscore_oo.h:170
Kind
Definition cscore_oo.h:48
@ kString
String property.
Definition cscore_oo.h:56
@ kInteger
Integer property.
Definition cscore_oo.h:54
@ kEnum
Enum property.
Definition cscore_oo.h:58
@ kBoolean
Boolean property.
Definition cscore_oo.h:52
@ kNone
No specific property.
Definition cscore_oo.h:50
CS_Status GetLastStatus() const
Returns the last status.
Definition cscore_oo.h:229
void Set(int value)
Sets property value.
Definition cscore_oo.h:130
bool IsBoolean() const
Returns true if property is a boolean.
Definition cscore_oo.h:92
std::vector< std::string > GetChoices() const
Returns the possible values for the enum property value.
Definition cscore_oo.h:219
int GetStep() const
Returns property step size.
Definition cscore_oo.h:160
Kind GetKind() const
Returns property kind.
Definition cscore_oo.h:78
bool IsString() const
Returns true if property is a string.
Definition cscore_oo.h:106
std::string GetString() const
Returns the string property value.
Definition cscore_oo.h:182
int GetMax() const
Returns property maximum value.
Definition cscore_oo.h:150
A sink for video that accepts a sequence of frames.
Definition cscore_oo.h:1135
VideoSink(VideoSink &&other) noexcept
Definition cscore_oo.h:1156
void SetSource(VideoSource source)
Configure which source should provide frames to this sink.
Definition cscore_oo.h:1289
Kind
Definition cscore_oo.h:1140
@ kCv
CV video sink.
Definition cscore_oo.h:1146
@ kUnknown
Unknown sink type.
Definition cscore_oo.h:1142
@ kRaw
Raw video sink.
Definition cscore_oo.h:1148
@ kMjpeg
MJPEG video sink.
Definition cscore_oo.h:1144
VideoProperty GetProperty(std::string_view name)
Get a property of the sink.
Definition cscore_oo.h:1220
friend void swap(VideoSink &first, VideoSink &second) noexcept
Definition cscore_oo.h:1330
std::string GetDescription() const
Get the sink description.
Definition cscore_oo.h:1208
std::vector< VideoProperty > EnumerateProperties() const
Enumerate all properties of this sink.
bool SetConfigJson(const wpi::json &config)
Set properties from a JSON configuration object.
Definition cscore_oo.h:1260
VideoProperty GetSourceProperty(std::string_view name)
Get a property of the associated source.
Definition cscore_oo.h:1316
bool SetConfigJson(std::string_view config)
Set properties from a JSON configuration string.
Definition cscore_oo.h:1249
int GetHandle() const
Returns the VideoSink handle.
Definition cscore_oo.h:1182
VideoSink & operator=(VideoSink other) noexcept
Definition cscore_oo.h:1158
VideoSource GetSource() const
Get the connected source.
Definition cscore_oo.h:1303
CS_Status m_status
Definition cscore_oo.h:1339
VideoSink() noexcept=default
std::string GetConfigJson() const
Get a JSON configuration string.
Definition cscore_oo.h:1270
bool operator==(const VideoSink &other) const
Definition cscore_oo.h:1184
CS_Sink m_handle
Definition cscore_oo.h:1340
VideoSink(CS_Sink handle)
Definition cscore_oo.h:1337
static std::vector< VideoSink > EnumerateSinks()
Enumerate all existing sinks.
std::string GetName() const
Get the name of the sink.
Definition cscore_oo.h:1200
CS_Status GetLastStatus() const
Definition cscore_oo.h:1321
wpi::json GetConfigJsonObject() const
Get a JSON configuration object.
~VideoSink()
Definition cscore_oo.h:1163
Kind GetKind() const
Get the kind of the sink.
Definition cscore_oo.h:1191
A source for video that provides a sequence of frames.
Definition cscore_oo.h:253
std::vector< VideoSink > EnumerateSinks()
Enumerate all sinks connected to this source.
bool SetPixelFormat(VideoMode::PixelFormat pixelFormat)
Set the pixel format.
Definition cscore_oo.h:454
double GetActualDataRate() const
Get the data rate (in bytes per second).
Definition cscore_oo.h:561
Kind GetKind() const
Get the kind of the source.
Definition cscore_oo.h:329
CS_Source m_handle
Video source handle.
Definition cscore_oo.h:603
VideoSource() noexcept=default
VideoProperty GetProperty(std::string_view name)
Get a property.
Definition cscore_oo.h:404
VideoMode GetVideoMode() const
Get the current video mode.
Definition cscore_oo.h:417
CS_Status m_status
Definition cscore_oo.h:600
~VideoSource()
Definition cscore_oo.h:311
int GetHandle() const
Definition cscore_oo.h:320
friend void swap(VideoSource &first, VideoSource &second) noexcept
Definition cscore_oo.h:591
VideoSource(CS_Source handle)
Definition cscore_oo.h:598
std::vector< VideoProperty > EnumerateProperties() const
Enumerate all properties of this source.
bool SetConfigJson(const wpi::json &config)
Set video mode and properties from a JSON configuration object.
Definition cscore_oo.h:519
bool IsConnected() const
Is the source currently connected to whatever is providing the images?
Definition cscore_oo.h:382
std::string GetDescription() const
Get the source description.
Definition cscore_oo.h:346
VideoSource(VideoSource &&other) noexcept
Definition cscore_oo.h:302
bool SetVideoMode(VideoMode::PixelFormat pixelFormat, int width, int height, int fps)
Set the video mode.
Definition cscore_oo.h:441
wpi::json GetConfigJsonObject() const
Get a JSON configuration object.
VideoSource & operator=(VideoSource other) noexcept
Definition cscore_oo.h:306
bool IsEnabled() const
Gets source enable status.
Definition cscore_oo.h:393
ConnectionStrategy
Connection strategy.
Definition cscore_oo.h:275
@ kConnectionKeepOpen
Try to keep the connection open regardless of whether any sinks are connected.
Definition cscore_oo.h:286
@ kConnectionAutoManage
Automatically connect or disconnect based on whether any sinks are connected to this source.
Definition cscore_oo.h:280
@ kConnectionForceClose
Never open the connection.
Definition cscore_oo.h:292
std::vector< VideoMode > EnumerateVideoModes() const
Enumerate all known video modes for this source.
Definition cscore_oo.h:570
uint64_t GetLastFrameTime() const
Get the last time a frame was captured.
Definition cscore_oo.h:357
double GetActualFPS() const
Get the actual FPS.
Definition cscore_oo.h:548
bool operator==(const VideoSource &other) const
Definition cscore_oo.h:322
Kind
Video source kind.
Definition cscore_oo.h:261
@ kCv
CV video source.
Definition cscore_oo.h:269
@ kHttp
HTTP video source.
Definition cscore_oo.h:267
@ kRaw
Raw video source.
Definition cscore_oo.h:271
@ kUnknown
Unknown video source.
Definition cscore_oo.h:263
@ kUsb
USB video source.
Definition cscore_oo.h:265
bool SetConfigJson(std::string_view config)
Set video mode and properties from a JSON configuration string.
Definition cscore_oo.h:508
bool SetFPS(int fps)
Set the frames per second (FPS).
Definition cscore_oo.h:477
static std::vector< VideoSource > EnumerateSources()
Enumerate all existing sources.
void SetConnectionStrategy(ConnectionStrategy strategy)
Sets the connection strategy.
Definition cscore_oo.h:371
CS_Status GetLastStatus() const
Definition cscore_oo.h:575
std::string GetConfigJson() const
Get a JSON configuration string.
Definition cscore_oo.h:529
bool SetResolution(int width, int height)
Set the resolution.
Definition cscore_oo.h:466
bool SetVideoMode(const VideoMode &mode)
Set the video mode.
Definition cscore_oo.h:427
std::string GetName() const
Get the name of the source.
Definition cscore_oo.h:338
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition sha1.h:30
CS_ConnectionStrategy
Connection strategy.
Definition cscore_c.h:177
CS_HttpCameraKind
HTTP Camera kinds.
Definition cscore_c.h:125
CS_PropertyKind
Property kinds.
Definition cscore_c.h:103
@ CS_CONNECTION_AUTO_MANAGE
Automatically connect or disconnect based on whether any sinks are connected to this source.
Definition cscore_c.h:182
@ CS_CONNECTION_KEEP_OPEN
Try to keep the connection open regardless of whether any sinks are connected.
Definition cscore_c.h:188
@ CS_CONNECTION_FORCE_CLOSE
Never open the connection.
Definition cscore_c.h:194
@ CS_HTTP_MJPGSTREAMER
Definition cscore_c.h:127
@ CS_HTTP_CSCORE
Definition cscore_c.h:128
@ CS_HTTP_UNKNOWN
Definition cscore_c.h:126
@ CS_HTTP_AXIS
Definition cscore_c.h:129
@ CS_PROP_ENUM
Definition cscore_c.h:108
@ CS_PROP_NONE
Definition cscore_c.h:104
@ CS_PROP_INTEGER
Definition cscore_c.h:106
@ CS_PROP_BOOLEAN
Definition cscore_c.h:105
@ CS_PROP_STRING
Definition cscore_c.h:107
@ CS_SOURCE_FRAMES_RECEIVED
Definition cscore_c.h:173
@ CS_SOURCE_BYTES_RECEIVED
Definition cscore_c.h:172
@ CS_SINK_MJPEG
Definition cscore_c.h:137
@ CS_SINK_RAW
Definition cscore_c.h:139
@ CS_SINK_CV
Definition cscore_c.h:138
@ CS_SINK_UNKNOWN
Definition cscore_c.h:136
@ CS_SOURCE_USB
Definition cscore_c.h:116
@ CS_SOURCE_HTTP
Definition cscore_c.h:117
@ CS_SOURCE_UNKNOWN
Definition cscore_c.h:115
@ CS_SOURCE_RAW
Definition cscore_c.h:119
@ CS_SOURCE_CV
Definition cscore_c.h:118
int GetCameraBrightness(CS_Source source, CS_Status *status)
void SetCameraExposureManual(CS_Source source, int value, CS_Status *status)
void SetCameraExposureAuto(CS_Source source, CS_Status *status)
void SetCameraWhiteBalanceManual(CS_Source source, int value, CS_Status *status)
void SetCameraBrightness(CS_Source source, int brightness, CS_Status *status)
void SetCameraWhiteBalanceHoldCurrent(CS_Source source, CS_Status *status)
void SetCameraWhiteBalanceAuto(CS_Source source, CS_Status *status)
void SetCameraExposureHoldCurrent(CS_Source source, CS_Status *status)
void SetSinkEnabled(CS_Sink sink, bool enabled, CS_Status *status)
void SetSinkDescription(CS_Sink sink, std::string_view description, CS_Status *status)
std::string GetSinkError(CS_Sink sink, CS_Status *status)
void SetSourceEnumPropertyChoices(CS_Source source, CS_Property property, std::span< const std::string > choices, CS_Status *status)
void SetSourceConnected(CS_Source source, bool connected, CS_Status *status)
void SetSourceDescription(CS_Source source, std::string_view description, CS_Status *status)
CS_Property CreateSourceProperty(CS_Source source, std::string_view name, CS_PropertyKind kind, int minimum, int maximum, int step, int defaultValue, int value, CS_Status *status)
void NotifySourceError(CS_Source source, std::string_view msg, CS_Status *status)
void SetHttpCameraUrls(CS_Source source, std::span< const std::string > urls, CS_Status *status)
CS_HttpCameraKind GetHttpCameraKind(CS_Source source, CS_Status *status)
CS_Listener AddListener(std::function< void(const RawEvent &event)> callback, int eventMask, bool immediateNotify, CS_Status *status)
void RemoveListener(CS_Listener handle, CS_Status *status)
int GetMjpegServerPort(CS_Sink sink, CS_Status *status)
std::string GetMjpegServerListenAddress(CS_Sink sink, CS_Status *status)
int GetPropertyMin(CS_Property property, CS_Status *status)
void SetProperty(CS_Property property, int value, CS_Status *status)
void SetStringProperty(CS_Property property, std::string_view value, CS_Status *status)
CS_PropertyKind GetPropertyKind(CS_Property property, CS_Status *status)
int GetPropertyDefault(CS_Property property, CS_Status *status)
int GetPropertyMax(CS_Property property, CS_Status *status)
int GetProperty(CS_Property property, CS_Status *status)
int GetPropertyStep(CS_Property property, CS_Status *status)
std::string GetStringProperty(CS_Property property, CS_Status *status)
std::vector< std::string > GetEnumPropertyChoices(CS_Property property, CS_Status *status)
std::string GetPropertyName(CS_Property property, CS_Status *status)
CS_Sink CreateMjpegServer(std::string_view name, std::string_view listenAddress, int port, CS_Status *status)
bool SetSinkConfigJson(CS_Sink sink, std::string_view config, CS_Status *status)
CS_Source GetSinkSource(CS_Sink sink, CS_Status *status)
CS_Sink CopySink(CS_Sink sink, CS_Status *status)
void SetSinkSource(CS_Sink sink, CS_Source source, CS_Status *status)
CS_Property GetSinkSourceProperty(CS_Sink sink, std::string_view name, CS_Status *status)
void ReleaseSink(CS_Sink sink, CS_Status *status)
std::string GetSinkDescription(CS_Sink sink, CS_Status *status)
std::string GetSinkName(CS_Sink sink, CS_Status *status)
std::string GetSinkConfigJson(CS_Sink sink, CS_Status *status)
CS_SinkKind GetSinkKind(CS_Sink sink, CS_Status *status)
CS_Property GetSinkProperty(CS_Sink sink, std::string_view name, CS_Status *status)
CS_Source CreateUsbCameraPath(std::string_view name, std::string_view path, CS_Status *status)
CS_Source CreateHttpCamera(std::string_view name, std::string_view url, CS_HttpCameraKind kind, CS_Status *status)
CS_Source CreateUsbCameraDev(std::string_view name, int dev, CS_Status *status)
void ReleaseSource(CS_Source source, CS_Status *status)
bool IsSourceConnected(CS_Source source, CS_Status *status)
uint64_t GetSourceLastFrameTime(CS_Source source, CS_Status *status)
bool SetSourceResolution(CS_Source source, int width, int height, CS_Status *status)
CS_Property GetSourceProperty(CS_Source source, std::string_view name, CS_Status *status)
bool SetSourceConfigJson(CS_Source source, std::string_view config, CS_Status *status)
bool SetSourcePixelFormat(CS_Source source, VideoMode::PixelFormat pixelFormat, CS_Status *status)
std::string GetSourceConfigJson(CS_Source source, CS_Status *status)
void SetSourceConnectionStrategy(CS_Source source, CS_ConnectionStrategy strategy, CS_Status *status)
VideoMode GetSourceVideoMode(CS_Source source, CS_Status *status)
CS_Source CopySource(CS_Source source, CS_Status *status)
bool IsSourceEnabled(CS_Source source, CS_Status *status)
std::vector< VideoMode > EnumerateSourceVideoModes(CS_Source source, CS_Status *status)
CS_SourceKind GetSourceKind(CS_Source source, CS_Status *status)
std::string GetSourceName(CS_Source source, CS_Status *status)
std::string GetSourceDescription(CS_Source source, CS_Status *status)
bool SetSourceVideoMode(CS_Source source, const VideoMode &mode, CS_Status *status)
bool SetSourceFPS(CS_Source source, int fps, CS_Status *status)
double GetTelemetryAverageValue(CS_Handle handle, CS_TelemetryKind kind, CS_Status *status)
CS_Handle CS_Source
Definition cscore_c.h:54
int CS_Status
Definition cscore_c.h:47
CS_Handle CS_Property
Definition cscore_c.h:50
CS_Handle CS_Sink
Definition cscore_c.h:53
CS_Handle CS_Listener
Definition cscore_c.h:51
CameraServer (cscore) namespace.
Definition ShuffleboardContainer.h:25
Implement std::hash so that hash_code can be used in STL containers.
Definition PointerIntPair.h:280
WPI_BASIC_JSON_TPL_DECLARATION void swap(wpi::WPI_BASIC_JSON_TPL &j1, wpi::WPI_BASIC_JSON_TPL &j2) noexcept(//NOLINT(readability-inconsistent-declaration-parameter-name, cert-dcl58-cpp) is_nothrow_move_constructible< wpi::WPI_BASIC_JSON_TPL >::value &&//NOLINT(misc-redundant-expression, cppcoreguidelines-noexcept-swap, performance-noexcept-swap) is_nothrow_move_assignable< wpi::WPI_BASIC_JSON_TPL >::value)
exchanges the values of two JSON objects
Definition json.h:5258
Listener event.
Definition cscore_cpp.h:102
CS_Sink sinkHandle
Definition cscore_cpp.h:157
CS_Property propertyHandle
Definition cscore_cpp.h:166
CS_Source sourceHandle
Definition cscore_cpp.h:156
CS_PropertyKind propertyKind
Definition cscore_cpp.h:167
USB camera information.
Definition cscore_cpp.h:44
Video mode.
Definition cscore_cpp.h:62
PixelFormat
Definition cscore_cpp.h:63