Home | History | Annotate | Download | only in libmediaplayer2
      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/scoped_local_ref.h>
     29 
     30 namespace android {
     31 
     32 JMedia2HTTPService::JMedia2HTTPService(JNIEnv *env, jobject thiz) {
     33     mMedia2HTTPServiceObj = env->NewGlobalRef(thiz);
     34     CHECK(mMedia2HTTPServiceObj != NULL);
     35 
     36     ScopedLocalRef<jclass> media2HTTPServiceClass(env, env->GetObjectClass(mMedia2HTTPServiceObj));
     37     CHECK(media2HTTPServiceClass.get() != NULL);
     38 
     39     mMakeHTTPConnectionMethod = env->GetMethodID(
     40             media2HTTPServiceClass.get(),
     41             "makeHTTPConnection",
     42             "()Landroid/media/Media2HTTPConnection;");
     43     CHECK(mMakeHTTPConnectionMethod != NULL);
     44 }
     45 
     46 JMedia2HTTPService::~JMedia2HTTPService() {
     47     JNIEnv *env = JavaVMHelper::getJNIEnv();
     48     env->DeleteGlobalRef(mMedia2HTTPServiceObj);
     49 }
     50 
     51 sp<MediaHTTPConnection> JMedia2HTTPService::makeHTTPConnection() {
     52     JNIEnv* env = JavaVMHelper::getJNIEnv();
     53     jobject media2HTTPConnectionObj =
     54         env->CallObjectMethod(mMedia2HTTPServiceObj, mMakeHTTPConnectionMethod);
     55 
     56     return new JMedia2HTTPConnection(env, media2HTTPConnectionObj);
     57 }
     58 
     59 }  // namespace android
     60