Cubietruck---31.蓝牙耳机与有线耳机的声音输出
来源:互联网 发布:安卓应用源码 编辑:程序博客网 时间:2024/04/28 04:07
getOutput的过程
./frameworks/av/services/audioflinger/AudioPolicyService.cpp
./hardware/libhardware_legacy/audio/audio_policy_hal.cpp
./hardware/libhardware_legacy/audio/AudioPolicyManagerBase.cpp
播放声音
./frameworks/base/media/java/android/media/SoundPool.java
SoundPool::play
SoundChannel::play
一.数据的写入
frameworks/av/services/audioflinger/AudioFlinger.cpp
frameworks/av/media/libnbaio/AudioStreamOutSink.cpp
1.2 耳机的输出
1.1 蓝牙耳机的输出
external/bluetooth/bluedroid/audio_a2dp_hw/audio_a2dp_hw.c
蓝牙耳机的声音播放
在frameworks/av/services/audioflinger/AudioPolicyService.cpp中
hardware/libhardware_legacy/audio/audio_policy_hal.cpp:ap_get_output(146)
hardware/libhardware_legacy/audio/AudioPolicyManagerBase.cpp:getDeviceForStrategy(2214), STRATEGY_MEDIA
I/cong ( 1346): hardware/libhardware_legacy/audio/AudioPolicyManagerBase.cpp:getA2dpOutput(1919),
I/cong ( 1346): hardware/libhardware_legacy/audio/AudioPolicyManagerBase.cpp:getOutput(522), getOutput() stream 1, samplingRate 0, format 0, channelMask 3, flags 0
I/cong ( 1346): hardware/libhardware_legacy/audio/AudioPolicyManagerBase.cpp:getOutput(614), getOutput() returns output 6
I/cong ( 1346): frameworks/av/services/audioflinger/AudioPolicyService.cpp:getOutput(228), getOutput() tid 2538
./frameworks/av/services/audioflinger/AudioPolicyService.cpp
- audio_io_handle_t AudioPolicyService::getOutput(audio_stream_type_t stream...)
- {
- return mpAudioPolicy->get_output(mpAudioPolicy, stream, samplingRate, format, channelMask, flags);
- }
./hardware/libhardware_legacy/audio/audio_policy_hal.cpp
- static audio_io_handle_t ap_get_output(struct audio_policy *pol,
- audio_stream_type_t stream,
- uint32_t sampling_rate,
- audio_format_t format,
- audio_channel_mask_t channelMask,
- audio_output_flags_t flags)
- {
- struct legacy_audio_policy *lap = to_lap(pol);
- dbmsg("tid %d", gettid());
- return lap->apm->getOutput((AudioSystem::stream_type)stream,
- sampling_rate, (int) format, channelMask,
- (AudioSystem::output_flags)flags);
- }
./hardware/libhardware_legacy/audio/AudioPolicyManagerBase.cpp
- audio_io_handle_t AudioPolicyManagerBase::getOutput(AudioSystem::stream_type stream,
- uint32_t samplingRate,
- uint32_t format,
- uint32_t channelMask,
- AudioSystem::output_flags flags)
- {
- audio_io_handle_t output = 0;
- uint32_t latency = 0;
- routing_strategy strategy = getStrategy((AudioSystem::stream_type)stream);
- audio_devices_t device = getDeviceForStrategy(strategy, false /*fromCache*/);
- // open a direct output if required by specified parameters
- IOProfile *profile = getProfileForDirectOutput(device,
- samplingRate,
- format,
- channelMask,
- (audio_output_flags_t)flags);
- if (profile != NULL) {
- dbmsg("getOutput() opening direct output device %x", device);
- AudioOutputDescriptor *outputDesc = new AudioOutputDescriptor(profile);
- outputDesc->mDevice = device;
- outputDesc->mSamplingRate = samplingRate;
- outputDesc->mFormat = (audio_format_t)format;
- outputDesc->mChannelMask = (audio_channel_mask_t)channelMask;
- outputDesc->mLatency = 0;
- outputDesc->mFlags = (audio_output_flags_t)(flags | AUDIO_OUTPUT_FLAG_DIRECT);;
- outputDesc->mRefCount[stream] = 0;
- outputDesc->mStopTime[stream] = 0;
- output = mpClientInterface->openOutput(profile->mModule->mHandle,
- &outputDesc->mDevice,
- &outputDesc->mSamplingRate,
- &outputDesc->mFormat,
- &outputDesc->mChannelMask,
- &outputDesc->mLatency,
- outputDesc->mFlags);
- // only accept an output with the requested parameters
- if (output == 0 ||
- (samplingRate != 0 && samplingRate != outputDesc->mSamplingRate) ||
- (format != 0 && format != outputDesc->mFormat) ||
- (channelMask != 0 && channelMask != outputDesc->mChannelMask)) {
- dbmsg("getOutput() failed opening direct output: output %d samplingRate %d %d,"
- "format %d %d, channelMask %04x %04x", output, samplingRate,
- outputDesc->mSamplingRate, format, outputDesc->mFormat, channelMask,
- outputDesc->mChannelMask);
- if (output != 0) {
- mpClientInterface->closeOutput(output);
- }
- delete outputDesc;
- return 0;
- }
- addOutput(output, outputDesc);
- dbmsg("getOutput() returns direct output %d", output);
- return output;
- }
- // ignoring channel mask due to downmix capability in mixer
- // open a non direct output
- // get which output is suitable for the specified stream. The actual routing change will happen
- // when startOutput() will be called
- SortedVector<audio_io_handle_t> outputs = getOutputsForDevice(device, mOutputs);
- output = selectOutput(outputs, flags);
- ALOGW_IF((output ==0), "getOutput() could not find output for stream %d, samplingRate %d,"
- "format %d, channels %x, flags %x", stream, samplingRate, format, channelMask, flags);
- dbmsg("getOutput() returns output %d", output);
- return output;
- }
播放声音
./frameworks/base/media/java/android/media/SoundPool.java
SoundPool::play
SoundChannel::play
一.数据的写入
frameworks/av/services/audioflinger/AudioFlinger.cpp
- void AudioFlinger::PlaybackThread::threadLoop_write()
- {
- ssize_t framesWritten = mNormalSink->write(mMixBuffer, count);
- }
frameworks/av/media/libnbaio/AudioStreamOutSink.cpp
- ssize_t AudioStreamOutSink::write(const void *buffer, size_t count)
- {
- ssize_t ret = mStream->write(mStream, buffer, count << mBitShift);
- return ret;
- }
1.2 耳机的输出
1.1 蓝牙耳机的输出
external/bluetooth/bluedroid/audio_a2dp_hw/audio_a2dp_hw.c
- static ssize_t out_write(struct audio_stream_out *stream, const void* buffer,
- size_t bytes)
- {
- struct a2dp_stream_out *out = (struct a2dp_stream_out *)stream;
- sent = skt_write(out->audio_fd, buffer, bytes);
- return sent;
- }
- static int skt_write(int fd, const void *p, size_t len)
- {
- int sent;
- struct pollfd pfd;
- pfd.fd = fd;
- pfd.events = POLLOUT;
- if (poll(&pfd, 1, 500) == 0)
- return 0;
- sent = send(fd, p, len, MSG_NOSIGNAL);
-
- return sent;
- }
蓝牙耳机的声音播放
在frameworks/av/services/audioflinger/AudioPolicyService.cpp中
- audio_io_handle_t AudioPolicyService::getOutput(audio_stream_type_t stream,...)
- {
- if (mpAudioPolicy == NULL) {
- return 0;
- }
- Mutex::Autolock _l(mLock);
- return mpAudioPolicy->get_output(mpAudioPolicy, stream, ...);
- }
- static audio_io_handle_t ap_get_output(struct audio_policy *pol, audio_stream_type_t stream,...)
- {
- struct legacy_audio_policy *lap = to_lap(pol);
- return lap->apm->getOutput((AudioSystem::stream_type)stream,);
- }
- audio_io_handle_t AudioPolicyManagerBase::getOutput(AudioSystem::stream_type stream, )
- {
- routing_strategy strategy = getStrategy((AudioSystem::stream_type)stream);
- audio_devices_t device = getDeviceForStrategy(strategy, false );
- IOProfile *profile = getProfileForDirectOutput(device,...);
- if (profile != NULL) {
- }
- SortedVector<audio_io_handle_t> outputs = getOutputsForDevice(device, mOutputs);
- output = selectOutput(outputs, flags);
- return output;
- }
I/cong ( 1346): hardware/libhardware_legacy/audio/AudioPolicyManagerBase.cpp:getA2dpOutput(1919),
I/cong ( 1346): hardware/libhardware_legacy/audio/AudioPolicyManagerBase.cpp:getOutput(522), getOutput() stream 1, samplingRate 0, format 0, channelMask 3, flags 0
I/cong ( 1346): hardware/libhardware_legacy/audio/AudioPolicyManagerBase.cpp:getOutput(614), getOutput() returns output 6
I/cong ( 1346): frameworks/av/services/audioflinger/AudioPolicyService.cpp:getOutput(228), getOutput() tid 2538
0 0
- Cubietruck---31.蓝牙耳机与有线耳机的声音输出
- Cubietruck---30.蓝牙耳机与有线耳机的切换
- android 判断有线耳机、蓝牙耳机连接
- 监听有线/蓝牙耳机的插入与拔出,电话的状态及拦截-Android
- Android 蓝牙(有线)耳机监听的问题
- Android如何监听蓝牙耳机和有线耳机的插拔
- 音频输入在有线耳机和蓝牙耳机直接切换时候mediaplayer的时间戳流程
- 关于蓝牙耳机通话,切换声音路径
- 蓝牙耳机
- 蓝牙耳机
- 蓝牙耳机
- 蓝牙耳机
- 蓝牙耳机与手机相连
- IPhone4S与蓝牙耳机连接
- Android RecognizerIntent与蓝牙耳机
- ipad耳机有声音,拔下耳机没声音的解决办法
- [WFD]连接wifi display,插入有线耳机,声音应该走耳机端
- Android与蓝牙耳机建立连接的分析
- Cubietruck---30.蓝牙耳机与有线耳机的切换
- 开发工具
- 关于ESP8266UART转WIFI的速度测试
- The Stein-Lov´asz Theorem 定理
- 考试期间有感
- Cubietruck---31.蓝牙耳机与有线耳机的声音输出
- hbase分布式集群搭建
- 应用端连接codis 3.0.3提示Proxy list is empty的处理
- 使用CSDN-CODE&C-IDE搭建tomcat环境
- 2.1 穷竭搜索(DFS)
- bean标签的解析及注册(三)AbstractBeanDefinition属性
- android开发--1.Android 源码下载
- 软件设计 - 面向对象设计原则
- android开发---2.eclipse与ndk adb等工具的使用