mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2026-06-14 12:05:58 +08:00
MediaPusher: 抽象精简代码
This commit is contained in:
@@ -57,7 +57,7 @@ void RtspPusher::teardown() {
|
||||
void RtspPusher::publish(const string &url_str) {
|
||||
RtspUrl url;
|
||||
if (!url.parse(url_str)) {
|
||||
onPublishResult(SockException(Err_other, StrPrinter << "illegal rtsp url:" << url_str), false);
|
||||
onPublishResult_l(SockException(Err_other, StrPrinter << "illegal rtsp url:" << url_str), false);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -83,7 +83,7 @@ void RtspPusher::publish(const string &url_str) {
|
||||
if (!strong_self) {
|
||||
return false;
|
||||
}
|
||||
strong_self->onPublishResult(SockException(Err_timeout, "publish rtsp timeout"), false);
|
||||
strong_self->onPublishResult_l(SockException(Err_timeout, "publish rtsp timeout"), false);
|
||||
return false;
|
||||
}, getPoller()));
|
||||
|
||||
@@ -94,7 +94,7 @@ void RtspPusher::publish(const string &url_str) {
|
||||
startConnect(url._host, url._port, publish_timeout_sec);
|
||||
}
|
||||
|
||||
void RtspPusher::onPublishResult(const SockException &ex, bool handshake_done) {
|
||||
void RtspPusher::onPublishResult_l(const SockException &ex, bool handshake_done) {
|
||||
DebugL << ex.what();
|
||||
if (ex.getErrCode() == Err_shutdown) {
|
||||
//主动shutdown的,不触发回调
|
||||
@@ -103,14 +103,10 @@ void RtspPusher::onPublishResult(const SockException &ex, bool handshake_done) {
|
||||
if (!handshake_done) {
|
||||
//播放结果回调
|
||||
_publish_timer.reset();
|
||||
if (_on_published) {
|
||||
_on_published(ex);
|
||||
}
|
||||
onPublishResult(ex);
|
||||
} else {
|
||||
//播放成功后异常断开回调
|
||||
if (_on_shutdown) {
|
||||
_on_shutdown(ex);
|
||||
}
|
||||
onShutdown(ex);
|
||||
}
|
||||
|
||||
if (ex) {
|
||||
@@ -120,12 +116,12 @@ void RtspPusher::onPublishResult(const SockException &ex, bool handshake_done) {
|
||||
|
||||
void RtspPusher::onErr(const SockException &ex) {
|
||||
//定时器_pPublishTimer为空后表明握手结束了
|
||||
onPublishResult(ex, !_publish_timer);
|
||||
onPublishResult_l(ex, !_publish_timer);
|
||||
}
|
||||
|
||||
void RtspPusher::onConnect(const SockException &err) {
|
||||
if (err) {
|
||||
onPublishResult(err, false);
|
||||
onPublishResult_l(err, false);
|
||||
return;
|
||||
}
|
||||
sendAnnounce();
|
||||
@@ -137,7 +133,7 @@ void RtspPusher::onRecv(const Buffer::Ptr &buf){
|
||||
} catch (exception &e) {
|
||||
SockException ex(Err_other, e.what());
|
||||
//定时器_pPublishTimer为空后表明握手结束了
|
||||
onPublishResult(ex, !_publish_timer);
|
||||
onPublishResult_l(ex, !_publish_timer);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -465,7 +461,7 @@ void RtspPusher::sendRecord() {
|
||||
_rtsp_reader->setDetachCB([weak_self]() {
|
||||
auto strong_self = weak_self.lock();
|
||||
if (strong_self) {
|
||||
strong_self->onPublishResult(SockException(Err_other, "媒体源被释放"), !strong_self->_publish_timer);
|
||||
strong_self->onPublishResult_l(SockException(Err_other, "媒体源被释放"), !strong_self->_publish_timer);
|
||||
}
|
||||
});
|
||||
if (_rtp_type != Rtsp::RTP_TCP) {
|
||||
@@ -479,7 +475,7 @@ void RtspPusher::sendRecord() {
|
||||
return true;
|
||||
}, getPoller()));
|
||||
}
|
||||
onPublishResult(SockException(Err_success, "success"), false);
|
||||
onPublishResult_l(SockException(Err_success, "success"), false);
|
||||
//提升发送性能
|
||||
setSocketFlags();
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user