Archive


Category: Uncategorized

  • WebRTC Simulcast

    简介 Simulcast 可以翻译成联播,不是新闻联播,而是多个媒体流的传播,如图所示 注: SFU 即 Selective Forward Unit, 媒体转发服务器 刚开始,发送方 sender 发送一路 1080p 的视频流给服务器 SFU, SFU 再转发给多个接收方 receiver1, receiver2 和 receiver3。 一会儿,receiver 2 和 receiver 3 通过 RTCP 反馈带宽不够,丢包率和延迟都比较大,也就是说 上行带宽对于 sender 是足够的, 下行带宽对于 receiver 1 也是没问题的 下行带宽对于 receiver 2 和 receiver 3 都有问题 这样联播的好处就来了,SFU 可以根据带宽评估的结果让 Sender 同时发送 1080p, 360p 和 180p 三路流,并分别转发给 receiver1, receiver […]

  • 化繁为简的状态模式

    最近看了同事写的一块代码,逻辑非常复杂,我们讨论了实现的方式,我建议他改用状态模式, 这样可以省去很多复杂的判断分支 这是用状态模式的做法 不用状态模式的代码大致如此 if(cpuRatio < xxx && memRatio < xxx) { state=Normal } else if(cpuRatio > xxx && memRatio > xxx) { state=Busy } else if(cpuRatio > xxx && memRatio > xxx) { state=Crazy } if(state == Crazy) { delegateOtherDoSomething() } else if (state == Busy) { complainAndDoSomething() } else if (state == Normal) […]

  • GStreamer Quick Start

    note of https://gstreamer.freedesktop.org/documentation/tutorials/basic/hello-world.html GStreamer is a framework for constructing graphs of various filters (termed elements here) that will handle streaming media. Any discrete (packetizable) media type is supported, with provisions for automatically determining source type. Formatting/framing information is provided with a powerful negotiation framework. Plugins are heavily used to provide for all elements, allowing one […]

  • WebRTC Video Pipeline

    概述 视频流水线是指视频从发送端摄像头捕捉视频图像,将视频流进行转换,编码,打包,发送,直到接收端进行解包,缓存,解码再到将视频图像渲染到画布上或者视频元素中 # linux send h264 rtp stream: gst-launch-1.0 -v ximagesrc \ ! video/x-raw,framerate=20/1 \ ! videoscale ! videoconvert \ ! x264enc tune=zerolatency bitrate=500 speed-preset=superfast \ ! rtph264pay \ ! udpsink host=127.0.0.1 port=5000 # Macos send h264 rtp stream: gst-launch-1.0 -v avfvideosrc capture-screen=true \ ! video/x-raw,framerate=20/1 \ ! videoscale ! videoconvert \ ! x264enc tune=zerolatency […]

  • 异步编程模式

    大约有两种基本的异步编程模式 Task-Based Asynchronous Pattern 基于任务的异步模式 以一个单个的方法(Task)来表示异步操作的发起和完成, 它引入了 Async, Await 这样的关键字 任务执行会返回一个 Promise 或 Future, 代表未来执行的结果 Event-Based Asynchronous Pattern 基于事件的异步模式 以事件驱动的模式来提供异步的行为,主要使用了事件回调和事件处理器的方式,类似于观察者模式的结构 它遵循了著名的好莱坞原则 “Don’t call us, we’ll call you” – “别打电话给我们,我们会打给你的” 在具体实现上,有三种模型 多进程 RPC 远程过程调用就是典型的用例,在多个进程间通过网络消息传输来进行异步调用,例如 Ajax。 在一台主机的多进程还可以使用众多的 IPC 方法,我觉得最好用的还是 UDS (Unix Domain Socket) 其地址族为 AF_UNIX,Socket type 可以是 SOCK_STREAM(类比 TCP) 和 SOCK_DGRAM(类比 UDP), SCOK_SEQPACKET(类比 SCTP) nc -U /tmp/test.sock […]

  • DTLS handshake

    DTLS record header DTLS Header Field Purpose 8-bit Message Type This field contains the type of DTLS record being sent. Valid types are as follows:- ChangeCipherSpec: 0x14- Alert: 0x15- Handshake: 0x16- Application Data: 0x17 16-bit Protocol Version This field contains the DTLS protocol version. Valid values are as follows:- DTLS 1.1: 0xFEFD 16-bit Epoch This […]

  • WebRTC’s data channel uses dcSCTP instead of usrSCTP

    Feautre https://bugs.chromium.org/p/webrtc/issues/detail?id=12614 Message Starting with Chrome M95 for the Canary and Dev channels, we’re going to start to rollout the DcSCTP library for the SCTP transport used by WebRTC’s Data Channels. It is a new implementation with a focus on security and compatibility with the previous implementation. No action should be required on your part […]

  • 线程切换的经典模式

    以 WebRTC library 为例,这两百行代码演示了线程切换的经典模式。 一个线程会有一个对应的任务队列,线程会不断检查这个队列,如果有任务就执行,无任务就等待 往这个任务队列中提交一个任务,就等于从当前线程切换了到了这个任务线程。 当然这个实现方面还是有些细节, 为了线程安全,GetNextTask 时需要加锁 /* * Copyright 2018 The WebRTC Project Authors. All rights reserved. * * Use of this source code is governed by a BSD-style license * that can be found in the LICENSE file in the root of the source * tree. An additional intellectual property rights […]

  • How to disable SRTP in WebRTC library

    Take peerconnection_client as example webrtc::PeerConnectionFactoryInterface::Options options; options.disable_encryption = this->disable_srtp_; peer_connection_factory_->SetOptions(options); step 1 change C:\webrtc-checkout\src\examples\peerconnection\client\flag_defs.h ABSL_FLAG(bool, disable_srtp, false, "disable srtp or not: false-enable srtp, true-disable srtp"); step 2 change C:\webrtc-checkout\src\examples\peerconnection\client\conductor.h class Conductor : public webrtc::PeerConnectionObserver, public webrtc::CreateSessionDescriptionObserver, public PeerConnectionClientObserver, public MainWndCallback { public: void DisableSrtp(bool flag); bool disable_srtp_; }; void Conductor::DisableSrtp(bool flag) { this->disable_srtp_ = flag; […]

  • How to get media stats from peer connection

    Take Peerconection_client as example step 1 class RtcStatsRecorder : public webrtc::RTCStatsCollectorCallback { public: void OnStatsDelivered(const rtc::scoped_refptr<const webrtc::RTCStatsReport>& report) override; }; step 2 void RtcStatsRecorder::OnStatsDelivered(const rtc::scoped_refptr<const webrtc::RTCStatsReport>& report) { RTC_LOG(LS_INFO) << report.ToJson() << endl; }