WPILibC++ 2024.1.1-beta-4
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 "cscore_cpp.h"
17
18namespace cs {
19
20/**
21 * @defgroup cscore_oo cscore C++ object-oriented API
22 *
23 * Recommended interface for C++, identical to Java API.
24 *
25 * <p>The classes are RAII and handle reference counting internally.
26 *
27 * @{
28 */
29
30// Forward declarations so friend declarations work correctly
31class ImageSource;
32class VideoEvent;
33class VideoSink;
34class VideoSource;
35
36/**
37 * A source or sink property.
38 */
40 friend class ImageSource;
41 friend class VideoEvent;
42 friend class VideoSink;
43 friend class VideoSource;
44
45 public:
46 enum Kind {
52 };
53
54 VideoProperty() = default;
55
56 std::string GetName() const;
57
58 Kind GetKind() const { return m_kind; }
59
60 explicit operator bool() const { return m_kind != kNone; }
61
62 // Kind checkers
63 bool IsBoolean() const { return m_kind == kBoolean; }
64 bool IsInteger() const { return m_kind == kInteger; }
65 bool IsString() const { return m_kind == kString; }
66 bool IsEnum() const { return m_kind == kEnum; }
67
68 int Get() const;
69 void Set(int value);
70 int GetMin() const;
71 int GetMax() const;
72 int GetStep() const;
73 int GetDefault() const;
74
75 // String-specific functions
76 std::string GetString() const;
78 void SetString(std::string_view value);
79
80 // Enum-specific functions
81 std::vector<std::string> GetChoices() const;
82
83 CS_Status GetLastStatus() const { return m_status; }
84
85 private:
86 explicit VideoProperty(CS_Property handle);
87 VideoProperty(CS_Property handle, Kind kind);
88
89 mutable CS_Status m_status{0};
90 CS_Property m_handle{0};
91 Kind m_kind{kNone};
92};
93
94/**
95 * A source for video that provides a sequence of frames.
96 */
98 friend class VideoEvent;
99 friend class VideoSink;
100
101 public:
102 enum Kind {
107 };
108
109 /** Connection strategy. Used for SetConnectionStrategy(). */
111 /**
112 * Automatically connect or disconnect based on whether any sinks are
113 * connected to this source. This is the default behavior.
114 */
116
117 /**
118 * Try to keep the connection open regardless of whether any sinks are
119 * connected.
120 */
122
123 /**
124 * Never open the connection. If this is set when the connection is open,
125 * close the connection.
126 */
128 };
129
130 VideoSource() noexcept = default;
132 VideoSource(VideoSource&& other) noexcept;
133 VideoSource& operator=(VideoSource other) noexcept;
134 ~VideoSource();
135
136 explicit operator bool() const { return m_handle != 0; }
137
138 int GetHandle() const { return m_handle; }
139
140 bool operator==(const VideoSource& other) const {
141 return m_handle == other.m_handle;
142 }
143
144 /**
145 * Get the kind of the source.
146 */
147 Kind GetKind() const;
148
149 /**
150 * Get the name of the source. The name is an arbitrary identifier
151 * provided when the source is created, and should be unique.
152 */
153 std::string GetName() const;
154
155 /**
156 * Get the source description. This is source-kind specific.
157 */
158 std::string GetDescription() const;
159
160 /**
161 * Get the last time a frame was captured.
162 * This uses the same time base as wpi::Now().
163 *
164 * @return Time in 1 us increments.
165 */
166 uint64_t GetLastFrameTime() const;
167
168 /**
169 * Sets the connection strategy. By default, the source will automatically
170 * connect or disconnect based on whether any sinks are connected.
171 *
172 * <p>This function is non-blocking; look for either a connection open or
173 * close event or call IsConnected() to determine the connection state.
174 *
175 * @param strategy connection strategy (auto, keep open, or force close)
176 */
178
179 /**
180 * Is the source currently connected to whatever is providing the images?
181 */
182 bool IsConnected() const;
183
184 /**
185 * Gets source enable status. This is determined with a combination of
186 * connection strategy and the number of sinks connected.
187 *
188 * @return True if enabled, false otherwise.
189 */
190 bool IsEnabled() const;
191
192 /** Get a property.
193 *
194 * @param name Property name
195 * @return Property contents (of kind Property::kNone if no property with
196 * the given name exists)
197 */
199
200 /**
201 * Enumerate all properties of this source.
202 */
203 std::vector<VideoProperty> EnumerateProperties() const;
204
205 /**
206 * Get the current video mode.
207 */
208 VideoMode GetVideoMode() const;
209
210 /**
211 * Set the video mode.
212 *
213 * @param mode Video mode
214 */
215 bool SetVideoMode(const VideoMode& mode);
216
217 /**
218 * Set the video mode.
219 *
220 * @param pixelFormat desired pixel format
221 * @param width desired width
222 * @param height desired height
223 * @param fps desired FPS
224 * @return True if set successfully
225 */
226 bool SetVideoMode(VideoMode::PixelFormat pixelFormat, int width, int height,
227 int fps);
228
229 /**
230 * Set the pixel format.
231 *
232 * @param pixelFormat desired pixel format
233 * @return True if set successfully
234 */
235 bool SetPixelFormat(VideoMode::PixelFormat pixelFormat);
236
237 /**
238 * Set the resolution.
239 *
240 * @param width desired width
241 * @param height desired height
242 * @return True if set successfully
243 */
244 bool SetResolution(int width, int height);
245
246 /**
247 * Set the frames per second (FPS).
248 *
249 * @param fps desired FPS
250 * @return True if set successfully
251 */
252 bool SetFPS(int fps);
253
254 /**
255 * Set video mode and properties from a JSON configuration string.
256 *
257 * The format of the JSON input is:
258 *
259 * <pre>
260 * {
261 * "pixel format": "MJPEG", "YUYV", etc
262 * "width": video mode width
263 * "height": video mode height
264 * "fps": video mode fps
265 * "brightness": percentage brightness
266 * "white balance": "auto", "hold", or value
267 * "exposure": "auto", "hold", or value
268 * "properties": [
269 * {
270 * "name": property name
271 * "value": property value
272 * }
273 * ]
274 * }
275 * </pre>
276 *
277 * @param config configuration
278 * @return True if set successfully
279 */
280 bool SetConfigJson(std::string_view config);
281
282 /**
283 * Set video mode and properties from a JSON configuration object.
284 *
285 * @param config configuration
286 * @return True if set successfully
287 */
288 bool SetConfigJson(const wpi::json& config);
289
290 /**
291 * Get a JSON configuration string.
292 *
293 * @return JSON configuration string
294 */
295 std::string GetConfigJson() const;
296
297 /**
298 * Get a JSON configuration object.
299 *
300 * @return JSON configuration object
301 */
302 wpi::json GetConfigJsonObject() const;
303
304 /**
305 * Get the actual FPS.
306 *
307 * <p>SetTelemetryPeriod() must be called for this to be valid.
308 *
309 * @return Actual FPS averaged over the telemetry period.
310 */
311 double GetActualFPS() const;
312
313 /**
314 * Get the data rate (in bytes per second).
315 *
316 * <p>SetTelemetryPeriod() must be called for this to be valid.
317 *
318 * @return Data rate averaged over the telemetry period.
319 */
320 double GetActualDataRate() const;
321
322 /**
323 * Enumerate all known video modes for this source.
324 */
325 std::vector<VideoMode> EnumerateVideoModes() const;
326
327 CS_Status GetLastStatus() const { return m_status; }
328
329 /**
330 * Enumerate all sinks connected to this source.
331 *
332 * @return Vector of sinks.
333 */
334 std::vector<VideoSink> EnumerateSinks();
335
336 /**
337 * Enumerate all existing sources.
338 *
339 * @return Vector of sources.
340 */
341 static std::vector<VideoSource> EnumerateSources();
342
343 friend void swap(VideoSource& first, VideoSource& second) noexcept {
344 using std::swap;
345 swap(first.m_status, second.m_status);
346 swap(first.m_handle, second.m_handle);
347 }
348
349 protected:
350 explicit VideoSource(CS_Source handle) : m_handle(handle) {}
351
352 mutable CS_Status m_status = 0;
354};
355
356/**
357 * A source that represents a video camera.
358 */
359class VideoCamera : public VideoSource {
360 public:
366 kFixedFlourescent2 = 5200
367 };
368
369 VideoCamera() = default;
370
371 /**
372 * Set the brightness, as a percentage (0-100).
373 */
374 void SetBrightness(int brightness);
375
376 /**
377 * Get the brightness, as a percentage (0-100).
378 */
379 int GetBrightness();
380
381 /**
382 * Set the white balance to auto.
383 */
384 void SetWhiteBalanceAuto();
385
386 /**
387 * Set the white balance to hold current.
388 */
390
391 /**
392 * Set the white balance to manual, with specified color temperature.
393 */
394 void SetWhiteBalanceManual(int value);
395
396 /**
397 * Set the exposure to auto aperature.
398 */
399 void SetExposureAuto();
400
401 /**
402 * Set the exposure to hold current.
403 */
405
406 /**
407 * Set the exposure to manual, as a percentage (0-100).
408 */
409 void SetExposureManual(int value);
410
411 protected:
412 explicit VideoCamera(CS_Source handle) : VideoSource(handle) {}
413};
414
415/**
416 * A source that represents a USB camera.
417 */
418class UsbCamera : public VideoCamera {
419 public:
420 UsbCamera() = default;
421
422 /**
423 * Create a source for a USB camera based on device number.
424 *
425 * @param name Source name (arbitrary unique identifier)
426 * @param dev Device number (e.g. 0 for /dev/video0)
427 */
428 UsbCamera(std::string_view name, int dev);
429
430 /**
431 * Create a source for a USB camera based on device path.
432 *
433 * @param name Source name (arbitrary unique identifier)
434 * @param path Path to device (e.g. "/dev/video0" on Linux)
435 */
437
438 /**
439 * Enumerate USB cameras on the local system.
440 *
441 * @return Vector of USB camera information (one for each camera)
442 */
443 static std::vector<UsbCameraInfo> EnumerateUsbCameras();
444
445 /**
446 * Change the path to the device.
447 */
448 void SetPath(std::string_view path);
449
450 /**
451 * Get the path to the device.
452 */
453 std::string GetPath() const;
454
455 /**
456 * Get the full camera information for the device.
457 */
458 UsbCameraInfo GetInfo() const;
459
460 /**
461 * Set how verbose the camera connection messages are.
462 *
463 * @param level 0=don't display Connecting message, 1=do display message
464 */
465 void SetConnectVerbose(int level);
466};
467
468/**
469 * A source that represents a MJPEG-over-HTTP (IP) camera.
470 */
471class HttpCamera : public VideoCamera {
472 public:
478 };
479
480 /**
481 * Create a source for a MJPEG-over-HTTP (IP) camera.
482 *
483 * @param name Source name (arbitrary unique identifier)
484 * @param url Camera URL (e.g. "http://10.x.y.11/video/stream.mjpg")
485 * @param kind Camera kind (e.g. kAxis)
486 */
488 HttpCameraKind kind = kUnknown);
489
490 /**
491 * Create a source for a MJPEG-over-HTTP (IP) camera.
492 *
493 * @param name Source name (arbitrary unique identifier)
494 * @param url Camera URL (e.g. "http://10.x.y.11/video/stream.mjpg")
495 * @param kind Camera kind (e.g. kAxis)
496 */
497 HttpCamera(std::string_view name, const char* url,
498 HttpCameraKind kind = kUnknown);
499
500 /**
501 * Create a source for a MJPEG-over-HTTP (IP) camera.
502 *
503 * @param name Source name (arbitrary unique identifier)
504 * @param url Camera URL (e.g. "http://10.x.y.11/video/stream.mjpg")
505 * @param kind Camera kind (e.g. kAxis)
506 */
507 HttpCamera(std::string_view name, const std::string& url,
508 HttpCameraKind kind = kUnknown);
509
510 /**
511 * Create a source for a MJPEG-over-HTTP (IP) camera.
512 *
513 * @param name Source name (arbitrary unique identifier)
514 * @param urls Array of Camera URLs
515 * @param kind Camera kind (e.g. kAxis)
516 */
517 HttpCamera(std::string_view name, std::span<const std::string> urls,
518 HttpCameraKind kind = kUnknown);
519
520 /**
521 * Create a source for a MJPEG-over-HTTP (IP) camera.
522 *
523 * @param name Source name (arbitrary unique identifier)
524 * @param urls Array of Camera URLs
525 * @param kind Camera kind (e.g. kAxis)
526 */
527 template <typename T>
528 HttpCamera(std::string_view name, std::initializer_list<T> urls,
529 HttpCameraKind kind = kUnknown);
530
531 /**
532 * Get the kind of HTTP camera.
533 *
534 * <p>Autodetection can result in returning a different value than the camera
535 * was created with.
536 */
538
539 /**
540 * Change the URLs used to connect to the camera.
541 */
542 void SetUrls(std::span<const std::string> urls);
543
544 /**
545 * Change the URLs used to connect to the camera.
546 */
547 template <typename T>
548 void SetUrls(std::initializer_list<T> urls);
549
550 /**
551 * Get the URLs used to connect to the camera.
552 */
553 std::vector<std::string> GetUrls() const;
554};
555
556/**
557 * A source that represents an Axis IP camera.
558 */
559class AxisCamera : public HttpCamera {
560 static std::string HostToUrl(std::string_view host);
561 static std::vector<std::string> HostToUrl(std::span<const std::string> hosts);
562 template <typename T>
563 static std::vector<std::string> HostToUrl(std::initializer_list<T> hosts);
564
565 public:
566 /**
567 * Create a source for an Axis IP camera.
568 *
569 * @param name Source name (arbitrary unique identifier)
570 * @param host Camera host IP or DNS name (e.g. "10.x.y.11")
571 */
573
574 /**
575 * Create a source for an Axis IP camera.
576 *
577 * @param name Source name (arbitrary unique identifier)
578 * @param host Camera host IP or DNS name (e.g. "10.x.y.11")
579 */
580 AxisCamera(std::string_view name, const char* host);
581
582 /**
583 * Create a source for an Axis IP camera.
584 *
585 * @param name Source name (arbitrary unique identifier)
586 * @param host Camera host IP or DNS name (e.g. "10.x.y.11")
587 */
588 AxisCamera(std::string_view name, const std::string& host);
589
590 /**
591 * Create a source for an Axis IP camera.
592 *
593 * @param name Source name (arbitrary unique identifier)
594 * @param hosts Array of Camera host IPs/DNS names
595 */
596 AxisCamera(std::string_view name, std::span<const std::string> hosts);
597
598 /**
599 * Create a source for an Axis IP camera.
600 *
601 * @param name Source name (arbitrary unique identifier)
602 * @param hosts Array of Camera host IPs/DNS names
603 */
604 template <typename T>
605 AxisCamera(std::string_view name, std::initializer_list<T> hosts);
606};
607
608/**
609 * A base class for single image providing sources.
610 */
611class ImageSource : public VideoSource {
612 protected:
613 ImageSource() = default;
614
615 public:
616 /**
617 * Signal sinks that an error has occurred. This should be called instead
618 * of NotifyFrame when an error occurs.
619 *
620 * @param msg Notification message.
621 */
623
624 /**
625 * Set source connection status. Defaults to true.
626 *
627 * @param connected True for connected, false for disconnected
628 */
629 void SetConnected(bool connected);
630
631 /**
632 * Set source description.
633 *
634 * @param description Description
635 */
636 void SetDescription(std::string_view description);
637
638 /**
639 * Create a property.
640 *
641 * @param name Property name
642 * @param kind Property kind
643 * @param minimum Minimum value
644 * @param maximum Maximum value
645 * @param step Step value
646 * @param defaultValue Default value
647 * @param value Current value
648 * @return Property
649 */
651 int minimum, int maximum, int step,
652 int defaultValue, int value);
653
654 /**
655 * Create an integer property.
656 *
657 * @param name Property name
658 * @param minimum Minimum value
659 * @param maximum Maximum value
660 * @param step Step value
661 * @param defaultValue Default value
662 * @param value Current value
663 * @return Property
664 */
666 int maximum, int step, int defaultValue,
667 int value);
668
669 /**
670 * Create a boolean property.
671 *
672 * @param name Property name
673 * @param defaultValue Default value
674 * @param value Current value
675 * @return Property
676 */
678 bool value);
679
680 /**
681 * Create a string property.
682 *
683 * @param name Property name
684 * @param value Current value
685 * @return Property
686 */
688 std::string_view value);
689
690 /**
691 * Configure enum property choices.
692 *
693 * @param property Property
694 * @param choices Choices
695 */
696 void SetEnumPropertyChoices(const VideoProperty& property,
697 std::span<const std::string> choices);
698
699 /**
700 * Configure enum property choices.
701 *
702 * @param property Property
703 * @param choices Choices
704 */
705 template <typename T>
706 void SetEnumPropertyChoices(const VideoProperty& property,
707 std::initializer_list<T> choices);
708};
709
710/**
711 * A sink for video that accepts a sequence of frames.
712 */
714 friend class VideoEvent;
715 friend class VideoSource;
716
717 public:
718 enum Kind {
722 };
723
724 VideoSink() noexcept = default;
725 VideoSink(const VideoSink& sink);
726 VideoSink(VideoSink&& sink) noexcept;
727 VideoSink& operator=(VideoSink other) noexcept;
728 ~VideoSink();
729
730 explicit operator bool() const { return m_handle != 0; }
731
732 int GetHandle() const { return m_handle; }
733
734 bool operator==(const VideoSink& other) const {
735 return m_handle == other.m_handle;
736 }
737
738 /**
739 * Get the kind of the sink.
740 */
741 Kind GetKind() const;
742
743 /**
744 * Get the name of the sink. The name is an arbitrary identifier
745 * provided when the sink is created, and should be unique.
746 */
747 std::string GetName() const;
748
749 /**
750 * Get the sink description. This is sink-kind specific.
751 */
752 std::string GetDescription() const;
753
754 /**
755 * Get a property of the sink.
756 *
757 * @param name Property name
758 * @return Property (kind Property::kNone if no property with
759 * the given name exists)
760 */
762
763 /**
764 * Enumerate all properties of this sink.
765 */
766 std::vector<VideoProperty> EnumerateProperties() const;
767
768 /**
769 * Set properties from a JSON configuration string.
770 *
771 * The format of the JSON input is:
772 *
773 * <pre>
774 * {
775 * "properties": [
776 * {
777 * "name": property name
778 * "value": property value
779 * }
780 * ]
781 * }
782 * </pre>
783 *
784 * @param config configuration
785 * @return True if set successfully
786 */
787 bool SetConfigJson(std::string_view config);
788
789 /**
790 * Set properties from a JSON configuration object.
791 *
792 * @param config configuration
793 * @return True if set successfully
794 */
795 bool SetConfigJson(const wpi::json& config);
796
797 /**
798 * Get a JSON configuration string.
799 *
800 * @return JSON configuration string
801 */
802 std::string GetConfigJson() const;
803
804 /**
805 * Get a JSON configuration object.
806 *
807 * @return JSON configuration object
808 */
809 wpi::json GetConfigJsonObject() const;
810
811 /**
812 * Configure which source should provide frames to this sink. Each sink
813 * can accept frames from only a single source, but a single source can
814 * provide frames to multiple clients.
815 *
816 * @param source Source
817 */
819
820 /**
821 * Get the connected source.
822 *
823 * @return Connected source (empty if none connected).
824 */
825 VideoSource GetSource() const;
826
827 /**
828 * Get a property of the associated source.
829 *
830 * @param name Property name
831 * @return Property (kind Property::kNone if no property with
832 * the given name exists or no source connected)
833 */
835
836 CS_Status GetLastStatus() const { return m_status; }
837
838 /**
839 * Enumerate all existing sinks.
840 *
841 * @return Vector of sinks.
842 */
843 static std::vector<VideoSink> EnumerateSinks();
844
845 friend void swap(VideoSink& first, VideoSink& second) noexcept {
846 using std::swap;
847 swap(first.m_status, second.m_status);
848 swap(first.m_handle, second.m_handle);
849 }
850
851 protected:
852 explicit VideoSink(CS_Sink handle) : m_handle(handle) {}
853
854 mutable CS_Status m_status = 0;
856};
857
858/**
859 * A sink that acts as a MJPEG-over-HTTP network server.
860 */
861class MjpegServer : public VideoSink {
862 public:
863 MjpegServer() = default;
864
865 /**
866 * Create a MJPEG-over-HTTP server sink.
867 *
868 * @param name Sink name (arbitrary unique identifier)
869 * @param listenAddress TCP listen address (empty string for all addresses)
870 * @param port TCP port number
871 */
872 MjpegServer(std::string_view name, std::string_view listenAddress, int port);
873
874 /**
875 * Create a MJPEG-over-HTTP server sink.
876 *
877 * @param name Sink name (arbitrary unique identifier)
878 * @param port TCP port number
879 */
880 MjpegServer(std::string_view name, int port) : MjpegServer(name, "", port) {}
881
882 /**
883 * Get the listen address of the server.
884 */
885 std::string GetListenAddress() const;
886
887 /**
888 * Get the port number of the server.
889 */
890 int GetPort() const;
891
892 /**
893 * Set the stream resolution for clients that don't specify it.
894 *
895 * <p>It is not necessary to set this if it is the same as the source
896 * resolution.
897 *
898 * <p>Setting this different than the source resolution will result in
899 * increased CPU usage, particularly for MJPEG source cameras, as it will
900 * decompress, resize, and recompress the image, instead of using the
901 * camera's MJPEG image directly.
902 *
903 * @param width width, 0 for unspecified
904 * @param height height, 0 for unspecified
905 */
906 void SetResolution(int width, int height);
907
908 /**
909 * Set the stream frames per second (FPS) for clients that don't specify it.
910 *
911 * <p>It is not necessary to set this if it is the same as the source FPS.
912 *
913 * @param fps FPS, 0 for unspecified
914 */
915 void SetFPS(int fps);
916
917 /**
918 * Set the compression for clients that don't specify it.
919 *
920 * <p>Setting this will result in increased CPU usage for MJPEG source cameras
921 * as it will decompress and recompress the image instead of using the
922 * camera's MJPEG image directly.
923 *
924 * @param quality JPEG compression quality (0-100), -1 for unspecified
925 */
926 void SetCompression(int quality);
927
928 /**
929 * Set the default compression used for non-MJPEG sources. If not set,
930 * 80 is used. This function has no effect on MJPEG source cameras; use
931 * SetCompression() instead to force recompression of MJPEG source images.
932 *
933 * @param quality JPEG compression quality (0-100)
934 */
935 void SetDefaultCompression(int quality);
936};
937
938/**
939 * A base class for single image reading sinks.
940 */
941class ImageSink : public VideoSink {
942 protected:
943 ImageSink() = default;
944
945 public:
946 /**
947 * Set sink description.
948 *
949 * @param description Description
950 */
951 void SetDescription(std::string_view description);
952
953 /**
954 * Get error string. Call this if WaitForFrame() returns 0 to determine
955 * what the error is.
956 */
957 std::string GetError() const;
958
959 /**
960 * Enable or disable getting new frames.
961 *
962 * <p>Disabling will cause processFrame (for callback-based CvSinks) to not
963 * be called and WaitForFrame() to not return. This can be used to save
964 * processor resources when frames are not needed.
965 */
966 void SetEnabled(bool enabled);
967};
968
969/**
970 * An event generated by the library and provided to event listeners.
971 */
972class VideoEvent : public RawEvent {
973 public:
974 /**
975 * Get the source associated with the event (if any).
976 */
977 VideoSource GetSource() const;
978
979 /**
980 * Get the sink associated with the event (if any).
981 */
982 VideoSink GetSink() const;
983
984 /**
985 * Get the property associated with the event (if any).
986 */
988};
989
990/**
991 * An event listener. This calls back to a desigated callback function when
992 * an event matching the specified mask is generated by the library.
993 */
995 public:
996 VideoListener() = default;
997
998 /**
999 * Create an event listener.
1000 *
1001 * @param callback Callback function
1002 * @param eventMask Bitmask of VideoEvent::Kind values
1003 * @param immediateNotify Whether callback should be immediately called with
1004 * a representative set of events for the current library state.
1005 */
1006 VideoListener(std::function<void(const VideoEvent& event)> callback,
1007 int eventMask, bool immediateNotify);
1008
1011 VideoListener(VideoListener&& other) noexcept;
1012 VideoListener& operator=(VideoListener&& other) noexcept;
1014
1015 friend void swap(VideoListener& first, VideoListener& second) noexcept {
1016 using std::swap;
1017 swap(first.m_handle, second.m_handle);
1018 }
1019
1020 private:
1021 CS_Listener m_handle{0};
1022};
1023
1024/** @} */
1025
1026} // namespace cs
1027
1028#include "cscore_oo.inc"
1029
1030#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 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:111
A source that represents an Axis IP camera.
Definition: cscore_oo.h:559
AxisCamera(std::string_view name, std::string_view host)
Create a source for an Axis IP camera.
Definition: cscore_oo.inc:375
A source that represents a MJPEG-over-HTTP (IP) camera.
Definition: cscore_oo.h:471
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.inc:287
std::vector< std::string > GetUrls() const
Get the URLs used to connect to the camera.
Definition: cscore_oo.inc:349
void SetUrls(std::span< const std::string > urls)
Change the URLs used to connect to the camera.
Definition: cscore_oo.inc:333
HttpCameraKind
Definition: cscore_oo.h:473
@ kMJPGStreamer
Definition: cscore_oo.h:475
@ kCSCore
Definition: cscore_oo.h:476
@ kAxis
Definition: cscore_oo.h:477
@ kUnknown
Definition: cscore_oo.h:474
HttpCameraKind GetHttpCameraKind() const
Get the kind of HTTP camera.
Definition: cscore_oo.inc:327
A base class for single image reading sinks.
Definition: cscore_oo.h:941
void SetEnabled(bool enabled)
Enable or disable getting new frames.
Definition: cscore_oo.inc:596
std::string GetError() const
Get error string.
Definition: cscore_oo.inc:591
void SetDescription(std::string_view description)
Set sink description.
Definition: cscore_oo.inc:586
ImageSink()=default
A base class for single image providing sources.
Definition: cscore_oo.h:611
VideoProperty CreateBooleanProperty(std::string_view name, bool defaultValue, bool value)
Create a boolean property.
Definition: cscore_oo.inc:432
ImageSource()=default
void SetDescription(std::string_view description)
Set source description.
Definition: cscore_oo.inc:403
VideoProperty CreateIntegerProperty(std::string_view name, int minimum, int maximum, int step, int defaultValue, int value)
Create an integer property.
Definition: cscore_oo.inc:419
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.inc:408
void SetConnected(bool connected)
Set source connection status.
Definition: cscore_oo.inc:398
VideoProperty CreateStringProperty(std::string_view name, std::string_view value)
Create a string property.
Definition: cscore_oo.inc:443
void NotifyError(std::string_view msg)
Signal sinks that an error has occurred.
Definition: cscore_oo.inc:393
void SetEnumPropertyChoices(const VideoProperty &property, std::span< const std::string > choices)
Configure enum property choices.
Definition: cscore_oo.inc:455
A sink that acts as a MJPEG-over-HTTP network server.
Definition: cscore_oo.h:861
void SetFPS(int fps)
Set the stream frames per second (FPS) for clients that don't specify it.
Definition: cscore_oo.inc:569
void SetResolution(int width, int height)
Set the stream resolution for clients that don't specify it.
Definition: cscore_oo.inc:562
MjpegServer()=default
std::string GetListenAddress() const
Get the listen address of the server.
Definition: cscore_oo.inc:552
MjpegServer(std::string_view name, int port)
Create a MJPEG-over-HTTP server sink.
Definition: cscore_oo.h:880
void SetDefaultCompression(int quality)
Set the default compression used for non-MJPEG sources.
Definition: cscore_oo.inc:580
void SetCompression(int quality)
Set the compression for clients that don't specify it.
Definition: cscore_oo.inc:574
int GetPort() const
Get the port number of the server.
Definition: cscore_oo.inc:557
A source that represents a USB camera.
Definition: cscore_oo.h:418
UsbCameraInfo GetInfo() const
Get the full camera information for the device.
Definition: cscore_oo.inc:276
static std::vector< UsbCameraInfo > EnumerateUsbCameras()
Enumerate USB cameras on the local system.
Definition: cscore_oo.inc:261
std::string GetPath() const
Get the path to the device.
Definition: cscore_oo.inc:271
void SetConnectVerbose(int level)
Set how verbose the camera connection messages are.
Definition: cscore_oo.inc:281
void SetPath(std::string_view path)
Change the path to the device.
Definition: cscore_oo.inc:266
UsbCamera()=default
A source that represents a video camera.
Definition: cscore_oo.h:359
VideoCamera(CS_Source handle)
Definition: cscore_oo.h:412
void SetExposureAuto()
Set the exposure to auto aperature.
Definition: cscore_oo.inc:238
void SetWhiteBalanceManual(int value)
Set the white balance to manual, with specified color temperature.
Definition: cscore_oo.inc:233
void SetWhiteBalanceAuto()
Set the white balance to auto.
Definition: cscore_oo.inc:223
int GetBrightness()
Get the brightness, as a percentage (0-100).
Definition: cscore_oo.inc:218
void SetBrightness(int brightness)
Set the brightness, as a percentage (0-100).
Definition: cscore_oo.inc:213
void SetWhiteBalanceHoldCurrent()
Set the white balance to hold current.
Definition: cscore_oo.inc:228
VideoCamera()=default
void SetExposureManual(int value)
Set the exposure to manual, as a percentage (0-100).
Definition: cscore_oo.inc:248
WhiteBalance
Definition: cscore_oo.h:361
@ kFixedOutdoor1
Definition: cscore_oo.h:363
@ kFixedFlourescent2
Definition: cscore_oo.h:366
@ kFixedIndoor
Definition: cscore_oo.h:362
@ kFixedFluorescent1
Definition: cscore_oo.h:365
@ kFixedOutdoor2
Definition: cscore_oo.h:364
void SetExposureHoldCurrent()
Set the exposure to hold current.
Definition: cscore_oo.inc:243
An event generated by the library and provided to event listeners.
Definition: cscore_oo.h:972
VideoSink GetSink() const
Get the sink associated with the event (if any).
Definition: cscore_oo.inc:606
VideoProperty GetProperty() const
Get the property associated with the event (if any).
Definition: cscore_oo.inc:611
VideoSource GetSource() const
Get the source associated with the event (if any).
Definition: cscore_oo.inc:601
An event listener.
Definition: cscore_oo.h:994
friend void swap(VideoListener &first, VideoListener &second) noexcept
Definition: cscore_oo.h:1015
~VideoListener()
Definition: cscore_oo.inc:637
VideoListener & operator=(const VideoListener &)=delete
VideoListener()=default
VideoListener(const VideoListener &)=delete
A source or sink property.
Definition: cscore_oo.h:39
int GetMin() const
Definition: cscore_oo.inc:33
int Get() const
Definition: cscore_oo.inc:23
bool IsInteger() const
Definition: cscore_oo.h:64
VideoProperty()=default
void SetString(std::string_view value)
Definition: cscore_oo.inc:64
bool IsEnum() const
Definition: cscore_oo.h:66
std::string GetName() const
Definition: cscore_oo.inc:18
int GetDefault() const
Definition: cscore_oo.inc:48
Kind
Definition: cscore_oo.h:46
@ kString
Definition: cscore_oo.h:50
@ kInteger
Definition: cscore_oo.h:49
@ kEnum
Definition: cscore_oo.h:51
@ kBoolean
Definition: cscore_oo.h:48
@ kNone
Definition: cscore_oo.h:47
CS_Status GetLastStatus() const
Definition: cscore_oo.h:83
void Set(int value)
Definition: cscore_oo.inc:28
bool IsBoolean() const
Definition: cscore_oo.h:63
std::vector< std::string > GetChoices() const
Definition: cscore_oo.inc:69
int GetStep() const
Definition: cscore_oo.inc:43
Kind GetKind() const
Definition: cscore_oo.h:58
bool IsString() const
Definition: cscore_oo.h:65
std::string GetString() const
Definition: cscore_oo.inc:53
int GetMax() const
Definition: cscore_oo.inc:38
A sink for video that accepts a sequence of frames.
Definition: cscore_oo.h:713
void SetSource(VideoSource source)
Configure which source should provide frames to this sink.
Definition: cscore_oo.inc:512
Kind
Definition: cscore_oo.h:718
@ kCv
Definition: cscore_oo.h:721
@ kUnknown
Definition: cscore_oo.h:719
@ kMjpeg
Definition: cscore_oo.h:720
VideoProperty GetProperty(std::string_view name)
Get a property of the sink.
Definition: cscore_oo.inc:507
friend void swap(VideoSink &first, VideoSink &second) noexcept
Definition: cscore_oo.h:845
std::string GetDescription() const
Get the sink description.
Definition: cscore_oo.inc:502
std::vector< VideoProperty > EnumerateProperties() const
Enumerate all properties of this sink.
Kind GetKind() const
Get the kind of the sink.
Definition: cscore_oo.inc:492
VideoProperty GetSourceProperty(std::string_view name)
Get a property of the associated source.
Definition: cscore_oo.inc:527
bool SetConfigJson(std::string_view config)
Set properties from a JSON configuration string.
Definition: cscore_oo.inc:532
int GetHandle() const
Definition: cscore_oo.h:732
VideoSource GetSource() const
Get the connected source.
Definition: cscore_oo.inc:521
CS_Status m_status
Definition: cscore_oo.h:854
VideoSink() noexcept=default
std::string GetConfigJson() const
Get a JSON configuration string.
Definition: cscore_oo.inc:542
bool operator==(const VideoSink &other) const
Definition: cscore_oo.h:734
CS_Sink m_handle
Definition: cscore_oo.h:855
VideoSink(CS_Sink handle)
Definition: cscore_oo.h:852
static std::vector< VideoSink > EnumerateSinks()
Enumerate all existing sinks.
std::string GetName() const
Get the name of the sink.
Definition: cscore_oo.inc:497
CS_Status GetLastStatus() const
Definition: cscore_oo.h:836
wpi::json GetConfigJsonObject() const
Get a JSON configuration object.
A source for video that provides a sequence of frames.
Definition: cscore_oo.h:97
std::vector< VideoSink > EnumerateSinks()
Enumerate all sinks connected to this source.
bool SetPixelFormat(VideoMode::PixelFormat pixelFormat)
Set the pixel format.
Definition: cscore_oo.inc:166
double GetActualDataRate() const
Get the data rate (in bytes per second).
Definition: cscore_oo.inc:202
CS_Source m_handle
Definition: cscore_oo.h:353
VideoSource() noexcept=default
VideoProperty GetProperty(std::string_view name)
Get a property.
Definition: cscore_oo.inc:144
VideoMode GetVideoMode() const
Get the current video mode.
Definition: cscore_oo.inc:149
CS_Status m_status
Definition: cscore_oo.h:352
int GetHandle() const
Definition: cscore_oo.h:138
friend void swap(VideoSource &first, VideoSource &second) noexcept
Definition: cscore_oo.h:343
VideoSource(CS_Source handle)
Definition: cscore_oo.h:350
std::vector< VideoProperty > EnumerateProperties() const
Enumerate all properties of this source.
bool IsConnected() const
Is the source currently connected to whatever is providing the images?
Definition: cscore_oo.inc:134
std::string GetDescription() const
Get the source description.
Definition: cscore_oo.inc:117
wpi::json GetConfigJsonObject() const
Get a JSON configuration object.
bool IsEnabled() const
Gets source enable status.
Definition: cscore_oo.inc:139
ConnectionStrategy
Connection strategy.
Definition: cscore_oo.h:110
@ kConnectionKeepOpen
Try to keep the connection open regardless of whether any sinks are connected.
Definition: cscore_oo.h:121
@ kConnectionAutoManage
Automatically connect or disconnect based on whether any sinks are connected to this source.
Definition: cscore_oo.h:115
@ kConnectionForceClose
Never open the connection.
Definition: cscore_oo.h:127
std::vector< VideoMode > EnumerateVideoModes() const
Enumerate all known video modes for this source.
Definition: cscore_oo.inc:208
uint64_t GetLastFrameTime() const
Get the last time a frame was captured.
Definition: cscore_oo.inc:122
double GetActualFPS() const
Get the actual FPS.
Definition: cscore_oo.inc:196
bool operator==(const VideoSource &other) const
Definition: cscore_oo.h:140
Kind
Definition: cscore_oo.h:102
@ kCv
Definition: cscore_oo.h:106
@ kHttp
Definition: cscore_oo.h:105
@ kUnknown
Definition: cscore_oo.h:103
@ kUsb
Definition: cscore_oo.h:104
bool SetConfigJson(std::string_view config)
Set video mode and properties from a JSON configuration string.
Definition: cscore_oo.inc:181
bool SetFPS(int fps)
Set the frames per second (FPS).
Definition: cscore_oo.inc:176
static std::vector< VideoSource > EnumerateSources()
Enumerate all existing sources.
void SetConnectionStrategy(ConnectionStrategy strategy)
Sets the connection strategy.
Definition: cscore_oo.inc:127
CS_Status GetLastStatus() const
Definition: cscore_oo.h:327
Kind GetKind() const
Get the kind of the source.
Definition: cscore_oo.inc:107
std::string GetConfigJson() const
Get a JSON configuration string.
Definition: cscore_oo.inc:191
bool SetResolution(int width, int height)
Set the resolution.
Definition: cscore_oo.inc:171
bool SetVideoMode(const VideoMode &mode)
Set the video mode.
Definition: cscore_oo.inc:154
std::string GetName() const
Get the name of the source.
Definition: cscore_oo.inc:112
basic_string_view< char > string_view
Definition: core.h:501
@ CS_CONNECTION_AUTO_MANAGE
Automatically connect or disconnect based on whether any sinks are connected to this source.
Definition: cscore_c.h:181
@ CS_CONNECTION_KEEP_OPEN
Try to keep the connection open regardless of whether any sinks are connected.
Definition: cscore_c.h:187
@ CS_CONNECTION_FORCE_CLOSE
Never open the connection.
Definition: cscore_c.h:193
@ CS_HTTP_MJPGSTREAMER
Definition: cscore_c.h:126
@ CS_HTTP_CSCORE
Definition: cscore_c.h:127
@ CS_HTTP_UNKNOWN
Definition: cscore_c.h:125
@ CS_HTTP_AXIS
Definition: cscore_c.h:128
@ CS_PROP_ENUM
Definition: cscore_c.h:107
@ CS_PROP_NONE
Definition: cscore_c.h:103
@ CS_PROP_INTEGER
Definition: cscore_c.h:105
@ CS_PROP_BOOLEAN
Definition: cscore_c.h:104
@ CS_PROP_STRING
Definition: cscore_c.h:106
@ CS_SINK_MJPEG
Definition: cscore_c.h:136
@ CS_SINK_CV
Definition: cscore_c.h:137
@ CS_SINK_UNKNOWN
Definition: cscore_c.h:135
@ CS_SOURCE_USB
Definition: cscore_c.h:115
@ CS_SOURCE_HTTP
Definition: cscore_c.h:116
@ CS_SOURCE_UNKNOWN
Definition: cscore_c.h:114
@ CS_SOURCE_CV
Definition: cscore_c.h:117
CS_Handle CS_Source
Definition: cscore_c.h:53
int CS_Status
Definition: cscore_c.h:46
CS_Handle CS_Property
Definition: cscore_c.h:49
CS_Handle CS_Sink
Definition: cscore_c.h:52
CS_Handle CS_Listener
Definition: cscore_c.h:50
CameraServer (cscore) namespace.
Definition: cscore_oo.inc:16
const T & first(const T &value, const Tail &...)
Definition: compile.h:60
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) is_nothrow_move_constructible< wpi::WPI_BASIC_JSON_TPL >::value &&//NOLINT(misc-redundant-expression) is_nothrow_move_assignable< wpi::WPI_BASIC_JSON_TPL >::value)
exchanges the values of two JSON objects
Definition: json.h:5219
fps
Definition: velocity.h:46
constexpr const char * name(const T &)
Listener event.
Definition: cscore_cpp.h:101
USB camera information.
Definition: cscore_cpp.h:44
Video mode.
Definition: cscore_cpp.h:62
PixelFormat
Definition: cscore_cpp.h:63