blob: cccfc914ab46bf0cf4774a1939e05795fd4a9d02 [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
22namespace android {
23
24struct MediaTrack;
25class MetaDataBase;
Marco Nelissen2a3363a2018-09-13 13:15:30 -070026class MediaBufferBase;
Marco Nelissen0b164472018-05-30 12:16:56 -070027
28extern "C" {
29
Marco Nelissencec44d02018-06-17 22:21:09 -070030struct CDataSource {
31 ssize_t (*readAt)(void *handle, off64_t offset, void *data, size_t size);
32 status_t (*getSize)(void *handle, off64_t *size);
33 uint32_t (*flags)(void *handle );
34 bool (*getUri)(void *handle, char *uriString, size_t bufferSize);
35 void *handle;
36};
37
Marco Nelissen2a3363a2018-09-13 13:15:30 -070038enum CMediaTrackReadOptions : uint32_t {
39 SEEK_PREVIOUS_SYNC = 0,
40 SEEK_NEXT_SYNC = 1,
41 SEEK_CLOSEST_SYNC = 2,
42 SEEK_CLOSEST = 3,
43 SEEK_FRAME_INDEX = 4,
44 SEEK = 8,
45 NONBLOCKING = 16
46};
47
48struct CMediaTrack {
49 void *data;
50 void (*free)(void *data);
51
52 status_t (*start)(void *data, MetaDataBase *params);
53 status_t (*stop)(void *data);
54 status_t (*getFormat)(void *data, MetaDataBase &format);
55 status_t (*read)(void *data, MediaBufferBase **buffer, uint32_t options, int64_t seekPosUs);
56 bool (*supportsNonBlockingRead)(void *data);
57};
58
Marco Nelissen0b164472018-05-30 12:16:56 -070059struct CMediaExtractor {
60 void *data;
61
62 void (*free)(void *data);
63 size_t (*countTracks)(void *data);
Marco Nelissen2a3363a2018-09-13 13:15:30 -070064 CMediaTrack* (*getTrack)(void *data, size_t index);
Marco Nelissen0b164472018-05-30 12:16:56 -070065 status_t (*getTrackMetaData)(
66 void *data,
67 MetaDataBase& meta,
68 size_t index, uint32_t flags);
69
70 status_t (*getMetaData)(void *data, MetaDataBase& meta);
71 uint32_t (*flags)(void *data);
72 status_t (*setMediaCas)(void *data, const uint8_t* casToken, size_t size);
73 const char * (*name)(void *data);
74};
75
Marco Nelissencec44d02018-06-17 22:21:09 -070076typedef CMediaExtractor* (*CreatorFunc)(CDataSource *source, void *meta);
Marco Nelissen0b164472018-05-30 12:16:56 -070077typedef void (*FreeMetaFunc)(void *meta);
78
79// The sniffer can optionally fill in an opaque object, "meta", that helps
80// the corresponding extractor initialize its state without duplicating
81// effort already exerted by the sniffer. If "freeMeta" is given, it will be
82// called against the opaque object when it is no longer used.
83typedef CreatorFunc (*SnifferFunc)(
Marco Nelissencec44d02018-06-17 22:21:09 -070084 CDataSource *source, float *confidence,
Marco Nelissen0b164472018-05-30 12:16:56 -070085 void **meta, FreeMetaFunc *freeMeta);
86
87typedef struct {
88 const uint8_t b[16];
89} media_uuid_t;
90
91typedef struct {
92 // version number of this structure
93 const uint32_t def_version;
94
95 // A unique identifier for this extractor.
96 // See below for a convenience macro to create this from a string.
97 media_uuid_t extractor_uuid;
98
99 // Version number of this extractor. When two extractors with the same
100 // uuid are encountered, the one with the largest version number will
101 // be used.
102 const uint32_t extractor_version;
103
104 // a human readable name
105 const char *extractor_name;
106
107 // the sniffer function
108 const SnifferFunc sniff;
109} ExtractorDef;
110
111const uint32_t EXTRACTORDEF_VERSION = 1;
112
113// each plugin library exports one function of this type
114typedef ExtractorDef (*GetExtractorDef)();
115
116} // extern "C"
117
118} // namespace android
119
120#endif // MEDIA_EXTRACTOR_PLUGIN_API_H_