ZLMediaKit/src/Rtp/RtpCache.cpp
Dw9 978143c86d
rtp级联(ps/ts/es)新增支持gop缓存功能 (#2395)
该修改主要解决rtp级联(调用startSendRtp接口)未做gop缓存导致上级无法秒开的问题。
同时通过RingBuffer对象线程隔离的特性,实现了在断连续推场景下归属线程切换导致的线程安全问题。
用户如未使用rtp级联功能,请修改配置文件关闭GOP缓存(rtp_proxy.gop_cache=0)以便节省内存。

---------

Co-authored-by: 夏楚 <771730766@qq.com>
2023-04-17 12:19:24 +08:00

55 lines
1.4 KiB
C++

/*
* Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved.
*
* This file is part of ZLMediaKit(https://github.com/xia-chu/ZLMediaKit).
*
* Use of this source code is governed by MIT license that can be found in the
* LICENSE file in the root of the source tree. All contributing project authors
* may be found in the AUTHORS file in the root of the source tree.
*/
#include "RtpCache.h"
#if defined(ENABLE_RTPPROXY)
using namespace toolkit;
namespace mediakit{
RtpCache::RtpCache(onFlushed cb) {
_cb = std::move(cb);
}
void RtpCache::onFlush(std::shared_ptr<List<Buffer::Ptr>> rtp_list, bool) {
_cb(std::move(rtp_list));
}
void RtpCache::input(uint64_t stamp, Buffer::Ptr buffer, bool is_key) {
inputPacket(stamp, true, std::move(buffer), is_key);
}
void RtpCachePS::flush() {
PSEncoderImp::flush();
RtpCache::flush();
}
void RtpCachePS::onRTP(Buffer::Ptr buffer, bool is_key) {
auto rtp = std::static_pointer_cast<RtpPacket>(buffer);
auto stamp = rtp->getStampMS();
input(stamp, std::move(buffer), is_key);
}
void RtpCacheRaw::flush() {
RawEncoderImp::flush();
RtpCache::flush();
}
void RtpCacheRaw::onRTP(Buffer::Ptr buffer, bool is_key) {
auto rtp = std::static_pointer_cast<RtpPacket>(buffer);
auto stamp = rtp->getStampMS();
input(stamp, std::move(buffer), is_key);
}
}//namespace mediakit
#endif//#if defined(ENABLE_RTPPROXY)