|
|
|
@ -29,7 +29,10 @@ public class RtspSurfaceRender2 implements RtspHelper.RtspCallback {
|
|
|
|
|
private final Object mBitmapLock = new Object();
|
|
|
|
|
private Bitmap mVideoBitmap = null;
|
|
|
|
|
private volatile boolean mIsResumed = false;
|
|
|
|
|
private volatile boolean mRecording = false;
|
|
|
|
|
|
|
|
|
|
private IFrameCallBack mFrameCallBack = null;
|
|
|
|
|
|
|
|
|
|
private int mWidth, mheight;
|
|
|
|
|
|
|
|
|
|
// mSurfaceView 渲染线程
|
|
|
|
|
Thread renderThread = new Thread(new Runnable() {
|
|
|
|
@ -67,6 +70,8 @@ public class RtspSurfaceRender2 implements RtspHelper.RtspCallback {
|
|
|
|
|
@Override
|
|
|
|
|
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
|
|
|
|
|
LogUtils.v(String.format("onSurfaceChanged: width = %d, height = %d", width, height));
|
|
|
|
|
mWidth = width;
|
|
|
|
|
mheight = height;
|
|
|
|
|
if (mVideoEncoder == null) {
|
|
|
|
|
LogUtils.v("init");
|
|
|
|
|
mVideoEncoder = new MovieEncoder1(mSurfaceView.getContext(), width, height);
|
|
|
|
@ -82,6 +87,10 @@ public class RtspSurfaceRender2 implements RtspHelper.RtspCallback {
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void reStart(){
|
|
|
|
|
RtspHelper.getInstance().createPlayer(mRtspUrl, mWidth, mheight, RtspSurfaceRender2.this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setRtspUrl(String url) {
|
|
|
|
|
mRtspUrl = url;
|
|
|
|
|
}
|
|
|
|
@ -90,7 +99,6 @@ public class RtspSurfaceRender2 implements RtspHelper.RtspCallback {
|
|
|
|
|
mSurfaceView.post(() -> {
|
|
|
|
|
if (!mVideoEncoder.isRecording()) {
|
|
|
|
|
mVideoEncoder.startRecording(new BaseMovieEncoder.EncoderConfig(EGL14.eglGetCurrentContext()));
|
|
|
|
|
mRecording = true;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
@ -99,7 +107,6 @@ public class RtspSurfaceRender2 implements RtspHelper.RtspCallback {
|
|
|
|
|
mSurfaceView.post(() -> {
|
|
|
|
|
if (mVideoEncoder.isRecording()) {
|
|
|
|
|
mVideoEncoder.stopRecording();
|
|
|
|
|
mRecording = false;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
@ -111,6 +118,9 @@ public class RtspSurfaceRender2 implements RtspHelper.RtspCallback {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onPreviewFrame(final ByteBuffer buffer, int width, int height) {
|
|
|
|
|
if (mFrameCallBack != null){
|
|
|
|
|
mFrameCallBack.onFrame();
|
|
|
|
|
}
|
|
|
|
|
synchronized (mBitmapLock) {
|
|
|
|
|
Bitmap overLayBitmap = TxtOverlay.INSTANCE.getOverlayBitmap();
|
|
|
|
|
mVideoBitmap.copyPixelsFromBuffer(buffer.position(0));
|
|
|
|
@ -130,4 +140,8 @@ public class RtspSurfaceRender2 implements RtspHelper.RtspCallback {
|
|
|
|
|
public void onPause() {
|
|
|
|
|
this.mIsResumed = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setFrameCallBack(IFrameCallBack mFrameCallBack) {
|
|
|
|
|
this.mFrameCallBack = mFrameCallBack;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|