• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2014 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 
18 /*
19  * This file defines an NDK API.
20  * Do not remove methods.
21  * Do not change method signatures.
22  * Do not change the value of constants.
23  * Do not change the size of any of the classes defined in here.
24  * Do not reference types that are not part of the NDK.
25  * Do not #include files that aren't part of the NDK.
26  */
27 
28 #ifndef _NDK_MEDIA_EXTRACTOR_H
29 #define _NDK_MEDIA_EXTRACTOR_H
30 
31 #include <sys/cdefs.h>
32 #include <sys/types.h>
33 
34 #include "NdkMediaCodec.h"
35 #include "NdkMediaFormat.h"
36 #include "NdkMediaCrypto.h"
37 
38 #ifdef __cplusplus
39 extern "C" {
40 #endif
41 
42 #if __ANDROID_API__ >= 21
43 
44 struct AMediaExtractor;
45 typedef struct AMediaExtractor AMediaExtractor;
46 
47 
48 /**
49  * Create new media extractor
50  */
51 AMediaExtractor* AMediaExtractor_new();
52 
53 /**
54  * Delete a previously created media extractor
55  */
56 media_status_t AMediaExtractor_delete(AMediaExtractor*);
57 
58 /**
59  *  Set the file descriptor from which the extractor will read.
60  */
61 media_status_t AMediaExtractor_setDataSourceFd(AMediaExtractor*, int fd, off64_t offset,
62         off64_t length);
63 
64 /**
65  * Set the URI from which the extractor will read.
66  */
67 media_status_t AMediaExtractor_setDataSource(AMediaExtractor*, const char *location);
68         // TODO support headers
69 
70 /**
71  * Return the number of tracks in the previously specified media file
72  */
73 size_t AMediaExtractor_getTrackCount(AMediaExtractor*);
74 
75 /**
76  * Return the format of the specified track. The caller must free the returned format
77  */
78 AMediaFormat* AMediaExtractor_getTrackFormat(AMediaExtractor*, size_t idx);
79 
80 /**
81  * Select the specified track. Subsequent calls to readSampleData, getSampleTrackIndex and
82  * getSampleTime only retrieve information for the subset of tracks selected.
83  * Selecting the same track multiple times has no effect, the track is
84  * only selected once.
85  */
86 media_status_t AMediaExtractor_selectTrack(AMediaExtractor*, size_t idx);
87 
88 /**
89  * Unselect the specified track. Subsequent calls to readSampleData, getSampleTrackIndex and
90  * getSampleTime only retrieve information for the subset of tracks selected..
91  */
92 media_status_t AMediaExtractor_unselectTrack(AMediaExtractor*, size_t idx);
93 
94 /**
95  * Read the current sample.
96  */
97 ssize_t AMediaExtractor_readSampleData(AMediaExtractor*, uint8_t *buffer, size_t capacity);
98 
99 /**
100  * Read the current sample's flags.
101  */
102 uint32_t AMediaExtractor_getSampleFlags(AMediaExtractor*); // see definitions below
103 
104 /**
105  * Returns the track index the current sample originates from (or -1
106  * if no more samples are available)
107  */
108 int AMediaExtractor_getSampleTrackIndex(AMediaExtractor*);
109 
110 /**
111  * Returns the current sample's presentation time in microseconds.
112  * or -1 if no more samples are available.
113  */
114 int64_t AMediaExtractor_getSampleTime(AMediaExtractor*);
115 
116 /**
117  * Advance to the next sample. Returns false if no more sample data
118  * is available (end of stream).
119  */
120 bool AMediaExtractor_advance(AMediaExtractor*);
121 
122 typedef enum {
123     AMEDIAEXTRACTOR_SEEK_PREVIOUS_SYNC,
124     AMEDIAEXTRACTOR_SEEK_NEXT_SYNC,
125     AMEDIAEXTRACTOR_SEEK_CLOSEST_SYNC
126 } SeekMode;
127 
128 /**
129  *
130  */
131 media_status_t AMediaExtractor_seekTo(AMediaExtractor*, int64_t seekPosUs, SeekMode mode);
132 
133 /**
134  * mapping of crypto scheme uuid to the scheme specific data for that scheme
135  */
136 typedef struct PsshEntry {
137     AMediaUUID uuid;
138     size_t datalen;
139     void *data;
140 } PsshEntry;
141 
142 /**
143  * list of crypto schemes and their data
144  */
145 typedef struct PsshInfo {
146     size_t numentries;
147     PsshEntry entries[0];
148 } PsshInfo;
149 
150 /**
151  * Get the PSSH info if present.
152  */
153 PsshInfo* AMediaExtractor_getPsshInfo(AMediaExtractor*);
154 
155 
156 AMediaCodecCryptoInfo *AMediaExtractor_getSampleCryptoInfo(AMediaExtractor *);
157 
158 
159 enum {
160     AMEDIAEXTRACTOR_SAMPLE_FLAG_SYNC = 1,
161     AMEDIAEXTRACTOR_SAMPLE_FLAG_ENCRYPTED = 2,
162 };
163 
164 #endif /* __ANDROID_API__ >= 21 */
165 
166 #ifdef __cplusplus
167 } // extern "C"
168 #endif
169 
170 #endif // _NDK_MEDIA_EXTRACTOR_H
171