| OLD | NEW |
| 1 /* | 1 /* |
| 2 * libjingle | 2 * libjingle |
| 3 * Copyright 2013 Google Inc. | 3 * Copyright 2013 Google Inc. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions are met: | 6 * modification, are permitted provided that the following conditions are met: |
| 7 * | 7 * |
| 8 * 1. Redistributions of source code must retain the above copyright notice, | 8 * 1. Redistributions of source code must retain the above copyright notice, |
| 9 * this list of conditions and the following disclaimer. | 9 * this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright notice, | 10 * 2. Redistributions in binary form must reproduce the above copyright notice, |
| (...skipping 1654 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1665 return JavaEnumFromIndex(jni, "MediaSource$State", p->state()); | 1665 return JavaEnumFromIndex(jni, "MediaSource$State", p->state()); |
| 1666 } | 1666 } |
| 1667 | 1667 |
| 1668 JOW(jobject, VideoCapturer_nativeCreateVideoCapturer)( | 1668 JOW(jobject, VideoCapturer_nativeCreateVideoCapturer)( |
| 1669 JNIEnv* jni, jclass, jstring j_device_name) { | 1669 JNIEnv* jni, jclass, jstring j_device_name) { |
| 1670 // Since we can't create platform specific java implementations in Java, we | 1670 // Since we can't create platform specific java implementations in Java, we |
| 1671 // defer the creation to C land. | 1671 // defer the creation to C land. |
| 1672 #if defined(ANDROID) | 1672 #if defined(ANDROID) |
| 1673 jclass j_video_capturer_class( | 1673 jclass j_video_capturer_class( |
| 1674 FindClass(jni, "org/webrtc/VideoCapturerAndroid")); | 1674 FindClass(jni, "org/webrtc/VideoCapturerAndroid")); |
| 1675 const jmethodID j_videocapturer_ctor(GetMethodID( | 1675 const int camera_id = jni->CallStaticIntMethod( |
| 1676 jni, j_video_capturer_class, "<init>", "()V")); | 1676 j_video_capturer_class, |
| 1677 jobject j_video_capturer = jni->NewObject(j_video_capturer_class, | 1677 GetStaticMethodID(jni, j_video_capturer_class, "lookupDeviceName", |
| 1678 j_videocapturer_ctor); | 1678 "(Ljava/lang/String;)I"), |
| 1679 CHECK_EXCEPTION(jni) << "error during NewObject"; | 1679 j_device_name); |
| 1680 | 1680 CHECK_EXCEPTION(jni) << "error during VideoCapturerAndroid.lookupDeviceName"; |
| 1681 rtc::scoped_refptr<AndroidVideoCapturerJni> delegate = | 1681 if (camera_id == -1) |
| 1682 AndroidVideoCapturerJni::Create(jni, j_video_capturer, j_device_name); | |
| 1683 if (!delegate.get()) | |
| 1684 return nullptr; | 1682 return nullptr; |
| 1685 rtc::scoped_ptr<webrtc::AndroidVideoCapturer> capturer( | 1683 jobject j_video_capturer = jni->NewObject( |
| 1684 j_video_capturer_class, |
| 1685 GetMethodID(jni, j_video_capturer_class, "<init>", "(I)V"), camera_id); |
| 1686 CHECK_EXCEPTION(jni) << "error during creation of VideoCapturerAndroid"; |
| 1687 rtc::scoped_refptr<webrtc::AndroidVideoCapturerDelegate> delegate = |
| 1688 new rtc::RefCountedObject<AndroidVideoCapturerJni>(jni, j_video_capturer); |
| 1689 rtc::scoped_ptr<cricket::VideoCapturer> capturer( |
| 1686 new webrtc::AndroidVideoCapturer(delegate)); | 1690 new webrtc::AndroidVideoCapturer(delegate)); |
| 1687 | 1691 |
| 1688 #else | 1692 #else |
| 1689 std::string device_name = JavaToStdString(jni, j_device_name); | 1693 std::string device_name = JavaToStdString(jni, j_device_name); |
| 1690 scoped_ptr<cricket::DeviceManagerInterface> device_manager( | 1694 scoped_ptr<cricket::DeviceManagerInterface> device_manager( |
| 1691 cricket::DeviceManagerFactory::Create()); | 1695 cricket::DeviceManagerFactory::Create()); |
| 1692 RTC_CHECK(device_manager->Init()) << "DeviceManager::Init() failed"; | 1696 RTC_CHECK(device_manager->Init()) << "DeviceManager::Init() failed"; |
| 1693 cricket::Device device; | 1697 cricket::Device device; |
| 1694 if (!device_manager->GetVideoCaptureDevice(device_name, &device)) { | 1698 if (!device_manager->GetVideoCaptureDevice(device_name, &device)) { |
| 1695 LOG(LS_ERROR) << "GetVideoCaptureDevice failed for " << device_name; | 1699 LOG(LS_ERROR) << "GetVideoCaptureDevice failed for " << device_name; |
| 1696 return 0; | 1700 return 0; |
| 1697 } | 1701 } |
| 1698 scoped_ptr<cricket::VideoCapturer> capturer( | 1702 scoped_ptr<cricket::VideoCapturer> capturer( |
| 1699 device_manager->CreateVideoCapturer(device)); | 1703 device_manager->CreateVideoCapturer(device)); |
| 1700 | 1704 |
| 1701 jclass j_video_capturer_class( | 1705 jclass j_video_capturer_class( |
| 1702 FindClass(jni, "org/webrtc/VideoCapturer")); | 1706 FindClass(jni, "org/webrtc/VideoCapturer")); |
| 1703 const jmethodID j_videocapturer_ctor(GetMethodID( | 1707 const jmethodID j_videocapturer_ctor(GetMethodID( |
| 1704 jni, j_video_capturer_class, "<init>", "()V")); | 1708 jni, j_video_capturer_class, "<init>", "()V")); |
| 1705 jobject j_video_capturer = | 1709 jobject j_video_capturer = |
| 1706 jni->NewObject(j_video_capturer_class, | 1710 jni->NewObject(j_video_capturer_class, |
| 1707 j_videocapturer_ctor); | 1711 j_videocapturer_ctor); |
| 1708 CHECK_EXCEPTION(jni) << "error during creation of VideoCapturer"; | 1712 CHECK_EXCEPTION(jni) << "error during creation of VideoCapturer"; |
| 1709 | 1713 |
| 1710 #endif | 1714 #endif |
| 1711 const jmethodID j_videocapturer_set_native_capturer(GetMethodID( | 1715 const jmethodID j_videocapturer_set_native_capturer(GetMethodID( |
| 1712 jni, j_video_capturer_class, "setNativeCapturer", "(J)V")); | 1716 jni, j_video_capturer_class, "setNativeCapturer", "(J)V")); |
| 1713 jni->CallVoidMethod(j_video_capturer, | 1717 jni->CallVoidMethod(j_video_capturer, |
| 1714 j_videocapturer_set_native_capturer, | 1718 j_videocapturer_set_native_capturer, |
| 1715 (jlong)capturer.release()); | 1719 jlongFromPointer(capturer.release())); |
| 1716 CHECK_EXCEPTION(jni) << "error during setNativeCapturer"; | 1720 CHECK_EXCEPTION(jni) << "error during setNativeCapturer"; |
| 1717 return j_video_capturer; | 1721 return j_video_capturer; |
| 1718 } | 1722 } |
| 1719 | 1723 |
| 1720 JOW(jlong, VideoRenderer_nativeCreateGuiVideoRenderer)( | 1724 JOW(jlong, VideoRenderer_nativeCreateGuiVideoRenderer)( |
| 1721 JNIEnv* jni, jclass, int x, int y) { | 1725 JNIEnv* jni, jclass, int x, int y) { |
| 1722 scoped_ptr<VideoRendererWrapper> renderer(VideoRendererWrapper::Create( | 1726 scoped_ptr<VideoRendererWrapper> renderer(VideoRendererWrapper::Create( |
| 1723 cricket::VideoRendererFactory::CreateGuiVideoRenderer(x, y))); | 1727 cricket::VideoRendererFactory::CreateGuiVideoRenderer(x, y))); |
| 1724 return (jlong)renderer.release(); | 1728 return (jlong)renderer.release(); |
| 1725 } | 1729 } |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1861 rtc::scoped_ptr<jbyte> buffer(static_cast<jbyte*>(malloc(log_size))); | 1865 rtc::scoped_ptr<jbyte> buffer(static_cast<jbyte*>(malloc(log_size))); |
| 1862 stream->ReadAll(buffer.get(), log_size, &read, nullptr); | 1866 stream->ReadAll(buffer.get(), log_size, &read, nullptr); |
| 1863 | 1867 |
| 1864 jbyteArray result = jni->NewByteArray(read); | 1868 jbyteArray result = jni->NewByteArray(read); |
| 1865 jni->SetByteArrayRegion(result, 0, read, buffer.get()); | 1869 jni->SetByteArrayRegion(result, 0, read, buffer.get()); |
| 1866 | 1870 |
| 1867 return result; | 1871 return result; |
| 1868 } | 1872 } |
| 1869 | 1873 |
| 1870 } // namespace webrtc_jni | 1874 } // namespace webrtc_jni |
| OLD | NEW |