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(); |
James Dong | 620a4240 | 2010-07-07 14:37:48 -0700 | [diff] [blame] | 37 | private static final HashMap<Integer, String> videoEncoderMap = new HashMap<Integer, String>(); |
| 38 | private static final HashMap<Integer, String> audioEncoderMap = new HashMap<Integer, String>(); |
Yu Shan Emily Lau | 1619367 | 2009-09-14 16:23:12 -0700 | [diff] [blame] | 39 | |
James Dong | 1b7babd | 2010-02-16 14:38:23 -0800 | [diff] [blame] | 40 | static { |
James Dong | 620a4240 | 2010-07-07 14:37:48 -0700 | [diff] [blame] | 41 | initAudioEncoderMap(); |
| 42 | initVideoEncoderMap(); |
James Dong | 1b7babd | 2010-02-16 14:38:23 -0800 | [diff] [blame] | 43 | }; |
Yu Shan Emily Lau | 1619367 | 2009-09-14 16:23:12 -0700 | [diff] [blame] | 44 | |
James Dong | 1b7babd | 2010-02-16 14:38:23 -0800 | [diff] [blame] | 45 | public static List<VideoEncoderCap> getVideoEncoders() { |
| 46 | return videoEncoders; |
Yu Shan Emily Lau | 1619367 | 2009-09-14 16:23:12 -0700 | [diff] [blame] | 47 | } |
| 48 | |
James Dong | 1b7babd | 2010-02-16 14:38:23 -0800 | [diff] [blame] | 49 | public static List<AudioEncoderCap> getAudioEncoders() { |
| 50 | return audioEncoders; |
Yu Shan Emily Lau | 1619367 | 2009-09-14 16:23:12 -0700 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | public static String getDeviceType() { |
| 54 | // push all the property into one big table |
| 55 | String s; |
| 56 | s = SystemProperties.get("ro.product.name"); |
| 57 | return s; |
| 58 | } |
| 59 | |
Yu Shan Emily Lau | dc1af5b | 2009-09-21 21:13:36 -0700 | [diff] [blame] | 60 | public static boolean getWMAEnable() { |
James Dong | 1b7babd | 2010-02-16 14:38:23 -0800 | [diff] [blame] | 61 | for (AudioDecoder decoder: audioDecoders) { |
| 62 | if (decoder == AudioDecoder.AUDIO_DECODER_WMA) { |
| 63 | return true; |
| 64 | } |
Yu Shan Emily Lau | dc1af5b | 2009-09-21 21:13:36 -0700 | [diff] [blame] | 65 | } |
James Dong | 1b7babd | 2010-02-16 14:38:23 -0800 | [diff] [blame] | 66 | return false; |
Yu Shan Emily Lau | dc1af5b | 2009-09-21 21:13:36 -0700 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | public static boolean getWMVEnable(){ |
James Dong | 1b7babd | 2010-02-16 14:38:23 -0800 | [diff] [blame] | 70 | for (VideoDecoder decoder: videoDecoders) { |
| 71 | if (decoder == VideoDecoder.VIDEO_DECODER_WMV) { |
| 72 | return true; |
Yu Shan Emily Lau | 34831c9 | 2009-09-25 11:18:40 -0700 | [diff] [blame] | 73 | } |
Yu Shan Emily Lau | 1619367 | 2009-09-14 16:23:12 -0700 | [diff] [blame] | 74 | } |
James Dong | 1b7babd | 2010-02-16 14:38:23 -0800 | [diff] [blame] | 75 | return false; |
Yu Shan Emily Lau | 1619367 | 2009-09-14 16:23:12 -0700 | [diff] [blame] | 76 | } |
| 77 | |
James Dong | 1b7babd | 2010-02-16 14:38:23 -0800 | [diff] [blame] | 78 | public static String getVideoCodecName(int videoEncoder) { |
| 79 | if (videoEncoder != MediaRecorder.VideoEncoder.H263 && |
| 80 | videoEncoder != MediaRecorder.VideoEncoder.H264 && |
| 81 | videoEncoder != MediaRecorder.VideoEncoder.MPEG_4_SP) { |
| 82 | throw new IllegalArgumentException("Unsupported video encoder " + videoEncoder); |
Yu Shan Emily Lau | 1619367 | 2009-09-14 16:23:12 -0700 | [diff] [blame] | 83 | } |
James Dong | 620a4240 | 2010-07-07 14:37:48 -0700 | [diff] [blame] | 84 | return videoEncoderMap.get(videoEncoder); |
Yu Shan Emily Lau | 1619367 | 2009-09-14 16:23:12 -0700 | [diff] [blame] | 85 | } |
| 86 | |
James Dong | 1b7babd | 2010-02-16 14:38:23 -0800 | [diff] [blame] | 87 | public static String getAudioCodecName(int audioEncoder) { |
| 88 | if (audioEncoder != MediaRecorder.AudioEncoder.AMR_NB && |
| 89 | audioEncoder != MediaRecorder.AudioEncoder.AMR_WB && |
| 90 | audioEncoder != MediaRecorder.AudioEncoder.AAC && |
Dave Burke | ec3f31f | 2012-04-28 22:02:13 -0700 | [diff] [blame] | 91 | audioEncoder != MediaRecorder.AudioEncoder.HE_AAC) { |
James Dong | 1b7babd | 2010-02-16 14:38:23 -0800 | [diff] [blame] | 92 | throw new IllegalArgumentException("Unsupported audio encodeer " + audioEncoder); |
| 93 | } |
James Dong | 620a4240 | 2010-07-07 14:37:48 -0700 | [diff] [blame] | 94 | return audioEncoderMap.get(audioEncoder); |
James Dong | 1b7babd | 2010-02-16 14:38:23 -0800 | [diff] [blame] | 95 | } |
| 96 | |
James Dong | b05a600 | 2011-09-07 19:31:24 -0700 | [diff] [blame] | 97 | public static int getMinFrameRateForCodec(int codec) { |
| 98 | return getMinOrMaxFrameRateForCodec(codec, false); |
| 99 | } |
| 100 | |
| 101 | public static int getMaxFrameRateForCodec(int codec) { |
| 102 | return getMinOrMaxFrameRateForCodec(codec, true); |
| 103 | } |
| 104 | |
| 105 | private static int getMinOrMaxFrameRateForCodec(int codec, boolean max) { |
| 106 | for (VideoEncoderCap cap: videoEncoders) { |
| 107 | if (cap.mCodec == codec) { |
| 108 | if (max) return cap.mMaxFrameRate; |
| 109 | else return cap.mMinFrameRate; |
| 110 | } |
| 111 | } |
| 112 | // Should never reach here |
| 113 | throw new IllegalArgumentException("Unsupported video codec " + codec); |
| 114 | } |
| 115 | |
James Dong | 1b7babd | 2010-02-16 14:38:23 -0800 | [diff] [blame] | 116 | private MediaProfileReader() {} // Don't call me |
| 117 | |
James Dong | 620a4240 | 2010-07-07 14:37:48 -0700 | [diff] [blame] | 118 | private static void initVideoEncoderMap() { |
James Dong | 1b7babd | 2010-02-16 14:38:23 -0800 | [diff] [blame] | 119 | // video encoders |
James Dong | 620a4240 | 2010-07-07 14:37:48 -0700 | [diff] [blame] | 120 | videoEncoderMap.put(MediaRecorder.VideoEncoder.H263, "h263"); |
| 121 | videoEncoderMap.put(MediaRecorder.VideoEncoder.H264, "h264"); |
| 122 | videoEncoderMap.put(MediaRecorder.VideoEncoder.MPEG_4_SP, "m4v"); |
| 123 | } |
James Dong | 1b7babd | 2010-02-16 14:38:23 -0800 | [diff] [blame] | 124 | |
James Dong | 620a4240 | 2010-07-07 14:37:48 -0700 | [diff] [blame] | 125 | private static void initAudioEncoderMap() { |
James Dong | 1b7babd | 2010-02-16 14:38:23 -0800 | [diff] [blame] | 126 | // audio encoders |
James Dong | 620a4240 | 2010-07-07 14:37:48 -0700 | [diff] [blame] | 127 | audioEncoderMap.put(MediaRecorder.AudioEncoder.AMR_NB, "amrnb"); |
| 128 | audioEncoderMap.put(MediaRecorder.AudioEncoder.AMR_WB, "amrwb"); |
| 129 | audioEncoderMap.put(MediaRecorder.AudioEncoder.AAC, "aac"); |
Dave Burke | ec3f31f | 2012-04-28 22:02:13 -0700 | [diff] [blame] | 130 | audioEncoderMap.put(MediaRecorder.AudioEncoder.HE_AAC, "heaac"); |
Yu Shan Emily Lau | 1619367 | 2009-09-14 16:23:12 -0700 | [diff] [blame] | 131 | } |
| 132 | } |