xref: /aosp_15_r20/external/oboe/src/opensles/AudioOutputStreamOpenSLES.h (revision 05767d913155b055644481607e6fa1e35e2fe72c)
1*05767d91SRobert Wu /*
2*05767d91SRobert Wu  * Copyright 2017 The Android Open Source Project
3*05767d91SRobert Wu  *
4*05767d91SRobert Wu  * Licensed under the Apache License, Version 2.0 (the "License");
5*05767d91SRobert Wu  * you may not use this file except in compliance with the License.
6*05767d91SRobert Wu  * You may obtain a copy of the License at
7*05767d91SRobert Wu  *
8*05767d91SRobert Wu  *      http://www.apache.org/licenses/LICENSE-2.0
9*05767d91SRobert Wu  *
10*05767d91SRobert Wu  * Unless required by applicable law or agreed to in writing, software
11*05767d91SRobert Wu  * distributed under the License is distributed on an "AS IS" BASIS,
12*05767d91SRobert Wu  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*05767d91SRobert Wu  * See the License for the specific language governing permissions and
14*05767d91SRobert Wu  * limitations under the License.
15*05767d91SRobert Wu  */
16*05767d91SRobert Wu 
17*05767d91SRobert Wu #ifndef AUDIO_OUTPUT_STREAM_OPENSL_ES_H_
18*05767d91SRobert Wu #define AUDIO_OUTPUT_STREAM_OPENSL_ES_H_
19*05767d91SRobert Wu 
20*05767d91SRobert Wu 
21*05767d91SRobert Wu #include <SLES/OpenSLES.h>
22*05767d91SRobert Wu #include <SLES/OpenSLES_Android.h>
23*05767d91SRobert Wu 
24*05767d91SRobert Wu #include "oboe/Oboe.h"
25*05767d91SRobert Wu #include "AudioStreamOpenSLES.h"
26*05767d91SRobert Wu 
27*05767d91SRobert Wu namespace oboe {
28*05767d91SRobert Wu 
29*05767d91SRobert Wu /**
30*05767d91SRobert Wu  * INTERNAL USE ONLY
31*05767d91SRobert Wu  */
32*05767d91SRobert Wu class AudioOutputStreamOpenSLES : public AudioStreamOpenSLES {
33*05767d91SRobert Wu public:
34*05767d91SRobert Wu     AudioOutputStreamOpenSLES();
35*05767d91SRobert Wu     explicit AudioOutputStreamOpenSLES(const AudioStreamBuilder &builder);
36*05767d91SRobert Wu 
37*05767d91SRobert Wu     virtual ~AudioOutputStreamOpenSLES() = default;
38*05767d91SRobert Wu 
39*05767d91SRobert Wu     Result open() override;
40*05767d91SRobert Wu     Result close() override;
41*05767d91SRobert Wu 
42*05767d91SRobert Wu     Result requestStart() override;
43*05767d91SRobert Wu     Result requestPause() override;
44*05767d91SRobert Wu     Result requestFlush() override;
45*05767d91SRobert Wu     Result requestStop() override;
46*05767d91SRobert Wu 
47*05767d91SRobert Wu protected:
48*05767d91SRobert Wu     Result requestPause_l();
49*05767d91SRobert Wu 
50*05767d91SRobert Wu     void setFramesRead(int64_t framesRead);
51*05767d91SRobert Wu 
52*05767d91SRobert Wu     Result updateServiceFrameCounter() override;
53*05767d91SRobert Wu 
54*05767d91SRobert Wu     void updateFramesRead() override;
55*05767d91SRobert Wu 
56*05767d91SRobert Wu private:
57*05767d91SRobert Wu 
58*05767d91SRobert Wu     SLuint32 channelCountToChannelMask(int chanCount) const;
59*05767d91SRobert Wu 
60*05767d91SRobert Wu     Result onAfterDestroy() override;
61*05767d91SRobert Wu 
62*05767d91SRobert Wu     Result requestFlush_l();
63*05767d91SRobert Wu 
64*05767d91SRobert Wu     Result requestStop_l();
65*05767d91SRobert Wu 
66*05767d91SRobert Wu     /**
67*05767d91SRobert Wu      * Set OpenSL ES PLAYSTATE.
68*05767d91SRobert Wu      *
69*05767d91SRobert Wu      * @param newState SL_PLAYSTATE_PAUSED, SL_PLAYSTATE_PLAYING, SL_PLAYSTATE_STOPPED
70*05767d91SRobert Wu      * @return
71*05767d91SRobert Wu      */
72*05767d91SRobert Wu     Result setPlayState_l(SLuint32 newState);
73*05767d91SRobert Wu 
74*05767d91SRobert Wu     SLPlayItf      mPlayInterface = nullptr;
75*05767d91SRobert Wu 
76*05767d91SRobert Wu };
77*05767d91SRobert Wu 
78*05767d91SRobert Wu } // namespace oboe
79*05767d91SRobert Wu 
80*05767d91SRobert Wu #endif //AUDIO_OUTPUT_STREAM_OPENSL_ES_H_
81