115a4d2ffd04dc6c70f2cd17dae12ac6bc14c69abKenny Root/* 215a4d2ffd04dc6c70f2cd17dae12ac6bc14c69abKenny Root * Copyright (C) 2009 The Android Open Source Project 315a4d2ffd04dc6c70f2cd17dae12ac6bc14c69abKenny Root * 415a4d2ffd04dc6c70f2cd17dae12ac6bc14c69abKenny Root * Licensed under the Apache License, Version 2.0 (the "License"); 515a4d2ffd04dc6c70f2cd17dae12ac6bc14c69abKenny Root * you may not use this file except in compliance with the License. 615a4d2ffd04dc6c70f2cd17dae12ac6bc14c69abKenny Root * You may obtain a copy of the License at 715a4d2ffd04dc6c70f2cd17dae12ac6bc14c69abKenny Root * 815a4d2ffd04dc6c70f2cd17dae12ac6bc14c69abKenny Root * http://www.apache.org/licenses/LICENSE-2.0 915a4d2ffd04dc6c70f2cd17dae12ac6bc14c69abKenny Root * 1015a4d2ffd04dc6c70f2cd17dae12ac6bc14c69abKenny Root * Unless required by applicable law or agreed to in writing, software 1115a4d2ffd04dc6c70f2cd17dae12ac6bc14c69abKenny Root * distributed under the License is distributed on an "AS IS" BASIS, 1215a4d2ffd04dc6c70f2cd17dae12ac6bc14c69abKenny Root * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1315a4d2ffd04dc6c70f2cd17dae12ac6bc14c69abKenny Root * See the License for the specific language governing permissions and 1415a4d2ffd04dc6c70f2cd17dae12ac6bc14c69abKenny Root * limitations under the License. 1515a4d2ffd04dc6c70f2cd17dae12ac6bc14c69abKenny Root */ 1615a4d2ffd04dc6c70f2cd17dae12ac6bc14c69abKenny Root 171619367ab823150fa8856d419abe02ceb75886f1Yu Shan Emily Laupackage com.android.mediaframeworktest; 181619367ab823150fa8856d419abe02ceb75886f1Yu Shan Emily Lau 191619367ab823150fa8856d419abe02ceb75886f1Yu Shan Emily Lauimport android.media.MediaRecorder; 201b7babd2cce5bb10adac7b061cf7ba065d480edbJames Dongimport android.media.EncoderCapabilities; 211b7babd2cce5bb10adac7b061cf7ba065d480edbJames Dongimport android.media.EncoderCapabilities.VideoEncoderCap; 221b7babd2cce5bb10adac7b061cf7ba065d480edbJames Dongimport android.media.EncoderCapabilities.AudioEncoderCap; 231b7babd2cce5bb10adac7b061cf7ba065d480edbJames Dongimport android.media.DecoderCapabilities; 241b7babd2cce5bb10adac7b061cf7ba065d480edbJames Dongimport android.media.DecoderCapabilities.VideoDecoder; 251b7babd2cce5bb10adac7b061cf7ba065d480edbJames Dongimport android.media.DecoderCapabilities.AudioDecoder; 261b7babd2cce5bb10adac7b061cf7ba065d480edbJames Dong 271619367ab823150fa8856d419abe02ceb75886f1Yu Shan Emily Lauimport android.os.SystemProperties; 281b7babd2cce5bb10adac7b061cf7ba065d480edbJames Dongimport java.util.List; 291619367ab823150fa8856d419abe02ceb75886f1Yu Shan Emily Lauimport java.util.HashMap; 301619367ab823150fa8856d419abe02ceb75886f1Yu Shan Emily Lau 311b7babd2cce5bb10adac7b061cf7ba065d480edbJames Dongpublic class MediaProfileReader 321b7babd2cce5bb10adac7b061cf7ba065d480edbJames Dong{ 331b7babd2cce5bb10adac7b061cf7ba065d480edbJames Dong private static final List<VideoDecoder> videoDecoders = DecoderCapabilities.getVideoDecoders(); 341b7babd2cce5bb10adac7b061cf7ba065d480edbJames Dong private static final List<AudioDecoder> audioDecoders = DecoderCapabilities.getAudioDecoders(); 351b7babd2cce5bb10adac7b061cf7ba065d480edbJames Dong private static final List<VideoEncoderCap> videoEncoders = EncoderCapabilities.getVideoEncoders(); 361b7babd2cce5bb10adac7b061cf7ba065d480edbJames Dong private static final List<AudioEncoderCap> audioEncoders = EncoderCapabilities.getAudioEncoders(); 37620a4240366f13c3359c6825c92e831563cc11b6James Dong private static final HashMap<Integer, String> videoEncoderMap = new HashMap<Integer, String>(); 38620a4240366f13c3359c6825c92e831563cc11b6James Dong private static final HashMap<Integer, String> audioEncoderMap = new HashMap<Integer, String>(); 391619367ab823150fa8856d419abe02ceb75886f1Yu Shan Emily Lau 401b7babd2cce5bb10adac7b061cf7ba065d480edbJames Dong static { 41620a4240366f13c3359c6825c92e831563cc11b6James Dong initAudioEncoderMap(); 42620a4240366f13c3359c6825c92e831563cc11b6James Dong initVideoEncoderMap(); 431b7babd2cce5bb10adac7b061cf7ba065d480edbJames Dong }; 441619367ab823150fa8856d419abe02ceb75886f1Yu Shan Emily Lau 451b7babd2cce5bb10adac7b061cf7ba065d480edbJames Dong public static List<VideoEncoderCap> getVideoEncoders() { 461b7babd2cce5bb10adac7b061cf7ba065d480edbJames Dong return videoEncoders; 471619367ab823150fa8856d419abe02ceb75886f1Yu Shan Emily Lau } 481619367ab823150fa8856d419abe02ceb75886f1Yu Shan Emily Lau 491b7babd2cce5bb10adac7b061cf7ba065d480edbJames Dong public static List<AudioEncoderCap> getAudioEncoders() { 501b7babd2cce5bb10adac7b061cf7ba065d480edbJames Dong return audioEncoders; 511619367ab823150fa8856d419abe02ceb75886f1Yu Shan Emily Lau } 521619367ab823150fa8856d419abe02ceb75886f1Yu Shan Emily Lau 531619367ab823150fa8856d419abe02ceb75886f1Yu Shan Emily Lau public static String getDeviceType() { 541619367ab823150fa8856d419abe02ceb75886f1Yu Shan Emily Lau // push all the property into one big table 551619367ab823150fa8856d419abe02ceb75886f1Yu Shan Emily Lau String s; 561619367ab823150fa8856d419abe02ceb75886f1Yu Shan Emily Lau s = SystemProperties.get("ro.product.name"); 571619367ab823150fa8856d419abe02ceb75886f1Yu Shan Emily Lau return s; 581619367ab823150fa8856d419abe02ceb75886f1Yu Shan Emily Lau } 591619367ab823150fa8856d419abe02ceb75886f1Yu Shan Emily Lau 60dc1af5befaa21e92c41dd6e173b2d6fb859cdd23Yu Shan Emily Lau public static boolean getWMAEnable() { 611b7babd2cce5bb10adac7b061cf7ba065d480edbJames Dong for (AudioDecoder decoder: audioDecoders) { 621b7babd2cce5bb10adac7b061cf7ba065d480edbJames Dong if (decoder == AudioDecoder.AUDIO_DECODER_WMA) { 631b7babd2cce5bb10adac7b061cf7ba065d480edbJames Dong return true; 641b7babd2cce5bb10adac7b061cf7ba065d480edbJames Dong } 65dc1af5befaa21e92c41dd6e173b2d6fb859cdd23Yu Shan Emily Lau } 661b7babd2cce5bb10adac7b061cf7ba065d480edbJames Dong return false; 67dc1af5befaa21e92c41dd6e173b2d6fb859cdd23Yu Shan Emily Lau } 68dc1af5befaa21e92c41dd6e173b2d6fb859cdd23Yu Shan Emily Lau 69dc1af5befaa21e92c41dd6e173b2d6fb859cdd23Yu Shan Emily Lau public static boolean getWMVEnable(){ 701b7babd2cce5bb10adac7b061cf7ba065d480edbJames Dong for (VideoDecoder decoder: videoDecoders) { 711b7babd2cce5bb10adac7b061cf7ba065d480edbJames Dong if (decoder == VideoDecoder.VIDEO_DECODER_WMV) { 721b7babd2cce5bb10adac7b061cf7ba065d480edbJames Dong return true; 731b7babd2cce5bb10adac7b061cf7ba065d480edbJames Dong } 74dc1af5befaa21e92c41dd6e173b2d6fb859cdd23Yu Shan Emily Lau } 751b7babd2cce5bb10adac7b061cf7ba065d480edbJames Dong return false; 76dc1af5befaa21e92c41dd6e173b2d6fb859cdd23Yu Shan Emily Lau } 77dc1af5befaa21e92c41dd6e173b2d6fb859cdd23Yu Shan Emily Lau 781b7babd2cce5bb10adac7b061cf7ba065d480edbJames Dong public static String getVideoCodecName(int videoEncoder) { 791b7babd2cce5bb10adac7b061cf7ba065d480edbJames Dong if (videoEncoder != MediaRecorder.VideoEncoder.H263 && 801b7babd2cce5bb10adac7b061cf7ba065d480edbJames Dong videoEncoder != MediaRecorder.VideoEncoder.H264 && 811b7babd2cce5bb10adac7b061cf7ba065d480edbJames Dong videoEncoder != MediaRecorder.VideoEncoder.MPEG_4_SP) { 821b7babd2cce5bb10adac7b061cf7ba065d480edbJames Dong throw new IllegalArgumentException("Unsupported video encoder " + videoEncoder); 831619367ab823150fa8856d419abe02ceb75886f1Yu Shan Emily Lau } 84620a4240366f13c3359c6825c92e831563cc11b6James Dong return videoEncoderMap.get(videoEncoder); 851619367ab823150fa8856d419abe02ceb75886f1Yu Shan Emily Lau } 861619367ab823150fa8856d419abe02ceb75886f1Yu Shan Emily Lau 871b7babd2cce5bb10adac7b061cf7ba065d480edbJames Dong public static String getAudioCodecName(int audioEncoder) { 881b7babd2cce5bb10adac7b061cf7ba065d480edbJames Dong if (audioEncoder != MediaRecorder.AudioEncoder.AMR_NB && 891b7babd2cce5bb10adac7b061cf7ba065d480edbJames Dong audioEncoder != MediaRecorder.AudioEncoder.AMR_WB && 901b7babd2cce5bb10adac7b061cf7ba065d480edbJames Dong audioEncoder != MediaRecorder.AudioEncoder.AAC && 911b7babd2cce5bb10adac7b061cf7ba065d480edbJames Dong audioEncoder != MediaRecorder.AudioEncoder.AAC_PLUS && 921b7babd2cce5bb10adac7b061cf7ba065d480edbJames Dong audioEncoder != MediaRecorder.AudioEncoder.EAAC_PLUS) { 931b7babd2cce5bb10adac7b061cf7ba065d480edbJames Dong throw new IllegalArgumentException("Unsupported audio encodeer " + audioEncoder); 941619367ab823150fa8856d419abe02ceb75886f1Yu Shan Emily Lau } 95620a4240366f13c3359c6825c92e831563cc11b6James Dong return audioEncoderMap.get(audioEncoder); 961619367ab823150fa8856d419abe02ceb75886f1Yu Shan Emily Lau } 971619367ab823150fa8856d419abe02ceb75886f1Yu Shan Emily Lau 981b7babd2cce5bb10adac7b061cf7ba065d480edbJames Dong private MediaProfileReader() {} // Don't call me 991b7babd2cce5bb10adac7b061cf7ba065d480edbJames Dong 100620a4240366f13c3359c6825c92e831563cc11b6James Dong private static void initVideoEncoderMap() { 1011b7babd2cce5bb10adac7b061cf7ba065d480edbJames Dong // video encoders 102620a4240366f13c3359c6825c92e831563cc11b6James Dong videoEncoderMap.put(MediaRecorder.VideoEncoder.H263, "h263"); 103620a4240366f13c3359c6825c92e831563cc11b6James Dong videoEncoderMap.put(MediaRecorder.VideoEncoder.H264, "h264"); 104620a4240366f13c3359c6825c92e831563cc11b6James Dong videoEncoderMap.put(MediaRecorder.VideoEncoder.MPEG_4_SP, "m4v"); 105620a4240366f13c3359c6825c92e831563cc11b6James Dong } 1061b7babd2cce5bb10adac7b061cf7ba065d480edbJames Dong 107620a4240366f13c3359c6825c92e831563cc11b6James Dong private static void initAudioEncoderMap() { 1081b7babd2cce5bb10adac7b061cf7ba065d480edbJames Dong // audio encoders 109620a4240366f13c3359c6825c92e831563cc11b6James Dong audioEncoderMap.put(MediaRecorder.AudioEncoder.AMR_NB, "amrnb"); 110620a4240366f13c3359c6825c92e831563cc11b6James Dong audioEncoderMap.put(MediaRecorder.AudioEncoder.AMR_WB, "amrwb"); 111620a4240366f13c3359c6825c92e831563cc11b6James Dong audioEncoderMap.put(MediaRecorder.AudioEncoder.AAC, "aac"); 112620a4240366f13c3359c6825c92e831563cc11b6James Dong audioEncoderMap.put(MediaRecorder.AudioEncoder.AAC_PLUS, "aacplus"); 113620a4240366f13c3359c6825c92e831563cc11b6James Dong audioEncoderMap.put(MediaRecorder.AudioEncoder.EAAC_PLUS, "eaacplus"); 1141619367ab823150fa8856d419abe02ceb75886f1Yu Shan Emily Lau } 1151619367ab823150fa8856d419abe02ceb75886f1Yu Shan Emily Lau} 116