OboeTester: print scheduler when it changes
For input and output stream callback threads.
diff --git a/apps/OboeTester/app/CMakeLists.txt b/apps/OboeTester/app/CMakeLists.txt
index f2c81c1..8de21f9 100644
--- a/apps/OboeTester/app/CMakeLists.txt
+++ b/apps/OboeTester/app/CMakeLists.txt
@@ -31,4 +31,4 @@
# link to oboe
target_link_libraries(oboetester log oboe atomic)
-# bump 2 to resync CMake
+# bump 3 to resync CMake
diff --git a/apps/OboeTester/app/src/main/cpp/AudioStreamGateway.cpp b/apps/OboeTester/app/src/main/cpp/AudioStreamGateway.cpp
index 7dd374f..c473540 100644
--- a/apps/OboeTester/app/src/main/cpp/AudioStreamGateway.cpp
+++ b/apps/OboeTester/app/src/main/cpp/AudioStreamGateway.cpp
@@ -17,6 +17,7 @@
#include <cstring>
#include <sched.h>
+#include "common/OboeDebug.h"
#include "oboe/Oboe.h"
#include "AudioStreamGateway.h"
@@ -27,10 +28,7 @@
void *audioData,
int numFrames) {
- if (!mSchedulerChecked) {
- mScheduler = sched_getscheduler(gettid());
- mSchedulerChecked = true;
- }
+ printScheduler();
if (mAudioSink != nullptr) {
mAudioSink->read(audioData, numFrames);
@@ -39,6 +37,3 @@
return oboe::DataCallbackResult::Continue;
}
-int AudioStreamGateway::getScheduler() {
- return mScheduler;
-}
diff --git a/apps/OboeTester/app/src/main/cpp/AudioStreamGateway.h b/apps/OboeTester/app/src/main/cpp/AudioStreamGateway.h
index 982d099..0aaf429 100644
--- a/apps/OboeTester/app/src/main/cpp/AudioStreamGateway.h
+++ b/apps/OboeTester/app/src/main/cpp/AudioStreamGateway.h
@@ -21,6 +21,7 @@
#include "flowgraph/FlowGraphNode.h"
#include "oboe/Oboe.h"
+#include "OboeTesterStreamCallback.h"
using namespace oboe::flowgraph;
@@ -29,9 +30,8 @@
* Pass in an AudioSink and then pass
* this object to the AudioStreamBuilder as a callback.
*/
-class AudioStreamGateway : public oboe::AudioStreamCallback {
+class AudioStreamGateway : public OboeTesterStreamCallback {
public:
-// AudioStreamGateway(int samplesPerFrame);
virtual ~AudioStreamGateway() = default;
void setAudioSink(std::shared_ptr<oboe::flowgraph::FlowGraphSink> sink) {
@@ -46,11 +46,8 @@
void *audioData,
int numFrames) override;
- int getScheduler();
-
private:
- bool mSchedulerChecked = false;
- int mScheduler;
+
std::shared_ptr<oboe::flowgraph::FlowGraphSink> mAudioSink;
};
diff --git a/apps/OboeTester/app/src/main/cpp/InputStreamCallbackAnalyzer.cpp b/apps/OboeTester/app/src/main/cpp/InputStreamCallbackAnalyzer.cpp
index d04f09a..f9290e1 100644
--- a/apps/OboeTester/app/src/main/cpp/InputStreamCallbackAnalyzer.cpp
+++ b/apps/OboeTester/app/src/main/cpp/InputStreamCallbackAnalyzer.cpp
@@ -23,6 +23,8 @@
int numFrames) {
int32_t channelCount = audioStream->getChannelCount();
+ printScheduler();
+
if (audioStream->getFormat() == oboe::AudioFormat::I16) {
int16_t *shortData = (int16_t *) audioData;
if (mRecording != nullptr) {
diff --git a/apps/OboeTester/app/src/main/cpp/InputStreamCallbackAnalyzer.h b/apps/OboeTester/app/src/main/cpp/InputStreamCallbackAnalyzer.h
index 42ffbfb..fc26b1f 100644
--- a/apps/OboeTester/app/src/main/cpp/InputStreamCallbackAnalyzer.h
+++ b/apps/OboeTester/app/src/main/cpp/InputStreamCallbackAnalyzer.h
@@ -24,17 +24,19 @@
// TODO #include "flowgraph/FlowGraph.h"
#include "oboe/Oboe.h"
#include "MultiChannelRecording.h"
+#include "OboeTesterStreamCallback.h"
#include "analyzer/PeakDetector.h"
constexpr int kMaxInputChannels = 8;
-class InputStreamCallbackAnalyzer : public oboe::AudioStreamCallback {
+class InputStreamCallbackAnalyzer : public OboeTesterStreamCallback {
public:
void reset() {
for (auto detector : mPeakDetectors) {
detector.reset();
}
+ OboeTesterStreamCallback::reset();
}
/**
diff --git a/apps/OboeTester/app/src/main/cpp/NativeAudioContext.cpp b/apps/OboeTester/app/src/main/cpp/NativeAudioContext.cpp
index 0026610..3b51177 100644
--- a/apps/OboeTester/app/src/main/cpp/NativeAudioContext.cpp
+++ b/apps/OboeTester/app/src/main/cpp/NativeAudioContext.cpp
@@ -111,7 +111,6 @@
for (auto entry : mOboeStreams) {
oboe::AudioStream *oboeStream = entry.second.get();
result = oboeStream->requestPause();
- printScheduler();
}
return result;
}
@@ -122,7 +121,6 @@
for (auto entry : mOboeStreams) {
oboe::AudioStream *oboeStream = entry.second.get();
result = oboeStream->requestStop();
- printScheduler();
}
return result;
}
@@ -237,6 +235,7 @@
configureForStart();
+ audioStreamGateway.reset();
result = startStreams();
if (!mUseCallback && result == oboe::Result::OK) {
diff --git a/apps/OboeTester/app/src/main/cpp/NativeAudioContext.h b/apps/OboeTester/app/src/main/cpp/NativeAudioContext.h
index d5cb994..bd445d1 100644
--- a/apps/OboeTester/app/src/main/cpp/NativeAudioContext.h
+++ b/apps/OboeTester/app/src/main/cpp/NativeAudioContext.h
@@ -224,13 +224,6 @@
virtual void close(int32_t streamIndex);
- void printScheduler() {
-#if OBOE_ENABLE_LOGGING
- int scheduler = audioStreamGateway.getScheduler();
-#endif
- LOGI("scheduler = 0x%08x, SCHED_FIFO = 0x%08X\n", scheduler, SCHED_FIFO);
- }
-
virtual void configureForStart() {}
oboe::Result start();
diff --git a/apps/OboeTester/app/src/main/cpp/OboeTesterStreamCallback.cpp b/apps/OboeTester/app/src/main/cpp/OboeTesterStreamCallback.cpp
new file mode 100644
index 0000000..aab60ab
--- /dev/null
+++ b/apps/OboeTester/app/src/main/cpp/OboeTesterStreamCallback.cpp
@@ -0,0 +1,40 @@
+/*
+ * Copyright 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+#include "AudioStreamGateway.h"
+#include "oboe/Oboe.h"
+#include "common/OboeDebug.h"
+#include <sched.h>
+#include <cstring>
+#include "OboeTesterStreamCallback.h"
+
+// Print if scheduler changes.
+void OboeTesterStreamCallback::printScheduler() {
+#if OBOE_ENABLE_LOGGING
+ int scheduler = sched_getscheduler(gettid());
+ if (scheduler != mPreviousScheduler) {
+ int schedulerType = scheduler & 0xFFFF; // mask off high flags
+ LOGD("callback CPU scheduler = 0x%08x = %s",
+ scheduler,
+ ((schedulerType == SCHED_FIFO) ? "SCHED_FIFO" :
+ ((schedulerType == SCHED_OTHER) ? "SCHED_OTHER" :
+ ((schedulerType == SCHED_RR) ? "SCHED_RR" : "UNKNOWN")))
+ );
+ mPreviousScheduler = scheduler;
+ }
+#endif
+}
\ No newline at end of file
diff --git a/apps/OboeTester/app/src/main/cpp/OboeTesterStreamCallback.h b/apps/OboeTester/app/src/main/cpp/OboeTesterStreamCallback.h
new file mode 100644
index 0000000..ec01fe5
--- /dev/null
+++ b/apps/OboeTester/app/src/main/cpp/OboeTesterStreamCallback.h
@@ -0,0 +1,41 @@
+/*
+ * Copyright 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef OBOETESTER_STREAM_CALLBACK_H
+#define OBOETESTER_STREAM_CALLBACK_H
+
+#include <unistd.h>
+#include <sys/types.h>
+#include "flowgraph/FlowGraphNode.h"
+#include "oboe/Oboe.h"
+
+class OboeTesterStreamCallback : public oboe::AudioStreamCallback {
+public:
+ virtual ~OboeTesterStreamCallback() = default;
+
+ // Call this before starting.
+ void reset() {
+ mPreviousScheduler = -1;
+ }
+
+protected:
+ void printScheduler();
+
+ int mPreviousScheduler = -1;
+};
+
+
+#endif //OBOETESTER_STREAM_CALLBACK_H