am c52c957c: Merge "Various changes to Media* APIs requested by the api council." into jb-dev

* commit 'c52c957c450ded6ecf2444595ea6ddfc9546c786':
  Various changes to Media* APIs requested by the api council.
This commit is contained in:
Andreas Huber
2012-05-04 08:55:40 -07:00
committed by Android Git Automerger
12 changed files with 1097 additions and 344 deletions

View File

@@ -11021,7 +11021,7 @@ package android.media {
}
public final class MediaCodec {
method public void configure(java.util.Map<java.lang.String, java.lang.Object>, android.view.Surface, android.media.MediaCrypto, int);
method public void configure(android.media.MediaFormat, android.view.Surface, android.media.MediaCrypto, int);
method public static android.media.MediaCodec createByCodecName(java.lang.String);
method public static android.media.MediaCodec createDecoderByType(java.lang.String);
method public static android.media.MediaCodec createEncoderByType(java.lang.String);
@@ -11030,7 +11030,7 @@ package android.media {
method public final void flush();
method public java.nio.ByteBuffer[] getInputBuffers();
method public java.nio.ByteBuffer[] getOutputBuffers();
method public final java.util.Map<java.lang.String, java.lang.Object> getOutputFormat();
method public final android.media.MediaFormat getOutputFormat();
method public final void queueInputBuffer(int, int, int, long, int) throws android.media.MediaCodec.CryptoException;
method public final void queueSecureInputBuffer(int, int, android.media.MediaCodec.CryptoInfo, long, int) throws android.media.MediaCodec.CryptoException;
method public final void release();
@@ -11038,15 +11038,15 @@ package android.media {
method public final void setVideoScalingMode(int);
method public final void start();
method public final void stop();
field public static int CONFIGURE_FLAG_ENCODE;
field public static final int FLAG_CODECCONFIG = 2; // 0x2
field public static final int FLAG_EOS = 4; // 0x4
field public static final int FLAG_SYNCFRAME = 1; // 0x1
field public static final int BUFFER_FLAG_CODEC_CONFIG = 2; // 0x2
field public static final int BUFFER_FLAG_END_OF_STREAM = 4; // 0x4
field public static final int BUFFER_FLAG_SYNC_FRAME = 1; // 0x1
field public static final int CONFIGURE_FLAG_ENCODE = 1; // 0x1
field public static final int CRYPTO_MODE_AES_CTR = 1; // 0x1
field public static final int CRYPTO_MODE_UNENCRYPTED = 0; // 0x0
field public static final int INFO_OUTPUT_BUFFERS_CHANGED = -3; // 0xfffffffd
field public static final int INFO_OUTPUT_FORMAT_CHANGED = -2; // 0xfffffffe
field public static final int INFO_TRY_AGAIN_LATER = -1; // 0xffffffff
field public static final int MODE_AES_CTR = 1; // 0x1
field public static final int MODE_UNENCRYPTED = 0; // 0x0
field public static final int VIDEO_SCALING_MODE_SCALE_TO_FIT = 1; // 0x1
field public static final int VIDEO_SCALING_MODE_SCALE_TO_FIT_WITH_CROPPING = 2; // 0x2
}
@@ -11076,43 +11076,170 @@ package android.media {
field public int numSubSamples;
}
public final class MediaCodecList {
method public static final int countCodecs();
method public static final android.media.MediaCodecList.CodecCapabilities getCodecCapabilities(int, java.lang.String);
method public static final java.lang.String getCodecName(int);
method public static final java.lang.String[] getSupportedTypes(int);
method public static final boolean isEncoder(int);
public final class MediaCodecInfo {
method public final android.media.MediaCodecInfo.CodecCapabilities getCapabilitiesForType(java.lang.String);
method public final java.lang.String getName();
method public final java.lang.String[] getSupportedTypes();
method public final boolean isEncoder();
}
public static final class MediaCodecList.CodecCapabilities {
ctor public MediaCodecList.CodecCapabilities();
public static final class MediaCodecInfo.CodecCapabilities {
ctor public MediaCodecInfo.CodecCapabilities();
field public static final int COLOR_Format12bitRGB444 = 3; // 0x3
field public static final int COLOR_Format16bitARGB1555 = 5; // 0x5
field public static final int COLOR_Format16bitARGB4444 = 4; // 0x4
field public static final int COLOR_Format16bitBGR565 = 7; // 0x7
field public static final int COLOR_Format16bitRGB565 = 6; // 0x6
field public static final int COLOR_Format18BitBGR666 = 41; // 0x29
field public static final int COLOR_Format18bitARGB1665 = 9; // 0x9
field public static final int COLOR_Format18bitRGB666 = 8; // 0x8
field public static final int COLOR_Format19bitARGB1666 = 10; // 0xa
field public static final int COLOR_Format24BitABGR6666 = 43; // 0x2b
field public static final int COLOR_Format24BitARGB6666 = 42; // 0x2a
field public static final int COLOR_Format24bitARGB1887 = 13; // 0xd
field public static final int COLOR_Format24bitBGR888 = 12; // 0xc
field public static final int COLOR_Format24bitRGB888 = 11; // 0xb
field public static final int COLOR_Format25bitARGB1888 = 14; // 0xe
field public static final int COLOR_Format32bitARGB8888 = 16; // 0x10
field public static final int COLOR_Format32bitBGRA8888 = 15; // 0xf
field public static final int COLOR_Format8bitRGB332 = 2; // 0x2
field public static final int COLOR_FormatCbYCrY = 27; // 0x1b
field public static final int COLOR_FormatCrYCbY = 28; // 0x1c
field public static final int COLOR_FormatL16 = 36; // 0x24
field public static final int COLOR_FormatL2 = 33; // 0x21
field public static final int COLOR_FormatL24 = 37; // 0x25
field public static final int COLOR_FormatL32 = 38; // 0x26
field public static final int COLOR_FormatL4 = 34; // 0x22
field public static final int COLOR_FormatL8 = 35; // 0x23
field public static final int COLOR_FormatMonochrome = 1; // 0x1
field public static final int COLOR_FormatRawBayer10bit = 31; // 0x1f
field public static final int COLOR_FormatRawBayer8bit = 30; // 0x1e
field public static final int COLOR_FormatRawBayer8bitcompressed = 32; // 0x20
field public static final int COLOR_FormatYCbYCr = 25; // 0x19
field public static final int COLOR_FormatYCrYCb = 26; // 0x1a
field public static final int COLOR_FormatYUV411PackedPlanar = 18; // 0x12
field public static final int COLOR_FormatYUV411Planar = 17; // 0x11
field public static final int COLOR_FormatYUV420PackedPlanar = 20; // 0x14
field public static final int COLOR_FormatYUV420PackedSemiPlanar = 39; // 0x27
field public static final int COLOR_FormatYUV420Planar = 19; // 0x13
field public static final int COLOR_FormatYUV420SemiPlanar = 21; // 0x15
field public static final int COLOR_FormatYUV422PackedPlanar = 23; // 0x17
field public static final int COLOR_FormatYUV422PackedSemiPlanar = 40; // 0x28
field public static final int COLOR_FormatYUV422Planar = 22; // 0x16
field public static final int COLOR_FormatYUV422SemiPlanar = 24; // 0x18
field public static final int COLOR_FormatYUV444Interleaved = 29; // 0x1d
field public static final int COLOR_QCOM_FormatYUV420SemiPlanar = 2141391872; // 0x7fa30c00
field public static final int COLOR_TI_FormatYUV420PackedSemiPlanar = 2130706688; // 0x7f000100
field public int[] colorFormats;
field public android.media.MediaCodecList.CodecProfileLevel[] profileLevels;
field public android.media.MediaCodecInfo.CodecProfileLevel[] profileLevels;
}
public static final class MediaCodecList.CodecProfileLevel {
ctor public MediaCodecList.CodecProfileLevel();
public static final class MediaCodecInfo.CodecProfileLevel {
ctor public MediaCodecInfo.CodecProfileLevel();
field public static final int AACObjectELD = 39; // 0x27
field public static final int AACObjectERLC = 17; // 0x11
field public static final int AACObjectHE = 5; // 0x5
field public static final int AACObjectHE_PS = 29; // 0x1d
field public static final int AACObjectLC = 2; // 0x2
field public static final int AACObjectLD = 23; // 0x17
field public static final int AACObjectLTP = 4; // 0x4
field public static final int AACObjectMain = 1; // 0x1
field public static final int AACObjectSSR = 3; // 0x3
field public static final int AACObjectScalable = 6; // 0x6
field public static final int AVCLevel1 = 1; // 0x1
field public static final int AVCLevel11 = 4; // 0x4
field public static final int AVCLevel12 = 8; // 0x8
field public static final int AVCLevel13 = 16; // 0x10
field public static final int AVCLevel1b = 2; // 0x2
field public static final int AVCLevel2 = 32; // 0x20
field public static final int AVCLevel21 = 64; // 0x40
field public static final int AVCLevel22 = 128; // 0x80
field public static final int AVCLevel3 = 256; // 0x100
field public static final int AVCLevel31 = 512; // 0x200
field public static final int AVCLevel32 = 1024; // 0x400
field public static final int AVCLevel4 = 2048; // 0x800
field public static final int AVCLevel41 = 4096; // 0x1000
field public static final int AVCLevel42 = 8192; // 0x2000
field public static final int AVCLevel5 = 16384; // 0x4000
field public static final int AVCLevel51 = 32768; // 0x8000
field public static final int AVCProfileBaseline = 1; // 0x1
field public static final int AVCProfileExtended = 4; // 0x4
field public static final int AVCProfileHigh = 8; // 0x8
field public static final int AVCProfileHigh10 = 16; // 0x10
field public static final int AVCProfileHigh422 = 32; // 0x20
field public static final int AVCProfileHigh444 = 64; // 0x40
field public static final int AVCProfileMain = 2; // 0x2
field public static final int H263Level10 = 1; // 0x1
field public static final int H263Level20 = 2; // 0x2
field public static final int H263Level30 = 4; // 0x4
field public static final int H263Level40 = 8; // 0x8
field public static final int H263Level45 = 16; // 0x10
field public static final int H263Level50 = 32; // 0x20
field public static final int H263Level60 = 64; // 0x40
field public static final int H263Level70 = 128; // 0x80
field public static final int H263ProfileBackwardCompatible = 4; // 0x4
field public static final int H263ProfileBaseline = 1; // 0x1
field public static final int H263ProfileH320Coding = 2; // 0x2
field public static final int H263ProfileHighCompression = 32; // 0x20
field public static final int H263ProfileHighLatency = 256; // 0x100
field public static final int H263ProfileISWV2 = 8; // 0x8
field public static final int H263ProfileISWV3 = 16; // 0x10
field public static final int H263ProfileInterlace = 128; // 0x80
field public static final int H263ProfileInternet = 64; // 0x40
field public static final int MPEG4Level0 = 1; // 0x1
field public static final int MPEG4Level0b = 2; // 0x2
field public static final int MPEG4Level1 = 4; // 0x4
field public static final int MPEG4Level2 = 8; // 0x8
field public static final int MPEG4Level3 = 16; // 0x10
field public static final int MPEG4Level4 = 32; // 0x20
field public static final int MPEG4Level4a = 64; // 0x40
field public static final int MPEG4Level5 = 128; // 0x80
field public static final int MPEG4ProfileAdvancedCoding = 4096; // 0x1000
field public static final int MPEG4ProfileAdvancedCore = 8192; // 0x2000
field public static final int MPEG4ProfileAdvancedRealTime = 1024; // 0x400
field public static final int MPEG4ProfileAdvancedScalable = 16384; // 0x4000
field public static final int MPEG4ProfileAdvancedSimple = 32768; // 0x8000
field public static final int MPEG4ProfileBasicAnimated = 256; // 0x100
field public static final int MPEG4ProfileCore = 4; // 0x4
field public static final int MPEG4ProfileCoreScalable = 2048; // 0x800
field public static final int MPEG4ProfileHybrid = 512; // 0x200
field public static final int MPEG4ProfileMain = 8; // 0x8
field public static final int MPEG4ProfileNbit = 16; // 0x10
field public static final int MPEG4ProfileScalableTexture = 32; // 0x20
field public static final int MPEG4ProfileSimple = 1; // 0x1
field public static final int MPEG4ProfileSimpleFBA = 128; // 0x80
field public static final int MPEG4ProfileSimpleFace = 64; // 0x40
field public static final int MPEG4ProfileSimpleScalable = 2; // 0x2
field public int level;
field public int profile;
}
public final class MediaCodecList {
method public static final int getCodecCount();
method public static final android.media.MediaCodecInfo getCodecInfoAt(int);
}
public final class MediaCrypto {
ctor public MediaCrypto(byte[], byte[]) throws java.lang.RuntimeException;
method public static final boolean isCryptoSchemeSupported(byte[]);
ctor public MediaCrypto(java.util.UUID, byte[]) throws android.media.MediaCryptoException;
method public static final boolean isCryptoSchemeSupported(java.util.UUID);
method public final void release();
method public final boolean requiresSecureDecoderComponent(java.lang.String);
}
public final class MediaCryptoException extends java.lang.Exception {
ctor public MediaCryptoException(java.lang.String);
}
public final class MediaExtractor {
ctor public MediaExtractor();
method public boolean advance();
method public int countTracks();
method public long getCachedDuration();
method public boolean getSampleCryptoInfo(android.media.MediaCodec.CryptoInfo);
method public int getSampleFlags();
method public long getSampleTime();
method public int getSampleTrackIndex();
method public java.util.Map<java.lang.String, java.lang.Object> getTrackFormat(int);
method public final int getTrackCount();
method public android.media.MediaFormat getTrackFormat(int);
method public boolean hasCacheReachedEndOfStream();
method public int readSampleData(java.nio.ByteBuffer, int);
method public final void release();
@@ -11132,6 +11259,37 @@ package android.media {
field public static final int SEEK_TO_PREVIOUS_SYNC = 0; // 0x0
}
public final class MediaFormat {
ctor public MediaFormat();
method public final boolean containsKey(java.lang.String);
method public static final android.media.MediaFormat createAudioFormat(java.lang.String, int, int);
method public static final android.media.MediaFormat createVideoFormat(java.lang.String, int, int);
method public final java.nio.ByteBuffer getByteBuffer(java.lang.String);
method public final float getFloat(java.lang.String);
method public final int getInteger(java.lang.String);
method public final long getLong(java.lang.String);
method public final java.lang.String getString(java.lang.String);
method public final void setByteBuffer(java.lang.String, java.nio.ByteBuffer);
method public final void setFloat(java.lang.String, float);
method public final void setInteger(java.lang.String, int);
method public final void setLong(java.lang.String, long);
method public final void setString(java.lang.String, java.lang.String);
field public static final java.lang.String KEY_AAC_PROFILE = "aac-profile";
field public static final java.lang.String KEY_BIT_RATE = "bitrate";
field public static final java.lang.String KEY_CHANNEL_COUNT = "channel-count";
field public static final java.lang.String KEY_CHANNEL_MASK = "channel-mask";
field public static final java.lang.String KEY_COLOR_FORMAT = "color-format";
field public static final java.lang.String KEY_DURATION = "durationUs";
field public static final java.lang.String KEY_FRAME_RATE = "frame-rate";
field public static final java.lang.String KEY_HEIGHT = "height";
field public static final java.lang.String KEY_IS_ADTS = "is-adts";
field public static final java.lang.String KEY_I_FRAME_INTERVAL = "i-frame-interval";
field public static final java.lang.String KEY_MAX_INPUT_SIZE = "max-input-size";
field public static final java.lang.String KEY_MIME = "mime";
field public static final java.lang.String KEY_SAMPLE_RATE = "sample-rate";
field public static final java.lang.String KEY_WIDTH = "width";
}
public class MediaMetadataRetriever {
ctor public MediaMetadataRetriever();
method public java.lang.String extractMetadata(int);

View File

@@ -17,6 +17,7 @@
package android.media;
import android.media.MediaCrypto;
import android.media.MediaFormat;
import android.view.Surface;
import java.nio.ByteBuffer;
import java.util.Map;
@@ -90,14 +91,14 @@ import java.util.Map;
* Most formats also require the actual data to be prefixed by a number
* of buffers containing setup data, or codec specific data, i.e. the
* first few buffers submitted to the codec object after starting it must
* be codec specific data marked as such using the flag {@link #FLAG_CODECCONFIG}
* be codec specific data marked as such using the flag {@link #BUFFER_FLAG_CODEC_CONFIG}
* in a call to {@link #queueInputBuffer}.
*
* Once the client reaches the end of the input data it signals the end of
* the input stream by specifying a flag of {@link #FLAG_EOS} in the call to
* the input stream by specifying a flag of {@link #BUFFER_FLAG_END_OF_STREAM} in the call to
* {@link #queueInputBuffer}. The codec will continue to return output buffers
* until it eventually signals the end of the output stream by specifying
* the same flag ({@link #FLAG_EOS}) on the BufferInfo returned in
* the same flag ({@link #BUFFER_FLAG_END_OF_STREAM}) on the BufferInfo returned in
* {@link #dequeueOutputBuffer}.
*
* In order to start decoding data that's not adjacent to previously submitted
@@ -109,42 +110,12 @@ import java.util.Map;
* flush does not support format discontinuities,
* for this a full stop(), configure(), start() cycle is necessary.
*
* The format of the media data is specified as string/value pairs represented
* as a Map<String, Object>.<p>
*
* Fields common to all formats:
*
* <table>
* <tr><th>Name</th><th>Value Type</th><th>Description</th></tr>
* <tr><td>mime</td><td>String</td><td>The type of the format.</td></tr>
* <tr><td>max-input-size</td><td>Integer</td><td>optional, maximum size of a buffer of input data</td></tr>
* <tr><td>bitrate</td><td>Integer</td><td><b>encoder-only</b>, desired bitrate in bits/second</td></tr>
* </table>
*
* Video formats have the following fields:
* <table>
* <tr><th>Name</th><th>Value Type</th><th>Description</th></tr>
* <tr><td>width</td><td>Integer</td><td></td></tr>
* <tr><td>height</td><td>Integer</td><td></td></tr>
* <tr><td>color-format</td><td>Integer</td><td><b>encoder-only</b></td></tr>
* <tr><td>frame-rate</td><td>Integer or Float</td><td><b>encoder-only</b></td></tr>
* <tr><td>i-frame-interval</td><td>Integer</td><td><b>encoder-only</b></td></tr>
* <tr><td>stride</td><td>Integer</td><td><b>encoder-only</b>, optional, defaults to width</td></tr>
* <tr><td>slice-height</td><td>Integer</td><td><b>encoder-only</b>, optional, defaults to height</td></tr>
* </table>
*
* Audio formats have the following fields:
* <table>
* <tr><th>Name</th><th>Value Type</th><th>Description</th></tr>
* <tr><td>channel-count</td><td>Integer</td><td></td></tr>
* <tr><td>sample-rate</td><td>Integer</td><td></td></tr>
* </table>
*
*/
*/
final public class MediaCodec {
/** Per buffer metadata includes an offset and size specifying
the range of valid data in the associated codec buffer.
*/
/**
* Per buffer metadata includes an offset and size specifying
* the range of valid data in the associated codec buffer.
*/
public final static class BufferInfo {
public void set(
int newOffset, int newSize, long newTimeUs, int newFlags) {
@@ -163,45 +134,46 @@ final public class MediaCodec {
// The follow flag constants MUST stay in sync with their equivalents
// in MediaCodec.h !
/** This indicates that the buffer marked as such contains the data
for a sync frame.
*/
public static final int FLAG_SYNCFRAME = 1;
/**
* This indicates that the buffer marked as such contains the data
* for a sync frame.
*/
public static final int BUFFER_FLAG_SYNC_FRAME = 1;
/** This indicated that the buffer marked as such contains codec
initialization / codec specific data instead of media data.
*/
public static final int FLAG_CODECCONFIG = 2;
/**
* This indicated that the buffer marked as such contains codec
* initialization / codec specific data instead of media data.
*/
public static final int BUFFER_FLAG_CODEC_CONFIG = 2;
/** This signals the end of stream, i.e. no buffers will be available
after this, unless of course, {@link #flush} follows.
*/
public static final int FLAG_EOS = 4;
/**
* This signals the end of stream, i.e. no buffers will be available
* after this, unless of course, {@link #flush} follows.
*/
public static final int BUFFER_FLAG_END_OF_STREAM = 4;
// The following mode constants MUST stay in sync with their equivalents
// in media/hardware/CryptoAPI.h !
public static final int MODE_UNENCRYPTED = 0;
public static final int MODE_AES_CTR = 1;
/** Instantiate a decoder supporting input data of the given mime type.
* @param type The mime type of the input data.
*/
/**
* Instantiate a decoder supporting input data of the given mime type.
* @param type The mime type of the input data.
*/
public static MediaCodec createDecoderByType(String type) {
return new MediaCodec(type, true /* nameIsType */, false /* encoder */);
}
/** Instantiate an encoder supporting output data of the given mime type.
* @param type The desired mime type of the output data.
*/
/**
* Instantiate an encoder supporting output data of the given mime type.
* @param type The desired mime type of the output data.
*/
public static MediaCodec createEncoderByType(String type) {
return new MediaCodec(type, true /* nameIsType */, true /* encoder */);
}
/** If you know the exact name of the component you want to instantiate
use this method to instantiate it. Use with caution.
Likely to be used with information obtained from {@link android.media.MediaCodecList}
@param name The name of the codec to be instantiated.
*/
/**
* If you know the exact name of the component you want to instantiate
* use this method to instantiate it. Use with caution.
* Likely to be used with information obtained from {@link android.media.MediaCodecList}
* @param name The name of the codec to be instantiated.
*/
public static MediaCodec createByCodecName(String name) {
return new MediaCodec(
name, false /* nameIsType */, false /* unused */);
@@ -217,38 +189,44 @@ final public class MediaCodec {
native_finalize();
}
// Make sure you call this when you're done to free up any opened
// component instance instead of relying on the garbage collector
// to do this for you at some point in the future.
/**
* Make sure you call this when you're done to free up any opened
* component instance instead of relying on the garbage collector
* to do this for you at some point in the future.
*/
public native final void release();
/** If this codec is to be used as an encoder, pass this flag.
*/
public static int CONFIGURE_FLAG_ENCODE = 1;
/**
* If this codec is to be used as an encoder, pass this flag.
*/
public static final int CONFIGURE_FLAG_ENCODE = 1;
/** Configures a component.
/**
* Configures a component.
*
* @param format The format of the input data (decoder) or the desired
* format of the output data (encoder).
* @param surface Specify a surface on which to render the output of this
* decoder.
* @param crypto Specify a crypto object to facilitate secure decryption
* of the media data.
* @param flags Specify {@link #CONFIGURE_FLAG_ENCODE} to configure the
* component as an encoder.
*/
* @param format The format of the input data (decoder) or the desired
* format of the output data (encoder).
* @param surface Specify a surface on which to render the output of this
* decoder.
* @param crypto Specify a crypto object to facilitate secure decryption
* of the media data.
* @param flags Specify {@link #CONFIGURE_FLAG_ENCODE} to configure the
* component as an encoder.
*/
public void configure(
Map<String, Object> format,
MediaFormat format,
Surface surface, MediaCrypto crypto, int flags) {
Map<String, Object> formatMap = format.getMap();
String[] keys = null;
Object[] values = null;
if (format != null) {
keys = new String[format.size()];
values = new Object[format.size()];
keys = new String[formatMap.size()];
values = new Object[formatMap.size()];
int i = 0;
for (Map.Entry<String, Object> entry: format.entrySet()) {
for (Map.Entry<String, Object> entry: formatMap.entrySet()) {
keys[i] = entry.getKey();
values[i] = entry.getValue();
++i;
@@ -262,22 +240,25 @@ final public class MediaCodec {
String[] keys, Object[] values,
Surface surface, MediaCrypto crypto, int flags);
/** After successfully configuring the component, call start. On return
* you can query the component for its input/output buffers.
*/
/**
* After successfully configuring the component, call start. On return
* you can query the component for its input/output buffers.
*/
public native final void start();
/** Finish the decode/encode session, note that the codec instance
* remains active and ready to be {@link #start}ed again.
* To ensure that it is available to other client call {@link #release}
* and don't just rely on garbage collection to eventually do this for you.
*/
/**
* Finish the decode/encode session, note that the codec instance
* remains active and ready to be {@link #start}ed again.
* To ensure that it is available to other client call {@link #release}
* and don't just rely on garbage collection to eventually do this for you.
*/
public native final void stop();
/** Flush both input and output ports of the component, all indices
* previously returned in calls to {@link #dequeueInputBuffer} and
* {@link #dequeueOutputBuffer} become invalid.
*/
/**
* Flush both input and output ports of the component, all indices
* previously returned in calls to {@link #dequeueInputBuffer} and
* {@link #dequeueOutputBuffer} become invalid.
*/
public native final void flush();
public final static class CryptoException extends RuntimeException {
@@ -293,46 +274,55 @@ final public class MediaCodec {
private int mErrorCode;
}
/** After filling a range of the input buffer at the specified index
* submit it to the component.
/**
* After filling a range of the input buffer at the specified index
* submit it to the component.
*
* Many decoders require the actual compressed data stream to be
* preceded by "codec specific data", i.e. setup data used to initialize
* the codec such as PPS/SPS in the case of AVC video or code tables
* in the case of vorbis audio.
* The class {@link android.media.MediaExtractor} provides codec
* specific data as part of
* the returned track format in entries named "csd-0", "csd-1" ...
* Many decoders require the actual compressed data stream to be
* preceded by "codec specific data", i.e. setup data used to initialize
* the codec such as PPS/SPS in the case of AVC video or code tables
* in the case of vorbis audio.
* The class {@link android.media.MediaExtractor} provides codec
* specific data as part of
* the returned track format in entries named "csd-0", "csd-1" ...
*
* These buffers should be submitted using the flag {@link #FLAG_CODECCONFIG}.
* These buffers should be submitted using the flag {@link #BUFFER_FLAG_CODEC_CONFIG}.
*
* To indicate that this is the final piece of input data (or rather that
* no more input data follows unless the decoder is subsequently flushed)
* specify the flag {@link #FLAG_EOS}.
* To indicate that this is the final piece of input data (or rather that
* no more input data follows unless the decoder is subsequently flushed)
* specify the flag {@link #BUFFER_FLAG_END_OF_STREAM}.
*
* @param index The index of a client-owned input buffer previously returned
* in a call to {@link #dequeueInputBuffer}.
* @param offset The byte offset into the input buffer at which the data starts.
* @param size The number of bytes of valid input data.
* @param presentationTimeUs The time at which this buffer should be rendered.
* @param flags A bitmask of flags {@link #FLAG_SYNCFRAME},
* {@link #FLAG_CODECCONFIG} or {@link #FLAG_EOS}.
* @throws CryptoException if a crypto object has been specified in
* {@link #configure}
*/
* @param index The index of a client-owned input buffer previously returned
* in a call to {@link #dequeueInputBuffer}.
* @param offset The byte offset into the input buffer at which the data starts.
* @param size The number of bytes of valid input data.
* @param presentationTimeUs The time at which this buffer should be rendered.
* @param flags A bitmask of flags {@link #BUFFER_FLAG_SYNC_FRAME},
* {@link #BUFFER_FLAG_CODEC_CONFIG} or {@link #BUFFER_FLAG_END_OF_STREAM}.
* @throws CryptoException if a crypto object has been specified in
* {@link #configure}
*/
public native final void queueInputBuffer(
int index,
int offset, int size, long presentationTimeUs, int flags)
throws CryptoException;
/** Metadata describing the structure of a (at least partially) encrypted
* input sample.
* A buffer's data is considered to be partitioned into "subSamples",
* each subSample starts with a (potentially empty) run of plain,
* unencrypted bytes followed by a (also potentially empty) run of
* encrypted bytes.
* numBytesOfClearData can be null to indicate that all data is encrypted.
*/
// The following mode constants MUST stay in sync with their equivalents
// in media/hardware/CryptoAPI.h !
public static final int CRYPTO_MODE_UNENCRYPTED = 0;
public static final int CRYPTO_MODE_AES_CTR = 1;
/**
* Metadata describing the structure of a (at least partially) encrypted
* input sample.
* A buffer's data is considered to be partitioned into "subSamples",
* each subSample starts with a (potentially empty) run of plain,
* unencrypted bytes followed by a (also potentially empty) run of
* encrypted bytes.
* numBytesOfClearData can be null to indicate that all data is encrypted.
* This information encapsulates per-sample metadata as outlined in
* ISO/IEC FDIS 23001-7:2011 "Common encryption in ISO base media file format files".
*/
public final static class CryptoInfo {
public void set(
int newNumSubSamples,
@@ -349,28 +339,44 @@ final public class MediaCodec {
mode = newMode;
}
/** The number of subSamples that make up the buffer's contents. */
/**
* The number of subSamples that make up the buffer's contents.
*/
public int numSubSamples;
/** The number of leading unencrypted bytes in each subSample. */
/**
* The number of leading unencrypted bytes in each subSample.
*/
public int[] numBytesOfClearData;
/** The number of trailing encrypted bytes in each subSample. */
/**
* The number of trailing encrypted bytes in each subSample.
*/
public int[] numBytesOfEncryptedData;
/** A 16-byte opaque key */
/**
* A 16-byte opaque key
*/
public byte[] key;
/** A 16-byte initialization vector */
/**
* A 16-byte initialization vector
*/
public byte[] iv;
/** The type of encryption that has been applied */
/**
* The type of encryption that has been applied,
* see {@link #CRYPTO_MODE_UNENCRYPTED} and {@link #CRYPTO_MODE_AES_CTR}.
*/
public int mode;
};
/** Similar to {@link #queueInputBuffer} but submits a buffer that is
* potentially encrypted.
* @param index The index of a client-owned input buffer previously returned
* in a call to {@link #dequeueInputBuffer}.
* @param offset The byte offset into the input buffer at which the data starts.
* @param presentationTimeUs The time at which this buffer should be rendered.
* @param flags A bitmask of flags {@link #FLAG_SYNCFRAME},
* {@link #FLAG_CODECCONFIG} or {@link #FLAG_EOS}.
/**
* Similar to {@link #queueInputBuffer} but submits a buffer that is
* potentially encrypted.
* @param index The index of a client-owned input buffer previously returned
* in a call to {@link #dequeueInputBuffer}.
* @param offset The byte offset into the input buffer at which the data starts.
* @param info Metadata required to facilitate decryption, the object can be
* reused immediately after this call returns.
* @param presentationTimeUs The time at which this buffer should be rendered.
* @param flags A bitmask of flags {@link #BUFFER_FLAG_SYNC_FRAME},
* {@link #BUFFER_FLAG_CODEC_CONFIG} or {@link #BUFFER_FLAG_END_OF_STREAM}.
*/
public native final void queueSecureInputBuffer(
int index,
@@ -379,80 +385,97 @@ final public class MediaCodec {
long presentationTimeUs,
int flags) throws CryptoException;
/** Returns the index of an input buffer to be filled with valid data
* or -1 if no such buffer is currently available.
* This method will return immediately if timeoutUs == 0, wait indefinitely
* for the availability of an input buffer if timeoutUs &lt; 0 or wait up
* to "timeoutUs" microseconds if timeoutUs &gt; 0.
* @param timeoutUs The timeout in microseconds, a negative timeout indicates "infinite".
*/
/**
* Returns the index of an input buffer to be filled with valid data
* or -1 if no such buffer is currently available.
* This method will return immediately if timeoutUs == 0, wait indefinitely
* for the availability of an input buffer if timeoutUs &lt; 0 or wait up
* to "timeoutUs" microseconds if timeoutUs &gt; 0.
* @param timeoutUs The timeout in microseconds, a negative timeout indicates "infinite".
*/
public native final int dequeueInputBuffer(long timeoutUs);
/** If a non-negative timeout had been specified in the call
/**
* If a non-negative timeout had been specified in the call
* to {@link #dequeueOutputBuffer}, indicates that the call timed out.
*/
*/
public static final int INFO_TRY_AGAIN_LATER = -1;
/** The output format has changed, subsequent data will follow the new
* format. {@link #getOutputFormat} returns the new format.
*/
/**
* The output format has changed, subsequent data will follow the new
* format. {@link #getOutputFormat} returns the new format.
*/
public static final int INFO_OUTPUT_FORMAT_CHANGED = -2;
/** The output buffers have changed, the client must refer to the new
* set of output buffers returned by {@link #getOutputBuffers} from
* this point on.
*/
/**
* The output buffers have changed, the client must refer to the new
* set of output buffers returned by {@link #getOutputBuffers} from
* this point on.
*/
public static final int INFO_OUTPUT_BUFFERS_CHANGED = -3;
/** Dequeue an output buffer, block at most "timeoutUs" microseconds.
* Returns the index of an output buffer that has been successfully
* decoded or one of the INFO_* constants below.
* @param info Will be filled with buffer meta data.
* @param timeoutUs The timeout in microseconds, a negative timeout indicates "infinite".
*/
/**
* Dequeue an output buffer, block at most "timeoutUs" microseconds.
* Returns the index of an output buffer that has been successfully
* decoded or one of the INFO_* constants below.
* @param info Will be filled with buffer meta data.
* @param timeoutUs The timeout in microseconds, a negative timeout indicates "infinite".
*/
public native final int dequeueOutputBuffer(
BufferInfo info, long timeoutUs);
/** If you are done with a buffer, use this call to return the buffer to
* the codec. If you previously specified a surface when configuring this
* video decoder you can optionally render the buffer.
* @param index The index of a client-owned output buffer previously returned
* in a call to {@link #dequeueOutputBuffer}.
* @param render If a valid surface was specified when configuring the codec,
* passing true renders this output buffer to the surface.
*/
/**
* If you are done with a buffer, use this call to return the buffer to
* the codec. If you previously specified a surface when configuring this
* video decoder you can optionally render the buffer.
* @param index The index of a client-owned output buffer previously returned
* in a call to {@link #dequeueOutputBuffer}.
* @param render If a valid surface was specified when configuring the codec,
* passing true renders this output buffer to the surface.
*/
public native final void releaseOutputBuffer(int index, boolean render);
/** Call this after dequeueOutputBuffer signals a format change by returning
* {@link #INFO_OUTPUT_FORMAT_CHANGED}
/**
* Call this after dequeueOutputBuffer signals a format change by returning
* {@link #INFO_OUTPUT_FORMAT_CHANGED}
*/
public native final Map<String, Object> getOutputFormat();
public final MediaFormat getOutputFormat() {
return new MediaFormat(getOutputFormatNative());
}
/** Call this after start() returns.
private native final Map<String, Object> getOutputFormatNative();
/**
* Call this after start() returns.
*/
public ByteBuffer[] getInputBuffers() {
return getBuffers(true /* input */);
}
/** Call this after start() returns and whenever dequeueOutputBuffer
* signals an output buffer change by returning
* {@link #INFO_OUTPUT_BUFFERS_CHANGED}
/**
* Call this after start() returns and whenever dequeueOutputBuffer
* signals an output buffer change by returning
* {@link #INFO_OUTPUT_BUFFERS_CHANGED}
*/
public ByteBuffer[] getOutputBuffers() {
return getBuffers(false /* input */);
}
/** The content is scaled to the surface dimensions */
/**
* The content is scaled to the surface dimensions
*/
public static final int VIDEO_SCALING_MODE_SCALE_TO_FIT = 1;
/** The content is scaled, maintaining its aspect ratio, the whole
surface area is used, content may be cropped
*/
/**
* The content is scaled, maintaining its aspect ratio, the whole
* surface area is used, content may be cropped
*/
public static final int VIDEO_SCALING_MODE_SCALE_TO_FIT_WITH_CROPPING = 2;
/** If a surface has been specified in a previous call to {@link #configure}
specifies the scaling mode to use. The default is "scale to fit".
*/
/**
* If a surface has been specified in a previous call to {@link #configure}
* specifies the scaling mode to use. The default is "scale to fit".
*/
public native final void setVideoScalingMode(int mode);
private native final ByteBuffer[] getBuffers(boolean input);

View File

@@ -0,0 +1,213 @@
/*
* Copyright (C) 2012 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package android.media;
public final class MediaCodecInfo {
private int mIndex;
/* package private */ MediaCodecInfo(int index) {
mIndex = index;
}
/**
* Retrieve the codec name.
*/
public final String getName() {
return MediaCodecList.getCodecName(mIndex);
}
/**
* Query if the codec is an encoder.
*/
public final boolean isEncoder() {
return MediaCodecList.isEncoder(mIndex);
}
/**
* Query the media types supported by the codec.
*/
public final String[] getSupportedTypes() {
return MediaCodecList.getSupportedTypes(mIndex);
}
public static final class CodecCapabilities {
public CodecProfileLevel[] profileLevels;
// from OMX_COLOR_FORMATTYPE
public final static int COLOR_FormatMonochrome = 1;
public final static int COLOR_Format8bitRGB332 = 2;
public final static int COLOR_Format12bitRGB444 = 3;
public final static int COLOR_Format16bitARGB4444 = 4;
public final static int COLOR_Format16bitARGB1555 = 5;
public final static int COLOR_Format16bitRGB565 = 6;
public final static int COLOR_Format16bitBGR565 = 7;
public final static int COLOR_Format18bitRGB666 = 8;
public final static int COLOR_Format18bitARGB1665 = 9;
public final static int COLOR_Format19bitARGB1666 = 10;
public final static int COLOR_Format24bitRGB888 = 11;
public final static int COLOR_Format24bitBGR888 = 12;
public final static int COLOR_Format24bitARGB1887 = 13;
public final static int COLOR_Format25bitARGB1888 = 14;
public final static int COLOR_Format32bitBGRA8888 = 15;
public final static int COLOR_Format32bitARGB8888 = 16;
public final static int COLOR_FormatYUV411Planar = 17;
public final static int COLOR_FormatYUV411PackedPlanar = 18;
public final static int COLOR_FormatYUV420Planar = 19;
public final static int COLOR_FormatYUV420PackedPlanar = 20;
public final static int COLOR_FormatYUV420SemiPlanar = 21;
public final static int COLOR_FormatYUV422Planar = 22;
public final static int COLOR_FormatYUV422PackedPlanar = 23;
public final static int COLOR_FormatYUV422SemiPlanar = 24;
public final static int COLOR_FormatYCbYCr = 25;
public final static int COLOR_FormatYCrYCb = 26;
public final static int COLOR_FormatCbYCrY = 27;
public final static int COLOR_FormatCrYCbY = 28;
public final static int COLOR_FormatYUV444Interleaved = 29;
public final static int COLOR_FormatRawBayer8bit = 30;
public final static int COLOR_FormatRawBayer10bit = 31;
public final static int COLOR_FormatRawBayer8bitcompressed = 32;
public final static int COLOR_FormatL2 = 33;
public final static int COLOR_FormatL4 = 34;
public final static int COLOR_FormatL8 = 35;
public final static int COLOR_FormatL16 = 36;
public final static int COLOR_FormatL24 = 37;
public final static int COLOR_FormatL32 = 38;
public final static int COLOR_FormatYUV420PackedSemiPlanar = 39;
public final static int COLOR_FormatYUV422PackedSemiPlanar = 40;
public final static int COLOR_Format18BitBGR666 = 41;
public final static int COLOR_Format24BitARGB6666 = 42;
public final static int COLOR_Format24BitABGR6666 = 43;
public final static int COLOR_TI_FormatYUV420PackedSemiPlanar = 0x7f000100;
public final static int COLOR_QCOM_FormatYUV420SemiPlanar = 0x7fa30c00;
/**
* Defined in the OpenMAX IL specs, color format values are drawn from
* OMX_COLOR_FORMATTYPE.
*/
public int[] colorFormats;
};
public static final class CodecProfileLevel {
// from OMX_VIDEO_AVCPROFILETYPE
public static final int AVCProfileBaseline = 0x01;
public static final int AVCProfileMain = 0x02;
public static final int AVCProfileExtended = 0x04;
public static final int AVCProfileHigh = 0x08;
public static final int AVCProfileHigh10 = 0x10;
public static final int AVCProfileHigh422 = 0x20;
public static final int AVCProfileHigh444 = 0x40;
// from OMX_VIDEO_AVCLEVELTYPE
public static final int AVCLevel1 = 0x01;
public static final int AVCLevel1b = 0x02;
public static final int AVCLevel11 = 0x04;
public static final int AVCLevel12 = 0x08;
public static final int AVCLevel13 = 0x10;
public static final int AVCLevel2 = 0x20;
public static final int AVCLevel21 = 0x40;
public static final int AVCLevel22 = 0x80;
public static final int AVCLevel3 = 0x100;
public static final int AVCLevel31 = 0x200;
public static final int AVCLevel32 = 0x400;
public static final int AVCLevel4 = 0x800;
public static final int AVCLevel41 = 0x1000;
public static final int AVCLevel42 = 0x2000;
public static final int AVCLevel5 = 0x4000;
public static final int AVCLevel51 = 0x8000;
// from OMX_VIDEO_H263PROFILETYPE
public static final int H263ProfileBaseline = 0x01;
public static final int H263ProfileH320Coding = 0x02;
public static final int H263ProfileBackwardCompatible = 0x04;
public static final int H263ProfileISWV2 = 0x08;
public static final int H263ProfileISWV3 = 0x10;
public static final int H263ProfileHighCompression = 0x20;
public static final int H263ProfileInternet = 0x40;
public static final int H263ProfileInterlace = 0x80;
public static final int H263ProfileHighLatency = 0x100;
// from OMX_VIDEO_H263LEVELTYPE
public static final int H263Level10 = 0x01;
public static final int H263Level20 = 0x02;
public static final int H263Level30 = 0x04;
public static final int H263Level40 = 0x08;
public static final int H263Level45 = 0x10;
public static final int H263Level50 = 0x20;
public static final int H263Level60 = 0x40;
public static final int H263Level70 = 0x80;
// from OMX_VIDEO_MPEG4PROFILETYPE
public static final int MPEG4ProfileSimple = 0x01;
public static final int MPEG4ProfileSimpleScalable = 0x02;
public static final int MPEG4ProfileCore = 0x04;
public static final int MPEG4ProfileMain = 0x08;
public static final int MPEG4ProfileNbit = 0x10;
public static final int MPEG4ProfileScalableTexture = 0x20;
public static final int MPEG4ProfileSimpleFace = 0x40;
public static final int MPEG4ProfileSimpleFBA = 0x80;
public static final int MPEG4ProfileBasicAnimated = 0x100;
public static final int MPEG4ProfileHybrid = 0x200;
public static final int MPEG4ProfileAdvancedRealTime = 0x400;
public static final int MPEG4ProfileCoreScalable = 0x800;
public static final int MPEG4ProfileAdvancedCoding = 0x1000;
public static final int MPEG4ProfileAdvancedCore = 0x2000;
public static final int MPEG4ProfileAdvancedScalable = 0x4000;
public static final int MPEG4ProfileAdvancedSimple = 0x8000;
// from OMX_VIDEO_MPEG4LEVELTYPE
public static final int MPEG4Level0 = 0x01;
public static final int MPEG4Level0b = 0x02;
public static final int MPEG4Level1 = 0x04;
public static final int MPEG4Level2 = 0x08;
public static final int MPEG4Level3 = 0x10;
public static final int MPEG4Level4 = 0x20;
public static final int MPEG4Level4a = 0x40;
public static final int MPEG4Level5 = 0x80;
// from OMX_AUDIO_AACPROFILETYPE
public static final int AACObjectMain = 1;
public static final int AACObjectLC = 2;
public static final int AACObjectSSR = 3;
public static final int AACObjectLTP = 4;
public static final int AACObjectHE = 5;
public static final int AACObjectScalable = 6;
public static final int AACObjectERLC = 17;
public static final int AACObjectLD = 23;
public static final int AACObjectHE_PS = 29;
public static final int AACObjectELD = 39;
/**
* Defined in the OpenMAX IL specs, depending on the type of media
* this can be OMX_VIDEO_AVCPROFILETYPE, OMX_VIDEO_H263PROFILETYPE,
* or OMX_VIDEO_MPEG4PROFILETYPE.
*/
public int profile;
/**
* Defined in the OpenMAX IL specs, depending on the type of media
* this can be OMX_VIDEO_AVCLEVELTYPE, OMX_VIDEO_H263LEVELTYPE
* or OMX_VIDEO_MPEG4LEVELTYPE.
*/
public int level;
};
public final CodecCapabilities getCapabilitiesForType(
String type) {
return MediaCodecList.getCodecCapabilities(mIndex, type);
}
}

View File

@@ -16,49 +16,35 @@
package android.media;
import android.media.MediaCodecInfo;
/**
* MediaCodecList class can be used to enumerate available codecs,
* find a codec supporting a given format and query the capabilities
* of a given codec.
*/
*/
final public class MediaCodecList {
/** Count the number of available codecs.
*/
public static native final int countCodecs();
/**
* Count the number of available codecs.
*/
public static native final int getCodecCount();
/** Retrieve the codec name at the specified index. */
public static native final String getCodecName(int index);
public static final MediaCodecInfo getCodecInfoAt(int index) {
if (index < 0 || index > getCodecCount()) {
throw new IllegalArgumentException();
}
/** Query if the codec at the specified index is an encoder. */
public static native final boolean isEncoder(int index);
return new MediaCodecInfo(index);
}
/** Query the media types supported by the codec at the specified index */
public static native final String[] getSupportedTypes(int index);
/* package private */ static native final String getCodecName(int index);
public static final class CodecProfileLevel {
/** Defined in the OpenMAX IL specs, depending on the type of media
* this can be OMX_VIDEO_AVCPROFILETYPE, OMX_VIDEO_H263PROFILETYPE
* or OMX_VIDEO_MPEG4PROFILETYPE.
*/
public int profile;
/* package private */ static native final boolean isEncoder(int index);
/** Defined in the OpenMAX IL specs, depending on the type of media
* this can be OMX_VIDEO_AVCLEVELTYPE, OMX_VIDEO_H263LEVELTYPE
* or OMX_VIDEO_MPEG4LEVELTYPE.
*/
public int level;
};
/* package private */ static native final String[] getSupportedTypes(int index);
public static final class CodecCapabilities {
public CodecProfileLevel[] profileLevels;
/** Defined in the OpenMAX IL specs, color format values are drawn from
* OMX_COLOR_FORMATTYPE.
*/
public int[] colorFormats;
};
public static native final CodecCapabilities getCodecCapabilities(
int index, String type);
/* package private */ static native final MediaCodecInfo.CodecCapabilities
getCodecCapabilities(int index, String type);
private static native final void native_init();

View File

@@ -16,6 +16,9 @@
package android.media;
import android.media.MediaCryptoException;
import java.util.UUID;
/**
* MediaCrypto class can be used in conjunction with {@link android.media.MediaCodec}
* to decode encrypted media data.
@@ -24,27 +27,47 @@ package android.media;
* the method {@link #isCryptoSchemeSupported} can be used to query if a given
* scheme is supported on the device.
*
*/
*/
public final class MediaCrypto {
/** Query if the given scheme identified by its UUID is supported on
* this device.
* @param uuid The UUID of the crypto scheme.
*/
public static final native boolean isCryptoSchemeSupported(byte[] uuid);
/** Instantiate a MediaCrypto object using opaque, crypto scheme specific
* data.
* @param uuid The UUID of the crypto scheme.
* @param initData Opaque initialization data specific to the crypto scheme.
*/
public MediaCrypto(byte[] uuid, byte[] initData) throws RuntimeException {
native_setup(uuid, initData);
/**
* Query if the given scheme identified by its UUID is supported on
* this device.
* @param uuid The UUID of the crypto scheme.
*/
public static final boolean isCryptoSchemeSupported(UUID uuid) {
return isCryptoSchemeSupportedNative(getByteArrayFromUUID(uuid));
}
/** Query if the crypto scheme requires the use of a secure decoder
* to decode data of the given mime type.
* @param mime The mime type of the media data
*/
private static final byte[] getByteArrayFromUUID(UUID uuid) {
long msb = uuid.getMostSignificantBits();
long lsb = uuid.getLeastSignificantBits();
byte[] uuidBytes = new byte[16];
for (int i = 0; i < 8; ++i) {
uuidBytes[i] = (byte)(msb >>> (8 * (7 - i)));
uuidBytes[8 + i] = (byte)(lsb >>> (8 * (7 - i)));
}
return uuidBytes;
}
private static final native boolean isCryptoSchemeSupportedNative(byte[] uuid);
/**
* Instantiate a MediaCrypto object using opaque, crypto scheme specific
* data.
* @param uuid The UUID of the crypto scheme.
* @param initData Opaque initialization data specific to the crypto scheme.
*/
public MediaCrypto(UUID uuid, byte[] initData) throws MediaCryptoException {
native_setup(getByteArrayFromUUID(uuid), initData);
}
/**
* Query if the crypto scheme requires the use of a secure decoder
* to decode data of the given mime type.
* @param mime The mime type of the media data
*/
public final native boolean requiresSecureDecoderComponent(String mime);
@Override
@@ -54,7 +77,10 @@ public final class MediaCrypto {
public native final void release();
private static native final void native_init();
private native final void native_setup(byte[] uuid, byte[] initData);
private native final void native_setup(byte[] uuid, byte[] initData)
throws MediaCryptoException;
private native final void native_finalize();
static {

View File

@@ -0,0 +1,27 @@
/*
* Copyright (C) 2012 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package android.media;
/**
* Exception thrown if MediaCrypto object could not be instantiated for
* whatever reason.
*/
public final class MediaCryptoException extends Exception {
public MediaCryptoException(String detailMessage) {
super(detailMessage);
}
}

View File

@@ -20,6 +20,7 @@ import android.content.ContentResolver;
import android.content.Context;
import android.content.res.AssetFileDescriptor;
import android.media.MediaCodec;
import android.media.MediaFormat;
import android.net.Uri;
import java.io.FileDescriptor;
import java.io.IOException;
@@ -33,7 +34,7 @@ import java.util.Map;
* <pre>
* MediaExtractor extractor = new MediaExtractor();
* extractor.setDataSource(...);
* int numTracks = extractor.countTracks();
* int numTracks = extractor.getTrackCount();
* for (int i = 0; i &lt; numTracks; ++i) {
* Map%lt;String, Object&gt; format = extractor.getTrackFormat(i);
* String mime = (String)format.get("mime");
@@ -52,7 +53,7 @@ import java.util.Map;
* extractor.release();
* extractor = null;
* </pre>
*/
*/
final public class MediaExtractor {
public MediaExtractor() {
native_setup();
@@ -174,105 +175,134 @@ final public class MediaExtractor {
native_finalize();
}
/** Make sure you call this when you're done to free up any resources
* instead of relying on the garbage collector to do this for you at
* some point in the future.
*/
/**
* Make sure you call this when you're done to free up any resources
* instead of relying on the garbage collector to do this for you at
* some point in the future.
*/
public native final void release();
/** Count the number of tracks found in the data source.
/**
* Count the number of tracks found in the data source.
*/
public native int countTracks();
public native final int getTrackCount();
/** Get the track format at the specified index.
* More detail on the representation can be found at {@link android.media.MediaCodec}
*/
public native Map<String, Object> getTrackFormat(int index);
/**
* Get the track format at the specified index.
* More detail on the representation can be found at {@link android.media.MediaCodec}
*/
public MediaFormat getTrackFormat(int index) {
return new MediaFormat(getTrackFormatNative(index));
}
/** Subsequent calls to {@link #readSampleData}, {@link #getSampleTrackIndex} and
* {@link #getSampleTime} only retrieve information for the subset of tracks
* selected.
* Selecting the same track multiple times has no effect, the track is
* only selected once.
*/
private native Map<String, Object> getTrackFormatNative(int index);
/**
* Subsequent calls to {@link #readSampleData}, {@link #getSampleTrackIndex} and
* {@link #getSampleTime} only retrieve information for the subset of tracks
* selected.
* Selecting the same track multiple times has no effect, the track is
* only selected once.
*/
public native void selectTrack(int index);
/** Subsequent calls to {@link #readSampleData}, {@link #getSampleTrackIndex} and
* {@link #getSampleTime} only retrieve information for the subset of tracks
* selected.
*/
/**
* Subsequent calls to {@link #readSampleData}, {@link #getSampleTrackIndex} and
* {@link #getSampleTime} only retrieve information for the subset of tracks
* selected.
*/
public native void unselectTrack(int index);
/** If possible, seek to a sync sample at or before the specified time */
/**
* If possible, seek to a sync sample at or before the specified time
*/
public static final int SEEK_TO_PREVIOUS_SYNC = 0;
/** If possible, seek to a sync sample at or after the specified time */
/**
* If possible, seek to a sync sample at or after the specified time
*/
public static final int SEEK_TO_NEXT_SYNC = 1;
/** If possible, seek to the sync sample closest to the specified time */
/**
* If possible, seek to the sync sample closest to the specified time
*/
public static final int SEEK_TO_CLOSEST_SYNC = 2;
/** If possible, seek to a sample closest to the specified time, which may
* NOT be a sync sample!
*/
/**
* If possible, seek to a sample closest to the specified time, which may
* NOT be a sync sample!
*/
public static final int SEEK_TO_CLOSEST = 3;
/** All selected tracks seek near the requested time according to the
* specified mode.
*/
/**
* All selected tracks seek near the requested time according to the
* specified mode.
*/
public native void seekTo(long timeUs, int mode);
/** Advance to the next sample. Returns false if no more sample data
* is available (end of stream).
/**
* Advance to the next sample. Returns false if no more sample data
* is available (end of stream).
*/
public native boolean advance();
/** Retrieve the current encoded sample and store it in the byte buffer
* starting at the given offset. Returns the sample size (or -1 if
* no more samples are available).
*/
/**
* Retrieve the current encoded sample and store it in the byte buffer
* starting at the given offset. Returns the sample size (or -1 if
* no more samples are available).
*/
public native int readSampleData(ByteBuffer byteBuf, int offset);
/** Returns the track index the current sample originates from (or -1
* if no more samples are available)
*/
/**
* Returns the track index the current sample originates from (or -1
* if no more samples are available)
*/
public native int getSampleTrackIndex();
/** Returns the current sample's presentation time in microseconds.
* or -1 if no more samples are available.
*/
/**
* Returns the current sample's presentation time in microseconds.
* or -1 if no more samples are available.
*/
public native long getSampleTime();
// Keep these in sync with their equivalents in NuMediaExtractor.h
/** The sample is a sync sample */
/**
* The sample is a sync sample
*/
public static final int SAMPLE_FLAG_SYNC = 1;
/** The sample is (at least partially) encrypted, see also the documentation
* for {@link android.media.MediaCodec#queueSecureInputBuffer}
*/
/**
* The sample is (at least partially) encrypted, see also the documentation
* for {@link android.media.MediaCodec#queueSecureInputBuffer}
*/
public static final int SAMPLE_FLAG_ENCRYPTED = 2;
/** Returns the current sample's flags. */
/**
* Returns the current sample's flags.
*/
public native int getSampleFlags();
/** If the sample flags indicate that the current sample is at least
* partially encrypted, this call returns relevant information about
* the structure of the sample data required for decryption.
* @param info The android.media.MediaCodec.CryptoInfo structure
* to be filled in.
* @return true iff the sample flags contain {@link #SAMPLE_FLAG_ENCRYPTED}
*/
/**
* If the sample flags indicate that the current sample is at least
* partially encrypted, this call returns relevant information about
* the structure of the sample data required for decryption.
* @param info The android.media.MediaCodec.CryptoInfo structure
* to be filled in.
* @return true iff the sample flags contain {@link #SAMPLE_FLAG_ENCRYPTED}
*/
public native boolean getSampleCryptoInfo(MediaCodec.CryptoInfo info);
/** Returns an estimate of how much data is presently cached in memory
expressed in microseconds. Returns -1 if that information is unavailable
or not applicable (no cache).
/**
* Returns an estimate of how much data is presently cached in memory
* expressed in microseconds. Returns -1 if that information is unavailable
* or not applicable (no cache).
*/
public native long getCachedDuration();
/** Returns true iff we are caching data and the cache has reached the
* end of the data stream (for now, a future seek may of course restart
* the fetching of data).
* This API only returns a meaningful result if {link #getCachedDuration}
* indicates the presence of a cache, i.e. does NOT return -1.
*/
/**
* Returns true iff we are caching data and the cache has reached the
* end of the data stream (for now, a future seek may of course restart
* the fetching of data).
* This API only returns a meaningful result if {link #getCachedDuration}
* indicates the presence of a cache, i.e. does NOT return -1.
*/
public native boolean hasCacheReachedEndOfStream();
private static native final void native_init();

View File

@@ -0,0 +1,290 @@
/*
* Copyright (C) 2012 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package android.media;
import java.nio.ByteBuffer;
import java.util.HashMap;
import java.util.Map;
/**
* Encapsulates the information describing the format of media data,
* be it audio or video.
*
* The format of the media data is specified as string/value pairs.
*
* Keys common to all formats:
*
* <table>
* <tr><th>Name</th><th>Value Type</th><th>Description</th></tr>
* <tr><td>{@link #KEY_MIME}</td><td>String</td><td>The type of the format.</td></tr>
* <tr><td>{@link #KEY_MAX_INPUT_SIZE}</td><td>Integer</td><td>optional, maximum size of a buffer of input data</td></tr>
* <tr><td>{@link #KEY_BIT_RATE}</td><td>Integer</td><td><b>encoder-only</b>, desired bitrate in bits/second</td></tr>
* </table>
*
* Video formats have the following keys:
* <table>
* <tr><th>Name</th><th>Value Type</th><th>Description</th></tr>
* <tr><td>{@link #KEY_WIDTH}</td><td>Integer</td><td></td></tr>
* <tr><td>{@link #KEY_HEIGHT}</td><td>Integer</td><td></td></tr>
* <tr><td>{@link #KEY_COLOR_FORMAT}</td><td>Integer</td><td><b>encoder-only</b></td></tr>
* <tr><td>{@link #KEY_FRAME_RATE}</td><td>Integer or Float</td><td><b>encoder-only</b></td></tr>
* <tr><td>{@link #KEY_I_FRAME_INTERVAL}</td><td>Integer</td><td><b>encoder-only</b></td></tr>
* </table>
*
* Audio formats have the following keys:
* <table>
* <tr><th>Name</th><th>Value Type</th><th>Description</th></tr>
* <tr><td>{@link #KEY_CHANNEL_COUNT}</td><td>Integer</td><td></td></tr>
* <tr><td>{@link #KEY_SAMPLE_RATE}</td><td>Integer</td><td></td></tr>
* <tr><td>{@link #KEY_IS_ADTS}</td><td>Integer</td><td>optional, if content is AAC audio, setting this key to 1 indicates that each audio frame is prefixed by the ADTS header.</td></tr>
* <tr><td>{@link #KEY_AAC_PROFILE}</td><td>Integer</td><td><b>encoder-only</b>, optional, if content is AAC audio, specifies the desired profile.</td></tr>
* <tr><td>{@link #KEY_CHANNEL_MASK}</td><td>Integer</td><td>A mask of audio channel assignments</td></tr>
* </table>
*
*/
public final class MediaFormat {
private Map<String, Object> mMap;
/**
* A key describing the mime type of the MediaFormat.
* The associated value is a string.
*/
public static final String KEY_MIME = "mime";
/**
* A key describing the sample rate of an audio format.
* The associated value is an integer
*/
public static final String KEY_SAMPLE_RATE = "sample-rate";
/**
* A key describing the number of channels in an audio format.
* The associated value is an integer
*/
public static final String KEY_CHANNEL_COUNT = "channel-count";
/**
* A key describing the width of the content in a video format.
* The associated value is an integer
*/
public static final String KEY_WIDTH = "width";
/**
* A key describing the height of the content in a video format.
* The associated value is an integer
*/
public static final String KEY_HEIGHT = "height";
/** A key describing the maximum size in bytes of a buffer of data
* described by this MediaFormat.
* The associated value is an integer
*/
public static final String KEY_MAX_INPUT_SIZE = "max-input-size";
/**
* A key describing the bitrate in bits/sec.
* The associated value is an integer
*/
public static final String KEY_BIT_RATE = "bitrate";
/**
* A key describing the color format of the content in a video format.
* Constants are declared in {@link android.media.MediaCodecInfo.CodecCapabilities}.
*/
public static final String KEY_COLOR_FORMAT = "color-format";
/**
* A key describing the frame rate of a video format in frames/sec.
* The associated value is an integer or a float.
*/
public static final String KEY_FRAME_RATE = "frame-rate";
/**
* A key describing the frequency of I frames expressed in secs
* between I frames.
* The associated value is an integer.
*/
public static final String KEY_I_FRAME_INTERVAL = "i-frame-interval";
/**
* @hide
*/
public static final String KEY_STRIDE = "stride";
/**
* @hide
*/
public static final String KEY_SLICE_HEIGHT = "slice-height";
/**
* A key describing the duration (in microseconds) of the content.
* The associated value is a long.
*/
public static final String KEY_DURATION = "durationUs";
/**
* A key mapping to a value of 1 if the content is AAC audio and
* audio frames are prefixed with an ADTS header.
* The associated value is an integer (0 or 1).
*/
public static final String KEY_IS_ADTS = "is-adts";
/**
* A key describing the channel composition of audio content. This mask
* is composed of bits drawn from channel mask definitions in {@link android.media.AudioFormat}.
* The associated value is an integer.
*/
public static final String KEY_CHANNEL_MASK = "channel-mask";
/**
* A key describing the AAC profile to be used (AAC audio formats only).
* Constants are declared in {@link android.media.MediaCodecInfo.CodecCapabilities}.
*/
public static final String KEY_AAC_PROFILE = "aac-profile";
/* package private */ MediaFormat(Map<String, Object> map) {
mMap = map;
}
/**
* Creates an empty MediaFormat
*/
public MediaFormat() {
mMap = new HashMap();
}
/* package private */ Map<String, Object> getMap() {
return mMap;
}
/**
* Returns true iff a key of the given name exists in the format.
*/
public final boolean containsKey(String name) {
return mMap.containsKey(name);
}
/**
* Returns the value of an integer key.
*/
public final int getInteger(String name) {
return ((Integer)mMap.get(name)).intValue();
}
/**
* Returns the value of a long key.
*/
public final long getLong(String name) {
return ((Long)mMap.get(name)).longValue();
}
/**
* Returns the value of a float key.
*/
public final float getFloat(String name) {
return ((Float)mMap.get(name)).floatValue();
}
/**
* Returns the value of a string key.
*/
public final String getString(String name) {
return (String)mMap.get(name);
}
/**
* Returns the value of a ByteBuffer key.
*/
public final ByteBuffer getByteBuffer(String name) {
return (ByteBuffer)mMap.get(name);
}
/**
* Sets the value of an integer key.
*/
public final void setInteger(String name, int value) {
mMap.put(name, new Integer(value));
}
/**
* Sets the value of a long key.
*/
public final void setLong(String name, long value) {
mMap.put(name, new Long(value));
}
/**
* Sets the value of a float key.
*/
public final void setFloat(String name, float value) {
mMap.put(name, new Float(value));
}
/**
* Sets the value of a string key.
*/
public final void setString(String name, String value) {
mMap.put(name, value);
}
/**
* Sets the value of a ByteBuffer key.
*/
public final void setByteBuffer(String name, ByteBuffer bytes) {
mMap.put(name, bytes);
}
/**
* Creates a minimal audio format.
* @param mime The mime type of the content.
* @param sampleRate The sampling rate of the content.
* @param channelCount The number of audio channels in the content.
*/
public static final MediaFormat createAudioFormat(
String mime,
int sampleRate,
int channelCount) {
MediaFormat format = new MediaFormat();
format.setString(KEY_MIME, mime);
format.setInteger(KEY_SAMPLE_RATE, sampleRate);
format.setInteger(KEY_CHANNEL_COUNT, channelCount);
return format;
}
/**
* Creates a minimal video format.
* @param mime The mime type of the content.
* @param width The width of the content (in pixels)
* @param height The height of the content (in pixels)
*/
public static final MediaFormat createVideoFormat(
String mime,
int width,
int height) {
MediaFormat format = new MediaFormat();
format.setString(KEY_MIME, mime);
format.setInteger(KEY_WIDTH, width);
format.setInteger(KEY_HEIGHT, height);
return format;
}
@Override
public String toString() {
return mMap.toString();
}
}

View File

@@ -630,9 +630,9 @@ static void android_media_MediaCodec_releaseOutputBuffer(
throwExceptionAsNecessary(env, err);
}
static jobject android_media_MediaCodec_getOutputFormat(
static jobject android_media_MediaCodec_getOutputFormatNative(
JNIEnv *env, jobject thiz) {
ALOGV("android_media_MediaCodec_getOutputFormat");
ALOGV("android_media_MediaCodec_getOutputFormatNative");
sp<JMediaCodec> codec = getMediaCodec(env, thiz);
@@ -790,8 +790,8 @@ static JNINativeMethod gMethods[] = {
{ "releaseOutputBuffer", "(IZ)V",
(void *)android_media_MediaCodec_releaseOutputBuffer },
{ "getOutputFormat", "()Ljava/util/Map;",
(void *)android_media_MediaCodec_getOutputFormat },
{ "getOutputFormatNative", "()Ljava/util/Map;",
(void *)android_media_MediaCodec_getOutputFormatNative },
{ "getBuffers", "(Z)[Ljava/nio/ByteBuffer;",
(void *)android_media_MediaCodec_getBuffers },

View File

@@ -27,7 +27,7 @@
using namespace android;
static jint android_media_MediaCodecList_countCodecs(
static jint android_media_MediaCodecList_getCodecCount(
JNIEnv *env, jobject thiz) {
return MediaCodecList::getInstance()->countCodecs();
}
@@ -105,13 +105,13 @@ static jobject android_media_MediaCodecList_getCodecCapabilities(
}
jclass capsClazz =
env->FindClass("android/media/MediaCodecList$CodecCapabilities");
env->FindClass("android/media/MediaCodecInfo$CodecCapabilities");
CHECK(capsClazz != NULL);
jobject caps = env->AllocObject(capsClazz);
jclass profileLevelClazz =
env->FindClass("android/media/MediaCodecList$CodecProfileLevel");
env->FindClass("android/media/MediaCodecInfo$CodecProfileLevel");
CHECK(profileLevelClazz != NULL);
jobjectArray profileLevelArray =
@@ -140,7 +140,7 @@ static jobject android_media_MediaCodecList_getCodecCapabilities(
jfieldID profileLevelsField = env->GetFieldID(
capsClazz,
"profileLevels",
"[Landroid/media/MediaCodecList$CodecProfileLevel;");
"[Landroid/media/MediaCodecInfo$CodecProfileLevel;");
env->SetObjectField(caps, profileLevelsField, profileLevelArray);
@@ -169,7 +169,7 @@ static void android_media_MediaCodecList_native_init(JNIEnv *env) {
}
static JNINativeMethod gMethods[] = {
{ "countCodecs", "()I", (void *)android_media_MediaCodecList_countCodecs },
{ "getCodecCount", "()I", (void *)android_media_MediaCodecList_getCodecCount },
{ "getCodecName", "(I)Ljava/lang/String;",
(void *)android_media_MediaCodecList_getCodecName },
{ "isEncoder", "(I)Z", (void *)android_media_MediaCodecList_isEncoder },
@@ -177,7 +177,7 @@ static JNINativeMethod gMethods[] = {
(void *)android_media_MediaCodecList_getSupportedTypes },
{ "getCodecCapabilities",
"(ILjava/lang/String;)Landroid/media/MediaCodecList$CodecCapabilities;",
"(ILjava/lang/String;)Landroid/media/MediaCodecInfo$CodecCapabilities;",
(void *)android_media_MediaCodecList_getCodecCapabilities },
{ "native_init", "()V", (void *)android_media_MediaCodecList_native_init },

View File

@@ -210,7 +210,7 @@ static void android_media_MediaCrypto_native_setup(
if (err != OK) {
jniThrowException(
env,
"java/lang/RuntimeException",
"android/media/MediaCryptoException",
"Failed to instantiate crypto object.");
return;
}
@@ -223,7 +223,7 @@ static void android_media_MediaCrypto_native_finalize(
android_media_MediaCrypto_release(env, thiz);
}
static jboolean android_media_MediaCrypto_isCryptoSchemeSupported(
static jboolean android_media_MediaCrypto_isCryptoSchemeSupportedNative(
JNIEnv *env, jobject thiz, jbyteArray uuidObj) {
jsize uuidLength = env->GetArrayLength(uuidObj);
@@ -284,8 +284,8 @@ static JNINativeMethod gMethods[] = {
{ "native_finalize", "()V",
(void *)android_media_MediaCrypto_native_finalize },
{ "isCryptoSchemeSupported", "([B)Z",
(void *)android_media_MediaCrypto_isCryptoSchemeSupported },
{ "isCryptoSchemeSupportedNative", "([B)Z",
(void *)android_media_MediaCrypto_isCryptoSchemeSupportedNative },
{ "requiresSecureDecoderComponent", "(Ljava/lang/String;)Z",
(void *)android_media_MediaCrypto_requiresSecureDecoderComponent },

View File

@@ -237,7 +237,7 @@ static void android_media_MediaExtractor_release(JNIEnv *env, jobject thiz) {
setMediaExtractor(env, thiz, NULL);
}
static jint android_media_MediaExtractor_countTracks(
static jint android_media_MediaExtractor_getTrackCount(
JNIEnv *env, jobject thiz) {
sp<JMediaExtractor> extractor = getMediaExtractor(env, thiz);
@@ -249,7 +249,7 @@ static jint android_media_MediaExtractor_countTracks(
return extractor->countTracks();
}
static jobject android_media_MediaExtractor_getTrackFormat(
static jobject android_media_MediaExtractor_getTrackFormatNative(
JNIEnv *env, jobject thiz, jint index) {
sp<JMediaExtractor> extractor = getMediaExtractor(env, thiz);
@@ -669,10 +669,10 @@ static void android_media_MediaExtractor_native_finalize(
static JNINativeMethod gMethods[] = {
{ "release", "()V", (void *)android_media_MediaExtractor_release },
{ "countTracks", "()I", (void *)android_media_MediaExtractor_countTracks },
{ "getTrackCount", "()I", (void *)android_media_MediaExtractor_getTrackCount },
{ "getTrackFormat", "(I)Ljava/util/Map;",
(void *)android_media_MediaExtractor_getTrackFormat },
{ "getTrackFormatNative", "(I)Ljava/util/Map;",
(void *)android_media_MediaExtractor_getTrackFormatNative },
{ "selectTrack", "(I)V", (void *)android_media_MediaExtractor_selectTrack },