mirror of
https://github.com/ossrs/srs.git
synced 2025-02-13 11:51:57 +00:00
SRT: Change bridges to bridge.
This commit is contained in:
parent
077d93c7b6
commit
e09daa2d4b
5 changed files with 17 additions and 57 deletions
|
@ -344,8 +344,8 @@ SrsRtcSource::~SrsRtcSource()
|
||||||
// for all consumers are auto free.
|
// for all consumers are auto free.
|
||||||
consumers.clear();
|
consumers.clear();
|
||||||
|
|
||||||
srs_freep(req);
|
|
||||||
srs_freep(bridge_);
|
srs_freep(bridge_);
|
||||||
|
srs_freep(req);
|
||||||
srs_freep(stream_desc_);
|
srs_freep(stream_desc_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -39,7 +39,6 @@ using namespace std;
|
||||||
#include <srs_protocol_utility.hpp>
|
#include <srs_protocol_utility.hpp>
|
||||||
#include <srs_protocol_json.hpp>
|
#include <srs_protocol_json.hpp>
|
||||||
#include <srs_app_rtc_source.hpp>
|
#include <srs_app_rtc_source.hpp>
|
||||||
#include <srs_app_srt_source.hpp>
|
|
||||||
|
|
||||||
// the timeout in srs_utime_t to wait encoder to republish
|
// the timeout in srs_utime_t to wait encoder to republish
|
||||||
// if timeout, close the connection.
|
// if timeout, close the connection.
|
||||||
|
|
|
@ -468,23 +468,6 @@ public:
|
||||||
// Global singleton instance.
|
// Global singleton instance.
|
||||||
extern SrsLiveSourceManager* _srs_sources;
|
extern SrsLiveSourceManager* _srs_sources;
|
||||||
|
|
||||||
// Destination type.
|
|
||||||
enum SrsBridgeDestType {
|
|
||||||
SrsBridgeDestTypeRtmp = 1,
|
|
||||||
SrsBridgeDestTypeRTC = 2,
|
|
||||||
SrsBridgeDestTypeSRT = 3,
|
|
||||||
};
|
|
||||||
|
|
||||||
class ISrsBridge {
|
|
||||||
public:
|
|
||||||
ISrsBridge(SrsBridgeDestType type);
|
|
||||||
virtual ~ISrsBridge();
|
|
||||||
public:
|
|
||||||
SrsBridgeDestType get_type() const;
|
|
||||||
protected:
|
|
||||||
SrsBridgeDestType type_;
|
|
||||||
};
|
|
||||||
|
|
||||||
// For RTMP2RTC, bridge SrsLiveSource to SrsRtcSource
|
// For RTMP2RTC, bridge SrsLiveSource to SrsRtcSource
|
||||||
class ISrsLiveSourceBridge
|
class ISrsLiveSourceBridge
|
||||||
{
|
{
|
||||||
|
|
|
@ -234,7 +234,7 @@ void SrsSrtConsumer::wait(int nb_msgs, srs_utime_t timeout)
|
||||||
srs_cond_timedwait(mw_wait, timeout);
|
srs_cond_timedwait(mw_wait, timeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
ISrsSrtSourceBridge::ISrsSrtSourceBridge(SrsBridgeDestType type) : ISrsBridge(type)
|
ISrsSrtSourceBridge::ISrsSrtSourceBridge()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -242,8 +242,7 @@ ISrsSrtSourceBridge::~ISrsSrtSourceBridge()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsRtmpFromSrtBridge::SrsRtmpFromSrtBridge(SrsLiveSource* source)
|
SrsRtmpFromSrtBridge::SrsRtmpFromSrtBridge(SrsLiveSource* source) : ISrsSrtSourceBridge()
|
||||||
: ISrsSrtSourceBridge(SrsBridgeDestTypeRtmp)
|
|
||||||
{
|
{
|
||||||
ts_ctx_ = new SrsTsContext();
|
ts_ctx_ = new SrsTsContext();
|
||||||
|
|
||||||
|
@ -645,6 +644,7 @@ SrsSrtSource::SrsSrtSource()
|
||||||
{
|
{
|
||||||
req = NULL;
|
req = NULL;
|
||||||
can_publish_ = true;
|
can_publish_ = true;
|
||||||
|
bridge_ = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsSrtSource::~SrsSrtSource()
|
SrsSrtSource::~SrsSrtSource()
|
||||||
|
@ -653,11 +653,7 @@ SrsSrtSource::~SrsSrtSource()
|
||||||
// for all consumers are auto free.
|
// for all consumers are auto free.
|
||||||
consumers.clear();
|
consumers.clear();
|
||||||
|
|
||||||
for (vector<ISrsSrtSourceBridge*>::iterator iter = bridgers_.begin(); iter != bridgers_.end(); ++iter) {
|
srs_freep(bridge_);
|
||||||
ISrsSrtSourceBridge* bridge = *iter;
|
|
||||||
srs_freep(bridge);
|
|
||||||
}
|
|
||||||
bridgers_.clear();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
srs_error_t SrsSrtSource::initialize(SrsRequest* r)
|
srs_error_t SrsSrtSource::initialize(SrsRequest* r)
|
||||||
|
@ -707,18 +703,10 @@ void SrsSrtSource::update_auth(SrsRequest* r)
|
||||||
req->update_auth(r);
|
req->update_auth(r);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SrsSrtSource::set_bridger(ISrsSrtSourceBridge *bridger)
|
void SrsSrtSource::set_bridge(ISrsSrtSourceBridge* bridge)
|
||||||
{
|
{
|
||||||
for (vector<ISrsSrtSourceBridge*>::iterator iter = bridgers_.begin(); iter != bridgers_.end(); ++iter) {
|
srs_freep(bridge_);
|
||||||
ISrsSrtSourceBridge* b = *iter;
|
bridge_ = bridge;
|
||||||
if (b->get_type() == bridger->get_type()) {
|
|
||||||
srs_freep(b);
|
|
||||||
*iter = bridger;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bridgers_.push_back(bridger);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
srs_error_t SrsSrtSource::create_consumer(SrsSrtConsumer*& consumer)
|
srs_error_t SrsSrtSource::create_consumer(SrsSrtConsumer*& consumer)
|
||||||
|
@ -765,11 +753,8 @@ srs_error_t SrsSrtSource::on_publish()
|
||||||
return srs_error_wrap(err, "source id change");
|
return srs_error_wrap(err, "source id change");
|
||||||
}
|
}
|
||||||
|
|
||||||
for (vector<ISrsSrtSourceBridge*>::iterator iter = bridgers_.begin(); iter != bridgers_.end(); ++iter) {
|
if ((err = bridge_->on_publish()) != srs_success) {
|
||||||
ISrsSrtSourceBridge* bridge = *iter;
|
return srs_error_wrap(err, "bridge on publish");
|
||||||
if ((err = bridge->on_publish()) != srs_success) {
|
|
||||||
return srs_error_wrap(err, "bridger on publish");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsStatistic* stat = SrsStatistic::instance();
|
SrsStatistic* stat = SrsStatistic::instance();
|
||||||
|
@ -787,12 +772,8 @@ void SrsSrtSource::on_unpublish()
|
||||||
|
|
||||||
can_publish_ = true;
|
can_publish_ = true;
|
||||||
|
|
||||||
for (vector<ISrsSrtSourceBridge*>::iterator iter = bridgers_.begin(); iter != bridgers_.end(); ++iter) {
|
bridge_->on_unpublish();
|
||||||
ISrsSrtSourceBridge* bridge = *iter;
|
srs_freep(bridge_);
|
||||||
bridge->on_unpublish();
|
|
||||||
srs_freep(bridge);
|
|
||||||
}
|
|
||||||
bridgers_.clear();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
srs_error_t SrsSrtSource::on_packet(SrsSrtPacket* packet)
|
srs_error_t SrsSrtSource::on_packet(SrsSrtPacket* packet)
|
||||||
|
@ -806,11 +787,8 @@ srs_error_t SrsSrtSource::on_packet(SrsSrtPacket* packet)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (vector<ISrsSrtSourceBridge*>::iterator iter = bridgers_.begin(); iter != bridgers_.end(); ++iter) {
|
if ((err = bridge_->on_packet(packet)) != srs_success) {
|
||||||
ISrsSrtSourceBridge* bridge = *iter;
|
return srs_error_wrap(err, "bridge consume message");
|
||||||
if ((err = bridge->on_packet(packet)) != srs_success) {
|
|
||||||
return srs_error_wrap(err, "bridger consume message");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return err;
|
return err;
|
||||||
|
|
|
@ -90,10 +90,10 @@ public:
|
||||||
virtual void wait(int nb_msgs, srs_utime_t timeout);
|
virtual void wait(int nb_msgs, srs_utime_t timeout);
|
||||||
};
|
};
|
||||||
|
|
||||||
class ISrsSrtSourceBridge : public ISrsBridge
|
class ISrsSrtSourceBridge
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ISrsSrtSourceBridge(SrsBridgeDestType type);
|
ISrsSrtSourceBridge();
|
||||||
virtual ~ISrsSrtSourceBridge();
|
virtual ~ISrsSrtSourceBridge();
|
||||||
public:
|
public:
|
||||||
virtual srs_error_t on_publish() = 0;
|
virtual srs_error_t on_publish() = 0;
|
||||||
|
@ -179,7 +179,7 @@ private:
|
||||||
// To delivery packets to clients.
|
// To delivery packets to clients.
|
||||||
std::vector<SrsSrtConsumer*> consumers;
|
std::vector<SrsSrtConsumer*> consumers;
|
||||||
bool can_publish_;
|
bool can_publish_;
|
||||||
std::vector<ISrsSrtSourceBridge*> bridgers_;
|
ISrsSrtSourceBridge* bridge_;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue