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