1 /*
2 * Copyright (C) 2021 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 */
17
18 #define LOG_NDEBUG 0
19 #define LOG_TAG "AAudioStreamAtom-JNI"
20
21 #include <jni.h>
22
23 #include <aaudio/AAudio.h>
24 #include <gtest/gtest.h>
25
tryOpeningStream(aaudio_direction_t direction,aaudio_performance_mode_t performanceMode)26 void tryOpeningStream(aaudio_direction_t direction, aaudio_performance_mode_t performanceMode) {
27 AAudioStreamBuilder *builder = nullptr;
28 ASSERT_EQ(AAUDIO_OK, AAudio_createStreamBuilder(&builder));
29 ASSERT_NE(nullptr, builder);
30 AAudioStreamBuilder_setDirection(builder, direction);
31 AAudioStreamBuilder_setPerformanceMode(builder, performanceMode);
32
33 AAudioStream *stream = nullptr;
34 ASSERT_EQ(AAUDIO_OK, AAudioStreamBuilder_openStream(builder, &stream));
35 ASSERT_NE(nullptr, stream);
36 ASSERT_EQ(direction, AAudioStream_getDirection(stream));
37
38 ASSERT_EQ(AAUDIO_OK, AAudioStream_requestStart(stream));
39 ASSERT_EQ(AAUDIO_OK, AAudioStream_requestStop(stream));
40
41 // Cleanup
42 ASSERT_EQ(AAUDIO_OK, AAudioStreamBuilder_delete(builder));
43 ASSERT_EQ(AAUDIO_OK, AAudioStream_close(stream));
44 }
45
46 extern "C" JNIEXPORT void JNICALL
Java_android_media_metrics_cts_MediaMetricsAtomHostSideTests_testAAudioLowLatencyOutputStream(JNIEnv *,jobject)47 Java_android_media_metrics_cts_MediaMetricsAtomHostSideTests_testAAudioLowLatencyOutputStream(
48 JNIEnv *, jobject /* this */) {
49 tryOpeningStream(AAUDIO_DIRECTION_OUTPUT, AAUDIO_PERFORMANCE_MODE_LOW_LATENCY);
50 }
51
52 extern "C" JNIEXPORT void JNICALL
Java_android_media_metrics_cts_MediaMetricsAtomHostSideTests_testAAudioLowLatencyInputStream(JNIEnv *,jobject)53 Java_android_media_metrics_cts_MediaMetricsAtomHostSideTests_testAAudioLowLatencyInputStream(
54 JNIEnv *, jobject /* this */) {
55 tryOpeningStream(AAUDIO_DIRECTION_INPUT, AAUDIO_PERFORMANCE_MODE_LOW_LATENCY);
56 }
57
58 extern "C" JNIEXPORT void JNICALL
Java_android_media_metrics_cts_MediaMetricsAtomHostSideTests_testAAudioLegacyOutputStream(JNIEnv *,jobject)59 Java_android_media_metrics_cts_MediaMetricsAtomHostSideTests_testAAudioLegacyOutputStream(
60 JNIEnv *, jobject /* this */) {
61 tryOpeningStream(AAUDIO_DIRECTION_OUTPUT, AAUDIO_PERFORMANCE_MODE_NONE);
62 }
63
64 extern "C" JNIEXPORT void JNICALL
Java_android_media_metrics_cts_MediaMetricsAtomHostSideTests_testAAudioLegacyInputStream(JNIEnv *,jobject)65 Java_android_media_metrics_cts_MediaMetricsAtomHostSideTests_testAAudioLegacyInputStream(
66 JNIEnv *, jobject /* this */) {
67 tryOpeningStream(AAUDIO_DIRECTION_INPUT, AAUDIO_PERFORMANCE_MODE_NONE);
68 }
69