Skip to content
Snippets Groups Projects
Commit fd27c36c authored by begeekmyfriend's avatar begeekmyfriend
Browse files

Use volatile variable for communication

parent d577b3dc
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -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,
Loading
Loading
@@ -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) {
Loading
Loading
Loading
Loading
@@ -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;
Loading
Loading
Loading
Loading
@@ -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();
Loading
Loading
@@ -48,7 +47,6 @@ public class SrsFlvMuxer {
* @param handler the rtmp event handler.
*/
public SrsFlvMuxer(RtmpHandler handler) {
mHandler = handler;
publisher = new DefaultRtmpPublisher(handler);
}
 
Loading
Loading
@@ -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.");
Loading
Loading
@@ -110,7 +107,7 @@ public class SrsFlvMuxer {
}
 
private void sendFlvTag(SrsFlvFrame frame) {
if (!connected || frame == null) {
if (frame == null) {
return;
}
 
Loading
Loading
@@ -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();
Loading
Loading
@@ -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() {
Loading
Loading
@@ -982,9 +981,11 @@ public class SrsFlvMuxer {
}
 
private void flvTagCacheAdd(SrsFlvFrame frame) {
mFlvTagCache.add(frame);
if (frame.isVideo()) {
getVideoFrameCacheNumber().incrementAndGet();
if (connected) {
mFlvTagCache.add(frame);
if (frame.isVideo()) {
getVideoFrameCacheNumber().incrementAndGet();
}
}
synchronized (txFrameLock) {
txFrameLock.notifyAll();
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