Marco Nelissen | 0b16447 | 2018-05-30 12:16:56 -0700 | [diff] [blame] | 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 | |
| 17 | #ifndef MEDIA_EXTRACTOR_PLUGIN_API_H_ |
| 18 | #define MEDIA_EXTRACTOR_PLUGIN_API_H_ |
| 19 | |
| 20 | #include <utils/Errors.h> // for status_t |
| 21 | |
Marco Nelissen | 56f1938 | 2018-09-12 15:30:59 -0700 | [diff] [blame] | 22 | struct AMediaFormat; |
| 23 | |
Marco Nelissen | 0b16447 | 2018-05-30 12:16:56 -0700 | [diff] [blame] | 24 | namespace android { |
| 25 | |
| 26 | struct MediaTrack; |
| 27 | class MetaDataBase; |
Marco Nelissen | 2a3363a | 2018-09-13 13:15:30 -0700 | [diff] [blame] | 28 | class MediaBufferBase; |
Marco Nelissen | 0b16447 | 2018-05-30 12:16:56 -0700 | [diff] [blame] | 29 | |
| 30 | extern "C" { |
| 31 | |
Marco Nelissen | cec44d0 | 2018-06-17 22:21:09 -0700 | [diff] [blame] | 32 | struct CDataSource { |
| 33 | ssize_t (*readAt)(void *handle, off64_t offset, void *data, size_t size); |
| 34 | status_t (*getSize)(void *handle, off64_t *size); |
| 35 | uint32_t (*flags)(void *handle ); |
| 36 | bool (*getUri)(void *handle, char *uriString, size_t bufferSize); |
| 37 | void *handle; |
| 38 | }; |
| 39 | |
Marco Nelissen | 2a3363a | 2018-09-13 13:15:30 -0700 | [diff] [blame] | 40 | enum CMediaTrackReadOptions : uint32_t { |
| 41 | SEEK_PREVIOUS_SYNC = 0, |
| 42 | SEEK_NEXT_SYNC = 1, |
| 43 | SEEK_CLOSEST_SYNC = 2, |
| 44 | SEEK_CLOSEST = 3, |
| 45 | SEEK_FRAME_INDEX = 4, |
| 46 | SEEK = 8, |
| 47 | NONBLOCKING = 16 |
| 48 | }; |
| 49 | |
| 50 | struct CMediaTrack { |
| 51 | void *data; |
| 52 | void (*free)(void *data); |
| 53 | |
Marco Nelissen | 3db2dcc | 2018-10-03 14:09:37 -0700 | [diff] [blame^] | 54 | status_t (*start)(void *data); |
Marco Nelissen | 2a3363a | 2018-09-13 13:15:30 -0700 | [diff] [blame] | 55 | status_t (*stop)(void *data); |
| 56 | status_t (*getFormat)(void *data, MetaDataBase &format); |
| 57 | status_t (*read)(void *data, MediaBufferBase **buffer, uint32_t options, int64_t seekPosUs); |
| 58 | bool (*supportsNonBlockingRead)(void *data); |
| 59 | }; |
| 60 | |
Marco Nelissen | 56f1938 | 2018-09-12 15:30:59 -0700 | [diff] [blame] | 61 | struct CMediaTrackV2 { |
| 62 | void *data; |
| 63 | void (*free)(void *data); |
| 64 | |
Marco Nelissen | 3db2dcc | 2018-10-03 14:09:37 -0700 | [diff] [blame^] | 65 | status_t (*start)(void *data); |
Marco Nelissen | 56f1938 | 2018-09-12 15:30:59 -0700 | [diff] [blame] | 66 | status_t (*stop)(void *data); |
| 67 | status_t (*getFormat)(void *data, AMediaFormat *format); |
| 68 | status_t (*read)(void *data, MediaBufferBase **buffer, uint32_t options, int64_t seekPosUs); |
| 69 | bool (*supportsNonBlockingRead)(void *data); |
| 70 | }; |
| 71 | |
| 72 | |
| 73 | struct CMediaExtractorV1 { |
Marco Nelissen | 0b16447 | 2018-05-30 12:16:56 -0700 | [diff] [blame] | 74 | void *data; |
| 75 | |
| 76 | void (*free)(void *data); |
| 77 | size_t (*countTracks)(void *data); |
Marco Nelissen | 2a3363a | 2018-09-13 13:15:30 -0700 | [diff] [blame] | 78 | CMediaTrack* (*getTrack)(void *data, size_t index); |
Marco Nelissen | 0b16447 | 2018-05-30 12:16:56 -0700 | [diff] [blame] | 79 | status_t (*getTrackMetaData)( |
| 80 | void *data, |
| 81 | MetaDataBase& meta, |
| 82 | size_t index, uint32_t flags); |
| 83 | |
| 84 | status_t (*getMetaData)(void *data, MetaDataBase& meta); |
| 85 | uint32_t (*flags)(void *data); |
| 86 | status_t (*setMediaCas)(void *data, const uint8_t* casToken, size_t size); |
| 87 | const char * (*name)(void *data); |
| 88 | }; |
| 89 | |
Marco Nelissen | 56f1938 | 2018-09-12 15:30:59 -0700 | [diff] [blame] | 90 | struct CMediaExtractorV2 { |
| 91 | void *data; |
| 92 | |
| 93 | void (*free)(void *data); |
| 94 | size_t (*countTracks)(void *data); |
| 95 | CMediaTrackV2* (*getTrack)(void *data, size_t index); |
| 96 | status_t (*getTrackMetaData)( |
| 97 | void *data, |
| 98 | AMediaFormat *meta, |
| 99 | size_t index, uint32_t flags); |
| 100 | |
| 101 | status_t (*getMetaData)(void *data, AMediaFormat *meta); |
| 102 | uint32_t (*flags)(void *data); |
| 103 | status_t (*setMediaCas)(void *data, const uint8_t* casToken, size_t size); |
| 104 | const char * (*name)(void *data); |
| 105 | }; |
| 106 | |
| 107 | typedef CMediaExtractorV1* (*CreatorFuncV1)(CDataSource *source, void *meta); |
Marco Nelissen | 0b16447 | 2018-05-30 12:16:56 -0700 | [diff] [blame] | 108 | typedef void (*FreeMetaFunc)(void *meta); |
| 109 | |
| 110 | // The sniffer can optionally fill in an opaque object, "meta", that helps |
| 111 | // the corresponding extractor initialize its state without duplicating |
| 112 | // effort already exerted by the sniffer. If "freeMeta" is given, it will be |
| 113 | // called against the opaque object when it is no longer used. |
Marco Nelissen | 56f1938 | 2018-09-12 15:30:59 -0700 | [diff] [blame] | 114 | typedef CreatorFuncV1 (*SnifferFuncV1)( |
Marco Nelissen | cec44d0 | 2018-06-17 22:21:09 -0700 | [diff] [blame] | 115 | CDataSource *source, float *confidence, |
Marco Nelissen | 0b16447 | 2018-05-30 12:16:56 -0700 | [diff] [blame] | 116 | void **meta, FreeMetaFunc *freeMeta); |
| 117 | |
Marco Nelissen | 56f1938 | 2018-09-12 15:30:59 -0700 | [diff] [blame] | 118 | typedef CMediaExtractorV2* (*CreatorFuncV2)(CDataSource *source, void *meta); |
| 119 | |
| 120 | typedef CreatorFuncV2 (*SnifferFuncV2)( |
| 121 | CDataSource *source, float *confidence, |
| 122 | void **meta, FreeMetaFunc *freeMeta); |
| 123 | |
| 124 | typedef CMediaExtractorV1 CMediaExtractor; |
| 125 | typedef CreatorFuncV1 CreatorFunc; |
| 126 | |
| 127 | |
Marco Nelissen | 0b16447 | 2018-05-30 12:16:56 -0700 | [diff] [blame] | 128 | typedef struct { |
| 129 | const uint8_t b[16]; |
| 130 | } media_uuid_t; |
| 131 | |
Marco Nelissen | 56f1938 | 2018-09-12 15:30:59 -0700 | [diff] [blame] | 132 | struct ExtractorDef { |
Marco Nelissen | 0b16447 | 2018-05-30 12:16:56 -0700 | [diff] [blame] | 133 | // version number of this structure |
| 134 | const uint32_t def_version; |
| 135 | |
| 136 | // A unique identifier for this extractor. |
| 137 | // See below for a convenience macro to create this from a string. |
| 138 | media_uuid_t extractor_uuid; |
| 139 | |
| 140 | // Version number of this extractor. When two extractors with the same |
| 141 | // uuid are encountered, the one with the largest version number will |
| 142 | // be used. |
| 143 | const uint32_t extractor_version; |
| 144 | |
| 145 | // a human readable name |
| 146 | const char *extractor_name; |
| 147 | |
Marco Nelissen | 56f1938 | 2018-09-12 15:30:59 -0700 | [diff] [blame] | 148 | union { |
| 149 | SnifferFuncV1 v1; |
| 150 | SnifferFuncV2 v2; |
| 151 | } sniff; |
| 152 | }; |
Marco Nelissen | 0b16447 | 2018-05-30 12:16:56 -0700 | [diff] [blame] | 153 | |
Marco Nelissen | 56f1938 | 2018-09-12 15:30:59 -0700 | [diff] [blame] | 154 | const uint32_t EXTRACTORDEF_VERSION_LEGACY = 1; |
| 155 | const uint32_t EXTRACTORDEF_VERSION_CURRENT = 2; |
| 156 | |
| 157 | const uint32_t EXTRACTORDEF_VERSION = EXTRACTORDEF_VERSION_LEGACY; |
Marco Nelissen | 0b16447 | 2018-05-30 12:16:56 -0700 | [diff] [blame] | 158 | |
| 159 | // each plugin library exports one function of this type |
| 160 | typedef ExtractorDef (*GetExtractorDef)(); |
| 161 | |
| 162 | } // extern "C" |
| 163 | |
| 164 | } // namespace android |
| 165 | |
| 166 | #endif // MEDIA_EXTRACTOR_PLUGIN_API_H_ |