1 /*
2  * Copyright 2020 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 MEGA_PLAYER_AUDIOSOURCE_H
18 #define MEGA_PLAYER_AUDIOSOURCE_H
19 
20 class AudioSource {
21 public:
AudioSource()22     AudioSource() {}
~AudioSource()23     virtual ~AudioSource() {}
24 
25     static const int NUMCHANNELS_UNSPECIFIED = -1;
26     static const int NUMCHANNELS_ERROR = -2;
getNumChannels()27     virtual int getNumChannels() { return NUMCHANNELS_UNSPECIFIED; }
28 
29     // Encoding Constants (specific to MegaAudio)
30     static const int ENCODING_UNSPECIFIED = -1;
31     static const int ENCODING_ERROR = -2;
32     static const int ENCODING_UNINITIALIZED = 0;
33     static const int ENCODING_FLOAT = 1;
34     static const int ENCODING_PCM16 = 2;
35     static const int ENCODING_PCM24 = 3;
36     static const int ENCODING_PCM32 = 4;
getEncoding()37     virtual int getEncoding() { return ENCODING_UNSPECIFIED; };
38 
39     /**
40      * Called before the stream starts to allow initialization of the source
41      * @param numFrames The number of frames that will be requested in each pull() call.
42      * @param numChans The number of channels in the stream.
43      */
init(int numFrames,int numChans)44     virtual void init(int numFrames, int numChans) {}
45 
46     /**
47      * Reset the stream to its beginning
48      */
reset()49     virtual void reset() {}
50 
trigger()51     virtual void trigger() {}
52 
53     /**
54      * Process a request for audio data.
55      * @param audioData The buffer to be filled.
56      * @param numFrames The number of frames of audio to provide.
57      * @param numChans The number of channels (in the buffer) required by the player.
58      * @return The number of frames actually generated. If this value is less than that
59      * requested, it may be interpreted by the player as the end of playback.
60      * Note that the player will be blocked by this call.
61      * Note that the data is assumed to be *interleaved*.
62      */
63     virtual int pull(float* buffer, int numFrames, int numChans) = 0;
64 };
65 
66 #endif // MEGA_PLAYER_AUDIOSOURCE_H
67