WPILibC++  unspecified
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Pages
CameraServer.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) FIRST 2014-2016. All Rights Reserved. */
3 /* Open Source Software - may be modified and shared by FRC teams. The code */
4 /* must be accompanied by the FIRST BSD license file in the root directory of */
5 /* the project. */
6 /*----------------------------------------------------------------------------*/
7 
8 #pragma once
9 
10 #include "USBCamera.h"
11 #include "ErrorBase.h"
12 #include "nivision.h"
13 #include "NIIMAQdx.h"
14 
15 #include "HAL/cpp/priority_mutex.h"
16 #include <thread>
17 #include <memory>
18 #include <condition_variable>
19 #include <tuple>
20 #include <vector>
21 
22 class CameraServer : public ErrorBase {
23  private:
24  static constexpr uint16_t kPort = 1180;
25  static constexpr uint8_t kMagicNumber[] = {0x01, 0x00, 0x00, 0x00};
26  static constexpr uint32_t kSize640x480 = 0;
27  static constexpr uint32_t kSize320x240 = 1;
28  static constexpr uint32_t kSize160x120 = 2;
29  static constexpr int32_t kHardwareCompression = -1;
30  static constexpr uint32_t kMaxImageSize = 200000;
31 
32  protected:
33  CameraServer();
34 
35  std::shared_ptr<USBCamera> m_camera;
36  std::thread m_serverThread;
37  std::thread m_captureThread;
38  priority_recursive_mutex m_imageMutex;
39  std::condition_variable_any m_newImageVariable;
40  std::vector<uint8_t*> m_dataPool;
41  unsigned int m_quality;
42  bool m_autoCaptureStarted;
43  bool m_hwClient;
44  std::tuple<uint8_t*, unsigned int, unsigned int, bool> m_imageData;
45 
46  void Serve();
47  void AutoCapture();
48  void SetImageData(uint8_t* data, unsigned int size, unsigned int start = 0,
49  bool imaqData = false);
50  void FreeImageData(
51  std::tuple<uint8_t*, unsigned int, unsigned int, bool> imageData);
52 
53  struct Request {
54  uint32_t fps;
55  int32_t compression;
56  uint32_t size;
57  };
58 
59  public:
60  static CameraServer* GetInstance();
61  void SetImage(Image const* image);
62 
63  void StartAutomaticCapture(
64  char const* cameraName = USBCamera::kDefaultCameraName);
65 
75  void StartAutomaticCapture(std::shared_ptr<USBCamera> camera);
76 
77  bool IsAutoCaptureStarted();
78 
79  void SetQuality(unsigned int quality);
80  unsigned int GetQuality();
81 
82  void SetSize(unsigned int size);
83 };
Definition: CameraServer.h:53
Definition: CameraServer.h:22
Definition: priority_mutex.h:22
Base class for most objects.
Definition: ErrorBase.h:66