dji_liveview_impl.hpp
Go to the documentation of this file.
1 
29 #ifndef ONBOARDSDK_DJI_LIVEVIEW_IMPL_H
30 #define ONBOARDSDK_DJI_LIVEVIEW_IMPL_H
31 
32 #include "dji_type.hpp"
33 #include "dji_vehicle.hpp"
34 #include "dji_liveview.hpp"
35 #include "dji_linker.hpp"
36 
37 namespace DJI {
38 namespace OSDK {
39 
40 // Forward Declaration
41 class Vehicle;
42 
43 class LiveViewImpl {
44  public:
45  LiveViewImpl(Vehicle *vehiclePtr);
46 
47  ~LiveViewImpl();
48 
49  LiveView::LiveViewErrCode startH264Stream(LiveView::LiveViewCameraPosition pos, H264Callback cb, void *userData);
50 
51  LiveView::LiveViewErrCode stopH264Stream(LiveView::LiveViewCameraPosition pos);
52 
53  LiveView::LiveViewErrCode changeH264Source(LiveView::LiveViewCameraPosition pos, LiveView::LiveViewCameraSource source);
54 
55  typedef struct H264CallbackHandler {
56  H264Callback cb;
57  void *userData;
58  } H264CallbackHandler;
59 
60  private:
61 
62  typedef enum E_OSDKCameraType {
63  OSDK_CAMERA_TYPE_PSDK = 31,
64  OSDK_CAMERA_TYPE_FPV = 39, //Matrice FPV
65  OSDK_CAMERA_TYPE_H20_DOUBLE_CAM = 42,
66  OSDK_CAMERA_TYPE_H20_TIRPLE_CAM = 43, //IR
67  OSDK_CAMERA_TYPE_UNKNOWN = 0xFF
68  } E_OSDKCameraType;
69 
70  enum {
71  UUID_MAJOR_TYPE_CAMERA = 0,
72  UUID_MAJOR_TYPE_RADAR = 1,
73  UUID_MAJOR_TYPE_PSDK = 2,
74  UUID_MAJOR_TYPE_UNKNOWN = 255
75  };
76 
77  typedef struct {
78  // 2:OSDK
79  uint8_t role;
80  // 0:subscribe 1:unsubscribe
81  uint8_t action;
82  // always 0
83  uint8_t type;
84  } __attribute__((packed)) T_SubscribeData;
85 
86  typedef struct {
87  uint8_t role;
88  } __attribute__((packed)) T_HeartBeatData;
89 
90  typedef struct {
91  uint8_t role;
92  uint8_t chnNum;
93  } __attribute__((packed)) T_LiveViewHeader;
94 
95  typedef struct {
96  uint16_t cmdSize;
97  uint8_t mode;
98  uint8_t action;
99  uint8_t channelId;
100  uint8_t priority;
101  } __attribute__((packed)) T_LiveViewMiniChannelItem;
102 
103  typedef struct {
104  uint16_t cmdSize;
105  uint8_t mode;
106  uint8_t action;
107  uint8_t channelId;
108  uint8_t priority;
109  uint8_t fps;
110  uint16_t width;
111  uint16_t height;
112  uint8_t codecStrategy;
113  uint8_t codecFormat;
114  uint8_t adaptiveResolutionEnable;
115  uint8_t sourceNum;
116  uint8_t size;
117  } __attribute__((packed)) T_LiveViewChannelItem;
118 
119  typedef struct {
120  uint8_t version;
121  uint8_t major;
122  uint8_t minor;
123  uint8_t dataIdx : 3;
124  uint8_t devicePos : 3;
125  uint8_t reserved : 2;
126  } __attribute__((packed)) T_LiveViewUuid;
127 
128  typedef struct {
129  T_LiveViewUuid uuid;
130  uint8_t cropEnable;
131  float cropOffsetX;
132  float cropOffsetY;
133  float cropWidth;
134  float cropHeight;
135  } __attribute__((packed)) T_LiveViewSingleSourceItem;
136 
137  typedef struct {
138  T_LiveViewUuid uuid;
139  uint8_t cropEnable;
140  float cropOffsetX;
141  float cropOffsetY;
142  float cropWidth;
143  float cropHeight;
144  uint8_t order;
145  float blendingOffsetX;
146  float blendingOffsetY;
147  float blendingWidth;
148  float blendingHeight;
149  } __attribute__((packed)) T_LiveViewMultiSourceItem;
150 
151  typedef struct {
152  T_LiveViewHeader header;
153  T_LiveViewChannelItem channel;
154  T_LiveViewSingleSourceItem source;
155  } __attribute__((packed)) T_LiveViewSubscribeItem;
156 
157  typedef struct {
158  T_LiveViewHeader header;
159  T_LiveViewMiniChannelItem channel;
160  } __attribute__((packed)) T_LiveViewUnsubscribeItem;
161 
162  typedef struct CameraListType
163  {
164  E_OSDKCameraType cameraType[3];
165  bool isMounted[3];
166  } CameraListType;
167 
168  Vehicle *vehicle;
169 
170  private:
171  static std::map<LiveView::LiveViewCameraPosition, H264CallbackHandler> h264CbHandlerMap;
172  static T_RecvCmdItem bulkCmdList[];
173  static E_OsdkStat RecordStreamHandler(struct _CommandHandle *cmdHandle,
174  const T_CmdInfo *cmdInfo,
175  const uint8_t *cmdData,
176  void *userData);
177  static E_OsdkStat getCameraPushing(struct _CommandHandle *cmdHandle,
178  const T_CmdInfo *cmdInfo,
179  const uint8_t *cmdData, void *userData);
180 
181  CameraListType getCameraList();
182  int subscribeLiveViewData(E_OSDKCameraType type, LiveView::LiveViewCameraPosition pos);
183  int unsubscribeLiveViewData(LiveView::LiveViewCameraPosition pos);
184 
185  T_OsdkTaskHandle h264TaskHandle;
186  static void *heartBeatTask(void *p);
187  E_OsdkStat startHeartBeatTask();
188  E_OsdkStat stopHeartBeatTask();
189 
190 };
191 } // OSDK
192 } // DJI
193 
194 #endif //ONBOARDSDK_DJI_LIVEVIEW_IMPL_H
Camera liveview API of OSDK.
Data type and Data Structure definitions for use throughout DJI OSDK.
Definition: dji_ack.cpp:38
Vehicle API for DJI onboardSDK library.