1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
|
/*
* Copyright (C) 2009 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.mediaframeworktest;
import android.media.MediaRecorder;
import android.media.EncoderCapabilities;
import android.media.EncoderCapabilities.VideoEncoderCap;
import android.media.EncoderCapabilities.AudioEncoderCap;
import android.media.DecoderCapabilities;
import android.media.DecoderCapabilities.VideoDecoder;
import android.media.DecoderCapabilities.AudioDecoder;
import android.os.SystemProperties;
import java.util.List;
import java.util.HashMap;
public class MediaProfileReader
{
private static final List<VideoDecoder> videoDecoders = DecoderCapabilities.getVideoDecoders();
private static final List<AudioDecoder> audioDecoders = DecoderCapabilities.getAudioDecoders();
private static final List<VideoEncoderCap> videoEncoders = EncoderCapabilities.getVideoEncoders();
private static final List<AudioEncoderCap> audioEncoders = EncoderCapabilities.getAudioEncoders();
private static final HashMap<Integer, String> videoEncoderMap = new HashMap<Integer, String>();
private static final HashMap<Integer, String> audioEncoderMap = new HashMap<Integer, String>();
static {
initAudioEncoderMap();
initVideoEncoderMap();
};
public static List<VideoEncoderCap> getVideoEncoders() {
return videoEncoders;
}
public static List<AudioEncoderCap> getAudioEncoders() {
return audioEncoders;
}
public static String getDeviceType() {
// push all the property into one big table
String s;
s = SystemProperties.get("ro.product.name");
return s;
}
public static boolean getWMAEnable() {
for (AudioDecoder decoder: audioDecoders) {
if (decoder == AudioDecoder.AUDIO_DECODER_WMA) {
return true;
}
}
return false;
}
public static boolean getWMVEnable(){
for (VideoDecoder decoder: videoDecoders) {
if (decoder == VideoDecoder.VIDEO_DECODER_WMV) {
return true;
}
}
return false;
}
public static String getVideoCodecName(int videoEncoder) {
if (videoEncoder != MediaRecorder.VideoEncoder.H263 &&
videoEncoder != MediaRecorder.VideoEncoder.H264 &&
videoEncoder != MediaRecorder.VideoEncoder.MPEG_4_SP) {
throw new IllegalArgumentException("Unsupported video encoder " + videoEncoder);
}
return videoEncoderMap.get(videoEncoder);
}
public static String getAudioCodecName(int audioEncoder) {
if (audioEncoder != MediaRecorder.AudioEncoder.AMR_NB &&
audioEncoder != MediaRecorder.AudioEncoder.AMR_WB &&
audioEncoder != MediaRecorder.AudioEncoder.AAC &&
audioEncoder != MediaRecorder.AudioEncoder.HE_AAC &&
audioEncoder != MediaRecorder.AudioEncoder.AAC_ELD) {
throw new IllegalArgumentException("Unsupported audio encodeer " + audioEncoder);
}
return audioEncoderMap.get(audioEncoder);
}
public static int getMinFrameRateForCodec(int codec) {
return getMinOrMaxFrameRateForCodec(codec, false);
}
public static int getMaxFrameRateForCodec(int codec) {
return getMinOrMaxFrameRateForCodec(codec, true);
}
private static int getMinOrMaxFrameRateForCodec(int codec, boolean max) {
for (VideoEncoderCap cap: videoEncoders) {
if (cap.mCodec == codec) {
if (max) return cap.mMaxFrameRate;
else return cap.mMinFrameRate;
}
}
// Should never reach here
throw new IllegalArgumentException("Unsupported video codec " + codec);
}
private MediaProfileReader() {} // Don't call me
private static void initVideoEncoderMap() {
// video encoders
videoEncoderMap.put(MediaRecorder.VideoEncoder.H263, "h263");
videoEncoderMap.put(MediaRecorder.VideoEncoder.H264, "h264");
videoEncoderMap.put(MediaRecorder.VideoEncoder.MPEG_4_SP, "m4v");
}
private static void initAudioEncoderMap() {
// audio encoders
audioEncoderMap.put(MediaRecorder.AudioEncoder.AMR_NB, "amrnb");
audioEncoderMap.put(MediaRecorder.AudioEncoder.AMR_WB, "amrwb");
audioEncoderMap.put(MediaRecorder.AudioEncoder.AAC, "aac");
audioEncoderMap.put(MediaRecorder.AudioEncoder.HE_AAC, "heaac");
audioEncoderMap.put(MediaRecorder.AudioEncoder.AAC_ELD, "aaceld");
}
}
|