Skip to content

Commit

Permalink
move retry to streamclient
Browse files Browse the repository at this point in the history
  • Loading branch information
pedroSG94 committed Oct 12, 2023
1 parent d5576da commit 8fec4e9
Show file tree
Hide file tree
Showing 32 changed files with 197 additions and 317 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public void onConnectionSuccessRtmp() {

@Override
public void onConnectionFailedRtmp(final String reason) {
if (rtmpCamera1.reTry(5000, reason, null)) {
if (rtmpCamera1.getStreamClient().reTry(5000, reason, null)) {
Toast.makeText(ExampleRtmpActivity.this, "Retry", Toast.LENGTH_SHORT)
.show();
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public void onConnectionSuccessRtsp() {

@Override
public void onConnectionFailedRtsp(final String reason) {
if (rtspCamera1.reTry(5000, reason, null)) {
if (rtspCamera1.getStreamClient().reTry(5000, reason, null)) {
Toast.makeText(ExampleRtspActivity.this, "Retry", Toast.LENGTH_SHORT)
.show();
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public void onConnectionSuccessSrt() {

@Override
public void onConnectionFailedSrt(final String reason) {
if (srtCamera1.reTry(5000, reason, null)) {
if (srtCamera1.getStreamClient().reTry(5000, reason, null)) {
Toast.makeText(ExampleSrtActivity.this, "Retry", Toast.LENGTH_SHORT)
.show();
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public void onConnectionSuccessRtmp() {

@Override
public void onConnectionFailedRtmp(final String reason) {
if (rtmpCamera2.reTry(5000, reason, null)) {
if (rtmpCamera2.getStreamClient().reTry(5000, reason, null)) {
Toast.makeText(SurfaceModeRtmpActivity.this, "Retry", Toast.LENGTH_SHORT)
.show();
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public void onConnectionSuccessRtsp() {
@Override
public void onConnectionFailedRtsp(final String reason) {
//Wait 5s and retry connect stream
if (rtspCamera2.reTry(5000, reason, null)) {
if (rtspCamera2.getStreamClient().reTry(5000, reason, null)) {
Toast.makeText(SurfaceModeRtspActivity.this, "Retry", Toast.LENGTH_SHORT)
.show();
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import androidx.annotation.RequiresApi;

import com.pedro.encoder.EncoderErrorCallback;
import com.pedro.encoder.Frame;
import com.pedro.encoder.audio.AudioEncoder;
import com.pedro.encoder.audio.GetAacData;
import com.pedro.encoder.input.audio.CustomAudioEffect;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import androidx.annotation.RequiresApi;

import com.pedro.encoder.EncoderErrorCallback;
import com.pedro.encoder.Frame;
import com.pedro.encoder.audio.AudioEncoder;
import com.pedro.encoder.audio.GetAacData;
import com.pedro.encoder.input.audio.GetMicrophoneData;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import androidx.annotation.RequiresApi;

import com.pedro.encoder.EncoderErrorCallback;
import com.pedro.encoder.Frame;
import com.pedro.encoder.audio.AudioEncoder;
import com.pedro.encoder.audio.GetAacData;
import com.pedro.encoder.input.audio.CustomAudioEffect;
Expand Down
1 change: 0 additions & 1 deletion library/src/main/java/com/pedro/library/base/StreamBase.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import com.pedro.encoder.audio.AudioEncoder
import com.pedro.encoder.audio.GetAacData
import com.pedro.encoder.input.audio.GetMicrophoneData
import com.pedro.encoder.input.video.CameraHelper
import com.pedro.encoder.input.video.GetCameraData
import com.pedro.encoder.video.FormatVideoEncoder
import com.pedro.encoder.video.GetVideoData
import com.pedro.encoder.video.VideoEncoder
Expand Down
33 changes: 11 additions & 22 deletions library/src/main/java/com/pedro/library/rtmp/RtmpCamera1.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,14 @@
import android.view.SurfaceView;
import android.view.TextureView;

import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;

import com.pedro.encoder.utils.CodecUtil;
import com.pedro.library.base.Camera1Base;
import com.pedro.library.util.client.RtmpStreamClient;
import com.pedro.library.util.client.SrtStreamClient;
import com.pedro.library.util.streamclient.RtmpStreamClient;
import com.pedro.library.util.streamclient.StreamClientListener;
import com.pedro.library.view.LightOpenGlView;
import com.pedro.library.view.OpenGlView;
import com.pedro.rtmp.flv.video.ProfileIop;
import com.pedro.rtmp.rtmp.RtmpClient;
import com.pedro.rtmp.rtmp.VideoCodec;
import com.pedro.rtmp.utils.ConnectCheckerRtmp;
Expand All @@ -45,42 +43,42 @@
* Created by pedro on 25/01/17.
*/

public class RtmpCamera1 extends Camera1Base {
public class RtmpCamera1 extends Camera1Base implements StreamClientListener {

private final RtmpClient rtmpClient;
private final RtmpStreamClient streamClient;

public RtmpCamera1(SurfaceView surfaceView, ConnectCheckerRtmp connectChecker) {
super(surfaceView);
rtmpClient = new RtmpClient(connectChecker);
streamClient = new RtmpStreamClient(rtmpClient);
streamClient = new RtmpStreamClient(rtmpClient, this);
}

public RtmpCamera1(TextureView textureView, ConnectCheckerRtmp connectChecker) {
super(textureView);
rtmpClient = new RtmpClient(connectChecker);
streamClient = new RtmpStreamClient(rtmpClient);
streamClient = new RtmpStreamClient(rtmpClient, this);
}

@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR2)
public RtmpCamera1(OpenGlView openGlView, ConnectCheckerRtmp connectChecker) {
super(openGlView);
rtmpClient = new RtmpClient(connectChecker);
streamClient = new RtmpStreamClient(rtmpClient);
streamClient = new RtmpStreamClient(rtmpClient, this);
}

@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR2)
public RtmpCamera1(LightOpenGlView lightOpenGlView, ConnectCheckerRtmp connectChecker) {
super(lightOpenGlView);
rtmpClient = new RtmpClient(connectChecker);
streamClient = new RtmpStreamClient(rtmpClient);
streamClient = new RtmpStreamClient(rtmpClient, this);
}

@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR2)
public RtmpCamera1(Context context, ConnectCheckerRtmp connectChecker) {
super(context);
rtmpClient = new RtmpClient(connectChecker);
streamClient = new RtmpStreamClient(rtmpClient);
streamClient = new RtmpStreamClient(rtmpClient, this);
}

public RtmpStreamClient getStreamClient() {
Expand Down Expand Up @@ -131,17 +129,8 @@ protected void getH264DataRtp(ByteBuffer h264Buffer, MediaCodec.BufferInfo info)
rtmpClient.sendVideo(h264Buffer, info);
}

/**
* Retries to connect with the given delay. You can pass an optional backupUrl
* if you'd like to connect to your backup server instead of the original one.
* Given backupUrl replaces the original one.
*/
public boolean reTry(long delay, String reason, @Nullable String backupUrl) {
boolean result = streamClient.shouldRetry(reason);
if (result) {
requestKeyFrame();
streamClient.reConnect(delay, backupUrl);
}
return result;
@Override
public void onRequestKeyframe() {
requestKeyFrame();
}
}
32 changes: 11 additions & 21 deletions library/src/main/java/com/pedro/library/rtmp/RtmpCamera2.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,14 @@
import android.view.SurfaceView;
import android.view.TextureView;

import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;

import com.pedro.encoder.utils.CodecUtil;
import com.pedro.library.base.Camera2Base;
import com.pedro.library.util.client.RtmpStreamClient;
import com.pedro.library.util.streamclient.RtmpStreamClient;
import com.pedro.library.util.streamclient.StreamClientListener;
import com.pedro.library.view.LightOpenGlView;
import com.pedro.library.view.OpenGlView;
import com.pedro.rtmp.flv.video.ProfileIop;
import com.pedro.rtmp.rtmp.RtmpClient;
import com.pedro.rtmp.rtmp.VideoCodec;
import com.pedro.rtmp.utils.ConnectCheckerRtmp;
Expand All @@ -44,7 +43,7 @@
* Created by pedro on 6/07/17.
*/
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
public class RtmpCamera2 extends Camera2Base {
public class RtmpCamera2 extends Camera2Base implements StreamClientListener {

private final RtmpClient rtmpClient;
private final RtmpStreamClient streamClient;
Expand All @@ -58,7 +57,7 @@ public class RtmpCamera2 extends Camera2Base {
public RtmpCamera2(SurfaceView surfaceView, ConnectCheckerRtmp connectChecker) {
super(surfaceView);
rtmpClient = new RtmpClient(connectChecker);
streamClient = new RtmpStreamClient(rtmpClient);
streamClient = new RtmpStreamClient(rtmpClient, this);
}

/**
Expand All @@ -70,25 +69,25 @@ public RtmpCamera2(SurfaceView surfaceView, ConnectCheckerRtmp connectChecker) {
public RtmpCamera2(TextureView textureView, ConnectCheckerRtmp connectChecker) {
super(textureView);
rtmpClient = new RtmpClient(connectChecker);
streamClient = new RtmpStreamClient(rtmpClient);
streamClient = new RtmpStreamClient(rtmpClient, this);
}

public RtmpCamera2(OpenGlView openGlView, ConnectCheckerRtmp connectChecker) {
super(openGlView);
rtmpClient = new RtmpClient(connectChecker);
streamClient = new RtmpStreamClient(rtmpClient);
streamClient = new RtmpStreamClient(rtmpClient, this);
}

public RtmpCamera2(LightOpenGlView lightOpenGlView, ConnectCheckerRtmp connectChecker) {
super(lightOpenGlView);
rtmpClient = new RtmpClient(connectChecker);
streamClient = new RtmpStreamClient(rtmpClient);
streamClient = new RtmpStreamClient(rtmpClient, this);
}

public RtmpCamera2(Context context, boolean useOpengl, ConnectCheckerRtmp connectChecker) {
super(context, useOpengl);
rtmpClient = new RtmpClient(connectChecker);
streamClient = new RtmpStreamClient(rtmpClient);
streamClient = new RtmpStreamClient(rtmpClient, this);
}

public RtmpStreamClient getStreamClient() {
Expand Down Expand Up @@ -139,18 +138,9 @@ protected void getH264DataRtp(ByteBuffer h264Buffer, MediaCodec.BufferInfo info)
rtmpClient.sendVideo(h264Buffer, info);
}

/**
* Retries to connect with the given delay. You can pass an optional backupUrl
* if you'd like to connect to your backup server instead of the original one.
* Given backupUrl replaces the original one.
*/
public boolean reTry(long delay, String reason, @Nullable String backupUrl) {
boolean result = streamClient.shouldRetry(reason);
if (result) {
requestKeyFrame();
streamClient.reConnect(delay, backupUrl);
}
return result;
@Override
public void onRequestKeyframe() {
requestKeyFrame();
}
}

26 changes: 7 additions & 19 deletions library/src/main/java/com/pedro/library/rtmp/RtmpDisplay.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,12 @@
import android.media.MediaCodec;
import android.os.Build;

import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;

import com.pedro.encoder.utils.CodecUtil;
import com.pedro.library.base.DisplayBase;
import com.pedro.library.util.client.RtmpStreamClient;
import com.pedro.library.util.client.StreamBaseClient;
import com.pedro.rtmp.flv.video.ProfileIop;
import com.pedro.library.util.streamclient.RtmpStreamClient;
import com.pedro.library.util.streamclient.StreamClientListener;
import com.pedro.rtmp.rtmp.RtmpClient;
import com.pedro.rtmp.rtmp.VideoCodec;
import com.pedro.rtmp.utils.ConnectCheckerRtmp;
Expand All @@ -41,15 +39,15 @@
* Created by pedro on 9/08/17.
*/
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
public class RtmpDisplay extends DisplayBase {
public class RtmpDisplay extends DisplayBase implements StreamClientListener {

private final RtmpClient rtmpClient;
private final RtmpStreamClient streamClient;

public RtmpDisplay(Context context, boolean useOpengl, ConnectCheckerRtmp connectChecker) {
super(context, useOpengl);
rtmpClient = new RtmpClient(connectChecker);
streamClient = new RtmpStreamClient(rtmpClient);
streamClient = new RtmpStreamClient(rtmpClient, this);
}

public RtmpStreamClient getStreamClient() {
Expand Down Expand Up @@ -99,18 +97,8 @@ protected void getH264DataRtp(ByteBuffer h264Buffer, MediaCodec.BufferInfo info)
rtmpClient.sendVideo(h264Buffer, info);
}


/**
* Retries to connect with the given delay. You can pass an optional backupUrl
* if you'd like to connect to your backup server instead of the original one.
* Given backupUrl replaces the original one.
*/
public boolean reTry(long delay, String reason, @Nullable String backupUrl) {
boolean result = streamClient.shouldRetry(reason);
if (result) {
requestKeyFrame();
streamClient.reConnect(delay, backupUrl);
}
return result;
@Override
public void onRequestKeyframe() {
requestKeyFrame();
}
}
30 changes: 10 additions & 20 deletions library/src/main/java/com/pedro/library/rtmp/RtmpFromFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,16 @@
import android.media.MediaCodec;
import android.os.Build;

import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;

import com.pedro.encoder.input.decoder.AudioDecoderInterface;
import com.pedro.encoder.input.decoder.VideoDecoderInterface;
import com.pedro.encoder.utils.CodecUtil;
import com.pedro.library.base.FromFileBase;
import com.pedro.library.util.client.RtmpStreamClient;
import com.pedro.library.util.streamclient.RtmpStreamClient;
import com.pedro.library.util.streamclient.StreamClientListener;
import com.pedro.library.view.LightOpenGlView;
import com.pedro.library.view.OpenGlView;
import com.pedro.rtmp.flv.video.ProfileIop;
import com.pedro.rtmp.rtmp.RtmpClient;
import com.pedro.rtmp.rtmp.VideoCodec;
import com.pedro.rtmp.utils.ConnectCheckerRtmp;
Expand All @@ -44,7 +43,7 @@
* Created by pedro on 26/06/17.
*/
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR2)
public class RtmpFromFile extends FromFileBase {
public class RtmpFromFile extends FromFileBase implements StreamClientListener {

private final RtmpClient rtmpClient;
private final RtmpStreamClient streamClient;
Expand All @@ -53,28 +52,28 @@ public RtmpFromFile(ConnectCheckerRtmp connectChecker,
VideoDecoderInterface videoDecoderInterface, AudioDecoderInterface audioDecoderInterface) {
super(videoDecoderInterface, audioDecoderInterface);
rtmpClient = new RtmpClient(connectChecker);
streamClient = new RtmpStreamClient(rtmpClient);
streamClient = new RtmpStreamClient(rtmpClient, this);
}

public RtmpFromFile(Context context, ConnectCheckerRtmp connectChecker,
VideoDecoderInterface videoDecoderInterface, AudioDecoderInterface audioDecoderInterface) {
super(context, videoDecoderInterface, audioDecoderInterface);
rtmpClient = new RtmpClient(connectChecker);
streamClient = new RtmpStreamClient(rtmpClient);
streamClient = new RtmpStreamClient(rtmpClient, this);
}

public RtmpFromFile(OpenGlView openGlView, ConnectCheckerRtmp connectChecker,
VideoDecoderInterface videoDecoderInterface, AudioDecoderInterface audioDecoderInterface) {
super(openGlView, videoDecoderInterface, audioDecoderInterface);
rtmpClient = new RtmpClient(connectChecker);
streamClient = new RtmpStreamClient(rtmpClient);
streamClient = new RtmpStreamClient(rtmpClient, this);
}

public RtmpFromFile(LightOpenGlView lightOpenGlView, ConnectCheckerRtmp connectChecker,
VideoDecoderInterface videoDecoderInterface, AudioDecoderInterface audioDecoderInterface) {
super(lightOpenGlView, videoDecoderInterface, audioDecoderInterface);
rtmpClient = new RtmpClient(connectChecker);
streamClient = new RtmpStreamClient(rtmpClient);
streamClient = new RtmpStreamClient(rtmpClient, this);
}

public RtmpStreamClient getStreamClient() {
Expand Down Expand Up @@ -124,17 +123,8 @@ protected void getAacDataRtp(ByteBuffer aacBuffer, MediaCodec.BufferInfo info) {
rtmpClient.sendAudio(aacBuffer, info);
}

/**
* Retries to connect with the given delay. You can pass an optional backupUrl
* if you'd like to connect to your backup server instead of the original one.
* Given backupUrl replaces the original one.
*/
public boolean reTry(long delay, String reason, @Nullable String backupUrl) {
boolean result = streamClient.shouldRetry(reason);
if (result) {
requestKeyFrame();
streamClient.reConnect(delay, backupUrl);
}
return result;
@Override
public void onRequestKeyframe() {
requestKeyFrame();
}
}
Loading

0 comments on commit 8fec4e9

Please sign in to comment.