blob: c3180dcf9d67d5eeedd35d21613497938eb26953 [file] [log] [blame]
Marco Nelissen0c3be872014-05-01 10:14:44 -07001/*
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
Dan Albert2975a242016-09-23 16:17:45 -070031#include <sys/cdefs.h>
Marco Nelissen0c3be872014-05-01 10:14:44 -070032#include <sys/types.h>
33
Marco Nelissen050eb322014-05-09 15:10:23 -070034#include "NdkMediaCodec.h"
Marco Nelissen0c3be872014-05-01 10:14:44 -070035#include "NdkMediaFormat.h"
Marco Nelissen050eb322014-05-09 15:10:23 -070036#include "NdkMediaCrypto.h"
Marco Nelissen0c3be872014-05-01 10:14:44 -070037
38#ifdef __cplusplus
39extern "C" {
40#endif
41
Dan Albert2975a242016-09-23 16:17:45 -070042#if __ANDROID_API__ >= 21
43
Marco Nelissen0c3be872014-05-01 10:14:44 -070044struct AMediaExtractor;
45typedef struct AMediaExtractor AMediaExtractor;
46
47
48/**
49 * Create new media extractor
50 */
51AMediaExtractor* AMediaExtractor_new();
52
53/**
54 * Delete a previously created media extractor
55 */
Marco Nelissene419d7c2014-05-15 14:17:25 -070056media_status_t AMediaExtractor_delete(AMediaExtractor*);
Marco Nelissen0c3be872014-05-01 10:14:44 -070057
58/**
59 * Set the file descriptor from which the extractor will read.
60 */
Glenn Kastenb187de12014-12-30 08:18:15 -080061media_status_t AMediaExtractor_setDataSourceFd(AMediaExtractor*, int fd, off64_t offset,
62 off64_t length);
Marco Nelissen0c3be872014-05-01 10:14:44 -070063
64/**
65 * Set the URI from which the extractor will read.
66 */
Glenn Kastenb187de12014-12-30 08:18:15 -080067media_status_t AMediaExtractor_setDataSource(AMediaExtractor*, const char *location);
68 // TODO support headers
Marco Nelissen0c3be872014-05-01 10:14:44 -070069
70/**
71 * Return the number of tracks in the previously specified media file
72 */
Marco Nelissene419d7c2014-05-15 14:17:25 -070073size_t AMediaExtractor_getTrackCount(AMediaExtractor*);
Marco Nelissen0c3be872014-05-01 10:14:44 -070074
75/**
76 * Return the format of the specified track. The caller must free the returned format
77 */
78AMediaFormat* 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 */
Marco Nelissene419d7c2014-05-15 14:17:25 -070086media_status_t AMediaExtractor_selectTrack(AMediaExtractor*, size_t idx);
Marco Nelissen0c3be872014-05-01 10:14:44 -070087
88/**
89 * Unselect the specified track. Subsequent calls to readSampleData, getSampleTrackIndex and
90 * getSampleTime only retrieve information for the subset of tracks selected..
91 */
Marco Nelissene419d7c2014-05-15 14:17:25 -070092media_status_t AMediaExtractor_unselectTrack(AMediaExtractor*, size_t idx);
Marco Nelissen0c3be872014-05-01 10:14:44 -070093
94/**
95 * Read the current sample.
96 */
Marco Nelissene419d7c2014-05-15 14:17:25 -070097ssize_t AMediaExtractor_readSampleData(AMediaExtractor*, uint8_t *buffer, size_t capacity);
Marco Nelissen0c3be872014-05-01 10:14:44 -070098
99/**
100 * Read the current sample's flags.
101 */
Marco Nelissene419d7c2014-05-15 14:17:25 -0700102uint32_t AMediaExtractor_getSampleFlags(AMediaExtractor*); // see definitions below
Marco Nelissen0c3be872014-05-01 10:14:44 -0700103
104/**
105 * Returns the track index the current sample originates from (or -1
106 * if no more samples are available)
107 */
108int 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 */
Marco Nelisseneb4860c2014-05-29 08:04:34 -0700114int64_t AMediaExtractor_getSampleTime(AMediaExtractor*);
Marco Nelissen0c3be872014-05-01 10:14:44 -0700115
116/**
117 * Advance to the next sample. Returns false if no more sample data
118 * is available (end of stream).
119 */
120bool AMediaExtractor_advance(AMediaExtractor*);
121
Marco Nelissen79e2b622014-05-16 08:07:28 -0700122typedef enum {
123 AMEDIAEXTRACTOR_SEEK_PREVIOUS_SYNC,
124 AMEDIAEXTRACTOR_SEEK_NEXT_SYNC,
125 AMEDIAEXTRACTOR_SEEK_CLOSEST_SYNC
126} SeekMode;
127
128/**
129 *
130 */
131media_status_t AMediaExtractor_seekTo(AMediaExtractor*, int64_t seekPosUs, SeekMode mode);
Marco Nelissen050eb322014-05-09 15:10:23 -0700132
133/**
134 * mapping of crypto scheme uuid to the scheme specific data for that scheme
135 */
136typedef 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 */
145typedef struct PsshInfo {
146 size_t numentries;
147 PsshEntry entries[0];
148} PsshInfo;
149
150/**
151 * Get the PSSH info if present.
152 */
153PsshInfo* AMediaExtractor_getPsshInfo(AMediaExtractor*);
154
155
156AMediaCodecCryptoInfo *AMediaExtractor_getSampleCryptoInfo(AMediaExtractor *);
157
158
Marco Nelissen0c3be872014-05-01 10:14:44 -0700159enum {
160 AMEDIAEXTRACTOR_SAMPLE_FLAG_SYNC = 1,
161 AMEDIAEXTRACTOR_SAMPLE_FLAG_ENCRYPTED = 2,
162};
163
Dan Albert2975a242016-09-23 16:17:45 -0700164#endif /* __ANDROID_API__ >= 21 */
165
Marco Nelissen0c3be872014-05-01 10:14:44 -0700166#ifdef __cplusplus
167} // extern "C"
168#endif
169
170#endif // _NDK_MEDIA_EXTRACTOR_H