-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathSdpData.php
33 lines (28 loc) · 835 Bytes
/
SdpData.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<?php
class SdpData
{
protected $sdpData;
public function __construct(string $sdpData)
{
$this->sdpData = $sdpData;
}
public function getMediaStreams(): array
{
$streams = [];
$stream = null;
$lines = preg_split('/\r\n/', $this->sdpData);
foreach ($lines as $line) {
if (isset($line[0])) {
$paramValue = substr($line, 2);
if ($line[0] === 'm') {
$streams[$paramValue] = [];
$stream = &$streams[$paramValue];
} else if ($stream !== null && $line[0] === 'a') {
$paramParts = explode(':', $paramValue, 2);
$stream[$paramParts[0]] = $paramParts[1] ?? '';
}
}
}
return $streams;
}
}