PHP code example of rtckit / sdp

1. Go to this page and download the library: Download rtckit/sdp library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

rtckit / sdp example snippets




use RTCKit\SDP\Parser;

<<<SDP
v=0
o=- 20518 0 IN IP4 192.168.0.1
s=VoIP Call
c=IN IP4 192.168.0.1
t=0 0
m=audio 5004 RTP/AVP 0 8 18
a=rtpmap:0 PCMU/8000
a=rtpmap:8 PCMA/8000
a=rtpmap:18 G729/8000
a=ptime:20
SDP;

$session = $parser->parse($sdp);
echo json_encode($session, JSON_PRETTY_PRINT);



use RTCKit\SDP\Serializer;

n->version = 0;
$session->origin = new stdClass;
$session->origin->username = '-';
$session->origin->sessionId = 20518;
$session->origin->sessionVersion = 0;
$session->origin->netType = 'IN';
$session->origin->ipVer = 4;
$session->origin->address = '192.168.0.1';
$session->name = 'VoIP Call';
$session->connection = new stdClass;
$session->connection->version = 4;
$session->connection->ip = '192.168.0.1';
$session->timing = new stdClass;
$session->timing->start = 0;
$session->timing->stop = 0;
$session->media = [
    new stdClass
];
$session->media[0]->rtp = [
    new stdClass,
    new stdClass,
    new stdClass
];
$session->media[0]->rtp[0]->payload = 0;
$session->media[0]->rtp[0]->codec = 'PCMU';
$session->media[0]->rtp[0]->rate = 8000;
$session->media[0]->rtp[1]->payload = 8;
$session->media[0]->rtp[1]->codec = 'PCMA';
$session->media[0]->rtp[1]->rate = 8000;
$session->media[0]->rtp[2]->payload = 18;
$session->media[0]->rtp[2]->codec = 'G729';
$session->media[0]->rtp[2]->rate = 8000;
$session->media[0]->fmtp = [];
$session->media[0]->type = 'audio';
$session->media[0]->port = 5004;
$session->media[0]->protocol = 'RTP/AVP';
$session->media[0]->payloads = '0 8 18';
$session->media[0]->ptime = 20;

$serializer = new Serializer;
$sdp = $serializer->serialize($session);
echo $sdp;
bash
php -d memory_limit=-1 ./vendor/bin/phpunit -c ./etc/phpunit.xml.dist
sh
php -d memory_limit=-1 ./vendor/bin/phpstan analyse -c ./etc/phpstan.neon -n -vvv --ansi --level=max src
php -d memory_limit=-1 ./vendor/bin/psalm --config=./etc/psalm.xml