xref: /aosp_15_r20/external/webrtc/rtc_tools/network_tester/jni.cc (revision d9f758449e529ab9291ac668be2861e7a55c2422)
1 /*
2  *  Copyright 2017 The WebRTC project authors. All Rights Reserved.
3  *
4  *  Use of this source code is governed by a BSD-style license
5  *  that can be found in the LICENSE file in the root of the source
6  *  tree. An additional intellectual property rights grant can be found
7  *  in the file PATENTS.  All contributing project authors may
8  *  be found in the AUTHORS file in the root of the source tree.
9  */
10 
11 #include <jni.h>
12 #undef JNIEXPORT
13 #define JNIEXPORT __attribute__((visibility("default")))
14 #include <string>
15 
16 #include "rtc_base/logging.h"
17 #include "rtc_base/thread.h"
18 #include "rtc_tools/network_tester/test_controller.h"
19 
20 extern "C" JNIEXPORT jlong JNICALL
Java_com_google_media_networktester_NetworkTester_CreateTestController(JNIEnv * jni,jclass)21 Java_com_google_media_networktester_NetworkTester_CreateTestController(
22     JNIEnv* jni,
23     jclass) {
24   rtc::ThreadManager::Instance()->WrapCurrentThread();
25   return reinterpret_cast<intptr_t>(new webrtc::TestController(
26       0, 0, "/mnt/sdcard/network_tester_client_config.dat",
27       "/mnt/sdcard/network_tester_client_packet_log.dat"));
28 }
29 
30 extern "C" JNIEXPORT void JNICALL
Java_com_google_media_networktester_NetworkTester_TestControllerConnect(JNIEnv * jni,jclass,jlong native_pointer)31 Java_com_google_media_networktester_NetworkTester_TestControllerConnect(
32     JNIEnv* jni,
33     jclass,
34     jlong native_pointer) {
35   reinterpret_cast<webrtc::TestController*>(native_pointer)
36       ->SendConnectTo("85.195.237.107", 9090);
37 }
38 
39 extern "C" JNIEXPORT bool JNICALL
Java_com_google_media_networktester_NetworkTester_TestControllerIsDone(JNIEnv * jni,jclass,jlong native_pointer)40 Java_com_google_media_networktester_NetworkTester_TestControllerIsDone(
41     JNIEnv* jni,
42     jclass,
43     jlong native_pointer) {
44   return reinterpret_cast<webrtc::TestController*>(native_pointer)
45       ->IsTestDone();
46 }
47 
48 extern "C" JNIEXPORT void JNICALL
Java_com_google_media_networktester_NetworkTester_TestControllerRun(JNIEnv * jni,jclass,jlong native_pointer)49 Java_com_google_media_networktester_NetworkTester_TestControllerRun(
50     JNIEnv* jni,
51     jclass,
52     jlong native_pointer) {
53   // 100 ms arbitrary chosen, but it works well.
54   rtc::Thread::Current()->ProcessMessages(/*cms=*/100);
55 }
56 
57 extern "C" JNIEXPORT void JNICALL
Java_com_google_media_networktester_NetworkTester_DestroyTestController(JNIEnv * jni,jclass,jlong native_pointer)58 Java_com_google_media_networktester_NetworkTester_DestroyTestController(
59     JNIEnv* jni,
60     jclass,
61     jlong native_pointer) {
62   webrtc::TestController* test_controller =
63       reinterpret_cast<webrtc::TestController*>(native_pointer);
64   if (test_controller) {
65     delete test_controller;
66   }
67   rtc::ThreadManager::Instance()->UnwrapCurrentThread();
68 }
69