also support rtsp

This commit is contained in:
JerryXiao 2023-08-21 20:46:59 +08:00
parent b03e4c03b9
commit 46b344eee2
Signed by: Jerry
GPG key ID: 22618F758B5BE2E5
3 changed files with 95 additions and 42 deletions

View file

@ -30,13 +30,13 @@ android {
dependencies {
implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'com.google.android.material:material:1.5.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
implementation 'androidx.preference:preference:1.2.0'
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.google.android.material:material:1.9.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'androidx.preference:preference:1.2.1'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
implementation 'com.github.pedroSG94.rtmp-rtsp-stream-client-java:rtplibrary:2.2.6'
}

View file

@ -119,7 +119,7 @@ public class MainActivity extends AppCompatActivity {
}
else {
Log.d(TAG, "button start");
MainActivity.this.screenCapService.createDisplay();
MainActivity.this.screenCapService.createDisplay(prefs.getString("server", "").toLowerCase().startsWith("rtsp"));
MainActivity.this.screenCapReq.launch(MainActivity.this.screenCapService.getScreenCapDisplay().sendIntent());
}
}

View file

@ -25,7 +25,10 @@ import androidx.preference.PreferenceManager;
import com.pedro.encoder.utils.CodecUtil;
import com.pedro.rtmp.utils.ConnectCheckerRtmp;
import com.pedro.rtplibrary.base.DisplayBase;
import com.pedro.rtplibrary.rtmp.RtmpDisplay;
import com.pedro.rtplibrary.rtsp.RtspDisplay;
import com.pedro.rtsp.utils.ConnectCheckerRtsp;
import java.util.HashSet;
import java.util.function.Consumer;
@ -49,9 +52,9 @@ public class ScreenCapService extends Service {
}
private final IBinder mBinder = new MBinder();
private RtmpDisplay screenCapDisplay;
private DisplayBase screenCapDisplay;
public RtmpDisplay getScreenCapDisplay() {
public DisplayBase getScreenCapDisplay() {
return this.screenCapDisplay;
}
private String infoDisplayText = "";
@ -75,46 +78,94 @@ public class ScreenCapService extends Service {
Log.d(TAG, "service destroyed");
}
protected void createDisplay() {
protected void createDisplay(boolean rtsp) {
boolean use_gl = prefs.getBoolean("use_gl", true);
Log.d(TAG, String.format("creating display use_gl=%b", use_gl));
this.screenCapDisplay = new RtmpDisplay(this, use_gl, new ConnectCheckerRtmp() {
public void onAuthErrorRtmp() {
String text = getString(R.string.status_auth_error);
showToast(text);
setInfoDisplay(text);
ScreenCapService.this.stop();
}
if (rtsp) {
this.screenCapDisplay = new RtspDisplay(this, use_gl, new ConnectCheckerRtsp() {
@Override
public void onConnectionStartedRtsp(@NonNull String rtspUrl) {
setInfoDisplay(getString(R.string.status_connecting, rtspUrl));
ScreenCapService.this.connectionStateChange(true);
}
public void onAuthSuccessRtmp() {
setInfoDisplay(getString(R.string.status_auth_success));
}
@Override
public void onConnectionSuccessRtsp() {
setInfoDisplay(getString(R.string.status_connected));
}
public void onConnectionFailedRtmp(@NonNull String reason) {
String text = getString(R.string.status_connection_failed_format, reason);
showToast(text);
setInfoDisplay(text);
ScreenCapService.this.stop();
}
@Override
public void onConnectionFailedRtsp(@NonNull String reason) {
String text = getString(R.string.status_connection_failed_format, reason);
showToast(text);
setInfoDisplay(text);
ScreenCapService.this.stop();
}
public void onConnectionStartedRtmp(@NonNull String rtmpUrl) {
setInfoDisplay(getString(R.string.status_connecting, rtmpUrl));
ScreenCapService.this.connectionStateChange(true);
}
@Override
public void onNewBitrateRtsp(long bitrate) {
setInfoDisplay(getString(R.string.status_bitrate_format, bitrate));
}
public void onConnectionSuccessRtmp() {
setInfoDisplay(getString(R.string.status_connected));
}
@Override
public void onDisconnectRtsp() {
setInfoDisplay(getString(R.string.status_disconnected));
ScreenCapService.this.stop();
}
public void onDisconnectRtmp() {
setInfoDisplay(getString(R.string.status_disconnected));
ScreenCapService.this.stop();
}
@Override
public void onAuthErrorRtsp() {
String text = getString(R.string.status_auth_error);
showToast(text);
setInfoDisplay(text);
ScreenCapService.this.stop();
}
public void onNewBitrateRtmp(long bitrate) {
setInfoDisplay(getString(R.string.status_bitrate_format, bitrate));
}
});
@Override
public void onAuthSuccessRtsp() {
setInfoDisplay(getString(R.string.status_auth_success));
}
});
}
else {
this.screenCapDisplay = new RtmpDisplay(this, use_gl, new ConnectCheckerRtmp() {
public void onAuthErrorRtmp() {
String text = getString(R.string.status_auth_error);
showToast(text);
setInfoDisplay(text);
ScreenCapService.this.stop();
}
public void onAuthSuccessRtmp() {
setInfoDisplay(getString(R.string.status_auth_success));
}
public void onConnectionFailedRtmp(@NonNull String reason) {
String text = getString(R.string.status_connection_failed_format, reason);
showToast(text);
setInfoDisplay(text);
ScreenCapService.this.stop();
}
public void onConnectionStartedRtmp(@NonNull String rtmpUrl) {
setInfoDisplay(getString(R.string.status_connecting, rtmpUrl));
ScreenCapService.this.connectionStateChange(true);
}
public void onConnectionSuccessRtmp() {
setInfoDisplay(getString(R.string.status_connected));
}
public void onDisconnectRtmp() {
setInfoDisplay(getString(R.string.status_disconnected));
ScreenCapService.this.stop();
}
public void onNewBitrateRtmp(long bitrate) {
setInfoDisplay(getString(R.string.status_bitrate_format, bitrate));
}
});
}
}
protected void startCapture(String server) {
@ -136,7 +187,9 @@ public class ScreenCapService extends Service {
screenCapDisplay.setForce(prefs.getBoolean("software_video_encoder", false) ? CodecUtil.Force.SOFTWARE : CodecUtil.Force.FIRST_COMPATIBLE_FOUND,
prefs.getBoolean("software_audio_encoder", false) ? CodecUtil.Force.SOFTWARE : CodecUtil.Force.FIRST_COMPATIBLE_FOUND);
screenCapDisplay.setWriteChunkSize(prefs.getInt("write_chunk_size_int", 1024));
if (screenCapDisplay instanceof RtmpDisplay d) {
d.setWriteChunkSize(prefs.getInt("write_chunk_size_int", 1024));
}
screenCapDisplay.setReTries(prefs.getInt("retries_int", 0));
screenCapDisplay.resizeCache(prefs.getInt("cache_size_int", 120));
screenCapDisplay.setLogs(prefs.getBoolean("enable_lib_logs", true));