Merge branch 'fix/live-stream-source' of https://github.com/Robbt/libretime into Robbt-fix/live-stream-source
This commit is contained in:
commit
e873e0d8da
|
@ -262,6 +262,41 @@ class PreferenceController extends Zend_Controller_Action
|
||||||
//Application_Model_RabbitMq::PushSchedule();
|
//Application_Model_RabbitMq::PushSchedule();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// pulling this from the 2.5.x branch
|
||||||
|
if (!Application_Model_Preference::GetMasterDjConnectionUrlOverride()) {
|
||||||
|
$master_connection_url = "http://".$_SERVER['SERVER_NAME'].":".$values["master_source_port"].$values["master_source_mount"];
|
||||||
|
if (empty($values["master_source_port"]) || empty($values["master_source_port"])) {
|
||||||
|
Application_Model_Preference::SetMasterDJSourceConnectionURL('N/A');
|
||||||
|
} else {
|
||||||
|
Application_Model_Preference::SetMasterDJSourceConnectionURL($master_connection_url);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Application_Model_Preference::SetMasterDJSourceConnectionURL($values["master_source_host"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!Application_Model_Preference::GetLiveDjConnectionUrlOverride()) {
|
||||||
|
$live_connection_url = "http://".$_SERVER['SERVER_NAME'].":".$values["show_source_port"].$values["show_source_mount"];
|
||||||
|
if (empty($values["show_source_port"]) || empty($values["show_source_mount"])) {
|
||||||
|
Application_Model_Preference::SetLiveDJSourceConnectionURL('N/A');
|
||||||
|
} else {
|
||||||
|
Application_Model_Preference::SetLiveDJSourceConnectionURL($live_connection_url);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Application_Model_Preference::SetLiveDJSourceConnectionURL($values["show_source_host"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Application_Model_StreamSetting::setMasterLiveStreamPort($values["master_source_port"]);
|
||||||
|
Application_Model_StreamSetting::setMasterLiveStreamMountPoint($values["master_source_mount"]);
|
||||||
|
Application_Model_StreamSetting::setDjLiveStreamPort($values["show_source_port"]);
|
||||||
|
Application_Model_StreamSetting::setDjLiveStreamMountPoint($values["show_source_mount"]);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Application_Model_StreamSetting::setOffAirMeta($values['offAirMeta']);
|
Application_Model_StreamSetting::setOffAirMeta($values['offAirMeta']);
|
||||||
|
|
||||||
// store stream update timestamp
|
// store stream update timestamp
|
||||||
|
@ -355,6 +390,7 @@ class PreferenceController extends Zend_Controller_Action
|
||||||
Application_Model_Preference::SetDefaultTransitionFade($values["transition_fade"]);
|
Application_Model_Preference::SetDefaultTransitionFade($values["transition_fade"]);
|
||||||
Application_Model_Preference::SetAutoTransition($values["auto_transition"]);
|
Application_Model_Preference::SetAutoTransition($values["auto_transition"]);
|
||||||
Application_Model_Preference::SetAutoSwitch($values["auto_switch"]);
|
Application_Model_Preference::SetAutoSwitch($values["auto_switch"]);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function serverBrowseAction()
|
public function serverBrowseAction()
|
||||||
|
|
|
@ -7,6 +7,7 @@ class Application_Form_LiveStreamingPreferences extends Zend_Form_SubForm
|
||||||
{
|
{
|
||||||
$CC_CONFIG = Config::getConfig();
|
$CC_CONFIG = Config::getConfig();
|
||||||
$isDemo = isset($CC_CONFIG['demo']) && $CC_CONFIG['demo'] == 1;
|
$isDemo = isset($CC_CONFIG['demo']) && $CC_CONFIG['demo'] == 1;
|
||||||
|
$isStreamConfigable = Application_Model_Preference::GetEnableStreamConf() == "true";
|
||||||
|
|
||||||
$defaultFade = Application_Model_Preference::GetDefaultTransitionFade();
|
$defaultFade = Application_Model_Preference::GetDefaultTransitionFade();
|
||||||
|
|
||||||
|
@ -63,42 +64,54 @@ class Application_Form_LiveStreamingPreferences extends Zend_Form_SubForm
|
||||||
|
|
||||||
// Master source connection url parameters
|
// Master source connection url parameters
|
||||||
$masterSourceHost = new Zend_Form_Element_Text('master_source_host');
|
$masterSourceHost = new Zend_Form_Element_Text('master_source_host');
|
||||||
$masterSourceHost->setAttrib('readonly', true)
|
$masterSourceHost->setLabel(_('Host:'))
|
||||||
->setLabel(_('Host:'))
|
->setAttrib('readonly', true)
|
||||||
->setValue(isset($masterSourceParams["host"])?$masterSourceParams["host"]:"");
|
->setValue(Application_Model_Preference::GetMasterDJSourceConnectionURL());
|
||||||
$this->addElement($masterSourceHost);
|
$this->addElement($masterSourceHost);
|
||||||
|
|
||||||
|
//liquidsoap harbor.input port
|
||||||
|
$betweenValidator = Application_Form_Helper_ValidationTypes::overrideBetweenValidator(1024, 49151);
|
||||||
|
$m_port = Application_Model_StreamSetting::getMasterLiveStreamPort();
|
||||||
$masterSourcePort = new Zend_Form_Element_Text('master_source_port');
|
$masterSourcePort = new Zend_Form_Element_Text('master_source_port');
|
||||||
$masterSourcePort->setAttrib('readonly', true)
|
$masterSourcePort->setLabel(_('Master Source Port:'))
|
||||||
->setLabel(_('Port:'))
|
->setValue($m_port)
|
||||||
->setValue(isset($masterSourceParams["port"])?$masterSourceParams["port"]:"");
|
->setValidators(array($betweenValidator))
|
||||||
|
->addValidator('regex', false, array('pattern'=>'/^[0-9]+$/', 'messages'=>array('regexNotMatch'=>_('Only numbers are allowed.'))));
|
||||||
$this->addElement($masterSourcePort);
|
$this->addElement($masterSourcePort);
|
||||||
|
|
||||||
|
$m_mount = Application_Model_StreamSetting::getMasterLiveStreamMountPoint();
|
||||||
$masterSourceMount = new Zend_Form_Element_Text('master_source_mount');
|
$masterSourceMount = new Zend_Form_Element_Text('master_source_mount');
|
||||||
$masterSourceMount->setAttrib('readonly', true)
|
$masterSourceMount->setLabel(_('Master Source Mount:'))
|
||||||
->setLabel(_('Mount:'))
|
->setValue($m_mount)
|
||||||
->setValue(isset($masterSourceParams["path"])?$masterSourceParams["path"]:"");
|
->setValidators(array(
|
||||||
|
array('regex', false, array('/^[^ &<>]+$/', 'messages' => _('Invalid character entered')))));
|
||||||
$this->addElement($masterSourceMount);
|
$this->addElement($masterSourceMount);
|
||||||
|
|
||||||
$showSourceParams = parse_url(Application_Model_Preference::GetLiveDJSourceConnectionURL());
|
$showSourceParams = parse_url(Application_Model_Preference::GetLiveDJSourceConnectionURL());
|
||||||
|
|
||||||
// Show source connection url parameters
|
// Show source connection url parameters
|
||||||
$showSourceHost = new Zend_Form_Element_Text('show_source_host');
|
$showSourceHost = new Zend_Form_Element_Text('show_source_host');
|
||||||
$showSourceHost->setAttrib('readonly', true)
|
$showSourceHost->setLabel(_('Host:'))
|
||||||
->setLabel(_('Host:'))
|
->setAttrib('readonly', true)
|
||||||
->setValue(isset($showSourceParams["host"])?$showSourceParams["host"]:"");
|
->setValue(Application_Model_Preference::GetLiveDJSourceConnectionURL());
|
||||||
$this->addElement($showSourceHost);
|
$this->addElement($showSourceHost);
|
||||||
|
|
||||||
|
//liquidsoap harbor.input port
|
||||||
|
$l_port = Application_Model_StreamSetting::getDjLiveStreamPort();
|
||||||
|
|
||||||
$showSourcePort = new Zend_Form_Element_Text('show_source_port');
|
$showSourcePort = new Zend_Form_Element_Text('show_source_port');
|
||||||
$showSourcePort->setAttrib('readonly', true)
|
$showSourcePort->setLabel(_('Show Source Port:'))
|
||||||
->setLabel(_('Port:'))
|
->setValue($l_port)
|
||||||
->setValue(isset($showSourceParams["port"])?$showSourceParams["port"]:"");
|
->setValidators(array($betweenValidator))
|
||||||
|
->addValidator('regex', false, array('pattern'=>'/^[0-9]+$/', 'messages'=>array('regexNotMatch'=>_('Only numbers are allowed.'))));
|
||||||
$this->addElement($showSourcePort);
|
$this->addElement($showSourcePort);
|
||||||
|
|
||||||
|
$l_mount = Application_Model_StreamSetting::getDjLiveStreamMountPoint();
|
||||||
$showSourceMount = new Zend_Form_Element_Text('show_source_mount');
|
$showSourceMount = new Zend_Form_Element_Text('show_source_mount');
|
||||||
$showSourceMount->setAttrib('readonly', true)
|
$showSourceMount->setLabel(_('Show Source Mount:'))
|
||||||
->setLabel(_('Mount:'))
|
->setValue($l_mount)
|
||||||
->setValue(isset($showSourceParams["path"])?$showSourceParams["path"]:"");
|
->setValidators(array(
|
||||||
|
array('regex', false, array('/^[^ &<>]+$/', 'messages' => _('Invalid character entered')))));
|
||||||
$this->addElement($showSourceMount);
|
$this->addElement($showSourceMount);
|
||||||
|
|
||||||
// demo only code
|
// demo only code
|
||||||
|
@ -125,12 +138,12 @@ class Application_Form_LiveStreamingPreferences extends Zend_Form_SubForm
|
||||||
array ('ViewScript',
|
array ('ViewScript',
|
||||||
array (
|
array (
|
||||||
'viewScript' => 'form/preferences_livestream.phtml',
|
'viewScript' => 'form/preferences_livestream.phtml',
|
||||||
'master_source_host' => isset($masterSourceParams["host"])?$masterSourceParams["host"]:"",
|
'master_source_host' => isset($masterSourceHost)?$masterSourceParams["host"]:"",
|
||||||
'master_source_port' => isset($masterSourceParams["port"])?$masterSourceParams["port"]:"",
|
'master_source_port' => isset($masterSourcePort)?$masterSourceParams["port"]:"",
|
||||||
'master_source_mount' => isset($masterSourceParams["path"])?$masterSourceParams["path"]:"",
|
'master_source_mount' => isset($masterSourceMount)?$masterSourceParams["path"]:"",
|
||||||
'show_source_host' => isset($showSourceParams["host"])?$showSourceParams["host"]:"",
|
'show_source_host' => isset($showSourceHost)?$showSourceParams["host"]:"",
|
||||||
'show_source_port' => isset($showSourceParams["port"])?$showSourceParams["port"]:"",
|
'show_source_port' => isset($showSourcePort)?$showSourceParams["port"]:"",
|
||||||
'show_source_mount' => isset($showSourceParams["path"])?$showSourceParams["path"]:"",
|
'show_source_mount' => isset($showSourceMount)?$showSourceParams["path"]:"",
|
||||||
'isDemo' => $isDemo,
|
'isDemo' => $isDemo,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
@ -140,7 +153,53 @@ class Application_Form_LiveStreamingPreferences extends Zend_Form_SubForm
|
||||||
|
|
||||||
public function isValid($data)
|
public function isValid($data)
|
||||||
{
|
{
|
||||||
return parent::isValid($data);
|
$isValid = parent::isValid($data);
|
||||||
|
$master_source_port = $data['master_source_port'];
|
||||||
|
$show_source_port = $data['show_source_port'];
|
||||||
|
|
||||||
|
if ($master_source_port == $show_source_port && $master_source_port != "") {
|
||||||
|
$element = $this->getElement('show_source_port');
|
||||||
|
$element->addError(_("You cannot use same port as Master DJ port."));
|
||||||
|
$isValid = false;
|
||||||
|
}
|
||||||
|
if ($master_source_port != "") {
|
||||||
|
if (is_numeric($master_source_port)) {
|
||||||
|
if ($master_source_port != Application_Model_StreamSetting::getMasterLiveStreamPort()) {
|
||||||
|
$sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
|
||||||
|
try {
|
||||||
|
socket_bind($sock, 0, $master_source_port);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
$element = $this->getElement("master_source_port");
|
||||||
|
$element->addError(sprintf(_("Port %s is not available"), $master_source_port));
|
||||||
|
$isValid = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
socket_close($sock);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$isValid = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($show_source_port != "") {
|
||||||
|
if (is_numeric($show_source_port)) {
|
||||||
|
if ($show_source_port != Application_Model_StreamSetting::getDjLiveStreamPort()) {
|
||||||
|
$sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
|
||||||
|
try {
|
||||||
|
socket_bind($sock, 0, $show_source_port);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
$element = $this->getElement("show_source_port");
|
||||||
|
$element->addError(sprintf(_("Port %s is not available"), $show_source_port));
|
||||||
|
$isValid = false;
|
||||||
|
}
|
||||||
|
socket_close($sock);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$isValid = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $isValid;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -464,7 +464,7 @@ class Application_Model_StreamSetting
|
||||||
|
|
||||||
public static function getDjLiveStreamPort()
|
public static function getDjLiveStreamPort()
|
||||||
{
|
{
|
||||||
return self::getValue("dj_live_stream_port", 8001);
|
return self::getValue("dj_live_stream_port", 8002);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function setDjLiveStreamMountPoint($value)
|
public static function setDjLiveStreamMountPoint($value)
|
||||||
|
|
|
@ -15,8 +15,8 @@
|
||||||
<?php echo $this->element->getElement('master_username')->render() ?>
|
<?php echo $this->element->getElement('master_username')->render() ?>
|
||||||
<span class="master_username_help_icon"></span>
|
<span class="master_username_help_icon"></span>
|
||||||
<?php echo $this->element->getElement('master_password')->render() ?>
|
<?php echo $this->element->getElement('master_password')->render() ?>
|
||||||
|
|
||||||
<?php echo $this->element->getElement("master_source_host")->render() ?>
|
<?php echo $this->element->getElement("master_source_host")->render() ?>
|
||||||
|
|
||||||
<?php echo $this->element->getElement("master_source_port")->render() ?>
|
<?php echo $this->element->getElement("master_source_port")->render() ?>
|
||||||
<?php echo $this->element->getElement("master_source_mount")->render() ?>
|
<?php echo $this->element->getElement("master_source_mount")->render() ?>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
|
@ -26,6 +26,7 @@
|
||||||
<p class="input-settings-inline-p">
|
<p class="input-settings-inline-p">
|
||||||
<?php echo _("DJs can use these settings in their broadcasting software to broadcast live only during shows assigned to them.") ?>
|
<?php echo _("DJs can use these settings in their broadcasting software to broadcast live only during shows assigned to them.") ?>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<?php echo $this->element->getElement("show_source_host")->render() ?>
|
<?php echo $this->element->getElement("show_source_host")->render() ?>
|
||||||
<?php echo $this->element->getElement("show_source_port")->render() ?>
|
<?php echo $this->element->getElement("show_source_port")->render() ?>
|
||||||
<?php echo $this->element->getElement("show_source_mount")->render() ?>
|
<?php echo $this->element->getElement("show_source_mount")->render() ?>
|
||||||
|
|
|
@ -208,8 +208,99 @@ class PypoFetch(Thread):
|
||||||
TODO: This function needs to be way shorter, and refactored :/ - MK
|
TODO: This function needs to be way shorter, and refactored :/ - MK
|
||||||
"""
|
"""
|
||||||
def regenerate_liquidsoap_conf(self, setting):
|
def regenerate_liquidsoap_conf(self, setting):
|
||||||
self.restart_liquidsoap()
|
existing = {}
|
||||||
self.update_liquidsoap_connection_status()
|
|
||||||
|
setting = sorted(setting.items())
|
||||||
|
try:
|
||||||
|
fh = open('/etc/airtime/liquidsoap.cfg', 'r')
|
||||||
|
except IOError, e:
|
||||||
|
#file does not exist
|
||||||
|
self.restart_liquidsoap()
|
||||||
|
return
|
||||||
|
|
||||||
|
self.logger.info("Reading existing config...")
|
||||||
|
# read existing conf file and build dict
|
||||||
|
while True:
|
||||||
|
line = fh.readline()
|
||||||
|
|
||||||
|
# empty line means EOF
|
||||||
|
if not line:
|
||||||
|
break
|
||||||
|
|
||||||
|
line = line.strip()
|
||||||
|
|
||||||
|
if not len(line) or line[0] == "#":
|
||||||
|
continue
|
||||||
|
|
||||||
|
try:
|
||||||
|
key, value = line.split('=', 1)
|
||||||
|
except ValueError:
|
||||||
|
continue
|
||||||
|
key = key.strip()
|
||||||
|
value = value.strip()
|
||||||
|
value = value.replace('"', '')
|
||||||
|
if value == '' or value == "0":
|
||||||
|
value = ''
|
||||||
|
existing[key] = value
|
||||||
|
fh.close()
|
||||||
|
|
||||||
|
# dict flag for any change in config
|
||||||
|
change = {}
|
||||||
|
# this flag is to detect disable -> disable change
|
||||||
|
# in that case, we don't want to restart even if there are changes.
|
||||||
|
state_change_restart = {}
|
||||||
|
#restart flag
|
||||||
|
restart = False
|
||||||
|
|
||||||
|
self.logger.info("Looking for changes...")
|
||||||
|
# look for changes
|
||||||
|
for k, s in setting:
|
||||||
|
if "output_sound_device" in k or "icecast_vorbis_metadata" in k:
|
||||||
|
dump, stream = k.split('_', 1)
|
||||||
|
state_change_restart[stream] = False
|
||||||
|
# This is the case where restart is required no matter what
|
||||||
|
if (existing[k] != str(s)):
|
||||||
|
self.logger.info("'Need-to-restart' state detected for %s...", s)
|
||||||
|
restart = True;
|
||||||
|
elif "master_live_stream_port" in k or "master_live_stream_mp" in k or "dj_live_stream_port" in k or "dj_live_stream_mp" in k or "off_air_meta" in k:
|
||||||
|
if (existing[k] != s):
|
||||||
|
self.logger.info("'Need-to-restart' state detected for %s...", s)
|
||||||
|
restart = True;
|
||||||
|
else:
|
||||||
|
stream, dump = k.split('_', 1)
|
||||||
|
if "_output" in k:
|
||||||
|
if (existing[k] != s):
|
||||||
|
self.logger.info("'Need-to-restart' state detected for %s...", s)
|
||||||
|
restart = True;
|
||||||
|
state_change_restart[stream] = True
|
||||||
|
elif (k != 'disabled'):
|
||||||
|
state_change_restart[stream] = True
|
||||||
|
else:
|
||||||
|
state_change_restart[stream] = False
|
||||||
|
else:
|
||||||
|
# setting inital value
|
||||||
|
if stream not in change:
|
||||||
|
change[stream] = False
|
||||||
|
if not (s == existing[k]):
|
||||||
|
self.logger.info("Keyname: %s, Current value: %s, New Value: %s", k, existing[k], s)
|
||||||
|
change[stream] = True
|
||||||
|
|
||||||
|
# set flag change for sound_device alway True
|
||||||
|
self.logger.info("Change:%s, State_Change:%s...", change, state_change_restart)
|
||||||
|
|
||||||
|
for k, v in state_change_restart.items():
|
||||||
|
if k == "sound_device" and v:
|
||||||
|
restart = True
|
||||||
|
elif v and change[k]:
|
||||||
|
self.logger.info("'Need-to-restart' state detected for %s...", k)
|
||||||
|
restart = True
|
||||||
|
# rewrite
|
||||||
|
if restart:
|
||||||
|
self.restart_liquidsoap()
|
||||||
|
else:
|
||||||
|
self.logger.info("No change detected in setting...")
|
||||||
|
self.update_liquidsoap_connection_status()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ls_timeout
|
@ls_timeout
|
||||||
|
|
Loading…
Reference in New Issue