MediaProfileReader.java revision 620a4240366f13c3359c6825c92e831563cc11b6
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
17package com.android.mediaframeworktest;
18
19import android.media.MediaRecorder;
20import android.media.EncoderCapabilities;
21import android.media.EncoderCapabilities.VideoEncoderCap;
22import android.media.EncoderCapabilities.AudioEncoderCap;
23import android.media.DecoderCapabilities;
24import android.media.DecoderCapabilities.VideoDecoder;
25import android.media.DecoderCapabilities.AudioDecoder;
26
27import android.os.SystemProperties;
28import java.util.List;
29import java.util.HashMap;
30
31public 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> videoEncoderMap = new HashMap<Integer, String>();
38    private static final HashMap<Integer, String> audioEncoderMap = new HashMap<Integer, String>();
39
40    static {
41        initAudioEncoderMap();
42        initVideoEncoderMap();
43    };
44
45    public static List<VideoEncoderCap> getVideoEncoders() {
46        return videoEncoders;
47    }
48
49    public static List<AudioEncoderCap> getAudioEncoders() {
50        return audioEncoders;
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
60    public static boolean getWMAEnable() {
61        for (AudioDecoder decoder: audioDecoders) {
62            if (decoder == AudioDecoder.AUDIO_DECODER_WMA) {
63                return true;
64            }
65        }
66        return false;
67    }
68
69    public static boolean getWMVEnable(){
70        for (VideoDecoder decoder: videoDecoders) {
71            if (decoder == VideoDecoder.VIDEO_DECODER_WMV) {
72                return true;
73            }
74        }
75        return false;
76    }
77
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);
83        }
84        return videoEncoderMap.get(videoEncoder);
85    }
86
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 &&
91            audioEncoder != MediaRecorder.AudioEncoder.AAC_PLUS &&
92            audioEncoder != MediaRecorder.AudioEncoder.EAAC_PLUS) {
93            throw new IllegalArgumentException("Unsupported audio encodeer " + audioEncoder);
94        }
95        return audioEncoderMap.get(audioEncoder);
96    }
97
98    private MediaProfileReader() {} // Don't call me
99
100    private static void initVideoEncoderMap() {
101        // video encoders
102        videoEncoderMap.put(MediaRecorder.VideoEncoder.H263, "h263");
103        videoEncoderMap.put(MediaRecorder.VideoEncoder.H264, "h264");
104        videoEncoderMap.put(MediaRecorder.VideoEncoder.MPEG_4_SP, "m4v");
105    }
106
107    private static void initAudioEncoderMap() {
108        // audio encoders
109        audioEncoderMap.put(MediaRecorder.AudioEncoder.AMR_NB, "amrnb");
110        audioEncoderMap.put(MediaRecorder.AudioEncoder.AMR_WB, "amrwb");
111        audioEncoderMap.put(MediaRecorder.AudioEncoder.AAC, "aac");
112        audioEncoderMap.put(MediaRecorder.AudioEncoder.AAC_PLUS, "aacplus");
113        audioEncoderMap.put(MediaRecorder.AudioEncoder.EAAC_PLUS, "eaacplus");
114    }
115}
116