• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 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 AUDIOPLAYER_H_
18 #define AUDIOPLAYER_H_
19 
20 #include <SLES/OpenSLES.h>
21 #include <SLES/OpenSLES_Android.h>
22 
23 namespace ndkaudio {
24 
25 class AudioSource;
26 
27 class AudioPlayer {
28  public:
29     AudioPlayer();
30     ~AudioPlayer();
31 
32     SLresult Open(int numChannels, AudioSource* filler);
33     void Close();
34 
35     SLresult RealizePlayer();
36     SLresult RealizeRoutingProxy();
37 
38     SLresult Start();
39     void Stop();
40 
isPlaying()41     inline bool isPlaying() {
42         return playing_;
43     }
getSource()44     inline AudioSource* getSource() {
45         return source_;
46     }
47 
48     // This is public because it needs to be called by the OpenSL ES callback, but it should not
49     // be called by anyone else.
50     SLresult enqueBuffer();
51 
getPlayerObject()52     SLPlayItf getPlayerObject() {
53         return bqPlayerPlay_;
54     }
55 
getConfigItf()56     SLAndroidConfigurationItf getConfigItf() {
57         return configItf_;
58     }
59 
60  private:
61     // void fill();
62 
63     AudioSource* source_;
64     int sampleRate_;
65     int numChannels_;
66 
67     float* playBuff_;
68     long numPlayBuffFrames_;
69     long playBuffSizeInBytes_;
70 
71     bool playing_;
72 
73     long time_;
74 
75     // OpenSLES stuff
76     SLObjectItf bqPlayerObject_;
77     SLPlayItf bqPlayerPlay_;
78     SLAndroidSimpleBufferQueueItf bq_;
79     SLAndroidConfigurationItf configItf_;
80 };
81 
82 } // namespace ndkaudio
83 
84 #endif /* AUDIOPLAYER_H_ */
85