[*] 每日优化

配置没有改变不要重连信令
忽略房间重复邀请
This commit is contained in:
acgist
2023-05-13 12:09:16 +08:00
parent 825fa907e5
commit 8430fa78a8
17 changed files with 707 additions and 383 deletions

View File

@@ -2,6 +2,7 @@ package com.acgist.taoyao.client;
import android.Manifest;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.res.ColorStateList;
@@ -18,6 +19,7 @@ import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.GridLayout;
import android.widget.Toast;
import androidx.activity.result.ActivityResultLauncher;
import androidx.activity.result.contract.ActivityResultContracts;
@@ -51,7 +53,7 @@ public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle bundle) {
Log.i(MainActivity.class.getSimpleName(), "onCreate");
Log.d(MainActivity.class.getSimpleName(), "onCreate");
super.onCreate(bundle);
final Window window = this.getWindow();
// 强制横屏
@@ -76,19 +78,19 @@ public class MainActivity extends AppCompatActivity {
@Override
protected void onStart() {
Log.i(MainActivity.class.getSimpleName(), "onStart");
Log.d(MainActivity.class.getSimpleName(), "onStart");
super.onStart();
}
@Override
protected void onStop() {
Log.i(MainActivity.class.getSimpleName(), "onStop");
Log.d(MainActivity.class.getSimpleName(), "onStop");
super.onStop();
}
@Override
protected void onDestroy() {
Log.i(MainActivity.class.getSimpleName(), "onDestroy");
Log.d(MainActivity.class.getSimpleName(), "onDestroy");
super.onDestroy();
// 资源释放
}
@@ -123,10 +125,12 @@ public class MainActivity extends AppCompatActivity {
Manifest.permission.RECEIVE_BOOT_COMPLETED,
Manifest.permission.WRITE_EXTERNAL_STORAGE
};
if (Stream.of(permissions).map(this.getApplicationContext()::checkSelfPermission).allMatch(v -> v == PackageManager.PERMISSION_GRANTED)) {
Log.i(MediaService.class.getSimpleName(), "授权成功");
final Context context = this.getApplicationContext();
if (Stream.of(permissions).map(context::checkSelfPermission).allMatch(v -> v == PackageManager.PERMISSION_GRANTED)) {
Log.d(MediaService.class.getSimpleName(), "授权成功");
} else {
ActivityCompat.requestPermissions(this, permissions, IdUtils.nextInt());
Toast.makeText(context, "授权失败", Toast.LENGTH_SHORT).show();
}
}
@@ -158,7 +162,7 @@ public class MainActivity extends AppCompatActivity {
new ActivityResultContracts.StartActivityForResult(),
result -> {
if (result.getResultCode() == Activity.RESULT_OK) {
Log.i(MediaManager.class.getSimpleName(), "屏幕捕获成功");
Log.d(MediaManager.class.getSimpleName(), "屏幕捕获成功");
final Intent intent = new Intent(this, MediaService.class);
intent.setAction(MediaService.Action.SCREEN_CAPTURE.name());
intent.putExtra("data", result.getData());
@@ -290,6 +294,7 @@ public class MainActivity extends AppCompatActivity {
layoutParams.width = 0;
layoutParams.height = 0;
} else {
// 复用布局
layoutParams = this.removeLayoutParams.remove(0);
}
final SurfaceView surfaceView = (SurfaceView) message.obj;
@@ -312,8 +317,9 @@ public class MainActivity extends AppCompatActivity {
return;
}
video.removeViewAt(index);
// 缓存布局
this.removeLayoutParams.add(surfaceView.getLayoutParams());
}
}
}
}

View File

@@ -77,7 +77,7 @@ public class MediaService extends Service {
@Override
public void onCreate() {
Log.i(MediaService.class.getSimpleName(), "onCreate");
Log.d(MediaService.class.getSimpleName(), "onCreate");
Log.i(MediaService.class.getSimpleName(), """
庭院深深深几许,杨柳堆烟,帘幕无重数。玉勒雕鞍游冶处,楼高不见章台路。
雨横风狂三月暮,门掩黄昏,无计留春住。泪眼问花花不语,乱红飞过秋千去。
@@ -97,13 +97,13 @@ public class MediaService extends Service {
@Override
public IBinder onBind(Intent intent) {
Log.i(MediaService.class.getSimpleName(), "onBind");
Log.d(MediaService.class.getSimpleName(), "onBind");
return new Binder();
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Log.i(MediaService.class.getSimpleName(), "onStartCommand" + intent.getAction());
Log.d(MediaService.class.getSimpleName(), "onStartCommand" + intent.getAction());
if (Action.BOOT.name().equals(intent.getAction())) {
this.boot();
this.openConnect();
@@ -122,7 +122,7 @@ public class MediaService extends Service {
@Override
public void onDestroy() {
Log.i(MediaService.class.getSimpleName(), "onDestroy");
Log.d(MediaService.class.getSimpleName(), "onDestroy");
super.onDestroy();
this.close();
}
@@ -155,11 +155,11 @@ public class MediaService extends Service {
resources.getInteger(R.integer.imageQuantity),
resources.getString(R.string.audioQuantity),
resources.getString(R.string.videoQuantity),
resources.getBoolean(R.bool.broadcaster),
resources.getInteger(R.integer.channelCount),
resources.getInteger(R.integer.iFrameInterval),
resources.getString(R.string.storagePathImage),
resources.getString(R.string.storagePathVideo),
resources.getBoolean(R.bool.broadcaster),
resources.getString(R.string.watermark),
VideoSourceType.valueOf(resources.getString(R.string.videoSourceType))
);
@@ -199,13 +199,20 @@ public class MediaService extends Service {
final String password = sharedPreferences.getString("settings.password", "taoyao");
final Context context = this.getApplicationContext();
final Resources resources = this.getResources();
this.close();
if(this.taoyao != null) {
if(this.taoyao.needReconnect(port, host, name, clientId, username, password)) {
this.close();
} else {
Log.d(MediaService.class.getSimpleName(), "配置没有改变忽略重连");
return;
}
}
// 连接信令
this.taoyao = new Taoyao(
port, host, resources.getString(R.string.version),
name, clientId, resources.getString(R.string.clientType), username, password,
resources.getString(R.string.version), resources.getString(R.string.clientType),
port, host, name, clientId, username, password,
resources.getInteger(R.integer.timeout), resources.getString(R.string.encrypt), resources.getString(R.string.encryptSecret),
this.mainHandler, context, this.taoyaoListener
MediaService.mainHandler, context, this.taoyaoListener
);
MediaManager.getInstance().initTaoyao(this.taoyao);
Toast.makeText(context, "连接信令", Toast.LENGTH_SHORT).show();
@@ -268,11 +275,11 @@ public class MediaService extends Service {
*/
private void settingAudio() {
final AudioManager audioManager = this.getApplicationContext().getSystemService(AudioManager.class);
Log.i(MediaService.class.getSimpleName(), "当前音频模式:" + audioManager.getMode());
Log.i(MediaService.class.getSimpleName(), "当前音频音量:" + audioManager.getStreamVolume(audioManager.getMode()));
// Log.i(MediaService.class.getSimpleName(), "当前蓝牙是否打开:" + audioManager.isBluetoothScoOn());
// Log.i(MediaService.class.getSimpleName(), "当前耳机是否打开:" + audioManager.isWiredHeadsetOn());
// Log.i(MediaService.class.getSimpleName(), "当前电话扬声器是否打开:" + audioManager.isSpeakerphoneOn());
Log.d(MediaService.class.getSimpleName(), "当前音频模式:" + audioManager.getMode());
Log.d(MediaService.class.getSimpleName(), "当前音频音量:" + audioManager.getStreamVolume(audioManager.getMode()));
// Log.d(MediaService.class.getSimpleName(), "当前蓝牙是否打开:" + audioManager.isBluetoothScoOn());
// Log.d(MediaService.class.getSimpleName(), "当前耳机是否打开:" + audioManager.isWiredHeadsetOn());
// Log.d(MediaService.class.getSimpleName(), "当前电话扬声器是否打开:" + audioManager.isSpeakerphoneOn());
// audioManager.setStreamVolume(AudioManager.MODE_IN_COMMUNICATION, audioManager.getStreamMaxVolume(AudioManager.MODE_IN_COMMUNICATION), AudioManager.FLAG_PLAY_SOUND);
}

View File

@@ -6,6 +6,7 @@ import android.content.SharedPreferences;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
@@ -22,18 +23,18 @@ public class SettingsActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
Log.i(SettingsActivity.class.getSimpleName(), "onCreate");
Log.d(SettingsActivity.class.getSimpleName(), "onCreate");
super.onCreate(savedInstanceState);
// 布局
this.binding = ActivitySettingsBinding.inflate(this.getLayoutInflater());
this.setContentView(this.binding.getRoot());
// 设置按钮
final View root = this.binding.getRoot();
root.setZ(100F);
this.setContentView(root);
this.binding.connect.setOnClickListener(this::settingsPersistent);
}
@Override
protected void onStart() {
Log.i(SettingsActivity.class.getSimpleName(), "onStart");
Log.d(SettingsActivity.class.getSimpleName(), "onStart");
super.onStart();
// 回填配置
final SharedPreferences sharedPreferences = this.getSharedPreferences("settings", Context.MODE_PRIVATE);
@@ -47,18 +48,18 @@ public class SettingsActivity extends AppCompatActivity {
@Override
protected void onStop() {
Log.i(SettingsActivity.class.getSimpleName(), "onStop");
Log.d(SettingsActivity.class.getSimpleName(), "onStop");
super.onStop();
}
@Override
protected void onDestroy() {
Log.i(SettingsActivity.class.getSimpleName(), "onDestroy");
Log.d(SettingsActivity.class.getSimpleName(), "onDestroy");
super.onDestroy();
}
/**
* 持久化日志
* 保存配置
*
* @param view View
*/
@@ -86,16 +87,19 @@ public class SettingsActivity extends AppCompatActivity {
editor.putString("settings.clientId", clientId);
editor.putString("settings.username", username);
editor.putString("settings.password", password);
editor.commit();
// 重连信令
final Intent serviceIntent = new Intent(this, MediaService.class);
serviceIntent.setAction(MediaService.Action.RECONNECT.name());
this.startService(serviceIntent);
// 预览页面
final Intent activityIntent = new Intent(this, MainActivity.class);
this.startActivity(activityIntent);
// 结束
this.finish();
if(editor.commit()) {
// 重连信令
final Intent serviceIntent = new Intent(this, MediaService.class);
serviceIntent.setAction(MediaService.Action.RECONNECT.name());
this.startService(serviceIntent);
// 预览页面
final Intent activityIntent = new Intent(this, MainActivity.class);
this.startActivity(activityIntent);
// 结束
this.finish();
} else {
Toast.makeText(this.getApplicationContext(), "配置保存失败", Toast.LENGTH_SHORT).show();
}
}
}
}

View File

@@ -6,7 +6,7 @@ import android.content.Intent;
import android.util.Log;
/**
* 开机启动
* 开机广播
*
* @author acgist
*/
@@ -14,7 +14,7 @@ public class TaoyaoReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Log.i(TaoyaoReceiver.class.getSimpleName(), "onReceive" + intent.getAction());
Log.d(TaoyaoReceiver.class.getSimpleName(), "onReceive" + intent.getAction());
if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) {
this.bootTaoyao(context);
} else {

View File

@@ -8,10 +8,10 @@
<bool name="playVideo">true</bool>
<!-- 信令版本 -->
<string name="version">1.0.0</string>
<!-- 超时时间 -->
<integer name="timeout">5000</integer>
<!-- 终端类型CAMERA|MOBILE -->
<string name="clientType">MOBILE</string>
<!-- 超时时间 -->
<integer name="timeout">5000</integer>
<!-- 信令加密策略AES|DES -->
<string name="encrypt">DES</string>
<!-- 信令加密密钥 -->
@@ -34,14 +34,14 @@
<bool name="audioProduce">true</bool>
<!-- 媒体配置:是否生产视频 -->
<bool name="videoProduce">true</bool>
<!-- 语音播报 -->
<bool name="broadcaster">false</bool>
<!-- 图片质量 -->
<integer name="imageQuantity">100</integer>
<!-- 音频质量 -->
<string name="audioQuantity">fd-audio</string>
<!-- 视频质量 -->
<string name="videoQuantity">fd-video</string>
<!-- 语音播报 -->
<bool name="broadcaster">false</bool>
<!-- 音频通道数量 -->
<integer name="channelCount">1</integer>
<!-- 视频关键帧频率 -->