NdkMediaExtractor.h revision 0c3be875376adaee8d8e8dd917c64926e1513b29
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 33#include "NdkMediaFormat.h" 34 35#ifdef __cplusplus 36extern "C" { 37#endif 38 39struct AMediaExtractor; 40typedef struct AMediaExtractor AMediaExtractor; 41 42 43/** 44 * Create new media extractor 45 */ 46AMediaExtractor* AMediaExtractor_new(); 47 48/** 49 * Delete a previously created media extractor 50 */ 51int AMediaExtractor_delete(AMediaExtractor*); 52 53/** 54 * Set the file descriptor from which the extractor will read. 55 */ 56int AMediaExtractor_setDataSourceFd(AMediaExtractor*, int fd, off64_t offset, off64_t length); 57 58/** 59 * Set the URI from which the extractor will read. 60 */ 61int AMediaExtractor_setDataSource(AMediaExtractor*, const char *location); // TODO support headers 62 63/** 64 * Return the number of tracks in the previously specified media file 65 */ 66int AMediaExtractor_getTrackCount(AMediaExtractor*); 67 68/** 69 * Return the format of the specified track. The caller must free the returned format 70 */ 71AMediaFormat* AMediaExtractor_getTrackFormat(AMediaExtractor*, size_t idx); 72 73/** 74 * Select the specified track. Subsequent calls to readSampleData, getSampleTrackIndex and 75 * getSampleTime only retrieve information for the subset of tracks selected. 76 * Selecting the same track multiple times has no effect, the track is 77 * only selected once. 78 */ 79int AMediaExtractor_selectTrack(AMediaExtractor*, size_t idx); 80 81/** 82 * Unselect the specified track. Subsequent calls to readSampleData, getSampleTrackIndex and 83 * getSampleTime only retrieve information for the subset of tracks selected.. 84 */ 85int AMediaExtractor_unselectTrack(AMediaExtractor*, size_t idx); 86 87/** 88 * Read the current sample. 89 */ 90int AMediaExtractor_readSampleData(AMediaExtractor*, uint8_t *buffer, size_t capacity); 91 92/** 93 * Read the current sample's flags. 94 */ 95int AMediaExtractor_getSampleFlags(AMediaExtractor*); // see definitions below 96 97/** 98 * Returns the track index the current sample originates from (or -1 99 * if no more samples are available) 100 */ 101int AMediaExtractor_getSampleTrackIndex(AMediaExtractor*); 102 103/** 104 * Returns the current sample's presentation time in microseconds. 105 * or -1 if no more samples are available. 106 */ 107int64_t AMediaExtractor_getSampletime(AMediaExtractor*); 108 109/** 110 * Advance to the next sample. Returns false if no more sample data 111 * is available (end of stream). 112 */ 113bool AMediaExtractor_advance(AMediaExtractor*); 114 115enum { 116 AMEDIAEXTRACTOR_SAMPLE_FLAG_SYNC = 1, 117 AMEDIAEXTRACTOR_SAMPLE_FLAG_ENCRYPTED = 2, 118}; 119 120 121#ifdef __cplusplus 122} // extern "C" 123#endif 124 125#endif // _NDK_MEDIA_EXTRACTOR_H 126