2018-10-25 10:00:17 +08:00
|
|
|
|
/*
|
2020-04-04 20:30:09 +08:00
|
|
|
|
* Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved.
|
2018-10-25 10:00:17 +08:00
|
|
|
|
*
|
2021-01-17 18:31:50 +08:00
|
|
|
|
* This file is part of ZLMediaKit(https://github.com/xia-chu/ZLMediaKit).
|
2018-10-25 10:00:17 +08:00
|
|
|
|
*
|
2020-04-04 20:30:09 +08:00
|
|
|
|
* 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.
|
2018-10-25 10:00:17 +08:00
|
|
|
|
*/
|
2018-10-18 23:48:00 +08:00
|
|
|
|
|
|
|
|
|
#ifndef ZLMEDIAKIT_FRAME_H
|
|
|
|
|
#define ZLMEDIAKIT_FRAME_H
|
|
|
|
|
|
2018-10-26 16:09:48 +08:00
|
|
|
|
#include <mutex>
|
2018-10-27 22:40:44 +08:00
|
|
|
|
#include <functional>
|
2018-10-23 11:09:21 +08:00
|
|
|
|
#include "Util/RingBuffer.h"
|
2018-10-18 23:48:00 +08:00
|
|
|
|
#include "Network/Socket.h"
|
2018-10-26 16:09:48 +08:00
|
|
|
|
|
|
|
|
|
using namespace std;
|
2018-10-24 17:17:55 +08:00
|
|
|
|
using namespace toolkit;
|
2018-10-18 23:48:00 +08:00
|
|
|
|
|
2018-10-24 17:17:55 +08:00
|
|
|
|
namespace mediakit{
|
2018-10-18 23:48:00 +08:00
|
|
|
|
|
2018-10-23 11:09:21 +08:00
|
|
|
|
typedef enum {
|
|
|
|
|
CodecInvalid = -1,
|
|
|
|
|
CodecH264 = 0,
|
2018-10-30 14:59:42 +08:00
|
|
|
|
CodecH265,
|
2018-10-26 17:46:31 +08:00
|
|
|
|
CodecAAC,
|
2020-04-08 15:42:52 +08:00
|
|
|
|
CodecG711A,
|
|
|
|
|
CodecG711U,
|
2020-05-11 22:33:10 +08:00
|
|
|
|
CodecOpus,
|
2020-12-26 16:00:35 +08:00
|
|
|
|
CodecL16,
|
2018-10-26 17:46:31 +08:00
|
|
|
|
CodecMax = 0x7FFF
|
2018-10-23 11:09:21 +08:00
|
|
|
|
} CodecId;
|
|
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
|
TrackInvalid = -1,
|
|
|
|
|
TrackVideo = 0,
|
|
|
|
|
TrackAudio,
|
2018-10-25 22:57:59 +08:00
|
|
|
|
TrackTitle,
|
2021-03-28 17:32:53 +08:00
|
|
|
|
TrackApplication,
|
2021-03-27 22:23:38 +08:00
|
|
|
|
TrackMax = 4
|
2018-10-23 11:09:21 +08:00
|
|
|
|
} TrackType;
|
|
|
|
|
|
2020-05-15 18:08:54 +08:00
|
|
|
|
/**
|
|
|
|
|
* 获取编码器名称
|
|
|
|
|
*/
|
|
|
|
|
const char *getCodecName(CodecId codecId);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取音视频类型
|
|
|
|
|
*/
|
|
|
|
|
TrackType getTrackType(CodecId codecId);
|
|
|
|
|
|
2018-10-27 22:54:16 +08:00
|
|
|
|
/**
|
|
|
|
|
* 编码信息的抽象接口
|
|
|
|
|
*/
|
2018-10-23 11:09:21 +08:00
|
|
|
|
class CodecInfo {
|
|
|
|
|
public:
|
2018-10-23 18:39:17 +08:00
|
|
|
|
typedef std::shared_ptr<CodecInfo> Ptr;
|
|
|
|
|
|
2018-10-23 11:09:21 +08:00
|
|
|
|
CodecInfo(){}
|
|
|
|
|
virtual ~CodecInfo(){}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取编解码器类型
|
|
|
|
|
*/
|
|
|
|
|
virtual CodecId getCodecId() const = 0;
|
2020-03-08 21:19:20 +08:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取编码器名称
|
|
|
|
|
*/
|
2020-03-09 16:04:34 +08:00
|
|
|
|
const char *getCodecName();
|
2020-05-11 22:33:10 +08:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取音视频类型
|
|
|
|
|
*/
|
|
|
|
|
TrackType getTrackType();
|
2018-10-23 11:09:21 +08:00
|
|
|
|
};
|
|
|
|
|
|
2018-10-27 22:54:16 +08:00
|
|
|
|
/**
|
|
|
|
|
* 帧类型的抽象接口
|
|
|
|
|
*/
|
2019-07-24 18:40:18 +08:00
|
|
|
|
class Frame : public Buffer, public CodecInfo {
|
2018-10-18 23:48:00 +08:00
|
|
|
|
public:
|
|
|
|
|
typedef std::shared_ptr<Frame> Ptr;
|
|
|
|
|
virtual ~Frame(){}
|
2018-11-17 17:26:38 +08:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 返回解码时间戳,单位毫秒
|
|
|
|
|
*/
|
|
|
|
|
virtual uint32_t dts() const = 0;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 返回显示时间戳,单位毫秒
|
|
|
|
|
*/
|
|
|
|
|
virtual uint32_t pts() const {
|
|
|
|
|
return dts();
|
|
|
|
|
}
|
2018-10-21 22:24:24 +08:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 前缀长度,譬如264前缀为0x00 00 00 01,那么前缀长度就是4
|
|
|
|
|
* aac前缀则为7个字节
|
|
|
|
|
*/
|
2021-01-17 18:31:50 +08:00
|
|
|
|
virtual size_t prefixSize() const = 0;
|
2018-10-23 21:41:45 +08:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 返回是否为关键帧
|
|
|
|
|
*/
|
|
|
|
|
virtual bool keyFrame() const = 0;
|
2019-07-24 18:02:55 +08:00
|
|
|
|
|
2019-08-01 18:49:04 +08:00
|
|
|
|
/**
|
|
|
|
|
* 是否为配置帧,譬如sps pps vps
|
|
|
|
|
*/
|
|
|
|
|
virtual bool configFrame() const = 0;
|
|
|
|
|
|
2019-07-24 18:02:55 +08:00
|
|
|
|
/**
|
|
|
|
|
* 是否可以缓存
|
|
|
|
|
*/
|
|
|
|
|
virtual bool cacheAble() const { return true; }
|
2019-07-24 18:40:18 +08:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 返回可缓存的frame
|
|
|
|
|
*/
|
|
|
|
|
static Ptr getCacheAbleFrame(const Ptr &frame);
|
2021-01-23 09:44:37 +08:00
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
//对象个数统计
|
|
|
|
|
ObjectStatistic<Frame> _statistic;
|
2018-10-18 23:48:00 +08:00
|
|
|
|
};
|
|
|
|
|
|
2020-05-11 22:33:10 +08:00
|
|
|
|
class FrameImp : public Frame {
|
|
|
|
|
public:
|
2021-02-05 11:51:16 +08:00
|
|
|
|
using Ptr = std::shared_ptr<FrameImp>;
|
|
|
|
|
|
|
|
|
|
template<typename C=FrameImp>
|
|
|
|
|
static std::shared_ptr<C> create();
|
2020-05-11 22:33:10 +08:00
|
|
|
|
|
|
|
|
|
char *data() const override{
|
|
|
|
|
return (char *)_buffer.data();
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-17 18:31:50 +08:00
|
|
|
|
size_t size() const override {
|
2020-05-11 22:33:10 +08:00
|
|
|
|
return _buffer.size();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint32_t dts() const override {
|
|
|
|
|
return _dts;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint32_t pts() const override{
|
|
|
|
|
return _pts ? _pts : _dts;
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-17 18:31:50 +08:00
|
|
|
|
size_t prefixSize() const override{
|
2020-05-11 22:33:10 +08:00
|
|
|
|
return _prefix_size;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CodecId getCodecId() const override{
|
2020-08-01 10:22:12 +08:00
|
|
|
|
return _codec_id;
|
2020-05-11 22:33:10 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool keyFrame() const override {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool configFrame() const override{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public:
|
2020-08-01 10:22:12 +08:00
|
|
|
|
CodecId _codec_id = CodecInvalid;
|
2020-05-11 22:33:10 +08:00
|
|
|
|
uint32_t _dts = 0;
|
|
|
|
|
uint32_t _pts = 0;
|
2021-01-17 18:31:50 +08:00
|
|
|
|
size_t _prefix_size = 0;
|
|
|
|
|
BufferLikeString _buffer;
|
2021-02-05 16:49:11 +08:00
|
|
|
|
|
|
|
|
|
private:
|
2021-01-23 09:44:37 +08:00
|
|
|
|
//对象个数统计
|
|
|
|
|
ObjectStatistic<FrameImp> _statistic;
|
2021-02-05 11:51:16 +08:00
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
friend class ResourcePool_l<FrameImp>;
|
|
|
|
|
FrameImp() = default;
|
|
|
|
|
|
|
|
|
|
template<typename C>
|
|
|
|
|
static std::shared_ptr<C> create_l();
|
2020-05-11 22:33:10 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 一个Frame类中可以有多个帧,他们通过 0x 00 00 01 分隔
|
|
|
|
|
* ZLMediaKit会先把这种复合帧split成单个帧然后再处理
|
|
|
|
|
* 一个复合帧可以通过无内存拷贝的方式切割成多个子Frame
|
|
|
|
|
* 提供该类的目的是切割复合帧时防止内存拷贝,提高性能
|
|
|
|
|
*/
|
|
|
|
|
template<typename Parent>
|
|
|
|
|
class FrameInternal : public Parent{
|
|
|
|
|
public:
|
|
|
|
|
typedef std::shared_ptr<FrameInternal> Ptr;
|
2021-01-17 18:31:50 +08:00
|
|
|
|
FrameInternal(const Frame::Ptr &parent_frame, char *ptr, size_t size, size_t prefix_size)
|
2020-05-11 22:33:10 +08:00
|
|
|
|
: Parent(ptr, size, parent_frame->dts(), parent_frame->pts(), prefix_size) {
|
|
|
|
|
_parent_frame = parent_frame;
|
|
|
|
|
}
|
|
|
|
|
bool cacheAble() const override {
|
|
|
|
|
return _parent_frame->cacheAble();
|
|
|
|
|
}
|
|
|
|
|
private:
|
|
|
|
|
Frame::Ptr _parent_frame;
|
|
|
|
|
};
|
|
|
|
|
|
2018-10-27 22:54:16 +08:00
|
|
|
|
/**
|
2020-05-11 22:33:10 +08:00
|
|
|
|
* 写帧接口的抽象接口类
|
2018-10-27 22:54:16 +08:00
|
|
|
|
*/
|
2018-10-27 22:40:44 +08:00
|
|
|
|
class FrameWriterInterface {
|
2018-10-26 16:09:48 +08:00
|
|
|
|
public:
|
2018-10-27 22:40:44 +08:00
|
|
|
|
typedef std::shared_ptr<FrameWriterInterface> Ptr;
|
|
|
|
|
FrameWriterInterface(){}
|
|
|
|
|
virtual ~FrameWriterInterface(){}
|
2020-05-11 22:33:10 +08:00
|
|
|
|
|
2018-10-26 16:09:48 +08:00
|
|
|
|
/**
|
2020-05-11 22:33:10 +08:00
|
|
|
|
* 写入帧数据
|
|
|
|
|
*/
|
2018-10-26 16:09:48 +08:00
|
|
|
|
virtual void inputFrame(const Frame::Ptr &frame) = 0;
|
|
|
|
|
};
|
|
|
|
|
|
2018-10-27 22:54:16 +08:00
|
|
|
|
/**
|
|
|
|
|
* 写帧接口转function,辅助类
|
|
|
|
|
*/
|
2018-10-27 22:40:44 +08:00
|
|
|
|
class FrameWriterInterfaceHelper : public FrameWriterInterface {
|
|
|
|
|
public:
|
|
|
|
|
typedef std::shared_ptr<FrameWriterInterfaceHelper> Ptr;
|
|
|
|
|
typedef std::function<void(const Frame::Ptr &frame)> onWriteFrame;
|
|
|
|
|
|
2018-10-27 22:54:16 +08:00
|
|
|
|
/**
|
|
|
|
|
* inputFrame后触发onWriteFrame回调
|
|
|
|
|
*/
|
2018-10-27 22:40:44 +08:00
|
|
|
|
FrameWriterInterfaceHelper(const onWriteFrame& cb){
|
|
|
|
|
_writeCallback = cb;
|
|
|
|
|
}
|
2020-05-11 22:33:10 +08:00
|
|
|
|
|
2018-10-27 22:40:44 +08:00
|
|
|
|
virtual ~FrameWriterInterfaceHelper(){}
|
2020-05-11 22:33:10 +08:00
|
|
|
|
|
2018-10-27 22:40:44 +08:00
|
|
|
|
/**
|
2020-05-11 22:33:10 +08:00
|
|
|
|
* 写入帧数据
|
|
|
|
|
*/
|
2018-10-27 22:40:44 +08:00
|
|
|
|
void inputFrame(const Frame::Ptr &frame) override {
|
|
|
|
|
_writeCallback(frame);
|
|
|
|
|
}
|
|
|
|
|
private:
|
|
|
|
|
onWriteFrame _writeCallback;
|
|
|
|
|
};
|
|
|
|
|
|
2018-10-27 22:54:16 +08:00
|
|
|
|
/**
|
|
|
|
|
* 支持代理转发的帧环形缓存
|
|
|
|
|
*/
|
2019-12-25 20:07:42 +08:00
|
|
|
|
class FrameDispatcher : public FrameWriterInterface {
|
2018-10-23 22:16:54 +08:00
|
|
|
|
public:
|
2019-12-25 20:07:42 +08:00
|
|
|
|
typedef std::shared_ptr<FrameDispatcher> Ptr;
|
2018-10-23 22:16:54 +08:00
|
|
|
|
|
2019-12-25 20:07:42 +08:00
|
|
|
|
FrameDispatcher(){}
|
|
|
|
|
virtual ~FrameDispatcher(){}
|
2018-10-23 22:16:54 +08:00
|
|
|
|
|
2020-05-11 22:33:10 +08:00
|
|
|
|
/**
|
|
|
|
|
* 添加代理
|
|
|
|
|
*/
|
2018-10-27 22:40:44 +08:00
|
|
|
|
void addDelegate(const FrameWriterInterface::Ptr &delegate){
|
2020-04-06 21:23:35 +08:00
|
|
|
|
//_delegates_write可能多线程同时操作
|
2018-10-26 16:09:48 +08:00
|
|
|
|
lock_guard<mutex> lck(_mtx);
|
2020-05-15 21:48:29 +08:00
|
|
|
|
_delegates_write.emplace(delegate.get(),delegate);
|
2020-04-06 21:23:35 +08:00
|
|
|
|
_need_update = true;
|
2018-10-23 22:16:54 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-05-11 22:33:10 +08:00
|
|
|
|
/**
|
|
|
|
|
* 删除代理
|
|
|
|
|
*/
|
2020-05-15 21:48:29 +08:00
|
|
|
|
void delDelegate(FrameWriterInterface *ptr){
|
2020-04-06 21:23:35 +08:00
|
|
|
|
//_delegates_write可能多线程同时操作
|
2018-10-26 16:09:48 +08:00
|
|
|
|
lock_guard<mutex> lck(_mtx);
|
2020-04-06 21:23:35 +08:00
|
|
|
|
_delegates_write.erase(ptr);
|
|
|
|
|
_need_update = true;
|
2018-10-23 22:16:54 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2020-05-11 22:33:10 +08:00
|
|
|
|
* 写入帧并派发
|
2018-10-23 22:16:54 +08:00
|
|
|
|
*/
|
|
|
|
|
void inputFrame(const Frame::Ptr &frame) override{
|
2020-04-06 21:23:35 +08:00
|
|
|
|
if(_need_update){
|
|
|
|
|
//发现代理列表发生变化了,这里同步一次
|
|
|
|
|
lock_guard<mutex> lck(_mtx);
|
|
|
|
|
_delegates_read = _delegates_write;
|
|
|
|
|
_need_update = false;
|
|
|
|
|
}
|
2020-04-06 21:44:32 +08:00
|
|
|
|
|
|
|
|
|
//_delegates_read能确保是单线程操作的
|
|
|
|
|
for(auto &pr : _delegates_read){
|
|
|
|
|
pr.second->inputFrame(frame);
|
|
|
|
|
}
|
2020-05-11 22:33:10 +08:00
|
|
|
|
}
|
2020-04-06 21:44:32 +08:00
|
|
|
|
|
2020-05-11 22:33:10 +08:00
|
|
|
|
/**
|
|
|
|
|
* 返回代理个数
|
|
|
|
|
*/
|
2021-01-17 18:31:50 +08:00
|
|
|
|
size_t size() const {
|
2020-05-11 22:33:10 +08:00
|
|
|
|
return _delegates_write.size();
|
2018-10-23 22:16:54 +08:00
|
|
|
|
}
|
|
|
|
|
private:
|
2018-10-26 16:09:48 +08:00
|
|
|
|
mutex _mtx;
|
2020-04-06 21:23:35 +08:00
|
|
|
|
map<void *,FrameWriterInterface::Ptr> _delegates_read;
|
|
|
|
|
map<void *,FrameWriterInterface::Ptr> _delegates_write;
|
|
|
|
|
bool _need_update = false;
|
2018-10-23 22:16:54 +08:00
|
|
|
|
};
|
|
|
|
|
|
2019-07-25 09:38:16 +08:00
|
|
|
|
/**
|
|
|
|
|
* 通过Frame接口包装指针,方便使用者把自己的数据快速接入ZLMediaKit
|
|
|
|
|
*/
|
|
|
|
|
class FrameFromPtr : public Frame{
|
2018-10-26 16:09:48 +08:00
|
|
|
|
public:
|
2019-07-25 09:38:16 +08:00
|
|
|
|
typedef std::shared_ptr<FrameFromPtr> Ptr;
|
2020-08-08 12:19:04 +08:00
|
|
|
|
|
2021-01-17 18:31:50 +08:00
|
|
|
|
FrameFromPtr(CodecId codec_id, char *ptr, size_t size, uint32_t dts, uint32_t pts = 0, size_t prefix_size = 0)
|
2020-08-08 12:19:04 +08:00
|
|
|
|
: FrameFromPtr(ptr, size, dts, pts, prefix_size) {
|
2020-08-01 10:22:12 +08:00
|
|
|
|
_codec_id = codec_id;
|
2020-08-08 12:19:04 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-01-17 18:31:50 +08:00
|
|
|
|
FrameFromPtr(char *ptr, size_t size, uint32_t dts, uint32_t pts = 0, size_t prefix_size = 0){
|
2020-08-01 10:22:12 +08:00
|
|
|
|
_ptr = ptr;
|
|
|
|
|
_size = size;
|
|
|
|
|
_dts = dts;
|
|
|
|
|
_pts = pts;
|
|
|
|
|
_prefix_size = prefix_size;
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-26 16:09:48 +08:00
|
|
|
|
char *data() const override{
|
2019-07-03 16:22:12 +08:00
|
|
|
|
return _ptr;
|
2018-10-26 16:09:48 +08:00
|
|
|
|
}
|
2020-08-01 10:22:12 +08:00
|
|
|
|
|
2021-01-17 18:31:50 +08:00
|
|
|
|
size_t size() const override {
|
2019-07-03 16:22:12 +08:00
|
|
|
|
return _size;
|
2018-10-26 16:09:48 +08:00
|
|
|
|
}
|
2019-07-03 16:22:12 +08:00
|
|
|
|
|
2018-11-17 17:26:38 +08:00
|
|
|
|
uint32_t dts() const override {
|
2019-07-03 16:22:12 +08:00
|
|
|
|
return _dts;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint32_t pts() const override{
|
2020-05-11 22:33:10 +08:00
|
|
|
|
return _pts ? _pts : dts();
|
2018-10-26 16:09:48 +08:00
|
|
|
|
}
|
2019-07-03 16:22:12 +08:00
|
|
|
|
|
2021-01-17 18:31:50 +08:00
|
|
|
|
size_t prefixSize() const override{
|
2020-05-11 22:33:10 +08:00
|
|
|
|
return _prefix_size;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool cacheAble() const override {
|
|
|
|
|
return false;
|
2018-10-26 16:09:48 +08:00
|
|
|
|
}
|
2020-08-01 10:22:12 +08:00
|
|
|
|
|
2020-08-08 12:19:04 +08:00
|
|
|
|
CodecId getCodecId() const override {
|
|
|
|
|
if (_codec_id == CodecInvalid) {
|
|
|
|
|
throw std::invalid_argument("FrameFromPtr对象未设置codec类型");
|
|
|
|
|
}
|
2020-08-01 10:22:12 +08:00
|
|
|
|
return _codec_id;
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-08 12:19:04 +08:00
|
|
|
|
void setCodecId(CodecId codec_id) {
|
|
|
|
|
_codec_id = codec_id;
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-01 10:22:12 +08:00
|
|
|
|
bool keyFrame() const override {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool configFrame() const override{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
FrameFromPtr() {}
|
|
|
|
|
|
2019-07-25 09:38:16 +08:00
|
|
|
|
protected:
|
|
|
|
|
char *_ptr;
|
|
|
|
|
uint32_t _dts;
|
|
|
|
|
uint32_t _pts = 0;
|
2021-01-17 18:31:50 +08:00
|
|
|
|
size_t _size;
|
|
|
|
|
size_t _prefix_size;
|
2020-08-01 10:22:12 +08:00
|
|
|
|
CodecId _codec_id = CodecInvalid;
|
2019-07-25 09:38:16 +08:00
|
|
|
|
};
|
|
|
|
|
|
2020-09-21 14:56:58 +08:00
|
|
|
|
/**
|
|
|
|
|
* 该对象可以把Buffer对象转换成可缓存的Frame对象
|
|
|
|
|
*/
|
|
|
|
|
template <typename Parent>
|
|
|
|
|
class FrameWrapper : public Parent{
|
|
|
|
|
public:
|
|
|
|
|
~FrameWrapper() = default;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 构造frame
|
|
|
|
|
* @param buf 数据缓存
|
|
|
|
|
* @param dts 解码时间戳
|
|
|
|
|
* @param pts 显示时间戳
|
|
|
|
|
* @param prefix 帧前缀长度
|
|
|
|
|
* @param offset buffer有效数据偏移量
|
|
|
|
|
*/
|
2021-01-17 18:31:50 +08:00
|
|
|
|
FrameWrapper(const Buffer::Ptr &buf, uint32_t dts, uint32_t pts, size_t prefix, size_t offset) : Parent(buf->data() + offset, buf->size() - offset, dts, pts, prefix){
|
2020-09-21 14:56:58 +08:00
|
|
|
|
_buf = buf;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 构造frame
|
|
|
|
|
* @param buf 数据缓存
|
|
|
|
|
* @param dts 解码时间戳
|
|
|
|
|
* @param pts 显示时间戳
|
|
|
|
|
* @param prefix 帧前缀长度
|
|
|
|
|
* @param offset buffer有效数据偏移量
|
|
|
|
|
* @param codec 帧类型
|
|
|
|
|
*/
|
2021-01-17 18:31:50 +08:00
|
|
|
|
FrameWrapper(const Buffer::Ptr &buf, uint32_t dts, uint32_t pts, size_t prefix, size_t offset, CodecId codec) : Parent(codec, buf->data() + offset, buf->size() - offset, dts, pts, prefix){
|
2020-09-21 14:56:58 +08:00
|
|
|
|
_buf = buf;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 该帧可缓存
|
|
|
|
|
*/
|
|
|
|
|
bool cacheAble() const override {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
Buffer::Ptr _buf;
|
|
|
|
|
};
|
|
|
|
|
|
2018-10-24 17:17:55 +08:00
|
|
|
|
}//namespace mediakit
|
2020-05-11 22:33:10 +08:00
|
|
|
|
#endif //ZLMEDIAKIT_FRAME_H
|