mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
fix the forwarder reconnect bug, feed it the sequence header.
This commit is contained in:
parent
c7ec6f511c
commit
270041b225
7 changed files with 44 additions and 8 deletions
|
@ -35,14 +35,17 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|||
#include <srs_core_pithy_print.hpp>
|
||||
#include <srs_core_rtmp.hpp>
|
||||
#include <srs_core_config.hpp>
|
||||
#include <srs_core_source.hpp>
|
||||
|
||||
#define SRS_PULSE_TIMEOUT_MS 100
|
||||
#define SRS_FORWARDER_SLEEP_MS 2000
|
||||
#define SRS_SEND_TIMEOUT_US 3000000L
|
||||
#define SRS_RECV_TIMEOUT_US SRS_SEND_TIMEOUT_US
|
||||
|
||||
SrsForwarder::SrsForwarder()
|
||||
SrsForwarder::SrsForwarder(SrsSource* _source)
|
||||
{
|
||||
source = _source;
|
||||
|
||||
client = NULL;
|
||||
stfd = NULL;
|
||||
stream_id = 0;
|
||||
|
@ -182,14 +185,17 @@ int SrsForwarder::cycle()
|
|||
return ret;
|
||||
}
|
||||
|
||||
// TODO: FIXME: need to cache the metadata and sequence header when reconnect.
|
||||
|
||||
if ((ret = client->publish(stream_name, stream_id)) != ERROR_SUCCESS) {
|
||||
srs_error("connect with server failed, stream_name=%s, stream_id=%d. ret=%d",
|
||||
stream_name.c_str(), stream_id, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
if ((ret = source->on_forwarder_start(this)) != ERROR_SUCCESS) {
|
||||
srs_error("callback the source to feed the sequence header failed. ret=%d", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
if ((ret = forward()) != ERROR_SUCCESS) {
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -38,6 +38,7 @@ class SrsSharedPtrMessage;
|
|||
class SrsOnMetaDataPacket;
|
||||
class SrsRtmpClient;
|
||||
class SrsRequest;
|
||||
class SrsSource;
|
||||
|
||||
/**
|
||||
* forward the stream to other servers.
|
||||
|
@ -55,10 +56,11 @@ private:
|
|||
st_netfd_t stfd;
|
||||
SrsThread* pthread;
|
||||
private:
|
||||
SrsSource* source;
|
||||
SrsRtmpClient* client;
|
||||
std::vector<SrsSharedPtrMessage*> msgs;
|
||||
public:
|
||||
SrsForwarder();
|
||||
SrsForwarder(SrsSource* _source);
|
||||
virtual ~SrsForwarder();
|
||||
public:
|
||||
virtual int on_publish(SrsRequest* req, std::string forward_server);
|
||||
|
|
|
@ -450,7 +450,7 @@ int SrsSource::on_reload_forward(string vhost)
|
|||
srs_error("create forwarders failed. ret=%d", ret);
|
||||
return ret;
|
||||
}
|
||||
// TODO: FIXME: must feed it the sequence header.
|
||||
|
||||
srs_trace("vhost %s forwarders reload success", vhost.c_str());
|
||||
|
||||
return ret;
|
||||
|
@ -498,6 +498,28 @@ int SrsSource::on_reload_transcode(string vhost)
|
|||
return ret;
|
||||
}
|
||||
|
||||
int SrsSource::on_forwarder_start(SrsForwarder* forwarder)
|
||||
{
|
||||
int ret = ERROR_SUCCESS;
|
||||
|
||||
// feed the forwarder the metadata/sequence header,
|
||||
// when reload to enable the forwarder.
|
||||
if (cache_metadata && (ret = forwarder->on_meta_data(cache_metadata->copy())) != ERROR_SUCCESS) {
|
||||
srs_error("forwarder process onMetaData message failed. ret=%d", ret);
|
||||
return ret;
|
||||
}
|
||||
if (cache_sh_video && (ret = forwarder->on_video(cache_sh_video->copy())) != ERROR_SUCCESS) {
|
||||
srs_error("forwarder process video sequence header message failed. ret=%d", ret);
|
||||
return ret;
|
||||
}
|
||||
if (cache_sh_audio && (ret = forwarder->on_audio(cache_sh_audio->copy())) != ERROR_SUCCESS) {
|
||||
srs_error("forwarder process audio sequence header message failed. ret=%d", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool SrsSource::can_publish()
|
||||
{
|
||||
return _can_publish;
|
||||
|
@ -837,7 +859,7 @@ int SrsSource::create_forwarders()
|
|||
for (int i = 0; conf && i < (int)conf->args.size(); i++) {
|
||||
std::string forward_server = conf->args.at(i);
|
||||
|
||||
SrsForwarder* forwarder = new SrsForwarder();
|
||||
SrsForwarder* forwarder = new SrsForwarder(this);
|
||||
forwarders.push_back(forwarder);
|
||||
|
||||
if ((ret = forwarder->on_publish(req, forward_server)) != ERROR_SUCCESS) {
|
||||
|
|
|
@ -221,6 +221,9 @@ public:
|
|||
virtual int on_reload_forward(std::string vhost);
|
||||
virtual int on_reload_hls(std::string vhost);
|
||||
virtual int on_reload_transcode(std::string vhost);
|
||||
// for the SrsForwarder to callback to request the sequence headers.
|
||||
public:
|
||||
virtual int on_forwarder_start(SrsForwarder* forwarder);
|
||||
public:
|
||||
virtual bool can_publish();
|
||||
virtual int on_meta_data(SrsCommonMessage* msg, SrsOnMetaDataPacket* metadata);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue