Skip to content

Commit c52c957

Browse files
theandi666Android (Google) Code Review
authored andcommitted
Merge "Various changes to Media* APIs requested by the api council." into jb-dev
2 parents 602290a + 60d610b commit c52c957

12 files changed

+1102
-349
lines changed

api/current.txt

Lines changed: 185 additions & 27 deletions
Large diffs are not rendered by default.

media/java/android/media/MediaCodec.java

Lines changed: 210 additions & 187 deletions
Large diffs are not rendered by default.
Lines changed: 213 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,213 @@
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+
17+
package android.media;
18+
19+
public final class MediaCodecInfo {
20+
private int mIndex;
21+
22+
/* package private */ MediaCodecInfo(int index) {
23+
mIndex = index;
24+
}
25+
26+
/**
27+
* Retrieve the codec name.
28+
*/
29+
public final String getName() {
30+
return MediaCodecList.getCodecName(mIndex);
31+
}
32+
33+
/**
34+
* Query if the codec is an encoder.
35+
*/
36+
public final boolean isEncoder() {
37+
return MediaCodecList.isEncoder(mIndex);
38+
}
39+
40+
/**
41+
* Query the media types supported by the codec.
42+
*/
43+
public final String[] getSupportedTypes() {
44+
return MediaCodecList.getSupportedTypes(mIndex);
45+
}
46+
47+
public static final class CodecCapabilities {
48+
public CodecProfileLevel[] profileLevels;
49+
50+
// from OMX_COLOR_FORMATTYPE
51+
public final static int COLOR_FormatMonochrome = 1;
52+
public final static int COLOR_Format8bitRGB332 = 2;
53+
public final static int COLOR_Format12bitRGB444 = 3;
54+
public final static int COLOR_Format16bitARGB4444 = 4;
55+
public final static int COLOR_Format16bitARGB1555 = 5;
56+
public final static int COLOR_Format16bitRGB565 = 6;
57+
public final static int COLOR_Format16bitBGR565 = 7;
58+
public final static int COLOR_Format18bitRGB666 = 8;
59+
public final static int COLOR_Format18bitARGB1665 = 9;
60+
public final static int COLOR_Format19bitARGB1666 = 10;
61+
public final static int COLOR_Format24bitRGB888 = 11;
62+
public final static int COLOR_Format24bitBGR888 = 12;
63+
public final static int COLOR_Format24bitARGB1887 = 13;
64+
public final static int COLOR_Format25bitARGB1888 = 14;
65+
public final static int COLOR_Format32bitBGRA8888 = 15;
66+
public final static int COLOR_Format32bitARGB8888 = 16;
67+
public final static int COLOR_FormatYUV411Planar = 17;
68+
public final static int COLOR_FormatYUV411PackedPlanar = 18;
69+
public final static int COLOR_FormatYUV420Planar = 19;
70+
public final static int COLOR_FormatYUV420PackedPlanar = 20;
71+
public final static int COLOR_FormatYUV420SemiPlanar = 21;
72+
public final static int COLOR_FormatYUV422Planar = 22;
73+
public final static int COLOR_FormatYUV422PackedPlanar = 23;
74+
public final static int COLOR_FormatYUV422SemiPlanar = 24;
75+
public final static int COLOR_FormatYCbYCr = 25;
76+
public final static int COLOR_FormatYCrYCb = 26;
77+
public final static int COLOR_FormatCbYCrY = 27;
78+
public final static int COLOR_FormatCrYCbY = 28;
79+
public final static int COLOR_FormatYUV444Interleaved = 29;
80+
public final static int COLOR_FormatRawBayer8bit = 30;
81+
public final static int COLOR_FormatRawBayer10bit = 31;
82+
public final static int COLOR_FormatRawBayer8bitcompressed = 32;
83+
public final static int COLOR_FormatL2 = 33;
84+
public final static int COLOR_FormatL4 = 34;
85+
public final static int COLOR_FormatL8 = 35;
86+
public final static int COLOR_FormatL16 = 36;
87+
public final static int COLOR_FormatL24 = 37;
88+
public final static int COLOR_FormatL32 = 38;
89+
public final static int COLOR_FormatYUV420PackedSemiPlanar = 39;
90+
public final static int COLOR_FormatYUV422PackedSemiPlanar = 40;
91+
public final static int COLOR_Format18BitBGR666 = 41;
92+
public final static int COLOR_Format24BitARGB6666 = 42;
93+
public final static int COLOR_Format24BitABGR6666 = 43;
94+
95+
public final static int COLOR_TI_FormatYUV420PackedSemiPlanar = 0x7f000100;
96+
public final static int COLOR_QCOM_FormatYUV420SemiPlanar = 0x7fa30c00;
97+
98+
/**
99+
* Defined in the OpenMAX IL specs, color format values are drawn from
100+
* OMX_COLOR_FORMATTYPE.
101+
*/
102+
public int[] colorFormats;
103+
};
104+
105+
public static final class CodecProfileLevel {
106+
// from OMX_VIDEO_AVCPROFILETYPE
107+
public static final int AVCProfileBaseline = 0x01;
108+
public static final int AVCProfileMain = 0x02;
109+
public static final int AVCProfileExtended = 0x04;
110+
public static final int AVCProfileHigh = 0x08;
111+
public static final int AVCProfileHigh10 = 0x10;
112+
public static final int AVCProfileHigh422 = 0x20;
113+
public static final int AVCProfileHigh444 = 0x40;
114+
115+
// from OMX_VIDEO_AVCLEVELTYPE
116+
public static final int AVCLevel1 = 0x01;
117+
public static final int AVCLevel1b = 0x02;
118+
public static final int AVCLevel11 = 0x04;
119+
public static final int AVCLevel12 = 0x08;
120+
public static final int AVCLevel13 = 0x10;
121+
public static final int AVCLevel2 = 0x20;
122+
public static final int AVCLevel21 = 0x40;
123+
public static final int AVCLevel22 = 0x80;
124+
public static final int AVCLevel3 = 0x100;
125+
public static final int AVCLevel31 = 0x200;
126+
public static final int AVCLevel32 = 0x400;
127+
public static final int AVCLevel4 = 0x800;
128+
public static final int AVCLevel41 = 0x1000;
129+
public static final int AVCLevel42 = 0x2000;
130+
public static final int AVCLevel5 = 0x4000;
131+
public static final int AVCLevel51 = 0x8000;
132+
133+
// from OMX_VIDEO_H263PROFILETYPE
134+
public static final int H263ProfileBaseline = 0x01;
135+
public static final int H263ProfileH320Coding = 0x02;
136+
public static final int H263ProfileBackwardCompatible = 0x04;
137+
public static final int H263ProfileISWV2 = 0x08;
138+
public static final int H263ProfileISWV3 = 0x10;
139+
public static final int H263ProfileHighCompression = 0x20;
140+
public static final int H263ProfileInternet = 0x40;
141+
public static final int H263ProfileInterlace = 0x80;
142+
public static final int H263ProfileHighLatency = 0x100;
143+
144+
// from OMX_VIDEO_H263LEVELTYPE
145+
public static final int H263Level10 = 0x01;
146+
public static final int H263Level20 = 0x02;
147+
public static final int H263Level30 = 0x04;
148+
public static final int H263Level40 = 0x08;
149+
public static final int H263Level45 = 0x10;
150+
public static final int H263Level50 = 0x20;
151+
public static final int H263Level60 = 0x40;
152+
public static final int H263Level70 = 0x80;
153+
154+
// from OMX_VIDEO_MPEG4PROFILETYPE
155+
public static final int MPEG4ProfileSimple = 0x01;
156+
public static final int MPEG4ProfileSimpleScalable = 0x02;
157+
public static final int MPEG4ProfileCore = 0x04;
158+
public static final int MPEG4ProfileMain = 0x08;
159+
public static final int MPEG4ProfileNbit = 0x10;
160+
public static final int MPEG4ProfileScalableTexture = 0x20;
161+
public static final int MPEG4ProfileSimpleFace = 0x40;
162+
public static final int MPEG4ProfileSimpleFBA = 0x80;
163+
public static final int MPEG4ProfileBasicAnimated = 0x100;
164+
public static final int MPEG4ProfileHybrid = 0x200;
165+
public static final int MPEG4ProfileAdvancedRealTime = 0x400;
166+
public static final int MPEG4ProfileCoreScalable = 0x800;
167+
public static final int MPEG4ProfileAdvancedCoding = 0x1000;
168+
public static final int MPEG4ProfileAdvancedCore = 0x2000;
169+
public static final int MPEG4ProfileAdvancedScalable = 0x4000;
170+
public static final int MPEG4ProfileAdvancedSimple = 0x8000;
171+
172+
// from OMX_VIDEO_MPEG4LEVELTYPE
173+
public static final int MPEG4Level0 = 0x01;
174+
public static final int MPEG4Level0b = 0x02;
175+
public static final int MPEG4Level1 = 0x04;
176+
public static final int MPEG4Level2 = 0x08;
177+
public static final int MPEG4Level3 = 0x10;
178+
public static final int MPEG4Level4 = 0x20;
179+
public static final int MPEG4Level4a = 0x40;
180+
public static final int MPEG4Level5 = 0x80;
181+
182+
// from OMX_AUDIO_AACPROFILETYPE
183+
public static final int AACObjectMain = 1;
184+
public static final int AACObjectLC = 2;
185+
public static final int AACObjectSSR = 3;
186+
public static final int AACObjectLTP = 4;
187+
public static final int AACObjectHE = 5;
188+
public static final int AACObjectScalable = 6;
189+
public static final int AACObjectERLC = 17;
190+
public static final int AACObjectLD = 23;
191+
public static final int AACObjectHE_PS = 29;
192+
public static final int AACObjectELD = 39;
193+
194+
/**
195+
* Defined in the OpenMAX IL specs, depending on the type of media
196+
* this can be OMX_VIDEO_AVCPROFILETYPE, OMX_VIDEO_H263PROFILETYPE,
197+
* or OMX_VIDEO_MPEG4PROFILETYPE.
198+
*/
199+
public int profile;
200+
201+
/**
202+
* Defined in the OpenMAX IL specs, depending on the type of media
203+
* this can be OMX_VIDEO_AVCLEVELTYPE, OMX_VIDEO_H263LEVELTYPE
204+
* or OMX_VIDEO_MPEG4LEVELTYPE.
205+
*/
206+
public int level;
207+
};
208+
209+
public final CodecCapabilities getCapabilitiesForType(
210+
String type) {
211+
return MediaCodecList.getCodecCapabilities(mIndex, type);
212+
}
213+
}

