webrtc源码学习 - Track Source Sink的关系

1、source & sink 的关系

source是生产媒体资源的,sink负责消费。

可以理解成sink 就是观察者,调用source AddOrUpdateSink接口注册sink ,soruce 产生数据的时候调用sink OnFrame接口,接收数据,下面是2个接口类,非常简单


template <typename VideoFrameT>
class VideoSourceInterface {
   
   
 public:
  virtual ~VideoSourceInterface() = default;

    // 添加sink
  virtual void AddOrUpdateSink(VideoSinkInterface<VideoFrameT>* sink,
                               const VideoSinkWants& wants) = 0;
  // RemoveSink must guarantee that at the time the method returns,
  // there is no current and no future calls to VideoSinkInterface::OnFrame.
  virtual void RemoveSink(VideoSinkInterface<VideoFrameT>* sink) = 0;
};
template <typename VideoFrameT>
class VideoSinkInterface {
   
   
 public:
  virtual ~VideoSinkInterface() = default;

    // source 产生数据回调到当前
  virtual void OnFrame(const VideoFrameT& frame) = 0;

  // Should be called by the source when it discards the frame due to rate
  // limiting.
  virtual void OnDiscardedFrame() {
   
   }
};

2、Track

Track 翻译成轨道, 其实就是对一组source 和 sink 封装,同时记录状态和一些附加功能。如果直接使用source 绑定 sink 不就可以了,为什么还需要Track呢,Track 解决什么问题?

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值