2011-08-15 22:10:46 +02:00
|
|
|
<?php
|
2015-03-11 00:15:38 +01:00
|
|
|
|
2021-10-11 16:10:47 +02:00
|
|
|
define('MAX_NUM_STREAMS', 4);
|
2015-03-11 00:15:38 +01:00
|
|
|
|
2022-09-06 12:00:50 +02:00
|
|
|
class Application_Model_StreamConfig
|
2012-07-16 03:17:13 +02:00
|
|
|
{
|
2022-09-06 12:00:50 +02:00
|
|
|
private static function toOutputKey($id)
|
|
|
|
{
|
2022-09-12 13:16:14 +02:00
|
|
|
return 's' . $id;
|
2022-09-06 12:00:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private static function toOutputId($key)
|
|
|
|
{
|
|
|
|
return intval(trim($key, 's'));
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function getOutput($key, $add_prefix = false)
|
|
|
|
{
|
|
|
|
$id = self::toOutputId($key);
|
|
|
|
$config_id = $id - 1;
|
|
|
|
$prefix = $add_prefix ? "s{$id}_" : '';
|
|
|
|
|
|
|
|
if (!Config::has("stream.outputs.merged.{$config_id}")) {
|
|
|
|
$result = [
|
|
|
|
$prefix . 'enable' => 'false',
|
|
|
|
$prefix . 'public_url' => '',
|
|
|
|
$prefix . 'output' => 'icecast',
|
|
|
|
$prefix . 'host' => 'localhost',
|
|
|
|
$prefix . 'port' => 8000,
|
|
|
|
$prefix . 'mount' => '',
|
|
|
|
$prefix . 'user' => 'source',
|
|
|
|
$prefix . 'pass' => '',
|
|
|
|
$prefix . 'admin_user' => 'admin',
|
|
|
|
$prefix . 'admin_pass' => '',
|
|
|
|
$prefix . 'channels' => 'stereo',
|
|
|
|
$prefix . 'bitrate' => 128,
|
|
|
|
$prefix . 'type' => '',
|
|
|
|
$prefix . 'name' => '',
|
|
|
|
$prefix . 'description' => '',
|
|
|
|
$prefix . 'genre' => '',
|
|
|
|
$prefix . 'url' => '',
|
|
|
|
$prefix . 'mobile' => 'false',
|
|
|
|
];
|
2012-03-02 22:55:11 +01:00
|
|
|
} else {
|
2022-09-06 12:00:50 +02:00
|
|
|
$output = Config::get("stream.outputs.merged.{$config_id}");
|
|
|
|
|
|
|
|
$result = [
|
|
|
|
$prefix . 'enable' => $output['enabled'] ?? 'false',
|
|
|
|
$prefix . 'output' => $output['kind'] ?? 'icecast',
|
|
|
|
$prefix . 'public_url' => $output['public_url'] ?? '',
|
|
|
|
$prefix . 'host' => $output['host'] ?? 'localhost',
|
|
|
|
$prefix . 'port' => $output['port'] ?? 8000,
|
|
|
|
$prefix . 'mount' => $output['mount'] ?? '',
|
|
|
|
$prefix . 'user' => $output['source_user'] ?? 'source',
|
|
|
|
$prefix . 'pass' => $output['source_password'] ?? '',
|
|
|
|
$prefix . 'admin_user' => $output['admin_user'] ?? 'admin',
|
|
|
|
$prefix . 'admin_pass' => $output['admin_password'] ?? '',
|
|
|
|
$prefix . 'channels' => $output['audio']['channels'] ?? 'stereo',
|
|
|
|
$prefix . 'bitrate' => $output['audio']['bitrate'] ?? 128,
|
|
|
|
$prefix . 'type' => $output['audio']['format'],
|
|
|
|
$prefix . 'name' => $output['name'] ?? '',
|
|
|
|
$prefix . 'description' => $output['description'] ?? '',
|
|
|
|
$prefix . 'genre' => $output['genre'] ?? '',
|
|
|
|
$prefix . 'url' => $output['website'] ?? '',
|
2023-10-14 09:13:04 +02:00
|
|
|
$prefix . 'mobile' => $output['mobile'] ?? 'false',
|
2022-09-06 12:00:50 +02:00
|
|
|
// $prefix . 'liquidsoap_error' => 'waiting',
|
|
|
|
];
|
2012-03-02 22:55:11 +01:00
|
|
|
}
|
2012-04-01 21:51:03 +02:00
|
|
|
|
2022-09-06 12:00:50 +02:00
|
|
|
if (!$result[$prefix . 'public_url']) {
|
2022-09-08 10:51:22 +02:00
|
|
|
$host = Config::get('general.public_url_raw')->getHost();
|
2022-09-06 12:00:50 +02:00
|
|
|
$port = $result[$prefix . 'port'];
|
|
|
|
$mount = $result[$prefix . 'mount'];
|
2021-10-11 16:10:47 +02:00
|
|
|
|
2022-09-06 12:00:50 +02:00
|
|
|
$result[$prefix . 'public_url'] = "http://{$host}:{$port}/{$mount}";
|
2021-10-11 16:10:47 +02:00
|
|
|
|
2022-09-06 12:00:50 +02:00
|
|
|
if ($result[$prefix . 'output'] == 'shoutcast') {
|
|
|
|
// The semi-colon is important to make Shoutcast stream URLs play instead turn into a page.
|
|
|
|
$result[$prefix . 'public_url'] .= ';';
|
|
|
|
}
|
2012-09-05 21:15:56 +02:00
|
|
|
}
|
2022-09-06 12:00:50 +02:00
|
|
|
|
|
|
|
return $result;
|
2012-03-02 22:55:11 +01:00
|
|
|
}
|
2012-04-01 21:51:03 +02:00
|
|
|
|
2022-09-06 12:00:50 +02:00
|
|
|
public static function getOutputEnabledKeys()
|
2012-04-01 21:51:03 +02:00
|
|
|
{
|
2022-09-06 12:00:50 +02:00
|
|
|
$keys = [];
|
2021-10-11 16:10:47 +02:00
|
|
|
|
2022-09-06 12:00:50 +02:00
|
|
|
foreach (Config::get('stream.outputs.merged') as $id => $output) {
|
|
|
|
if ($output['enabled'] ?? false) {
|
|
|
|
$keys[] = self::toOutputKey($id + 1);
|
|
|
|
}
|
2012-03-02 22:55:11 +01:00
|
|
|
}
|
2012-09-05 21:15:56 +02:00
|
|
|
|
2022-09-06 12:00:50 +02:00
|
|
|
return $keys;
|
2012-03-02 22:55:11 +01:00
|
|
|
}
|
2022-09-06 12:00:50 +02:00
|
|
|
}
|
2015-02-20 21:50:40 +01:00
|
|
|
|
2022-09-06 12:00:50 +02:00
|
|
|
class Application_Model_StreamSetting
|
|
|
|
{
|
2015-03-23 17:37:22 +01:00
|
|
|
public static function getEnabledStreamData()
|
|
|
|
{
|
2021-10-11 16:10:47 +02:00
|
|
|
$streams = [];
|
2015-03-23 17:37:22 +01:00
|
|
|
$streamIds = self::getEnabledStreamIds();
|
|
|
|
foreach ($streamIds as $id) {
|
|
|
|
$streamData = self::getStreamData($id);
|
2021-10-11 16:10:47 +02:00
|
|
|
$prefix = $id . '_';
|
|
|
|
$streams[$id] = [
|
2022-09-06 12:00:50 +02:00
|
|
|
'url' => $streamData[$prefix . 'public_url'],
|
2021-10-11 16:10:47 +02:00
|
|
|
'codec' => $streamData[$prefix . 'type'],
|
|
|
|
'bitrate' => $streamData[$prefix . 'bitrate'],
|
|
|
|
'mobile' => $streamData[$prefix . 'mobile'],
|
|
|
|
];
|
2015-03-23 17:37:22 +01:00
|
|
|
}
|
2021-10-11 16:10:47 +02:00
|
|
|
|
2015-03-23 17:37:22 +01:00
|
|
|
return $streams;
|
|
|
|
}
|
|
|
|
|
2011-09-27 21:26:40 +02:00
|
|
|
/* Returns the id's of all streams that are enabled in an array. An
|
|
|
|
* example of the array returned in JSON notation is ["s1", "s2", "s3"] */
|
2012-04-01 21:51:03 +02:00
|
|
|
public static function getEnabledStreamIds()
|
|
|
|
{
|
2022-09-06 12:00:50 +02:00
|
|
|
return Application_Model_StreamConfig::getOutputEnabledKeys();
|
2011-09-27 21:26:40 +02:00
|
|
|
}
|
2012-04-01 21:51:03 +02:00
|
|
|
|
2011-09-27 21:26:40 +02:00
|
|
|
/* Returns all information related to a specific stream. An example
|
|
|
|
* of a stream id is 's1' or 's2'. */
|
2012-04-01 21:51:03 +02:00
|
|
|
public static function getStreamData($p_streamId)
|
|
|
|
{
|
2022-09-06 12:00:50 +02:00
|
|
|
return Application_Model_StreamConfig::getOutput($p_streamId, true);
|
2011-08-15 22:10:46 +02:00
|
|
|
}
|
2012-04-01 21:51:03 +02:00
|
|
|
|
2012-11-02 22:50:43 +01:00
|
|
|
/* Similar to getStreamData, but removes all sX prefixes to
|
|
|
|
* make data easier to iterate over */
|
|
|
|
public static function getStreamDataNormalized($p_streamId)
|
|
|
|
{
|
2022-09-06 12:00:50 +02:00
|
|
|
return Application_Model_StreamConfig::getOutput($p_streamId, false);
|
2012-11-02 22:50:43 +01:00
|
|
|
}
|
|
|
|
|
2012-04-01 21:51:03 +02:00
|
|
|
public static function getStreamSetting()
|
|
|
|
{
|
2021-10-11 16:10:47 +02:00
|
|
|
$settings = [];
|
2015-03-11 00:15:38 +01:00
|
|
|
$numStreams = MAX_NUM_STREAMS;
|
2021-10-11 16:10:47 +02:00
|
|
|
for ($streamIdx = 1; $streamIdx <= $numStreams; ++$streamIdx) {
|
|
|
|
$settings = array_merge($settings, self::getStreamData('s' . $streamIdx));
|
2012-03-02 22:55:11 +01:00
|
|
|
}
|
2021-10-11 16:10:47 +02:00
|
|
|
$settings['master_live_stream_port'] = self::getMasterLiveStreamPort();
|
|
|
|
$settings['master_live_stream_mp'] = self::getMasterLiveStreamMountPoint();
|
|
|
|
$settings['dj_live_stream_port'] = self::getDjLiveStreamPort();
|
|
|
|
$settings['dj_live_stream_mp'] = self::getDjLiveStreamMountPoint();
|
2022-08-06 19:18:40 +02:00
|
|
|
$settings['off_air_meta'] = Application_Model_Preference::getOffAirMeta();
|
2021-10-11 16:10:47 +02:00
|
|
|
$settings['icecast_vorbis_metadata'] = self::getIcecastVorbisMetadata();
|
|
|
|
$settings['output_sound_device'] = self::getOutputSoundDevice();
|
|
|
|
$settings['output_sound_device_type'] = self::getOutputSoundDeviceType();
|
|
|
|
|
2015-03-11 00:15:38 +01:00
|
|
|
return $settings;
|
2011-08-15 22:10:46 +02:00
|
|
|
}
|
2012-04-01 21:51:03 +02:00
|
|
|
|
|
|
|
public static function getStreamEnabled($stream_id)
|
|
|
|
{
|
2022-09-06 12:00:50 +02:00
|
|
|
return in_array('s' . $stream_id, self::getEnabledStreamIds());
|
2011-10-13 20:20:08 +02:00
|
|
|
}
|
2012-04-01 21:51:03 +02:00
|
|
|
|
2011-12-07 16:31:16 +01:00
|
|
|
/*
|
|
|
|
* Only returns info that is needed for data collection
|
|
|
|
* returns array('s1'=>array(keyname=>value))
|
|
|
|
*/
|
2012-04-01 21:51:03 +02:00
|
|
|
public static function getStreamInfoForDataCollection()
|
|
|
|
{
|
2022-09-06 12:00:50 +02:00
|
|
|
$result = [];
|
|
|
|
$stream_ids = self::getEnabledStreamIds();
|
2021-10-11 16:10:47 +02:00
|
|
|
|
2022-09-06 12:00:50 +02:00
|
|
|
foreach ($stream_ids as $stream_id) {
|
|
|
|
$stream = self::getStreamDataNormalized($stream_id);
|
|
|
|
$keys = array_flip(['output', 'type', 'bitrate', 'host']);
|
|
|
|
$result[$stream_id] = array_intersect_key($stream, $keys);
|
2011-12-07 16:31:16 +01:00
|
|
|
}
|
2012-07-16 03:17:13 +02:00
|
|
|
|
2022-09-06 12:00:50 +02:00
|
|
|
return $result;
|
2012-03-02 22:55:11 +01:00
|
|
|
}
|
2012-04-01 21:51:03 +02:00
|
|
|
|
2012-07-10 05:32:21 +02:00
|
|
|
public static function getMasterLiveStreamPort()
|
|
|
|
{
|
2022-09-06 12:00:50 +02:00
|
|
|
return Config::get('stream.inputs.main.port') ?? 8001;
|
2012-03-02 22:55:11 +01:00
|
|
|
}
|
2012-04-01 21:51:03 +02:00
|
|
|
|
2012-07-10 05:32:21 +02:00
|
|
|
public static function getMasterLiveStreamMountPoint()
|
|
|
|
{
|
2022-09-06 12:00:50 +02:00
|
|
|
return Config::get('stream.inputs.main.mount') ?? 'main';
|
2012-03-02 22:55:11 +01:00
|
|
|
}
|
2012-04-01 21:51:03 +02:00
|
|
|
|
2023-03-30 20:39:02 +02:00
|
|
|
public static function getMasterLiveStreamSecure()
|
|
|
|
{
|
|
|
|
return Config::get('stream.inputs.main.secure') ?? false;
|
|
|
|
}
|
|
|
|
|
2012-07-10 05:32:21 +02:00
|
|
|
public static function getDjLiveStreamPort()
|
|
|
|
{
|
2022-09-06 12:00:50 +02:00
|
|
|
return Config::get('stream.inputs.show.port') ?? 8002;
|
2012-03-02 22:55:11 +01:00
|
|
|
}
|
2012-04-01 21:51:03 +02:00
|
|
|
|
2012-07-10 05:32:21 +02:00
|
|
|
public static function getDjLiveStreamMountPoint()
|
|
|
|
{
|
2022-09-06 12:00:50 +02:00
|
|
|
return Config::get('stream.inputs.show.mount') ?? 'show';
|
2021-10-11 16:10:47 +02:00
|
|
|
}
|
|
|
|
|
2023-03-30 20:39:02 +02:00
|
|
|
public static function getDjLiveStreamSecure()
|
|
|
|
{
|
|
|
|
return Config::get('stream.inputs.show.secure') ?? false;
|
|
|
|
}
|
|
|
|
|
2021-10-11 16:10:47 +02:00
|
|
|
public static function getAdminUser($stream)
|
|
|
|
{
|
2022-09-06 12:00:50 +02:00
|
|
|
return self::getStreamDataNormalized($stream)['admin_user'];
|
2021-10-11 16:10:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public static function getAdminPass($stream)
|
|
|
|
{
|
2022-09-06 12:00:50 +02:00
|
|
|
return self::getStreamDataNormalized($stream)['admin_pass'];
|
2021-10-11 16:10:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public static function getIcecastVorbisMetadata()
|
|
|
|
{
|
2022-09-06 12:00:50 +02:00
|
|
|
foreach (Config::get('stream.outputs.merged') as $output) {
|
|
|
|
if ($output['audio']['enable_metadata'] ?? false) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return '';
|
2015-03-11 00:15:38 +01:00
|
|
|
}
|
|
|
|
|
2021-10-11 16:10:47 +02:00
|
|
|
public static function getOutputSoundDevice()
|
|
|
|
{
|
2022-09-06 12:00:50 +02:00
|
|
|
return Config::get('stream.outputs.system.0.enabled') ?? 'false';
|
2015-03-11 00:15:38 +01:00
|
|
|
}
|
|
|
|
|
2021-10-11 16:10:47 +02:00
|
|
|
public static function getOutputSoundDeviceType()
|
|
|
|
{
|
2022-09-06 12:00:50 +02:00
|
|
|
return Config::get('stream.outputs.system.0.kind') ?? '';
|
2015-03-11 00:15:38 +01:00
|
|
|
}
|
2011-09-27 21:26:40 +02:00
|
|
|
}
|