Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

oboe: copy more parameters in FilterAudioStream #1898

Merged
merged 2 commits into from
Aug 16, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ public void onSkipTest(View view) {
private String getConfigText(StreamConfiguration config) {
return ((config.getDirection() == StreamConfiguration.DIRECTION_OUTPUT) ? "OUT" : "IN")
+ ", Perf = " + StreamConfiguration.convertPerformanceModeToText(
config.getPerformanceMode())
config.getPerformanceMode())
+ ", " + StreamConfiguration.convertSharingModeToText(config.getSharingMode())
+ ", " + config.getSampleRate();
}
Expand All @@ -213,6 +213,10 @@ private void log(String text) {
mAutomatedTestRunner.log(text);
}

private void flushLog() {
mAutomatedTestRunner.flushLog();
}

private void appendFailedSummary(String text) {
mAutomatedTestRunner.appendFailedSummary(text);
}
Expand Down Expand Up @@ -293,6 +297,7 @@ private void testConfiguration(boolean isInput,
+ ", Dev = " + actualConfig.getDeviceId()
);
log(actualConfigText);
flushLog();

stream = (isInput)
? mAudioInTester.getCurrentAudioStream()
Expand Down Expand Up @@ -345,6 +350,7 @@ private void testConfiguration(boolean isInput,
// Wait for Java plug count to change or stream to disconnect.
while (!mTestFailed && mAutomatedTestRunner.isThreadEnabled() && !mSkipTest &&
stream.getState() == StreamConfiguration.STREAM_STATE_STARTED) {
flushLog();
Thread.sleep(POLL_DURATION_MILLIS);
if (mPlugCount > oldPlugCount) {
timeoutCount = TIME_TO_FAILURE_MILLIS / POLL_DURATION_MILLIS;
Expand All @@ -355,6 +361,7 @@ private void testConfiguration(boolean isInput,
// Wait for timeout or stream to disconnect.
while (!mTestFailed && mAutomatedTestRunner.isThreadEnabled() && !mSkipTest && (timeoutCount > 0) &&
stream.getState() == StreamConfiguration.STREAM_STATE_STARTED) {
flushLog();
Thread.sleep(POLL_DURATION_MILLIS);
timeoutCount--;
if (timeoutCount == 0) {
Expand Down Expand Up @@ -417,6 +424,7 @@ private void testConfiguration(boolean isInput,
} else {
log(TEXT_SKIP);
}
flushLog();
// Give hardware time to settle between tests.
Thread.sleep(1000);
mAutomatedTestRunner.incrementTestCount();
Expand All @@ -442,20 +450,28 @@ private void testConfiguration(int performanceMode,
testConfiguration(true, performanceMode, sharingMode);
}

private void testConfiguration(int performanceMode,
int sharingMode, int sampleRate) throws InterruptedException {
testConfiguration(false, performanceMode, sharingMode, sampleRate);
testConfiguration(true, performanceMode, sharingMode, sampleRate);
}

@Override
public void runTest() {
mPlugCount = 0;

// Try several different configurations.
try {
testConfiguration(false, StreamConfiguration.PERFORMANCE_MODE_LOW_LATENCY,
StreamConfiguration.SHARING_MODE_EXCLUSIVE, 44100);
testConfiguration(StreamConfiguration.PERFORMANCE_MODE_LOW_LATENCY,
StreamConfiguration.SHARING_MODE_EXCLUSIVE);
testConfiguration(StreamConfiguration.PERFORMANCE_MODE_LOW_LATENCY,
StreamConfiguration.SHARING_MODE_SHARED);
testConfiguration(StreamConfiguration.PERFORMANCE_MODE_NONE,
StreamConfiguration.SHARING_MODE_SHARED);
if (NativeEngine.isMMapExclusiveSupported()){
testConfiguration(StreamConfiguration.PERFORMANCE_MODE_LOW_LATENCY,
StreamConfiguration.SHARING_MODE_EXCLUSIVE);
}
testConfiguration(StreamConfiguration.PERFORMANCE_MODE_LOW_LATENCY,
StreamConfiguration.SHARING_MODE_SHARED);
testConfiguration(StreamConfiguration.PERFORMANCE_MODE_LOW_LATENCY,
StreamConfiguration.SHARING_MODE_SHARED, 44100);
} catch (InterruptedException e) {
log("Test CANCELLED - INVALID!");
} catch (Exception e) {
Expand Down
4 changes: 4 additions & 0 deletions src/common/FilterAudioStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,13 @@ class FilterAudioStream : public AudioStream, AudioStreamCallback {
// Copy parameters that may not match builder.
mBufferCapacityInFrames = mChildStream->getBufferCapacityInFrames();
mPerformanceMode = mChildStream->getPerformanceMode();
mSharingMode = mChildStream->getSharingMode();
mInputPreset = mChildStream->getInputPreset();
mFramesPerBurst = mChildStream->getFramesPerBurst();
mDeviceId = mChildStream->getDeviceId();
mHardwareSampleRate = mChildStream->getHardwareSampleRate();
mHardwareChannelCount = mChildStream->getHardwareChannelCount();
mHardwareFormat = mChildStream->getHardwareFormat();
}

virtual ~FilterAudioStream() = default;
Expand Down
25 changes: 24 additions & 1 deletion tests/testStreamOpen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@
*/

#include <gtest/gtest.h>

#include <aaudio/AAudioExtensions.h>
#include <oboe/Oboe.h>
#include <android/api-level.h>

#include <android/api-level.h>
#ifndef __ANDROID_API_S__
#define __ANDROID_API_S__ 31
#endif
Expand Down Expand Up @@ -389,6 +391,27 @@ TEST_F(StreamOpenOutput, LowLatencyStreamHasSmallBufferSize){
}
}

// Make sure the parameters get copied from the child stream.
TEST_F(StreamOpenOutput, AAudioOutputSampleRate44100FilterConfiguration) {
if (mBuilder.isAAudioRecommended()) {
mBuilder.setDirection(Direction::Output);
mBuilder.setPerformanceMode(PerformanceMode::LowLatency);
mBuilder.setSharingMode(SharingMode::Exclusive);
// Try to force the use of a FilterAudioStream by requesting conversion.
mBuilder.setSampleRate(44100);
mBuilder.setSampleRateConversionQuality(SampleRateConversionQuality::Medium);
ASSERT_TRUE(openStream());
ASSERT_LT(0, mStream->getHardwareSampleRate());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getHardware* functions are only supported in Android API 34+. Please wrap this test around an SDK level check.

ASSERT_LT(0, mStream->getHardwareChannelCount());
ASSERT_LT(0, (int)mStream->getHardwareFormat());
// If MMAP is not supported then we cannot get an EXCLUSIVE mode stream.
if (!AAudioExtensions::getInstance().isMMapSupported()) {
ASSERT_NE(SharingMode::Exclusive, mStream->getSharingMode()); // IMPOSSIBLE
}
ASSERT_TRUE(closeStream());
}
}

// See if sample rate conversion by Oboe is calling the callback.
TEST_F(StreamOpenOutput, AAudioOutputSampleRate44100) {
checkSampleRateConversionAdvancing(Direction::Output);
Expand Down