Skip to content

Commit

Permalink
添加gitee仓库
Browse files Browse the repository at this point in the history
  • Loading branch information
mingzhixian committed Nov 4, 2023
1 parent 0130341 commit ee6e062
Show file tree
Hide file tree
Showing 11 changed files with 54 additions and 94 deletions.
Binary file modified easycontrol/.gradle/8.0/executionHistory/executionHistory.lock
Binary file not shown.
Binary file modified easycontrol/.gradle/8.0/fileHashes/fileHashes.bin
Binary file not shown.
Binary file modified easycontrol/.gradle/8.0/fileHashes/fileHashes.lock
Binary file not shown.
Binary file modified easycontrol/.gradle/8.0/fileHashes/resourceHashesCache.bin
Binary file not shown.
Binary file modified easycontrol/.gradle/buildOutputCleanup/buildOutputCleanup.lock
Binary file not shown.
Binary file modified easycontrol/.gradle/file-system.probe
Binary file not shown.
17 changes: 0 additions & 17 deletions easycontrol/.idea/deploymentTargetDropDown.xml

This file was deleted.

69 changes: 33 additions & 36 deletions easycontrol/.idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,23 @@ public class Client {

// 是否正常解码播放
public boolean isNormalPlay = true;
private boolean startSuccess = false;

private final Dialog dialog = AppData.publicTools.createClientLoading(AppData.main, () -> clientView.hide(true));

public Client(Device device, UsbDevice usbDevice) {
// try {
// UsbChannel usbChannel=new UsbChannel(usbDevice);
// usbChannel.write(new byte[]{1});
// byte[] bytes=usbChannel.read(1);
// Log.e("sdsd", Arrays.toString(bytes));
// } catch (Exception e) {
// throw new RuntimeException(e);
// }
// 显示加载框
dialog.show();
// 启动超时
executor.execute(() -> {
try {
Thread.sleep(8000);
} catch (InterruptedException ignored) {
}
if (!startSuccess) clientView.hide(true);
});
// 启动Client
new Thread(() -> {
executor.execute(() -> {
try {
// 连接ADB
connectADB(device, usbDevice);
Expand All @@ -70,30 +71,19 @@ public Client(Device device, UsbDevice usbDevice) {
// 更新UI
AppData.main.runOnUiThread(dialog::cancel);
createUI();
// 阻塞等待连接断开
synchronized (stream) {
stream.wait();
}
startSuccess = true;
} catch (Exception e) {
AppData.main.runOnUiThread(() -> {
Toast.makeText(AppData.main, e.toString(), Toast.LENGTH_SHORT).show();
Log.e("easycontrol", e.toString());
clientView.hide(true);
});
}
}).start();
});
}

// 连接ADB
private void connectADB(Device device, UsbDevice usbDevice) throws Exception {
executor.execute(() -> {
try {
// 连接和授权总共超时时间为5秒
Thread.sleep(5000);
} catch (InterruptedException ignored) {
}
if (adb == null) AppData.main.runOnUiThread(() -> clientView.hide(true));
});
if (usbDevice == null) {
Pair<String, Integer> address = AppData.publicTools.getIpAndPort(device.address);
if (address == null) throw new Exception("地址格式错误");
Expand Down Expand Up @@ -130,16 +120,7 @@ private void startServer(Device device) throws Exception {
setWidth = tmpDeviceSize.first;
setHeight = tmpDeviceSize.second;
}
adb.runAdbCmd("CLASSPATH=/data/local/tmp/" + AppData.serverName + " app_process / top.saymzx.easycontrol.server.Server" +
" is_audio=" + (device.isAudio ? 1 : 0) +
" max_size=" + device.maxSize +
" max_fps=" + device.maxFps +
" video_bit_rate=" + device.maxVideoBit +
" turn_off_screen=" + (AppData.setting.getSlaveTurnOffScreen() ? 1 : 0) +
" auto_control_screen=" + (AppData.setting.getAutoControlScreen() ? 1 : 0) +
" set_width=" + setWidth +
" set_height=" + setHeight +
" > /dev/null 2>&1 & ", false);
adb.runAdbCmd("CLASSPATH=/data/local/tmp/" + AppData.serverName + " app_process / top.saymzx.easycontrol.server.Server" + " is_audio=" + (device.isAudio ? 1 : 0) + " max_size=" + device.maxSize + " max_fps=" + device.maxFps + " video_bit_rate=" + device.maxVideoBit + " turn_off_screen=" + (AppData.setting.getSlaveTurnOffScreen() ? 1 : 0) + " auto_control_screen=" + (AppData.setting.getAutoControlScreen() ? 1 : 0) + " set_width=" + setWidth + " set_height=" + setHeight + " > /dev/null 2>&1 & ", false);
} catch (Exception ignored) {
throw new Exception("启动Server失败");
}
Expand All @@ -166,14 +147,14 @@ private void createSubService() throws Exception {
// 视频大小
clientView.videoSize = new Pair<>(stream.readInt(), stream.readInt());
// 视频解码
stream.readByte();
if (stream.readByte() != 1) throw new IOException("数据错误");
ByteBuffer csd0 = readFrame();
stream.readByte();
if (stream.readByte() != 1) throw new IOException("数据错误");
ByteBuffer csd1 = readFrame();
videoDecode = new VideoDecode(clientView.videoSize, csd0, csd1);
// 音频解码
if (stream.readByte() == 1) {
stream.readByte();
if (stream.readByte() != 2) throw new IOException("数据错误");
csd0 = readFrame();
audioDecode = new AudioDecode(csd0);
}
Expand Down Expand Up @@ -245,10 +226,9 @@ private void executeOtherService() {
controller.sendKeepAlive();
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
clientView.hide(true);
executor.execute(this::executeOtherService);
} catch (InterruptedException ignored) {
}
executor.execute(this::executeOtherService);
}

private ByteBuffer readFrame() throws InterruptedException, IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ public void release() {

public synchronized void decodeIn(ByteBuffer data) {
try {
int inIndex = videoDecodec.dequeueInputBuffer(0);
// 15ms相当于60帧的帧间隔时间
int inIndex = videoDecodec.dequeueInputBuffer(15_000);
// 缓冲区已满则丢帧
if (inIndex < 0) return;
videoDecodec.getInputBuffer(inIndex).put(data);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,8 @@ private static void setVideoEncodec() throws IOException {
encodecFormat.setInteger(MediaFormat.KEY_BIT_RATE, Options.videoBitRate);
encodecFormat.setInteger(MediaFormat.KEY_FRAME_RATE, Options.maxFps);
encodecFormat.setInteger(MediaFormat.KEY_COLOR_FORMAT, MediaCodecInfo.CodecCapabilities.COLOR_FormatSurface);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q)
encodecFormat.setInteger(MediaFormat.KEY_PREPEND_HEADER_TO_SYNC_FRAMES, 1);
}
encodecFormat.setInteger(MediaFormat.KEY_I_FRAME_INTERVAL, 2);
// 若在这个时间间隔内没有检测到足够大的场景变化,视频编码器将重复前一帧的内容,而不是编码全新的帧,以减少计算负担和节省带宽
encodecFormat.setLong(MediaFormat.KEY_REPEAT_PREVIOUS_FRAME_AFTER, 50_000);
Expand Down

0 comments on commit ee6e062

Please sign in to comment.