目录
webrtc拉流篇,可参考
https://mp.youkuaiyun.com/mp_blog/creation/editor/122743325
RTMP采用的封装格式是FLV。所以在指定输出流媒体的时候须要指定其封装格式为“flv”。同理,其余流媒体协议也须要指定其封装格式。例如采用UDP推送流媒体的时候,能够指定其封装格式为“mpegts”。
一 关键类
| 环形缓冲,聚合了_RingStorage template<typename T> class RingBuffer : public enable_shared_from_this<RingBuffer<T> > { public: typedef std::shared_ptr<RingBuffer> Ptr; typedef _RingReader<T> RingReader; typedef _RingStorage<T> RingStorage; typedef _RingReaderDispatcher<T> RingReaderDispatcher; typedef function<void(int size)> onReaderChanged; RingBuffer(int max_size = 1024, const onReaderChanged &cb = nullptr) { _on_reader_changed = cb; _storage = std::make_shared<RingStorage>(max_size); } ~RingBuffer() {} void write(T in, bool is_key = true) { if (_delegate) { _delegate->onWrite(std::move(in), is_key); return; } LOCK_GUARD(_mtx_map); for (auto &pr : _dispatcher_map) { auto &second = pr.second; //切换线程后触发onRead事件 pr.first->async([second, in, is_key]() { second->write(std::move(const_cast<T &>(in)), is_key); }, false); } _storage->write(std::move(in), is_key); } int readerCount() { return _total_count;< |

本文详细介绍了在WebRTC拉流和RTMP推流中,如何使用环形缓冲(RingBuffer)进行数据管理。RingBuffer包含了_RingStorage、_RingReader和_RingReaderDispatcher等关键类,用于缓存、读取和分发FFmpeg解码后的RTMP数据包。当推流缓冲超过最大尺寸时,若未被拉流处理,会清除旧数据。整个推流和拉流过程是独立进行的,展示了在实时音视频传输中的数据处理机制。
最低0.47元/天 解锁文章
3258

被折叠的 条评论
为什么被折叠?



