Skip to content

Commit

Permalink
Patch underlying Android RTMP library to send more consistent key frames
Browse files Browse the repository at this point in the history
  • Loading branch information
derekbedwards committed Oct 25, 2019
1 parent 083a968 commit d8f31d5
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 18 deletions.
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@ repositories {

dependencies {
compile 'com.facebook.react:react-native:+'
implementation 'com.github.pedroSG94.rtmp-rtsp-stream-client-java:rtplibrary:1.6.7'
implementation 'com.github.behaviorcloud.rtmp-rtsp-stream-client-java:rtplibrary:1.7.3'
}
1 change: 1 addition & 0 deletions android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />
<uses-feature android:name="android.hardware.camera.level.full"/>
</manifest>

47 changes: 33 additions & 14 deletions android/src/main/java/com/pedrolibrary/RNBroadcastView.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,26 @@
import android.util.Log;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import com.pedro.rtplibrary.view.OpenGlView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;

import com.facebook.react.uimanager.ThemedReactContext;
import com.pedro.encoder.input.video.CameraOpenException;
import com.pedro.rtplibrary.rtmp.RtmpCamera2;
import com.pedro.rtplibrary.rtmp.RtmpCamera1;
import com.pedro.encoder.input.video.CameraHelper;
import net.ossrs.rtmp.ConnectCheckerRtmp;

import static com.facebook.react.common.ReactConstants.TAG;


public class RNBroadcastView extends FrameLayout implements
ConnectCheckerRtmp, SurfaceHolder.Callback {
private SurfaceView mCameraView;
// private SurfaceView mCameraView;
private OpenGlView mCameraView;
private ThemedReactContext mContext = null;
private RtmpCamera2 rtmpCamera2;
private RtmpCamera1 rtmpCamera1;
private Boolean isLive = false;
private Boolean surfaceExists = false;
private String streamUrl = "";
Expand All @@ -32,20 +35,22 @@ public RNBroadcastView(@NonNull ThemedReactContext context) {
// context.addLifecycleEventListener(this);
mContext = context;

mCameraView = new SurfaceView(context);
// mCameraView = new SurfaceView(context);
mCameraView = new OpenGlView(context);
mCameraView.setKeepAspectRatio(true);
mCameraView.getHolder().addCallback(this);

addView(mCameraView);

rtmpCamera2 = new RtmpCamera2(mCameraView, this);
rtmpCamera2.setReTries(10);
rtmpCamera1 = new RtmpCamera1(mCameraView, this);
rtmpCamera1.setReTries(10);

Log.d(TAG, "About to return from RNBroadcastView");
}

private void handleException(Exception e) {
try {
rtmpCamera2.stopStream();
rtmpCamera1.stopStream();
} catch (Exception e1) {
//
}
Expand Down Expand Up @@ -76,9 +81,21 @@ public void handleStopPublish() {

public void startStreaming() {
if (surfaceExists && !streamUrl.isEmpty()) {
if (rtmpCamera2.isRecording()
|| rtmpCamera2.prepareAudio() && rtmpCamera2.prepareVideo()) {
rtmpCamera2.startStream(streamUrl);
boolean hardwareRotation = true;
try {
rtmpCamera1.getGlInterface();
}
catch (Exception e) {
hardwareRotation = false;
}

int cameraOrientation = CameraHelper.getCameraOrientation(getContext()),
captureWidth = 640,
captureHeight = 480;

if (rtmpCamera1.isRecording()
|| rtmpCamera1.prepareAudio() && rtmpCamera1.prepareVideo(captureWidth, captureHeight, 30, 600*1024, hardwareRotation, 1, cameraOrientation)) {
rtmpCamera1.startStream(streamUrl);
isLive = true;
} else {
// Toast.makeText(this, "Error preparing stream, This device cant do it",
Expand All @@ -89,7 +106,7 @@ public void startStreaming() {
}

public void stopStreaming() {
rtmpCamera2.stopStream();
rtmpCamera1.stopStream();
isLive = false;
}

Expand Down Expand Up @@ -185,15 +202,17 @@ public void surfaceCreated(SurfaceHolder surfaceHolder) {
@Override
public void surfaceChanged(SurfaceHolder surfaceHolder, int i, int i1, int i2) {
Log.d(TAG, "SurfaceChanged");
rtmpCamera2.startPreview();
rtmpCamera1.startPreview();
int cameraOrientation = CameraHelper.getCameraOrientation(getContext());
rtmpCamera1.setPreviewOrientation(cameraOrientation);
}

@Override
public void surfaceDestroyed(SurfaceHolder surfaceHolder) {
surfaceExists = false;
if (rtmpCamera2.isStreaming()) {
if (rtmpCamera1.isStreaming()) {
stopStreaming();
}
rtmpCamera2.stopPreview();
rtmpCamera1.stopPreview();
}
}
4 changes: 2 additions & 2 deletions ios/RNBroadcast/LFLivePreview.m
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ - (LFLiveSession*)session {
videoConfiguration.videoBitRate = 800*1024;
videoConfiguration.videoMaxBitRate = 1000*1024;
videoConfiguration.videoMinBitRate = 500*1024;
videoConfiguration.videoFrameRate = 24;
videoConfiguration.videoMaxKeyframeInterval = 48;
videoConfiguration.videoFrameRate = 30;
videoConfiguration.videoMaxKeyframeInterval = 30;
videoConfiguration.outputImageOrientation = UIInterfaceOrientationLandscapeRight;
videoConfiguration.autorotate = YES;
videoConfiguration.sessionPreset = LFCaptureSessionPreset720x1280;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

{
"name": "react-native-broadcast",
"version": "1.0.9",
"version": "1.0.10",
"description": "RTMP Broadcaster library for React Native",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit d8f31d5

Please sign in to comment.