mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2026-07-07 04:08:13 +08:00
整理代码
This commit is contained in:
@@ -18,46 +18,47 @@
|
||||
|
||||
namespace mediakit {
|
||||
|
||||
class RtmpPusher: public RtmpProtocol , public TcpClient , public PusherBase{
|
||||
class RtmpPusher : public RtmpProtocol, public TcpClient, public PusherBase {
|
||||
public:
|
||||
typedef std::shared_ptr<RtmpPusher> Ptr;
|
||||
RtmpPusher(const EventPoller::Ptr &poller,const RtmpMediaSource::Ptr &src);
|
||||
virtual ~RtmpPusher();
|
||||
|
||||
void publish(const string &strUrl) override ;
|
||||
~RtmpPusher() override;
|
||||
|
||||
void publish(const string &url) override ;
|
||||
void teardown() override;
|
||||
|
||||
void setOnPublished(const Event &cb) override {
|
||||
_onPublished = cb;
|
||||
_on_published = cb;
|
||||
}
|
||||
|
||||
void setOnShutdown(const Event &cb) override{
|
||||
_onShutdown = cb;
|
||||
_on_shutdown = cb;
|
||||
}
|
||||
|
||||
protected:
|
||||
//for Tcpclient override
|
||||
void onRecv(const Buffer::Ptr &pBuf) override;
|
||||
void onRecv(const Buffer::Ptr &buf) override;
|
||||
void onConnect(const SockException &err) override;
|
||||
void onErr(const SockException &ex) override;
|
||||
|
||||
//for RtmpProtocol override
|
||||
void onRtmpChunk(RtmpPacket &chunkData) override;
|
||||
void onRtmpChunk(RtmpPacket &chunk_data) override;
|
||||
void onSendRawData(const Buffer::Ptr &buffer) override{
|
||||
send(buffer);
|
||||
}
|
||||
|
||||
private:
|
||||
void onPublishResult(const SockException &ex,bool handshakeCompleted);
|
||||
void onPublishResult(const SockException &ex, bool handshake_done);
|
||||
|
||||
template<typename FUN>
|
||||
inline void addOnResultCB(const FUN &fun) {
|
||||
lock_guard<recursive_mutex> lck(_mtxOnResultCB);
|
||||
_mapOnResultCB.emplace(_send_req_id, fun);
|
||||
lock_guard<recursive_mutex> lck(_mtx_on_result);
|
||||
_map_on_result.emplace(_send_req_id, fun);
|
||||
}
|
||||
template<typename FUN>
|
||||
inline void addOnStatusCB(const FUN &fun) {
|
||||
lock_guard<recursive_mutex> lck(_mtxOnStatusCB);
|
||||
_dqOnStatusCB.emplace_back(fun);
|
||||
lock_guard<recursive_mutex> lck(_mtx_on_status);
|
||||
_deque_on_status.emplace_back(fun);
|
||||
}
|
||||
|
||||
void onCmd_result(AMFDecoder &dec);
|
||||
@@ -69,23 +70,25 @@ private:
|
||||
inline void send_publish();
|
||||
inline void send_metaData();
|
||||
void setSocketFlags();
|
||||
private:
|
||||
string _strApp;
|
||||
string _strStream;
|
||||
string _strTcUrl;
|
||||
|
||||
unordered_map<int, function<void(AMFDecoder &dec)> > _mapOnResultCB;
|
||||
recursive_mutex _mtxOnResultCB;
|
||||
deque<function<void(AMFValue &dec)> > _dqOnStatusCB;
|
||||
recursive_mutex _mtxOnStatusCB;
|
||||
//超时功能实现
|
||||
std::shared_ptr<Timer> _pPublishTimer;
|
||||
//源
|
||||
std::weak_ptr<RtmpMediaSource> _pMediaSrc;
|
||||
RtmpMediaSource::RingType::RingReader::Ptr _pRtmpReader;
|
||||
private:
|
||||
string _app;
|
||||
string _stream_id;
|
||||
string _tc_url;
|
||||
|
||||
recursive_mutex _mtx_on_result;
|
||||
recursive_mutex _mtx_on_status;
|
||||
deque<function<void(AMFValue &dec)> > _deque_on_status;
|
||||
unordered_map<int, function<void(AMFDecoder &dec)> > _map_on_result;
|
||||
|
||||
//事件监听
|
||||
Event _onShutdown;
|
||||
Event _onPublished;
|
||||
Event _on_shutdown;
|
||||
Event _on_published;
|
||||
|
||||
//推流超时定时器
|
||||
std::shared_ptr<Timer> _publish_timer;
|
||||
std::weak_ptr<RtmpMediaSource> _publish_src;
|
||||
RtmpMediaSource::RingType::RingReader::Ptr _rtmp_reader;
|
||||
};
|
||||
|
||||
} /* namespace mediakit */
|
||||
|
||||
Reference in New Issue
Block a user