blob: 916472cef5ca86721d41604da5eddfded38301a4 [file] [log] [blame]
Marco Nelissen0b164472018-05-30 12:16:56 -07001/*
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
Marco Nelissen5dcf85a2018-10-11 09:49:02 -070021#include <media/NdkMediaError.h>
Marco Nelissen56f19382018-09-12 15:30:59 -070022struct AMediaFormat;
23
Marco Nelissen0b164472018-05-30 12:16:56 -070024namespace android {
25
26struct MediaTrack;
27class MetaDataBase;
Marco Nelissen2a3363a2018-09-13 13:15:30 -070028class MediaBufferBase;
Marco Nelissen0b164472018-05-30 12:16:56 -070029
30extern "C" {
31
Marco Nelissencec44d02018-06-17 22:21:09 -070032struct 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 Nelissen2a3363a2018-09-13 13:15:30 -070040enum 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
Marco Nelissen0e043b62018-11-14 11:26:05 -080050/**
Marco Nelissena3082872018-12-19 14:36:28 -080051 * only use CMediaBuffer allocated from the CMediaBufferGroup that is
Marco Nelissen0e043b62018-11-14 11:26:05 -080052 * provided to CMediaTrack::start()
53 */
Marco Nelissena3082872018-12-19 14:36:28 -080054struct CMediaBuffer {
Marco Nelissen0e043b62018-11-14 11:26:05 -080055 void *handle;
56 void (*release)(void *handle);
57 void* (*data)(void *handle);
58 size_t (*size)(void *handle);
59 size_t (*range_offset)(void *handle);
60 size_t (*range_length)(void *handle);
61 void (*set_range)(void *handle, size_t offset, size_t length);
62 AMediaFormat* (*meta_data)(void *handle);
63};
64
Marco Nelissena3082872018-12-19 14:36:28 -080065struct CMediaBufferGroup {
Marco Nelissen0e043b62018-11-14 11:26:05 -080066 void *handle;
67 bool (*init)(void *handle, size_t buffers, size_t buffer_size, size_t growthLimit);
68 void (*add_buffer)(void *handle, size_t size);
69 media_status_t (*acquire_buffer)(void *handle,
Marco Nelissena3082872018-12-19 14:36:28 -080070 CMediaBuffer **buffer, bool nonBlocking, size_t requestedSize);
Marco Nelissen0e043b62018-11-14 11:26:05 -080071 bool (*has_buffers)(void *handle);
72};
73
Marco Nelissena3082872018-12-19 14:36:28 -080074struct CMediaTrack {
Marco Nelissen0e043b62018-11-14 11:26:05 -080075 void *data;
76 void (*free)(void *data);
77
Marco Nelissena3082872018-12-19 14:36:28 -080078 media_status_t (*start)(void *data, CMediaBufferGroup *bufferGroup);
Marco Nelissen0e043b62018-11-14 11:26:05 -080079 media_status_t (*stop)(void *data);
80 media_status_t (*getFormat)(void *data, AMediaFormat *format);
Marco Nelissena3082872018-12-19 14:36:28 -080081 media_status_t (*read)(void *data, CMediaBuffer **buffer, uint32_t options, int64_t seekPosUs);
Marco Nelissen0e043b62018-11-14 11:26:05 -080082 bool (*supportsNonBlockingRead)(void *data);
83};
Marco Nelissen56f19382018-09-12 15:30:59 -070084
Marco Nelissena3082872018-12-19 14:36:28 -080085struct CMediaExtractor {
Marco Nelissen0b164472018-05-30 12:16:56 -070086 void *data;
87
88 void (*free)(void *data);
89 size_t (*countTracks)(void *data);
Marco Nelissen2a3363a2018-09-13 13:15:30 -070090 CMediaTrack* (*getTrack)(void *data, size_t index);
Marco Nelissen5dcf85a2018-10-11 09:49:02 -070091 media_status_t (*getTrackMetaData)(
Marco Nelissen56f19382018-09-12 15:30:59 -070092 void *data,
93 AMediaFormat *meta,
94 size_t index, uint32_t flags);
95
Marco Nelissen5dcf85a2018-10-11 09:49:02 -070096 media_status_t (*getMetaData)(void *data, AMediaFormat *meta);
Marco Nelissen56f19382018-09-12 15:30:59 -070097 uint32_t (*flags)(void *data);
Marco Nelissen5dcf85a2018-10-11 09:49:02 -070098 media_status_t (*setMediaCas)(void *data, const uint8_t* casToken, size_t size);
Marco Nelissen56f19382018-09-12 15:30:59 -070099 const char * (*name)(void *data);
100};
101
Marco Nelissena3082872018-12-19 14:36:28 -0800102typedef CMediaExtractor* (*CreatorFunc)(CDataSource *source, void *meta);
Marco Nelissen0b164472018-05-30 12:16:56 -0700103typedef void (*FreeMetaFunc)(void *meta);
104
105// The sniffer can optionally fill in an opaque object, "meta", that helps
106// the corresponding extractor initialize its state without duplicating
107// effort already exerted by the sniffer. If "freeMeta" is given, it will be
108// called against the opaque object when it is no longer used.
Marco Nelissena3082872018-12-19 14:36:28 -0800109typedef CreatorFunc (*SnifferFunc)(
Marco Nelissencec44d02018-06-17 22:21:09 -0700110 CDataSource *source, float *confidence,
Marco Nelissen0b164472018-05-30 12:16:56 -0700111 void **meta, FreeMetaFunc *freeMeta);
112
Marco Nelissena3082872018-12-19 14:36:28 -0800113typedef CMediaExtractor CMediaExtractor;
114typedef CreatorFunc CreatorFunc;
Marco Nelissen56f19382018-09-12 15:30:59 -0700115
116
Marco Nelissen0b164472018-05-30 12:16:56 -0700117typedef struct {
118 const uint8_t b[16];
119} media_uuid_t;
120
Marco Nelissen56f19382018-09-12 15:30:59 -0700121struct ExtractorDef {
Marco Nelissen0b164472018-05-30 12:16:56 -0700122 // version number of this structure
123 const uint32_t def_version;
124
125 // A unique identifier for this extractor.
126 // See below for a convenience macro to create this from a string.
127 media_uuid_t extractor_uuid;
128
129 // Version number of this extractor. When two extractors with the same
130 // uuid are encountered, the one with the largest version number will
131 // be used.
132 const uint32_t extractor_version;
133
134 // a human readable name
135 const char *extractor_name;
136
Marco Nelissen56f19382018-09-12 15:30:59 -0700137 union {
Marco Nelissen57822092019-01-07 14:51:32 -0800138 struct {
139 SnifferFunc sniff;
140 } v2;
141 struct {
142 SnifferFunc sniff;
143 // a NULL terminated list of container mime types and/or file extensions
144 // that this extractor supports
145 const char **supported_types;
146 } v3;
147 } u;
Marco Nelissen56f19382018-09-12 15:30:59 -0700148};
Marco Nelissen0b164472018-05-30 12:16:56 -0700149
Marco Nelissena3082872018-12-19 14:36:28 -0800150// the C++ based API which first shipped in P and is no longer supported
Marco Nelissen56f19382018-09-12 15:30:59 -0700151const uint32_t EXTRACTORDEF_VERSION_LEGACY = 1;
Marco Nelissen56f19382018-09-12 15:30:59 -0700152
Marco Nelissena3082872018-12-19 14:36:28 -0800153// the first C/NDK based API
154const uint32_t EXTRACTORDEF_VERSION_NDK_V1 = 2;
155
Marco Nelissen57822092019-01-07 14:51:32 -0800156// the second C/NDK based API
157const uint32_t EXTRACTORDEF_VERSION_NDK_V2 = 3;
158
159const uint32_t EXTRACTORDEF_VERSION = EXTRACTORDEF_VERSION_NDK_V2;
Marco Nelissen0b164472018-05-30 12:16:56 -0700160
161// each plugin library exports one function of this type
162typedef ExtractorDef (*GetExtractorDef)();
163
164} // extern "C"
165
166} // namespace android
167
168#endif // MEDIA_EXTRACTOR_PLUGIN_API_H_