3
3
import android .os .Bundle ;
4
4
import android .view .Surface ;
5
5
6
+ import com .MAVLink .enums .GOPRO_COMMAND ;
6
7
import com .o3dr .android .client .Drone ;
7
8
import com .o3dr .android .client .apis .CameraApi ;
8
9
import com .o3dr .android .client .apis .CapabilityApi ;
9
10
import com .o3dr .services .android .lib .drone .action .CameraActions ;
10
11
import com .o3dr .services .android .lib .drone .attribute .error .CommandExecutionError ;
11
12
import com .o3dr .services .android .lib .drone .companion .solo .tlv .SoloGoproConstants ;
12
13
import com .o3dr .services .android .lib .drone .companion .solo .tlv .SoloGoproRecord ;
14
+ import com .o3dr .services .android .lib .drone .companion .solo .tlv .SoloGoproSetExtendedRequest ;
13
15
import com .o3dr .services .android .lib .drone .companion .solo .tlv .SoloGoproSetRequest ;
14
16
import com .o3dr .services .android .lib .model .AbstractCommandListener ;
15
17
18
+ import java .text .SimpleDateFormat ;
19
+ import java .util .Date ;
20
+ import java .util .Locale ;
16
21
import java .util .concurrent .ConcurrentHashMap ;
17
22
18
23
/**
23
28
*/
24
29
public class SoloCameraApi extends SoloApi {
25
30
26
- private static final String TAG = SoloCameraApi . class . getSimpleName ( );
31
+ private static final SimpleDateFormat FILE_DATE_FORMAT = new SimpleDateFormat ( "yyyy_MM_dd_HH_mm_ss" , Locale . US );
27
32
28
33
private static final ConcurrentHashMap <Drone , SoloCameraApi > soloCameraApiCache = new ConcurrentHashMap <>();
29
34
private static final Builder <SoloCameraApi > apiBuilder = new Builder <SoloCameraApi >() {
@@ -116,21 +121,6 @@ public void stopVideoRecording(final AbstractCommandListener listener) {
116
121
sendVideoRecordingCommand (SoloGoproConstants .STOP_RECORDING , listener );
117
122
}
118
123
119
- /**
120
- * Switches the camera capture mode.
121
- *
122
- * @param captureMode One of {@link SoloGoproConstants#CAPTURE_MODE_VIDEO},
123
- * {@link SoloGoproConstants#CAPTURE_MODE_PHOTO},
124
- * {@link SoloGoproConstants#CAPTURE_MODE_BURST},
125
- * {@link SoloGoproConstants#CAPTURE_MODE_TIME_LAPSE}
126
- * @param listener Register a callback to receive update of the command execution status.
127
- * @since 2.6.8
128
- */
129
- public void switchCameraCaptureMode (@ SoloGoproConstants .CaptureMode byte captureMode , final AbstractCommandListener listener ) {
130
- final SoloGoproSetRequest captureModeRequest = new SoloGoproSetRequest (SoloGoproConstants .CAPTURE_MODE , captureMode );
131
- sendMessage (captureModeRequest , listener );
132
- }
133
-
134
124
private void sendVideoRecordingCommand (@ SoloGoproConstants .RecordCommand final int recordCommand , final AbstractCommandListener listener ) {
135
125
//Set the gopro to video mode
136
126
switchCameraCaptureMode (SoloGoproConstants .CAPTURE_MODE_VIDEO , new AbstractCommandListener () {
@@ -157,17 +147,22 @@ public void onTimeout() {
157
147
});
158
148
}
159
149
150
+ public void startVideoStream (final Surface surface , final String tag , final AbstractCommandListener listener ) {
151
+ startVideoStream (surface , tag , false , listener );
152
+ }
153
+
160
154
/**
161
155
* Attempt to grab ownership and start the video stream from the connected drone. Can fail if
162
156
* the video stream is already owned by another client.
163
157
*
164
158
* @param surface Surface object onto which the video is decoded.
165
159
* @param tag Video tag.
160
+ * @param enableLocalRecording Set to true to enable local recording, false to disable it.
166
161
* @param listener Register a callback to receive update of the command execution status.
167
162
*
168
163
* @since 2.5.0
169
164
*/
170
- public void startVideoStream (final Surface surface , final String tag , final AbstractCommandListener listener ) {
165
+ public void startVideoStream (final Surface surface , final String tag , final boolean enableLocalRecording , final AbstractCommandListener listener ) {
171
166
if (surface == null ) {
172
167
postErrorEvent (CommandExecutionError .COMMAND_FAILED , listener );
173
168
return ;
@@ -182,6 +177,13 @@ public void onFeatureSupportResult(String featureId, int result, Bundle resultIn
182
177
case CapabilityApi .FEATURE_SUPPORTED :
183
178
final Bundle videoProps = new Bundle ();
184
179
videoProps .putInt (CameraApi .VIDEO_PROPS_UDP_PORT , SOLO_STREAM_UDP_PORT );
180
+
181
+ videoProps .putBoolean (CameraApi .VIDEO_ENABLE_LOCAL_RECORDING , enableLocalRecording );
182
+ if (enableLocalRecording ){
183
+ String localRecordingFilename = "solo_stream_" + FILE_DATE_FORMAT .format (new Date ());
184
+ videoProps .putString (CameraApi .VIDEO_LOCAL_RECORDING_FILENAME , localRecordingFilename );
185
+ }
186
+
185
187
cameraApi .startVideoStream (surface , tag , videoProps , listener );
186
188
break ;
187
189
@@ -252,4 +254,77 @@ public void onFeatureSupportResult(String featureId, int result, Bundle resultIn
252
254
}
253
255
});
254
256
}
257
+
258
+ /**
259
+ * Switches the camera capture mode.
260
+ *
261
+ * @param captureMode One of {@link SoloGoproConstants#CAPTURE_MODE_VIDEO},
262
+ * {@link SoloGoproConstants#CAPTURE_MODE_PHOTO},
263
+ * {@link SoloGoproConstants#CAPTURE_MODE_BURST},
264
+ * {@link SoloGoproConstants#CAPTURE_MODE_TIME_LAPSE}
265
+ * @param listener Register a callback to receive update of the command execution status.
266
+ * @since 2.6.8
267
+ */
268
+ public void switchCameraCaptureMode (@ SoloGoproConstants .CaptureMode byte captureMode , final AbstractCommandListener listener ) {
269
+ final SoloGoproSetRequest captureModeRequest = new SoloGoproSetRequest ((short ) GOPRO_COMMAND .GOPRO_COMMAND_CAPTURE_MODE , captureMode );
270
+ sendMessage (captureModeRequest , listener );
271
+ }
272
+
273
+ private void sendExtendedRequest (AbstractCommandListener listener , int command , byte value1 , byte value2 , byte value3 , byte value4 ){
274
+ byte [] values = {value1 , value2 , value3 , value4 };
275
+ SoloGoproSetExtendedRequest extendedRequest = new SoloGoproSetExtendedRequest ((short ) command , values );
276
+ sendMessage (extendedRequest , listener );
277
+ }
278
+
279
+ private void sendExtendedRequest (AbstractCommandListener listener , int command , byte value ){
280
+ sendExtendedRequest (listener , command , value , (byte ) 0 , (byte ) 0 , (byte ) 0 );
281
+ }
282
+
283
+ /**
284
+ * Updates the camera video settings.
285
+ * @since 2.7.0
286
+ * @param resolution
287
+ * @param frameRate
288
+ * @param fieldOfView
289
+ * @param flags
290
+ */
291
+ public void updateVideoSettings (byte resolution , byte frameRate , byte fieldOfView , byte flags , AbstractCommandListener listener ){
292
+ sendExtendedRequest (listener , GOPRO_COMMAND .GOPRO_COMMAND_VIDEO_SETTINGS , resolution , frameRate , fieldOfView , flags );
293
+ }
294
+
295
+ public void setCameraPhotoResolution (byte photoResolution , AbstractCommandListener listener ){
296
+ sendExtendedRequest (listener , GOPRO_COMMAND .GOPRO_COMMAND_PHOTO_RESOLUTION , photoResolution );
297
+ }
298
+
299
+ public void enableCameraLowLight (boolean enable , AbstractCommandListener listener ){
300
+ sendExtendedRequest (listener , GOPRO_COMMAND .GOPRO_COMMAND_LOW_LIGHT , enable ? (byte ) 1 : (byte ) 0 );
301
+ }
302
+
303
+ public void setCameraPhotoBurstRate (byte burstRate , AbstractCommandListener listener ){
304
+ sendExtendedRequest (listener , GOPRO_COMMAND .GOPRO_COMMAND_PHOTO_BURST_RATE , burstRate );
305
+ }
306
+
307
+ public void enableCameraProtune (boolean enable , AbstractCommandListener listener ){
308
+ sendExtendedRequest (listener , GOPRO_COMMAND .GOPRO_COMMAND_PROTUNE , enable ? (byte )1 : (byte ) 0 );
309
+ }
310
+
311
+ public void setCameraProtuneWhiteBalance (byte whiteBalance , AbstractCommandListener listener ) {
312
+ sendExtendedRequest (listener , GOPRO_COMMAND .GOPRO_COMMAND_PROTUNE_WHITE_BALANCE , whiteBalance );
313
+ }
314
+
315
+ public void setCameraProtuneColour (byte colour , AbstractCommandListener listener ) {
316
+ sendExtendedRequest (listener , GOPRO_COMMAND .GOPRO_COMMAND_PROTUNE_COLOUR , colour );
317
+ }
318
+
319
+ public void setCameraProtuneGain (byte gain , AbstractCommandListener listener ) {
320
+ sendExtendedRequest (listener , GOPRO_COMMAND .GOPRO_COMMAND_PROTUNE_GAIN , gain );
321
+ }
322
+
323
+ public void setCameraProtuneSharpness (byte sharpness , AbstractCommandListener listener ) {
324
+ sendExtendedRequest (listener , GOPRO_COMMAND .GOPRO_COMMAND_PROTUNE_SHARPNESS , sharpness );
325
+ }
326
+
327
+ public void setCameraProtuneExposure (byte exposure , AbstractCommandListener listener ) {
328
+ sendExtendedRequest (listener , GOPRO_COMMAND .GOPRO_COMMAND_PROTUNE_EXPOSURE , exposure );
329
+ }
255
330
}
0 commit comments