mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-22 19:00:01 +08:00
优化FrameDispatcher相关代码
This commit is contained in:
parent
d04761c2c6
commit
60d96f4f3b
@ -215,34 +215,27 @@ void FrameMerger::flush() {
|
|||||||
*/
|
*/
|
||||||
class FrameWriterInterfaceHelper : public FrameWriterInterface {
|
class FrameWriterInterfaceHelper : public FrameWriterInterface {
|
||||||
public:
|
public:
|
||||||
typedef std::shared_ptr<FrameWriterInterfaceHelper> Ptr;
|
using Ptr = std::shared_ptr<FrameWriterInterfaceHelper>;
|
||||||
typedef std::function<bool(const Frame::Ptr &frame)> onWriteFrame;
|
using onWriteFrame = std::function<bool(const Frame::Ptr &frame)>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* inputFrame后触发onWriteFrame回调
|
* inputFrame后触发onWriteFrame回调
|
||||||
*/
|
*/
|
||||||
FrameWriterInterfaceHelper(const onWriteFrame& cb){
|
FrameWriterInterfaceHelper(onWriteFrame cb) { _callback = std::move(cb); }
|
||||||
_writeCallback = cb;
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual ~FrameWriterInterfaceHelper(){}
|
virtual ~FrameWriterInterfaceHelper() = default;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 写入帧数据
|
* 写入帧数据
|
||||||
*/
|
*/
|
||||||
bool inputFrame(const Frame::Ptr &frame) override {
|
bool inputFrame(const Frame::Ptr &frame) override { return _callback(frame); }
|
||||||
return _writeCallback(frame);
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
onWriteFrame _writeCallback;
|
onWriteFrame _callback;
|
||||||
};
|
};
|
||||||
|
|
||||||
FrameWriterInterface* FrameDispatcher::addDelegate(const std::function<bool(const Frame::Ptr &frame)> &cb) {
|
FrameWriterInterface* FrameDispatcher::addDelegate(std::function<bool(const Frame::Ptr &frame)> cb) {
|
||||||
auto delegate = std::make_shared<FrameWriterInterfaceHelper>(cb);
|
return addDelegate(std::make_shared<FrameWriterInterfaceHelper>(std::move(cb)));
|
||||||
std::lock_guard<std::mutex> lck(_mtx);
|
|
||||||
_delegates.emplace(delegate.get(), delegate);
|
|
||||||
return delegate.get();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}//namespace mediakit
|
}//namespace mediakit
|
||||||
|
@ -290,12 +290,13 @@ public:
|
|||||||
/**
|
/**
|
||||||
* 添加代理
|
* 添加代理
|
||||||
*/
|
*/
|
||||||
void addDelegate(const FrameWriterInterface::Ptr &delegate) {
|
FrameWriterInterface* addDelegate(FrameWriterInterface::Ptr delegate) {
|
||||||
std::lock_guard<std::mutex> lck(_mtx);
|
std::lock_guard<std::mutex> lck(_mtx);
|
||||||
_delegates.emplace(delegate.get(), delegate);
|
return _delegates.emplace(delegate.get(), std::move(delegate)).first->second.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
FrameWriterInterface* addDelegate(const std::function<bool(const Frame::Ptr &frame)> &cb);
|
FrameWriterInterface* addDelegate(std::function<bool(const Frame::Ptr &frame)> cb);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 删除代理
|
* 删除代理
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user