1 /*
2 * Copyright 2017, 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 //#define LOG_NDEBUG 0
18 #define LOG_TAG "Media2HTTPService-JNI"
19 #include <utils/Log.h>
20
21 #include "android_media_Media2HTTPConnection.h"
22 #include "android_media_Media2HTTPService.h"
23
24 #include "android_runtime/AndroidRuntime.h"
25 #include "android_runtime/Log.h"
26 #include "jni.h"
27 #include <nativehelper/JNIHelp.h>
28
29 #include <media/stagefright/foundation/ADebug.h>
30 #include <nativehelper/ScopedLocalRef.h>
31
32 namespace android {
33
JMedia2HTTPService(JNIEnv * env,jobject thiz)34 JMedia2HTTPService::JMedia2HTTPService(JNIEnv *env, jobject thiz) {
35 mMedia2HTTPServiceObj = env->NewGlobalRef(thiz);
36 CHECK(mMedia2HTTPServiceObj != NULL);
37
38 ScopedLocalRef<jclass> media2HTTPServiceClass(env, env->GetObjectClass(mMedia2HTTPServiceObj));
39 CHECK(media2HTTPServiceClass.get() != NULL);
40
41 mMakeHTTPConnectionMethod = env->GetMethodID(
42 media2HTTPServiceClass.get(),
43 "makeHTTPConnection",
44 "()Landroid/media/Media2HTTPConnection;");
45 CHECK(mMakeHTTPConnectionMethod != NULL);
46 }
47
~JMedia2HTTPService()48 JMedia2HTTPService::~JMedia2HTTPService() {
49 JNIEnv *env = AndroidRuntime::getJNIEnv();
50 env->DeleteGlobalRef(mMedia2HTTPServiceObj);
51 }
52
makeHTTPConnection()53 sp<MediaHTTPConnection> JMedia2HTTPService::makeHTTPConnection() {
54 JNIEnv* env = AndroidRuntime::getJNIEnv();
55 jobject media2HTTPConnectionObj =
56 env->CallObjectMethod(mMedia2HTTPServiceObj, mMakeHTTPConnectionMethod);
57
58 return new JMedia2HTTPConnection(env, media2HTTPConnectionObj);
59 }
60
61 } // namespace android
62