JMedia2HTTPService.cpp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. //#define LOG_NDEBUG 0
  17. #define LOG_TAG "JMedia2HTTPService"
  18. #include <utils/Log.h>
  19. #include <jni.h>
  20. #include <mediaplayer2/JavaVMHelper.h>
  21. #include <mediaplayer2/JMedia2HTTPService.h>
  22. #include <mediaplayer2/JMedia2HTTPConnection.h>
  23. #include <media/stagefright/foundation/ADebug.h>
  24. #include <nativehelper/scoped_local_ref.h>
  25. namespace android {
  26. JMedia2HTTPService::JMedia2HTTPService(JNIEnv *env, jobject thiz) {
  27. mMedia2HTTPServiceObj = env->NewGlobalRef(thiz);
  28. CHECK(mMedia2HTTPServiceObj != NULL);
  29. ScopedLocalRef<jclass> media2HTTPServiceClass(env, env->GetObjectClass(mMedia2HTTPServiceObj));
  30. CHECK(media2HTTPServiceClass.get() != NULL);
  31. mMakeHTTPConnectionMethod = env->GetMethodID(
  32. media2HTTPServiceClass.get(),
  33. "makeHTTPConnection",
  34. "()Landroid/media/Media2HTTPConnection;");
  35. CHECK(mMakeHTTPConnectionMethod != NULL);
  36. }
  37. JMedia2HTTPService::~JMedia2HTTPService() {
  38. JNIEnv *env = JavaVMHelper::getJNIEnv();
  39. env->DeleteGlobalRef(mMedia2HTTPServiceObj);
  40. }
  41. sp<MediaHTTPConnection> JMedia2HTTPService::makeHTTPConnection() {
  42. JNIEnv* env = JavaVMHelper::getJNIEnv();
  43. jobject media2HTTPConnectionObj =
  44. env->CallObjectMethod(mMedia2HTTPServiceObj, mMakeHTTPConnectionMethod);
  45. return new JMedia2HTTPConnection(env, media2HTTPConnectionObj);
  46. }
  47. } // namespace android