Kenny Root | 15a4d2f | 2010-03-11 18:20:12 -0800 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (C) 2009 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 | |
Yu Shan Emily Lau | 1619367 | 2009-09-14 16:23:12 -0700 | [diff] [blame] | 17 | package com.android.mediaframeworktest; |
| 18 | |
| 19 | import android.media.MediaRecorder; |
James Dong | 1b7babd | 2010-02-16 14:38:23 -0800 | [diff] [blame] | 20 | import android.media.EncoderCapabilities; |
| 21 | import android.media.EncoderCapabilities.VideoEncoderCap; |
| 22 | import android.media.EncoderCapabilities.AudioEncoderCap; |
| 23 | import android.media.DecoderCapabilities; |
| 24 | import android.media.DecoderCapabilities.VideoDecoder; |
| 25 | import android.media.DecoderCapabilities.AudioDecoder; |
| 26 | |
Yu Shan Emily Lau | 1619367 | 2009-09-14 16:23:12 -0700 | [diff] [blame] | 27 | import android.os.SystemProperties; |
James Dong | 1b7babd | 2010-02-16 14:38:23 -0800 | [diff] [blame] | 28 | import java.util.List; |
Yu Shan Emily Lau | 1619367 | 2009-09-14 16:23:12 -0700 | [diff] [blame] | 29 | import java.util.HashMap; |
| 30 | |
James Dong | 1b7babd | 2010-02-16 14:38:23 -0800 | [diff] [blame] | 31 | public class MediaProfileReader |
| 32 | { |
| 33 | private static final List<VideoDecoder> videoDecoders = DecoderCapabilities.getVideoDecoders(); |
| 34 | private static final List<AudioDecoder> audioDecoders = DecoderCapabilities.getAudioDecoders(); |
| 35 | private static final List<VideoEncoderCap> videoEncoders = EncoderCapabilities.getVideoEncoders(); |
| 36 | private static final List<AudioEncoderCap> audioEncoders = EncoderCapabilities.getAudioEncoders(); |
| 37 | private static final HashMap<Integer, String> encoderMap = new HashMap<Integer, String>(); |
Yu Shan Emily Lau | 1619367 | 2009-09-14 16:23:12 -0700 | [diff] [blame] | 38 | |
James Dong | 1b7babd | 2010-02-16 14:38:23 -0800 | [diff] [blame] | 39 | static { |
| 40 | initEncoderMap(); |
| 41 | }; |
Yu Shan Emily Lau | 1619367 | 2009-09-14 16:23:12 -0700 | [diff] [blame] | 42 | |
James Dong | 1b7babd | 2010-02-16 14:38:23 -0800 | [diff] [blame] | 43 | public static List<VideoEncoderCap> getVideoEncoders() { |
| 44 | return videoEncoders; |
Yu Shan Emily Lau | 1619367 | 2009-09-14 16:23:12 -0700 | [diff] [blame] | 45 | } |
| 46 | |
James Dong | 1b7babd | 2010-02-16 14:38:23 -0800 | [diff] [blame] | 47 | public static List<AudioEncoderCap> getAudioEncoders() { |
| 48 | return audioEncoders; |
Yu Shan Emily Lau | 1619367 | 2009-09-14 16:23:12 -0700 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | public static String getDeviceType() { |
| 52 | // push all the property into one big table |
| 53 | String s; |
| 54 | s = SystemProperties.get("ro.product.name"); |
| 55 | return s; |
| 56 | } |
| 57 | |
Yu Shan Emily Lau | dc1af5b | 2009-09-21 21:13:36 -0700 | [diff] [blame] | 58 | public static boolean getWMAEnable() { |
James Dong | 1b7babd | 2010-02-16 14:38:23 -0800 | [diff] [blame] | 59 | for (AudioDecoder decoder: audioDecoders) { |
| 60 | if (decoder == AudioDecoder.AUDIO_DECODER_WMA) { |
| 61 | return true; |
| 62 | } |
Yu Shan Emily Lau | dc1af5b | 2009-09-21 21:13:36 -0700 | [diff] [blame] | 63 | } |
James Dong | 1b7babd | 2010-02-16 14:38:23 -0800 | [diff] [blame] | 64 | return false; |
Yu Shan Emily Lau | dc1af5b | 2009-09-21 21:13:36 -0700 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | public static boolean getWMVEnable(){ |
James Dong | 1b7babd | 2010-02-16 14:38:23 -0800 | [diff] [blame] | 68 | for (VideoDecoder decoder: videoDecoders) { |
| 69 | if (decoder == VideoDecoder.VIDEO_DECODER_WMV) { |
| 70 | return true; |
Yu Shan Emily Lau | 34831c9 | 2009-09-25 11:18:40 -0700 | [diff] [blame] | 71 | } |
Yu Shan Emily Lau | 1619367 | 2009-09-14 16:23:12 -0700 | [diff] [blame] | 72 | } |
James Dong | 1b7babd | 2010-02-16 14:38:23 -0800 | [diff] [blame] | 73 | return false; |
Yu Shan Emily Lau | 1619367 | 2009-09-14 16:23:12 -0700 | [diff] [blame] | 74 | } |
| 75 | |
James Dong | 1b7babd | 2010-02-16 14:38:23 -0800 | [diff] [blame] | 76 | public static String getVideoCodecName(int videoEncoder) { |
| 77 | if (videoEncoder != MediaRecorder.VideoEncoder.H263 && |
| 78 | videoEncoder != MediaRecorder.VideoEncoder.H264 && |
| 79 | videoEncoder != MediaRecorder.VideoEncoder.MPEG_4_SP) { |
| 80 | throw new IllegalArgumentException("Unsupported video encoder " + videoEncoder); |
Yu Shan Emily Lau | 1619367 | 2009-09-14 16:23:12 -0700 | [diff] [blame] | 81 | } |
James Dong | 1b7babd | 2010-02-16 14:38:23 -0800 | [diff] [blame] | 82 | return encoderMap.get(videoEncoder); |
Yu Shan Emily Lau | 1619367 | 2009-09-14 16:23:12 -0700 | [diff] [blame] | 83 | } |
| 84 | |
James Dong | 1b7babd | 2010-02-16 14:38:23 -0800 | [diff] [blame] | 85 | public static String getAudioCodecName(int audioEncoder) { |
| 86 | if (audioEncoder != MediaRecorder.AudioEncoder.AMR_NB && |
| 87 | audioEncoder != MediaRecorder.AudioEncoder.AMR_WB && |
| 88 | audioEncoder != MediaRecorder.AudioEncoder.AAC && |
| 89 | audioEncoder != MediaRecorder.AudioEncoder.AAC_PLUS && |
| 90 | audioEncoder != MediaRecorder.AudioEncoder.EAAC_PLUS) { |
| 91 | throw new IllegalArgumentException("Unsupported audio encodeer " + audioEncoder); |
| 92 | } |
| 93 | return encoderMap.get(audioEncoder); |
| 94 | } |
| 95 | |
| 96 | private MediaProfileReader() {} // Don't call me |
| 97 | |
| 98 | private static void initEncoderMap() { |
| 99 | // video encoders |
| 100 | encoderMap.put(MediaRecorder.VideoEncoder.H263, "h263"); |
| 101 | encoderMap.put(MediaRecorder.VideoEncoder.H264, "h264"); |
| 102 | encoderMap.put(MediaRecorder.VideoEncoder.MPEG_4_SP, "m4v"); |
| 103 | |
| 104 | // audio encoders |
| 105 | encoderMap.put(MediaRecorder.AudioEncoder.AMR_NB, "amrnb"); |
| 106 | encoderMap.put(MediaRecorder.AudioEncoder.AMR_WB, "amrwb"); |
| 107 | encoderMap.put(MediaRecorder.AudioEncoder.AAC, "aac"); |
| 108 | encoderMap.put(MediaRecorder.AudioEncoder.AAC_PLUS, "aacplus"); |
| 109 | encoderMap.put(MediaRecorder.AudioEncoder.EAAC_PLUS, "eaacplus"); |
Yu Shan Emily Lau | 1619367 | 2009-09-14 16:23:12 -0700 | [diff] [blame] | 110 | } |
| 111 | } |