Move /webrtc/api/android files to /webrtc/sdk/android

I decided to make one webrtc/sdk/android/BUILD.gn for both tests and Java/jni src.

External dependencies needs to be updated after this CL.

Future work is required to clean up the Android api and move
implementation details to /webrtc/sdk/android/src.

BUG=webrtc:5882,webrtc:6804
NOPRESUBMIT=True

Review-Url: https://codereview.webrtc.org/2547483003
Cr-Commit-Position: refs/heads/master@{#15443}
This commit is contained in:
magjed 2016-12-06 04:29:37 -08:00 committed by Commit bot
parent 45bb5130b0
commit 768c64877e
98 changed files with 721 additions and 684 deletions

View File

@ -309,7 +309,7 @@ if (!build_with_chromium) {
if (is_android) {
deps += [
":android_junit_tests",
"//webrtc/sdk/android/instrumentationtests",
"//webrtc/sdk/android:libjingle_peerconnection_android_unittest",
]
} else {
deps += [ "modules/video_capture:video_capture_tests" ]
@ -712,8 +712,8 @@ if (rtc_include_tests) {
deps = [
"//base:base_java_test_support",
"//webrtc/api:libjingle_peerconnection_java",
"//webrtc/examples:AppRTCMobile_javalib",
"//webrtc/sdk/android:libjingle_peerconnection_java",
]
}
}

View File

@ -16,12 +16,6 @@ group("api") {
public_deps = [
":libjingle_peerconnection",
]
if (is_android && !build_with_chromium) {
public_deps += [
":libjingle_peerconnection_java",
":libjingle_peerconnection_so",
]
}
}
rtc_source_set("call_api") {
@ -155,191 +149,6 @@ rtc_static_library("libjingle_peerconnection") {
}
}
# Exclude the targets below from the Chromium build since they cannot be built
# due to incompability with Chromium's logging implementation.
if (is_android && !build_with_chromium) {
config("libjingle_peerconnection_jni_warnings_config") {
# The warnings below are enabled by default. Since GN orders compiler flags
# for a target before flags from configs, the only way to disable such
# warnings is by having them in a separate config, loaded from the target.
if (!is_win) {
cflags = [
"-Wno-sign-compare",
"-Wno-unused-variable",
]
}
}
rtc_static_library("libjingle_peerconnection_jni") {
sources = [
"android/jni/androidhistogram_jni.cc",
"android/jni/androidmediacodeccommon.h",
"android/jni/androidmediadecoder_jni.cc",
"android/jni/androidmediadecoder_jni.h",
"android/jni/androidmediaencoder_jni.cc",
"android/jni/androidmediaencoder_jni.h",
"android/jni/androidnetworkmonitor_jni.cc",
"android/jni/androidnetworkmonitor_jni.h",
"android/jni/androidvideotracksource.cc",
"android/jni/androidvideotracksource.h",
"android/jni/androidvideotracksource_jni.cc",
"android/jni/classreferenceholder.cc",
"android/jni/classreferenceholder.h",
"android/jni/jni_helpers.cc",
"android/jni/jni_helpers.h",
"android/jni/native_handle_impl.cc",
"android/jni/native_handle_impl.h",
"android/jni/peerconnection_jni.cc",
"android/jni/surfacetexturehelper_jni.cc",
"android/jni/surfacetexturehelper_jni.h",
]
configs += [ ":libjingle_peerconnection_jni_warnings_config" ]
if (!build_with_chromium && is_clang) {
# Suppress warnings from the Chromium Clang plugin (bugs.webrtc.org/163).
suppressed_configs += [
"//build/config/clang:extra_warnings",
"//build/config/clang:find_bad_constructs",
]
}
# TODO(jschuh): Bug 1348: fix this warning.
configs += [ "//build/config/compiler:no_size_t_to_int_warning" ]
if (is_win) {
cflags += [
"/wd4245", # conversion from "int" to "size_t", signed/unsigned mismatch.
"/wd4389", # signed/unsigned mismatch.
]
}
deps = [
":libjingle_peerconnection",
]
if (rtc_build_libyuv) {
deps += [ "$rtc_libyuv_dir" ]
public_deps = [
"$rtc_libyuv_dir",
]
} else {
# Need to add a directory normally exported by libyuv.
include_dirs = [ "$rtc_libyuv_dir/include" ]
}
}
rtc_static_library("libjingle_peerconnection_metrics_default_jni") {
sources = [
"android/jni/androidmetrics_jni.cc",
]
configs += [ ":libjingle_peerconnection_jni_warnings_config" ]
deps = [
":libjingle_peerconnection",
"../system_wrappers:field_trial_default",
"../system_wrappers:metrics_default",
]
}
rtc_shared_library("libjingle_peerconnection_so") {
sources = [
"android/jni/jni_onload.cc",
]
suppressed_configs += [ "//build/config/android:hide_native_jni_exports" ]
deps = [
":libjingle_peerconnection",
":libjingle_peerconnection_jni",
":libjingle_peerconnection_metrics_default_jni",
]
output_extension = "so"
}
}
# Classes that don't require jni can be used in Chromium.
if (is_android) {
android_library("libjingle_peerconnection_java") {
java_files = [
"../modules/audio_device/android/java/src/org/webrtc/voiceengine/BuildInfo.java",
"../modules/audio_device/android/java/src/org/webrtc/voiceengine/WebRtcAudioEffects.java",
"../modules/audio_device/android/java/src/org/webrtc/voiceengine/WebRtcAudioManager.java",
"../modules/audio_device/android/java/src/org/webrtc/voiceengine/WebRtcAudioRecord.java",
"../modules/audio_device/android/java/src/org/webrtc/voiceengine/WebRtcAudioTrack.java",
"../modules/audio_device/android/java/src/org/webrtc/voiceengine/WebRtcAudioUtils.java",
"android/java/src/org/webrtc/AudioSource.java",
"android/java/src/org/webrtc/AudioTrack.java",
"android/java/src/org/webrtc/CallSessionFileRotatingLogSink.java",
"android/java/src/org/webrtc/Camera1Capturer.java",
"android/java/src/org/webrtc/Camera1Enumerator.java",
"android/java/src/org/webrtc/Camera1Session.java",
"android/java/src/org/webrtc/Camera2Capturer.java",
"android/java/src/org/webrtc/Camera2Enumerator.java",
"android/java/src/org/webrtc/Camera2Session.java",
"android/java/src/org/webrtc/CameraCapturer.java",
"android/java/src/org/webrtc/CameraEnumerationAndroid.java",
"android/java/src/org/webrtc/CameraEnumerator.java",
"android/java/src/org/webrtc/CameraSession.java",
"android/java/src/org/webrtc/CameraVideoCapturer.java",
"android/java/src/org/webrtc/DataChannel.java",
"android/java/src/org/webrtc/EglBase.java",
"android/java/src/org/webrtc/EglBase10.java",
"android/java/src/org/webrtc/EglBase14.java",
"android/java/src/org/webrtc/EglRenderer.java",
"android/java/src/org/webrtc/FileVideoCapturer.java",
"android/java/src/org/webrtc/GlRectDrawer.java",
"android/java/src/org/webrtc/GlShader.java",
"android/java/src/org/webrtc/GlTextureFrameBuffer.java",
"android/java/src/org/webrtc/GlUtil.java",
"android/java/src/org/webrtc/Histogram.java",
"android/java/src/org/webrtc/IceCandidate.java",
"android/java/src/org/webrtc/MediaCodecVideoDecoder.java",
"android/java/src/org/webrtc/MediaCodecVideoEncoder.java",
"android/java/src/org/webrtc/MediaConstraints.java",
"android/java/src/org/webrtc/MediaSource.java",
"android/java/src/org/webrtc/MediaStream.java",
"android/java/src/org/webrtc/MediaStreamTrack.java",
"android/java/src/org/webrtc/NetworkMonitor.java",
"android/java/src/org/webrtc/NetworkMonitorAutoDetect.java",
"android/java/src/org/webrtc/PeerConnection.java",
"android/java/src/org/webrtc/PeerConnectionFactory.java",
"android/java/src/org/webrtc/RendererCommon.java",
"android/java/src/org/webrtc/RtpParameters.java",
"android/java/src/org/webrtc/RtpReceiver.java",
"android/java/src/org/webrtc/RtpSender.java",
"android/java/src/org/webrtc/ScreenCapturerAndroid.java",
"android/java/src/org/webrtc/SdpObserver.java",
"android/java/src/org/webrtc/SessionDescription.java",
"android/java/src/org/webrtc/StatsObserver.java",
"android/java/src/org/webrtc/StatsReport.java",
"android/java/src/org/webrtc/SurfaceTextureHelper.java",
"android/java/src/org/webrtc/SurfaceViewRenderer.java",
"android/java/src/org/webrtc/VideoCapturer.java",
"android/java/src/org/webrtc/VideoCapturerAndroid.java",
"android/java/src/org/webrtc/VideoFileRenderer.java",
"android/java/src/org/webrtc/VideoRenderer.java",
"android/java/src/org/webrtc/VideoRendererGui.java",
"android/java/src/org/webrtc/VideoSource.java",
"android/java/src/org/webrtc/VideoTrack.java",
"android/java/src/org/webrtc/YuvConverter.java",
]
deps = [
"../base:base_java",
]
}
android_library("libjingle_peerconnection_metrics_default_java") {
java_files = [ "android/java/src/org/webrtc/Metrics.java" ]
deps = [
"../base:base_java",
]
}
}
rtc_source_set("rtc_stats_api") {
cflags = []
sources = [
@ -491,9 +300,9 @@ if (rtc_include_tests) {
"test/androidtestinitializer.h",
]
deps += [
":libjingle_peerconnection_java",
":libjingle_peerconnection_jni",
"//testing/android/native_test:native_test_support",
"//webrtc/sdk/android:libjingle_peerconnection_java",
"//webrtc/sdk/android:libjingle_peerconnection_jni",
]
}

View File

@ -1 +0,0 @@
magjed@webrtc.org

View File

@ -0,0 +1,3 @@
include_rules = [
"+webrtc/sdk/android/src/jni",
]

View File

@ -1,5 +1,5 @@
/*
* Copyright 2015 The WebRTC project authors. All Rights Reserved.
* Copyright 2016 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
@ -7,35 +7,5 @@
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef WEBRTC_API_JAVA_JNI_ANDROIDMEDIADECODER_JNI_H_
#define WEBRTC_API_JAVA_JNI_ANDROIDMEDIADECODER_JNI_H_
#include "webrtc/api/android/jni/jni_helpers.h"
#include "webrtc/media/engine/webrtcvideodecoderfactory.h"
namespace webrtc_jni {
// Implementation of Android MediaCodec based decoder factory.
class MediaCodecVideoDecoderFactory
: public cricket::WebRtcVideoDecoderFactory {
public:
MediaCodecVideoDecoderFactory();
virtual ~MediaCodecVideoDecoderFactory();
void SetEGLContext(JNIEnv* jni, jobject render_egl_context);
// WebRtcVideoDecoderFactory implementation.
webrtc::VideoDecoder* CreateVideoDecoder(webrtc::VideoCodecType type)
override;
void DestroyVideoDecoder(webrtc::VideoDecoder* decoder) override;
private:
jobject egl_context_;
std::vector<webrtc::VideoCodecType> supported_codec_types_;
};
} // namespace webrtc_jni
#endif // WEBRTC_API_JAVA_JNI_ANDROIDMEDIADECODER_JNI_H_
// TODO(magjed): Update external dependencies and remove this.
#include "webrtc/sdk/android/src/jni/androidmediadecoder_jni.h"

View File

@ -1,5 +1,5 @@
/*
* Copyright 2015 The WebRTC project authors. All Rights Reserved.
* Copyright 2016 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
@ -7,43 +7,5 @@
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef WEBRTC_API_JAVA_JNI_ANDROIDMEDIAENCODER_JNI_H_
#define WEBRTC_API_JAVA_JNI_ANDROIDMEDIAENCODER_JNI_H_
#include <vector>
#include "webrtc/api/android/jni/jni_helpers.h"
#include "webrtc/media/engine/webrtcvideoencoderfactory.h"
namespace webrtc_jni {
// Implementation of Android MediaCodec based encoder factory.
class MediaCodecVideoEncoderFactory
: public cricket::WebRtcVideoEncoderFactory {
public:
MediaCodecVideoEncoderFactory();
virtual ~MediaCodecVideoEncoderFactory();
void SetEGLContext(JNIEnv* jni, jobject egl_context);
// WebRtcVideoEncoderFactory implementation.
webrtc::VideoEncoder* CreateVideoEncoder(
const cricket::VideoCodec& codec) override;
const std::vector<cricket::VideoCodec>& supported_codecs() const override;
void DestroyVideoEncoder(webrtc::VideoEncoder* encoder) override;
private:
// Disable overloaded virtual function warning. TODO(magjed): Remove once
// http://crbug/webrtc/6402 is fixed.
using cricket::WebRtcVideoEncoderFactory::CreateVideoEncoder;
jobject egl_context_;
// Empty if platform support is lacking, const after ctor returns.
std::vector<cricket::VideoCodec> supported_codecs_;
};
} // namespace webrtc_jni
#endif // WEBRTC_API_JAVA_JNI_ANDROIDMEDIAENCODER_JNI_H_
// TODO(magjed): Update external dependencies and remove this.
#include "webrtc/sdk/android/src/jni/androidmediaencoder_jni.h"

View File

@ -1,5 +1,5 @@
/*
* Copyright 2015 The WebRTC project authors. All Rights Reserved.
* Copyright 2016 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
@ -7,87 +7,5 @@
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef WEBRTC_API_JAVA_JNI_ANDROIDNETWORKMONITOR_JNI_H_
#define WEBRTC_API_JAVA_JNI_ANDROIDNETWORKMONITOR_JNI_H_
#include "webrtc/base/networkmonitor.h"
#include <map>
#include "webrtc/api/android/jni/jni_helpers.h"
#include "webrtc/base/basictypes.h"
#include "webrtc/base/thread_checker.h"
namespace webrtc_jni {
typedef int64_t NetworkHandle;
// c++ equivalent of java NetworkMonitorAutoDetect.ConnectionType.
enum NetworkType {
NETWORK_UNKNOWN,
NETWORK_ETHERNET,
NETWORK_WIFI,
NETWORK_4G,
NETWORK_3G,
NETWORK_2G,
NETWORK_UNKNOWN_CELLULAR,
NETWORK_BLUETOOTH,
NETWORK_NONE
};
// The information is collected from Android OS so that the native code can get
// the network type and handle (Android network ID) for each interface.
struct NetworkInformation {
std::string interface_name;
NetworkHandle handle;
NetworkType type;
std::vector<rtc::IPAddress> ip_addresses;
std::string ToString() const;
};
class AndroidNetworkMonitor : public rtc::NetworkMonitorBase,
public rtc::NetworkBinderInterface {
public:
AndroidNetworkMonitor();
static void SetAndroidContext(JNIEnv* jni, jobject context);
void Start() override;
void Stop() override;
int BindSocketToNetwork(int socket_fd,
const rtc::IPAddress& address) override;
rtc::AdapterType GetAdapterType(const std::string& if_name) override;
void OnNetworkConnected(const NetworkInformation& network_info);
void OnNetworkDisconnected(NetworkHandle network_handle);
void SetNetworkInfos(const std::vector<NetworkInformation>& network_infos);
private:
static jobject application_context_;
static int android_sdk_int_;
JNIEnv* jni() { return AttachCurrentThreadIfNeeded(); }
void OnNetworkConnected_w(const NetworkInformation& network_info);
void OnNetworkDisconnected_w(NetworkHandle network_handle);
ScopedGlobalRef<jclass> j_network_monitor_class_;
ScopedGlobalRef<jobject> j_network_monitor_;
rtc::ThreadChecker thread_checker_;
bool started_ = false;
std::map<std::string, rtc::AdapterType> adapter_type_by_name_;
std::map<rtc::IPAddress, NetworkHandle> network_handle_by_address_;
std::map<NetworkHandle, NetworkInformation> network_info_by_handle_;
};
class AndroidNetworkMonitorFactory : public rtc::NetworkMonitorFactory {
public:
AndroidNetworkMonitorFactory() {}
rtc::NetworkMonitorInterface* CreateNetworkMonitor() override;
};
} // namespace webrtc_jni
#endif // WEBRTC_API_JAVA_JNI_ANDROIDNETWORKMONITOR_JNI_H_
// TODO(magjed): Update external dependencies and remove this.
#include "webrtc/sdk/android/src/jni/androidnetworkmonitor_jni.h"

View File

@ -1,5 +1,5 @@
/*
* Copyright 2015 The WebRTC project authors. All Rights Reserved.
* Copyright 2016 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
@ -7,35 +7,5 @@
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
// Android's FindClass() is trickier than usual because the app-specific
// ClassLoader is not consulted when there is no app-specific frame on the
// stack. Consequently, we only look up all classes once in app/webrtc.
// http://developer.android.com/training/articles/perf-jni.html#faq_FindClass
#ifndef WEBRTC_API_JAVA_JNI_CLASSREFERENCEHOLDER_H_
#define WEBRTC_API_JAVA_JNI_CLASSREFERENCEHOLDER_H_
#include <jni.h>
#include <map>
#include <string>
namespace webrtc_jni {
// LoadGlobalClassReferenceHolder must be called in JNI_OnLoad.
void LoadGlobalClassReferenceHolder();
// FreeGlobalClassReferenceHolder must be called in JNI_UnLoad.
void FreeGlobalClassReferenceHolder();
// Returns a global reference guaranteed to be valid for the lifetime of the
// process.
jclass FindClass(JNIEnv* jni, const char* name);
// Convenience macro defining JNI-accessible methods in the org.webrtc package.
// Eliminates unnecessary boilerplate and line-wraps, reducing visual clutter.
#define JOW(rettype, name) extern "C" rettype JNIEXPORT JNICALL \
Java_org_webrtc_##name
} // namespace webrtc_jni
#endif // WEBRTC_API_JAVA_JNI_CLASSREFERENCEHOLDER_H_
// TODO(magjed): Update external dependencies and remove this.
#include "webrtc/sdk/android/src/jni/classreferenceholder.h"

View File

@ -1,5 +1,5 @@
/*
* Copyright 2015 The WebRTC project authors. All Rights Reserved.
* Copyright 2016 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
@ -7,185 +7,5 @@
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
// This file contain convenience functions and classes for JNI.
// Before using any of the methods, InitGlobalJniVariables must be called.
#ifndef WEBRTC_API_JAVA_JNI_JNI_HELPERS_H_
#define WEBRTC_API_JAVA_JNI_JNI_HELPERS_H_
#include <jni.h>
#include <string>
#include "webrtc/base/constructormagic.h"
#include "webrtc/base/checks.h"
#include "webrtc/base/thread_checker.h"
// Abort the process if |jni| has a Java exception pending.
// This macros uses the comma operator to execute ExceptionDescribe
// and ExceptionClear ignoring their return values and sending ""
// to the error stream.
#define CHECK_EXCEPTION(jni) \
RTC_CHECK(!jni->ExceptionCheck()) \
<< (jni->ExceptionDescribe(), jni->ExceptionClear(), "")
// Helper that calls ptr->Release() and aborts the process with a useful
// message if that didn't actually delete *ptr because of extra refcounts.
#define CHECK_RELEASE(ptr) \
RTC_CHECK_EQ(0, (ptr)->Release()) << "Unexpected refcount."
namespace webrtc_jni {
jint InitGlobalJniVariables(JavaVM *jvm);
// Return a |JNIEnv*| usable on this thread or NULL if this thread is detached.
JNIEnv* GetEnv();
JavaVM *GetJVM();
// Return a |JNIEnv*| usable on this thread. Attaches to |g_jvm| if necessary.
JNIEnv* AttachCurrentThreadIfNeeded();
// Return a |jlong| that will correctly convert back to |ptr|. This is needed
// because the alternative (of silently passing a 32-bit pointer to a vararg
// function expecting a 64-bit param) picks up garbage in the high 32 bits.
jlong jlongFromPointer(void* ptr);
// JNIEnv-helper methods that RTC_CHECK success: no Java exception thrown and
// found object/class/method/field is non-null.
jmethodID GetMethodID(
JNIEnv* jni, jclass c, const std::string& name, const char* signature);
jmethodID GetStaticMethodID(
JNIEnv* jni, jclass c, const char* name, const char* signature);
jfieldID GetFieldID(JNIEnv* jni, jclass c, const char* name,
const char* signature);
jclass GetObjectClass(JNIEnv* jni, jobject object);
// Throws an exception if the object field is null.
jobject GetObjectField(JNIEnv* jni, jobject object, jfieldID id);
jobject GetNullableObjectField(JNIEnv* jni, jobject object, jfieldID id);
jstring GetStringField(JNIEnv* jni, jobject object, jfieldID id);
jlong GetLongField(JNIEnv* jni, jobject object, jfieldID id);
jint GetIntField(JNIEnv* jni, jobject object, jfieldID id);
bool GetBooleanField(JNIEnv* jni, jobject object, jfieldID id);
// Returns true if |obj| == null in Java.
bool IsNull(JNIEnv* jni, jobject obj);
// Given a UTF-8 encoded |native| string return a new (UTF-16) jstring.
jstring JavaStringFromStdString(JNIEnv* jni, const std::string& native);
// Given a (UTF-16) jstring return a new UTF-8 native string.
std::string JavaToStdString(JNIEnv* jni, const jstring& j_string);
// Return the (singleton) Java Enum object corresponding to |index|;
jobject JavaEnumFromIndex(JNIEnv* jni, jclass state_class,
const std::string& state_class_name, int index);
// Returns the name of a Java enum.
std::string GetJavaEnumName(JNIEnv* jni,
const std::string& className,
jobject j_enum);
jobject NewGlobalRef(JNIEnv* jni, jobject o);
void DeleteGlobalRef(JNIEnv* jni, jobject o);
// Scope Java local references to the lifetime of this object. Use in all C++
// callbacks (i.e. entry points that don't originate in a Java callstack
// through a "native" method call).
class ScopedLocalRefFrame {
public:
explicit ScopedLocalRefFrame(JNIEnv* jni);
~ScopedLocalRefFrame();
private:
JNIEnv* jni_;
};
// Scoped holder for global Java refs.
template<class T> // T is jclass, jobject, jintArray, etc.
class ScopedGlobalRef {
public:
ScopedGlobalRef(JNIEnv* jni, T obj)
: obj_(static_cast<T>(jni->NewGlobalRef(obj))) {}
~ScopedGlobalRef() {
DeleteGlobalRef(AttachCurrentThreadIfNeeded(), obj_);
}
T operator*() const {
return obj_;
}
private:
T obj_;
};
// Provides a convenient way to iterate over a Java Iterable using the
// C++ range-for loop.
// E.g. for (jobject value : Iterable(jni, j_iterable)) { ... }
// Note: Since Java iterators cannot be duplicated, the iterator class is not
// copyable to prevent creating multiple C++ iterators that refer to the same
// Java iterator.
class Iterable {
public:
Iterable(JNIEnv* jni, jobject iterable) : jni_(jni), iterable_(iterable) {}
class Iterator {
public:
// Creates an iterator representing the end of any collection.
Iterator();
// Creates an iterator pointing to the beginning of the specified
// collection.
Iterator(JNIEnv* jni, jobject iterable);
// Move constructor - necessary to be able to return iterator types from
// functions.
Iterator(Iterator&& other);
// Move assignment should not be used.
Iterator& operator=(Iterator&&) = delete;
// Advances the iterator one step.
Iterator& operator++();
// Provides a way to compare the iterator with itself and with the end
// iterator.
// Note: all other comparison results are undefined, just like for C++ input
// iterators.
bool operator==(const Iterator& other);
bool operator!=(const Iterator& other) { return !(*this == other); }
jobject operator*();
private:
bool AtEnd() const;
JNIEnv* jni_ = nullptr;
jobject iterator_ = nullptr;
jobject value_ = nullptr;
jmethodID has_next_id_ = nullptr;
jmethodID next_id_ = nullptr;
rtc::ThreadChecker thread_checker_;
RTC_DISALLOW_COPY_AND_ASSIGN(Iterator);
};
Iterable::Iterator begin() { return Iterable::Iterator(jni_, iterable_); }
Iterable::Iterator end() { return Iterable::Iterator(); }
private:
JNIEnv* jni_;
jobject iterable_;
RTC_DISALLOW_COPY_AND_ASSIGN(Iterable);
};
} // namespace webrtc_jni
#endif // WEBRTC_API_JAVA_JNI_JNI_HELPERS_H_
// TODO(magjed): Update external dependencies and remove this.
#include "webrtc/sdk/android/src/jni/jni_helpers.h"

View File

@ -23,8 +23,6 @@ RTC_PUSH_IGNORING_WUNDEF()
#include "base/android/jni_android.h"
RTC_POP_IGNORING_WUNDEF()
#include "webrtc/api/android/jni/classreferenceholder.h"
#include "webrtc/api/android/jni/jni_helpers.h"
#include "webrtc/base/checks.h"
#include "webrtc/base/ssladapter.h"
#include "webrtc/voice_engine/include/voe_base.h"
@ -45,9 +43,7 @@ void EnsureInitializedOnce() {
RTC_CHECK_EQ(0, jni->GetJavaVM(&jvm));
jobject context = ::base::android::GetApplicationContext().obj();
RTC_CHECK_GE(webrtc_jni::InitGlobalJniVariables(jvm), 0);
RTC_CHECK(rtc::InitializeSSL()) << "Failed to InitializeSSL()";
webrtc_jni::LoadGlobalClassReferenceHolder();
webrtc::VoiceEngine::SetAndroidObjects(jvm, context);
}

View File

@ -40,7 +40,7 @@
"type": "console_test_launcher",
},
"libjingle_peerconnection_android_unittest": {
"label": "//webrtc/sdk/android/instrumentationtests:libjingle_peerconnection_android_unittest",
"label": "//webrtc/sdk/android:libjingle_peerconnection_android_unittest",
"type": "additional_compile_target",
},
"modules_tests": {

View File

@ -62,7 +62,7 @@ if (is_android) {
"//webrtc/base:base_java",
]
shared_libraries = [ "//webrtc/api:libjingle_peerconnection_so" ]
shared_libraries = [ "//webrtc/sdk/android:libjingle_peerconnection_so" ]
}
android_library("AppRTCMobile_javalib") {
@ -92,10 +92,10 @@ if (is_android) {
deps = [
":AppRTCMobile_resources",
"//webrtc/api:libjingle_peerconnection_java",
"//webrtc/api:libjingle_peerconnection_metrics_default_java",
"//webrtc/base:base_java",
"//webrtc/examples/androidapp/third_party/autobanh:autobanh_java",
"//webrtc/sdk/android:libjingle_peerconnection_java",
"//webrtc/sdk/android:libjingle_peerconnection_metrics_default_java",
]
}
@ -118,7 +118,7 @@ if (is_android) {
deps = [
":AppRTCMobile_javalib",
"//webrtc/api:libjingle_peerconnection_java",
"//webrtc/sdk/android:libjingle_peerconnection_java",
]
data = [

View File

@ -688,7 +688,7 @@ if (rtc_include_tests) {
if (is_android) {
deps += [
"//testing/android/native_test:native_test_support",
"//webrtc/api:libjingle_peerconnection_java",
"//webrtc/sdk/android:libjingle_peerconnection_java",
]
# Need to disable error due to the line in

221
webrtc/sdk/android/BUILD.gn Normal file
View File

@ -0,0 +1,221 @@
# Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
#
# Use of this source code is governed by a BSD-style license
# that can be found in the LICENSE file in the root of the source
# tree. An additional intellectual property rights grant can be found
# in the file PATENTS. All contributing project authors may
# be found in the AUTHORS file in the root of the source tree.
import("//webrtc/build/webrtc.gni")
import("//build/config/android/config.gni")
import("//build/config/android/rules.gni")
config("libjingle_peerconnection_jni_warnings_config") {
# The warnings below are enabled by default. Since GN orders compiler flags
# for a target before flags from configs, the only way to disable such
# warnings is by having them in a separate config, loaded from the target.
if (!is_win) {
cflags = [
"-Wno-sign-compare",
"-Wno-unused-variable",
]
}
}
rtc_static_library("libjingle_peerconnection_jni") {
sources = [
"src/jni/androidhistogram_jni.cc",
"src/jni/androidmediacodeccommon.h",
"src/jni/androidmediadecoder_jni.cc",
"src/jni/androidmediadecoder_jni.h",
"src/jni/androidmediaencoder_jni.cc",
"src/jni/androidmediaencoder_jni.h",
"src/jni/androidnetworkmonitor_jni.cc",
"src/jni/androidnetworkmonitor_jni.h",
"src/jni/androidvideotracksource.cc",
"src/jni/androidvideotracksource.h",
"src/jni/androidvideotracksource_jni.cc",
"src/jni/classreferenceholder.cc",
"src/jni/classreferenceholder.h",
"src/jni/jni_helpers.cc",
"src/jni/jni_helpers.h",
"src/jni/native_handle_impl.cc",
"src/jni/native_handle_impl.h",
"src/jni/peerconnection_jni.cc",
"src/jni/surfacetexturehelper_jni.cc",
"src/jni/surfacetexturehelper_jni.h",
]
configs += [ ":libjingle_peerconnection_jni_warnings_config" ]
if (is_clang) {
# Suppress warnings from the Chromium Clang plugin (bugs.webrtc.org/163).
suppressed_configs += [
"//build/config/clang:extra_warnings",
"//build/config/clang:find_bad_constructs",
]
}
# TODO(jschuh): Bug 1348: fix this warning.
configs += [ "//build/config/compiler:no_size_t_to_int_warning" ]
if (is_win) {
cflags += [
"/wd4245", # conversion from "int" to "size_t", signed/unsigned mismatch.
"/wd4389", # signed/unsigned mismatch.
]
}
deps = [
"//webrtc/api:libjingle_peerconnection",
]
if (rtc_build_libyuv) {
deps += [ "$rtc_libyuv_dir" ]
public_deps = [
"$rtc_libyuv_dir",
]
} else {
# Need to add a directory normally exported by libyuv.
include_dirs = [ "$rtc_libyuv_dir/include" ]
}
}
rtc_static_library("libjingle_peerconnection_metrics_default_jni") {
sources = [
"src/jni/androidmetrics_jni.cc",
]
configs += [ ":libjingle_peerconnection_jni_warnings_config" ]
deps = [
"//webrtc/api:libjingle_peerconnection",
"//webrtc/system_wrappers:field_trial_default",
"//webrtc/system_wrappers:metrics_default",
]
}
rtc_shared_library("libjingle_peerconnection_so") {
sources = [
"src/jni/jni_onload.cc",
]
suppressed_configs += [ "//build/config/android:hide_native_jni_exports" ]
deps = [
":libjingle_peerconnection_jni",
":libjingle_peerconnection_metrics_default_jni",
"//webrtc/api:libjingle_peerconnection",
]
output_extension = "so"
}
android_library("libjingle_peerconnection_java") {
java_files = [
"//webrtc/modules/audio_device/android/java/src/org/webrtc/voiceengine/BuildInfo.java",
"//webrtc/modules/audio_device/android/java/src/org/webrtc/voiceengine/WebRtcAudioEffects.java",
"//webrtc/modules/audio_device/android/java/src/org/webrtc/voiceengine/WebRtcAudioManager.java",
"//webrtc/modules/audio_device/android/java/src/org/webrtc/voiceengine/WebRtcAudioRecord.java",
"//webrtc/modules/audio_device/android/java/src/org/webrtc/voiceengine/WebRtcAudioTrack.java",
"//webrtc/modules/audio_device/android/java/src/org/webrtc/voiceengine/WebRtcAudioUtils.java",
"api/org/webrtc/AudioSource.java",
"api/org/webrtc/AudioTrack.java",
"api/org/webrtc/CallSessionFileRotatingLogSink.java",
"api/org/webrtc/Camera1Capturer.java",
"api/org/webrtc/Camera1Enumerator.java",
"api/org/webrtc/Camera1Session.java",
"api/org/webrtc/Camera2Capturer.java",
"api/org/webrtc/Camera2Enumerator.java",
"api/org/webrtc/Camera2Session.java",
"api/org/webrtc/CameraCapturer.java",
"api/org/webrtc/CameraEnumerationAndroid.java",
"api/org/webrtc/CameraEnumerator.java",
"api/org/webrtc/CameraSession.java",
"api/org/webrtc/CameraVideoCapturer.java",
"api/org/webrtc/DataChannel.java",
"api/org/webrtc/EglBase.java",
"api/org/webrtc/EglBase10.java",
"api/org/webrtc/EglBase14.java",
"api/org/webrtc/EglRenderer.java",
"api/org/webrtc/FileVideoCapturer.java",
"api/org/webrtc/GlRectDrawer.java",
"api/org/webrtc/GlShader.java",
"api/org/webrtc/GlTextureFrameBuffer.java",
"api/org/webrtc/GlUtil.java",
"api/org/webrtc/Histogram.java",
"api/org/webrtc/IceCandidate.java",
"api/org/webrtc/MediaCodecVideoDecoder.java",
"api/org/webrtc/MediaCodecVideoEncoder.java",
"api/org/webrtc/MediaConstraints.java",
"api/org/webrtc/MediaSource.java",
"api/org/webrtc/MediaStream.java",
"api/org/webrtc/MediaStreamTrack.java",
"api/org/webrtc/NetworkMonitor.java",
"api/org/webrtc/NetworkMonitorAutoDetect.java",
"api/org/webrtc/PeerConnection.java",
"api/org/webrtc/PeerConnectionFactory.java",
"api/org/webrtc/RendererCommon.java",
"api/org/webrtc/RtpParameters.java",
"api/org/webrtc/RtpReceiver.java",
"api/org/webrtc/RtpSender.java",
"api/org/webrtc/ScreenCapturerAndroid.java",
"api/org/webrtc/SdpObserver.java",
"api/org/webrtc/SessionDescription.java",
"api/org/webrtc/StatsObserver.java",
"api/org/webrtc/StatsReport.java",
"api/org/webrtc/SurfaceTextureHelper.java",
"api/org/webrtc/SurfaceViewRenderer.java",
"api/org/webrtc/VideoCapturer.java",
"api/org/webrtc/VideoCapturerAndroid.java",
"api/org/webrtc/VideoFileRenderer.java",
"api/org/webrtc/VideoRenderer.java",
"api/org/webrtc/VideoRendererGui.java",
"api/org/webrtc/VideoSource.java",
"api/org/webrtc/VideoTrack.java",
"api/org/webrtc/YuvConverter.java",
]
deps = [
"//webrtc/base:base_java",
]
}
android_library("libjingle_peerconnection_metrics_default_java") {
java_files = [ "api/org/webrtc/Metrics.java" ]
deps = [
"//webrtc/base:base_java",
]
}
if (rtc_include_tests) {
instrumentation_test_apk("libjingle_peerconnection_android_unittest") {
apk_name = "libjingle_peerconnection_android_unittest"
android_manifest = "instrumentationtests/AndroidManifest.xml"
java_files = [
"instrumentationtests/src/org/webrtc/Camera1CapturerUsingByteBufferTest.java",
"instrumentationtests/src/org/webrtc/Camera1CapturerUsingTextureTest.java",
"instrumentationtests/src/org/webrtc/Camera2CapturerTest.java",
"instrumentationtests/src/org/webrtc/CameraVideoCapturerTestFixtures.java",
"instrumentationtests/src/org/webrtc/EglRendererTest.java",
"instrumentationtests/src/org/webrtc/GlRectDrawerTest.java",
"instrumentationtests/src/org/webrtc/MediaCodecVideoEncoderTest.java",
"instrumentationtests/src/org/webrtc/NetworkMonitorTest.java",
"instrumentationtests/src/org/webrtc/PeerConnectionTest.java",
"instrumentationtests/src/org/webrtc/RendererCommonTest.java",
"instrumentationtests/src/org/webrtc/SurfaceTextureHelperTest.java",
"instrumentationtests/src/org/webrtc/SurfaceViewRendererOnMeasureTest.java",
"instrumentationtests/src/org/webrtc/WebRtcJniBootTest.java",
]
deps = [
"//base:base_java",
"//webrtc/base:base_java",
"//webrtc/sdk/android:libjingle_peerconnection_java",
"//webrtc/sdk/android:libjingle_peerconnection_metrics_default_java",
]
shared_libraries = [ "//webrtc/sdk/android:libjingle_peerconnection_so" ]
}
}

View File

@ -1,51 +0,0 @@
# Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
#
# Use of this source code is governed by a BSD-style license
# that can be found in the LICENSE file in the root of the source
# tree. An additional intellectual property rights grant can be found
# in the file PATENTS. All contributing project authors may
# be found in the AUTHORS file in the root of the source tree.
import("//build/config/android/config.gni")
import("//build/config/android/rules.gni")
import("//webrtc/build/webrtc.gni")
group("instrumentationtests") {
# This target shall build all targets in instrumentationtests.
testonly = true
public_deps = []
public_deps += [ ":libjingle_peerconnection_android_unittest" ]
}
if (rtc_include_tests) {
instrumentation_test_apk("libjingle_peerconnection_android_unittest") {
apk_name = "libjingle_peerconnection_android_unittest"
android_manifest = "AndroidManifest.xml"
java_files = [
"src/org/webrtc/Camera1CapturerUsingByteBufferTest.java",
"src/org/webrtc/Camera1CapturerUsingTextureTest.java",
"src/org/webrtc/Camera2CapturerTest.java",
"src/org/webrtc/CameraVideoCapturerTestFixtures.java",
"src/org/webrtc/EglRendererTest.java",
"src/org/webrtc/GlRectDrawerTest.java",
"src/org/webrtc/MediaCodecVideoEncoderTest.java",
"src/org/webrtc/NetworkMonitorTest.java",
"src/org/webrtc/PeerConnectionTest.java",
"src/org/webrtc/RendererCommonTest.java",
"src/org/webrtc/SurfaceTextureHelperTest.java",
"src/org/webrtc/SurfaceViewRendererOnMeasureTest.java",
"src/org/webrtc/WebRtcJniBootTest.java",
]
deps = [
"../../../api:libjingle_peerconnection_java",
"../../../api:libjingle_peerconnection_metrics_default_java",
"../../../base:base_java",
"//base:base_java",
]
shared_libraries = [ "../../../api:libjingle_peerconnection_so" ]
}
}

View File

@ -0,0 +1,5 @@
include_rules = [
"+third_party/libyuv",
"+webrtc/common_video/libyuv/include/webrtc_libyuv.h",
"+webrtc/voice_engine/include/voe_base.h",
]

View File

@ -11,9 +11,9 @@
#include <map>
#include <memory>
#include "webrtc/api/android/jni/classreferenceholder.h"
#include "webrtc/api/android/jni/jni_helpers.h"
#include "webrtc/api/android/jni/native_handle_impl.h"
#include "webrtc/sdk/android/src/jni/classreferenceholder.h"
#include "webrtc/sdk/android/src/jni/jni_helpers.h"
#include "webrtc/sdk/android/src/jni/native_handle_impl.h"
#include "webrtc/system_wrappers/include/metrics.h"
// Enables collection of native histograms and creating them.

View File

@ -8,15 +8,15 @@
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef WEBRTC_API_JAVA_JNI_ANDROIDMEDIACODECCOMMON_H_
#define WEBRTC_API_JAVA_JNI_ANDROIDMEDIACODECCOMMON_H_
#ifndef WEBRTC_SDK_ANDROID_SRC_JNI_ANDROIDMEDIACODECCOMMON_H_
#define WEBRTC_SDK_ANDROID_SRC_JNI_ANDROIDMEDIACODECCOMMON_H_
#include <android/log.h>
#include <string>
#include "webrtc/base/thread.h"
#include "webrtc/api/android/jni/classreferenceholder.h"
#include "webrtc/api/android/jni/jni_helpers.h"
#include "webrtc/sdk/android/src/jni/classreferenceholder.h"
#include "webrtc/sdk/android/src/jni/jni_helpers.h"
#include "webrtc/base/logging.h"
#include "webrtc/base/thread.h"
@ -94,4 +94,4 @@ static inline bool CheckException(JNIEnv* jni) {
} // namespace webrtc_jni
#endif // WEBRTC_API_JAVA_JNI_ANDROIDMEDIACODECCOMMON_H_
#endif // WEBRTC_SDK_ANDROID_SRC_JNI_ANDROIDMEDIACODECCOMMON_H_

View File

@ -14,15 +14,15 @@
// NOTICE: androidmediadecoder_jni.h must be included before
// androidmediacodeccommon.h to avoid build errors.
#include "webrtc/api/android/jni/androidmediadecoder_jni.h"
#include "webrtc/sdk/android/src/jni/androidmediadecoder_jni.h"
#include "third_party/libyuv/include/libyuv/convert.h"
#include "third_party/libyuv/include/libyuv/convert_from.h"
#include "third_party/libyuv/include/libyuv/video_common.h"
#include "webrtc/api/android/jni/androidmediacodeccommon.h"
#include "webrtc/api/android/jni/classreferenceholder.h"
#include "webrtc/api/android/jni/native_handle_impl.h"
#include "webrtc/api/android/jni/surfacetexturehelper_jni.h"
#include "webrtc/sdk/android/src/jni/androidmediacodeccommon.h"
#include "webrtc/sdk/android/src/jni/classreferenceholder.h"
#include "webrtc/sdk/android/src/jni/native_handle_impl.h"
#include "webrtc/sdk/android/src/jni/surfacetexturehelper_jni.h"
#include "webrtc/base/bind.h"
#include "webrtc/base/checks.h"
#include "webrtc/base/logging.h"

View File

@ -0,0 +1,41 @@
/*
* Copyright 2015 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef WEBRTC_SDK_ANDROID_SRC_JNI_ANDROIDMEDIADECODER_JNI_H_
#define WEBRTC_SDK_ANDROID_SRC_JNI_ANDROIDMEDIADECODER_JNI_H_
#include "webrtc/sdk/android/src/jni/jni_helpers.h"
#include "webrtc/media/engine/webrtcvideodecoderfactory.h"
namespace webrtc_jni {
// Implementation of Android MediaCodec based decoder factory.
class MediaCodecVideoDecoderFactory
: public cricket::WebRtcVideoDecoderFactory {
public:
MediaCodecVideoDecoderFactory();
virtual ~MediaCodecVideoDecoderFactory();
void SetEGLContext(JNIEnv* jni, jobject render_egl_context);
// WebRtcVideoDecoderFactory implementation.
webrtc::VideoDecoder* CreateVideoDecoder(webrtc::VideoCodecType type)
override;
void DestroyVideoDecoder(webrtc::VideoDecoder* decoder) override;
private:
jobject egl_context_;
std::vector<webrtc::VideoCodecType> supported_codec_types_;
};
} // namespace webrtc_jni
#endif // WEBRTC_SDK_ANDROID_SRC_JNI_ANDROIDMEDIADECODER_JNI_H_

View File

@ -10,7 +10,7 @@
// NOTICE: androidmediaencoder_jni.h must be included before
// androidmediacodeccommon.h to avoid build errors.
#include "webrtc/api/android/jni/androidmediaencoder_jni.h"
#include "webrtc/sdk/android/src/jni/androidmediaencoder_jni.h"
#include <algorithm>
#include <memory>
@ -19,9 +19,9 @@
#include "third_party/libyuv/include/libyuv/convert.h"
#include "third_party/libyuv/include/libyuv/convert_from.h"
#include "third_party/libyuv/include/libyuv/video_common.h"
#include "webrtc/api/android/jni/androidmediacodeccommon.h"
#include "webrtc/api/android/jni/classreferenceholder.h"
#include "webrtc/api/android/jni/native_handle_impl.h"
#include "webrtc/sdk/android/src/jni/androidmediacodeccommon.h"
#include "webrtc/sdk/android/src/jni/classreferenceholder.h"
#include "webrtc/sdk/android/src/jni/native_handle_impl.h"
#include "webrtc/base/bind.h"
#include "webrtc/base/checks.h"
#include "webrtc/base/logging.h"

View File

@ -0,0 +1,49 @@
/*
* Copyright 2015 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef WEBRTC_SDK_ANDROID_SRC_JNI_ANDROIDMEDIAENCODER_JNI_H_
#define WEBRTC_SDK_ANDROID_SRC_JNI_ANDROIDMEDIAENCODER_JNI_H_
#include <vector>
#include "webrtc/sdk/android/src/jni/jni_helpers.h"
#include "webrtc/media/engine/webrtcvideoencoderfactory.h"
namespace webrtc_jni {
// Implementation of Android MediaCodec based encoder factory.
class MediaCodecVideoEncoderFactory
: public cricket::WebRtcVideoEncoderFactory {
public:
MediaCodecVideoEncoderFactory();
virtual ~MediaCodecVideoEncoderFactory();
void SetEGLContext(JNIEnv* jni, jobject egl_context);
// WebRtcVideoEncoderFactory implementation.
webrtc::VideoEncoder* CreateVideoEncoder(
const cricket::VideoCodec& codec) override;
const std::vector<cricket::VideoCodec>& supported_codecs() const override;
void DestroyVideoEncoder(webrtc::VideoEncoder* encoder) override;
private:
// Disable overloaded virtual function warning. TODO(magjed): Remove once
// http://crbug/webrtc/6402 is fixed.
using cricket::WebRtcVideoEncoderFactory::CreateVideoEncoder;
jobject egl_context_;
// Empty if platform support is lacking, const after ctor returns.
std::vector<cricket::VideoCodec> supported_codecs_;
};
} // namespace webrtc_jni
#endif // WEBRTC_SDK_ANDROID_SRC_JNI_ANDROIDMEDIAENCODER_JNI_H_

View File

@ -11,8 +11,8 @@
#include <map>
#include <memory>
#include "webrtc/api/android/jni/classreferenceholder.h"
#include "webrtc/api/android/jni/jni_helpers.h"
#include "webrtc/sdk/android/src/jni/classreferenceholder.h"
#include "webrtc/sdk/android/src/jni/jni_helpers.h"
#include "webrtc/system_wrappers/include/metrics.h"
#include "webrtc/system_wrappers/include/metrics_default.h"

View File

@ -8,14 +8,14 @@
* be found in the AUTHORS file in the root of the source tree.
*/
#include "webrtc/api/android/jni/androidnetworkmonitor_jni.h"
#include "webrtc/sdk/android/src/jni/androidnetworkmonitor_jni.h"
#include <dlfcn.h>
// This was added in Lollipop to dlfcn.h
#define RTLD_NOLOAD 4
#include "webrtc/api/android/jni/classreferenceholder.h"
#include "webrtc/api/android/jni/jni_helpers.h"
#include "webrtc/sdk/android/src/jni/classreferenceholder.h"
#include "webrtc/sdk/android/src/jni/jni_helpers.h"
#include "webrtc/base/bind.h"
#include "webrtc/base/common.h"
#include "webrtc/base/ipaddress.h"

View File

@ -0,0 +1,93 @@
/*
* Copyright 2015 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef WEBRTC_SDK_ANDROID_SRC_JNI_ANDROIDNETWORKMONITOR_JNI_H_
#define WEBRTC_SDK_ANDROID_SRC_JNI_ANDROIDNETWORKMONITOR_JNI_H_
#include "webrtc/base/networkmonitor.h"
#include <map>
#include "webrtc/sdk/android/src/jni/jni_helpers.h"
#include "webrtc/base/basictypes.h"
#include "webrtc/base/thread_checker.h"
namespace webrtc_jni {
typedef int64_t NetworkHandle;
// c++ equivalent of java NetworkMonitorAutoDetect.ConnectionType.
enum NetworkType {
NETWORK_UNKNOWN,
NETWORK_ETHERNET,
NETWORK_WIFI,
NETWORK_4G,
NETWORK_3G,
NETWORK_2G,
NETWORK_UNKNOWN_CELLULAR,
NETWORK_BLUETOOTH,
NETWORK_NONE
};
// The information is collected from Android OS so that the native code can get
// the network type and handle (Android network ID) for each interface.
struct NetworkInformation {
std::string interface_name;
NetworkHandle handle;
NetworkType type;
std::vector<rtc::IPAddress> ip_addresses;
std::string ToString() const;
};
class AndroidNetworkMonitor : public rtc::NetworkMonitorBase,
public rtc::NetworkBinderInterface {
public:
AndroidNetworkMonitor();
static void SetAndroidContext(JNIEnv* jni, jobject context);
void Start() override;
void Stop() override;
int BindSocketToNetwork(int socket_fd,
const rtc::IPAddress& address) override;
rtc::AdapterType GetAdapterType(const std::string& if_name) override;
void OnNetworkConnected(const NetworkInformation& network_info);
void OnNetworkDisconnected(NetworkHandle network_handle);
void SetNetworkInfos(const std::vector<NetworkInformation>& network_infos);
private:
static jobject application_context_;
static int android_sdk_int_;
JNIEnv* jni() { return AttachCurrentThreadIfNeeded(); }
void OnNetworkConnected_w(const NetworkInformation& network_info);
void OnNetworkDisconnected_w(NetworkHandle network_handle);
ScopedGlobalRef<jclass> j_network_monitor_class_;
ScopedGlobalRef<jobject> j_network_monitor_;
rtc::ThreadChecker thread_checker_;
bool started_ = false;
std::map<std::string, rtc::AdapterType> adapter_type_by_name_;
std::map<rtc::IPAddress, NetworkHandle> network_handle_by_address_;
std::map<NetworkHandle, NetworkInformation> network_info_by_handle_;
};
class AndroidNetworkMonitorFactory : public rtc::NetworkMonitorFactory {
public:
AndroidNetworkMonitorFactory() {}
rtc::NetworkMonitorInterface* CreateNetworkMonitor() override;
};
} // namespace webrtc_jni
#endif // WEBRTC_SDK_ANDROID_SRC_JNI_ANDROIDNETWORKMONITOR_JNI_H_

View File

@ -8,7 +8,7 @@
* be found in the AUTHORS file in the root of the source tree.
*/
#include "webrtc/api/android/jni/androidvideotracksource.h"
#include "webrtc/sdk/android/src/jni/androidvideotracksource.h"
#include <utility>

View File

@ -11,8 +11,8 @@
#ifndef WEBRTC_API_ANDROID_JNI_ANDROIDVIDEOTRACKSOURCE_H_
#define WEBRTC_API_ANDROID_JNI_ANDROIDVIDEOTRACKSOURCE_H_
#include "webrtc/api/android/jni/native_handle_impl.h"
#include "webrtc/api/android/jni/surfacetexturehelper_jni.h"
#include "webrtc/sdk/android/src/jni/native_handle_impl.h"
#include "webrtc/sdk/android/src/jni/surfacetexturehelper_jni.h"
#include "webrtc/base/asyncinvoker.h"
#include "webrtc/base/checks.h"
#include "webrtc/base/thread_checker.h"

View File

@ -8,8 +8,8 @@
* be found in the AUTHORS file in the root of the source tree.
*/
#include "webrtc/api/android/jni/androidvideotracksource.h"
#include "webrtc/api/android/jni/classreferenceholder.h"
#include "webrtc/sdk/android/src/jni/androidvideotracksource.h"
#include "webrtc/sdk/android/src/jni/classreferenceholder.h"
#include "webrtc/api/videosourceproxy.h"
// Identifiers are over 80 characters long so this is needed to fit them on one

View File

@ -7,9 +7,9 @@
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include "webrtc/api/android/jni/classreferenceholder.h"
#include "webrtc/sdk/android/src/jni/classreferenceholder.h"
#include "webrtc/api/android/jni/jni_helpers.h"
#include "webrtc/sdk/android/src/jni/jni_helpers.h"
namespace webrtc_jni {

View File

@ -0,0 +1,41 @@
/*
* Copyright 2015 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
// Android's FindClass() is trickier than usual because the app-specific
// ClassLoader is not consulted when there is no app-specific frame on the
// stack. Consequently, we only look up all classes once in app/webrtc.
// http://developer.android.com/training/articles/perf-jni.html#faq_FindClass
#ifndef WEBRTC_SDK_ANDROID_SRC_JNI_CLASSREFERENCEHOLDER_H_
#define WEBRTC_SDK_ANDROID_SRC_JNI_CLASSREFERENCEHOLDER_H_
#include <jni.h>
#include <map>
#include <string>
namespace webrtc_jni {
// LoadGlobalClassReferenceHolder must be called in JNI_OnLoad.
void LoadGlobalClassReferenceHolder();
// FreeGlobalClassReferenceHolder must be called in JNI_UnLoad.
void FreeGlobalClassReferenceHolder();
// Returns a global reference guaranteed to be valid for the lifetime of the
// process.
jclass FindClass(JNIEnv* jni, const char* name);
// Convenience macro defining JNI-accessible methods in the org.webrtc package.
// Eliminates unnecessary boilerplate and line-wraps, reducing visual clutter.
#define JOW(rettype, name) extern "C" rettype JNIEXPORT JNICALL \
Java_org_webrtc_##name
} // namespace webrtc_jni
#endif // WEBRTC_SDK_ANDROID_SRC_JNI_CLASSREFERENCEHOLDER_H_

View File

@ -7,9 +7,9 @@
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include "webrtc/api/android/jni/jni_helpers.h"
#include "webrtc/sdk/android/src/jni/jni_helpers.h"
#include "webrtc/api/android/jni/classreferenceholder.h"
#include "webrtc/sdk/android/src/jni/classreferenceholder.h"
#include <asm/unistd.h>
#include <sys/prctl.h>

View File

@ -0,0 +1,191 @@
/*
* Copyright 2015 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
// This file contain convenience functions and classes for JNI.
// Before using any of the methods, InitGlobalJniVariables must be called.
#ifndef WEBRTC_SDK_ANDROID_SRC_JNI_JNI_HELPERS_H_
#define WEBRTC_SDK_ANDROID_SRC_JNI_JNI_HELPERS_H_
#include <jni.h>
#include <string>
#include "webrtc/base/constructormagic.h"
#include "webrtc/base/checks.h"
#include "webrtc/base/thread_checker.h"
// Abort the process if |jni| has a Java exception pending.
// This macros uses the comma operator to execute ExceptionDescribe
// and ExceptionClear ignoring their return values and sending ""
// to the error stream.
#define CHECK_EXCEPTION(jni) \
RTC_CHECK(!jni->ExceptionCheck()) \
<< (jni->ExceptionDescribe(), jni->ExceptionClear(), "")
// Helper that calls ptr->Release() and aborts the process with a useful
// message if that didn't actually delete *ptr because of extra refcounts.
#define CHECK_RELEASE(ptr) \
RTC_CHECK_EQ(0, (ptr)->Release()) << "Unexpected refcount."
namespace webrtc_jni {
jint InitGlobalJniVariables(JavaVM *jvm);
// Return a |JNIEnv*| usable on this thread or NULL if this thread is detached.
JNIEnv* GetEnv();
JavaVM *GetJVM();
// Return a |JNIEnv*| usable on this thread. Attaches to |g_jvm| if necessary.
JNIEnv* AttachCurrentThreadIfNeeded();
// Return a |jlong| that will correctly convert back to |ptr|. This is needed
// because the alternative (of silently passing a 32-bit pointer to a vararg
// function expecting a 64-bit param) picks up garbage in the high 32 bits.
jlong jlongFromPointer(void* ptr);
// JNIEnv-helper methods that RTC_CHECK success: no Java exception thrown and
// found object/class/method/field is non-null.
jmethodID GetMethodID(
JNIEnv* jni, jclass c, const std::string& name, const char* signature);
jmethodID GetStaticMethodID(
JNIEnv* jni, jclass c, const char* name, const char* signature);
jfieldID GetFieldID(JNIEnv* jni, jclass c, const char* name,
const char* signature);
jclass GetObjectClass(JNIEnv* jni, jobject object);
// Throws an exception if the object field is null.
jobject GetObjectField(JNIEnv* jni, jobject object, jfieldID id);
jobject GetNullableObjectField(JNIEnv* jni, jobject object, jfieldID id);
jstring GetStringField(JNIEnv* jni, jobject object, jfieldID id);
jlong GetLongField(JNIEnv* jni, jobject object, jfieldID id);
jint GetIntField(JNIEnv* jni, jobject object, jfieldID id);
bool GetBooleanField(JNIEnv* jni, jobject object, jfieldID id);
// Returns true if |obj| == null in Java.
bool IsNull(JNIEnv* jni, jobject obj);
// Given a UTF-8 encoded |native| string return a new (UTF-16) jstring.
jstring JavaStringFromStdString(JNIEnv* jni, const std::string& native);
// Given a (UTF-16) jstring return a new UTF-8 native string.
std::string JavaToStdString(JNIEnv* jni, const jstring& j_string);
// Return the (singleton) Java Enum object corresponding to |index|;
jobject JavaEnumFromIndex(JNIEnv* jni, jclass state_class,
const std::string& state_class_name, int index);
// Returns the name of a Java enum.
std::string GetJavaEnumName(JNIEnv* jni,
const std::string& className,
jobject j_enum);
jobject NewGlobalRef(JNIEnv* jni, jobject o);
void DeleteGlobalRef(JNIEnv* jni, jobject o);
// Scope Java local references to the lifetime of this object. Use in all C++
// callbacks (i.e. entry points that don't originate in a Java callstack
// through a "native" method call).
class ScopedLocalRefFrame {
public:
explicit ScopedLocalRefFrame(JNIEnv* jni);
~ScopedLocalRefFrame();
private:
JNIEnv* jni_;
};
// Scoped holder for global Java refs.
template<class T> // T is jclass, jobject, jintArray, etc.
class ScopedGlobalRef {
public:
ScopedGlobalRef(JNIEnv* jni, T obj)
: obj_(static_cast<T>(jni->NewGlobalRef(obj))) {}
~ScopedGlobalRef() {
DeleteGlobalRef(AttachCurrentThreadIfNeeded(), obj_);
}
T operator*() const {
return obj_;
}
private:
T obj_;
};
// Provides a convenient way to iterate over a Java Iterable using the
// C++ range-for loop.
// E.g. for (jobject value : Iterable(jni, j_iterable)) { ... }
// Note: Since Java iterators cannot be duplicated, the iterator class is not
// copyable to prevent creating multiple C++ iterators that refer to the same
// Java iterator.
class Iterable {
public:
Iterable(JNIEnv* jni, jobject iterable) : jni_(jni), iterable_(iterable) {}
class Iterator {
public:
// Creates an iterator representing the end of any collection.
Iterator();
// Creates an iterator pointing to the beginning of the specified
// collection.
Iterator(JNIEnv* jni, jobject iterable);
// Move constructor - necessary to be able to return iterator types from
// functions.
Iterator(Iterator&& other);
// Move assignment should not be used.
Iterator& operator=(Iterator&&) = delete;
// Advances the iterator one step.
Iterator& operator++();
// Provides a way to compare the iterator with itself and with the end
// iterator.
// Note: all other comparison results are undefined, just like for C++ input
// iterators.
bool operator==(const Iterator& other);
bool operator!=(const Iterator& other) { return !(*this == other); }
jobject operator*();
private:
bool AtEnd() const;
JNIEnv* jni_ = nullptr;
jobject iterator_ = nullptr;
jobject value_ = nullptr;
jmethodID has_next_id_ = nullptr;
jmethodID next_id_ = nullptr;
rtc::ThreadChecker thread_checker_;
RTC_DISALLOW_COPY_AND_ASSIGN(Iterator);
};
Iterable::Iterator begin() { return Iterable::Iterator(jni_, iterable_); }
Iterable::Iterator end() { return Iterable::Iterator(); }
private:
JNIEnv* jni_;
jobject iterable_;
RTC_DISALLOW_COPY_AND_ASSIGN(Iterable);
};
} // namespace webrtc_jni
#endif // WEBRTC_SDK_ANDROID_SRC_JNI_JNI_HELPERS_H_

View File

@ -12,8 +12,8 @@
#undef JNIEXPORT
#define JNIEXPORT __attribute__((visibility("default")))
#include "webrtc/api/android/jni/classreferenceholder.h"
#include "webrtc/api/android/jni/jni_helpers.h"
#include "webrtc/sdk/android/src/jni/classreferenceholder.h"
#include "webrtc/sdk/android/src/jni/jni_helpers.h"
#include "webrtc/base/ssladapter.h"
namespace webrtc_jni {

View File

@ -8,11 +8,11 @@
* be found in the AUTHORS file in the root of the source tree.
*/
#include "webrtc/api/android/jni/native_handle_impl.h"
#include "webrtc/sdk/android/src/jni/native_handle_impl.h"
#include <memory>
#include "webrtc/api/android/jni/jni_helpers.h"
#include "webrtc/sdk/android/src/jni/jni_helpers.h"
#include "webrtc/base/bind.h"
#include "webrtc/base/checks.h"
#include "webrtc/base/keep_ref_until_done.h"

View File

@ -8,8 +8,8 @@
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef WEBRTC_API_JAVA_JNI_NATIVE_HANDLE_IMPL_H_
#define WEBRTC_API_JAVA_JNI_NATIVE_HANDLE_IMPL_H_
#ifndef WEBRTC_SDK_ANDROID_SRC_JNI_NATIVE_HANDLE_IMPL_H_
#define WEBRTC_SDK_ANDROID_SRC_JNI_NATIVE_HANDLE_IMPL_H_
#include <jni.h>
@ -84,4 +84,4 @@ class AndroidTextureBuffer : public webrtc::NativeHandleBuffer {
} // namespace webrtc_jni
#endif // WEBRTC_API_JAVA_JNI_NATIVE_HANDLE_IMPL_H_
#endif // WEBRTC_SDK_ANDROID_SRC_JNI_NATIVE_HANDLE_IMPL_H_

View File

@ -45,13 +45,13 @@
#include "third_party/libyuv/include/libyuv/convert_from.h"
#include "third_party/libyuv/include/libyuv/scale.h"
#include "webrtc/api/android/jni/androidmediadecoder_jni.h"
#include "webrtc/api/android/jni/androidmediaencoder_jni.h"
#include "webrtc/api/android/jni/androidnetworkmonitor_jni.h"
#include "webrtc/api/android/jni/androidvideotracksource.h"
#include "webrtc/api/android/jni/classreferenceholder.h"
#include "webrtc/api/android/jni/jni_helpers.h"
#include "webrtc/api/android/jni/native_handle_impl.h"
#include "webrtc/sdk/android/src/jni/androidmediadecoder_jni.h"
#include "webrtc/sdk/android/src/jni/androidmediaencoder_jni.h"
#include "webrtc/sdk/android/src/jni/androidnetworkmonitor_jni.h"
#include "webrtc/sdk/android/src/jni/androidvideotracksource.h"
#include "webrtc/sdk/android/src/jni/classreferenceholder.h"
#include "webrtc/sdk/android/src/jni/jni_helpers.h"
#include "webrtc/sdk/android/src/jni/native_handle_impl.h"
#include "webrtc/api/mediaconstraintsinterface.h"
#include "webrtc/api/peerconnectioninterface.h"
#include "webrtc/api/rtpreceiverinterface.h"

View File

@ -9,9 +9,9 @@
*/
#include "webrtc/api/android/jni/surfacetexturehelper_jni.h"
#include "webrtc/sdk/android/src/jni/surfacetexturehelper_jni.h"
#include "webrtc/api/android/jni/classreferenceholder.h"
#include "webrtc/sdk/android/src/jni/classreferenceholder.h"
#include "webrtc/base/bind.h"
#include "webrtc/base/checks.h"
#include "webrtc/base/logging.h"

View File

@ -8,13 +8,13 @@
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef WEBRTC_API_JAVA_JNI_SURFACETEXTUREHELPER_JNI_H_
#define WEBRTC_API_JAVA_JNI_SURFACETEXTUREHELPER_JNI_H_
#ifndef WEBRTC_SDK_ANDROID_SRC_JNI_SURFACETEXTUREHELPER_JNI_H_
#define WEBRTC_SDK_ANDROID_SRC_JNI_SURFACETEXTUREHELPER_JNI_H_
#include <jni.h>
#include "webrtc/api/android/jni/jni_helpers.h"
#include "webrtc/api/android/jni/native_handle_impl.h"
#include "webrtc/sdk/android/src/jni/jni_helpers.h"
#include "webrtc/sdk/android/src/jni/native_handle_impl.h"
#include "webrtc/base/refcount.h"
#include "webrtc/base/scoped_ref_ptr.h"
#include "webrtc/common_video/include/video_frame_buffer.h"
@ -65,4 +65,4 @@ class SurfaceTextureHelper : public rtc::RefCountInterface {
} // namespace webrtc_jni
#endif // WEBRTC_API_JAVA_JNI_SURFACETEXTUREHELPER_JNI_H_
#endif // WEBRTC_SDK_ANDROID_SRC_JNI_SURFACETEXTUREHELPER_JNI_H_