media/java/android/media/MediaCodecList.java

Lines changed: 18 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -16,49 +16,35 @@
1616

1717
package android.media;
1818

19+
import android.media.MediaCodecInfo;
20+
1921
/**
2022
* MediaCodecList class can be used to enumerate available codecs,
2123
* find a codec supporting a given format and query the capabilities
2224
* of a given codec.
23-
*/
25+
*/
2426
final public class MediaCodecList {
25-
/** Count the number of available codecs.
26-
*/
27-
public static native final int countCodecs();
27+
/**
28+
* Count the number of available codecs.
29+
*/
30+
public static native final int getCodecCount();
2831

29-
/** Retrieve the codec name at the specified index. */
30-
public static native final String getCodecName(int index);
32+
public static final MediaCodecInfo getCodecInfoAt(int index) {
33+
if (index < 0 || index > getCodecCount()) {
34+
throw new IllegalArgumentException();
35+
}
3136

32-
/** Query if the codec at the specified index is an encoder. */
33-
public static native final boolean isEncoder(int index);
34-
35-
/** Query the media types supported by the codec at the specified index */
36-
public static native final String[] getSupportedTypes(int index);
37+
return new MediaCodecInfo(index);
38+
}
3739

38-
public static final class CodecProfileLevel {
39-
/** Defined in the OpenMAX IL specs, depending on the type of media
40-
* this can be OMX_VIDEO_AVCPROFILETYPE, OMX_VIDEO_H263PROFILETYPE
41-
* or OMX_VIDEO_MPEG4PROFILETYPE.
42-
*/
43-
public int profile;
40+
/* package private */ static native final String getCodecName(int index);
4441

45-
/** Defined in the OpenMAX IL specs, depending on the type of media
46-
* this can be OMX_VIDEO_AVCLEVELTYPE, OMX_VIDEO_H263LEVELTYPE
47-
* or OMX_VIDEO_MPEG4LEVELTYPE.
48-
*/
49-
public int level;
50-
};
42+
/* package private */ static native final boolean isEncoder(int index);
5143

52-
public static final class CodecCapabilities {
53-
public CodecProfileLevel[] profileLevels;
44+
/* package private */ static native final String[] getSupportedTypes(int index);
5445

55-
/** Defined in the OpenMAX IL specs, color format values are drawn from
56-
* OMX_COLOR_FORMATTYPE.
57-
*/
58-
public int[] colorFormats;
59-
};
60-
public static native final CodecCapabilities getCodecCapabilities(
61-
int index, String type);
46+
/* package private */ static native final MediaCodecInfo.CodecCapabilities
47+
getCodecCapabilities(int index, String type);
6248

6349
private static native final void native_init();
6450

media/java/android/media/MediaCrypto.java

Lines changed: 44 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616

1717
package android.media;
1818

19+
import android.media.MediaCryptoException;
20+
import java.util.UUID;
21+
1922
/**
2023
* MediaCrypto class can be used in conjunction with {@link android.media.MediaCodec}
2124
* to decode encrypted media data.
@@ -24,27 +27,47 @@
2427
* the method {@link #isCryptoSchemeSupported} can be used to query if a given
2528
* scheme is supported on the device.
2629
*
27-
*/
30+
*/
2831
public final class MediaCrypto {
29-
/** Query if the given scheme identified by its UUID is supported on
30-
* this device.
31-
* @param uuid The UUID of the crypto scheme.
32-
*/
33-
public static final native boolean isCryptoSchemeSupported(byte[] uuid);
32+
/**
33+
* Query if the given scheme identified by its UUID is supported on
34+
* this device.
35+
* @param uuid The UUID of the crypto scheme.
36+
*/
37+
public static final boolean isCryptoSchemeSupported(UUID uuid) {
38+
return isCryptoSchemeSupportedNative(getByteArrayFromUUID(uuid));
39+
}
40+
41+
private static final byte[] getByteArrayFromUUID(UUID uuid) {
42+
long msb = uuid.getMostSignificantBits();
43+
long lsb = uuid.getLeastSignificantBits();
44+
45+
byte[] uuidBytes = new byte[16];
46+
for (int i = 0; i < 8; ++i) {
47+
uuidBytes[i] = (byte)(msb >>> (8 * (7 - i)));
48+
uuidBytes[8 + i] = (byte)(lsb >>> (8 * (7 - i)));
49+
}
3450

35-
/** Instantiate a MediaCrypto object using opaque, crypto scheme specific
36-
* data.
37-
* @param uuid The UUID of the crypto scheme.
38-
* @param initData Opaque initialization data specific to the crypto scheme.
39-
*/
40-
public MediaCrypto(byte[] uuid, byte[] initData) throws RuntimeException {
41-
native_setup(uuid, initData);
51+
return uuidBytes;
4252
}
4353

44-
/** Query if the crypto scheme requires the use of a secure decoder
45-
* to decode data of the given mime type.
46-
* @param mime The mime type of the media data
47-
*/
54+
private static final native boolean isCryptoSchemeSupportedNative(byte[] uuid);
55+
56+
/**
57+
* Instantiate a MediaCrypto object using opaque, crypto scheme specific
58+
* data.
59+
* @param uuid The UUID of the crypto scheme.
60+
* @param initData Opaque initialization data specific to the crypto scheme.
61+
*/
62+
public MediaCrypto(UUID uuid, byte[] initData) throws MediaCryptoException {
63+
native_setup(getByteArrayFromUUID(uuid), initData);
64+
}
65+
66+
/**
67+
* Query if the crypto scheme requires the use of a secure decoder
68+
* to decode data of the given mime type.
69+
* @param mime The mime type of the media data
70+
*/
4871
public final native boolean requiresSecureDecoderComponent(String mime);
4972

5073
@Override
@@ -54,7 +77,10 @@ protected void finalize() {
5477

5578
public native final void release();
5679
private static native final void native_init();
57-
private native final void native_setup(byte[] uuid, byte[] initData);
80+
81+
private native final void native_setup(byte[] uuid, byte[] initData)
82+
throws MediaCryptoException;
83+
5884
private native final void native_finalize();
5985

6086
static {
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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+
17+
package android.media;
18+
19+
/**
20+
* Exception thrown if MediaCrypto object could not be instantiated for
21+
* whatever reason.
22+
*/
23+
public final class MediaCryptoException extends Exception {
24+
public MediaCryptoException(String detailMessage) {
25+
super(detailMessage);
26+
}
27+
}

0 commit comments

Comments
 (0)