Use volatile variable for communication

Signed-off-by: begeekmyfriend <begeekmyfriend@gmail.com>
camera2
begeekmyfriend 8 years ago
parent d577b3dc45
commit fd27c36c4f

@ -156,7 +156,7 @@ static bool convert_to_i420_with_crop_scale(uint8_t *src_frame, jint src_width,
LIBENC_LOGE("ConvertToI420 failure"); LIBENC_LOGE("ConvertToI420 failure");
return false; return false;
} }
//need_flip ? -i420_rotated_frame.width : i420_rotated_frame.width
ret = I420Scale(i420_rotated_frame.y, i420_rotated_frame.width, ret = I420Scale(i420_rotated_frame.y, i420_rotated_frame.width,
i420_rotated_frame.u, i420_rotated_frame.width / 2, i420_rotated_frame.u, i420_rotated_frame.width / 2,
i420_rotated_frame.v, i420_rotated_frame.width / 2, i420_rotated_frame.v, i420_rotated_frame.width / 2,
@ -176,7 +176,7 @@ static bool convert_to_i420_with_crop_scale(uint8_t *src_frame, jint src_width,
} }
static void libenc_setEncoderBitrate(JNIEnv *env, jobject thiz, jint bitrate) { static void libenc_setEncoderBitrate(JNIEnv *env, jobject thiz, jint bitrate) {
x264_ctx.bitrate = bitrate / 1000; // kbps x264_ctx.bitrate = bitrate / 1024; // kbps
} }
static void libenc_setEncoderFps(JNIEnv *env, jobject thiz, jint fps) { static void libenc_setEncoderFps(JNIEnv *env, jobject thiz, jint fps) {

@ -36,7 +36,7 @@ public class SrsCameraView extends GLSurfaceView implements GLSurfaceView.Render
private int mSurfaceHeight; private int mSurfaceHeight;
private int mPreviewWidth; private int mPreviewWidth;
private int mPreviewHeight; private int mPreviewHeight;
private boolean mIsEncoding; private volatile boolean mIsEncoding;
private boolean mIsTorchOn = false; private boolean mIsTorchOn = false;
private float mInputAspectRatio; private float mInputAspectRatio;
private float mOutputAspectRatio; private float mOutputAspectRatio;

@ -26,7 +26,6 @@ public class SrsFlvMuxer {
private volatile boolean connected = false; private volatile boolean connected = false;
private DefaultRtmpPublisher publisher; private DefaultRtmpPublisher publisher;
private RtmpHandler mHandler;
private Thread worker; private Thread worker;
private final Object txFrameLock = new Object(); private final Object txFrameLock = new Object();
@ -48,7 +47,6 @@ public class SrsFlvMuxer {
* @param handler the rtmp event handler. * @param handler the rtmp event handler.
*/ */
public SrsFlvMuxer(RtmpHandler handler) { public SrsFlvMuxer(RtmpHandler handler) {
mHandler = handler;
publisher = new DefaultRtmpPublisher(handler); publisher = new DefaultRtmpPublisher(handler);
} }
@ -91,7 +89,6 @@ public class SrsFlvMuxer {
} catch (IllegalStateException e) { } catch (IllegalStateException e) {
// Ignore illegal state. // Ignore illegal state.
} }
connected = false;
mVideoSequenceHeader = null; mVideoSequenceHeader = null;
mAudioSequenceHeader = null; mAudioSequenceHeader = null;
Log.i(TAG, "worker: disconnect ok."); Log.i(TAG, "worker: disconnect ok.");
@ -110,7 +107,7 @@ public class SrsFlvMuxer {
} }
private void sendFlvTag(SrsFlvFrame frame) { private void sendFlvTag(SrsFlvFrame frame) {
if (!connected || frame == null) { if (frame == null) {
return; return;
} }
@ -176,6 +173,7 @@ public class SrsFlvMuxer {
* stop the muxer, disconnect RTMP connection. * stop the muxer, disconnect RTMP connection.
*/ */
public void stop() { public void stop() {
connected = false;
mFlvTagCache.clear(); mFlvTagCache.clear();
if (worker != null) { if (worker != null) {
worker.interrupt(); worker.interrupt();
@ -189,8 +187,9 @@ public class SrsFlvMuxer {
} }
flv.reset(); flv.reset();
needToFindKeyFrame = true; needToFindKeyFrame = true;
disconnect();
Log.i(TAG, "SrsFlvMuxer closed"); Log.i(TAG, "SrsFlvMuxer closed");
// We should not block the main thread
new Thread(new Runnable() { new Thread(new Runnable() {
@Override @Override
public void run() { public void run() {
@ -982,10 +981,12 @@ public class SrsFlvMuxer {
} }
private void flvTagCacheAdd(SrsFlvFrame frame) { private void flvTagCacheAdd(SrsFlvFrame frame) {
if (connected) {
mFlvTagCache.add(frame); mFlvTagCache.add(frame);
if (frame.isVideo()) { if (frame.isVideo()) {
getVideoFrameCacheNumber().incrementAndGet(); getVideoFrameCacheNumber().incrementAndGet();
} }
}
synchronized (txFrameLock) { synchronized (txFrameLock) {
txFrameLock.notifyAll(); txFrameLock.notifyAll();
} }

Loading…
Cancel
Save