blob: 9caea3e7e8538e5a0c567aac1c89a717d704aa0a [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
21
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
50struct CMediaTrack {
51 void *data;
52 void (*free)(void *data);
53
54 status_t (*start)(void *data, MetaDataBase *params);
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 Nelissen56f19382018-09-12 15:30:59 -070061struct CMediaTrackV2 {
62 void *data;
63 void (*free)(void *data);
64
65 status_t (*start)(void *data, AMediaFormat *params);
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
73struct CMediaExtractorV1 {
Marco Nelissen0b164472018-05-30 12:16:56 -070074 void *data;
75
76 void (*free)(void *data);
77 size_t (*countTracks)(void *data);
Marco Nelissen2a3363a2018-09-13 13:15:30 -070078 CMediaTrack* (*getTrack)(void *data, size_t index);
Marco Nelissen0b164472018-05-30 12:16:56 -070079 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 Nelissen56f19382018-09-12 15:30:59 -070090struct 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
107typedef CMediaExtractorV1* (*CreatorFuncV1)(CDataSource *source, void *meta);
Marco Nelissen0b164472018-05-30 12:16:56 -0700108typedef 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 Nelissen56f19382018-09-12 15:30:59 -0700114typedef CreatorFuncV1 (*SnifferFuncV1)(
Marco Nelissencec44d02018-06-17 22:21:09 -0700115 CDataSource *source, float *confidence,
Marco Nelissen0b164472018-05-30 12:16:56 -0700116 void **meta, FreeMetaFunc *freeMeta);
117
Marco Nelissen56f19382018-09-12 15:30:59 -0700118typedef CMediaExtractorV2* (*CreatorFuncV2)(CDataSource *source, void *meta);
119
120typedef CreatorFuncV2 (*SnifferFuncV2)(
121 CDataSource *source, float *confidence,
122 void **meta, FreeMetaFunc *freeMeta);
123
124typedef CMediaExtractorV1 CMediaExtractor;
125typedef CreatorFuncV1 CreatorFunc;
126
127
Marco Nelissen0b164472018-05-30 12:16:56 -0700128typedef struct {
129 const uint8_t b[16];
130} media_uuid_t;
131
Marco Nelissen56f19382018-09-12 15:30:59 -0700132struct ExtractorDef {
Marco Nelissen0b164472018-05-30 12:16:56 -0700133 // 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 Nelissen56f19382018-09-12 15:30:59 -0700148 union {
149 SnifferFuncV1 v1;
150 SnifferFuncV2 v2;
151 } sniff;
152};
Marco Nelissen0b164472018-05-30 12:16:56 -0700153
Marco Nelissen56f19382018-09-12 15:30:59 -0700154const uint32_t EXTRACTORDEF_VERSION_LEGACY = 1;
155const uint32_t EXTRACTORDEF_VERSION_CURRENT = 2;
156
157const uint32_t EXTRACTORDEF_VERSION = EXTRACTORDEF_VERSION_LEGACY;
Marco Nelissen0b164472018-05-30 12:16:56 -0700158
159// each plugin library exports one function of this type
160typedef ExtractorDef (*GetExtractorDef)();
161
162} // extern "C"
163
164} // namespace android
165
166#endif // MEDIA_EXTRACTOR_PLUGIN_API_H_