Exemplo n.º 1
0
 public function streamSettingAction()
 {
     global $CC_CONFIG;
     $request = $this->getRequest();
     $baseUrl = $request->getBaseUrl();
     $this->view->headScript()->appendFile($baseUrl . '/js/airtime/preferences/streamsetting.js?' . $CC_CONFIG['airtime_version'], 'text/javascript');
     $isSaas = Application_Model_Preference::GetPlanLevel() == 'disabled' ? false : true;
     // get current settings
     $temp = Application_Model_StreamSetting::getStreamSetting();
     $setting = array();
     foreach ($temp as $t) {
         $setting[$t['keyname']] = $t['value'];
     }
     // get predefined type and bitrate from pref table
     $temp_types = Application_Model_Preference::GetStreamType();
     $stream_types = array();
     foreach ($temp_types as $type) {
         if (trim($type) == "ogg") {
             $temp = "OGG/VORBIS";
         } else {
             $temp = strtoupper(trim($type));
         }
         $stream_types[trim($type)] = $temp;
     }
     $temp_bitrate = Application_Model_Preference::GetStreamBitrate();
     $max_bitrate = intval(Application_Model_Preference::GetMaxBitrate());
     $stream_bitrates = array();
     foreach ($temp_bitrate as $type) {
         if (intval($type) <= $max_bitrate) {
             $stream_bitrates[trim($type)] = strtoupper(trim($type)) . " Kbit/s";
         }
     }
     $num_of_stream = intval(Application_Model_Preference::GetNumOfStreams());
     $form = new Application_Form_StreamSetting();
     $form->setSetting($setting);
     $form->startFrom();
     $live_stream_subform = new Application_Form_LiveStreamingPreferences();
     $form->addSubForm($live_stream_subform, "live_stream_subform");
     for ($i = 1; $i <= $num_of_stream; $i++) {
         $subform = new Application_Form_StreamSettingSubForm();
         $subform->setPrefix($i);
         $subform->setSetting($setting);
         $subform->setStreamTypes($stream_types);
         $subform->setStreamBitrates($stream_bitrates);
         $subform->startForm();
         $form->addSubForm($subform, "s" . $i . "_subform");
     }
     if ($request->isPost()) {
         $values = $request->getPost();
         $error = false;
         if ($form->isValid($values)) {
             if (!$isSaas) {
                 $values['output_sound_device'] = $form->getValue('output_sound_device');
                 $values['output_sound_device_type'] = $form->getValue('output_sound_device_type');
             }
             $values['icecast_vorbis_metadata'] = $form->getValue('icecast_vorbis_metadata');
             $values['streamFormat'] = $form->getValue('streamFormat');
             Application_Model_StreamSetting::setStreamSetting($values);
             // this goes into cc_pref table
             Application_Model_Preference::SetStreamLabelFormat($values['streamFormat']);
             Application_Model_Preference::SetLiveStreamMasterUsername($values["master_username"]);
             Application_Model_Preference::SetLiveStreamMasterPassword($values["master_password"]);
             Application_Model_Preference::SetDefaultTransitionFade($values["transition_fade"]);
             Application_Model_Preference::SetAutoTransition($values["auto_transition"]);
             Application_Model_Preference::SetAutoSwitch($values["auto_switch"]);
             if (!$isSaas) {
                 if (!Application_Model_Preference::GetMasterDjConnectionUrlOverride()) {
                     $master_connection_url = "http://" . $_SERVER['SERVER_NAME'] . ":" . $values["master_harbor_input_port"] . "/" . $values["master_harbor_input_mount_point"];
                     if (empty($values["master_harbor_input_port"]) || empty($values["master_harbor_input_mount_point"])) {
                         Application_Model_Preference::SetMasterDJSourceConnectionURL('N/A');
                     } else {
                         Application_Model_Preference::SetMasterDJSourceConnectionURL($master_connection_url);
                     }
                 } else {
                     Application_Model_Preference::SetMasterDJSourceConnectionURL($values["master_dj_connection_url"]);
                 }
                 if (!Application_Model_Preference::GetLiveDjConnectionUrlOverride()) {
                     $live_connection_url = "http://" . $_SERVER['SERVER_NAME'] . ":" . $values["dj_harbor_input_port"] . "/" . $values["dj_harbor_input_mount_point"];
                     if (empty($values["dj_harbor_input_port"]) || empty($values["dj_harbor_input_mount_point"])) {
                         Application_Model_Preference::SetLiveDJSourceConnectionURL('N/A');
                     } else {
                         Application_Model_Preference::SetLiveDJSourceConnectionURL($live_connection_url);
                     }
                 } else {
                     Application_Model_Preference::SetLiveDJSourceConnectionURL($values["live_dj_connection_url"]);
                 }
                 // extra info that goes into cc_stream_setting
                 Application_Model_StreamSetting::setMasterLiveStreamPort($values["master_harbor_input_port"]);
                 Application_Model_StreamSetting::setMasterLiveStreamMountPoint($values["master_harbor_input_mount_point"]);
                 Application_Model_StreamSetting::setDjLiveStreamPort($values["dj_harbor_input_port"]);
                 Application_Model_StreamSetting::setDjLiveStreamMountPoint($values["dj_harbor_input_mount_point"]);
             }
             // store stream update timestamp
             Application_Model_Preference::SetStreamUpdateTimestamp();
             $data = array();
             $info = Application_Model_StreamSetting::getStreamSetting();
             $data['setting'] = $info;
             for ($i = 1; $i <= $num_of_stream; $i++) {
                 Application_Model_StreamSetting::setLiquidsoapError($i, "waiting");
             }
             Application_Model_RabbitMq::SendMessageToPypo("update_stream_setting", $data);
             $this->view->statusMsg = "<div class='success'>Stream Setting Updated.</div>";
         }
     }
     $live_stream_subform->updateVariables();
     $this->view->confirm_pypo_restart_text = "If you change the username or password values for an enabled stream the playout engine will be rebooted and your listeners will hear silence for 5-10 seconds. Changing the following fields will NOT cause a reboot: Stream Label (Global Settings), and Switch Transition Fade(s), Master Username, and Master Password (Input Stream Settings). If Airtime is recording, and if the change causes a playout engine restart, the recording will be interrupted.";
     $this->view->num_stream = $num_of_stream;
     $this->view->enable_stream_conf = Application_Model_Preference::GetEnableStreamConf();
     $this->view->form = $form;
 }
 public function streamSettingAction()
 {
     $CC_CONFIG = Config::getConfig();
     $request = $this->getRequest();
     $baseUrl = Application_Common_OsPath::getBaseDir();
     $this->view->headScript()->appendFile($baseUrl . 'js/airtime/preferences/streamsetting.js?' . $CC_CONFIG['airtime_version'], 'text/javascript');
     // get current settings
     $temp = Application_Model_StreamSetting::getStreamSetting();
     $setting = array();
     foreach ($temp as $t) {
         $setting[$t['keyname']] = $t['value'];
     }
     $name_map = array('ogg' => 'Ogg Vorbis', 'fdkaac' => 'AAC+', 'aac' => 'AAC', 'opus' => 'Opus', 'mp3' => 'MP3');
     // get predefined type and bitrate from pref table
     $temp_types = Application_Model_Preference::GetStreamType();
     $stream_types = array();
     foreach ($temp_types as $type) {
         $type = strtolower(trim($type));
         if (isset($name_map[$type])) {
             $name = $name_map[$type];
         } else {
             $name = $type;
         }
         $stream_types[$type] = $name;
     }
     $temp_bitrate = Application_Model_Preference::GetStreamBitrate();
     $max_bitrate = intval(Application_Model_Preference::GetMaxBitrate());
     $stream_bitrates = array();
     foreach ($temp_bitrate as $type) {
         if (intval($type) <= $max_bitrate) {
             $stream_bitrates[trim($type)] = strtoupper(trim($type)) . " kbit/s";
         }
     }
     $num_of_stream = intval(Application_Model_Preference::GetNumOfStreams());
     $form = new Application_Form_StreamSetting();
     $form->setSetting($setting);
     $form->startFrom();
     $live_stream_subform = new Application_Form_LiveStreamingPreferences();
     $form->addSubForm($live_stream_subform, "live_stream_subform");
     for ($i = 1; $i <= $num_of_stream; $i++) {
         $subform = new Application_Form_StreamSettingSubForm();
         $subform->setPrefix($i);
         $subform->setSetting($setting);
         $subform->setStreamTypes($stream_types);
         $subform->setStreamBitrates($stream_bitrates);
         $subform->startForm();
         $form->addSubForm($subform, "s" . $i . "_subform");
     }
     if ($request->isPost()) {
         $params = $request->getPost();
         /* Parse through post data and put in format
          * $form->isValid() is expecting it in
          */
         $postData = explode('&', $params['data']);
         $s1_data = array();
         $s2_data = array();
         $s3_data = array();
         $values = array();
         foreach ($postData as $k => $v) {
             $v = explode('=', urldecode($v));
             if (strpos($v[0], "s1_data") !== false) {
                 /* In this case $v[0] may be 's1_data[enable]' , for example.
                  * We only want the 'enable' part
                  */
                 preg_match('/\\[(.*)\\]/', $v[0], $matches);
                 $s1_data[$matches[1]] = $v[1];
             } elseif (strpos($v[0], "s2_data") !== false) {
                 preg_match('/\\[(.*)\\]/', $v[0], $matches);
                 $s2_data[$matches[1]] = $v[1];
             } elseif (strpos($v[0], "s3_data") !== false) {
                 preg_match('/\\[(.*)\\]/', $v[0], $matches);
                 $s3_data[$matches[1]] = $v[1];
             } else {
                 $values[$v[0]] = $v[1];
             }
         }
         $values["s1_data"] = $s1_data;
         $values["s2_data"] = $s2_data;
         $values["s3_data"] = $s3_data;
         $error = false;
         if ($form->isValid($values)) {
             $values['output_sound_device'] = $form->getValue('output_sound_device');
             $values['output_sound_device_type'] = $form->getValue('output_sound_device_type');
             $values['icecast_vorbis_metadata'] = $form->getValue('icecast_vorbis_metadata');
             $values['streamFormat'] = $form->getValue('streamFormat');
             Application_Model_StreamSetting::setStreamSetting($values);
             /* If the admin password values are empty then we should not
              * set the pseudo password ('xxxxxx') on the front-end
              */
             $s1_set_admin_pass = !empty($values["s1_data"]["admin_pass"]);
             $s2_set_admin_pass = !empty($values["s2_data"]["admin_pass"]);
             $s3_set_admin_pass = !empty($values["s3_data"]["admin_pass"]);
             // this goes into cc_pref table
             Application_Model_Preference::SetStreamLabelFormat($values['streamFormat']);
             Application_Model_Preference::SetLiveStreamMasterUsername($values["master_username"]);
             Application_Model_Preference::SetLiveStreamMasterPassword($values["master_password"]);
             Application_Model_Preference::SetDefaultTransitionFade($values["transition_fade"]);
             Application_Model_Preference::SetAutoTransition($values["auto_transition"]);
             Application_Model_Preference::SetAutoSwitch($values["auto_switch"]);
             // compare new values with current value
             $changeRGenabled = Application_Model_Preference::GetEnableReplayGain() != $values["enableReplayGain"];
             $changeRGmodifier = Application_Model_Preference::getReplayGainModifier() != $values["replayGainModifier"];
             if ($changeRGenabled || $changeRGmodifier) {
                 Application_Model_Preference::SetEnableReplayGain($values["enableReplayGain"]);
                 Application_Model_Preference::setReplayGainModifier($values["replayGainModifier"]);
                 $md = array('schedule' => Application_Model_Schedule::getSchedule());
                 Application_Model_RabbitMq::SendMessageToPypo("update_schedule", $md);
                 //Application_Model_RabbitMq::PushSchedule();
             }
             if (!Application_Model_Preference::GetMasterDjConnectionUrlOverride()) {
                 $master_connection_url = "http://" . $_SERVER['SERVER_NAME'] . ":" . $values["master_harbor_input_port"] . "/" . $values["master_harbor_input_mount_point"];
                 if (empty($values["master_harbor_input_port"]) || empty($values["master_harbor_input_mount_point"])) {
                     Application_Model_Preference::SetMasterDJSourceConnectionURL('N/A');
                 } else {
                     Application_Model_Preference::SetMasterDJSourceConnectionURL($master_connection_url);
                 }
             } else {
                 Application_Model_Preference::SetMasterDJSourceConnectionURL($values["master_dj_connection_url"]);
             }
             if (!Application_Model_Preference::GetLiveDjConnectionUrlOverride()) {
                 $live_connection_url = "http://" . $_SERVER['SERVER_NAME'] . ":" . $values["dj_harbor_input_port"] . "/" . $values["dj_harbor_input_mount_point"];
                 if (empty($values["dj_harbor_input_port"]) || empty($values["dj_harbor_input_mount_point"])) {
                     Application_Model_Preference::SetLiveDJSourceConnectionURL('N/A');
                 } else {
                     Application_Model_Preference::SetLiveDJSourceConnectionURL($live_connection_url);
                 }
             } else {
                 Application_Model_Preference::SetLiveDJSourceConnectionURL($values["live_dj_connection_url"]);
             }
             // extra info that goes into cc_stream_setting
             Application_Model_StreamSetting::setMasterLiveStreamPort($values["master_harbor_input_port"]);
             Application_Model_StreamSetting::setMasterLiveStreamMountPoint($values["master_harbor_input_mount_point"]);
             Application_Model_StreamSetting::setDjLiveStreamPort($values["dj_harbor_input_port"]);
             Application_Model_StreamSetting::setDjLiveStreamMountPoint($values["dj_harbor_input_mount_point"]);
             Application_Model_StreamSetting::setOffAirMeta($values['offAirMeta']);
             // store stream update timestamp
             Application_Model_Preference::SetStreamUpdateTimestamp();
             $data = array();
             $info = Application_Model_StreamSetting::getStreamSetting();
             $data['setting'] = $info;
             for ($i = 1; $i <= $num_of_stream; $i++) {
                 Application_Model_StreamSetting::setLiquidsoapError($i, "waiting");
             }
             Application_Model_RabbitMq::SendMessageToPypo("update_stream_setting", $data);
             $live_stream_subform->updateVariables();
             $this->view->enable_stream_conf = Application_Model_Preference::GetEnableStreamConf();
             $this->view->form = $form;
             $this->view->num_stream = $num_of_stream;
             $this->view->statusMsg = "<div class='success'>" . _("Stream Setting Updated.") . "</div>";
             $this->_helper->json->sendJson(array("valid" => "true", "html" => $this->view->render('preference/stream-setting.phtml'), "s1_set_admin_pass" => $s1_set_admin_pass, "s2_set_admin_pass" => $s2_set_admin_pass, "s3_set_admin_pass" => $s3_set_admin_pass));
         } else {
             $live_stream_subform->updateVariables();
             $this->view->enable_stream_conf = Application_Model_Preference::GetEnableStreamConf();
             $this->view->form = $form;
             $this->view->num_stream = $num_of_stream;
             $this->_helper->json->sendJson(array("valid" => "false", "html" => $this->view->render('preference/stream-setting.phtml')));
         }
     }
     $live_stream_subform->updateVariables();
     $this->view->num_stream = $num_of_stream;
     $this->view->enable_stream_conf = Application_Model_Preference::GetEnableStreamConf();
     $this->view->form = $form;
 }