MediaProfileReader.java revision 34831c9330d4f2993ac1d698a7e176c4b8848b48
1package com.android.mediaframeworktest;
2
3import android.media.MediaRecorder;
4import android.os.SystemProperties;
5import java.util.HashMap;
6
7public class MediaProfileReader {
8
9    public static final HashMap<String, Integer>
10    OUTPUT_FORMAT_TABLE = new HashMap<String, Integer>();
11    public static String MEDIA_ENC_VID = "ro.media.enc.vid.";
12    public static String MEDIA_AUD_VID = "ro.media.enc.aud.";
13    public static String[] VIDEO_ENCODER_PROPERTY = {".width", ".height", ".bps", ".fps",};
14    public static String[] AUDIO_ENCODER_PROPERTY = {".bps", ".hz", ".ch",};
15
16    public static String getVideoCodecProperty() {
17        String s;
18        s = SystemProperties.get("ro.media.enc.vid.codec");
19        return s;
20    }
21
22    public static String getAudioCodecProperty() {
23        String s;
24        s = SystemProperties.get("ro.media.enc.aud.codec");
25        return s;
26    }
27
28    public static String getDeviceType() {
29        // push all the property into one big table
30        String s;
31        s = SystemProperties.get("ro.product.name");
32        return s;
33    }
34
35    public static boolean getWMAEnable() {
36        // push all the property into one big table
37        int wmaEnable = 1;
38        wmaEnable = SystemProperties.getInt("ro.media.dec.aud.wma.enabled",
39                wmaEnable);
40        if (wmaEnable == 1) {
41            return true;
42        } else {
43            return false;
44        }
45    }
46
47    public static boolean getWMVEnable(){
48        int wmvEnable = 1;
49        wmvEnable = SystemProperties.getInt("ro.media.dec.vid.wmv.enabled",
50                wmvEnable);
51        if (wmvEnable == 1) {
52            return true;
53        } else {
54            return false;
55        }
56    }
57
58    public static void createVideoProfileTable() {
59        // push all the property into one big table
60        String encoderType = getVideoCodecProperty();
61        if (encoderType.length() != 0) {
62            String encoder[] = encoderType.split(",");
63            for (int i = 0; i < encoder.length; i++) {
64                for (int j = 0; j < VIDEO_ENCODER_PROPERTY.length; j++) {
65                    String propertyName = MEDIA_ENC_VID + encoder[i] + VIDEO_ENCODER_PROPERTY[j];
66                    String prop = SystemProperties.get(propertyName);
67                    // push to the table
68                    String propRange[] = prop.split(",");
69                    OUTPUT_FORMAT_TABLE.put((encoder[i] + VIDEO_ENCODER_PROPERTY[j] + "_low"),
70                            Integer.parseInt(propRange[0]));
71                    OUTPUT_FORMAT_TABLE.put((encoder[i] + VIDEO_ENCODER_PROPERTY[j] + "_high"),
72                            Integer.parseInt(propRange[1]));
73                }
74
75            }
76        }
77    }
78
79    public static void createAudioProfileTable() {
80        // push all the property into one big table
81        String audioType = getAudioCodecProperty();
82        String encoder[] = audioType.split(",");
83        if (audioType.length() != 0) {
84            for (int i = 0; i < encoder.length; i++) {
85                for (int j = 0; j < AUDIO_ENCODER_PROPERTY.length; j++) {
86                    String propertyName = MEDIA_AUD_VID + encoder[i] + AUDIO_ENCODER_PROPERTY[j];
87                    String prop = SystemProperties.get(propertyName);
88                    // push to the table
89                    String propRange[] = prop.split(",");
90                    OUTPUT_FORMAT_TABLE.put((encoder[i] + AUDIO_ENCODER_PROPERTY[j] + "_low"),
91                            Integer.parseInt(propRange[0]));
92                    OUTPUT_FORMAT_TABLE.put((encoder[i] + AUDIO_ENCODER_PROPERTY[j] + "_high"),
93                            Integer.parseInt(propRange[1]));
94                }
95            }
96        }
97    }
98
99    public static void createEncoderTable(){
100        OUTPUT_FORMAT_TABLE.put("h263", MediaRecorder.VideoEncoder.H263);
101        OUTPUT_FORMAT_TABLE.put("h264", MediaRecorder.VideoEncoder.H264);
102        OUTPUT_FORMAT_TABLE.put("m4v", MediaRecorder.VideoEncoder.MPEG_4_SP);
103        OUTPUT_FORMAT_TABLE.put("amrnb", MediaRecorder.AudioEncoder.AMR_NB);
104        OUTPUT_FORMAT_TABLE.put("amrwb", MediaRecorder.AudioEncoder.AMR_WB);
105        OUTPUT_FORMAT_TABLE.put("aac", MediaRecorder.AudioEncoder.AAC);
106        OUTPUT_FORMAT_TABLE.put("aacplus", MediaRecorder.AudioEncoder.AAC_PLUS);
107        OUTPUT_FORMAT_TABLE.put("eaacplus",
108                MediaRecorder.AudioEncoder.EAAC_PLUS);
109    }
110}
111