MediaProperties.java revision bcbf68583e38eeb79266f9f3a8c3d1b17f75a8c2
1/*
2 * Copyright (C) 2011 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
18package android.media.videoeditor;
19
20import android.util.Pair;
21
22/**
23 * This class defines all properties of a media file such as supported height,
24 * aspect ratio, bitrate for export function.
25 * {@hide}
26 */
27public class MediaProperties {
28    /**
29     *  Supported heights
30     */
31    public static final int HEIGHT_144 = 144;
32    public static final int HEIGHT_288 = 288;
33    public static final int HEIGHT_360 = 360;
34    public static final int HEIGHT_480 = 480;
35    public static final int HEIGHT_720 = 720;
36    public static final int HEIGHT_1088 = 1088;
37
38    /**
39     *  Supported aspect ratios
40     */
41    public static final int ASPECT_RATIO_UNDEFINED = 0;
42    public static final int ASPECT_RATIO_3_2 = 1;
43    public static final int ASPECT_RATIO_16_9 = 2;
44    public static final int ASPECT_RATIO_4_3 = 3;
45    public static final int ASPECT_RATIO_5_3 = 4;
46    public static final int ASPECT_RATIO_11_9 = 5;
47
48    /**
49     *  The array of supported aspect ratios
50     */
51    private static final int[] ASPECT_RATIOS = new int[] {
52        ASPECT_RATIO_3_2,
53        ASPECT_RATIO_16_9,
54        ASPECT_RATIO_4_3,
55        ASPECT_RATIO_5_3,
56        ASPECT_RATIO_11_9
57    };
58
59    /**
60     *  Supported resolutions for specific aspect ratios
61     */
62    @SuppressWarnings({"unchecked"})
63    private static final Pair<Integer, Integer>[] ASPECT_RATIO_3_2_RESOLUTIONS =
64        new Pair[] {
65        new Pair<Integer, Integer>(720, HEIGHT_480),
66//*tmpLSA*/        new Pair<Integer, Integer>(1080, HEIGHT_720)
67/*tmpLSA*/        new Pair<Integer, Integer>(1088, HEIGHT_720)
68    };
69
70    @SuppressWarnings({"unchecked"})
71    private static final Pair<Integer, Integer>[] ASPECT_RATIO_4_3_RESOLUTIONS =
72        new Pair[] {
73        new Pair<Integer, Integer>(640, HEIGHT_480),
74        new Pair<Integer, Integer>(960, HEIGHT_720)
75    };
76
77    @SuppressWarnings({"unchecked"})
78    private static final Pair<Integer, Integer>[] ASPECT_RATIO_5_3_RESOLUTIONS =
79        new Pair[] {
80        new Pair<Integer, Integer>(800, HEIGHT_480)
81    };
82
83    @SuppressWarnings({"unchecked"})
84    private static final Pair<Integer, Integer>[] ASPECT_RATIO_11_9_RESOLUTIONS =
85        new Pair[] {
86        new Pair<Integer, Integer>(176, HEIGHT_144),
87        new Pair<Integer, Integer>(352, HEIGHT_288)
88    };
89
90    @SuppressWarnings({"unchecked"})
91    private static final Pair<Integer, Integer>[] ASPECT_RATIO_16_9_RESOLUTIONS =
92        new Pair[] {
93        new Pair<Integer, Integer>(848, HEIGHT_480),
94        new Pair<Integer, Integer>(1280, HEIGHT_720),
95    };
96
97    /**
98     *  Bitrate values (in bits per second)
99     */
100    public static final int BITRATE_28K = 28000;
101    public static final int BITRATE_40K = 40000;
102    public static final int BITRATE_64K = 64000;
103    public static final int BITRATE_96K = 96000;
104    public static final int BITRATE_128K = 128000;
105    public static final int BITRATE_192K = 192000;
106    public static final int BITRATE_256K = 256000;
107    public static final int BITRATE_384K = 384000;
108    public static final int BITRATE_512K = 512000;
109    public static final int BITRATE_800K = 800000;
110    public static final int BITRATE_2M = 2000000;
111    public static final int BITRATE_5M = 5000000;
112    public static final int BITRATE_8M = 8000000;
113
114    /**
115     *  The array of supported bitrates
116     */
117    private static final int[] SUPPORTED_BITRATES = new int[] {
118        BITRATE_28K,
119        BITRATE_40K,
120        BITRATE_64K,
121        BITRATE_96K,
122        BITRATE_128K,
123        BITRATE_192K,
124        BITRATE_256K,
125        BITRATE_384K,
126        BITRATE_512K,
127        BITRATE_800K,
128        BITRATE_2M,
129        BITRATE_5M,
130        BITRATE_8M
131    };
132
133    /**
134     *  Video codec types
135     */
136    public static final int VCODEC_H263 = 1;
137    public static final int VCODEC_MPEG4 = 2;
138    // 3 Value is used for MPEG4_EMP
139    public static final int VCODEC_H264BP = 4;
140    public static final int VCODEC_H264MP = 5;  // Unsupported
141
142    /**
143     *  The array of supported video codecs
144     */
145    private static final int[] SUPPORTED_VCODECS = new int[] {
146        VCODEC_H264BP,
147        VCODEC_H263,
148        VCODEC_MPEG4,
149    };
150
151    /* H.263 Profiles and levels */
152    public static final int     H263_PROFILE_0_LEVEL_10   = 0;
153    public static final int     H263_PROFILE_0_LEVEL_20   = 1;
154    public static final int     H263_PROFILE_0_LEVEL_30   = 2;
155    public static final int     H263_PROFILE_0_LEVEL_40   = 3;
156    public static final int     H263_PROFILE_0_LEVEL_45   = 4;
157    /* MPEG-4 Profiles and levels */
158    public static final int     MPEG4_SP_LEVEL_0          = 50;
159    public static final int     MPEG4_SP_LEVEL_0B         = 51;
160    public static final int     MPEG4_SP_LEVEL_1          = 52;
161    public static final int     MPEG4_SP_LEVEL_2          = 53;
162    public static final int     MPEG4_SP_LEVEL_3          = 54;
163    public static final int     MPEG4_SP_LEVEL_4A         = 55;
164    public static final int     MPEG4_SP_LEVEL_5          = 56;
165    /* AVC Profiles and levels */
166    public static final int     H264_PROFILE_0_LEVEL_1    = 150;
167    public static final int     H264_PROFILE_0_LEVEL_1B   = 151;
168    public static final int     H264_PROFILE_0_LEVEL_1_1  = 152;
169    public static final int     H264_PROFILE_0_LEVEL_1_2  = 153;
170    public static final int     H264_PROFILE_0_LEVEL_1_3  = 154;
171    public static final int     H264_PROFILE_0_LEVEL_2    = 155;
172    public static final int     H264_PROFILE_0_LEVEL_2_1  = 156;
173    public static final int     H264_PROFILE_0_LEVEL_2_2  = 157;
174    public static final int     H264_PROFILE_0_LEVEL_3    = 158;
175    public static final int     H264_PROFILE_0_LEVEL_3_1  = 159;
176    public static final int     H264_PROFILE_0_LEVEL_3_2  = 160;
177    public static final int     H264_PROFILE_0_LEVEL_4    = 161;
178    public static final int     H264_PROFILE_0_LEVEL_4_1  = 162;
179    public static final int     H264_PROFILE_0_LEVEL_4_2  = 163;
180    public static final int     H264_PROFILE_0_LEVEL_5    = 164;
181    public static final int     H264_PROFILE_0_LEVEL_5_1  = 165;
182    /* Unsupported profile and level */
183    public static final int     UNSUPPORTED_PROFILE_LEVEL = 255;
184
185    /**
186     *  The array of supported video codec Profile and Levels
187     */
188    private static final int[] SUPPORTED_VCODEC_PROFILE_LEVELS = new int[] {
189        H263_PROFILE_0_LEVEL_10,
190        H263_PROFILE_0_LEVEL_20,
191        H263_PROFILE_0_LEVEL_30,
192        H263_PROFILE_0_LEVEL_40,
193        H263_PROFILE_0_LEVEL_45,
194        MPEG4_SP_LEVEL_0,
195        MPEG4_SP_LEVEL_0B,
196        MPEG4_SP_LEVEL_1,
197        MPEG4_SP_LEVEL_2,
198        MPEG4_SP_LEVEL_3,
199        MPEG4_SP_LEVEL_4A,
200        MPEG4_SP_LEVEL_5,
201        H264_PROFILE_0_LEVEL_1,
202        H264_PROFILE_0_LEVEL_1B,
203        H264_PROFILE_0_LEVEL_1_1,
204        H264_PROFILE_0_LEVEL_1_2,
205        H264_PROFILE_0_LEVEL_1_3,
206        H264_PROFILE_0_LEVEL_2,
207        H264_PROFILE_0_LEVEL_2_1,
208        H264_PROFILE_0_LEVEL_2_2,
209        H264_PROFILE_0_LEVEL_3,
210        H264_PROFILE_0_LEVEL_3_1,
211        H264_PROFILE_0_LEVEL_3_2,
212        H264_PROFILE_0_LEVEL_4,
213        H264_PROFILE_0_LEVEL_4_1,
214        H264_PROFILE_0_LEVEL_4_2,
215        H264_PROFILE_0_LEVEL_5,
216        H264_PROFILE_0_LEVEL_5_1,
217        UNSUPPORTED_PROFILE_LEVEL
218    };
219
220    /**
221     *  Audio codec types
222     */
223    public static final int ACODEC_NO_AUDIO = 0;
224    public static final int ACODEC_AMRNB = 1;
225    public static final int ACODEC_AAC_LC = 2;
226    public static final int ACODEC_AAC_PLUS = 3;
227    public static final int ACODEC_ENHANCED_AAC_PLUS = 4;
228    public static final int ACODEC_MP3 = 5;
229    public static final int ACODEC_EVRC = 6;
230    // 7 value is used for PCM
231    public static final int ACODEC_AMRWB = 8;
232    public static final int ACODEC_OGG = 9;
233
234    /**
235     *  The array of supported audio codecs
236     */
237    private static final int[] SUPPORTED_ACODECS = new int[] {
238        ACODEC_AAC_LC,
239        ACODEC_AMRNB,
240        ACODEC_AMRWB
241    };
242
243
244    /**
245     *  Samples per frame for each audio codec
246     */
247    public static final int SAMPLES_PER_FRAME_AAC = 1024;
248    public static final int SAMPLES_PER_FRAME_MP3 = 1152;
249    public static final int SAMPLES_PER_FRAME_AMRNB = 160;
250    public static final int SAMPLES_PER_FRAME_AMRWB = 320;
251
252    public static final int DEFAULT_SAMPLING_FREQUENCY = 32000;
253    public static final int DEFAULT_CHANNEL_COUNT = 2;
254
255    /**
256     *  File format types
257     */
258    public static final int FILE_3GP = 0;
259    public static final int FILE_MP4 = 1;
260    // 2 is for AMRNB
261    public static final int FILE_MP3 = 3;
262    // 4 is for PCM
263    public static final int FILE_JPEG = 5;
264    // 6 is for BMP
265    // 7 is for GIF
266    public static final int FILE_PNG = 8;
267    // 9 is for ARGB8888
268    public static final int FILE_M4V = 10;
269    public static final int FILE_UNSUPPORTED = 255;
270
271    /**
272     * Undefined video codec profiles
273     */
274    public static final int UNDEFINED_VIDEO_PROFILE = 255;
275
276    /**
277     * The array of the supported file formats
278     */
279    private static final int[] SUPPORTED_VIDEO_FILE_FORMATS = new int[] {
280        FILE_3GP,
281        FILE_MP4,
282        FILE_M4V
283    };
284
285    /**
286     * The maximum count of audio tracks supported
287     */
288    public static final int AUDIO_MAX_TRACK_COUNT = 1;
289
290    /** The maximum volume supported (100 means that no amplification is
291     * supported, i.e. attenuation only)
292     */
293    public static final int AUDIO_MAX_VOLUME_PERCENT = 100;
294
295    /**
296     * This class cannot be instantiated
297     */
298    private MediaProperties() {
299    }
300
301    /**
302     * @return The array of supported aspect ratios
303     */
304    public static int[] getAllSupportedAspectRatios() {
305        return ASPECT_RATIOS;
306    }
307
308    /**
309     * Get the supported resolutions for the specified aspect ratio.
310     *
311     * @param aspectRatio The aspect ratio for which the resolutions are
312     *        requested
313     * @return The array of width and height pairs
314     */
315    public static Pair<Integer, Integer>[] getSupportedResolutions(int aspectRatio) {
316        final Pair<Integer, Integer>[] resolutions;
317        switch (aspectRatio) {
318            case ASPECT_RATIO_3_2: {
319                resolutions = ASPECT_RATIO_3_2_RESOLUTIONS;
320                break;
321            }
322
323            case ASPECT_RATIO_4_3: {
324                resolutions = ASPECT_RATIO_4_3_RESOLUTIONS;
325                break;
326            }
327
328            case ASPECT_RATIO_5_3: {
329                resolutions = ASPECT_RATIO_5_3_RESOLUTIONS;
330                break;
331            }
332
333            case ASPECT_RATIO_11_9: {
334                resolutions = ASPECT_RATIO_11_9_RESOLUTIONS;
335                break;
336            }
337
338            case ASPECT_RATIO_16_9: {
339                resolutions = ASPECT_RATIO_16_9_RESOLUTIONS;
340                break;
341            }
342
343            default: {
344                throw new IllegalArgumentException("Unknown aspect ratio: " + aspectRatio);
345            }
346        }
347
348        return resolutions;
349    }
350
351    /**
352     * @return The array of supported video codecs
353     */
354    public static int[] getSupportedVideoCodecs() {
355        return SUPPORTED_VCODECS;
356    }
357
358    /**
359     * @return The array of supported audio codecs
360     */
361    public static int[] getSupportedAudioCodecs() {
362        return SUPPORTED_ACODECS;
363    }
364
365    /**
366     * @return The array of supported file formats
367     */
368    public static int[] getSupportedVideoFileFormat() {
369        return SUPPORTED_VIDEO_FILE_FORMATS;
370    }
371
372    /**
373     * @return The array of supported video bitrates
374     */
375    public static int[] getSupportedVideoBitrates() {
376        return SUPPORTED_BITRATES;
377    }
378
379    /**
380     * @return The maximum value for the audio volume
381     */
382    public static int getSupportedMaxVolume() {
383        return MediaProperties.AUDIO_MAX_VOLUME_PERCENT;
384    }
385
386    /**
387     * @return The maximum number of audio tracks supported
388     */
389    public static int getSupportedAudioTrackCount() {
390        return MediaProperties.AUDIO_MAX_TRACK_COUNT;
391    }
392}
393