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 解决什么问题?