xref: /aosp_15_r20/external/oboe/src/opensles/AudioOutputStreamOpenSLES.h (revision 05767d913155b055644481607e6fa1e35e2fe72c)
1 /*
2  * Copyright 2017 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 #ifndef AUDIO_OUTPUT_STREAM_OPENSL_ES_H_
18 #define AUDIO_OUTPUT_STREAM_OPENSL_ES_H_
19 
20 
21 #include <SLES/OpenSLES.h>
22 #include <SLES/OpenSLES_Android.h>
23 
24 #include "oboe/Oboe.h"
25 #include "AudioStreamOpenSLES.h"
26 
27 namespace oboe {
28 
29 /**
30  * INTERNAL USE ONLY
31  */
32 class AudioOutputStreamOpenSLES : public AudioStreamOpenSLES {
33 public:
34     AudioOutputStreamOpenSLES();
35     explicit AudioOutputStreamOpenSLES(const AudioStreamBuilder &builder);
36 
37     virtual ~AudioOutputStreamOpenSLES() = default;
38 
39     Result open() override;
40     Result close() override;
41 
42     Result requestStart() override;
43     Result requestPause() override;
44     Result requestFlush() override;
45     Result requestStop() override;
46 
47 protected:
48     Result requestPause_l();
49 
50     void setFramesRead(int64_t framesRead);
51 
52     Result updateServiceFrameCounter() override;
53 
54     void updateFramesRead() override;
55 
56 private:
57 
58     SLuint32 channelCountToChannelMask(int chanCount) const;
59 
60     Result onAfterDestroy() override;
61 
62     Result requestFlush_l();
63 
64     Result requestStop_l();
65 
66     /**
67      * Set OpenSL ES PLAYSTATE.
68      *
69      * @param newState SL_PLAYSTATE_PAUSED, SL_PLAYSTATE_PLAYING, SL_PLAYSTATE_STOPPED
70      * @return
71      */
72     Result setPlayState_l(SLuint32 newState);
73 
74     SLPlayItf      mPlayInterface = nullptr;
75 
76 };
77 
78 } // namespace oboe
79 
80 #endif //AUDIO_OUTPUT_STREAM_OPENSL_ES_H_
81