[*] 每日优化
This commit is contained in:
@@ -280,6 +280,7 @@ public class MediaService extends Service {
|
|||||||
final AudioManager audioManager = this.getApplicationContext().getSystemService(AudioManager.class);
|
final AudioManager audioManager = this.getApplicationContext().getSystemService(AudioManager.class);
|
||||||
Log.d(MediaService.class.getSimpleName(), "当前音频模式:" + audioManager.getMode());
|
Log.d(MediaService.class.getSimpleName(), "当前音频模式:" + audioManager.getMode());
|
||||||
Log.d(MediaService.class.getSimpleName(), "当前音频音量:" + audioManager.getStreamVolume(audioManager.getMode()));
|
Log.d(MediaService.class.getSimpleName(), "当前音频音量:" + audioManager.getStreamVolume(audioManager.getMode()));
|
||||||
|
Log.d(MediaService.class.getSimpleName(), "当前最大音频音量:" + audioManager.getStreamMaxVolume(audioManager.getMode()));
|
||||||
// Log.d(MediaService.class.getSimpleName(), "当前蓝牙是否打开:" + audioManager.isBluetoothScoOn());
|
// Log.d(MediaService.class.getSimpleName(), "当前蓝牙是否打开:" + audioManager.isBluetoothScoOn());
|
||||||
// Log.d(MediaService.class.getSimpleName(), "当前耳机是否打开:" + audioManager.isWiredHeadsetOn());
|
// Log.d(MediaService.class.getSimpleName(), "当前耳机是否打开:" + audioManager.isWiredHeadsetOn());
|
||||||
// Log.d(MediaService.class.getSimpleName(), "当前电话扬声器是否打开:" + audioManager.isSpeakerphoneOn());
|
// Log.d(MediaService.class.getSimpleName(), "当前电话扬声器是否打开:" + audioManager.isSpeakerphoneOn());
|
||||||
|
|||||||
@@ -1224,7 +1224,7 @@ public final class Taoyao implements ITaoyao {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final String type = MapUtils.get(body, "type");
|
final String type = MapUtils.get(body, "type");
|
||||||
sessionClient.pause(type);
|
sessionClient.pauseLocal(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1241,7 +1241,7 @@ public final class Taoyao implements ITaoyao {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final String type = MapUtils.get(body, "type");
|
final String type = MapUtils.get(body, "type");
|
||||||
sessionClient.resume(type);
|
sessionClient.resumeLocal(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import java.util.concurrent.ConcurrentHashMap;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 房间远程终端
|
* 房间远程终端
|
||||||
|
*
|
||||||
* 注意:这里媒体MediaStreamTrack使用Mediasoup方法释放不要直接调用MediaStreamTrack.dispose()释放
|
* 注意:这里媒体MediaStreamTrack使用Mediasoup方法释放不要直接调用MediaStreamTrack.dispose()释放
|
||||||
*
|
*
|
||||||
* @author acgist
|
* @author acgist
|
||||||
@@ -24,12 +25,25 @@ public class RemoteClient extends RoomClient {
|
|||||||
/**
|
/**
|
||||||
* 媒体流Track
|
* 媒体流Track
|
||||||
* 消费者ID = 媒体流Track
|
* 消费者ID = 媒体流Track
|
||||||
|
*
|
||||||
* 注意:track由mediasoup的consumer释放
|
* 注意:track由mediasoup的consumer释放
|
||||||
*/
|
*/
|
||||||
protected final Map<String, MediaStreamTrack> tracks;
|
protected final Map<String, MediaStreamTrack> tracks;
|
||||||
|
/**
|
||||||
|
* 音频消费者指针
|
||||||
|
*/
|
||||||
protected long audioConsumerPointer;
|
protected long audioConsumerPointer;
|
||||||
|
/**
|
||||||
|
* 视频消费指针
|
||||||
|
*/
|
||||||
protected long videoConsumerPointer;
|
protected long videoConsumerPointer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param name 终端名称
|
||||||
|
* @param clientId 终端ID
|
||||||
|
* @param taoyao 信令
|
||||||
|
* @param mainHandler MainHandler
|
||||||
|
*/
|
||||||
public RemoteClient(String name, String clientId, ITaoyao taoyao, Handler mainHandler) {
|
public RemoteClient(String name, String clientId, ITaoyao taoyao, Handler mainHandler) {
|
||||||
super(name, clientId, taoyao, mainHandler);
|
super(name, clientId, taoyao, mainHandler);
|
||||||
this.tracks = new ConcurrentHashMap<>();
|
this.tracks = new ConcurrentHashMap<>();
|
||||||
@@ -120,12 +134,14 @@ public class RemoteClient extends RoomClient {
|
|||||||
* 关闭消费者
|
* 关闭消费者
|
||||||
*
|
*
|
||||||
* @param consumerId 消费者ID
|
* @param consumerId 消费者ID
|
||||||
|
*
|
||||||
|
* @return MediaStreamTrack
|
||||||
*/
|
*/
|
||||||
public void close(String consumerId) {
|
public MediaStreamTrack close(String consumerId) {
|
||||||
Log.i(RemoteClient.class.getSimpleName(), "关闭远程终端消费者:" + this.clientId + " - " + consumerId);
|
Log.i(RemoteClient.class.getSimpleName(), "关闭远程终端消费者:" + this.clientId + " - " + consumerId);
|
||||||
synchronized (this.tracks) {
|
synchronized (this.tracks) {
|
||||||
// 注意:使用nativeMediaConsumerClose释放资源
|
// 注意:使用nativeMediaConsumerClose释放资源
|
||||||
this.tracks.remove(consumerId);
|
return this.tracks.remove(consumerId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ import org.webrtc.PeerConnection;
|
|||||||
import org.webrtc.PeerConnectionFactory;
|
import org.webrtc.PeerConnectionFactory;
|
||||||
import org.webrtc.SdpObserver;
|
import org.webrtc.SdpObserver;
|
||||||
import org.webrtc.SessionDescription;
|
import org.webrtc.SessionDescription;
|
||||||
|
import org.webrtc.SurfaceViewRenderer;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -54,6 +55,7 @@ public class SessionClient extends Client {
|
|||||||
private final boolean videoProduce;
|
private final boolean videoProduce;
|
||||||
private final MediaProperties mediaProperties;
|
private final MediaProperties mediaProperties;
|
||||||
private final WebrtcProperties webrtcProperties;
|
private final WebrtcProperties webrtcProperties;
|
||||||
|
private SurfaceViewRenderer localSurfaceViewRenderer;
|
||||||
/**
|
/**
|
||||||
* 本地媒体
|
* 本地媒体
|
||||||
*/
|
*/
|
||||||
@@ -136,7 +138,7 @@ public class SessionClient extends Client {
|
|||||||
this.peerConnection = this.peerConnectionFactory.createPeerConnection(configuration, this.observer);
|
this.peerConnection = this.peerConnectionFactory.createPeerConnection(configuration, this.observer);
|
||||||
this.peerConnection.addStream(this.mediaStream);
|
this.peerConnection.addStream(this.mediaStream);
|
||||||
if(this.preview) {
|
if(this.preview) {
|
||||||
// 实现预览
|
this.previewLocal();
|
||||||
}
|
}
|
||||||
// 设置streamId同步
|
// 设置streamId同步
|
||||||
// final List<String> streamIds = new ArrayList<>();
|
// final List<String> streamIds = new ArrayList<>();
|
||||||
@@ -243,7 +245,6 @@ public class SessionClient extends Client {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.remoteMediaStream.audioTracks.forEach(audioTrack -> {
|
this.remoteMediaStream.audioTracks.forEach(audioTrack -> {
|
||||||
audioTrack.setVolume(0);
|
|
||||||
audioTrack.setEnabled(false);
|
audioTrack.setEnabled(false);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -255,7 +256,6 @@ public class SessionClient extends Client {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.remoteMediaStream.audioTracks.forEach(audioTrack -> {
|
this.remoteMediaStream.audioTracks.forEach(audioTrack -> {
|
||||||
audioTrack.setVolume(Config.DEFAULT_VOLUME);
|
|
||||||
audioTrack.setEnabled(true);
|
audioTrack.setEnabled(true);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -280,10 +280,6 @@ public class SessionClient extends Client {
|
|||||||
if(this.remoteMediaStream == null) {
|
if(this.remoteMediaStream == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(this.surfaceViewRenderer != null) {
|
|
||||||
// TODO:测试
|
|
||||||
this.surfaceViewRenderer.pauseVideo();
|
|
||||||
}
|
|
||||||
this.remoteMediaStream.videoTracks.forEach(videoTrack -> {
|
this.remoteMediaStream.videoTracks.forEach(videoTrack -> {
|
||||||
videoTrack.setEnabled(false);
|
videoTrack.setEnabled(false);
|
||||||
});
|
});
|
||||||
@@ -295,19 +291,14 @@ public class SessionClient extends Client {
|
|||||||
if(this.remoteMediaStream == null) {
|
if(this.remoteMediaStream == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(this.surfaceViewRenderer != null) {
|
|
||||||
// TODO:测试
|
|
||||||
this.surfaceViewRenderer.disableFpsReduction();
|
|
||||||
}
|
|
||||||
this.remoteMediaStream.videoTracks.forEach(videoTrack -> {
|
this.remoteMediaStream.videoTracks.forEach(videoTrack -> {
|
||||||
videoTrack.setEnabled(true);
|
videoTrack.setEnabled(true);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void pause(String type) {
|
public void pauseLocal(String type) {
|
||||||
if(MediaStreamTrack.AUDIO_TRACK_KIND.equals(type)) {
|
if(MediaStreamTrack.AUDIO_TRACK_KIND.equals(type)) {
|
||||||
this.mediaStream.audioTracks.forEach(audioTrack -> {
|
this.mediaStream.audioTracks.forEach(audioTrack -> {
|
||||||
audioTrack.setVolume(0);
|
|
||||||
audioTrack.setEnabled(false);
|
audioTrack.setEnabled(false);
|
||||||
});
|
});
|
||||||
} else if(MediaStreamTrack.VIDEO_TRACK_KIND.equals(type)) {
|
} else if(MediaStreamTrack.VIDEO_TRACK_KIND.equals(type)) {
|
||||||
@@ -318,10 +309,9 @@ public class SessionClient extends Client {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void resume(String type) {
|
public void resumeLocal(String type) {
|
||||||
if(MediaStreamTrack.AUDIO_TRACK_KIND.equals(type)) {
|
if(MediaStreamTrack.AUDIO_TRACK_KIND.equals(type)) {
|
||||||
this.mediaStream.audioTracks.forEach(audioTrack -> {
|
this.mediaStream.audioTracks.forEach(audioTrack -> {
|
||||||
audioTrack.setVolume(Config.DEFAULT_VOLUME);
|
|
||||||
audioTrack.setEnabled(true);
|
audioTrack.setEnabled(true);
|
||||||
});
|
});
|
||||||
} else if(MediaStreamTrack.VIDEO_TRACK_KIND.equals(type)) {
|
} else if(MediaStreamTrack.VIDEO_TRACK_KIND.equals(type)) {
|
||||||
@@ -332,6 +322,30 @@ public class SessionClient extends Client {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void previewLocal() {
|
||||||
|
if(this.mediaStream == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.mediaStream.videoTracks.forEach(videoTrack -> {
|
||||||
|
videoTrack.setEnabled(true);
|
||||||
|
if(this.localSurfaceViewRenderer == null) {
|
||||||
|
this.localSurfaceViewRenderer = this.mediaManager.buildSurfaceViewRenderer(Config.WHAT_NEW_LOCAL_VIDEO, videoTrack);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void releaseLocal() {
|
||||||
|
// 释放本地视频资源
|
||||||
|
if(this.localSurfaceViewRenderer != null) {
|
||||||
|
// 释放资源
|
||||||
|
this.localSurfaceViewRenderer.release();
|
||||||
|
// 移除资源:注意先释放再移除避免报错
|
||||||
|
this.mainHandler.obtainMessage(Config.WHAT_REMOVE_VIDEO, this.localSurfaceViewRenderer).sendToTarget();
|
||||||
|
// 设置为空
|
||||||
|
this.localSurfaceViewRenderer = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void close() {
|
public void close() {
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
@@ -339,14 +353,9 @@ public class SessionClient extends Client {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
super.close();
|
super.close();
|
||||||
|
this.releaseLocal();
|
||||||
try {
|
try {
|
||||||
// PeerConnection自动释放
|
// PeerConnection自动释放:mediaStream、remoteMediaStream
|
||||||
// if(this.mediaStream != null) {
|
|
||||||
// this.mediaStream.dispose();
|
|
||||||
// }
|
|
||||||
// if(this.remoteMediaStream != null) {
|
|
||||||
// this.remoteMediaStream.dispose();
|
|
||||||
// }
|
|
||||||
if(this.peerConnection != null) {
|
if(this.peerConnection != null) {
|
||||||
this.peerConnection.dispose();
|
this.peerConnection.dispose();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user