@@ -83,6 +83,10 @@ public final class PlayEngine implements IFilter, IPushableConsumer, IPipeConnec
8383
8484 private static final Logger log = Red5LoggerFactory .getLogger (PlayEngine .class );
8585
86+ private static boolean isDebug = log .isDebugEnabled ();
87+
88+ private static boolean isTrace = log .isTraceEnabled ();
89+
8690 private final AtomicReference <IMessageInput > msgInReference = new AtomicReference <>();
8791
8892 private final AtomicReference <IMessageOutput > msgOutReference = new AtomicReference <>();
@@ -280,7 +284,7 @@ void setMessageOut(IMessageOutput msgOut) {
280284 * Start stream
281285 */
282286 public void start () {
283- if (log . isDebugEnabled () ) {
287+ if (isDebug ) {
284288 log .debug ("start - subscriber stream state: {}" , (subscriberStream != null ? subscriberStream .getState () : null ));
285289 }
286290 switch (subscriberStream .getState ()) {
@@ -290,7 +294,7 @@ public void start() {
290294 IMessageOutput out = consumerService .getConsumerOutput (subscriberStream );
291295 if (msgOutReference .compareAndSet (null , out )) {
292296 out .subscribe (this , null );
293- } else if (log . isDebugEnabled () ) {
297+ } else if (isDebug ) {
294298 log .debug ("Message output was already set for stream: {}" , subscriberStream );
295299 }
296300 break ;
@@ -389,7 +393,7 @@ public void play(IPlayItem item, boolean withReset) throws StreamNotFoundExcepti
389393 IMessage msg = null ;
390394 currentItem .set (item );
391395 long itemLength = item .getLength ();
392- if (log . isDebugEnabled () ) {
396+ if (isDebug ) {
393397 log .debug ("Play decision is {} (0=Live, 1=File, 2=Wait, 3=N/A) item length: {}" , playDecision , itemLength );
394398 }
395399 switch (playDecision ) {
@@ -431,7 +435,7 @@ public void play(IPlayItem item, boolean withReset) throws StreamNotFoundExcepti
431435 in = providerService .getLiveProviderInput (thisScope , itemName , true );
432436 if (msgInReference .compareAndSet (null , in )) {
433437 if (type == -1 && itemLength >= 0 ) {
434- if (log . isDebugEnabled () ) {
438+ if (isDebug ) {
435439 log .debug ("Creating wait job for {}" , itemLength );
436440 }
437441 // Wait given timeout for stream to be published
@@ -443,7 +447,7 @@ public void execute(ISchedulingService service) {
443447 }
444448 });
445449 } else if (type == -2 ) {
446- if (log . isDebugEnabled () ) {
450+ if (isDebug ) {
447451 log .debug ("Creating wait job" );
448452 }
449453 // Wait x seconds for the stream to be published
@@ -456,7 +460,7 @@ public void execute(ISchedulingService service) {
456460 } else {
457461 connectToProvider (itemName );
458462 }
459- } else if (log . isDebugEnabled () ) {
463+ } else if (isDebug ) {
460464 log .debug ("Message input already set for {}" , itemName );
461465 }
462466 break ;
@@ -756,7 +760,7 @@ public void seek(int position) throws IllegalStateException, OperationNotSupport
756760 * If stream is in stopped state
757761 */
758762 public void stop () throws IllegalStateException {
759- if (log . isDebugEnabled () ) {
763+ if (isDebug ) {
760764 log .debug ("stop - subscriber stream state: {}" , (subscriberStream != null ? subscriberStream .getState () : null ));
761765 }
762766 // allow stop if playing or paused
@@ -805,7 +809,7 @@ public void stop() throws IllegalStateException {
805809 * Close stream
806810 */
807811 public void close () {
808- if (log . isDebugEnabled () ) {
812+ if (isDebug ) {
809813 log .debug ("close" );
810814 }
811815 if (!subscriberStream .getState ().equals (StreamState .CLOSED )) {
@@ -824,7 +828,7 @@ public void close() {
824828 if (out != null ) {
825829 List <IConsumer > consumers = out .getConsumers ();
826830 // assume a list of 1 in most cases
827- if (log . isDebugEnabled () ) {
831+ if (isDebug ) {
828832 log .debug ("Message out consumers: {}" , consumers .size ());
829833 }
830834 if (!consumers .isEmpty ()) {
@@ -965,7 +969,7 @@ private void doPushMessage(Status status) {
965969 * The message to send.
966970 */
967971 private void doPushMessage (AbstractMessage message ) {
968- if (log . isTraceEnabled () ) {
972+ if (isTrace ) {
969973 String msgType = message .getMessageType ();
970974 log .trace ("doPushMessage: {}" , msgType );
971975 }
@@ -1019,7 +1023,7 @@ private void sendMessage(RTMPMessage messageIn) {
10191023 event .setSourceType (eventIn .getSourceType ());
10201024 // instance the outgoing message
10211025 RTMPMessage messageOut = RTMPMessage .build (event , eventTime );
1022- if (log . isTraceEnabled () ) {
1026+ if (isTrace ) {
10231027 log .trace ("Source type - in: {} out: {}" , eventIn .getSourceType (), messageOut .getBody ().getSourceType ());
10241028 long delta = System .currentTimeMillis () - playbackStart ;
10251029 log .trace ("sendMessage: streamStartTS {}, length {}, streamOffset {}, timestamp {} last timestamp {} delta {} buffered {}" , new Object [] { streamStartTS .get (), currentItem .get ().getLength (), streamOffset , eventTime , lastMessageTs , delta , lastMessageTs - delta });
@@ -1032,7 +1036,7 @@ private void sendMessage(RTMPMessage messageIn) {
10321036 long length = currentItem .get ().getLength ();
10331037 if (length >= 0 ) {
10341038 int duration = eventTime - streamStartTS .get ();
1035- if (log . isTraceEnabled () ) {
1039+ if (isTrace ) {
10361040 log .trace ("sendMessage duration={} length={}" , duration , length );
10371041 }
10381042 if (duration - streamOffset >= length ) {
@@ -1052,7 +1056,7 @@ private void sendMessage(RTMPMessage messageIn) {
10521056 // subtract the offset time of when the stream started playing for the client
10531057 eventTime -= startTs ;
10541058 messageOut .getBody ().setTimestamp (eventTime );
1055- if (log . isTraceEnabled () ) {
1059+ if (isTrace ) {
10561060 log .trace ("sendMessage (updated): streamStartTS={}, length={}, streamOffset={}, timestamp={}" , new Object [] { startTs , currentItem .get ().getLength (), streamOffset , eventTime });
10571061 }
10581062 }
@@ -1150,7 +1154,7 @@ private void sendStopStatus(IPlayItem item) {
11501154 * @param bytes
11511155 */
11521156 private void sendOnPlayStatus (String code , int duration , long bytes ) {
1153- if (log . isDebugEnabled () ) {
1157+ if (isDebug ) {
11541158 log .debug ("Sending onPlayStatus - code: {} duration: {} bytes: {}" , code , duration , bytes );
11551159 }
11561160 // create the buffer
@@ -1204,7 +1208,7 @@ private void sendTransitionStatus() {
12041208 private void sendCompleteStatus () {
12051209 // may be the correct duration
12061210 int duration = (lastMessageTs > 0 ) ? Math .max (0 , lastMessageTs - streamStartTS .get ()) : 0 ;
1207- if (log . isDebugEnabled () ) {
1211+ if (isDebug ) {
12081212 log .debug ("sendCompleteStatus - duration: {} bytes sent: {}" , duration , bytesSent .get ());
12091213 }
12101214 sendOnPlayStatus (StatusCodes .NS_PLAY_COMPLETE , duration , bytesSent .get ());
@@ -1417,7 +1421,7 @@ public void onPipeConnectionEvent(PipeConnectionEvent event) {
14171421 }
14181422 break ;
14191423 default :
1420- if (log . isDebugEnabled () ) {
1424+ if (isDebug ) {
14211425 log .debug ("Unhandled pipe event: {}" , event );
14221426 }
14231427 }
@@ -1447,10 +1451,11 @@ public void pushMessage(IPipe pipe, IMessage message) throws IOException {
14471451 RTMPMessage rtmpMessage = (RTMPMessage ) message ;
14481452 IRTMPEvent body = rtmpMessage .getBody ();
14491453 if (body instanceof IStreamData ) {
1454+ final String subscribedStreamName = subscriberStream .getBroadcastStreamPublishName ();
14501455 // the subscriber paused
14511456 if (subscriberStream .getState () == StreamState .PAUSED ) {
14521457 if (log .isInfoEnabled () && shouldLogPacketDrop ()) {
1453- log .info ("Dropping packet because we are paused. sessionId={} stream={} count={}" , sessionId , subscriberStream . getBroadcastStreamPublishName () , droppedPacketsCount );
1458+ log .info ("Dropping packet because we are paused. sessionId={} stream={} count={}" , sessionId , subscribedStreamName , droppedPacketsCount );
14541459 }
14551460 videoFrameDropper .dropPacket (rtmpMessage );
14561461 return ;
@@ -1469,7 +1474,7 @@ public void pushMessage(IPipe pipe, IMessage message) throws IOException {
14691474 droppedPacketsCount ++;
14701475 if (log .isInfoEnabled () && shouldLogPacketDrop ()) {
14711476 // client disabled video or the app doesn't have enough bandwidth allowed for this stream
1472- log .info ("Drop packet. Failed to acquire token or no video. sessionId={} stream={} count={}" , sessionId , subscriberStream . getBroadcastStreamPublishName () , droppedPacketsCount );
1477+ log .info ("Drop packet. Failed to acquire token or no video. sessionId={} stream={} count={}" , sessionId , subscribedStreamName , droppedPacketsCount );
14731478 }
14741479 return ;
14751480 }
@@ -1480,14 +1485,14 @@ public void pushMessage(IPipe pipe, IMessage message) throws IOException {
14801485 // pending video messages and drop video packets until the queue is below the threshold.
14811486 // only check for frame dropping if the codec supports it
14821487 long pendingVideos = pendingVideoMessages ();
1483- if (log . isTraceEnabled () ) {
1484- log .trace ("Pending messages sessionId={} pending ={} threshold ={} sequential ={} stream ={}, count ={}" , new Object [] { sessionId , pendingVideos , maxPendingVideoFrames , numSequentialPendingVideoFrames , subscriberStream . getBroadcastStreamPublishName () , droppedPacketsCount });
1488+ if (isTrace ) {
1489+ log .trace ("Pending messages sessionId={} stream ={} pending ={} threshold ={} sequential ={} dropped ={}" , new Object [] { sessionId , subscribedStreamName , pendingVideos , maxPendingVideoFrames , numSequentialPendingVideoFrames , droppedPacketsCount });
14851490 }
14861491 if (!videoFrameDropper .canSendPacket (rtmpMessage , pendingVideos )) {
14871492 // drop frame as it depends on other frames that were dropped before
14881493 droppedPacketsCount ++;
14891494 if (log .isInfoEnabled () && shouldLogPacketDrop ()) {
1490- log .info ("Frame dropper says to drop packet. sessionId={} stream={} count ={}" , sessionId , subscriberStream . getBroadcastStreamPublishName () , droppedPacketsCount );
1495+ log .info ("Frame dropper says to drop packet. sessionId={} stream={} dropped ={}" , sessionId , subscribedStreamName , droppedPacketsCount );
14911496 }
14921497 return ;
14931498 }
@@ -1501,7 +1506,7 @@ public void pushMessage(IPipe pipe, IMessage message) throws IOException {
15011506 if (pendingVideos > maxPendingVideoFrames || numSequentialPendingVideoFrames > maxSequentialPendingVideoFrames ) {
15021507 droppedPacketsCount ++;
15031508 if (log .isInfoEnabled () && shouldLogPacketDrop ()) {
1504- log .info ("Drop packet. Pending above threshold. sessionId={} pending ={} threshold ={} sequential ={} stream ={} count ={}" , new Object [] { sessionId , pendingVideos , maxPendingVideoFrames , numSequentialPendingVideoFrames , subscriberStream . getBroadcastStreamPublishName () , droppedPacketsCount });
1509+ log .info ("Drop packet. Pending above threshold. sessionId={} stream ={} pending ={} threshold ={} sequential ={} dropped ={}" , new Object [] { sessionId , subscribedStreamName , pendingVideos , maxPendingVideoFrames , numSequentialPendingVideoFrames , droppedPacketsCount });
15051510 }
15061511 // drop because the client has insufficient bandwidth
15071512 long now = System .currentTimeMillis ();
@@ -1570,7 +1575,7 @@ private long pendingVideoMessages() {
15701575 return (Long ) pendingRequest .getResult ();
15711576 }
15721577 }
1573- return 0 ;
1578+ return 0L ;
15741579 }
15751580
15761581 /**
0 commit comments