示例#1
0
 /**
  * Start waiting for a valid handshake.
  *
  * @param service The scheduling service to use
  */
 protected void startWaitForHandshake(ISchedulingService service) {
   getWriteLock().lock();
   try {
     waitForHandshakeService = service;
     waitForHandshakeJob =
         service.addScheduledOnceJob(maxHandshakeTimeout, new WaitForHandshakeJob());
   } finally {
     getWriteLock().unlock();
   }
 }
示例#2
0
 /**
  * Pull the next message from IMessageInput and schedule it for push according to the timestamp.
  */
 protected void scheduleNextMessage() {
   boolean first = (nextRTMPMessage == null);
   long delta = 0L;
   do {
     nextRTMPMessage = getNextRTMPMessage();
     if (nextRTMPMessage != null) {
       IRTMPEvent rtmpEvent = nextRTMPMessage.getBody();
       // filter all non-AV messages
       if (rtmpEvent instanceof VideoData || rtmpEvent instanceof AudioData) {
         rtmpEvent = nextRTMPMessage.getBody();
         nextTS = rtmpEvent.getTimestamp();
         if (first) {
           vodStartTS = nextTS;
           first = false;
         }
         delta = nextTS - vodStartTS - (System.currentTimeMillis() - serverStartTS);
         if (delta < WAIT_THRESHOLD) {
           if (doPushMessage()) {
             if (state != StreamState.PLAYING) {
               // Stream is not playing, don't load more messages
               nextRTMPMessage = null;
             }
           } else {
             nextRTMPMessage = null;
           }
         }
       }
     } else {
       onItemEnd();
     }
   } while (nextRTMPMessage != null || delta < WAIT_THRESHOLD);
   // start the job all over again
   vodJobName =
       scheduler.addScheduledOnceJob(
           delta,
           new IScheduledJob() {
             public void execute(ISchedulingService service) {
               if (vodJobName != null) {
                 vodJobName = null;
                 if (doPushMessage()) {
                   if (state == StreamState.PLAYING) {
                     scheduleNextMessage();
                   } else {
                     // Stream is paused, don't load more messages
                     nextRTMPMessage = null;
                   }
                 }
               }
             }
           });
 }
示例#3
0
 /**
  * Play a specific IPlayItem. The strategy for now is VOD first, Live second.
  *
  * @param item Item to play
  */
 protected void play(IPlayItem item) {
   // dont play unless we are stopped
   if (state == StreamState.STOPPED) {
     // assume this is not live stream
     boolean isLive = false;
     if (providerService != null) {
       msgIn = providerService.getVODProviderInput(getScope(), item.getName());
       if (msgIn == null) {
         msgIn = providerService.getLiveProviderInput(getScope(), item.getName(), true);
         isLive = true;
       }
       if (msgIn == null) {
         log.warn("ABNORMAL Can't get both VOD and Live input from providerService");
         return;
       }
     }
     setState(StreamState.PLAYING);
     currentItem = item;
     sendResetMessage();
     if (msgIn != null) {
       msgIn.subscribe(this, null);
     }
     if (isLive) {
       if (item.getLength() >= 0) {
         liveJobName =
             scheduler.addScheduledOnceJob(
                 item.getLength(),
                 new IScheduledJob() {
                   public void execute(ISchedulingService service) {
                     if (liveJobName == null) {
                       return;
                     }
                     liveJobName = null;
                     onItemEnd();
                   }
                 });
       }
     } else {
       long start = item.getStart();
       if (start < 0) {
         start = 0;
       }
       sendVODInitCM(msgIn, (int) start);
       startBroadcastVOD();
     }
   }
 }
示例#4
0
 /**
  * Start waiting for a valid handshake.
  *
  * @param service The scheduling service to use
  */
 protected void startWaitForHandshake(ISchedulingService service) {
   waitForHandshakeJob =
       service.addScheduledOnceJob(maxHandshakeTimeout, new WaitForHandshakeJob());
 }