Separate publishing control from camera preview

Signed-off-by: Leo Ma <begeekmyfriend@gmail.com>
camera2
Leo Ma 9 years ago
parent d49144ae53
commit 4c57223703

@ -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
@ -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")) {

@ -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() {
@ -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) {
@ -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();

@ -61,6 +61,14 @@ public class SrsPublisher {
}
}
public void startCamera() {
mCameraView.startCamera();
}
public void stopCamera() {
mCameraView.stopCamera();
}
public void startEncode() {
if (!mEncoder.start()) {
return;
@ -85,10 +93,7 @@ public class SrsPublisher {
}
}
if (!mCameraView.startCamera()) {
mEncoder.stop();
return;
}
mCameraView.enableEncoding();
aworker = new Thread(new Runnable() {
@Override
@ -103,7 +108,7 @@ public class SrsPublisher {
public void stopEncode() {
stopAudio();
mCameraView.stopCamera();
stopCamera();
mEncoder.stop();
}

Loading…
Cancel
Save