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