addStreamProxy新增force,支持强制重试拉流

This commit is contained in:
xia-chu
2026-03-17 19:30:08 +08:00
parent a13063c5e4
commit 4e170e9281
6 changed files with 43 additions and 22 deletions

View File

@@ -46,6 +46,10 @@ void TsPlayerImp::onPlayResult(const SockException &ex) {
}
void TsPlayerImp::onShutdown(const SockException &ex) {
if (!ex) {
// http-ts拉流如果为eof正常断开那么强制为异常状态
const_cast<SockException &>(ex).reset(Err_other, ex.what());
}
while (_demuxer) {
try {
// shared_from_this()可能抛异常 [AUTO-TRANSLATED:6af9bd3c]

View File

@@ -32,7 +32,7 @@ PlayerProxy::PlayerProxy(
setOnClose(nullptr);
setOnConnect(nullptr);
setOnDisconnect(nullptr);
_reconnect_delay_min = reconnect_delay_min > 0 ? reconnect_delay_min : 2;
_reconnect_delay_max = reconnect_delay_max > 0 ? reconnect_delay_max : 60;
_reconnect_delay_step = reconnect_delay_step > 0 ? reconnect_delay_step : 3;
@@ -51,15 +51,14 @@ void PlayerProxy::setOnClose(function<void(const SockException &ex)> cb) {
}
void PlayerProxy::setOnDisconnect(std::function<void()> cb) {
_on_disconnect = cb ? std::move(cb) : [] () {};
_on_disconnect = cb ? std::move(cb) : []() {};
}
void PlayerProxy::setOnConnect(std::function<void(const TranslationInfo&)> cb) {
_on_connect = cb ? std::move(cb) : [](const TranslationInfo&) {};
void PlayerProxy::setOnConnect(std::function<void(const TranslationInfo &)> cb) {
_on_connect = cb ? std::move(cb) : [](const TranslationInfo &) {};
}
void PlayerProxy::setTranslationInfo()
{
void PlayerProxy::setTranslationInfo() {
_transtalion_info.byte_speed = _media_src ? _media_src->getBytesSpeed() : -1;
_transtalion_info.start_time_stamp = _media_src ? _media_src->getCreateStamp() : 0;
_transtalion_info.stream_info.clear();
@@ -72,22 +71,21 @@ void PlayerProxy::setTranslationInfo()
back.codec_type = track->getTrackType();
back.codec_name = track->getCodecName();
switch (back.codec_type) {
case TrackAudio : {
case TrackAudio: {
auto audio_track = dynamic_pointer_cast<AudioTrack>(track);
back.audio_sample_rate = audio_track->getAudioSampleRate();
back.audio_channel = audio_track->getAudioChannel();
back.audio_sample_bit = audio_track->getAudioSampleBit();
break;
}
case TrackVideo : {
case TrackVideo: {
auto video_track = dynamic_pointer_cast<VideoTrack>(track);
back.video_width = video_track->getVideoWidth();
back.video_height = video_track->getVideoHeight();
back.video_fps = video_track->getVideoFps();
break;
}
default:
break;
default: break;
}
}
}
@@ -120,7 +118,8 @@ void PlayerProxy::play(const string &strUrlTmp) {
if (!err) {
// 取消定时器,避免hls拉流索引文件因为网络波动失败重连成功后出现循环重试的情况 [AUTO-TRANSLATED:91e5f0c8]
// Cancel the timer to avoid the situation where the hls stream index file fails to reconnect due to network fluctuations and then retries in a loop after successful reconnection
// Cancel the timer to avoid the situation where the hls stream index file fails to reconnect due to network fluctuations and then retries in a loop
// after successful reconnection
strongSelf->_timer.reset();
strongSelf->_live_ticker.resetTime();
strongSelf->_live_status = 0;
@@ -129,7 +128,7 @@ void PlayerProxy::play(const string &strUrlTmp) {
*piFailedCnt = 0; // 连续播放失败次数清0
strongSelf->onPlaySuccess();
strongSelf->setTranslationInfo();
strongSelf->_on_connect(strongSelf->_transtalion_info);
strongSelf->_on_connect(strongSelf->_transtalion_info);
InfoL << "play " << strUrlTmp << " success";
} else if (*piFailedCnt < strongSelf->_retry_count || strongSelf->_retry_count < 0) {
@@ -151,6 +150,10 @@ void PlayerProxy::play(const string &strUrlTmp) {
if (err) {
NOTICE_EMIT(BroadcastPlayerProxyFailedArgs, Broadcast::kBroadcastPlayerProxyFailed, *strongSelf, err);
}
if (strongSelf->_on_play) {
strongSelf->_on_play(err);
strongSelf->_on_play = nullptr;
}
// 注销直接拉流代理产生的流:#532 [AUTO-TRANSLATED:c6343a3b]
// Unregister the stream generated by the direct stream proxy: #532
@@ -291,7 +294,7 @@ float PlayerProxy::getLossRate(MediaSource &sender, TrackType type) {
return getPacketLossRate(type);
}
toolkit::EventPoller::Ptr PlayerProxy::getOwnerPoller(MediaSource &sender) {
toolkit::EventPoller::Ptr PlayerProxy::getOwnerPoller(MediaSource &sender) {
return getPoller();
}
@@ -314,10 +317,10 @@ void PlayerProxy::onPlaySuccess() {
// rtmp拉流代理 [AUTO-TRANSLATED:21173335]
// Rtmp stream proxy
if (reset_when_replay || !_muxer) {
auto old = _option.enable_rtmp;
auto old = _option.enable_rtmp;
_option.enable_rtmp = false;
_muxer = std::make_shared<MultiMediaSourceMuxer>(_tuple, getDuration(), _option);
_option.enable_rtmp = old;
_option.enable_rtmp = old;
}
} else {
// 其他拉流代理 [AUTO-TRANSLATED:e5f2e45d]