Skip to content

Commit

Permalink
use generic ConnectChecker
Browse files Browse the repository at this point in the history
  • Loading branch information
pedroSG94 committed Nov 3, 2023
1 parent 6e864a3 commit 825f733
Show file tree
Hide file tree
Showing 64 changed files with 524 additions and 576 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import android.util.Log
import androidx.annotation.RequiresApi
import androidx.core.app.NotificationCompat
import androidx.lifecycle.MutableLiveData
import com.pedro.common.ConnectChecker
import com.pedro.library.base.Camera2Base
import com.pedro.library.rtmp.RtmpCamera2
import com.pedro.library.rtsp.RtspCamera2
Expand Down Expand Up @@ -70,7 +71,7 @@ class RtpService : Service() {
notificationManager?.createNotificationChannel(channel)
}
keepAliveTrick()
camera2Base = RtmpCamera2(this, true, connectCheckerRtp)
camera2Base = RtmpCamera2(this, true, connectChecker)
observer.postValue(this)
}

Expand Down Expand Up @@ -105,11 +106,11 @@ class RtpService : Service() {

fun prepare(endpoint: String): Boolean {
if (endpoint.startsWith("rtmp")) {
camera2Base = RtmpCamera2(this, true, connectCheckerRtp)
camera2Base = RtmpCamera2(this, true, connectChecker)
} else if (endpoint.startsWith("rtsp")){
camera2Base = RtspCamera2(this, true, connectCheckerRtp)
camera2Base = RtspCamera2(this, true, connectChecker)
} else {
camera2Base = SrtCamera2(this, true, connectCheckerRtp)
camera2Base = SrtCamera2(this, true, connectChecker)
}
return camera2Base?.prepareVideo() ?: false && camera2Base?.prepareAudio() ?: false
}
Expand Down Expand Up @@ -158,34 +159,34 @@ class RtpService : Service() {
camera2Base?.replaceView(context)
}

private val connectCheckerRtp = object : ConnectCheckerRtp {
override fun onConnectionStartedRtp(rtpUrl: String) {
private val connectChecker = object : ConnectChecker {
override fun onConnectionStarted(url: String) {
showNotification("Stream connection started")
}

override fun onConnectionSuccessRtp() {
override fun onConnectionSuccess() {
showNotification("Stream started")
Log.e(TAG, "RTP service destroy")
}

override fun onNewBitrateRtp(bitrate: Long) {
override fun onNewBitrate(bitrate: Long) {

}

override fun onConnectionFailedRtp(reason: String) {
override fun onConnectionFailed(reason: String) {
showNotification("Stream connection failed")
Log.e(TAG, "RTP service destroy")
}

override fun onDisconnectRtp() {
override fun onDisconnect() {
showNotification("Stream stopped")
}

override fun onAuthErrorRtp() {
override fun onAuthError() {
showNotification("Stream auth error")
}

override fun onAuthSuccessRtp() {
override fun onAuthSuccess() {
showNotification("Stream auth success")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,17 @@
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.ActionBarDrawerToggle;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.view.GravityCompat;
import androidx.drawerlayout.widget.DrawerLayout;

import com.google.android.material.navigation.NavigationView;
import com.pedro.common.ConnectChecker;
import com.pedro.encoder.input.video.CameraHelper;
import com.pedro.encoder.input.video.CameraOpenException;
import com.pedro.rtmp.utils.ConnectCheckerRtmp;
import com.pedro.library.rtmp.RtmpCamera1;
import com.pedro.streamer.R;
import com.pedro.streamer.utils.PathUtils;
Expand All @@ -65,7 +66,7 @@
* {@link com.pedro.library.rtmp.RtmpCamera1}
*/
public class RtmpActivity extends AppCompatActivity
implements Button.OnClickListener, ConnectCheckerRtmp, SurfaceHolder.Callback,
implements Button.OnClickListener, ConnectChecker, SurfaceHolder.Callback,
View.OnTouchListener {

private Integer[] orientations = new Integer[] { 0, 90, 180, 270 };
Expand Down Expand Up @@ -315,16 +316,16 @@ private boolean prepareEncoders() {
}

@Override
public void onConnectionStartedRtmp(String rtmpUrl) {
public void onConnectionStarted(@NonNull String url) {
}

@Override
public void onConnectionSuccessRtmp() {
public void onConnectionSuccess() {
Toast.makeText(RtmpActivity.this, "Connection success", Toast.LENGTH_SHORT).show();
}

@Override
public void onConnectionFailedRtmp(final String reason) {
public void onConnectionFailed(@NonNull final String reason) {
Toast.makeText(RtmpActivity.this, "Connection failed. " + reason, Toast.LENGTH_SHORT)
.show();
rtmpCamera1.stopStream();
Expand All @@ -342,12 +343,12 @@ public void onConnectionFailedRtmp(final String reason) {
}

@Override
public void onNewBitrateRtmp(final long bitrate) {
public void onNewBitrate(final long bitrate) {
tvBitrate.setText(bitrate + " bps");
}

@Override
public void onDisconnectRtmp() {
public void onDisconnect() {
Toast.makeText(RtmpActivity.this, "Disconnected", Toast.LENGTH_SHORT).show();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2
&& rtmpCamera1.isRecording()) {
Expand All @@ -362,12 +363,12 @@ public void onDisconnectRtmp() {
}

@Override
public void onAuthErrorRtmp() {
public void onAuthError() {
Toast.makeText(RtmpActivity.this, "Auth error", Toast.LENGTH_SHORT).show();
}

@Override
public void onAuthSuccessRtmp() {
public void onAuthSuccess() {
Toast.makeText(RtmpActivity.this, "Auth success", Toast.LENGTH_SHORT).show();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,21 @@
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.ActionBarDrawerToggle;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.view.GravityCompat;
import androidx.drawerlayout.widget.DrawerLayout;
import com.google.android.material.navigation.NavigationView;
import com.pedro.common.ConnectChecker;
import com.pedro.encoder.input.video.CameraHelper;
import com.pedro.encoder.input.video.CameraOpenException;
import com.pedro.library.rtsp.RtspCamera1;
import com.pedro.streamer.R;
import com.pedro.streamer.utils.PathUtils;
import com.pedro.rtsp.rtsp.Protocol;
import com.pedro.rtsp.utils.ConnectCheckerRtsp;

import org.jetbrains.annotations.NotNull;

Expand All @@ -65,7 +67,7 @@
* {@link com.pedro.library.rtsp.RtspCamera1}
*/
public class RtspActivity extends AppCompatActivity
implements Button.OnClickListener, ConnectCheckerRtsp, SurfaceHolder.Callback,
implements Button.OnClickListener, ConnectChecker, SurfaceHolder.Callback,
View.OnTouchListener {

private Integer[] orientations = new Integer[] { 0, 90, 180, 270 };
Expand Down Expand Up @@ -332,16 +334,16 @@ private boolean prepareEncoders() {
}

@Override
public void onConnectionStartedRtsp(@NotNull String rtspUrl) {
public void onConnectionStarted(@NotNull String rtspUrl) {
}

@Override
public void onConnectionSuccessRtsp() {
public void onConnectionSuccess() {
Toast.makeText(RtspActivity.this, "Connection success", Toast.LENGTH_SHORT).show();
}

@Override
public void onConnectionFailedRtsp(final String reason) {
public void onConnectionFailed(@NonNull final String reason) {
Toast.makeText(RtspActivity.this, "Connection failed. " + reason, Toast.LENGTH_SHORT)
.show();
rtspCamera1.stopStream();
Expand All @@ -359,12 +361,12 @@ public void onConnectionFailedRtsp(final String reason) {
}

@Override
public void onNewBitrateRtsp(final long bitrate) {
public void onNewBitrate(final long bitrate) {
tvBitrate.setText(bitrate + " bps");
}

@Override
public void onDisconnectRtsp() {
public void onDisconnect() {
Toast.makeText(RtspActivity.this, "Disconnected", Toast.LENGTH_SHORT).show();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2
&& rtspCamera1.isRecording()) {
Expand All @@ -379,7 +381,7 @@ public void onDisconnectRtsp() {
}

@Override
public void onAuthErrorRtsp() {
public void onAuthError() {
bStartStop.setText(getResources().getString(R.string.start_button));
rtspCamera1.stopStream();
Toast.makeText(RtspActivity.this, "Auth error", Toast.LENGTH_SHORT).show();
Expand All @@ -396,7 +398,7 @@ public void onAuthErrorRtsp() {
}

@Override
public void onAuthSuccessRtsp() {
public void onAuthSuccess() {
Toast.makeText(RtspActivity.this, "Auth success", Toast.LENGTH_SHORT).show();
}

Expand Down
Loading

0 comments on commit 825f733

Please sign in to comment.