ZLMediaKit/src/Rtp/RtpCache.h
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

65 lines
1.9 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.
*/
#ifndef ZLMEDIAKIT_RTPCACHE_H
#define ZLMEDIAKIT_RTPCACHE_H
#if defined(ENABLE_RTPPROXY)
#include "PSEncoder.h"
#include "RawEncoder.h"
#include "Common/PacketCache.h"
namespace mediakit{
class RtpCache : protected PacketCache<toolkit::Buffer> {
public:
using onFlushed = std::function<void(std::shared_ptr<toolkit::List<toolkit::Buffer::Ptr> >)>;
RtpCache(onFlushed cb);
~RtpCache() override = default;
protected:
/**
* 输入rtp(目的是为了合并写)
* @param buffer rtp数据
*/
void input(uint64_t stamp, toolkit::Buffer::Ptr buffer,bool is_key = false);
protected:
void onFlush(std::shared_ptr<toolkit::List<toolkit::Buffer::Ptr> > rtp_list, bool) override;
private:
onFlushed _cb;
};
class RtpCachePS : public RtpCache, public PSEncoderImp {
public:
RtpCachePS(onFlushed cb, uint32_t ssrc, uint8_t payload_type = 96) : RtpCache(std::move(cb)), PSEncoderImp(ssrc, payload_type) {};
~RtpCachePS() override = default;
void flush() override;
protected:
void onRTP(toolkit::Buffer::Ptr rtp, bool is_key = false) override;
};
class RtpCacheRaw : public RtpCache, public RawEncoderImp {
public:
RtpCacheRaw(onFlushed cb, uint32_t ssrc, uint8_t payload_type = 96, bool send_audio = true) : RtpCache(std::move(cb)), RawEncoderImp(ssrc, payload_type, send_audio) {};
~RtpCacheRaw() override = default;
void flush() override;
protected:
void onRTP(toolkit::Buffer::Ptr rtp, bool is_key = false) override;
};
}//namespace mediakit
#endif//ENABLE_RTPPROXY
#endif //ZLMEDIAKIT_RTPCACHE_H