| Marco Nelissen | 0c3be87 | 2014-05-01 10:14:44 -0700 | [diff] [blame] | 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 |  | 
| Dan Albert | 2975a24 | 2016-09-23 16:17:45 -0700 | [diff] [blame] | 31 | #include <sys/cdefs.h> | 
| Marco Nelissen | 0c3be87 | 2014-05-01 10:14:44 -0700 | [diff] [blame] | 32 | #include <sys/types.h> | 
|  | 33 |  | 
| Marco Nelissen | 050eb32 | 2014-05-09 15:10:23 -0700 | [diff] [blame] | 34 | #include "NdkMediaCodec.h" | 
| Marco Nelissen | 0c3be87 | 2014-05-01 10:14:44 -0700 | [diff] [blame] | 35 | #include "NdkMediaFormat.h" | 
| Marco Nelissen | 050eb32 | 2014-05-09 15:10:23 -0700 | [diff] [blame] | 36 | #include "NdkMediaCrypto.h" | 
| Marco Nelissen | 0c3be87 | 2014-05-01 10:14:44 -0700 | [diff] [blame] | 37 |  | 
|  | 38 | #ifdef __cplusplus | 
|  | 39 | extern "C" { | 
|  | 40 | #endif | 
|  | 41 |  | 
| Dan Albert | 2975a24 | 2016-09-23 16:17:45 -0700 | [diff] [blame] | 42 | #if __ANDROID_API__ >= 21 | 
|  | 43 |  | 
| Marco Nelissen | 0c3be87 | 2014-05-01 10:14:44 -0700 | [diff] [blame] | 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 | */ | 
| Marco Nelissen | e419d7c | 2014-05-15 14:17:25 -0700 | [diff] [blame] | 56 | media_status_t AMediaExtractor_delete(AMediaExtractor*); | 
| Marco Nelissen | 0c3be87 | 2014-05-01 10:14:44 -0700 | [diff] [blame] | 57 |  | 
|  | 58 | /** | 
|  | 59 | *  Set the file descriptor from which the extractor will read. | 
|  | 60 | */ | 
| Glenn Kasten | b187de1 | 2014-12-30 08:18:15 -0800 | [diff] [blame] | 61 | media_status_t AMediaExtractor_setDataSourceFd(AMediaExtractor*, int fd, off64_t offset, | 
|  | 62 | off64_t length); | 
| Marco Nelissen | 0c3be87 | 2014-05-01 10:14:44 -0700 | [diff] [blame] | 63 |  | 
|  | 64 | /** | 
|  | 65 | * Set the URI from which the extractor will read. | 
|  | 66 | */ | 
| Glenn Kasten | b187de1 | 2014-12-30 08:18:15 -0800 | [diff] [blame] | 67 | media_status_t AMediaExtractor_setDataSource(AMediaExtractor*, const char *location); | 
|  | 68 | // TODO support headers | 
| Marco Nelissen | 0c3be87 | 2014-05-01 10:14:44 -0700 | [diff] [blame] | 69 |  | 
|  | 70 | /** | 
|  | 71 | * Return the number of tracks in the previously specified media file | 
|  | 72 | */ | 
| Marco Nelissen | e419d7c | 2014-05-15 14:17:25 -0700 | [diff] [blame] | 73 | size_t AMediaExtractor_getTrackCount(AMediaExtractor*); | 
| Marco Nelissen | 0c3be87 | 2014-05-01 10:14:44 -0700 | [diff] [blame] | 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 | */ | 
| Marco Nelissen | e419d7c | 2014-05-15 14:17:25 -0700 | [diff] [blame] | 86 | media_status_t AMediaExtractor_selectTrack(AMediaExtractor*, size_t idx); | 
| Marco Nelissen | 0c3be87 | 2014-05-01 10:14:44 -0700 | [diff] [blame] | 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 | */ | 
| Marco Nelissen | e419d7c | 2014-05-15 14:17:25 -0700 | [diff] [blame] | 92 | media_status_t AMediaExtractor_unselectTrack(AMediaExtractor*, size_t idx); | 
| Marco Nelissen | 0c3be87 | 2014-05-01 10:14:44 -0700 | [diff] [blame] | 93 |  | 
|  | 94 | /** | 
|  | 95 | * Read the current sample. | 
|  | 96 | */ | 
| Marco Nelissen | e419d7c | 2014-05-15 14:17:25 -0700 | [diff] [blame] | 97 | ssize_t AMediaExtractor_readSampleData(AMediaExtractor*, uint8_t *buffer, size_t capacity); | 
| Marco Nelissen | 0c3be87 | 2014-05-01 10:14:44 -0700 | [diff] [blame] | 98 |  | 
|  | 99 | /** | 
|  | 100 | * Read the current sample's flags. | 
|  | 101 | */ | 
| Marco Nelissen | e419d7c | 2014-05-15 14:17:25 -0700 | [diff] [blame] | 102 | uint32_t AMediaExtractor_getSampleFlags(AMediaExtractor*); // see definitions below | 
| Marco Nelissen | 0c3be87 | 2014-05-01 10:14:44 -0700 | [diff] [blame] | 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 | */ | 
| Marco Nelissen | eb4860c | 2014-05-29 08:04:34 -0700 | [diff] [blame] | 114 | int64_t AMediaExtractor_getSampleTime(AMediaExtractor*); | 
| Marco Nelissen | 0c3be87 | 2014-05-01 10:14:44 -0700 | [diff] [blame] | 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 |  | 
| Marco Nelissen | 79e2b62 | 2014-05-16 08:07:28 -0700 | [diff] [blame] | 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); | 
| Marco Nelissen | 050eb32 | 2014-05-09 15:10:23 -0700 | [diff] [blame] | 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 |  | 
| Marco Nelissen | 0c3be87 | 2014-05-01 10:14:44 -0700 | [diff] [blame] | 159 | enum { | 
|  | 160 | AMEDIAEXTRACTOR_SAMPLE_FLAG_SYNC = 1, | 
|  | 161 | AMEDIAEXTRACTOR_SAMPLE_FLAG_ENCRYPTED = 2, | 
|  | 162 | }; | 
|  | 163 |  | 
| Dan Albert | 2975a24 | 2016-09-23 16:17:45 -0700 | [diff] [blame] | 164 | #endif /* __ANDROID_API__ >= 21 */ | 
|  | 165 |  | 
| Marco Nelissen | 0c3be87 | 2014-05-01 10:14:44 -0700 | [diff] [blame] | 166 | #ifdef __cplusplus | 
|  | 167 | } // extern "C" | 
|  | 168 | #endif | 
|  | 169 |  | 
|  | 170 | #endif // _NDK_MEDIA_EXTRACTOR_H |