相关文件
MediaStore.java
定义多媒体文件类型type值
###查看安装的声卡
1|root@android:/ # cat /proc/asound/cards
0 [tef6638media ]: tef6638_media - tef6638_media
tef6638_media
1 [tef6638navi ]: tef6638_navi - tef6638_navi
tef6638_navi
2 [tef6638tts ]: tef6638_tts - tef6638_tts
tef6638_tts
3 [nforebtcodec ]: nfore_bt_codec - nfore_bt_codec
nfore_bt_codec
tinyalsa
源码路径external\tinyalsa
audio音频种类
frameworks\base\media\java\android\media\AudioSystem.java
/* These values must be kept in sync with system/audio.h */
/*
* If these are modified, please also update Settings.System.VOLUME_SETTINGS
* and attrs.xml and AudioManager.java.
*/
/* The default audio stream */
public static final int STREAM_DEFAULT = -1;
/* The audio stream for phone calls */
public static final int STREAM_VOICE_CALL = 0;
/* The audio stream for system sounds */
public static final int STREAM_SYSTEM = 1;
/* The audio stream for the phone ring and message alerts */
public static final int STREAM_RING = 2;
/* The audio stream for music playback */
public static final int STREAM_MUSIC = 3;
/* The audio stream for alarms */
public static final int STREAM_ALARM = 4;
/* The audio stream for notifications */
public static final int STREAM_NOTIFICATION = 5;
/* @hide The audio stream for phone calls when connected on bluetooth */
public static final int STREAM_BLUETOOTH_SCO = 6;
/* @hide The audio stream for enforced system sounds in certain countries (e.g camera in Japan) */
public static final int STREAM_SYSTEM_ENFORCED = 7;
/* @hide The audio stream for DTMF tones */
public static final int STREAM_DTMF = 8;
/* @hide The audio stream for text to speech (TTS) */
public static final int STREAM_TTS = 9;
不同类型的音频音量调节范围也是不同的
frameworks\base\services\core\java\com\android\server\audio\AudioService.java
/** Maximum volume index values for audio streams */
/// M: Modify the max stream volume @{
private static int[] MAX_STREAM_VOLUME = new int[] {
7, // STREAM_VOICE_CALL
15, // STREAM_SYSTEM
15, // STREAM_RING
15, // STREAM_MUSIC
15, // STREAM_ALARM
15, // STREAM_NOTIFICATION
15, // STREAM_BLUETOOTH_SCO
15, // STREAM_SYSTEM_ENFORCED
15, // STREAM_DTMF
15 // STREAM_TTS
};
AudioTrack
相关文件路径:
frameworks\base\media\java\android\media\AudioTrack.java
frameworks\base\core\jni\android_media_AudioTrack.cpp
frameworks\av\media\libmedia\AudioTrack.cpp
同时支持static和streaming两种数据模式。
getMinBufferSize(int sampleRateInHz, int channelConfig, int audioFormat),最小size取决于采样数、声道数、采样深度这三个属性。
AudioTrack通过createTrack_l函数调用AudioFlinger的createTrack得到IAudioTrack,IAudioTrack是与AudioTrack通信的通道
status_t AudioTrack::createTrack_l(){
const sp<IAudioFlinger>& audioFlinger = AudioSystem::get_audio_flinger();
if (audioFlinger == 0) {
ALOGE("Could not get audioflinger");
return NO_INIT;
}
......
sp<IAudioTrack> track = audioFlinger->createTrack(streamType,
mSampleRate,
mFormat,
mChannelMask,
&temp,
&trackFlags,
mSharedBuffer,
output,
tid,
&mSessionId,
mClientUid,
&status);
ALOGE_IF(originalSessionId != AUDIO_SESSION_ALLOCATE && mSessionId != originalSessionId,
"session ID changed from %d to %d", originalSessionId, mSessionId);
if (status != NO_ERROR) {
ALOGE("AudioFlinger could not create track, status: %d", status);
goto release;
}
ALOG_ASSERT(track != 0);
......
}
AudioPolicyService
stream type 和 strategy对应关系
路由选择,优先级排列
1.Flags与要求相似度最高的Output
2.Primary Output
3.如果上面两种都找不到,则默认返回第一个Output
这样AudioPolicyService就完成了整个路由路径的选择,AudioTrack则是通过AudioSystem::getOutput间接调用到AudioPolicyService提供的功能
AudioFlinger
在AudioFlinger中起到关键作用,PlayBackThread和AudioMixer