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");
return false;
}
//need_flip ? -i420_rotated_frame.width : 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.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) {
x264_ctx.bitrate = bitrate / 1000; // kbps
x264_ctx.bitrate = bitrate / 1024; // kbps
}
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 mPreviewWidth;
private int mPreviewHeight;
private boolean mIsEncoding;
private volatile boolean mIsEncoding;
private boolean mIsTorchOn = false;
private float mInputAspectRatio;
private float mOutputAspectRatio;

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

Loading…
Cancel
Save