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