private FrameWriterInterfaceHelper

This commit is contained in:
cqm 2022-11-01 11:44:50 +08:00
parent ac3d7bd21f
commit dde352542b
2 changed files with 35 additions and 29 deletions

View File

@ -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

View File

@ -278,29 +278,6 @@ public:
virtual void flush() {}; virtual void flush() {};
}; };
/**
* 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;
};
/** /**
* *
*/ */
@ -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();
}
/** /**
* *
*/ */