Loading media/libaaudio/tests/test_steal_exclusive.cpp +19 −10 Original line number Original line Diff line number Diff line Loading @@ -116,7 +116,7 @@ public: do { do { closeAudioStream(); closeAudioStream(); if (mOpenDelayMillis) usleep(mOpenDelayMillis * 1000); if (mOpenDelayMillis) usleep(mOpenDelayMillis * 1000); openAudioStream(mDirection); openAudioStream(mDirection, mRequestedSharingMode); // It is possible for the stream to be disconnected, or stolen between the time // It is possible for the stream to be disconnected, or stolen between the time // it is opened and when it is started. If that happens then try again. // it is opened and when it is started. If that happens then try again. // If it was stolen then it should succeed the second time because there will already be // If it was stolen then it should succeed the second time because there will already be Loading @@ -136,11 +136,13 @@ public: return AAUDIO_CALLBACK_RESULT_CONTINUE; return AAUDIO_CALLBACK_RESULT_CONTINUE; } } aaudio_result_t openAudioStream(aaudio_direction_t direction) { aaudio_result_t openAudioStream(aaudio_direction_t direction, aaudio_sharing_mode_t requestedSharingMode) { std::lock_guard<std::mutex> lock(mLock); std::lock_guard<std::mutex> lock(mLock); AAudioStreamBuilder *builder = nullptr; AAudioStreamBuilder *builder = nullptr; mDirection = direction; mDirection = direction; mRequestedSharingMode = requestedSharingMode; // Use an AAudioStreamBuilder to contain requested parameters. // Use an AAudioStreamBuilder to contain requested parameters. aaudio_result_t result = AAudio_createStreamBuilder(&builder); aaudio_result_t result = AAudio_createStreamBuilder(&builder); Loading @@ -153,7 +155,7 @@ public: // Request stream properties. // Request stream properties. AAudioStreamBuilder_setFormat(builder, AAUDIO_FORMAT_PCM_FLOAT); AAudioStreamBuilder_setFormat(builder, AAUDIO_FORMAT_PCM_FLOAT); AAudioStreamBuilder_setPerformanceMode(builder, AAUDIO_PERFORMANCE_MODE_LOW_LATENCY); AAudioStreamBuilder_setPerformanceMode(builder, AAUDIO_PERFORMANCE_MODE_LOW_LATENCY); AAudioStreamBuilder_setSharingMode(builder, AAUDIO_SHARING_MODE_EXCLUSIVE); AAudioStreamBuilder_setSharingMode(builder, mRequestedSharingMode); AAudioStreamBuilder_setDirection(builder, direction); AAudioStreamBuilder_setDirection(builder, direction); AAudioStreamBuilder_setDataCallback(builder, s_myDataCallbackProc, this); AAudioStreamBuilder_setDataCallback(builder, s_myDataCallbackProc, this); AAudioStreamBuilder_setErrorCallback(builder, s_myErrorCallbackProc, this); AAudioStreamBuilder_setErrorCallback(builder, s_myErrorCallbackProc, this); Loading Loading @@ -280,6 +282,7 @@ private: AAudioStream *mStream = nullptr; AAudioStream *mStream = nullptr; aaudio_direction_t mDirection = AAUDIO_DIRECTION_OUTPUT; aaudio_direction_t mDirection = AAUDIO_DIRECTION_OUTPUT; aaudio_sharing_mode_t mRequestedSharingMode = AAUDIO_UNSPECIFIED; std::mutex mLock; std::mutex mLock; std::string mName; std::string mName; int mMaxRetries = 1; int mMaxRetries = 1; Loading Loading @@ -316,10 +319,11 @@ static void s_myErrorCallbackProc( } } static void s_usage() { static void s_usage() { printf("test_steal_exclusive [-i] [-r{maxRetries}] [-d{delay}]\n"); printf("test_steal_exclusive [-i] [-r{maxRetries}] [-d{delay}] -s\n"); printf(" -i direction INPUT, otherwise OUTPUT\n"); printf(" -i direction INPUT, otherwise OUTPUT\n"); printf(" -d delay open by milliseconds, default = 0\n"); printf(" -d delay open by milliseconds, default = 0\n"); printf(" -r max retries in the error callback, default = 1\n"); printf(" -r max retries in the error callback, default = 1\n"); printf(" -s try to open in SHARED mode\n"); } } int main(int argc, char ** argv) { int main(int argc, char ** argv) { Loading @@ -330,12 +334,13 @@ int main(int argc, char ** argv) { int errorCount = 0; int errorCount = 0; int maxRetries = 1; int maxRetries = 1; int openDelayMillis = 0; int openDelayMillis = 0; aaudio_sharing_mode_t requestedSharingMode = AAUDIO_SHARING_MODE_EXCLUSIVE; // Make printf print immediately so that debug info is not stuck // Make printf print immediately so that debug info is not stuck // in a buffer if we hang or crash. // in a buffer if we hang or crash. setvbuf(stdout, nullptr, _IONBF, (size_t) 0); setvbuf(stdout, nullptr, _IONBF, (size_t) 0); printf("Test Stealing an EXCLUSIVE stream V1.0\n"); printf("Test interaction between streams V1.1\n"); printf("\n"); printf("\n"); for (int i = 1; i < argc; i++) { for (int i = 1; i < argc; i++) { Loading @@ -352,6 +357,9 @@ int main(int argc, char ** argv) { case 'r': case 'r': maxRetries = atoi(&arg[2]); maxRetries = atoi(&arg[2]); break; break; case 's': requestedSharingMode = AAUDIO_SHARING_MODE_SHARED; break; default: default: s_usage(); s_usage(); exit(EXIT_FAILURE); exit(EXIT_FAILURE); Loading @@ -369,17 +377,18 @@ int main(int argc, char ** argv) { victim.setMaxRetries(maxRetries); victim.setMaxRetries(maxRetries); thief.setMaxRetries(maxRetries); thief.setMaxRetries(maxRetries); result = victim.openAudioStream(direction); result = victim.openAudioStream(direction, requestedSharingMode); if (result != AAUDIO_OK) { if (result != AAUDIO_OK) { printf("s_OpenAudioStream victim returned %s\n", printf("s_OpenAudioStream victim returned %s\n", AAudio_convertResultToText(result)); AAudio_convertResultToText(result)); errorCount++; errorCount++; } } if (victim.sharingMode == AAUDIO_SHARING_MODE_EXCLUSIVE) { if (victim.sharingMode == requestedSharingMode) { printf("Victim modes is EXCLUSIVE => OK\n"); printf("Victim modes is %s => OK\n", s_sharingModeToText(requestedSharingMode)); } else { } else { printf("Victim modes should be EXCLUSIVE => test not valid!\n"); printf("Victim modes should be %s => test not valid!\n", s_sharingModeToText(requestedSharingMode)); goto onerror; goto onerror; } } Loading @@ -406,7 +415,7 @@ int main(int argc, char ** argv) { } } printf("Trying to start the THIEF stream, which may steal the VICTIM MMAP resource -----\n"); printf("Trying to start the THIEF stream, which may steal the VICTIM MMAP resource -----\n"); result = thief.openAudioStream(direction); result = thief.openAudioStream(direction, requestedSharingMode); if (result != AAUDIO_OK) { if (result != AAUDIO_OK) { printf("s_OpenAudioStream victim returned %s\n", printf("s_OpenAudioStream victim returned %s\n", AAudio_convertResultToText(result)); AAudio_convertResultToText(result)); Loading Loading
media/libaaudio/tests/test_steal_exclusive.cpp +19 −10 Original line number Original line Diff line number Diff line Loading @@ -116,7 +116,7 @@ public: do { do { closeAudioStream(); closeAudioStream(); if (mOpenDelayMillis) usleep(mOpenDelayMillis * 1000); if (mOpenDelayMillis) usleep(mOpenDelayMillis * 1000); openAudioStream(mDirection); openAudioStream(mDirection, mRequestedSharingMode); // It is possible for the stream to be disconnected, or stolen between the time // It is possible for the stream to be disconnected, or stolen between the time // it is opened and when it is started. If that happens then try again. // it is opened and when it is started. If that happens then try again. // If it was stolen then it should succeed the second time because there will already be // If it was stolen then it should succeed the second time because there will already be Loading @@ -136,11 +136,13 @@ public: return AAUDIO_CALLBACK_RESULT_CONTINUE; return AAUDIO_CALLBACK_RESULT_CONTINUE; } } aaudio_result_t openAudioStream(aaudio_direction_t direction) { aaudio_result_t openAudioStream(aaudio_direction_t direction, aaudio_sharing_mode_t requestedSharingMode) { std::lock_guard<std::mutex> lock(mLock); std::lock_guard<std::mutex> lock(mLock); AAudioStreamBuilder *builder = nullptr; AAudioStreamBuilder *builder = nullptr; mDirection = direction; mDirection = direction; mRequestedSharingMode = requestedSharingMode; // Use an AAudioStreamBuilder to contain requested parameters. // Use an AAudioStreamBuilder to contain requested parameters. aaudio_result_t result = AAudio_createStreamBuilder(&builder); aaudio_result_t result = AAudio_createStreamBuilder(&builder); Loading @@ -153,7 +155,7 @@ public: // Request stream properties. // Request stream properties. AAudioStreamBuilder_setFormat(builder, AAUDIO_FORMAT_PCM_FLOAT); AAudioStreamBuilder_setFormat(builder, AAUDIO_FORMAT_PCM_FLOAT); AAudioStreamBuilder_setPerformanceMode(builder, AAUDIO_PERFORMANCE_MODE_LOW_LATENCY); AAudioStreamBuilder_setPerformanceMode(builder, AAUDIO_PERFORMANCE_MODE_LOW_LATENCY); AAudioStreamBuilder_setSharingMode(builder, AAUDIO_SHARING_MODE_EXCLUSIVE); AAudioStreamBuilder_setSharingMode(builder, mRequestedSharingMode); AAudioStreamBuilder_setDirection(builder, direction); AAudioStreamBuilder_setDirection(builder, direction); AAudioStreamBuilder_setDataCallback(builder, s_myDataCallbackProc, this); AAudioStreamBuilder_setDataCallback(builder, s_myDataCallbackProc, this); AAudioStreamBuilder_setErrorCallback(builder, s_myErrorCallbackProc, this); AAudioStreamBuilder_setErrorCallback(builder, s_myErrorCallbackProc, this); Loading Loading @@ -280,6 +282,7 @@ private: AAudioStream *mStream = nullptr; AAudioStream *mStream = nullptr; aaudio_direction_t mDirection = AAUDIO_DIRECTION_OUTPUT; aaudio_direction_t mDirection = AAUDIO_DIRECTION_OUTPUT; aaudio_sharing_mode_t mRequestedSharingMode = AAUDIO_UNSPECIFIED; std::mutex mLock; std::mutex mLock; std::string mName; std::string mName; int mMaxRetries = 1; int mMaxRetries = 1; Loading Loading @@ -316,10 +319,11 @@ static void s_myErrorCallbackProc( } } static void s_usage() { static void s_usage() { printf("test_steal_exclusive [-i] [-r{maxRetries}] [-d{delay}]\n"); printf("test_steal_exclusive [-i] [-r{maxRetries}] [-d{delay}] -s\n"); printf(" -i direction INPUT, otherwise OUTPUT\n"); printf(" -i direction INPUT, otherwise OUTPUT\n"); printf(" -d delay open by milliseconds, default = 0\n"); printf(" -d delay open by milliseconds, default = 0\n"); printf(" -r max retries in the error callback, default = 1\n"); printf(" -r max retries in the error callback, default = 1\n"); printf(" -s try to open in SHARED mode\n"); } } int main(int argc, char ** argv) { int main(int argc, char ** argv) { Loading @@ -330,12 +334,13 @@ int main(int argc, char ** argv) { int errorCount = 0; int errorCount = 0; int maxRetries = 1; int maxRetries = 1; int openDelayMillis = 0; int openDelayMillis = 0; aaudio_sharing_mode_t requestedSharingMode = AAUDIO_SHARING_MODE_EXCLUSIVE; // Make printf print immediately so that debug info is not stuck // Make printf print immediately so that debug info is not stuck // in a buffer if we hang or crash. // in a buffer if we hang or crash. setvbuf(stdout, nullptr, _IONBF, (size_t) 0); setvbuf(stdout, nullptr, _IONBF, (size_t) 0); printf("Test Stealing an EXCLUSIVE stream V1.0\n"); printf("Test interaction between streams V1.1\n"); printf("\n"); printf("\n"); for (int i = 1; i < argc; i++) { for (int i = 1; i < argc; i++) { Loading @@ -352,6 +357,9 @@ int main(int argc, char ** argv) { case 'r': case 'r': maxRetries = atoi(&arg[2]); maxRetries = atoi(&arg[2]); break; break; case 's': requestedSharingMode = AAUDIO_SHARING_MODE_SHARED; break; default: default: s_usage(); s_usage(); exit(EXIT_FAILURE); exit(EXIT_FAILURE); Loading @@ -369,17 +377,18 @@ int main(int argc, char ** argv) { victim.setMaxRetries(maxRetries); victim.setMaxRetries(maxRetries); thief.setMaxRetries(maxRetries); thief.setMaxRetries(maxRetries); result = victim.openAudioStream(direction); result = victim.openAudioStream(direction, requestedSharingMode); if (result != AAUDIO_OK) { if (result != AAUDIO_OK) { printf("s_OpenAudioStream victim returned %s\n", printf("s_OpenAudioStream victim returned %s\n", AAudio_convertResultToText(result)); AAudio_convertResultToText(result)); errorCount++; errorCount++; } } if (victim.sharingMode == AAUDIO_SHARING_MODE_EXCLUSIVE) { if (victim.sharingMode == requestedSharingMode) { printf("Victim modes is EXCLUSIVE => OK\n"); printf("Victim modes is %s => OK\n", s_sharingModeToText(requestedSharingMode)); } else { } else { printf("Victim modes should be EXCLUSIVE => test not valid!\n"); printf("Victim modes should be %s => test not valid!\n", s_sharingModeToText(requestedSharingMode)); goto onerror; goto onerror; } } Loading @@ -406,7 +415,7 @@ int main(int argc, char ** argv) { } } printf("Trying to start the THIEF stream, which may steal the VICTIM MMAP resource -----\n"); printf("Trying to start the THIEF stream, which may steal the VICTIM MMAP resource -----\n"); result = thief.openAudioStream(direction); result = thief.openAudioStream(direction, requestedSharingMode); if (result != AAUDIO_OK) { if (result != AAUDIO_OK) { printf("s_OpenAudioStream victim returned %s\n", printf("s_OpenAudioStream victim returned %s\n", AAudio_convertResultToText(result)); AAudio_convertResultToText(result)); Loading