// plain传输至其它服务,如 FFmpeg GStreamer 等
async plainTransport({ av, ip, port }) {
let rtpTransport;
let rtpConsumer;
try {
const plainTransport = {
listenIp: { ip: "192.168.0.252", announcedIp: null }, // 本机ip地址,不能127.0.0.1
};
const key = av === 'video' ? 'VC' : 'AC';
const router = await this._routers.get(key).getAvailableMediasoupRouter();
rtpTransport = await router.createPlainTransport({
// No RTP will be received from the remote side
comedia: false,
// FFmpeg and GStreamer don't support RTP/RTCP multiplexing ("a=rtcp-mux" in SDP)
rtcpMux: true,
...plainTransport,
});
// global.mediasoup.rtp.videoTransport = rtpTransport;
this.plainTransports.push(rtpTransport);
rtpTransport.on('tuple', (tuple) => {
console.log('plainTransport on tuple', tuple);
});
rtpTransport.on('rtcptuple', (rtcptuple) => {
console.log('plainTransport on rtcptuple', rtcptuple);
});
rtpTransport.on('sctpstatechange', (sctpState) => {
console.log('plainTransport on tuple', sctpState);
});
await rtpTransport.connect({
ip: ip, // 目标ip
port: parseInt(port), // 目标端口
// rtcpPort: parseInt(port) + 1, // rtcpMux 为true时,不能设置rtcpPort
});
/* console.log(
"mediasoup %a RTP SEND transport connected: %s:%d <--> %s:%d (%s)",
av,
rtpTransport.tuple.localIp,
rtpTransport.tuple.localPort,
rtpTransport.tuple.remoteIp,
rtpTransport.tuple.remotePort,
rtpTransport.tuple.protocol
);
console.log(
"mediasoup %a RTCP SEND transport connected: %s:%d <--> %s:%d (%s)",
av,
rtpTransport.rtcpTuple.localIp,
rtpTransport.rtcpTuple.localPort,
rtpTransport.rtcpTuple.remoteIp,
rtpTransport.rtcpTuple.remotePort,
rtpTransport.rtcpTuple.protocol
); */
const producers = [...this.producers.values()]
.filter((producer) => producer.kind === av)
.map((producer) => ({
id: producer.id
}));
console.log('plainTransport producers', producers);
rtpConsumer = await rtpTransport.consume({
producerId: producers[0].id, // 测试只取第1个
rtpCapabilities: router.rtpCapabilities, // Assume the recorder supports same formats as mediasoup's router
paused: true,
});
// global.mediasoup.rtp.videoConsumer = rtpConsumer;
rtpTransport.consumer = rtpConsumer;
/* console.log(
"mediasoup %a RTP SEND consumer created, kind: %s, type: %s, paused: %s, SSRC: %s CNAME: %s",
av,
rtpConsumer.kind,
rtpConsumer.type,
rtpConsumer.paused,
rtpConsumer.rtpParameters.encodings[0].ssrc,
rtpConsumer.rtpParameters.rtcp.cname
); */
rtpConsumer.resume();
return { status: 0 };
} catch (error) {
if (rtpConsumer) rtpConsumer.close();
if (rtpTransport) rtpTransport.close();
return error;
}
}
Mediasoup 传输至FFmpeg 或GStreamer
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 本文首发地址:开源实践网:Mediasoup项目实践(一)mediasoup-demo部署[https://www...
- 服务器环境 CentOS7 Node.js v14.17.5 GCC v9.1.1 Python 2.7.5 (3...
- 1、Gstreamer design Overview 概括性介绍GStreamer的架构及Gstreamer内部...
- 简单的说就是把中文字符串利用URLEncode 进行转换,在Django端需要用Python 利用相同的方法去解析...