MediaExtractorPluginApi.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. /*
  2. * Copyright (C) 2018 The Android Open Source Project
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #ifndef MEDIA_EXTRACTOR_PLUGIN_API_H_
  17. #define MEDIA_EXTRACTOR_PLUGIN_API_H_
  18. #include <utils/Errors.h> // for status_t
  19. #include <media/NdkMediaError.h>
  20. struct AMediaFormat;
  21. namespace android {
  22. struct MediaTrack;
  23. class MetaDataBase;
  24. class MediaBufferBase;
  25. extern "C" {
  26. struct CDataSource {
  27. ssize_t (*readAt)(void *handle, off64_t offset, void *data, size_t size);
  28. status_t (*getSize)(void *handle, off64_t *size);
  29. uint32_t (*flags)(void *handle );
  30. bool (*getUri)(void *handle, char *uriString, size_t bufferSize);
  31. void *handle;
  32. };
  33. enum CMediaTrackReadOptions : uint32_t {
  34. SEEK_PREVIOUS_SYNC = 0,
  35. SEEK_NEXT_SYNC = 1,
  36. SEEK_CLOSEST_SYNC = 2,
  37. SEEK_CLOSEST = 3,
  38. SEEK_FRAME_INDEX = 4,
  39. SEEK = 8,
  40. NONBLOCKING = 16
  41. };
  42. /**
  43. * only use CMediaBuffer allocated from the CMediaBufferGroup that is
  44. * provided to CMediaTrack::start()
  45. */
  46. struct CMediaBuffer {
  47. void *handle;
  48. void (*release)(void *handle);
  49. void* (*data)(void *handle);
  50. size_t (*size)(void *handle);
  51. size_t (*range_offset)(void *handle);
  52. size_t (*range_length)(void *handle);
  53. void (*set_range)(void *handle, size_t offset, size_t length);
  54. AMediaFormat* (*meta_data)(void *handle);
  55. };
  56. struct CMediaBufferGroup {
  57. void *handle;
  58. bool (*init)(void *handle, size_t buffers, size_t buffer_size, size_t growthLimit);
  59. void (*add_buffer)(void *handle, size_t size);
  60. media_status_t (*acquire_buffer)(void *handle,
  61. CMediaBuffer **buffer, bool nonBlocking, size_t requestedSize);
  62. bool (*has_buffers)(void *handle);
  63. };
  64. struct CMediaTrack {
  65. void *data;
  66. void (*free)(void *data);
  67. media_status_t (*start)(void *data, CMediaBufferGroup *bufferGroup);
  68. media_status_t (*stop)(void *data);
  69. media_status_t (*getFormat)(void *data, AMediaFormat *format);
  70. media_status_t (*read)(void *data, CMediaBuffer **buffer, uint32_t options, int64_t seekPosUs);
  71. bool (*supportsNonBlockingRead)(void *data);
  72. };
  73. struct CMediaExtractor {
  74. void *data;
  75. void (*free)(void *data);
  76. size_t (*countTracks)(void *data);
  77. CMediaTrack* (*getTrack)(void *data, size_t index);
  78. media_status_t (*getTrackMetaData)(
  79. void *data,
  80. AMediaFormat *meta,
  81. size_t index, uint32_t flags);
  82. media_status_t (*getMetaData)(void *data, AMediaFormat *meta);
  83. uint32_t (*flags)(void *data);
  84. media_status_t (*setMediaCas)(void *data, const uint8_t* casToken, size_t size);
  85. const char * (*name)(void *data);
  86. };
  87. typedef CMediaExtractor* (*CreatorFunc)(CDataSource *source, void *meta);
  88. typedef void (*FreeMetaFunc)(void *meta);
  89. // The sniffer can optionally fill in an opaque object, "meta", that helps
  90. // the corresponding extractor initialize its state without duplicating
  91. // effort already exerted by the sniffer. If "freeMeta" is given, it will be
  92. // called against the opaque object when it is no longer used.
  93. typedef CreatorFunc (*SnifferFunc)(
  94. CDataSource *source, float *confidence,
  95. void **meta, FreeMetaFunc *freeMeta);
  96. typedef CMediaExtractor CMediaExtractor;
  97. typedef CreatorFunc CreatorFunc;
  98. typedef struct {
  99. const uint8_t b[16];
  100. } media_uuid_t;
  101. struct ExtractorDef {
  102. // version number of this structure
  103. const uint32_t def_version;
  104. // A unique identifier for this extractor.
  105. // See below for a convenience macro to create this from a string.
  106. media_uuid_t extractor_uuid;
  107. // Version number of this extractor. When two extractors with the same
  108. // uuid are encountered, the one with the largest version number will
  109. // be used.
  110. const uint32_t extractor_version;
  111. // a human readable name
  112. const char *extractor_name;
  113. union {
  114. struct {
  115. SnifferFunc sniff;
  116. } v2;
  117. struct {
  118. SnifferFunc sniff;
  119. // a NULL terminated list of container mime types and/or file extensions
  120. // that this extractor supports
  121. const char **supported_types;
  122. } v3;
  123. } u;
  124. };
  125. // the C++ based API which first shipped in P and is no longer supported
  126. const uint32_t EXTRACTORDEF_VERSION_LEGACY = 1;
  127. // the first C/NDK based API
  128. const uint32_t EXTRACTORDEF_VERSION_NDK_V1 = 2;
  129. // the second C/NDK based API
  130. const uint32_t EXTRACTORDEF_VERSION_NDK_V2 = 3;
  131. const uint32_t EXTRACTORDEF_VERSION = EXTRACTORDEF_VERSION_NDK_V2;
  132. // each plugin library exports one function of this type
  133. typedef ExtractorDef (*GetExtractorDef)();
  134. } // extern "C"
  135. } // namespace android
  136. #endif // MEDIA_EXTRACTOR_PLUGIN_API_H_