Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 66feec9f authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Set initial audio device for AudioTrack and AudioRecord" into oc-dr1-dev

parents d4ef5f1e 2ac76943
Loading
Loading
Loading
Loading
+9 −2
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@
#include <stdlib.h>
#include <math.h>
#include <aaudio/AAudio.h>
#include <aaudio/AAudioTesting.h>
#include "AAudioExampleUtils.h"
#include "AAudioSimpleRecorder.h"

@@ -42,7 +43,7 @@ int main(int argc, char **argv)
    const aaudio_format_t requestedDataFormat = AAUDIO_FORMAT_PCM_I16;
    aaudio_format_t actualDataFormat;

    const int requestedInputChannelCount = 1; // Can affect whether we get a FAST path.
    const int requestedInputChannelCount = 2; // Can affect whether we get a FAST path.

    //aaudio_performance_mode_t requestedPerformanceMode = AAUDIO_PERFORMANCE_MODE_NONE;
    const aaudio_performance_mode_t requestedPerformanceMode = AAUDIO_PERFORMANCE_MODE_LOW_LATENCY;
@@ -61,6 +62,7 @@ int main(int argc, char **argv)
    int16_t *data = nullptr;
    float peakLevel = 0.0;
    int loopCounter = 0;
    int32_t deviceId;

    // Make printf print immediately so that debug info is not stuck
    // in a buffer if we hang or crash.
@@ -68,6 +70,8 @@ int main(int argc, char **argv)

    printf("%s - Monitor input level using AAudio\n", argv[0]);

//    AAudio_setMMapPolicy(AAUDIO_POLICY_ALWAYS);

    recorder.setPerformanceMode(requestedPerformanceMode);
    recorder.setSharingMode(requestedSharingMode);

@@ -79,6 +83,9 @@ int main(int argc, char **argv)
    }
    aaudioStream = recorder.getStream();

    deviceId = AAudioStream_getDeviceId(aaudioStream);
    printf("deviceId = %d\n", deviceId);

    actualSamplesPerFrame = AAudioStream_getSamplesPerFrame(aaudioStream);
    printf("SamplesPerFrame = %d\n", actualSamplesPerFrame);
    actualSampleRate = AAudioStream_getSampleRate(aaudioStream);
