Commit dde35254 by cqm

private FrameWriterInterfaceHelper

parent ac3d7bd2
...@@ -210,5 +210,39 @@ void FrameMerger::flush() { ...@@ -210,5 +210,39 @@ void FrameMerger::flush() {
} }
clear(); clear();
} }
/**
* 写帧接口转function,辅助类
*/
class FrameWriterInterfaceHelper : public FrameWriterInterface {
public:
typedef std::shared_ptr<FrameWriterInterfaceHelper> Ptr;
typedef std::function<bool(const Frame::Ptr &frame)> onWriteFrame;
/**
* inputFrame后触发onWriteFrame回调
*/
FrameWriterInterfaceHelper(const onWriteFrame& cb){
_writeCallback = cb;
}
virtual ~FrameWriterInterfaceHelper(){}
/**
* 写入帧数据
*/
bool inputFrame(const Frame::Ptr &frame) override {
return _writeCallback(frame);
}
private:
onWriteFrame _writeCallback;
};
FrameWriterInterface* FrameDispatcher::addDelegate(const std::function<bool(const Frame::Ptr &frame)> &cb) {
auto delegate = std::make_shared<FrameWriterInterfaceHelper>(cb);
std::lock_guard<std::mutex> lck(_mtx);
_delegates.emplace(delegate.get(), delegate);
return delegate.get();
}
}//namespace mediakit }//namespace mediakit
...@@ -279,29 +279,6 @@ public: ...@@ -279,29 +279,6 @@ public:
}; };
/** /**
* 写帧接口转function,辅助类
*/
class FrameWriterInterfaceHelper : public FrameWriterInterface {
public:
typedef std::shared_ptr<FrameWriterInterfaceHelper> Ptr;
typedef std::function<bool(const Frame::Ptr &frame)> onWriteFrame;
/**
* inputFrame后触发onWriteFrame回调
*/
FrameWriterInterfaceHelper(const onWriteFrame &cb) { _writeCallback = cb; }
virtual ~FrameWriterInterfaceHelper() = default;
/**
* 写入帧数据
*/
bool inputFrame(const Frame::Ptr &frame) override { return _writeCallback(frame); }
private:
onWriteFrame _writeCallback;
};
/**
* 支持代理转发的帧环形缓存 * 支持代理转发的帧环形缓存
*/ */
class FrameDispatcher : public FrameWriterInterface { class FrameDispatcher : public FrameWriterInterface {
...@@ -318,12 +295,7 @@ public: ...@@ -318,12 +295,7 @@ public:
_delegates.emplace(delegate.get(), delegate); _delegates.emplace(delegate.get(), delegate);
} }
FrameWriterInterface* addDelegate(const std::function<bool(const Frame::Ptr &frame)> &cb) { FrameWriterInterface* addDelegate(const std::function<bool(const Frame::Ptr &frame)> &cb);
auto delegate = std::make_shared<FrameWriterInterfaceHelper>(cb);
std::lock_guard<std::mutex> lck(_mtx);
_delegates.emplace(delegate.get(), delegate);
return delegate.get();
}
/** /**
* 删除代理 * 删除代理
*/ */
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论