CC-4321: NowPlaying: Cancelling Webstream has no effect and results in OnAir being grayed out

-fixed
This commit is contained in:
Martin Konecny 2012-08-31 12:18:37 -04:00
parent 79b6d13c16
commit c043053407
3 changed files with 43 additions and 32 deletions

View File

@ -14,11 +14,8 @@ class Application_Model_Schedule
$sql = "SELECT COUNT(*) FROM ".$CC_CONFIG["scheduleTable"] $sql = "SELECT COUNT(*) FROM ".$CC_CONFIG["scheduleTable"]
." WHERE file_id = {$p_fileId} AND ends > NOW() AT TIME ZONE 'UTC'"; ." WHERE file_id = {$p_fileId} AND ends > NOW() AT TIME ZONE 'UTC'";
$count = $con->query($sql)->fetchColumn(0); $count = $con->query($sql)->fetchColumn(0);
if (is_numeric($count) && ($count != '0')) {
return TRUE; return (is_numeric($count) && ($count != '0'));
} else {
return FALSE;
}
} }
/** /**

View File

@ -24,7 +24,11 @@ class Application_Model_Scheduler
{ {
$this->con = Propel::getConnection(CcSchedulePeer::DATABASE_NAME); $this->con = Propel::getConnection(CcSchedulePeer::DATABASE_NAME);
$this->epochNow = microtime(true); //subtracting one because sometimes when we cancel a track, we set its end time
//to epochNow and then send the new schedule to pypo. Sometimes the currently cancelled
//track can still be included in the new schedule because it may have a few ms left to play.
//subtracting 1 second from epochNow resolves this issue.
$this->epochNow = microtime(true)-1;
$this->nowDT = DateTime::createFromFormat("U.u", $this->epochNow, new DateTimeZone("UTC")); $this->nowDT = DateTime::createFromFormat("U.u", $this->epochNow, new DateTimeZone("UTC"));
if ($this->nowDT === false) { if ($this->nowDT === false) {
@ -324,6 +328,8 @@ class Application_Model_Scheduler
* @param int $showInstance * @param int $showInstance
* @param array $exclude * @param array $exclude
* ids of sched items to remove from the calulation. * ids of sched items to remove from the calulation.
* This function squeezes all items of a show together so that
* there are no gaps between them.
*/ */
private function removeGaps($showInstance, $exclude=null) private function removeGaps($showInstance, $exclude=null)
{ {
@ -665,7 +671,7 @@ class Application_Model_Scheduler
//playing. //playing.
$removedItem->setDbCueOut($cueout) $removedItem->setDbCueOut($cueout)
->setDbClipLength($cliplength) ->setDbClipLength($cliplength)
->setDbEnds($this->nowDT->sub(new DateInteval("PT1S"))) ->setDbEnds($this->nowDT)
->save($this->con); ->save($this->con);
} else { } else {
$removedItem->delete($this->con); $removedItem->delete($this->con);

View File

@ -81,27 +81,29 @@ class PypoPush(Thread):
chains.remove(original_chain) chains.remove(original_chain)
except ValueError, e: except ValueError, e:
self.logger.error(str(e)) self.logger.error(str(e))
if len(liquidsoap_queue_approx) == 0 and current_event_chain[0]['type'] == 'file':
#Something is scheduled but Liquidsoap is not playing anything! if len(liquidsoap_queue_approx) == 0 and not self.current_stream_info:
#Need to schedule it immediately..this might happen if Liquidsoap crashed. #Nothing is currently being playing by Liquidsoap
self.modify_cue_point(current_event_chain[0]) if current_event_chain[0]['type'] == 'file':
next_media_item_chain = current_event_chain #Something is scheduled but Liquidsoap is not playing anything!
time_until_next_play = 0 #Need to schedule it immediately..this might happen if Liquidsoap crashed.
#sleep for 0.2 seconds to give pypo-file time to copy. self.modify_cue_point(current_event_chain[0])
time.sleep(0.2) next_media_item_chain = current_event_chain
continue time_until_next_play = 0
if not self.current_stream_info and current_event_chain[0]['type'] == 'stream': #sleep for 0.2 seconds to give pypo-file time to copy.
#a stream is schedule but Liquidsoap is not playing it. Need to start it. time.sleep(0.2)
next_media_item_chain = current_event_chain continue
time_until_next_play = 0 if current_event_chain[0]['type'] == 'stream':
continue #a stream is schedule but Liquidsoap is not playing it. Need to start it.
next_media_item_chain = current_event_chain
time_until_next_play = 0
continue
#At this point we know that Liquidsoap is playing something, and that something #At this point we know that Liquidsoap is playing something, and that something
#is scheduled. We need to verify whether the schedule we just received matches #is scheduled. We need to verify whether the schedule we just received matches
#what Liquidsoap is playing, and if not, correct it. #what Liquidsoap is playing, and if not, correct it.
media_chain = filter(lambda item: (item["type"] == "file"), current_event_chain)
stream_chain = filter(lambda item: (item["type"] == "stream"), current_event_chain) self.handle_new_schedule(media_schedule, liquidsoap_queue_approx, current_event_chain)
self.handle_new_schedule(media_schedule, liquidsoap_queue_approx, media_chain, stream_chain)
#At this point everything in the present has been taken care of and Liquidsoap #At this point everything in the present has been taken care of and Liquidsoap
@ -184,7 +186,7 @@ class PypoPush(Thread):
return liquidsoap_queue_approx return liquidsoap_queue_approx
def handle_new_schedule(self, media_schedule, liquidsoap_queue_approx, media_chain, stream_chain): def handle_new_schedule(self, media_schedule, liquidsoap_queue_approx, current_event_chain):
""" """
This function's purpose is to gracefully handle situations where This function's purpose is to gracefully handle situations where
Liquidsoap already has a track in its queue, but the schedule Liquidsoap already has a track in its queue, but the schedule
@ -192,18 +194,24 @@ class PypoPush(Thread):
call other functions that will connect to Liquidsoap and alter its call other functions that will connect to Liquidsoap and alter its
queue. queue.
""" """
media_chain = filter(lambda item: (item["type"] == "file"), current_event_chain)
stream_chain = filter(lambda item: (item["type"] == "stream"), current_event_chain)
self.logger.debug(self.current_stream_info)
self.logger.debug(current_event_chain)
if self.current_stream_info: if self.current_stream_info:
if len(stream_chain) == 0: if current_event_chain[0]['type'] == "stream":
if self.current_stream_info['uri'] != stream_chain[0]['uri']:
#Liquidsoap is rebroadcasting a webstream and a webstream is scheduled
#to play, but they are not the same!
self.stop_web_stream(self.current_stream_info)
self.start_web_stream(stream_chain[0])
else:
#Liquidsoap is rebroadcasting a webstream, but there is no stream #Liquidsoap is rebroadcasting a webstream, but there is no stream
#in the schedule. Let's stop streaming. #in the schedule. Let's stop streaming.
self.stop_web_stream(self.current_stream_info) self.stop_web_stream(self.current_stream_info)
elif self.current_stream_info['uri'] != stream_chain[0]['uri']:
#Liquidsoap is rebroadcasting a webstream and a webstream is scheduled
#to play, but they are not the same!
self.stop_web_stream(self.current_stream_info)
self.start_web_stream(stream_chain[0])
problem_at_iteration = self.find_removed_items(media_schedule, liquidsoap_queue_approx) problem_at_iteration = self.find_removed_items(media_schedule, liquidsoap_queue_approx)