Ocean
Loading...
Searching...
No Matches
ALiveVideo.h
Go to the documentation of this file.
1/*
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 */
7
8#ifndef META_OCEAN_MEDIA_ANDROID_A_LIVE_VIDEO_H
9#define META_OCEAN_MEDIA_ANDROID_A_LIVE_VIDEO_H
10
15
17#include "ocean/base/Value.h"
18
20
22
23#include <jni.h>
24
25namespace Ocean
26{
27
28namespace Media
29{
30
31namespace Android
32{
33
34#ifdef OCEAN_MEDIA_ANDROID_NATIVECAMERALIBRARY_AVAILABLE
35
36/**
37 * This class implements an live video class for Android.
38 * @ingroup mediaandroid
39 */
40class OCEAN_MEDIA_A_EXPORT ALiveVideo final :
41 virtual public AMedium,
42 virtual public LiveVideo
43{
44 friend class ALibrary;
45 friend class ALiveVideoManager;
46
47 public:
48
49 /**
50 * This class holds the relevant information of a selectable live video device.
51 */
52 class Device
53 {
54 friend class ALiveVideo;
55
56 public:
57
58 /// Definition of an unordered map mapping metadata tags to their values.
59 using MetadataMap = std::unordered_map<uint32_t, Value>;
60
61 public:
62
63 /**
64 * Default constructor.
65 */
66 Device() = default;
67
68 /**
69 * Returns the device's id.
70 * @return The id of the device
71 */
72 inline const std::string& id() const;
73
74 /**
75 * Returns the device's name.
76 * @return The name of the device
77 */
78 inline const std::string& name() const;
79
80 /**
81 * Returns the device's direction.
82 * @return The direction of the device
83 */
84 inline acamera_metadata_enum_android_lens_facing_t lensFacing() const;
85
86 /**
87 * Returns the optional metadata map of the device.
88 * @return The optional metadata map of the device
89 */
90 inline const MetadataMap& metadataMap() const;
91
92 /**
93 * Returns whether this object is valid.
94 * @return True, if so
95 */
96 inline bool isValid() const;
97
98 /**
99 * Returns the readable string for a lens facing type.
100 * @param lensFacing The lens facing type to return the readable string for
101 * @return The readable string for the given lens facing type
102 */
103 static std::string readableLensFacing(const acamera_metadata_enum_android_lens_facing_t lensFacing);
104
105 protected:
106
107 /**
108 * Creates a new device object.
109 * @param id The id of the device, must be valid
110 * @param name The human redable name of the device, must be valid
111 * @param lensFacing The direction of the device
112 * @param metadataMap The optional metadata map of the device
113 */
114 inline Device(const std::string& id, const std::string& name_, const acamera_metadata_enum_android_lens_facing_t lensFacing, MetadataMap&& metadataMap = MetadataMap());
115
116 protected:
117
118 /// The device's id.
119 std::string id_;
120
121 /// The device's human readable name.
122 std::string name_;
123
124 /// The device's direction.
125 acamera_metadata_enum_android_lens_facing_t lensFacing_ = acamera_metadata_enum_acamera_lens_facing(-1);
126
127 /// The optional metadata map of the device.
129 };
130
131 using Devices = std::vector<Device>;
132
133 private:
134
135 /**
136 * Definition of Android image formats that are missing from the NDK
137 * These values are used but they are missing from the NDK header, media/NdkImage.h.
138 * @see https://developer.android.com/reference/kotlin/android/graphics/ImageFormat
139 */
141 {
142 // Android YUV P010 format.
143 AIMAGE_FORMAT_YCBCR_P010 = 54,
144 };
145
146 public:
147
148 /**
149 * Returns whether the medium is started currently.
150 * @see Medium::isStarted().
151 */
152 bool isStarted() const override;
153
154 /**
155 * Returns the start timestamp.
156 * @see FiniteMedium::startTimestamp().
157 */
158 Timestamp startTimestamp() const override;
159
160 /**
161 * Returns the pause timestamp.
162 * @see FiniteMedium::pauseTimestamp().
163 */
164 Timestamp pauseTimestamp() const override;
165
166 /**
167 * Returns the stop timestamp.
168 * @see FiniteMedium::stopTimestamp().
169 */
170 Timestamp stopTimestamp() const override;
171
172 /**
173 * Returns the transformation between the camera and device.
174 * @see FrameMedium::device_T_camera().
175 */
177
178 /**
179 * Returns the supported stream types.
180 * @see LiveVideo::supportedStreamTypes().
181 */
183
184 /**
185 * Returns the supported stream configurations for a given stream type.
186 * @see LiveVideo::supportedStreamConfigurations().
187 */
188 StreamConfigurations supportedStreamConfigurations(const StreamType streamType = ST_INVALID) const override;
189
190 /**
191 * Returns the current exposure duration of this device.
192 * @see exposureDuration().
193 */
194 double exposureDuration(double* minDuration = nullptr, double* maxDuration = nullptr, ControlMode* exposureMode = nullptr) const override;
195
196 /**
197 * Returns the current ISO of this device.
198 * @see iso().
199 */
200 float iso(float* minISO = nullptr, float* maxISO = nullptr, ControlMode* isoMode = nullptr) const override;
201
202 /**
203 * Returns the current focus of this device.
204 * @see LiveVideo::focus().
205 */
206 float focus(ControlMode* focusMode = nullptr) const override;
207
208 /**
209 * Sets the preferred stream type.
210 * @see LiveVideo::setPreferredStreamConfiguration().
211 */
212 bool setPreferredStreamType(const StreamType streamType) override;
213
214 /**
215 * Sets the preferred stream configuration.
216 * @see LiveVideo::setPreferredStreamConfiguration().
217 */
218 bool setPreferredStreamConfiguration(const StreamConfiguration& streamConfiguration) override;
219
220 /**
221 * Sets the exposure duration of this device.
222 * Note: 'allowShorterExposure' is ignored
223 * @see setExposureDuration().
224 */
225 bool setExposureDuration(const double duration, const bool allowShorterExposure = false) override;
226
227 /**
228 * Sets the ISO of this device.
229 * @see setISO().
230 */
231 bool setISO(const float iso) override;
232
233 /**
234 * Sets the focus of this device.
235 * @see setFocus().
236 */
237 bool setFocus(const float position) override;
238
239 /**
240 * Returns whether video stabilization is currently enabled.
241 * @see videoStabilization().
242 */
243 bool videoStabilization() const override;
244
245 /**
246 * Sets whether video stabilization should be enabled.
247 * @see setVideoStabilization().
248 */
249 bool setVideoStabilization(const bool enable) override;
250
251 /**
252 * Explicitly feeds a new external frame this live video.
253 * This function is intended for situations in which this live video does not receive the frame anymore from the system (e.g., when ARCore is accessing the video stream).<br>
254 * Do not call this function in case the live video is still receiving pixel buffers from the Android media system.
255 * @param frame The frame to be fed, must be valid
256 * @param anyCamera The camera profile defining the projection, must be valid
257 * @param exposureMode The exposure mode of the camera, CM_INVALID if unknown
258 * @param exposureDuration The exposure duration of the camera, in seconds, -1 if unknown
259 * @param isoMode The ISO mode of the camera, CM_INVALID if unknown
260 * @param iso The ISO of the camera, -1 if unknown
261 * @param focusMode The focus mode of the camera, CM_INVALID if unknown
262 * @param focusValue The focus value of the camera, in the same domain as ACAMERA_LENS_INFO_MINIMUM_FOCUS_DISTANCE, -1 if unknown
263 */
264 void feedNewFrame(Frame&& frame, SharedAnyCamera&& anyCamera, const ControlMode exposureMode, const double exposureDuration, const ControlMode isoMode, const float iso, const ControlMode focusMode, const float focusValue);
265
266 /**
267 * Forces a restart of the live video for situations in which the camera was used by an external resource.
268 * This function is intended for situations in which e.g., ARCore has used the borrowed the camera resource but does not use it anymore.
269 * Do not call this function in case the live video is still receiving pixel buffers from the Android media system.
270 * @return True, if succeeded
271 */
273
274 /**
275 * Returns the list of currently selectable devices.
276 * @return The list of currently selectable devices
277 */
279
280 protected:
281
282 /**
283 * Creates a new medium by a given url.
284 * @param url Url of the medium
285 * @param id Optional unique id of the medium
286 */
287 explicit ALiveVideo(const std::string& url, const std::string& id);
288
289 /**
290 * Destructs the live video object.
291 */
292 ~ALiveVideo() override;
293
294 /**
295 * Starts the medium.
296 * @see Medium::start().
297 */
298 bool start() override;
299
300 /**
301 * Pauses the medium.
302 * @see Medium::pause():
303 */
304 bool pause() override;
305
306 /**
307 * Stops the medium.
308 * @see Medium::stop().
309 */
310 bool stop() override;
311
312 /**
313 * Initializes the camera and all corresponding resources.
314 * @return True, if succeeded
315 */
317
318 /**
319 * Releases the camera and all corresponding resources.
320 * @return True, if succeeded
321 */
322 bool release();
323
324 /**
325 * Creates an Android camera for the URL of this medium.
326 * @param frameType The resulting frame type matching with the Android camera
327 * @return True, if succeeded
328 */
329 bool createCamera(FrameType& frameType);
330
331 /**
332 * Releases the Android camera.
333 * @return True, if succeeded
334 */
336
337 /**
338 * Creates a new image reader based on a given frame type, needs a valid camera.
339 * @param frameType The frame type of the image reader, must be valid
340 * @return True, if succeeded
341 */
342 bool createImageReader(const FrameType& frameType);
343
344 /**
345 * Releases the image reader.
346 */
348
349 /**
350 * Creates a new capture session, needs a valid camera and image reader.
351 * @return True, if succeeded
352 */
354
355 /**
356 * Sets or update a repeating capture request.
357 */
359
360 /**
361 * Releases the capture session.
362 */
364
365 /**
366 * The callback function for camera images.
367 * @param imageReader The image reader of the event, must be valid
368 * @see onCameraImageCallbackStatic().
369 */
370 void onCameraImageCallback(AImageReader* imageReader);
371
372 /**
373 * The callback function for a disconnected camera.
374 * @param cameraDevice The camera device of the event, must be valid
375 * @see onCameraDisconnectedStatic().
376 */
377 void onCameraDisconnected(ACameraDevice* cameraDevice);
378
379 /**
380 * The callback function for errors.
381 * @param cameraDevice The camera device of the event, must be valid
382 * @param error The error value of the event
383 * @see onCameraErrorStatic().
384 */
385 void onCameraError(ACameraDevice* cameraDevice, int error);
386
387 /**
388 * The callback function for an active session.
389 * @param session The session, must be valid
390 */
391 void onSessionActive(ACameraCaptureSession* session);
392
393 /**
394 * The callback function for a closed session.
395 * @param session The session, must be valid
396 */
397 void onSessionClosed(ACameraCaptureSession* session);
398
399 /**
400 * The callback function for a started capture.
401 * @param session The session, must be valid
402 * @param request The capture request, must be valid
403 * @param timestamp The capture results, must be valid
404 */
405 void onCaptureStarted(ACameraCaptureSession* session, const ACaptureRequest* request, int64_t timestamp);
406
407 /**
408 * The callback function for a completed capture.
409 * @param session The session, must be valid
410 * @param request The capture request, must be valid
411 * @param result The capture results, must be valid
412 */
413 void onCaptureCompleted(ACameraCaptureSession* session, ACaptureRequest* request, const ACameraMetadata* result);
414
415 /**
416 * Event function for new camera frames.
417 * @param frame The new camera frame, must be valid
418 * @param anyCamera The camera profile defining the projection, invalid if unknown
419 * @return True, if succeeded
420 */
421 bool onNewFrame(Frame&& frame, SharedAnyCamera&& anyCamera);
422
423 /**
424 * Determines the camera id and associated frame type for a given URL.
425 * @param cameraManager The camera manager from which the camera id will be determined, must be valid
426 * @param url The URL for which the camera id will be determined
427 * @param id Optional known id of the camera, if provided the camera id will be verified again
428 * @param preferredFrameType The preferred frame type (may contain a valid image dimension, or just a pixel format), can be invalid
429 * @param frameType The resulting frame type matching with the resulting id
430 * @param streamConfigurations Optional resulting stream configurations
431 * @param device_T_camera Optional resulting transformation between camera and device
432 * @return The resulting id of the camera
433 */
434 static std::string cameraIdForMedium(ACameraManager* cameraManager, const std::string& url, const std::string& id, const FrameType& preferredFrameType, FrameType& frameType, StreamConfigurations* streamConfigurations = nullptr, HomogenousMatrixD4* device_T_camera = nullptr);
435
436 /**
437 * Determines the camera id and associated frame type for a given URL or/and id.
438 * @param cameraIdList The camera id list from which the camera id will be determined, must be valid
439 * @param url The URL for which the camera id will be determined
440 * @param id Optional known id of the camera, if provided the camera id will be verified again
441 * @return The resulting id of the camera, empty if no camera could be found
442 */
443 static std::string cameraIdForMedium(ACameraIdList* cameraIdList, const std::string& url, const std::string& id);
444
445 /**
446 * Determines the range of the exposure duration of the camera sensor.
447 * @param cameraManager The camera manager, must be valid
448 * @param cameraId The id of the camera, must be valid
449 * @param minExposureDuration The minimal exposure duration, in seconds
450 * @param maxExposureDuration The maximal exposure duration, in seconds
451 * @return True, if succeeded
452 */
453 static bool cameraExposureDurationRange(ACameraManager* cameraManager, const std::string& cameraId, double& minExposureDuration, double& maxExposureDuration);
454
455 /**
456 * Determines the range of the ISO of the camera sensor.
457 * @param cameraManager The camera manager, must be valid
458 * @param cameraId The id of the camera, must be valid
459 * @param minISO The minimal ISO
460 * @param maxISO The maximal ISO
461 * @return True, if succeeded
462 */
463 static bool cameraISORange(ACameraManager* cameraManager, const std::string& cameraId, float& minISO, float& maxISO);
464
465 /**
466 * Determines the supported focus modes of the camera sensor.
467 * @param cameraManager The camera manager, must be valid
468 * @param cameraId The id of the camera, must be valid
469 * @param focusModes The resulting available focus modes
470 * @param minFocusPosition The minimal focus distance, which is the reciprocal of the focus distance in meters
471 * @return True, if succeeded
472 */
473 static bool cameraAvailableFocusModes(ACameraManager* cameraManager, const std::string& cameraId, ControlModes& focusModes, float& minFocusPosition);
474
475 /**
476 * Determines the physical size of the camera sensor.
477 * @param cameraManager The camera manager, must be valid
478 * @param cameraId The id of the camera, must be valid
479 * @param cameraSensorPhysicalSizeX Resulting horizontal physical size of the sensor
480 * @return True, if succeeded
481 */
482 static bool cameraSensorPysicalSize(ACameraManager* cameraManager, const std::string& cameraId, float& cameraSensorPhysicalSizeX);
483
484 /**
485 * Determines the horizontal field of view from the camera's metadata based on `ACAMERA_LENS_FOCAL_LENGTH`.
486 * @param cameraSensorPhysicalSizeX The horizontal physical size of camera sensor, as provided by `ACAMERA_SENSOR_INFO_PHYSICAL_SIZE`.
487 * @param cameraMetadata The camera's metadata for a recent frame, must be valid
488 * @param fovX The resulting horizontal field of view of the camera, in radian
489 * @return True, if succeeded
490 */
491 static bool horizontalFieldOfView(const float cameraSensorPhysicalSizeX, const ACameraMetadata* cameraMetadata, float& fovX);
492
493 /**
494 * Extracts the next frame from an Android image object.
495 * @param image The Android image object from which the next frame will be extracted
496 * @param frame The resulting frame containing the extracted image
497 * @param timestampNs The resulting timestamp of the frame, as provided by AImage_getTimestamp(), in nanoseconds
498 * @return True, if succeeded
499 */
500 static bool frameFromImage(AImage* image, Frame& frame, int64_t& timestampNs);
501
502 /**
503 * Returns the transformation between camera and device (device_T_camera).
504 * @param cameraMetadata The camera metadata from which the transformation will be determined, must be valid
505 * @return The camera transformation with default camera pointing towards the negative z-space with y-axis upwards; invalid if the transformation could not be determined
506 */
507 static HomogenousMatrixD4 determineCameraTransformation(ACameraMetadata* cameraMetadata);
508
509 /**
510 * Translates an Android pixel format to an Ocean pixel format.
511 * @param androidFormat The Android pixel format to translate
512 * @return The corresponding Ocean pixel format, FORMAT_UNDEFINED if no corresponding Ocean pixel format exists
513 */
514 static FrameType::PixelFormat androidFormatToPixelFormat(const int32_t androidFormat);
515
516 /**
517 * Translates Android formats to readable strings.
518 * @param androidFormat The Android pixel format to translate
519 * @return The corresponding readable string of the Android format
520 */
521 static std::string androidFormatToString(const int32_t androidFormat);
522
523 /**
524 * Translates an Ocean pixel format to an Android pixel format.
525 * @param pixelFormat The Ocean pixel format to translate
526 * @return The corresponding Android pixel format, 0 if no corresponding Android pixel format exists
527 */
528 static int32_t pixelFormatToAndroidFormat(const FrameType::PixelFormat pixelFormat);
529
530 /**
531 * Determines the available stream configurations for the camera metadata from a camera.
532 * @param cameraMetadata The camera metadata from which the stream configurations will be determined, must be valid
533 * @return The resulting stream configurations
534 */
535 static StreamConfigurations determineAvailableStreamConfigurations(const ACameraMetadata* cameraMetadata);
536
537 /**
538 * The static callback function for camera images.
539 * @param context The event's context, must be valid
540 * @param imageReader The image reader of the event, must be valid
541 * @see onCameraImageCallback().
542 */
543 static void onCameraImageCallbackStatic(void* context, AImageReader* imageReader);
544
545 /**
546 * The static callback function for a disconnected camera.
547 * @param context The event's context, must be valid
548 * @param cameraDevice The camera device of the event, must be valid
549 * @see onCameraDisconnected().
550 */
551 static void onCameraDisconnectedStatic(void* context, ACameraDevice* cameraDevice);
552
553 /**
554 * The static callback function for errors.
555 * @param context The event's context, must be valid
556 * @param cameraDevice The camera device of the event, must be valid
557 * @param error The error value of the event
558 * @see onCameraError().
559 */
560 static void onCameraErrorStatic(void* context, ACameraDevice* cameraDevice, int error);
561
562 /**
563 * The static callback function for an active session.
564 * @param context The event's context, must be valid
565 * @param session The session, must be valid
566 */
567 static void onSessionActiveStatic(void* context, ACameraCaptureSession* session);
568
569 /**
570 * The static callback function for a ready session.
571 * @param context The event's context, must be valid
572 * @param session The session, must be valid
573 */
574 static void onSessionReadyStatic(void* context, ACameraCaptureSession* session);
575
576 /**
577 * The static callback function for a closed session.
578 * @param context The event's context, must be valid
579 * @param session The session, must be valid
580 */
581 static void onSessionClosedStatic(void* context, ACameraCaptureSession* session);
582
583 /**
584 * The static callback function for a failed capture.
585 * @param context The event's context, must be valid
586 * @param session The session, must be valid
587 * @param request The capture request, must be valid
588 * @param failure The failure, must be valid
589 */
590 static void onCaptureFailedStatic(void* context, ACameraCaptureSession* session, ACaptureRequest* request, ACameraCaptureFailure* failure);
591
592 /**
593 * The static callback function for a completed capture sequence.
594 * @param context The event's context, must be valid
595 * @param session The session, must be valid
596 * @param sequenceId The sequence id
597 * @param frameNumber The number of frames
598 */
599 static void onCaptureSequenceCompletedStatic(void* context, ACameraCaptureSession* session, int sequenceId, int64_t frameNumber);
600
601 /**
602 * The static callback function for an aborted sequence.
603 * @param context The event's context, must be valid
604 * @param session The session, must be valid
605 * @param sequenceId The sequence id
606 */
607 static void onCaptureSequenceAbortedStatic(void* context, ACameraCaptureSession* session, int sequenceId);
608
609 /**
610 * The static callback function for a started capture.
611 * @param context The event's context, must be valid
612 * @param session The session, must be valid
613 * @param request The capture request, must be valid
614 * @param timestamp The capture timestamp
615 */
616 static void onCaptureStartedStatic(void *context, ACameraCaptureSession *session, const ACaptureRequest *request, int64_t timestamp);
617
618 /**
619 * The static callback function for a completed capture.
620 * @param context The event's context, must be valid
621 * @param session The session, must be valid
622 * @param request The capture request, must be valid
623 * @param result The capture results, must be valid
624 */
625 static void onCaptureCompletedStatic(void* context, ACameraCaptureSession* session, ACaptureRequest* request, const ACameraMetadata* result);
626
627 /**
628 * Translates a camera status to a readable strings.
629 * @param cameraStatus The camera status
630 * @return The readable camera status.
631 */
632 static std::string translateCameraStatus(const camera_status_t cameraStatus);
633
634 protected:
635
636 /// Unique camera id defined by Android, may be valid even if 'cameraDevice_' is not yet valid.
637 std::string cameraId_;
638
639 /// The camera device.
640 ACameraDevice* cameraDevice_ = nullptr;
641
642 /// The image reader.
643 AImageReader* imageReader_ = nullptr;
644
645 /// The native Android window associated with the video.
646 ANativeWindow* nativeWindow_ = nullptr;
647
648 /// The session output.
650
651 /// The session output container.
653
654 /// The capture session.
655 ACameraCaptureSession* captureSession_ = nullptr;
656
657 /// The capture request.
658 ACaptureRequest* captureRequest_ = nullptr;
659
660 /// The output target.
661 ACameraOutputTarget* outputTarget_ = nullptr;
662
663 /// The horizontal size of the physical camera sensor, if known; -1 if unknown.
664 float cameraSensorPhysicalSizeX_ = -1.0f;
665
666 /// The transformation between camera and device, with default camera pointing towards the negative z-space with y-axis up.
667 HomogenousMatrixD4 device_T_camera_ = HomogenousMatrixD4(false);
668
669 /// The timestamp converter to convert timestamps from the camera to unix timestamps.
670 Timestamp::TimestampConverter timestampConverter_ = Timestamp::TimestampConverter(Timestamp::TimestampConverter::TD_BOOTTIME);
671
672 /// The current exposure mode of this device.
673 ControlMode exposureMode_ = CM_INVALID;
674
675 /// The current exposure duration of this device.
676 double exposureDuration_ = -1.0;
677
678 /// Minimal duration to set, in seconds, with range (0, infinity), -1 if unknown.
679 double exposureDurationMin_ = -1.0;
680
681 /// Maximal duration to set, in seconds, with range [exposureDurationMin_, infinity), -1 if unknown
682 double exposureDurationMax_ = -1.0;
683
684 /// The current ISO mode of this device.
685 ControlMode isoMode_ = CM_INVALID;
686
687 /// The current ISO, with range [isoMin_, isoMax_], 0 for auto IOS, -1 if unknown.
688 float iso_ = -1.0f;
689
690 /// Minimal ISO to set, with range (0, infinity), -1 if unknown.
691 float isoMin_ = -1.0f;
692
693 /// Maximal ISO to set, with range (isoMin_, infinity), -1 if unknown.
694 float isoMax_ = -1.0f;
695
696 /// The current focus mode of this device.
697 ControlMode focusMode_ = CM_INVALID;
698
699 /// The focus position to be set, with range [0, 1] with 0 shortest distance and 1 furthest distance, -1 if unknown.
700 float focusPosition_ = -1.0f;
701
702 /// The minimal focus distance (reciprocal of the focus distance in meters), -1 if unknown.
703 float focusPositionMin_ = -1.0f;
704
705 /// Whether video stabilization is enabled (true) or disabled (false).
706 bool videoStabilizationEnabled_ = false;
707
708 /// The stream configurations available for this camera.
710
711 /// Start timestamp.
713
714 /// Pause timestamp.
716
717 /// Stop timestamp.
719
720 /// True, if the capture session is currently closing (a release has been invoked but not yet finished).
721 std::atomic<bool> sessionCurrentlyClosing_ = false;
722};
723
724inline ALiveVideo::Device::Device(const std::string& id, const std::string& name, const acamera_metadata_enum_android_lens_facing_t lensFacing, MetadataMap&& metadataMap) :
725 id_(id),
726 name_(name),
727 lensFacing_(lensFacing),
728 metadataMap_(std::move(metadataMap))
729{
730 ocean_assert(!id_.empty());
731 ocean_assert(!name_.empty());
732}
733
734inline const std::string& ALiveVideo::Device::id() const
735{
736 return id_;
737}
738
739inline const std::string& ALiveVideo::Device::name() const
740{
741 return name_;
742}
743
744inline acamera_metadata_enum_android_lens_facing_t ALiveVideo::Device::lensFacing() const
745{
746 return lensFacing_;
747}
748
750{
751 return metadataMap_;
752}
753
755{
756 return !id_.empty();
757}
758
759#endif // OCEAN_MEDIA_ANDROID_NATIVECAMERALIBRARY_AVAILABLE
760
761}
762
763}
764
765}
766
767#endif // META_OCEAN_MEDIA_ANDROID_A_LIVE_VIDEO_H
This class implements Ocean's image class.
Definition Frame.h:1808
Definition of a frame type composed by the frame dimension, pixel format and pixel origin.
Definition Frame.h:30
PixelFormat
Definition of all pixel formats available in the Ocean framework.
Definition Frame.h:183
This class implements the android library.
Definition ALibrary.h:37
This class holds the relevant information of a selectable live video device.
Definition ALiveVideo.h:53
const MetadataMap & metadataMap() const
Returns the optional metadata map of the device.
Definition ALiveVideo.h:749
MetadataMap metadataMap_
The optional metadata map of the device.
Definition ALiveVideo.h:128
std::unordered_map< uint32_t, Value > MetadataMap
Definition of an unordered map mapping metadata tags to their values.
Definition ALiveVideo.h:59
static std::string readableLensFacing(const acamera_metadata_enum_android_lens_facing_t lensFacing)
Returns the readable string for a lens facing type.
Device()=default
Default constructor.
const std::string & id() const
Returns the device's id.
Definition ALiveVideo.h:734
bool isValid() const
Returns whether this object is valid.
Definition ALiveVideo.h:754
const std::string & name() const
Returns the device's name.
Definition ALiveVideo.h:739
acamera_metadata_enum_android_lens_facing_t lensFacing() const
Returns the device's direction.
Definition ALiveVideo.h:744
std::string id_
The device's id.
Definition ALiveVideo.h:119
std::string name_
The device's human readable name.
Definition ALiveVideo.h:122
This class implements an live video class for Android.
Definition ALiveVideo.h:43
bool setRepeatingRequest()
Sets or update a repeating capture request.
StreamConfigurations availableStreamConfigurations_
The stream configurations available for this camera.
Definition ALiveVideo.h:709
bool onNewFrame(Frame &&frame, SharedAnyCamera &&anyCamera)
Event function for new camera frames.
static std::string cameraIdForMedium(ACameraIdList *cameraIdList, const std::string &url, const std::string &id)
Determines the camera id and associated frame type for a given URL or/and id.
static HomogenousMatrixD4 determineCameraTransformation(ACameraMetadata *cameraMetadata)
Returns the transformation between camera and device (device_T_camera).
bool setVideoStabilization(const bool enable) override
Sets whether video stabilization should be enabled.
bool start() override
Starts the medium.
float focus(ControlMode *focusMode=nullptr) const override
Returns the current focus of this device.
StreamTypes supportedStreamTypes() const override
Returns the supported stream types.
static bool cameraISORange(ACameraManager *cameraManager, const std::string &cameraId, float &minISO, float &maxISO)
Determines the range of the ISO of the camera sensor.
static void onCameraImageCallbackStatic(void *context, AImageReader *imageReader)
The static callback function for camera images.
bool stop() override
Stops the medium.
static bool cameraSensorPysicalSize(ACameraManager *cameraManager, const std::string &cameraId, float &cameraSensorPhysicalSizeX)
Determines the physical size of the camera sensor.
bool releaseCamera()
Releases the Android camera.
static bool cameraAvailableFocusModes(ACameraManager *cameraManager, const std::string &cameraId, ControlModes &focusModes, float &minFocusPosition)
Determines the supported focus modes of the camera sensor.
void onCameraError(ACameraDevice *cameraDevice, int error)
The callback function for errors.
void onCaptureStarted(ACameraCaptureSession *session, const ACaptureRequest *request, int64_t timestamp)
The callback function for a started capture.
bool setFocus(const float position) override
Sets the focus of this device.
static void onSessionClosedStatic(void *context, ACameraCaptureSession *session)
The static callback function for a closed session.
void releaseCaptureSession()
Releases the capture session.
static void onCaptureStartedStatic(void *context, ACameraCaptureSession *session, const ACaptureRequest *request, int64_t timestamp)
The static callback function for a started capture.
bool createCaptureSession()
Creates a new capture session, needs a valid camera and image reader.
HomogenousMatrixD4 device_T_camera() const override
Returns the transformation between the camera and device.
static StreamConfigurations determineAvailableStreamConfigurations(const ACameraMetadata *cameraMetadata)
Determines the available stream configurations for the camera metadata from a camera.
AIMAGE_FORMATS_MISSING_FROM_NDK
Definition of Android image formats that are missing from the NDK These values are used but they are ...
Definition ALiveVideo.h:141
void releaseImageReader()
Releases the image reader.
void onCameraDisconnected(ACameraDevice *cameraDevice)
The callback function for a disconnected camera.
Timestamp pauseTimestamp() const override
Returns the pause timestamp.
bool setExposureDuration(const double duration, const bool allowShorterExposure=false) override
Sets the exposure duration of this device.
bool release()
Releases the camera and all corresponding resources.
static Devices selectableDevices()
Returns the list of currently selectable devices.
bool forceRestart()
Forces a restart of the live video for situations in which the camera was used by an external resourc...
static void onCaptureSequenceAbortedStatic(void *context, ACameraCaptureSession *session, int sequenceId)
The static callback function for an aborted sequence.
bool initialize()
Initializes the camera and all corresponding resources.
static FrameType::PixelFormat androidFormatToPixelFormat(const int32_t androidFormat)
Translates an Android pixel format to an Ocean pixel format.
ALiveVideo(const std::string &url, const std::string &id)
Creates a new medium by a given url.
static void onCaptureCompletedStatic(void *context, ACameraCaptureSession *session, ACaptureRequest *request, const ACameraMetadata *result)
The static callback function for a completed capture.
bool setPreferredStreamType(const StreamType streamType) override
Sets the preferred stream type.
Timestamp startTimestamp() const override
Returns the start timestamp.
static void onCameraErrorStatic(void *context, ACameraDevice *cameraDevice, int error)
The static callback function for errors.
bool setPreferredStreamConfiguration(const StreamConfiguration &streamConfiguration) override
Sets the preferred stream configuration.
static bool horizontalFieldOfView(const float cameraSensorPhysicalSizeX, const ACameraMetadata *cameraMetadata, float &fovX)
Determines the horizontal field of view from the camera's metadata based on ACAMERA_LENS_FOCAL_LENGTH...
static std::string translateCameraStatus(const camera_status_t cameraStatus)
Translates a camera status to a readable strings.
void onCameraImageCallback(AImageReader *imageReader)
The callback function for camera images.
Timestamp stopTimestamp_
Stop timestamp.
Definition ALiveVideo.h:718
NativeCameraLibrary::ScopedACaptureSessionOutput sessionOutput_
The session output.
Definition ALiveVideo.h:649
Timestamp stopTimestamp() const override
Returns the stop timestamp.
bool createCamera(FrameType &frameType)
Creates an Android camera for the URL of this medium.
static void onCaptureSequenceCompletedStatic(void *context, ACameraCaptureSession *session, int sequenceId, int64_t frameNumber)
The static callback function for a completed capture sequence.
static bool cameraExposureDurationRange(ACameraManager *cameraManager, const std::string &cameraId, double &minExposureDuration, double &maxExposureDuration)
Determines the range of the exposure duration of the camera sensor.
static void onSessionActiveStatic(void *context, ACameraCaptureSession *session)
The static callback function for an active session.
bool setISO(const float iso) override
Sets the ISO of this device.
static void onSessionReadyStatic(void *context, ACameraCaptureSession *session)
The static callback function for a ready session.
bool videoStabilization() const override
Returns whether video stabilization is currently enabled.
bool pause() override
Pauses the medium.
StreamConfigurations supportedStreamConfigurations(const StreamType streamType=ST_INVALID) const override
Returns the supported stream configurations for a given stream type.
static std::string cameraIdForMedium(ACameraManager *cameraManager, const std::string &url, const std::string &id, const FrameType &preferredFrameType, FrameType &frameType, StreamConfigurations *streamConfigurations=nullptr, HomogenousMatrixD4 *device_T_camera=nullptr)
Determines the camera id and associated frame type for a given URL.
NativeCameraLibrary::ScopedACaptureSessionOutputContainer sessionOutputContainer_
The session output container.
Definition ALiveVideo.h:652
void feedNewFrame(Frame &&frame, SharedAnyCamera &&anyCamera, const ControlMode exposureMode, const double exposureDuration, const ControlMode isoMode, const float iso, const ControlMode focusMode, const float focusValue)
Explicitly feeds a new external frame this live video.
bool isStarted() const override
Returns whether the medium is started currently.
void onSessionClosed(ACameraCaptureSession *session)
The callback function for a closed session.
bool createImageReader(const FrameType &frameType)
Creates a new image reader based on a given frame type, needs a valid camera.
static std::string androidFormatToString(const int32_t androidFormat)
Translates Android formats to readable strings.
float iso(float *minISO=nullptr, float *maxISO=nullptr, ControlMode *isoMode=nullptr) const override
Returns the current ISO of this device.
static bool frameFromImage(AImage *image, Frame &frame, int64_t &timestampNs)
Extracts the next frame from an Android image object.
void onSessionActive(ACameraCaptureSession *session)
The callback function for an active session.
std::string cameraId_
Unique camera id defined by Android, may be valid even if 'cameraDevice_' is not yet valid.
Definition ALiveVideo.h:637
static int32_t pixelFormatToAndroidFormat(const FrameType::PixelFormat pixelFormat)
Translates an Ocean pixel format to an Android pixel format.
~ALiveVideo() override
Destructs the live video object.
void onCaptureCompleted(ACameraCaptureSession *session, ACaptureRequest *request, const ACameraMetadata *result)
The callback function for a completed capture.
Timestamp startTimestamp_
Start timestamp.
Definition ALiveVideo.h:712
std::vector< Device > Devices
Definition ALiveVideo.h:131
Timestamp pauseTimestamp_
Pause timestamp.
Definition ALiveVideo.h:715
static void onCaptureFailedStatic(void *context, ACameraCaptureSession *session, ACaptureRequest *request, ACameraCaptureFailure *failure)
The static callback function for a failed capture.
double exposureDuration(double *minDuration=nullptr, double *maxDuration=nullptr, ControlMode *exposureMode=nullptr) const override
Returns the current exposure duration of this device.
static void onCameraDisconnectedStatic(void *context, ACameraDevice *cameraDevice)
The static callback function for a disconnected camera.
This class implements the base class for all Medium objects in the Android library.
Definition AMedium.h:35
Definition of a scoped object for ACaptureSessionOutputContainer objects.
Definition NativeCameraLibrary.h:95
Definition of a scoped object for ACaptureSessionOutput objects.
Definition NativeCameraLibrary.h:114
This class holds the relevant information describing a video stream configuration.
Definition LiveVideo.h:166
This class is the base class for all live videos.
Definition LiveVideo.h:38
StreamType
Definition of individual stream types.
Definition LiveVideo.h:64
ControlMode
Definition of individual control modes.
Definition LiveVideo.h:46
std::vector< ControlMode > ControlModes
Definition of a vector holding control modes.
Definition LiveVideo.h:58
std::vector< StreamConfiguration > StreamConfigurations
Definition of a vector holding stream configurations.
Definition LiveVideo.h:207
std::vector< StreamType > StreamTypes
Definition of a vector holding stream types.
Definition LiveVideo.h:78
This class is a helper class allowing to converter timestamps defined in a specific time domain to un...
Definition Timestamp.h:54
This class implements a timestamp.
Definition Timestamp.h:47
std::shared_ptr< AnyCamera > SharedAnyCamera
Definition of a shared pointer holding an AnyCamera object with Scalar precision.
Definition AnyCamera.h:60
The namespace covering the entire Ocean framework.
Definition Accessor.h:15