blob: 5a319d749763301d9706c96e0c7f7764d6106d6a [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
31#include <sys/types.h>
32
Marco Nelissen050eb322014-05-09 15:10:23 -070033#include "NdkMediaCodec.h"
Marco Nelissen0c3be872014-05-01 10:14:44 -070034#include "NdkMediaFormat.h"
Marco Nelissen050eb322014-05-09 15:10:23 -070035#include "NdkMediaCrypto.h"
Marco Nelissen0c3be872014-05-01 10:14:44 -070036
37#ifdef __cplusplus
38extern "C" {
39#endif
40
41struct AMediaExtractor;
42typedef struct AMediaExtractor AMediaExtractor;
43
44
45/**
46 * Create new media extractor
47 */
48AMediaExtractor* AMediaExtractor_new();
49
50/**
51 * Delete a previously created media extractor
52 */
Marco Nelissene419d7c2014-05-15 14:17:25 -070053media_status_t AMediaExtractor_delete(AMediaExtractor*);
Marco Nelissen0c3be872014-05-01 10:14:44 -070054
55/**
56 * Set the file descriptor from which the extractor will read.
57 */
Marco Nelissene419d7c2014-05-15 14:17:25 -070058media_status_t AMediaExtractor_setDataSourceFd(AMediaExtractor*, int fd, off64_t offset, off64_t length);
Marco Nelissen0c3be872014-05-01 10:14:44 -070059
60/**
61 * Set the URI from which the extractor will read.
62 */
Marco Nelissene419d7c2014-05-15 14:17:25 -070063media_status_t AMediaExtractor_setDataSource(AMediaExtractor*, const char *location); // TODO support headers
Marco Nelissen0c3be872014-05-01 10:14:44 -070064
65/**
66 * Return the number of tracks in the previously specified media file
67 */
Marco Nelissene419d7c2014-05-15 14:17:25 -070068size_t AMediaExtractor_getTrackCount(AMediaExtractor*);
Marco Nelissen0c3be872014-05-01 10:14:44 -070069
70/**
71 * Return the format of the specified track. The caller must free the returned format
72 */
73AMediaFormat* AMediaExtractor_getTrackFormat(AMediaExtractor*, size_t idx);
74
75/**
76 * Select the specified track. Subsequent calls to readSampleData, getSampleTrackIndex and
77 * getSampleTime only retrieve information for the subset of tracks selected.
78 * Selecting the same track multiple times has no effect, the track is
79 * only selected once.
80 */
Marco Nelissene419d7c2014-05-15 14:17:25 -070081media_status_t AMediaExtractor_selectTrack(AMediaExtractor*, size_t idx);
Marco Nelissen0c3be872014-05-01 10:14:44 -070082
83/**
84 * Unselect the specified track. Subsequent calls to readSampleData, getSampleTrackIndex and
85 * getSampleTime only retrieve information for the subset of tracks selected..
86 */
Marco Nelissene419d7c2014-05-15 14:17:25 -070087media_status_t AMediaExtractor_unselectTrack(AMediaExtractor*, size_t idx);
Marco Nelissen0c3be872014-05-01 10:14:44 -070088
89/**
90 * Read the current sample.
91 */
Marco Nelissene419d7c2014-05-15 14:17:25 -070092ssize_t AMediaExtractor_readSampleData(AMediaExtractor*, uint8_t *buffer, size_t capacity);
Marco Nelissen0c3be872014-05-01 10:14:44 -070093
94/**
95 * Read the current sample's flags.
96 */
Marco Nelissene419d7c2014-05-15 14:17:25 -070097uint32_t AMediaExtractor_getSampleFlags(AMediaExtractor*); // see definitions below
Marco Nelissen0c3be872014-05-01 10:14:44 -070098
99/**
100 * Returns the track index the current sample originates from (or -1
101 * if no more samples are available)
102 */
103int AMediaExtractor_getSampleTrackIndex(AMediaExtractor*);
104
105/**
106 * Returns the current sample's presentation time in microseconds.
107 * or -1 if no more samples are available.
108 */
109int64_t AMediaExtractor_getSampletime(AMediaExtractor*);
110
111/**
112 * Advance to the next sample. Returns false if no more sample data
113 * is available (end of stream).
114 */
115bool AMediaExtractor_advance(AMediaExtractor*);
116
Marco Nelissen79e2b622014-05-16 08:07:28 -0700117typedef enum {
118 AMEDIAEXTRACTOR_SEEK_PREVIOUS_SYNC,
119 AMEDIAEXTRACTOR_SEEK_NEXT_SYNC,
120 AMEDIAEXTRACTOR_SEEK_CLOSEST_SYNC
121} SeekMode;
122
123/**
124 *
125 */
126media_status_t AMediaExtractor_seekTo(AMediaExtractor*, int64_t seekPosUs, SeekMode mode);
Marco Nelissen050eb322014-05-09 15:10:23 -0700127
128/**
129 * mapping of crypto scheme uuid to the scheme specific data for that scheme
130 */
131typedef struct PsshEntry {
132 AMediaUUID uuid;
133 size_t datalen;
134 void *data;
135} PsshEntry;
136
137/**
138 * list of crypto schemes and their data
139 */
140typedef struct PsshInfo {
141 size_t numentries;
142 PsshEntry entries[0];
143} PsshInfo;
144
145/**
146 * Get the PSSH info if present.
147 */
148PsshInfo* AMediaExtractor_getPsshInfo(AMediaExtractor*);
149
150
151AMediaCodecCryptoInfo *AMediaExtractor_getSampleCryptoInfo(AMediaExtractor *);
152
153
Marco Nelissen0c3be872014-05-01 10:14:44 -0700154enum {
155 AMEDIAEXTRACTOR_SAMPLE_FLAG_SYNC = 1,
156 AMEDIAEXTRACTOR_SAMPLE_FLAG_ENCRYPTED = 2,
157};
158
Marco Nelissen0c3be872014-05-01 10:14:44 -0700159#ifdef __cplusplus
160} // extern "C"
161#endif
162
163#endif // _NDK_MEDIA_EXTRACTOR_H