1 /*
2 * Copyright 2018 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 #include <gtest/gtest.h>
19 #include <oboe/Oboe.h>
20
21 using namespace oboe;
22
23
24 class MyCallback : public AudioStreamCallback {
25 public:
onAudioReady(AudioStream * oboeStream,void * audioData,int32_t numFrames)26 DataCallbackResult onAudioReady(AudioStream *oboeStream, void *audioData, int32_t numFrames) override {
27 return DataCallbackResult::Continue;
28 }
29 };
30
31 class XRunBehaviour : public ::testing::Test {
32
33 protected:
34
openStream()35 bool openStream() {
36 Result r = mBuilder.openStream(&mStream);
37 EXPECT_EQ(r, Result::OK) << "Failed to open stream " << convertToText(r);
38 return (r == Result::OK);
39 }
40
closeStream()41 bool closeStream() {
42 Result r = mStream->close();
43 EXPECT_EQ(r, Result::OK) << "Failed to close stream. " << convertToText(r);
44 return (r == Result::OK);
45 }
46
47 AudioStreamBuilder mBuilder;
48 AudioStream *mStream = nullptr;
49
50 };
51
52 // TODO figure out this behaviour - On OpenSLES xRuns are supported within AudioStreamBuffered,
53 // however, these aren't the same as the actual stream underruns
TEST_F(XRunBehaviour,SupportedWhenStreamIsUsingAAudio)54 TEST_F(XRunBehaviour, SupportedWhenStreamIsUsingAAudio){
55
56 ASSERT_TRUE(openStream());
57 if (mStream->getAudioApi() == AudioApi::AAudio){
58 ASSERT_TRUE(mStream->isXRunCountSupported());
59 }
60 ASSERT_TRUE(closeStream());
61 }
62
TEST_F(XRunBehaviour,NotSupportedOnOpenSLESWhenStreamIsUsingCallback)63 TEST_F(XRunBehaviour, NotSupportedOnOpenSLESWhenStreamIsUsingCallback){
64
65 MyCallback callback;
66 mBuilder.setCallback(&callback);
67 ASSERT_TRUE(openStream());
68 if (mStream->getAudioApi() == AudioApi::OpenSLES){
69 ASSERT_FALSE(mStream->isXRunCountSupported());
70 }
71 ASSERT_TRUE(closeStream());
72 }
73
TEST_F(XRunBehaviour,SupportedOnOpenSLESWhenStreamIsUsingBlockingIO)74 TEST_F(XRunBehaviour, SupportedOnOpenSLESWhenStreamIsUsingBlockingIO){
75
76 ASSERT_TRUE(openStream());
77 if (mStream->getAudioApi() == AudioApi::OpenSLES){
78 ASSERT_TRUE(mStream->isXRunCountSupported());
79 }
80 ASSERT_TRUE(closeStream());
81 }