1 /*
2  * Copyright 2021 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_JAVASOURCEPROXY_H
18 #define MEGA_PLAYER_JAVASOURCEPROXY_H
19 
20 #include <jni.h>
21 
22 #include "AudioSource.h"
23 
24 class JavaSourceProxy: public AudioSource {
25 public:
26     static void initJni(JNIEnv* env);
27 
28     JavaSourceProxy(jobject sourceObj);
29     virtual ~JavaSourceProxy();
30 
getJavaSourceObject()31     jobject getJavaSourceObject() { return mSourceObj; }
32 
33     // AudioSource virtuals
34     virtual void init(int numFrames, int numChans);
35 
36     virtual void start();
37     virtual void stop();
38 
39     virtual void reset();
40 
41     virtual int pull(float* buffer, int numFrames, int numChans);
42 
43 private:
44     jobject mSourceObj;
45 
46     static jmethodID    sMidInit;
47     static jmethodID    sMidStart;
48     static jmethodID    sMidStop;
49     static jmethodID    sMidReset;
50     static jmethodID    sMidPull;
51 
52     jfloatArray mJavaBuffer;
53 
54     bool mIsJVMAttached;
55     JNIEnv * attachToJVM();
56     void detachFromJVM();
57 };
58 
59 #endif // MEGA_PLAYER_JAVASOURCEPROXY_H
60