21
21
import java .io .IOException ;
22
22
import java .lang .ref .WeakReference ;
23
23
import java .util .Collection ;
24
+ import java .util .EnumSet ;
24
25
import java .util .HashMap ;
25
26
import java .util .Map ;
26
27
import java .util .concurrent .CopyOnWriteArrayList ;
@@ -77,6 +78,8 @@ public class ServerStream extends AbstractStream implements IServerStream, IFilt
77
78
78
79
private static final long WAIT_THRESHOLD = 0 ;
79
80
81
+ private static EnumSet <StreamState > PLAYING_OR_PAUSED = EnumSet .of (StreamState .PLAYING , StreamState .PAUSED );
82
+
80
83
/**
81
84
* Stream published name
82
85
*/
@@ -424,7 +427,7 @@ public void setPublishedName(String name) {
424
427
* Start this server-side stream
425
428
*/
426
429
public void start () {
427
- if (state != StreamState .UNINIT ) {
430
+ if (state . get () != StreamState .UNINIT ) {
428
431
throw new IllegalStateException ("State " + state + " not valid to start" );
429
432
}
430
433
if (items .size () == 0 ) {
@@ -452,7 +455,7 @@ public void start() {
452
455
* Stop this server-side stream
453
456
*/
454
457
public void stop () {
455
- if (state == StreamState . PLAYING || state == StreamState . PAUSED ) {
458
+ if (PLAYING_OR_PAUSED . contains ( state . get ()) ) {
456
459
if (liveJobName != null ) {
457
460
scheduler .removeScheduledJob (liveJobName );
458
461
liveJobName = null ;
@@ -493,7 +496,7 @@ public void stopRecording() {
493
496
/** {@inheritDoc} */
494
497
@ SuppressWarnings ("incomplete-switch" )
495
498
public void pause () {
496
- switch (state ) {
499
+ switch (state . get () ) {
497
500
case PLAYING :
498
501
setState (StreamState .PAUSED );
499
502
break ;
@@ -508,14 +511,14 @@ public void pause() {
508
511
/** {@inheritDoc} */
509
512
public void seek (int position ) {
510
513
// seek only allowed when playing or paused
511
- if (state == StreamState . PLAYING || state == StreamState . PAUSED ) {
514
+ if (PLAYING_OR_PAUSED . contains ( state . get ()) ) {
512
515
sendVODSeekCM (msgIn , position );
513
516
}
514
517
}
515
518
516
519
/** {@inheritDoc} */
517
520
public void close () {
518
- if (state == StreamState . PLAYING || state == StreamState . PAUSED ) {
521
+ if (PLAYING_OR_PAUSED . contains ( state . get ()) ) {
519
522
stop ();
520
523
}
521
524
if (msgOut != null ) {
@@ -567,7 +570,7 @@ public void onPipeConnectionEvent(PipeConnectionEvent event) {
567
570
*/
568
571
protected void play (IPlayItem item ) {
569
572
// dont play unless we are stopped
570
- if (state == StreamState .STOPPED ) {
573
+ if (state . get () == StreamState .STOPPED ) {
571
574
// assume this is not live stream
572
575
boolean isLive = false ;
573
576
if (providerService != null ) {
@@ -738,7 +741,7 @@ protected void scheduleNextMessage() {
738
741
delta = nextTS - vodStartTS - (System .currentTimeMillis () - serverStartTS );
739
742
if (delta < WAIT_THRESHOLD ) {
740
743
if (doPushMessage ()) {
741
- if (state != StreamState .PLAYING ) {
744
+ if (state . get () != StreamState .PLAYING ) {
742
745
// Stream is not playing, don't load more messages
743
746
nextRTMPMessage = null ;
744
747
}
@@ -757,7 +760,7 @@ public void execute(ISchedulingService service) {
757
760
if (vodJobName != null ) {
758
761
vodJobName = null ;
759
762
if (doPushMessage ()) {
760
- if (state == StreamState .PLAYING ) {
763
+ if (state . get () == StreamState .PLAYING ) {
761
764
scheduleNextMessage ();
762
765
} else {
763
766
// Stream is paused, don't load more messages
0 commit comments