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_OBOEPLAYER_H
18 #define MEGA_PLAYER_OBOEPLAYER_H
19 
20 #include <jni.h>
21 
22 #include <oboe/Oboe.h>
23 
24 #include "Player.h"
25 
26 class OboePlayer : public Player, oboe::AudioStreamCallback {
27 public:
28     OboePlayer(JNIEnv *env, AudioSource* source, int playerSubtype);
~OboePlayer()29     virtual ~OboePlayer() {}
30 
31     // Inherited from oboe::AudioStreamCallback
32     virtual oboe::DataCallbackResult onAudioReady(oboe::AudioStream *oboeStream, void *audioData,
33                                                     int32_t numFrames) override;
34     virtual void onErrorAfterClose(oboe::AudioStream *oboeStream, oboe::Result error) override;
35     virtual void onErrorBeforeClose(oboe::AudioStream * oboeStream, oboe::Result error) override;
36 
37     virtual Result setupStream(int32_t channelCount, int32_t sampleRate, int32_t routeDeviceId) override;
38     virtual Result startStream() override;
39 
40     bool getJavaTimestamp(jobject timestampObj);
41 
42 private:
43     // AudioTimestamp Field IDs
44     JavaVM* mJvm;
45 
46     jfieldID    mFidFramePosition;
47     jfieldID    mFidNanoTime;
48 };
49 
50 #endif // MEGA_PLAYER_OBOEPLAYER_H
51