Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(98)

Unified Diff: talk/app/webrtc/test/androidtestinitializer.cc

Issue 1570513004: Reland "Add APK targets to build libjingle tests for Android." (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « talk/app/webrtc/test/androidtestinitializer.h ('k') | talk/app/webrtc/webrtcsdp_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: talk/app/webrtc/test/androidtestinitializer.cc
diff --git a/talk/app/webrtc/java/jni/surfacetexturehelper_jni.cc b/talk/app/webrtc/test/androidtestinitializer.cc
similarity index 51%
copy from talk/app/webrtc/java/jni/surfacetexturehelper_jni.cc
copy to talk/app/webrtc/test/androidtestinitializer.cc
index 3e32b9a6fe29d89b5635bbd13e2c6dff7192a838..883c2d81782d80f4dedccdb04d4e5ac9ee48ad67 100644
--- a/talk/app/webrtc/java/jni/surfacetexturehelper_jni.cc
+++ b/talk/app/webrtc/test/androidtestinitializer.cc
@@ -23,46 +23,52 @@
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
*/
+#include "talk/app/webrtc/test/androidtestinitializer.h"
+
+#include <pthread.h>
-#include "talk/app/webrtc/java/jni/surfacetexturehelper_jni.h"
+// Note: this dependency is dangerous since it reaches into Chromium's base.
+// There's a risk of e.g. macro clashes. This file may only be used in tests.
+// Since we use Chromes build system for creating the gtest binary, this should
+// be fine.
+#include "base/android/context_utils.h"
+#include "base/android/jni_android.h"
#include "talk/app/webrtc/java/jni/classreferenceholder.h"
-#include "webrtc/base/bind.h"
+#include "talk/app/webrtc/java/jni/jni_helpers.h"
#include "webrtc/base/checks.h"
+#include "webrtc/base/ssladapter.h"
+#include "webrtc/voice_engine/include/voe_base.h"
-namespace webrtc_jni {
+namespace webrtc {
-SurfaceTextureHelper::SurfaceTextureHelper(
- JNIEnv* jni, jobject surface_texture_helper)
- : j_surface_texture_helper_(jni, surface_texture_helper),
- j_return_texture_method_(
- GetMethodID(jni,
- FindClass(jni, "org/webrtc/SurfaceTextureHelper"),
- "returnTextureFrame",
- "()V")) {
- CHECK_EXCEPTION(jni) << "error during initialization of SurfaceTextureHelper";
-}
+namespace {
-SurfaceTextureHelper::~SurfaceTextureHelper() {
-}
+static pthread_once_t g_initialize_once = PTHREAD_ONCE_INIT;
+
+// There can only be one JNI_OnLoad in each binary. So since this is a GTEST
+// C++ runner binary, we want to initialize the same global objects we normally
+// do if this had been a Java binary.
+void EnsureInitializedOnce() {
+ RTC_CHECK(::base::android::IsVMInitialized());
+ JNIEnv* jni = ::base::android::AttachCurrentThread();
+ JavaVM* jvm = NULL;
+ RTC_CHECK_EQ(0, jni->GetJavaVM(&jvm));
+ jobject context = ::base::android::GetApplicationContext();
-void SurfaceTextureHelper::ReturnTextureFrame() const {
- JNIEnv* jni = AttachCurrentThreadIfNeeded();
- jni->CallVoidMethod(*j_surface_texture_helper_, j_return_texture_method_);
+ RTC_CHECK_GE(webrtc_jni::InitGlobalJniVariables(jvm), 0);
+ RTC_CHECK(rtc::InitializeSSL()) << "Failed to InitializeSSL()";
+ webrtc_jni::LoadGlobalClassReferenceHolder();
- CHECK_EXCEPTION(
- jni) << "error during SurfaceTextureHelper.returnTextureFrame";
+ webrtc::VoiceEngine::SetAndroidObjects(jvm, context);
}
-rtc::scoped_refptr<webrtc::VideoFrameBuffer>
-SurfaceTextureHelper::CreateTextureFrame(int width, int height,
- const NativeHandleImpl& native_handle) {
- return new rtc::RefCountedObject<AndroidTextureBuffer>(
- width, height, native_handle, *j_surface_texture_helper_,
- rtc::Bind(&SurfaceTextureHelper::ReturnTextureFrame, this));
+} // anonymous namespace
+
+void InitializeAndroidObjects() {
+ RTC_CHECK_EQ(0, pthread_once(&g_initialize_once, &EnsureInitializedOnce));
}
-} // namespace webrtc_jni
+} // namespace webrtc
« no previous file with comments | « talk/app/webrtc/test/androidtestinitializer.h ('k') | talk/app/webrtc/webrtcsdp_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698