@@ -133,7 +140,7 @@ int main(int argc, char **argv)
    framesLeft = framesToRecord;
    while (framesLeft > 0) {
        // Read audio data from the stream.
        const int64_t timeoutNanos = 100 * NANOS_PER_MILLISECOND;
        const int64_t timeoutNanos = 1000 * NANOS_PER_MILLISECOND;
        int minFrames = (framesToRecord < framesPerRead) ? framesToRecord : framesPerRead;
        int actual = AAudioStream_read(aaudioStream, data, minFrames, timeoutNanos);
        if (actual < 0) {
+4 −0
Original line number Diff line number Diff line
@@ -64,6 +64,7 @@ int main(int argc, char **argv)
    int32_t  xRunCount = 0;
    float   *floatData = nullptr;
    int16_t *shortData = nullptr;
    int32_t deviceId;

    // Make printf print immediately so that debug info is not stuck
    // in a buffer if we hang or crash.
@@ -86,6 +87,9 @@ int main(int argc, char **argv)
    aaudioStream = player.getStream();
    // Request stream properties.

    deviceId = AAudioStream_getDeviceId(aaudioStream);
    printf("deviceId = %d\n", deviceId);

    state = AAudioStream_getState(aaudioStream);
    printf("after open, state = %s\n", AAudio_convertStreamStateToText(state));

+12 −3
Original line number Diff line number Diff line
@@ -69,7 +69,8 @@ AudioRecord::AudioRecord(const String16 &opPackageName)
    : mActive(false), mStatus(NO_INIT), mOpPackageName(opPackageName),
      mSessionId(AUDIO_SESSION_ALLOCATE),
      mPreviousPriority(ANDROID_PRIORITY_NORMAL), mPreviousSchedulingGroup(SP_DEFAULT),
      mSelectedDeviceId(AUDIO_PORT_HANDLE_NONE), mPortId(AUDIO_PORT_HANDLE_NONE)
      mSelectedDeviceId(AUDIO_PORT_HANDLE_NONE), mRoutedDeviceId(AUDIO_PORT_HANDLE_NONE),
      mPortId(AUDIO_PORT_HANDLE_NONE)
{
}

@@ -503,7 +504,14 @@ audio_port_handle_t AudioRecord::getRoutedDeviceId() {
    if (mInput == AUDIO_IO_HANDLE_NONE) {
        return AUDIO_PORT_HANDLE_NONE;
    }
    return AudioSystem::getDeviceIdForIo(mInput);
    // if the input stream does not have an active audio patch, use either the device initially
    // selected by audio policy manager or the last routed device
    audio_port_handle_t deviceId = AudioSystem::getDeviceIdForIo(mInput);
    if (deviceId == AUDIO_PORT_HANDLE_NONE) {
        deviceId = mRoutedDeviceId;
    }
    mRoutedDeviceId = deviceId;
    return deviceId;
}

// -------------------------------------------------------------------------
@@ -550,13 +558,14 @@ status_t AudioRecord::openRecord_l(const Modulo<uint32_t> &epoch, const String16
            .channel_mask = mChannelMask,
            .format = mFormat
        };
    mRoutedDeviceId = mSelectedDeviceId;
    status = AudioSystem::getInputForAttr(&mAttributes, &input,
                                        mSessionId,
                                        // FIXME compare to AudioTrack
                                        mClientPid,
                                        mClientUid,
                                        &config,
                                        mFlags, mSelectedDeviceId, &mPortId);
                                        mFlags, &mRoutedDeviceId, &mPortId);

    if (status != NO_ERROR || input == AUDIO_IO_HANDLE_NONE) {
        ALOGE("Could not get audio input for session %d, record source %d, sample rate %u, "
+2 −2
Original line number Diff line number Diff line
@@ -819,7 +819,7 @@ status_t AudioSystem::getOutputForAttr(const audio_attributes_t *attr,
                                        uid_t uid,
                                        const audio_config_t *config,
                                        audio_output_flags_t flags,
                                        audio_port_handle_t selectedDeviceId,
                                        audio_port_handle_t *selectedDeviceId,
                                        audio_port_handle_t *portId)
{
    const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
@@ -863,7 +863,7 @@ status_t AudioSystem::getInputForAttr(const audio_attributes_t *attr,
                                uid_t uid,
                                const audio_config_base_t *config,
                                audio_input_flags_t flags,
                                audio_port_handle_t selectedDeviceId,
                                audio_port_handle_t *selectedDeviceId,
                                audio_port_handle_t *portId)
{
    const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
+11 −2
Original line number Diff line number Diff line
@@ -184,6 +184,7 @@ AudioTrack::AudioTrack()
      mPreviousSchedulingGroup(SP_DEFAULT),
      mPausedPosition(0),
      mSelectedDeviceId(AUDIO_PORT_HANDLE_NONE),
      mRoutedDeviceId(AUDIO_PORT_HANDLE_NONE),
      mPortId(AUDIO_PORT_HANDLE_NONE)
{
    mAttributes.content_type = AUDIO_CONTENT_TYPE_UNKNOWN;
@@ -1226,7 +1227,14 @@ audio_port_handle_t AudioTrack::getRoutedDeviceId() {
    if (mOutput == AUDIO_IO_HANDLE_NONE) {
        return AUDIO_PORT_HANDLE_NONE;
    }
    return AudioSystem::getDeviceIdForIo(mOutput);
    // if the output stream does not have an active audio patch, use either the device initially
    // selected by audio policy manager or the last routed device
    audio_port_handle_t deviceId = AudioSystem::getDeviceIdForIo(mOutput);
    if (deviceId == AUDIO_PORT_HANDLE_NONE) {
        deviceId = mRoutedDeviceId;
    }
    mRoutedDeviceId = deviceId;
    return deviceId;
}

status_t AudioTrack::attachAuxEffect(int effectId)
@@ -1306,10 +1314,11 @@ status_t AudioTrack::createTrack_l()
    config.channel_mask = mChannelMask;
    config.format = mFormat;
    config.offload_info = mOffloadInfoCopy;
    mRoutedDeviceId = mSelectedDeviceId;
    status = AudioSystem::getOutputForAttr(attr, &output,
                                           mSessionId, &streamType, mClientUid,
                                           &config,
                                           mFlags, mSelectedDeviceId, &mPortId);
                                           mFlags, &mRoutedDeviceId, &mPortId);

    if (status != NO_ERROR || output == AUDIO_IO_HANDLE_NONE) {
        ALOGE("Could not get audio output for session %d, stream type %d, usage %d, sample rate %u,"
Loading