Use volatile flag for communication

Signed-off-by: begeekmyfriend <begeekmyfriend@gmail.com>
camera2
begeekmyfriend 8 years ago
parent 9a3984d463
commit 0984dd5907

@ -24,7 +24,7 @@ public class SrsFlvMuxer {
private static final int VIDEO_ALLOC_SIZE = 128 * 1024; private static final int VIDEO_ALLOC_SIZE = 128 * 1024;
private static final int AUDIO_ALLOC_SIZE = 4 * 1024; private static final int AUDIO_ALLOC_SIZE = 4 * 1024;
private volatile boolean connected = false; private volatile boolean started = false;
private DefaultRtmpPublisher publisher; private DefaultRtmpPublisher publisher;
private Thread worker; private Thread worker;
@ -95,14 +95,13 @@ public class SrsFlvMuxer {
} }
private boolean connect(String url) { private boolean connect(String url) {
if (!connected) { boolean connected = false;
Log.i(TAG, String.format("worker: connecting to RTMP server by url=%s\n", url)); Log.i(TAG, String.format("worker: connecting to RTMP server by url=%s\n", url));
if (publisher.connect(url)) { if (publisher.connect(url)) {
connected = publisher.publish("live"); connected = publisher.publish("live");
}
mVideoSequenceHeader = null;
mAudioSequenceHeader = null;
} }
mVideoSequenceHeader = null;
mAudioSequenceHeader = null;
return connected; return connected;
} }
@ -128,6 +127,7 @@ public class SrsFlvMuxer {
* start to the remote server for remux. * start to the remote server for remux.
*/ */
public void start(final String rtmpUrl) { public void start(final String rtmpUrl) {
started = true;
worker = new Thread(new Runnable() { worker = new Thread(new Runnable() {
@Override @Override
public void run() { public void run() {
@ -173,7 +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; started = false;
mFlvTagCache.clear(); mFlvTagCache.clear();
if (worker != null) { if (worker != null) {
worker.interrupt(); worker.interrupt();
@ -980,7 +980,7 @@ public class SrsFlvMuxer {
} }
private void flvTagCacheAdd(SrsFlvFrame frame) { private void flvTagCacheAdd(SrsFlvFrame frame) {
if (connected) { if (started) {
mFlvTagCache.add(frame); mFlvTagCache.add(frame);
if (frame.isVideo()) { if (frame.isVideo()) {
getVideoFrameCacheNumber().incrementAndGet(); getVideoFrameCacheNumber().incrementAndGet();

Loading…
Cancel
Save