Loading services/oboeservice/AAudioEndpointManager.cpp +28 −13 Original line number Diff line number Diff line Loading @@ -51,13 +51,13 @@ std::string AAudioEndpointManager::dump() const { size_t inputs = mInputs.size(); result << "Inputs: " << inputs << "\n"; for (const auto &input : mInputs) { result << " Input(" << input.first << ", " << input.second << ")\n"; result << " Input(" << input << ")\n"; } size_t outputs = mOutputs.size(); result << "Outputs: " << outputs << "\n"; for (const auto &output : mOutputs) { result << " Output(" << output.first << ", " << output.second << ")\n"; result << " Output(" << output << ")\n"; } if (isLocked) { Loading @@ -66,27 +66,40 @@ std::string AAudioEndpointManager::dump() const { return result.str(); } AAudioServiceEndpoint *AAudioEndpointManager::openEndpoint(AAudioService &audioService, int32_t deviceId, aaudio_direction_t direction) { AAudioServiceEndpoint *AAudioEndpointManager::openEndpoint(AAudioService &audioService, const AAudioStreamConfiguration& configuration, aaudio_direction_t direction) { AAudioServiceEndpoint *endpoint = nullptr; AAudioServiceEndpointCapture *capture = nullptr; AAudioServiceEndpointPlay *player = nullptr; std::lock_guard<std::mutex> lock(mLock); // Try to find an existing endpoint. switch (direction) { case AAUDIO_DIRECTION_INPUT: endpoint = mInputs[deviceId]; for (AAudioServiceEndpoint *ep : mInputs) { if (ep->matches(configuration)) { endpoint = ep; break; } } break; case AAUDIO_DIRECTION_OUTPUT: endpoint = mOutputs[deviceId]; for (AAudioServiceEndpoint *ep : mOutputs) { if (ep->matches(configuration)) { endpoint = ep; break; } } break; default: assert(false); // There are only two possible directions. break; } ALOGD("AAudioEndpointManager::openEndpoint(), found %p for device = %d, dir = %d", endpoint, deviceId, (int)direction); endpoint, configuration.getDeviceId(), (int)direction); // If we can't find an existing one then open a new one. if (endpoint == nullptr) { Loading @@ -105,7 +118,7 @@ AAudioServiceEndpoint *AAudioEndpointManager::openEndpoint(AAudioService &audioS } if (endpoint != nullptr) { aaudio_result_t result = endpoint->open(deviceId); aaudio_result_t result = endpoint->open(configuration); if (result != AAUDIO_OK) { ALOGE("AAudioEndpointManager::findEndpoint(), open failed"); delete endpoint; Loading @@ -113,17 +126,17 @@ AAudioServiceEndpoint *AAudioEndpointManager::openEndpoint(AAudioService &audioS } else { switch(direction) { case AAUDIO_DIRECTION_INPUT: mInputs[deviceId] = capture; mInputs.push_back(capture); break; case AAUDIO_DIRECTION_OUTPUT: mOutputs[deviceId] = player; mOutputs.push_back(player); break; default: break; } } ALOGD("AAudioEndpointManager::openEndpoint(), created %p for device = %d, dir = %d", endpoint, deviceId, (int)direction); endpoint, configuration.getDeviceId(), (int)direction); } if (endpoint != nullptr) { Loading Loading @@ -156,10 +169,12 @@ void AAudioEndpointManager::closeEndpoint(AAudioServiceEndpoint *serviceEndpoint switch (direction) { case AAUDIO_DIRECTION_INPUT: mInputs.erase(deviceId); mInputs.erase( std::remove(mInputs.begin(), mInputs.end(), serviceEndpoint), mInputs.end()); break; case AAUDIO_DIRECTION_OUTPUT: mOutputs.erase(deviceId); mOutputs.erase( std::remove(mOutputs.begin(), mOutputs.end(), serviceEndpoint), mOutputs.end()); break; default: break; Loading services/oboeservice/AAudioEndpointManager.h +3 −3 Original line number Diff line number Diff line Loading @@ -54,7 +54,7 @@ public: * @return endpoint or nullptr */ AAudioServiceEndpoint *openEndpoint(android::AAudioService &audioService, int32_t deviceId, const AAudioStreamConfiguration& configuration, aaudio_direction_t direction); void closeEndpoint(AAudioServiceEndpoint *serviceEndpoint); Loading @@ -63,8 +63,8 @@ private: mutable std::mutex mLock; std::map<int32_t, AAudioServiceEndpointCapture *> mInputs; std::map<int32_t, AAudioServiceEndpointPlay *> mOutputs; std::vector<AAudioServiceEndpointCapture *> mInputs; std::vector<AAudioServiceEndpointPlay *> mOutputs; }; Loading services/oboeservice/AAudioServiceEndpoint.cpp +23 −3 Original line number Diff line number Diff line Loading @@ -45,15 +45,18 @@ using namespace aaudio; // TODO just import names needed #define DEFAULT_BUFFER_CAPACITY (48 * 8) // Set up an EXCLUSIVE MMAP stream that will be shared. aaudio_result_t AAudioServiceEndpoint::open(int32_t deviceId) { mRequestedDeviceId = deviceId; aaudio_result_t AAudioServiceEndpoint::open(const AAudioStreamConfiguration& configuration) { mRequestedDeviceId = configuration.getDeviceId(); mStreamInternal = getStreamInternal(); AudioStreamBuilder builder; builder.setSharingMode(AAUDIO_SHARING_MODE_EXCLUSIVE); // Don't fall back to SHARED because that would cause recursion. builder.setSharingModeMatchRequired(true); builder.setDeviceId(deviceId); builder.setDeviceId(mRequestedDeviceId); builder.setFormat(configuration.getAudioFormat()); builder.setSampleRate(configuration.getSampleRate()); builder.setSamplesPerFrame(configuration.getSamplesPerFrame()); builder.setDirection(getDirection()); builder.setBufferCapacity(DEFAULT_BUFFER_CAPACITY); Loading Loading @@ -139,3 +142,20 @@ void AAudioServiceEndpoint::disconnectRegisteredStreams() { } mRegisteredStreams.clear(); } bool AAudioServiceEndpoint::matches(const AAudioStreamConfiguration& configuration) { if (configuration.getDeviceId() != AAUDIO_UNSPECIFIED && configuration.getDeviceId() != mStreamInternal->getDeviceId()) { return false; } if (configuration.getSampleRate() != AAUDIO_UNSPECIFIED && configuration.getSampleRate() != mStreamInternal->getSampleRate()) { return false; } if (configuration.getSamplesPerFrame() != AAUDIO_UNSPECIFIED && configuration.getSamplesPerFrame() != mStreamInternal->getSamplesPerFrame()) { return false; } return true; } services/oboeservice/AAudioServiceEndpoint.h +3 −1 Original line number Diff line number Diff line Loading @@ -36,7 +36,7 @@ class AAudioServiceEndpoint { public: virtual ~AAudioServiceEndpoint() = default; virtual aaudio_result_t open(int32_t deviceId); virtual aaudio_result_t open(const AAudioStreamConfiguration& configuration); int32_t getSampleRate() const { return mStreamInternal->getSampleRate(); } int32_t getSamplesPerFrame() const { return mStreamInternal->getSamplesPerFrame(); } Loading Loading @@ -67,6 +67,8 @@ public: mReferenceCount = count; } bool matches(const AAudioStreamConfiguration& configuration); virtual AudioStreamInternal *getStreamInternal() = 0; std::atomic<bool> mCallbackEnabled; Loading services/oboeservice/AAudioServiceEndpointCapture.cpp +2 −2 Original line number Diff line number Diff line Loading @@ -42,8 +42,8 @@ AAudioServiceEndpointCapture::~AAudioServiceEndpointCapture() { delete mDistributionBuffer; } aaudio_result_t AAudioServiceEndpointCapture::open(int32_t deviceId) { aaudio_result_t result = AAudioServiceEndpoint::open(deviceId); aaudio_result_t AAudioServiceEndpointCapture::open(const AAudioStreamConfiguration& configuration) { aaudio_result_t result = AAudioServiceEndpoint::open(configuration); if (result == AAUDIO_OK) { delete mDistributionBuffer; int distributionBufferSizeBytes = getStreamInternal()->getFramesPerBurst() Loading Loading
services/oboeservice/AAudioEndpointManager.cpp +28 −13 Original line number Diff line number Diff line Loading @@ -51,13 +51,13 @@ std::string AAudioEndpointManager::dump() const { size_t inputs = mInputs.size(); result << "Inputs: " << inputs << "\n"; for (const auto &input : mInputs) { result << " Input(" << input.first << ", " << input.second << ")\n"; result << " Input(" << input << ")\n"; } size_t outputs = mOutputs.size(); result << "Outputs: " << outputs << "\n"; for (const auto &output : mOutputs) { result << " Output(" << output.first << ", " << output.second << ")\n"; result << " Output(" << output << ")\n"; } if (isLocked) { Loading @@ -66,27 +66,40 @@ std::string AAudioEndpointManager::dump() const { return result.str(); } AAudioServiceEndpoint *AAudioEndpointManager::openEndpoint(AAudioService &audioService, int32_t deviceId, aaudio_direction_t direction) { AAudioServiceEndpoint *AAudioEndpointManager::openEndpoint(AAudioService &audioService, const AAudioStreamConfiguration& configuration, aaudio_direction_t direction) { AAudioServiceEndpoint *endpoint = nullptr; AAudioServiceEndpointCapture *capture = nullptr; AAudioServiceEndpointPlay *player = nullptr; std::lock_guard<std::mutex> lock(mLock); // Try to find an existing endpoint. switch (direction) { case AAUDIO_DIRECTION_INPUT: endpoint = mInputs[deviceId]; for (AAudioServiceEndpoint *ep : mInputs) { if (ep->matches(configuration)) { endpoint = ep; break; } } break; case AAUDIO_DIRECTION_OUTPUT: endpoint = mOutputs[deviceId]; for (AAudioServiceEndpoint *ep : mOutputs) { if (ep->matches(configuration)) { endpoint = ep; break; } } break; default: assert(false); // There are only two possible directions. break; } ALOGD("AAudioEndpointManager::openEndpoint(), found %p for device = %d, dir = %d", endpoint, deviceId, (int)direction); endpoint, configuration.getDeviceId(), (int)direction); // If we can't find an existing one then open a new one. if (endpoint == nullptr) { Loading @@ -105,7 +118,7 @@ AAudioServiceEndpoint *AAudioEndpointManager::openEndpoint(AAudioService &audioS } if (endpoint != nullptr) { aaudio_result_t result = endpoint->open(deviceId); aaudio_result_t result = endpoint->open(configuration); if (result != AAUDIO_OK) { ALOGE("AAudioEndpointManager::findEndpoint(), open failed"); delete endpoint; Loading @@ -113,17 +126,17 @@ AAudioServiceEndpoint *AAudioEndpointManager::openEndpoint(AAudioService &audioS } else { switch(direction) { case AAUDIO_DIRECTION_INPUT: mInputs[deviceId] = capture; mInputs.push_back(capture); break; case AAUDIO_DIRECTION_OUTPUT: mOutputs[deviceId] = player; mOutputs.push_back(player); break; default: break; } } ALOGD("AAudioEndpointManager::openEndpoint(), created %p for device = %d, dir = %d", endpoint, deviceId, (int)direction); endpoint, configuration.getDeviceId(), (int)direction); } if (endpoint != nullptr) { Loading Loading @@ -156,10 +169,12 @@ void AAudioEndpointManager::closeEndpoint(AAudioServiceEndpoint *serviceEndpoint switch (direction) { case AAUDIO_DIRECTION_INPUT: mInputs.erase(deviceId); mInputs.erase( std::remove(mInputs.begin(), mInputs.end(), serviceEndpoint), mInputs.end()); break; case AAUDIO_DIRECTION_OUTPUT: mOutputs.erase(deviceId); mOutputs.erase( std::remove(mOutputs.begin(), mOutputs.end(), serviceEndpoint), mOutputs.end()); break; default: break; Loading
services/oboeservice/AAudioEndpointManager.h +3 −3 Original line number Diff line number Diff line Loading @@ -54,7 +54,7 @@ public: * @return endpoint or nullptr */ AAudioServiceEndpoint *openEndpoint(android::AAudioService &audioService, int32_t deviceId, const AAudioStreamConfiguration& configuration, aaudio_direction_t direction); void closeEndpoint(AAudioServiceEndpoint *serviceEndpoint); Loading @@ -63,8 +63,8 @@ private: mutable std::mutex mLock; std::map<int32_t, AAudioServiceEndpointCapture *> mInputs; std::map<int32_t, AAudioServiceEndpointPlay *> mOutputs; std::vector<AAudioServiceEndpointCapture *> mInputs; std::vector<AAudioServiceEndpointPlay *> mOutputs; }; Loading
services/oboeservice/AAudioServiceEndpoint.cpp +23 −3 Original line number Diff line number Diff line Loading @@ -45,15 +45,18 @@ using namespace aaudio; // TODO just import names needed #define DEFAULT_BUFFER_CAPACITY (48 * 8) // Set up an EXCLUSIVE MMAP stream that will be shared. aaudio_result_t AAudioServiceEndpoint::open(int32_t deviceId) { mRequestedDeviceId = deviceId; aaudio_result_t AAudioServiceEndpoint::open(const AAudioStreamConfiguration& configuration) { mRequestedDeviceId = configuration.getDeviceId(); mStreamInternal = getStreamInternal(); AudioStreamBuilder builder; builder.setSharingMode(AAUDIO_SHARING_MODE_EXCLUSIVE); // Don't fall back to SHARED because that would cause recursion. builder.setSharingModeMatchRequired(true); builder.setDeviceId(deviceId); builder.setDeviceId(mRequestedDeviceId); builder.setFormat(configuration.getAudioFormat()); builder.setSampleRate(configuration.getSampleRate()); builder.setSamplesPerFrame(configuration.getSamplesPerFrame()); builder.setDirection(getDirection()); builder.setBufferCapacity(DEFAULT_BUFFER_CAPACITY); Loading Loading @@ -139,3 +142,20 @@ void AAudioServiceEndpoint::disconnectRegisteredStreams() { } mRegisteredStreams.clear(); } bool AAudioServiceEndpoint::matches(const AAudioStreamConfiguration& configuration) { if (configuration.getDeviceId() != AAUDIO_UNSPECIFIED && configuration.getDeviceId() != mStreamInternal->getDeviceId()) { return false; } if (configuration.getSampleRate() != AAUDIO_UNSPECIFIED && configuration.getSampleRate() != mStreamInternal->getSampleRate()) { return false; } if (configuration.getSamplesPerFrame() != AAUDIO_UNSPECIFIED && configuration.getSamplesPerFrame() != mStreamInternal->getSamplesPerFrame()) { return false; } return true; }
services/oboeservice/AAudioServiceEndpoint.h +3 −1 Original line number Diff line number Diff line Loading @@ -36,7 +36,7 @@ class AAudioServiceEndpoint { public: virtual ~AAudioServiceEndpoint() = default; virtual aaudio_result_t open(int32_t deviceId); virtual aaudio_result_t open(const AAudioStreamConfiguration& configuration); int32_t getSampleRate() const { return mStreamInternal->getSampleRate(); } int32_t getSamplesPerFrame() const { return mStreamInternal->getSamplesPerFrame(); } Loading Loading @@ -67,6 +67,8 @@ public: mReferenceCount = count; } bool matches(const AAudioStreamConfiguration& configuration); virtual AudioStreamInternal *getStreamInternal() = 0; std::atomic<bool> mCallbackEnabled; Loading
services/oboeservice/AAudioServiceEndpointCapture.cpp +2 −2 Original line number Diff line number Diff line Loading @@ -42,8 +42,8 @@ AAudioServiceEndpointCapture::~AAudioServiceEndpointCapture() { delete mDistributionBuffer; } aaudio_result_t AAudioServiceEndpointCapture::open(int32_t deviceId) { aaudio_result_t result = AAudioServiceEndpoint::open(deviceId); aaudio_result_t AAudioServiceEndpointCapture::open(const AAudioStreamConfiguration& configuration) { aaudio_result_t result = AAudioServiceEndpoint::open(configuration); if (result == AAUDIO_OK) { delete mDistributionBuffer; int distributionBufferSizeBytes = getStreamInternal()->getFramesPerBurst() Loading