MediaExtractor.java revision 8240d9239d9aabed75c49f9d4d69fd8a5fe4c899
1/* 2 * Copyright (C) 2012 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 17package android.media; 18 19import java.nio.ByteBuffer; 20import java.util.Map; 21 22/** 23 * MediaExtractor 24 * @hide 25*/ 26final public class MediaExtractor { 27 public MediaExtractor(String path) { 28 native_setup(path); 29 } 30 31 @Override 32 protected void finalize() { 33 native_finalize(); 34 } 35 36 // Make sure you call this when you're done to free up any resources 37 // instead of relying on the garbage collector to do this for you at 38 // some point in the future. 39 public native final void release(); 40 41 public native int countTracks(); 42 public native Map<String, Object> getTrackFormat(int index); 43 44 // Subsequent calls to "readSampleData", "getSampleTrackIndex" and 45 // "getSampleTime" only retrieve information for the subset of tracks 46 // selected by the call below. 47 // Selecting the same track multiple times has no effect, the track 48 // is only selected once. 49 public native void selectTrack(int index); 50 51 // All selected tracks seek near the requested time. The next sample 52 // returned for each selected track will be a sync sample. 53 public native void seekTo(long timeUs); 54 55 public native boolean advance(); 56 57 // Retrieve the current encoded sample and store it in the byte buffer 58 // starting at the given offset. Returns the sample size. 59 public native int readSampleData(ByteBuffer byteBuf, int offset); 60 61 // Returns the track index the current sample originates from. 62 public native int getSampleTrackIndex(); 63 64 // Returns the current sample's presentation time in microseconds. 65 public native long getSampleTime(); 66 67 // Keep these in sync with their equivalents in NuMediaExtractor.h 68 public static final int SAMPLE_FLAG_SYNC = 1; 69 public static final int SAMPLE_FLAG_ENCRYPTED = 2; 70 71 // Returns the current sample's flags. 72 public native int getSampleFlags(); 73 74 private static native final void native_init(); 75 private native final void native_setup(String path); 76 private native final void native_finalize(); 77 78 static { 79 System.loadLibrary("media_jni"); 80 native_init(); 81 } 82 83 private int mNativeContext; 84} 85