您的位置:首页 > 其它

Cubietruck---31.蓝牙耳机与有线耳机的声音输出

2016-07-01 19:26 627 查看
getOutput的过程

./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, ...);

}

hardware/libhardware_legacy/audio/audio_policy_hal.cpp:ap_get_output(146)

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,);

}

hardware/libhardware_legacy/audio/AudioPolicyManagerBase.cpp:getDeviceForStrategy(2214), STRATEGY_MEDIA

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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: