Simplify getCodecs by using array functions
This commit is contained in:
parent
f929267910
commit
945e77f9bc
|
@ -727,67 +727,38 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO {
|
||||||
|
|
||||||
public function getCodecs($type, $showDefaults = false) {
|
public function getCodecs($type, $showDefaults = false) {
|
||||||
$allSupported = array();
|
$allSupported = array();
|
||||||
$Sccp_Codec = array('alaw', 'ulaw', 'g722', 'g723', 'g726', 'g729', 'gsm', 'h264', 'h263', 'h261');
|
$sccpCodec = array_fill_keys(array('alaw', 'ulaw', 'g722', 'g723', 'g726', 'g729', 'gsm', 'h264', 'h263', 'h261'),0);
|
||||||
// First see if have any site defaults
|
// First see if have any site defaults
|
||||||
$val = $this->sccpvalues['allow']['data'];
|
$val = $this->sccpvalues['allow']['data'];
|
||||||
if (empty($val)) {
|
if (empty($val)) {
|
||||||
// No site defaults so return chan-sccp defaults
|
// No site defaults so return chan-sccp defaults
|
||||||
$val = $this->sccpvalues['allow']['systemdefault'];
|
$val = $this->sccpvalues['allow']['systemdefault'];
|
||||||
}
|
}
|
||||||
$lcodecs = explode(',',$val);
|
$siteCodecs = array_fill_keys(explode(',',$val), 1);
|
||||||
switch ($type) {
|
switch ($type) {
|
||||||
case 'audio':
|
case 'audio':
|
||||||
$allCodecs = $this->FreePBX->Codecs->getAudio();
|
$fpbxCodecs = $this->FreePBX->Codecs->getAudio();
|
||||||
break;
|
break;
|
||||||
case 'video':
|
case 'video':
|
||||||
$allCodecs = $this->FreePBX->Codecs->getVideo();
|
$fpbxCodecs = $this->FreePBX->Codecs->getVideo();
|
||||||
break;
|
break;
|
||||||
case 'text':
|
case 'text':
|
||||||
$lcodecs = $this->getConfig('textcodecs');
|
$siteCodecs = $this->getConfig('textcodecs');
|
||||||
$allCodecs = $this->FreePBX->Codecs->getText(true);
|
$fpbxCodecs = $this->FreePBX->Codecs->getText(true);
|
||||||
break;
|
break;
|
||||||
case 'image':
|
case 'image':
|
||||||
$lcodecs = $this->getConfig('imagecodecs');
|
$siteCodecs = $this->getConfig('imagecodecs');
|
||||||
$allCodecs = $this->FreePBX->Codecs->getImage(true);
|
$fpbxCodecs = $this->FreePBX->Codecs->getImage(true);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
foreach ($allCodecs as $c => $v) {
|
// These have value set to 1
|
||||||
if (in_array($c, $Sccp_Codec)) {
|
$enabledCodecs = array_intersect_key($siteCodecs, $sccpCodec, $fpbxCodecs);
|
||||||
$allSupported[$c] = $v;
|
// These have value set to 0
|
||||||
}
|
$allSupported = array_intersect_key($sccpCodec,$fpbxCodecs);
|
||||||
}
|
$disabledCodecs = array_diff_key($allSupported,$enabledCodecs);
|
||||||
if (empty($lcodecs)) {
|
$codecs = array_merge($enabledCodecs, $disabledCodecs);
|
||||||
if (empty($allSupported)) {
|
|
||||||
$lcodecs = $allCodecs;
|
|
||||||
} else {
|
|
||||||
$lcodecs = $allSupported;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
foreach ($lcodecs as $c) {
|
|
||||||
if (isset($allSupported[$c])) {
|
|
||||||
$codecs[$c] = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ($showDefaults) {
|
|
||||||
foreach ($allSupported as $c => $v) {
|
|
||||||
if (!isset($codecs[$c])) {
|
|
||||||
$codecs[$c] = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return $codecs;
|
return $codecs;
|
||||||
} else {
|
|
||||||
//Remove non digits
|
|
||||||
$final = array();
|
|
||||||
foreach ($codecs as $codec => $order) {
|
|
||||||
$order = trim($order);
|
|
||||||
if (ctype_digit($order)) {
|
|
||||||
$final[$codec] = $order;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
asort($final);
|
|
||||||
return $final;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -8,8 +8,8 @@
|
||||||
|
|
||||||
$def_val = null;
|
$def_val = null;
|
||||||
$dev_id = null;
|
$dev_id = null;
|
||||||
$audio_codecs = $this->getCodecs('audio', true);
|
$audio_codecs = $this->getCodecs('audio');
|
||||||
$video_codecs = $this->getCodecs('video', true);
|
$video_codecs = $this->getCodecs('video');
|
||||||
$sccp_disallow_def = $this->sccpvalues['disallow']['data'];
|
$sccp_disallow_def = $this->sccpvalues['disallow']['data'];
|
||||||
$sys_disallow_def = $this->sccpvalues['disallow']['systemdefault'];
|
$sys_disallow_def = $this->sccpvalues['disallow']['systemdefault'];
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue