[*] 日常优化
This commit is contained in:
@@ -1,19 +1,19 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 日志头文件
|
||||||
|
*/
|
||||||
namespace acgist {
|
namespace acgist {
|
||||||
|
|
||||||
#include "android/log.h"
|
#include "android/log.h"
|
||||||
|
|
||||||
#define LOG_TAG "libtaoyao"
|
// TODO:优化INFO提示
|
||||||
|
#ifndef LOG_TAG_TAOYAO
|
||||||
#define LOG_D(format, ...) __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, "%s " format, __func__, ##__VA_ARGS__)
|
#define LOG_TAG_TAOYAO "libtaoyao"
|
||||||
#define LOG_I(format, ...) __android_log_print(ANDROID_LOG_INFO, LOG_TAG, "%s " format, __func__, ##__VA_ARGS__)
|
#define LOG_D(format, ...) __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG_TAOYAO, "%s " format, __func__, ##__VA_ARGS__)
|
||||||
#define LOG_W(format, ...) __android_log_print(ANDROID_LOG_WARN, LOG_TAG, "%s " format, __func__, ##__VA_ARGS__)
|
#define LOG_I(format, ...) __android_log_print(ANDROID_LOG_INFO, LOG_TAG_TAOYAO, "%s " format, __func__, ##__VA_ARGS__)
|
||||||
#define LOG_E(format, ...) __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, "%s " format, __func__, ##__VA_ARGS__)
|
#define LOG_W(format, ...) __android_log_print(ANDROID_LOG_WARN, LOG_TAG_TAOYAO, "%s " format, __func__, ##__VA_ARGS__)
|
||||||
|
#define LOG_E(format, ...) __android_log_print(ANDROID_LOG_ERROR, LOG_TAG_TAOYAO, "%s " format, __func__, ##__VA_ARGS__)
|
||||||
//#define LOG_D(...) acgist::__android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__)
|
#endif
|
||||||
//#define LOG_I(...) acgist::__android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__)
|
|
||||||
//#define LOG_W(...) acgist::__android_log_print(ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__)
|
|
||||||
//#define LOG_E(...) acgist::__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,15 +6,25 @@
|
|||||||
|
|
||||||
#include "sdk/android/src/jni/jvm.h"
|
#include "sdk/android/src/jni/jvm.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 媒体管理器头文件
|
||||||
|
*/
|
||||||
namespace acgist {
|
namespace acgist {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 全局JavaVM指针
|
* 全局JavaVM指针
|
||||||
*/
|
*/
|
||||||
extern JavaVM* taoyaoJavaVM;
|
extern JavaVM* taoyaoJavaVM;
|
||||||
|
/**
|
||||||
|
* 绑定Java线程
|
||||||
|
*
|
||||||
|
* @param env JNIEnv
|
||||||
|
* @param name Java线程名称
|
||||||
|
*/
|
||||||
extern void bindJavaThread(JNIEnv** env, const char* name = "C++Thread");
|
extern void bindJavaThread(JNIEnv** env, const char* name = "C++Thread");
|
||||||
|
/**
|
||||||
|
* 解绑Java线程
|
||||||
|
*/
|
||||||
extern void unbindJavaThread();
|
extern void unbindJavaThread();
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -10,39 +10,170 @@
|
|||||||
#include "Log.hpp"
|
#include "Log.hpp"
|
||||||
#include "RouterCallback.hpp"
|
#include "RouterCallback.hpp"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 视频房间头文件
|
||||||
|
*/
|
||||||
namespace acgist {
|
namespace acgist {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 视频房间
|
||||||
|
*/
|
||||||
class Room : public RouterCallback {
|
class Room : public RouterCallback {
|
||||||
public:
|
public:
|
||||||
|
/**
|
||||||
|
* 房间ID
|
||||||
|
*/
|
||||||
std::string roomId;
|
std::string roomId;
|
||||||
|
/**
|
||||||
|
* 全局共用PeerConnectionFactory
|
||||||
|
*/
|
||||||
webrtc::PeerConnectionFactoryInterface* factory;
|
webrtc::PeerConnectionFactoryInterface* factory;
|
||||||
|
/**
|
||||||
|
* 全局共用RTCConfiguration
|
||||||
|
*/
|
||||||
webrtc::PeerConnectionInterface::RTCConfiguration* rtcConfiguration;
|
webrtc::PeerConnectionInterface::RTCConfiguration* rtcConfiguration;
|
||||||
|
/**
|
||||||
|
* 房间Device
|
||||||
|
*/
|
||||||
mediasoupclient::Device* device;
|
mediasoupclient::Device* device;
|
||||||
|
/**
|
||||||
|
* 发送通道
|
||||||
|
*/
|
||||||
mediasoupclient::SendTransport* sendTransport;
|
mediasoupclient::SendTransport* sendTransport;
|
||||||
|
/**
|
||||||
|
* 接收通道
|
||||||
|
*/
|
||||||
mediasoupclient::RecvTransport* recvTransport;
|
mediasoupclient::RecvTransport* recvTransport;
|
||||||
|
/**
|
||||||
|
* 发送监听器
|
||||||
|
*/
|
||||||
mediasoupclient::SendTransport::Listener* sendListener;
|
mediasoupclient::SendTransport::Listener* sendListener;
|
||||||
|
/**
|
||||||
|
* 接收监听器
|
||||||
|
*/
|
||||||
mediasoupclient::RecvTransport::Listener* recvListener;
|
mediasoupclient::RecvTransport::Listener* recvListener;
|
||||||
|
/**
|
||||||
|
* 音频生产者
|
||||||
|
*/
|
||||||
mediasoupclient::Producer* audioProducer;
|
mediasoupclient::Producer* audioProducer;
|
||||||
|
/**
|
||||||
|
* 视频生产者
|
||||||
|
*/
|
||||||
mediasoupclient::Producer* videoProducer;
|
mediasoupclient::Producer* videoProducer;
|
||||||
|
/**
|
||||||
|
* 生产者监听器
|
||||||
|
*/
|
||||||
mediasoupclient::Producer::Listener* producerListener;
|
mediasoupclient::Producer::Listener* producerListener;
|
||||||
|
/**
|
||||||
|
* 消费者监听器
|
||||||
|
*/
|
||||||
mediasoupclient::Consumer::Listener* consumerListener;
|
mediasoupclient::Consumer::Listener* consumerListener;
|
||||||
|
/**
|
||||||
|
* 消费者列表
|
||||||
|
*/
|
||||||
std::map<std::string, mediasoupclient::Consumer*> consumers;
|
std::map<std::string, mediasoupclient::Consumer*> consumers;
|
||||||
public:
|
public:
|
||||||
|
/**
|
||||||
|
* @param roomId 房间ID
|
||||||
|
* @param routerCallback 房间路由回调
|
||||||
|
*/
|
||||||
Room(const std::string& roomId, const jobject& routerCallback);
|
Room(const std::string& roomId, const jobject& routerCallback);
|
||||||
|
/**
|
||||||
|
* 析构函数
|
||||||
|
*/
|
||||||
virtual ~Room();
|
virtual ~Room();
|
||||||
public:
|
public:
|
||||||
|
/**
|
||||||
|
* 进入房间
|
||||||
|
*
|
||||||
|
* @param env JNIEnv
|
||||||
|
* @param rtpCapabilities RTP协商
|
||||||
|
* @param factory PeerConnectionFactory
|
||||||
|
* @param rtcConfiguration RTCConfiguration
|
||||||
|
*/
|
||||||
void enterRoom(JNIEnv* env, const std::string& rtpCapabilities, webrtc::PeerConnectionFactoryInterface* factory, webrtc::PeerConnectionInterface::RTCConfiguration& rtcConfiguration);
|
void enterRoom(JNIEnv* env, const std::string& rtpCapabilities, webrtc::PeerConnectionFactoryInterface* factory, webrtc::PeerConnectionInterface::RTCConfiguration& rtcConfiguration);
|
||||||
|
/**
|
||||||
|
* 创建发送通道
|
||||||
|
*
|
||||||
|
* @param env JNIEnv
|
||||||
|
* @param body 信令主体
|
||||||
|
*/
|
||||||
void createSendTransport(JNIEnv* env, const std::string& body);
|
void createSendTransport(JNIEnv* env, const std::string& body);
|
||||||
|
/**
|
||||||
|
* 创建接收通道
|
||||||
|
*
|
||||||
|
* @param env JNIEnv
|
||||||
|
* @param body 信令主体
|
||||||
|
*/
|
||||||
void createRecvTransport(JNIEnv* env, const std::string& body);
|
void createRecvTransport(JNIEnv* env, const std::string& body);
|
||||||
|
/**
|
||||||
|
* 生成音频
|
||||||
|
*
|
||||||
|
* @param env JNIEnv
|
||||||
|
* @param mediaStream 媒体流
|
||||||
|
*/
|
||||||
void mediaProduceAudio(JNIEnv* env, webrtc::MediaStreamInterface* mediaStream);
|
void mediaProduceAudio(JNIEnv* env, webrtc::MediaStreamInterface* mediaStream);
|
||||||
|
/**
|
||||||
|
* 生成视频
|
||||||
|
*
|
||||||
|
* @param env JNIEnv
|
||||||
|
* @param mediaStream 媒体流
|
||||||
|
*/
|
||||||
void mediaProduceVideo(JNIEnv* env, webrtc::MediaStreamInterface* mediaStream);
|
void mediaProduceVideo(JNIEnv* env, webrtc::MediaStreamInterface* mediaStream);
|
||||||
|
/**
|
||||||
|
* 消费媒体
|
||||||
|
*
|
||||||
|
* @param env JNIEnv
|
||||||
|
* @param message 信令消息
|
||||||
|
*/
|
||||||
void mediaConsume(JNIEnv* env, const std::string& message);
|
void mediaConsume(JNIEnv* env, const std::string& message);
|
||||||
|
/**
|
||||||
|
* 暂停生产者
|
||||||
|
*
|
||||||
|
* @param env JNIEnv
|
||||||
|
* @param producerId 生产者ID
|
||||||
|
*/
|
||||||
void mediaProducerPause(JNIEnv* env, const std::string& producerId);
|
void mediaProducerPause(JNIEnv* env, const std::string& producerId);
|
||||||
|
/**
|
||||||
|
* 恢复生产者
|
||||||
|
*
|
||||||
|
* @param env JNIEnv
|
||||||
|
* @param producerId 生产者ID
|
||||||
|
*/
|
||||||
void mediaProducerResume(JNIEnv* env, const std::string& producerId);
|
void mediaProducerResume(JNIEnv* env, const std::string& producerId);
|
||||||
|
/**
|
||||||
|
* 关闭生产者
|
||||||
|
*
|
||||||
|
* @param env JNIEnv
|
||||||
|
* @param producerId 生产者ID
|
||||||
|
*/
|
||||||
void mediaProducerClose(JNIEnv* env, const std::string& producerId);
|
void mediaProducerClose(JNIEnv* env, const std::string& producerId);
|
||||||
|
/**
|
||||||
|
* 暂停消费者
|
||||||
|
*
|
||||||
|
* @param env JNIEnv
|
||||||
|
* @param consumerId 消费者ID
|
||||||
|
*/
|
||||||
void mediaConsumerPause(JNIEnv* env, const std::string& consumerId);
|
void mediaConsumerPause(JNIEnv* env, const std::string& consumerId);
|
||||||
|
/**
|
||||||
|
* 恢复消费者
|
||||||
|
*
|
||||||
|
* @param env JNIEnv
|
||||||
|
* @param consumerId 消费者ID
|
||||||
|
*/
|
||||||
void mediaConsumerResume(JNIEnv* env, const std::string& consumerId);
|
void mediaConsumerResume(JNIEnv* env, const std::string& consumerId);
|
||||||
|
/**
|
||||||
|
* 关闭消费者
|
||||||
|
*
|
||||||
|
* @param env JNIEnv
|
||||||
|
* @param consumerId 消费者ID
|
||||||
|
*/
|
||||||
void mediaConsumerClose(JNIEnv* env, const std::string& consumerId);
|
void mediaConsumerClose(JNIEnv* env, const std::string& consumerId);
|
||||||
|
/**
|
||||||
|
* 关闭房间
|
||||||
|
*
|
||||||
|
* @param env JNIEnv
|
||||||
|
*/
|
||||||
void closeRoom(JNIEnv* env);
|
void closeRoom(JNIEnv* env);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -403,8 +403,9 @@ public final class MediaManager {
|
|||||||
// });
|
// });
|
||||||
final JavaAudioDeviceModule javaAudioDeviceModule = JavaAudioDeviceModule.builder(this.context)
|
final JavaAudioDeviceModule javaAudioDeviceModule = JavaAudioDeviceModule.builder(this.context)
|
||||||
// .setSampleRate(48000)
|
// .setSampleRate(48000)
|
||||||
// .setAudioSource(MediaRecorder.AudioSource.MIC)
|
// .setSampleRate(mediaAudioProperties.getSampleRate())
|
||||||
// .setAudioFormat(AudioFormat.ENCODING_PCM_16BIT)
|
// .setAudioFormat(AudioFormat.ENCODING_PCM_16BIT)
|
||||||
|
// .setAudioSource(MediaRecorder.AudioSource.MIC)
|
||||||
// .setAudioAttributes(audioAttributes)
|
// .setAudioAttributes(audioAttributes)
|
||||||
// 超低延迟
|
// 超低延迟
|
||||||
// .setUseLowLatency()
|
// .setUseLowLatency()
|
||||||
|
|||||||
@@ -332,17 +332,27 @@ class Session {
|
|||||||
this.localVideoEnabled = false;
|
this.localVideoEnabled = false;
|
||||||
this.remoteAudioEnabled = false;
|
this.remoteAudioEnabled = false;
|
||||||
this.remoteVideoEnabled = false;
|
this.remoteVideoEnabled = false;
|
||||||
|
if(this.localAudioTrack) {
|
||||||
this.localAudioTrack.stop();
|
this.localAudioTrack.stop();
|
||||||
this.localAudioTrack = null;
|
this.localAudioTrack = null;
|
||||||
|
}
|
||||||
|
if(this.localVideoTrack) {
|
||||||
this.localVideoTrack.stop();
|
this.localVideoTrack.stop();
|
||||||
this.localVideoTrack = null;
|
this.localVideoTrack = null;
|
||||||
|
}
|
||||||
|
if(this.remoteAudioTrack) {
|
||||||
this.remoteAudioTrack.stop();
|
this.remoteAudioTrack.stop();
|
||||||
this.remoteAudioTrack = null;
|
this.remoteAudioTrack = null;
|
||||||
|
}
|
||||||
|
if(this.remoteVideoTrack) {
|
||||||
this.remoteVideoTrack.stop();
|
this.remoteVideoTrack.stop();
|
||||||
this.remoteVideoTrack = null;
|
this.remoteVideoTrack = null;
|
||||||
|
}
|
||||||
|
if(this.peerConnection) {
|
||||||
this.peerConnection.close();
|
this.peerConnection.close();
|
||||||
this.peerConnection = null;
|
this.peerConnection = null;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async addIceCandidate(candidate) {
|
async addIceCandidate(candidate) {
|
||||||
if(this.closed) {
|
if(this.closed) {
|
||||||
@@ -769,7 +779,6 @@ class Taoyao extends RemoteClient {
|
|||||||
// const stream = await this._getExternalVideoStream();
|
// const stream = await this._getExternalVideoStream();
|
||||||
// track = stream.getVideoTracks()[0].clone();
|
// track = stream.getVideoTracks()[0].clone();
|
||||||
} else if (self.videoSource === "camera") {
|
} else if (self.videoSource === "camera") {
|
||||||
console.debug("enableWebcam() | calling getUserMedia()");
|
|
||||||
// TODO:参数
|
// TODO:参数
|
||||||
stream = await navigator.mediaDevices.getUserMedia({
|
stream = await navigator.mediaDevices.getUserMedia({
|
||||||
audio: self.audioConfig,
|
audio: self.audioConfig,
|
||||||
@@ -846,6 +855,8 @@ class Taoyao extends RemoteClient {
|
|||||||
ideal: audio.sampleSize,
|
ideal: audio.sampleSize,
|
||||||
max: media.maxSampleSize,
|
max: media.maxSampleSize,
|
||||||
};
|
};
|
||||||
|
// 强制修改
|
||||||
|
// me.audioConfig.sampleRate = 8000;
|
||||||
me.audioConfig.sampleRate = {
|
me.audioConfig.sampleRate = {
|
||||||
min: media.minSampleRate,
|
min: media.minSampleRate,
|
||||||
ideal: audio.sampleRate,
|
ideal: audio.sampleRate,
|
||||||
|
|||||||
Reference in New Issue
Block a user