[*] 日常优化
This commit is contained in:
@@ -228,29 +228,6 @@ public class MainActivity extends AppCompatActivity {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* MainHandler
|
||||
* 后台线程和UI线程关联线程Handler
|
||||
*
|
||||
* @author acgist
|
||||
*/
|
||||
public class MainHandler extends Handler {
|
||||
|
||||
@Override
|
||||
public void handleMessage(@NonNull Message message) {
|
||||
super.handleMessage(message);
|
||||
Log.d(MainHandler.class.getSimpleName(), "MainHandler消息:" + message.what);
|
||||
switch (message.what) {
|
||||
case Config.WHAT_SCREEN_CAPTURE -> MainActivity.this.screenCapture(message);
|
||||
case Config.WHAT_RECORD -> MainActivity.this.record(message);
|
||||
case Config.WHAT_NEW_LOCAL_VIDEO,
|
||||
Config.WHAT_NEW_REMOTE_VIDEO -> MainActivity.this.previewVideo(message);
|
||||
case Config.WHAT_REMOVE_VIDEO -> MainActivity.this.removePreviewVideo(message);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 屏幕捕获
|
||||
*
|
||||
@@ -321,5 +298,28 @@ public class MainActivity extends AppCompatActivity {
|
||||
this.removeLayoutParams.add(surfaceView.getLayoutParams());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* MainHandler
|
||||
* 后台线程和UI线程关联线程Handler
|
||||
*
|
||||
* @author acgist
|
||||
*/
|
||||
public class MainHandler extends Handler {
|
||||
|
||||
@Override
|
||||
public void handleMessage(@NonNull Message message) {
|
||||
super.handleMessage(message);
|
||||
Log.d(MainHandler.class.getSimpleName(), "MainHandler消息:" + message.what);
|
||||
switch (message.what) {
|
||||
case Config.WHAT_SCREEN_CAPTURE -> MainActivity.this.screenCapture(message);
|
||||
case Config.WHAT_RECORD -> MainActivity.this.record(message);
|
||||
case Config.WHAT_NEW_LOCAL_VIDEO,
|
||||
Config.WHAT_NEW_REMOTE_VIDEO -> MainActivity.this.previewVideo(message);
|
||||
case Config.WHAT_REMOVE_VIDEO -> MainActivity.this.removePreviewVideo(message);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@ namespace acgist {
|
||||
|
||||
#include "android/log.h"
|
||||
|
||||
// TODO:优化INFO提示
|
||||
#ifndef LOG_TAG_TAOYAO
|
||||
#define LOG_TAG_TAOYAO "libtaoyao"
|
||||
#define LOG_D(format, ...) __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG_TAOYAO, "%s " format, __func__, ##__VA_ARGS__)
|
||||
|
||||
@@ -6,28 +6,133 @@
|
||||
#include "MediaManager.hpp"
|
||||
#include "mediasoupclient.hpp"
|
||||
|
||||
/**
|
||||
* 路由回调头文件
|
||||
*/
|
||||
namespace acgist {
|
||||
|
||||
/**
|
||||
* 路由回调
|
||||
*/
|
||||
class RouterCallback {
|
||||
public:
|
||||
/**
|
||||
* 回调对象
|
||||
*/
|
||||
jobject routerCallback;
|
||||
public:
|
||||
/**
|
||||
* @param routerCallback 回调对象
|
||||
*/
|
||||
RouterCallback(jobject routerCallback);
|
||||
/**
|
||||
* 析构函数
|
||||
*/
|
||||
virtual ~RouterCallback();
|
||||
public:
|
||||
/**
|
||||
* 进入房间回调
|
||||
*
|
||||
* @param env JNIEnv
|
||||
* @param rtpCapabilities RTP协商
|
||||
* @param sctpCapabilities SCTP协商
|
||||
*/
|
||||
void enterRoomCallback(JNIEnv* env, const std::string& rtpCapabilities, const std::string& sctpCapabilities);
|
||||
/**
|
||||
* 关闭房间回调
|
||||
*
|
||||
* @param env JNIEnv
|
||||
*/
|
||||
void closeRoomCallback(JNIEnv* env);
|
||||
/**
|
||||
* 发送通道连接回调
|
||||
*
|
||||
* @param env JNIEnv
|
||||
* @param transportId 通道ID
|
||||
* @param dtlsParameters DTLS参数
|
||||
*/
|
||||
void sendTransportConnectCallback(JNIEnv* env, const std::string& transportId, const std::string& dtlsParameters);
|
||||
/**
|
||||
* 接收通道连接回调
|
||||
*
|
||||
* @param env JNIEnv
|
||||
* @param transportId 通道ID
|
||||
* @param dtlsParameters DTLS参数
|
||||
*/
|
||||
void recvTransportConnectCallback(JNIEnv* env, const std::string& transportId, const std::string& dtlsParameters);
|
||||
/**
|
||||
* 发送通道生产回调
|
||||
*
|
||||
* @param env JNIEnv
|
||||
* @param kind 类型
|
||||
* @param transportId 通道ID
|
||||
* @param rtpParameters RTP参数
|
||||
*
|
||||
* @return 生产者ID
|
||||
*/
|
||||
std::string sendTransportProduceCallback(JNIEnv* env, const std::string& kind, const std::string& transportId, const std::string& rtpParameters);
|
||||
/**
|
||||
* 新建生产者回调
|
||||
*
|
||||
* @param env JNIEnv
|
||||
* @param kind 生产者类型
|
||||
* @param producerId 生产者ID
|
||||
* @param producerPointer 生产者指针
|
||||
* @param producerMediaTrackPointer 媒体Tracker指针
|
||||
*/
|
||||
void producerNewCallback(JNIEnv* env, const std::string& kind, const std::string& producerId, mediasoupclient::Producer* producerPointer, webrtc::MediaStreamTrackInterface* producerMediaTrackPointer);
|
||||
/**
|
||||
* 关闭生产者回调
|
||||
*
|
||||
* @param env JNIEnv
|
||||
* @param producerId 生产者ID
|
||||
*/
|
||||
void producerCloseCallback(JNIEnv* env, const std::string& producerId);
|
||||
/**
|
||||
* 暂停生产者回调
|
||||
*
|
||||
* @param env JNIEnv
|
||||
* @param producerId 生产者ID
|
||||
*/
|
||||
void producerPauseCallback(JNIEnv* env, const std::string& producerId);
|
||||
/**
|
||||
* 恢复生产者回调
|
||||
*
|
||||
* @param env JNIEnv
|
||||
* @param producerId 生产者ID
|
||||
*/
|
||||
void producerResumeCallback(JNIEnv* env, const std::string& producerId);
|
||||
/**
|
||||
* 新建消费者回调
|
||||
*
|
||||
* @param env JNIEnv
|
||||
* @param message 信令消息
|
||||
* @param consumerPointer 消费者指针
|
||||
* @param consumerMediaTrackPointer 媒体Tracker指针
|
||||
*/
|
||||
void consumerNewCallback(JNIEnv* env, const std::string& message, mediasoupclient::Consumer* consumerPointer, webrtc::MediaStreamTrackInterface* consumerMediaTrackPointer);
|
||||
/**
|
||||
* 关闭消费者回调
|
||||
*
|
||||
* @param env JNIEnv
|
||||
* @param consumerId 消费者ID
|
||||
*/
|
||||
void consumerCloseCallback(JNIEnv* env, const std::string& consumerId);
|
||||
/**
|
||||
* 暂停消费者回调
|
||||
*
|
||||
* @param env JNIEnv
|
||||
* @param consumerId 消费者ID
|
||||
*/
|
||||
void consumerPauseCallback(JNIEnv* env, const std::string& consumerId);
|
||||
/**
|
||||
* 恢复消费者回调
|
||||
*
|
||||
* @param env JNIEnv
|
||||
* @param consumerId 消费者ID
|
||||
*/
|
||||
void consumerResumeCallback(JNIEnv* env, const std::string& consumerId);
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
@@ -8,19 +8,30 @@ namespace acgist {
|
||||
JavaVMAttachArgs args;
|
||||
args.name = name;
|
||||
args.version = JNI_VERSION_1_6;
|
||||
if(taoyaoJavaVM == nullptr) {
|
||||
LOG_W("绑定线程失败:JavaVM为空");
|
||||
return;
|
||||
}
|
||||
taoyaoJavaVM->AttachCurrentThreadAsDaemon(env, &args);
|
||||
}
|
||||
|
||||
void unbindJavaThread() {
|
||||
if(taoyaoJavaVM == nullptr) {
|
||||
LOG_W("解绑线程失败:JavaVM为空");
|
||||
return;
|
||||
}
|
||||
taoyaoJavaVM->DetachCurrentThread();
|
||||
}
|
||||
|
||||
/**
|
||||
* 非常重要
|
||||
* 加载库文件时加载WebRTC,JNI自动调用。
|
||||
*/
|
||||
extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* javaVM, void* reserved) {
|
||||
extern "C" JNIEXPORT jint JNICALL
|
||||
JNI_OnLoad(JavaVM* javaVM, void* reserved) {
|
||||
LOG_I("加载WebRTC");
|
||||
taoyaoJavaVM = javaVM;
|
||||
// JNIEnv* env = webrtc::jni::GetEnv();
|
||||
// JNIEnv* env = webrtc::jni::GetEnv();
|
||||
// 下面非常重要
|
||||
webrtc::jni::InitGlobalJniVariables(javaVM);
|
||||
return JNI_VERSION_1_6;
|
||||
}
|
||||
@@ -28,7 +39,7 @@ namespace acgist {
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_acgist_taoyao_media_MediaManager_nativeInit(JNIEnv* env, jobject me) {
|
||||
std::string version = mediasoupclient::Version();
|
||||
LOG_I("加载MediasoupClient", version.data());
|
||||
LOG_I("加载MediasoupClient %s", version.data());
|
||||
mediasoupclient::Initialize();
|
||||
// => { spatialLayers: 2, temporalLayers: 3 }
|
||||
// mediasoupclient::parseScalabilityMode("L2T3");
|
||||
|
||||
@@ -967,7 +967,14 @@ public final class MediaManager {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载MediasoupClient
|
||||
*/
|
||||
private native void nativeInit();
|
||||
|
||||
/**
|
||||
* 关闭MediasoupClient
|
||||
*/
|
||||
private native void nativeStop();
|
||||
|
||||
}
|
||||
|
||||
@@ -7,18 +7,105 @@ package com.acgist.taoyao.media;
|
||||
*/
|
||||
public interface RouterCallback {
|
||||
|
||||
/**
|
||||
* 进入房间回调
|
||||
*
|
||||
* @param rtpCapabilities RTP协商
|
||||
* @param sctpCapabilities SCTP协商
|
||||
*/
|
||||
default void enterRoomCallback(String rtpCapabilities, String sctpCapabilities) {};
|
||||
|
||||
/**
|
||||
* 关闭房间回调
|
||||
*/
|
||||
default void closeRoomCallback() {};
|
||||
|
||||
/**
|
||||
* 发送通道连接回调
|
||||
*
|
||||
* @param transportId 通告ID
|
||||
* @param dtlsParameters DTLS参数
|
||||
*/
|
||||
default void sendTransportConnectCallback(String transportId, String dtlsParameters) {};
|
||||
|
||||
/**
|
||||
* 接收通道连接回调
|
||||
*
|
||||
* @param transportId 通道ID
|
||||
* @param dtlsParameters DTLS参数
|
||||
*/
|
||||
default void recvTransportConnectCallback(String transportId, String dtlsParameters) {};
|
||||
|
||||
/**
|
||||
* 发送通道生产回调
|
||||
*
|
||||
* @param kind 类型
|
||||
* @param transportId 通道ID
|
||||
* @param rtpParameters RTP参数
|
||||
*
|
||||
* @return 生产者ID
|
||||
*/
|
||||
default String sendTransportProduceCallback(String kind, String transportId, String rtpParameters) { return null; };
|
||||
|
||||
/**
|
||||
* 新建生产者回调
|
||||
*
|
||||
* @param kind 生产者类型
|
||||
* @param producerId 生产者ID
|
||||
* @param producerPointer 生产者指针
|
||||
* @param producerMediaTrackPointer 媒体Tracker指针
|
||||
*/
|
||||
default void producerNewCallback(String kind, String producerId, long producerPointer, long producerMediaTrackPointer) {};
|
||||
|
||||
/**
|
||||
* 关闭生产者回调
|
||||
*
|
||||
* @param producerId 生产者ID
|
||||
*/
|
||||
default void producerCloseCallback(String producerId) {};
|
||||
|
||||
/**
|
||||
* 暂停生产者回调
|
||||
*
|
||||
* @param producerId 生产者ID
|
||||
*/
|
||||
default void producerPauseCallback(String producerId) {};
|
||||
|
||||
/**
|
||||
* 恢复生产者回调
|
||||
*
|
||||
* @param producerId 生产者ID
|
||||
*/
|
||||
default void producerResumeCallback(String producerId) {};
|
||||
|
||||
/**
|
||||
* 新建消费者回调
|
||||
*
|
||||
* @param message 信令消息
|
||||
* @param consumerPointer 消费者指针
|
||||
* @param consumerMediaTrackPointer 媒体Tracker指针
|
||||
*/
|
||||
default void consumerNewCallback(String message, long consumerPointer, long consumerMediaTrackPointer) {};
|
||||
|
||||
/**
|
||||
* 关闭消费者回调
|
||||
*
|
||||
* @param consumerId 消费者ID
|
||||
*/
|
||||
default void consumerCloseCallback(String consumerId) {};
|
||||
|
||||
/**
|
||||
* 暂停消费者回调
|
||||
*
|
||||
* @param consumerId 消费者ID
|
||||
*/
|
||||
default void consumerPauseCallback(String consumerId) {};
|
||||
|
||||
/**
|
||||
* 恢复消费者回调
|
||||
*
|
||||
* @param consumerId 消费者ID
|
||||
*/
|
||||
default void consumerResumeCallback(String consumerId) {};
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user