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