[*] 本地录像

This commit is contained in:
acgist
2023-06-02 07:17:10 +08:00
parent a06f6a251f
commit becc68b05f
19 changed files with 404 additions and 179 deletions

View File

@@ -8,7 +8,9 @@
android:extractNativeLibs="true"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:killAfterRestore="true"
android:label="@string/app_name"
android:persistent="true"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true">
<activity

View File

@@ -625,10 +625,10 @@ public final class Taoyao implements ITaoyao {
case "client::reboot" -> this.clientReboot(message, message.body());
case "client::register" -> this.clientRegister(message, message.body());
case "client::shutdown" -> this.clientShutdown(message, message.body());
case "control::client::record" -> this.controlClientRecord(message, message.body());
case "control::config::audio" -> this.controlConfigAudio(message, message.body());
case "control::config::video" -> this.controlConfigVideo(message, message.body());
case "control::photograph" -> this.controlPhotograph(message, message.body());
case "control::record" -> this.controlRecord(message, message.body());
case "media::audio::volume" -> this.mediaAudioVolume(message, message.body());
case "media::consume" -> this.mediaConsume(message, message.body());
case "media::consumer::close" -> this.mediaConsumerClose(message, message.body());
@@ -751,6 +751,26 @@ public final class Taoyao implements ITaoyao {
Process.killProcess(Process.myPid());
}
/**
* 录像
*
* @param message 信令消息
* @param body 信令主体
*/
private void controlClientRecord(Message message, Map<String, Object> body) {
String filepath;
final Boolean enabled = MapUtils.getBoolean(body, "enabled");
if(Boolean.TRUE.equals(enabled)) {
final RecordClient recordClient = this.mediaManager.startRecord();
filepath = recordClient.getFilepath();
} else {
filepath = this.mediaManager.stopRecord();
}
body.put("enabled", enabled);
body.put("filepath", filepath);
this.push(message);
}
/**
* 更新音频配置
*
@@ -785,26 +805,6 @@ public final class Taoyao implements ITaoyao {
this.push(message);
}
/**
* 录像
*
* @param message 信令消息
* @param body 信令主体
*/
private void controlRecord(Message message, Map<String, Object> body) {
String filepath;
final Boolean enabled = MapUtils.getBoolean(body, "enabled");
if(Boolean.TRUE.equals(enabled)) {
final RecordClient recordClient = this.mediaManager.startRecord();
filepath = recordClient.getFilepath();
} else {
filepath = this.mediaManager.stopRecord();
}
body.put("enabled", enabled);
body.put("filepath", filepath);
this.push(message);
}
/**
* 远程音量
*

View File

@@ -2,6 +2,8 @@ package com.acgist.taoyao.media;
import android.content.Context;
import android.content.Intent;
import android.media.MediaCodecInfo;
import android.media.MediaCodecList;
import android.media.projection.MediaProjection;
import android.os.Handler;
import android.speech.tts.TextToSpeech;
@@ -45,6 +47,8 @@ import org.webrtc.audio.JavaAudioDeviceModule;
import java.util.Arrays;
import java.util.Locale;
import java.util.UUID;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
/**
* 媒体管理器
@@ -185,20 +189,23 @@ public final class MediaManager {
// WebRtcAudioUtils.setWebRtcBasedAcousticEchoCanceler(true);
// // 自动增益
// WebRtcAudioUtils.setWebRtcBasedAutomaticGainControl(true);
// // 支持的编码器
// final MediaCodecList mediaCodecList = new MediaCodecList(-1);
// for (MediaCodecInfo mediaCodecInfo : mediaCodecList.getCodecInfos()) {
// final String[] supportedTypes = mediaCodecInfo.getSupportedTypes();
// Log.d(MediaManager.class.getSimpleName(), "编码器名称:" + mediaCodecInfo.getName());
// Log.d(MediaManager.class.getSimpleName(), "编码器类型:" + String.join(", ", supportedTypes));
// for (String supportType : supportedTypes) {
// final MediaCodecInfo.CodecCapabilities codecCapabilities = mediaCodecInfo.getCapabilitiesForType(supportType);
// Log.d(MediaManager.class.getSimpleName(), "编码器支持的文件格式:" + codecCapabilities.getMimeType());
// // MediaCodecInfo.CodecCapabilities.COLOR_*
// final int[] colorFormats = codecCapabilities.colorFormats;
// Log.d(MediaManager.class.getSimpleName(), "编码器支持的色彩格式:" + IntStream.of(colorFormats).boxed().map(String::valueOf).collect(Collectors.joining(", ")));
// }
// }
// // 支持的编码解码
final MediaCodecList mediaCodecList = new MediaCodecList(MediaCodecList.ALL_CODECS);
for (MediaCodecInfo mediaCodecInfo : mediaCodecList.getCodecInfos()) {
// OMX.google = 软编
// OMX.core = 硬编
final String[] supportedTypes = mediaCodecInfo.getSupportedTypes();
final String type = mediaCodecInfo.isEncoder() ? "编码器" : "解码器";
Log.d(MediaManager.class.getSimpleName(), type + "名称:" + mediaCodecInfo.getName());
Log.d(MediaManager.class.getSimpleName(), type + "类型:" + String.join(", ", supportedTypes));
for (String supportType : supportedTypes) {
final MediaCodecInfo.CodecCapabilities codecCapabilities = mediaCodecInfo.getCapabilitiesForType(supportType);
Log.d(MediaManager.class.getSimpleName(), type + "支持的文件格式:" + codecCapabilities.getMimeType());
// MediaCodecInfo.CodecCapabilities.COLOR_*
final int[] colorFormats = codecCapabilities.colorFormats;
Log.d(MediaManager.class.getSimpleName(), type + "支持的色彩格式:" + IntStream.of(colorFormats).boxed().map(String::valueOf).collect(Collectors.joining(", ")));
}
}
}
private MediaManager() {