| Robert Shih | 2501816 | 2018-09-13 22:07:34 -0700 | [diff] [blame] | 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 "JMedia2HTTPService" | 
|  | 19 | #include <utils/Log.h> | 
|  | 20 |  | 
|  | 21 | #include <jni.h> | 
|  | 22 |  | 
|  | 23 | #include <mediaplayer2/JavaVMHelper.h> | 
|  | 24 | #include <mediaplayer2/JMedia2HTTPService.h> | 
|  | 25 | #include <mediaplayer2/JMedia2HTTPConnection.h> | 
|  | 26 | #include <media/stagefright/foundation/ADebug.h> | 
|  | 27 |  | 
|  | 28 | #include <nativehelper/JNIHelp.h> | 
|  | 29 | #include <nativehelper/ScopedLocalRef.h> | 
|  | 30 |  | 
|  | 31 | namespace android { | 
|  | 32 |  | 
|  | 33 | JMedia2HTTPService::JMedia2HTTPService(JNIEnv *env, jobject thiz) { | 
|  | 34 | mMedia2HTTPServiceObj = env->NewGlobalRef(thiz); | 
|  | 35 | CHECK(mMedia2HTTPServiceObj != NULL); | 
|  | 36 |  | 
|  | 37 | ScopedLocalRef<jclass> media2HTTPServiceClass(env, env->GetObjectClass(mMedia2HTTPServiceObj)); | 
|  | 38 | CHECK(media2HTTPServiceClass.get() != NULL); | 
|  | 39 |  | 
|  | 40 | mMakeHTTPConnectionMethod = env->GetMethodID( | 
|  | 41 | media2HTTPServiceClass.get(), | 
|  | 42 | "makeHTTPConnection", | 
|  | 43 | "()Landroid/media/Media2HTTPConnection;"); | 
|  | 44 | CHECK(mMakeHTTPConnectionMethod != NULL); | 
|  | 45 | } | 
|  | 46 |  | 
|  | 47 | JMedia2HTTPService::~JMedia2HTTPService() { | 
|  | 48 | JNIEnv *env = JavaVMHelper::getJNIEnv(); | 
|  | 49 | env->DeleteGlobalRef(mMedia2HTTPServiceObj); | 
|  | 50 | } | 
|  | 51 |  | 
|  | 52 | sp<MediaHTTPConnection> JMedia2HTTPService::makeHTTPConnection() { | 
|  | 53 | JNIEnv* env = JavaVMHelper::getJNIEnv(); | 
|  | 54 | jobject media2HTTPConnectionObj = | 
|  | 55 | env->CallObjectMethod(mMedia2HTTPServiceObj, mMakeHTTPConnectionMethod); | 
|  | 56 |  | 
|  | 57 | return new JMedia2HTTPConnection(env, media2HTTPConnectionObj); | 
|  | 58 | } | 
|  | 59 |  | 
|  | 60 | }  // namespace android |