Skip to content
Snippets Groups Projects
Commit 4c572237 authored by Leo Ma's avatar Leo Ma
Browse files

Separate publishing control from camera preview


Signed-off-by: default avatarLeo Ma <begeekmyfriend@gmail.com>
parent d49144ae
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -72,6 +72,8 @@ public class MainActivity extends AppCompatActivity implements RtmpHandler.RtmpL
mPublisher.setRtmpHandler(new RtmpHandler(this));
mPublisher.setRecordHandler(new SrsRecordHandler(this));
mPublisher.setPreviewResolution(640, 480);
mPublisher.setOutputResolution(720, 1280);
mPublisher.setVideoHDMode();
 
btnPublish.setOnClickListener(new View.OnClickListener() {
@Override
Loading
Loading
@@ -82,8 +84,7 @@ public class MainActivity extends AppCompatActivity implements RtmpHandler.RtmpL
editor.putString("rtmpUrl", rtmpUrl);
editor.apply();
 
mPublisher.setOutputResolution(720, 1280);
mPublisher.setVideoHDMode();
mPublisher.startCamera();
mPublisher.startPublish(rtmpUrl);
 
if (btnSwitchEncoder.getText().toString().contentEquals("soft encoder")) {
Loading
Loading
Loading
Loading
@@ -215,7 +215,7 @@ public class SrsCameraView extends GLSurfaceView implements GLSurfaceView.Render
return mCamId;
}
 
public boolean startCamera() {
public void enableEncoding() {
worker = new Thread(new Runnable() {
@Override
public void run() {
Loading
Loading
@@ -238,7 +238,23 @@ public class SrsCameraView extends GLSurfaceView implements GLSurfaceView.Render
}
});
worker.start();
}
 
public void disableEncoding() {
if (worker != null) {
worker.interrupt();
try {
worker.join();
} catch (InterruptedException e) {
e.printStackTrace();
worker.interrupt();
}
mGLIntBufferCache.clear();
worker = null;
}
}
public boolean startCamera() {
if (mCamera == null) {
mCamera = openCamera();
if (mCamera == null) {
Loading
Loading
@@ -283,17 +299,7 @@ public class SrsCameraView extends GLSurfaceView implements GLSurfaceView.Render
}
 
public void stopCamera() {
if (worker != null) {
worker.interrupt();
try {
worker.join();
} catch (InterruptedException e) {
e.printStackTrace();
worker.interrupt();
}
mGLIntBufferCache.clear();
worker = null;
}
disableEncoding();
 
if (mCamera != null) {
mCamera.stopPreview();
Loading
Loading
Loading
Loading
@@ -61,6 +61,14 @@ public class SrsPublisher {
}
}
public void startCamera() {
mCameraView.startCamera();
}
public void stopCamera() {
mCameraView.stopCamera();
}
public void startEncode() {
if (!mEncoder.start()) {
return;
Loading
Loading
@@ -85,10 +93,7 @@ public class SrsPublisher {
}
}
if (!mCameraView.startCamera()) {
mEncoder.stop();
return;
}
mCameraView.enableEncoding();
aworker = new Thread(new Runnable() {
@Override
Loading
Loading
@@ -103,7 +108,7 @@ public class SrsPublisher {
public void stopEncode() {
stopAudio();
mCameraView.stopCamera();
stopCamera();
mEncoder.stop();
}
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment