优化PlayerProxy代码

This commit is contained in:
xia-chu 2023-05-13 00:14:35 +08:00
parent 0afe75229e
commit 4fa04d6a37
2 changed files with 9 additions and 10 deletions

View File

@ -34,6 +34,7 @@ PlayerProxy::PlayerProxy(
_stream_id = stream_id; _stream_id = stream_id;
_retry_count = retry_count; _retry_count = retry_count;
setOnClose(nullptr);
setOnConnect(nullptr); setOnConnect(nullptr);
setOnDisconnect(nullptr); setOnDisconnect(nullptr);
@ -43,16 +44,15 @@ PlayerProxy::PlayerProxy(
_live_secs = 0; _live_secs = 0;
_live_status = 1; _live_status = 1;
_repull_count = 0; _repull_count = 0;
_on_close = [](const SockException &) {};
(*this)[Client::kWaitTrackReady] = false; (*this)[Client::kWaitTrackReady] = false;
} }
void PlayerProxy::setPlayCallbackOnce(const function<void(const SockException &ex)> &cb) { void PlayerProxy::setPlayCallbackOnce(function<void(const SockException &ex)> cb) {
_on_play = cb; _on_play = std::move(cb);
} }
void PlayerProxy::setOnClose(const function<void(const SockException &ex)> &cb) { void PlayerProxy::setOnClose(function<void(const SockException &ex)> cb) {
_on_close = cb ? cb : [](const SockException &) {}; _on_close = cb ? std::move(cb) : [](const SockException &) {};
} }
void PlayerProxy::setOnDisconnect(std::function<void()> cb) { void PlayerProxy::setOnDisconnect(std::function<void()> cb) {
@ -174,7 +174,7 @@ void PlayerProxy::play(const string &strUrlTmp) {
MediaPlayer::play(strUrlTmp); MediaPlayer::play(strUrlTmp);
} catch (std::exception &ex) { } catch (std::exception &ex) {
ErrorL << ex.what(); ErrorL << ex.what();
_on_play_result(SockException(Err_other, ex.what())); onPlayResult(SockException(Err_other, ex.what()));
return; return;
} }
_pull_url = strUrlTmp; _pull_url = strUrlTmp;
@ -324,9 +324,8 @@ int PlayerProxy::getStatus() {
uint64_t PlayerProxy::getLiveSecs() { uint64_t PlayerProxy::getLiveSecs() {
if (_live_status == 0) { if (_live_status == 0) {
return _live_secs + _live_ticker.elapsedTime() / 1000; return _live_secs + _live_ticker.elapsedTime() / 1000;
} else {
return _live_secs;
} }
return _live_secs;
} }
uint64_t PlayerProxy::getRePullCount() { uint64_t PlayerProxy::getRePullCount() {

View File

@ -76,13 +76,13 @@ public:
* play结果回调play执行之前有效 * play结果回调play执行之前有效
* @param cb * @param cb
*/ */
void setPlayCallbackOnce(const std::function<void(const toolkit::SockException &ex)> &cb); void setPlayCallbackOnce(std::function<void(const toolkit::SockException &ex)> cb);
/** /**
* *
* @param cb * @param cb
*/ */
void setOnClose(const std::function<void(const toolkit::SockException &ex)> &cb); void setOnClose(std::function<void(const toolkit::SockException &ex)> cb);
/** /**
* Set a callback for failed server connection * Set a callback for failed server connection