also support rtsp
This commit is contained in:
parent
b03e4c03b9
commit
46b344eee2
3 changed files with 95 additions and 42 deletions
|
@ -30,13 +30,13 @@ android {
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
|
||||||
implementation 'androidx.appcompat:appcompat:1.4.1'
|
implementation 'androidx.appcompat:appcompat:1.6.1'
|
||||||
implementation 'com.google.android.material:material:1.5.0'
|
implementation 'com.google.android.material:material:1.9.0'
|
||||||
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
|
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
|
||||||
implementation 'androidx.preference:preference:1.2.0'
|
implementation 'androidx.preference:preference:1.2.1'
|
||||||
testImplementation 'junit:junit:4.13.2'
|
testImplementation 'junit:junit:4.13.2'
|
||||||
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
|
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
|
||||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
|
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
|
||||||
|
|
||||||
implementation 'com.github.pedroSG94.rtmp-rtsp-stream-client-java:rtplibrary:2.2.6'
|
implementation 'com.github.pedroSG94.rtmp-rtsp-stream-client-java:rtplibrary:2.2.6'
|
||||||
}
|
}
|
|
@ -119,7 +119,7 @@ public class MainActivity extends AppCompatActivity {
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Log.d(TAG, "button start");
|
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());
|
MainActivity.this.screenCapReq.launch(MainActivity.this.screenCapService.getScreenCapDisplay().sendIntent());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,10 @@ import androidx.preference.PreferenceManager;
|
||||||
|
|
||||||
import com.pedro.encoder.utils.CodecUtil;
|
import com.pedro.encoder.utils.CodecUtil;
|
||||||
import com.pedro.rtmp.utils.ConnectCheckerRtmp;
|
import com.pedro.rtmp.utils.ConnectCheckerRtmp;
|
||||||
|
import com.pedro.rtplibrary.base.DisplayBase;
|
||||||
import com.pedro.rtplibrary.rtmp.RtmpDisplay;
|
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.HashSet;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
@ -49,9 +52,9 @@ public class ScreenCapService extends Service {
|
||||||
}
|
}
|
||||||
|
|
||||||
private final IBinder mBinder = new MBinder();
|
private final IBinder mBinder = new MBinder();
|
||||||
private RtmpDisplay screenCapDisplay;
|
private DisplayBase screenCapDisplay;
|
||||||
|
|
||||||
public RtmpDisplay getScreenCapDisplay() {
|
public DisplayBase getScreenCapDisplay() {
|
||||||
return this.screenCapDisplay;
|
return this.screenCapDisplay;
|
||||||
}
|
}
|
||||||
private String infoDisplayText = "";
|
private String infoDisplayText = "";
|
||||||
|
@ -75,9 +78,56 @@ public class ScreenCapService extends Service {
|
||||||
Log.d(TAG, "service destroyed");
|
Log.d(TAG, "service destroyed");
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void createDisplay() {
|
protected void createDisplay(boolean rtsp) {
|
||||||
boolean use_gl = prefs.getBoolean("use_gl", true);
|
boolean use_gl = prefs.getBoolean("use_gl", true);
|
||||||
Log.d(TAG, String.format("creating display use_gl=%b", use_gl));
|
Log.d(TAG, String.format("creating display use_gl=%b", use_gl));
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onConnectionSuccessRtsp() {
|
||||||
|
setInfoDisplay(getString(R.string.status_connected));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onConnectionFailedRtsp(@NonNull String reason) {
|
||||||
|
String text = getString(R.string.status_connection_failed_format, reason);
|
||||||
|
showToast(text);
|
||||||
|
setInfoDisplay(text);
|
||||||
|
ScreenCapService.this.stop();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onNewBitrateRtsp(long bitrate) {
|
||||||
|
setInfoDisplay(getString(R.string.status_bitrate_format, bitrate));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDisconnectRtsp() {
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onAuthSuccessRtsp() {
|
||||||
|
setInfoDisplay(getString(R.string.status_auth_success));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else {
|
||||||
this.screenCapDisplay = new RtmpDisplay(this, use_gl, new ConnectCheckerRtmp() {
|
this.screenCapDisplay = new RtmpDisplay(this, use_gl, new ConnectCheckerRtmp() {
|
||||||
public void onAuthErrorRtmp() {
|
public void onAuthErrorRtmp() {
|
||||||
String text = getString(R.string.status_auth_error);
|
String text = getString(R.string.status_auth_error);
|
||||||
|
@ -116,6 +166,7 @@ public class ScreenCapService extends Service {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected void startCapture(String server) {
|
protected void startCapture(String server) {
|
||||||
if (this.connected) {
|
if (this.connected) {
|
||||||
|
@ -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,
|
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);
|
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.setReTries(prefs.getInt("retries_int", 0));
|
||||||
screenCapDisplay.resizeCache(prefs.getInt("cache_size_int", 120));
|
screenCapDisplay.resizeCache(prefs.getInt("cache_size_int", 120));
|
||||||
screenCapDisplay.setLogs(prefs.getBoolean("enable_lib_logs", true));
|
screenCapDisplay.setLogs(prefs.getBoolean("enable_lib_logs", true));
|
||||||
|
|
Loading…
Reference in a new issue