承接 rtckit/sdp 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

rtckit/sdp

Composer 安装命令:

composer require rtckit/sdp

包简介

Session Description Protocol (SDP) Library for PHP

README 文档

README

RFC 2327, RFC 4566 and RFC 8866 compliant SDP parsing/serialization library for PHP.

CI Status Psalm Type Coverage Latest Stable Version Installs on Packagist Test Coverage Maintainability License

Quickstart

Session Description Parsing

Once installed, you can parse SDP session description right away as follows:

<?php

use RTCKit\SDP\Parser;

require_once __DIR__ . '/vendor/autoload.php';

$parser = new Parser;
$sdp = <<<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);

The $session variable (a stdClass object) will now be populated with the parsed SDP session description. Here's the output of the above example:

{
    "version": 0,
    "origin": {
        "username": "-",
        "sessionId": 20518,
        "sessionVersion": 0,
        "netType": "IN",
        "ipVer": 4,
        "address": "192.168.0.1"
    },
    "name": "VoIP Call",
    "connection": {
        "version": 4,
        "ip": "192.168.0.1"
    },
    "timing": {
        "start": 0,
        "stop": 0
    },
    "media": [
        {
            "rtp": [
                {
                    "payload": 0,
                    "codec": "PCMU",
                    "rate": 8000
                },
                {
                    "payload": 8,
                    "codec": "PCMA",
                    "rate": 8000
                },
                {
                    "payload": 18,
                    "codec": "G729",
                    "rate": 8000
                }
            ],
            "fmtp": [],
            "type": "audio",
            "port": 5004,
            "protocol": "RTP\/AVP",
            "payloads": "0 8 18",
            "ptime": 20
        }
    ]
}

Session Description Serialization

Serializing is the opposite action of parsing:

<?php

use RTCKit\SDP\Serializer;

require_once __DIR__ . '/vendor/autoload.php';

$session = new stdClass;

$session->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;

The $sdp variable will now contain the serialized SDP session description:

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

Requirements

RTCKit\SDP is compatible with PHP 8.1+ and has no external library and extension dependencies.

Installation

You can add the library as project dependency using Composer:

composer require rtckit/sdp

If you only need the library during development, for instance when used in your test suite, then you should add it as a development-only dependency:

composer require --dev rtckit/sdp

Tests

To run the test suite, clone this repository and then install dependencies via Composer:

composer install

Then, go to the project root and run:

php -d memory_limit=-1 ./vendor/bin/phpunit -c ./etc/phpunit.xml.dist

Static Analysis

In order to ensure high code quality, RTCKit\SDP uses PHPStan and Psalm:

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

License

MIT, see LICENSE file.

Acknowledgments

  • sdp-transform - SDP parser and serializer for JavaScript, main source of inspiration for this library
  • RFC 2327 - SDP: Session Description Protocol (April 1998)
  • RFC 4566 - SDP: Session Description Protocol (July 2006)
  • RFC 8866 - SDP: Session Description Protocol (January 2021)

Contributing

Bug reports (and small patches) can be submitted via the issue tracker. Forking the repository and submitting a Pull Request is preferred for substantial patches.

rtckit/sdp 适用场景与选型建议

rtckit/sdp 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 82 次下载、GitHub Stars 达 2, 最近一次更新时间为 2024 年 01 月 05 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「voip」 「telephony」 「SDP」 「telco」 「session description protocol」 「rfc 2327」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 rtckit/sdp 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 rtckit/sdp 我们能提供哪些服务?
定制开发 / 二次开发

基于 rtckit/sdp 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 82
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 30
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-01-05