8 #ifndef META_OCEAN_MEDIA_ANDROID_NATIVE_MEDIA_LIBRARY_H
9 #define META_OCEAN_MEDIA_ANDROID_NATIVE_MEDIA_LIBRARY_H
17 #if defined(__ANDROID_API__) && __ANDROID_API__ >= 21
19 #ifndef OCEAN_MEDIA_ANDROID_NATIVEMEDIALIBRARY_AVAILABLE
20 #define OCEAN_MEDIA_ANDROID_NATIVEMEDIALIBRARY_AVAILABLE
23 #if __ANDROID_API__ >= 24
24 #include <media/NdkImageReader.h>
27 #include <media/NdkMediaCodec.h>
28 #include <media/NdkMediaExtractor.h>
29 #include <media/NdkMediaFormat.h>
30 #include <media/NdkMediaMuxer.h>
97 static constexpr
const char* AMEDIAFORMAT_KEY_MIME =
"mime";
98 static constexpr
const char* AMEDIAFORMAT_KEY_COLOR_FORMAT =
"color-format";
99 static constexpr
const char* AMEDIAFORMAT_KEY_COLOR_RANGE =
"color-range";
100 static constexpr
const char* AMEDIAFORMAT_KEY_WIDTH =
"width";
101 static constexpr
const char* AMEDIAFORMAT_KEY_HEIGHT =
"height";
102 static constexpr
const char* AMEDIAFORMAT_KEY_STRIDE =
"stride";
103 static constexpr
const char* AMEDIAFORMAT_KEY_SLICE_HEIGHT =
"slice-height";
104 static constexpr
const char* AMEDIAFORMAT_KEY_DURATION =
"durationUs";
105 static constexpr
const char* AMEDIAFORMAT_KEY_BITS_PER_SAMPLE =
"bits-per-sample";
106 static constexpr
const char* AMEDIAFORMAT_KEY_BIT_RATE =
"bitrate";
107 static constexpr
const char* AMEDIAFORMAT_KEY_SAMPLE_RATE =
"sample-rate";
108 static constexpr
const char* AMEDIAFORMAT_KEY_CHANNEL_COUNT =
"channel-count";
109 static constexpr
const char* AMEDIAFORMAT_KEY_PCM_ENCODING =
"pcm-encoding";
110 static constexpr
const char* AMEDIAFORMAT_KEY_DISPLAY_HEIGHT =
"display-height";
111 static constexpr
const char* AMEDIAFORMAT_KEY_DISPLAY_CROP =
"crop";
112 static constexpr
const char* AMEDIAFORMAT_KEY_CAPTURE_RATE =
"capture-rate";
113 static constexpr
const char* AMEDIAFORMAT_KEY_FRAME_RATE =
"frame-rate";
114 static constexpr
const char* AMEDIAFORMAT_KEY_I_FRAME_INTERVAL =
"i-frame-interval";
118 #if __ANDROID_API__ >= 24
137 using Function_AImageReader_new = media_status_t (int32_t width, int32_t height, int32_t format, int32_t maxImages, AImageReader** reader);
155 using Function_AMediaCodec_configure = media_status_t (AMediaCodec* codec,
const AMediaFormat* format, ANativeWindow* surface, AMediaCrypto* crypto, uint32_t flags);
226 inline bool isInitialized()
const;
228 #if __ANDROID_API__ >= 24
233 inline void AImage_delete(AImage* image)
const;
234 inline media_status_t AImage_getWidth(
const AImage* image, int32_t* width)
const;
235 inline media_status_t AImage_getHeight(
const AImage* image, int32_t* height)
const;
236 inline media_status_t AImage_getFormat(
const AImage* image, int32_t* format)
const;
237 inline media_status_t AImage_getCropRect(
const AImage* image, AImageCropRect* rect)
const;
238 inline media_status_t AImage_getTimestamp(
const AImage* image, int64_t* timestampNs)
const;
239 inline media_status_t AImage_getNumberOfPlanes(
const AImage* image, int32_t* numPlanes)
const;
240 inline media_status_t AImage_getPlanePixelStride(
const AImage* image,
int planeIdx, int32_t* pixelStride)
const;
241 inline media_status_t AImage_getPlaneRowStride(
const AImage* image,
int planeIdx, int32_t* rowStride)
const;
242 inline media_status_t AImage_getPlaneData(
const AImage* image,
int planeIdx, uint8_t** data,
int* dataLength)
const;
247 inline media_status_t AImageReader_new(int32_t width, int32_t height, int32_t format, int32_t maxImages, AImageReader** reader)
const;
248 inline void AImageReader_delete(AImageReader* reader)
const;
249 inline media_status_t AImageReader_getWindow(AImageReader* reader, ANativeWindow** window)
const;
250 inline media_status_t AImageReader_getWidth(
const AImageReader* reader, int32_t* width)
const;
251 inline media_status_t AImageReader_getHeight(
const AImageReader* reader, int32_t* height)
const;
252 inline media_status_t AImageReader_getFormat(
const AImageReader* reader, int32_t* format)
const;
253 inline media_status_t AImageReader_getMaxImages(
const AImageReader* reader, int32_t* maxImages)
const;
254 inline media_status_t AImageReader_acquireNextImage(AImageReader* reader, AImage** image)
const;
255 inline media_status_t AImageReader_acquireLatestImage(AImageReader* reader, AImage** image)
const;
256 inline media_status_t AImageReader_setImageListener(AImageReader* reader, AImageReader_ImageListener* listener)
const;
263 inline AMediaCodec* AMediaCodec_createDecoderByType(
const char* mime_type)
const;
264 inline AMediaCodec* AMediaCodec_createEncoderByType(
const char* mime_type)
const;
265 inline media_status_t AMediaCodec_configure(AMediaCodec* codec,
const AMediaFormat* format, ANativeWindow* surface, AMediaCrypto* crypto, uint32_t flags)
const;
266 inline media_status_t AMediaCodec_delete(AMediaCodec* codec)
const;
267 inline ssize_t AMediaCodec_dequeueInputBuffer(AMediaCodec* codec, int64_t timeoutUs)
const;
268 inline ssize_t AMediaCodec_dequeueOutputBuffer(AMediaCodec* codec, AMediaCodecBufferInfo* info, int64_t timeoutUs)
const;
269 inline media_status_t AMediaCodec_flush(AMediaCodec* codec)
const;
270 inline AMediaFormat* AMediaCodec_getBufferFormat(AMediaCodec* codec,
size_t index)
const;
271 inline uint8_t* AMediaCodec_getInputBuffer(AMediaCodec* codec,
size_t idx,
size_t* out_size)
const;
272 inline AMediaFormat* AMediaCodec_getInputFormat(AMediaCodec* codec)
const;
273 inline uint8_t* AMediaCodec_getOutputBuffer(AMediaCodec* codec,
size_t idx,
size_t* out_size)
const;
274 inline AMediaFormat* AMediaCodec_getOutputFormat(AMediaCodec* codec)
const;
275 inline media_status_t AMediaCodec_queueInputBuffer(AMediaCodec* codec,
size_t idx,
unsigned int offset,
size_t size, uint64_t time, uint32_t flags)
const;
276 inline media_status_t AMediaCodec_releaseOutputBuffer(AMediaCodec* codec,
size_t idx,
bool render)
const;
277 inline media_status_t AMediaCodec_start(AMediaCodec* codec)
const;
278 inline media_status_t AMediaCodec_stop(AMediaCodec* codec)
const;
283 inline media_status_t AMediaFormat_delete(AMediaFormat* format)
const;
284 inline AMediaFormat* AMediaFormat_new()
const;
285 inline bool AMediaFormat_getInt32(AMediaFormat* mediaFormat,
const char* name, int32_t* out)
const;
286 inline bool AMediaFormat_getInt64(AMediaFormat* mediaFormat,
const char* name, int64_t* out)
const;
287 inline bool AMediaFormat_getString(AMediaFormat* mediaFormat,
const char* name,
const char** out)
const;
288 inline bool AMediaFormat_getRect(AMediaFormat *,
const char *name, int32_t *left, int32_t *top, int32_t *right, int32_t *bottom)
const;
289 inline void AMediaFormat_setBuffer(AMediaFormat* format,
const char* name,
const void* data,
size_t size)
const;
290 inline void AMediaFormat_setFloat(AMediaFormat* format,
const char* name,
float value)
const;
291 inline void AMediaFormat_setInt32(AMediaFormat* format,
const char* name, int32_t value)
const;
292 inline void AMediaFormat_setInt64(AMediaFormat* format,
const char* name, int64_t value)
const;
293 inline void AMediaFormat_setString(AMediaFormat* format,
const char* name,
const char* value)
const;
294 inline const char* AMediaFormat_toString(AMediaFormat* format)
const;
299 inline ssize_t AMediaMuxer_addTrack(AMediaMuxer* muxer,
const AMediaFormat* format)
const;
300 inline media_status_t AMediaMuxer_delete(AMediaMuxer* muxer)
const;
301 inline AMediaMuxer* AMediaMuxer_new(
int fd, OutputFormat format)
const;
302 inline media_status_t AMediaMuxer_setLocation(AMediaMuxer* muxer,
float latitude,
float longitude)
const;
303 inline media_status_t AMediaMuxer_setOrientationHint(AMediaMuxer* muxer,
int degrees)
const;
304 inline media_status_t AMediaMuxer_start(AMediaMuxer* muxer)
const;
305 inline media_status_t AMediaMuxer_stop(AMediaMuxer* muxer)
const;
306 inline media_status_t AMediaMuxer_writeSampleData(AMediaMuxer* muxer,
size_t trackIdx,
const uint8_t* data,
const AMediaCodecBufferInfo* info)
const;
311 inline bool AMediaExtractor_advance(AMediaExtractor* mediaExtractor)
const;
312 inline media_status_t AMediaExtractor_delete(AMediaExtractor* mediaExtractor)
const;
313 inline int64_t AMediaExtractor_getSampleTime(AMediaExtractor* mediaExtractor)
const;
314 inline size_t AMediaExtractor_getTrackCount(AMediaExtractor* mediaExtractor)
const;
315 inline AMediaFormat* AMediaExtractor_getTrackFormat(AMediaExtractor* mediaExtractor,
size_t idx)
const;
316 inline AMediaExtractor* AMediaExtractor_new()
const;
317 inline ssize_t AMediaExtractor_readSampleData(AMediaExtractor* mediaExtractor, uint8_t* buffer,
size_t capacity)
const;
318 inline media_status_t AMediaExtractor_seekTo(AMediaExtractor* mediaExtractor, int64_t seekPosUs, SeekMode mode)
const;
319 inline media_status_t AMediaExtractor_selectTrack(AMediaExtractor* mediaExtractor,
size_t idx)
const;
320 inline media_status_t AMediaExtractor_setDataSource(AMediaExtractor* mediaExtractor,
const char* location)
const;
321 inline media_status_t AMediaExtractor_setDataSourceFd(AMediaExtractor* mediaExtractor,
int fd, off64_t offset, off64_t length)
const;
349 void* libraryHandle_ =
nullptr;
351 #if __ANDROID_API__ >= 24
435 unsigned int initializationCounter_ = 0u;
465 #if __ANDROID_API__ >= 24
470 ocean_assert(AImage_delete_ !=
nullptr);
472 AImage_delete_(image);
478 ocean_assert(AImage_getWidth_ !=
nullptr);
480 return AImage_getWidth_(image, width);
486 ocean_assert(AImage_getHeight_ !=
nullptr);
488 return AImage_getHeight_(image, height);
494 ocean_assert(AImage_getFormat_ !=
nullptr);
496 return AImage_getFormat_(image, format);
502 ocean_assert(AImage_getCropRect_ !=
nullptr);
504 return AImage_getCropRect_(image, rect);
510 ocean_assert(AImage_getTimestamp_ !=
nullptr);
512 return AImage_getTimestamp_(image, timestampNs);
518 ocean_assert(AImage_getNumberOfPlanes_ !=
nullptr);
520 return AImage_getNumberOfPlanes_(image, numPlanes);
526 ocean_assert(AImage_getPlanePixelStride_ !=
nullptr);
528 return AImage_getPlanePixelStride_(image, planeIdx, pixelStride);
534 ocean_assert(AImage_getPlaneRowStride_ !=
nullptr);
536 return AImage_getPlaneRowStride_(image, planeIdx, rowStride);
542 ocean_assert(AImage_getPlaneData_ !=
nullptr);
544 return AImage_getPlaneData_(image, planeIdx, data, dataLength);
550 ocean_assert(AImageReader_new_ !=
nullptr);
552 return AImageReader_new_(width, height, format, maxImages, reader);
558 ocean_assert(AImageReader_delete_ !=
nullptr);
560 AImageReader_delete_(reader);
566 ocean_assert(AImageReader_getWindow_ !=
nullptr);
568 return AImageReader_getWindow_(reader, window);
574 ocean_assert(AImageReader_getWidth_ !=
nullptr);
576 return AImageReader_getWidth_(reader, width);
582 ocean_assert(AImageReader_getHeight_ !=
nullptr);
584 return AImageReader_getHeight_(reader, height);
590 ocean_assert(AImageReader_getFormat_ !=
nullptr);
592 return AImageReader_getFormat_(reader, format);
598 ocean_assert(AImageReader_getMaxImages_ !=
nullptr);
600 return AImageReader_getMaxImages_(reader, maxImages);
606 ocean_assert(AImageReader_acquireNextImage_ !=
nullptr);
608 return AImageReader_acquireNextImage_(reader, image);
614 ocean_assert(AImageReader_acquireLatestImage_ !=
nullptr);
616 return AImageReader_acquireLatestImage_(reader, image);
622 ocean_assert(AImageReader_setImageListener_ !=
nullptr);
624 return AImageReader_setImageListener_(reader, listener);
632 ocean_assert(AMediaCodec_createDecoderByType_ !=
nullptr);
634 return AMediaCodec_createDecoderByType_(mime_type);
640 ocean_assert(AMediaCodec_createEncoderByType_ !=
nullptr);
642 return AMediaCodec_createEncoderByType_(mime_type);
648 ocean_assert(AMediaCodec_configure_ !=
nullptr);
650 return AMediaCodec_configure_(codec, format, surface, crypto, flags);
656 ocean_assert(AMediaCodec_delete_ !=
nullptr);
658 return AMediaCodec_delete_(codec);
664 ocean_assert(AMediaCodec_dequeueInputBuffer_ !=
nullptr);
666 return AMediaCodec_dequeueInputBuffer_(codec, timeoutUs);
672 ocean_assert(AMediaCodec_dequeueOutputBuffer_ !=
nullptr);
674 return AMediaCodec_dequeueOutputBuffer_(codec, info, timeoutUs);
680 ocean_assert(AMediaCodec_flush_ !=
nullptr);
682 return AMediaCodec_flush_(codec);
688 ocean_assert(AMediaCodec_getBufferFormat_ !=
nullptr);
690 return AMediaCodec_getBufferFormat_(codec, index);
696 ocean_assert(AMediaCodec_getInputBuffer_ !=
nullptr);
698 return AMediaCodec_getInputBuffer_(codec, idx, out_size);
704 ocean_assert(AMediaCodec_getInputFormat_ !=
nullptr);
706 return AMediaCodec_getInputFormat_(codec);
712 ocean_assert(AMediaCodec_getOutputBuffer_ !=
nullptr);
714 return AMediaCodec_getOutputBuffer_(codec, idx, out_size);
720 ocean_assert(AMediaCodec_getOutputFormat_ !=
nullptr);
722 return AMediaCodec_getOutputFormat_(codec);
728 ocean_assert(AMediaCodec_queueInputBuffer_ !=
nullptr);
730 return AMediaCodec_queueInputBuffer_(codec, idx, offset, size, time, flags);
736 ocean_assert(AMediaCodec_releaseOutputBuffer_ !=
nullptr);
738 return AMediaCodec_releaseOutputBuffer_(codec, idx, render);
744 ocean_assert(AMediaCodec_start_ !=
nullptr);
746 return AMediaCodec_start_(codec);
752 ocean_assert(AMediaCodec_stop_ !=
nullptr);
754 return AMediaCodec_stop_(codec);
760 ocean_assert(AMediaFormat_delete_ !=
nullptr);
762 return AMediaFormat_delete_(format);
768 ocean_assert(AMediaFormat_new_ !=
nullptr);
770 return AMediaFormat_new_();
776 ocean_assert(AMediaFormat_getInt32_ !=
nullptr);
778 return AMediaFormat_getInt32_(mediaFormat, name, out);
784 ocean_assert(AMediaFormat_getInt64_ !=
nullptr);
786 return AMediaFormat_getInt64_(mediaFormat, name, out);
792 ocean_assert(AMediaFormat_getString_ !=
nullptr);
794 return AMediaFormat_getString_(mediaFormat, name, out);
800 ocean_assert(AMediaFormat_getRect_ !=
nullptr);
802 return AMediaFormat_getRect_(mediaFormat, name, left, top, right, bottom);
808 ocean_assert(AMediaFormat_setBuffer_ !=
nullptr);
810 return AMediaFormat_setBuffer_(format, name, data, size);
816 ocean_assert(AMediaFormat_setFloat_ !=
nullptr);
818 return AMediaFormat_setFloat_(format, name, value);
824 ocean_assert(AMediaFormat_setInt32_ !=
nullptr);
826 return AMediaFormat_setInt32_(format, name, value);
832 ocean_assert(AMediaFormat_setInt64_ !=
nullptr);
834 return AMediaFormat_setInt64_(format, name, value);
840 ocean_assert(AMediaFormat_setString_ !=
nullptr);
842 return AMediaFormat_setString_(format, name, value);
848 ocean_assert(AMediaFormat_toString_ !=
nullptr);
850 return AMediaFormat_toString_(format);
856 ocean_assert(AMediaMuxer_addTrack_ !=
nullptr);
858 return AMediaMuxer_addTrack_(muxer, format);
864 ocean_assert(AMediaMuxer_delete_ !=
nullptr);
866 return AMediaMuxer_delete_(muxer);
872 ocean_assert(AMediaMuxer_new_ !=
nullptr);
874 return AMediaMuxer_new_(fd, format);
880 ocean_assert(AMediaMuxer_setLocation_ !=
nullptr);
882 return AMediaMuxer_setLocation_(muxer, latitude, longitude);
888 ocean_assert(AMediaMuxer_setOrientationHint_ !=
nullptr);
890 return AMediaMuxer_setOrientationHint_(muxer, degrees);
896 ocean_assert(AMediaMuxer_start_ !=
nullptr);
898 return AMediaMuxer_start_(muxer);
904 ocean_assert(AMediaMuxer_stop_ !=
nullptr);
906 return AMediaMuxer_stop_(muxer);
912 ocean_assert(AMediaMuxer_writeSampleData_ !=
nullptr);
914 return AMediaMuxer_writeSampleData_(muxer, trackIdx, data, info);
920 ocean_assert(AMediaExtractor_advance_ !=
nullptr);
922 return AMediaExtractor_advance_(mediaExtractor);
928 ocean_assert(AMediaExtractor_delete_ !=
nullptr);
930 return AMediaExtractor_delete_(mediaExtractor);
936 ocean_assert(AMediaExtractor_getTrackCount_ !=
nullptr);
938 return AMediaExtractor_getTrackCount_(mediaExtractor);
944 ocean_assert(AMediaExtractor_getTrackFormat_ !=
nullptr);
946 return AMediaExtractor_getTrackFormat_(mediaExtractor, idx);
952 ocean_assert(AMediaExtractor_new_ !=
nullptr);
954 return AMediaExtractor_new_();
960 ocean_assert(AMediaExtractor_readSampleData_ !=
nullptr);
962 return AMediaExtractor_readSampleData_(mediaExtractor, buffer, capacity);
968 ocean_assert(AMediaExtractor_getSampleTime_ !=
nullptr);
970 return AMediaExtractor_getSampleTime_(mediaExtractor);
976 ocean_assert(AMediaExtractor_seekTo_ !=
nullptr);
978 return AMediaExtractor_seekTo_(mediaExtractor, seekPosUs, mode);
984 ocean_assert(AMediaExtractor_selectTrack_ !=
nullptr);
986 return AMediaExtractor_selectTrack_(mediaExtractor, idx);
992 ocean_assert(AMediaExtractor_setDataSource_ !=
nullptr);
994 return AMediaExtractor_setDataSource_(mediaExtractor, location);
1000 ocean_assert(AMediaExtractor_setDataSourceFd_ !=
nullptr);
1002 return AMediaExtractor_setDataSourceFd_(mediaExtractor, fd, offset, length);
This class implements a recursive lock object.
Definition: Lock.h:31
This class implements a scoped lock object for recursive lock objects.
Definition: Lock.h:135
This class wraps an unmanaged object (or reference) which needs to be released after usage.
Definition: ScopedObject.h:28
This template class is the base class for all singleton objects.
Definition: Singleton.h:71
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15