RTC: Refactor code.

pull/1809/head
winlin 5 years ago
parent 70d51ffc5b
commit 8ca793593d

@ -1031,7 +1031,7 @@ srs_error_t SrsRtcPlayer::on_rtcp_ps_feedback(char* buf, int nb_buf)
switch (fmt) {
case kPLI: {
SrsRtcPublisher* publisher = session_->source_->rtc_publisher();
ISrsRtcPublisher* publisher = session_->source_->rtc_publisher();
if (publisher) {
publisher->request_keyframe();
srs_trace("RTC request PLI");
@ -1088,10 +1088,9 @@ SrsRtcPublisher::SrsRtcPublisher(SrsRtcSession* session)
SrsRtcPublisher::~SrsRtcPublisher()
{
source->set_rtc_publisher(NULL);
// TODO: FIXME: Do unpublish when session timeout.
if (source) {
source->set_rtc_publisher(NULL);
source->on_unpublish();
}

@ -36,6 +36,7 @@
#include <srs_kernel_rtc_rtp.hpp>
#include <srs_kernel_rtc_rtcp.hpp>
#include <srs_app_rtc_queue.hpp>
#include <srs_app_rtc_source.hpp>
#include <string>
#include <map>
@ -248,7 +249,7 @@ private:
srs_error_t on_rtcp_rr(char* data, int nb_data);
};
class SrsRtcPublisher : virtual public ISrsHourGlass, virtual public ISrsRtpPacketDecodeHandler
class SrsRtcPublisher : virtual public ISrsHourGlass, virtual public ISrsRtpPacketDecodeHandler, virtual public ISrsRtcPublisher
{
private:
SrsHourGlass* report_timer;

@ -232,6 +232,14 @@ SrsRtcSource* SrsRtcSourceManager::fetch(SrsRequest* r)
SrsRtcSourceManager* _srs_rtc_sources = new SrsRtcSourceManager();
ISrsRtcPublisher::ISrsRtcPublisher()
{
}
ISrsRtcPublisher::~ISrsRtcPublisher()
{
}
SrsRtcSource::SrsRtcSource()
{
_source_id = _pre_source_id = -1;
@ -382,12 +390,12 @@ void SrsRtcSource::on_unpublish()
// TODO: FIXME: Handle by statistic.
}
SrsRtcPublisher* SrsRtcSource::rtc_publisher()
ISrsRtcPublisher* SrsRtcSource::rtc_publisher()
{
return rtc_publisher_;
}
void SrsRtcSource::set_rtc_publisher(SrsRtcPublisher* v)
void SrsRtcSource::set_rtc_publisher(ISrsRtcPublisher* v)
{
rtc_publisher_ = v;
}

@ -35,7 +35,6 @@
class SrsRequest;
class SrsConnection;
class SrsMetaCache;
class SrsRtcPublisher;
class SrsSharedPtrMessage;
class SrsCommonMessage;
class SrsMessageArray;
@ -94,6 +93,15 @@ private:
// Global singleton instance.
extern SrsRtcSourceManager* _srs_rtc_sources;
class ISrsRtcPublisher
{
public:
ISrsRtcPublisher();
virtual ~ISrsRtcPublisher();
public:
virtual void request_keyframe() = 0;
};
class SrsRtcSource
{
private:
@ -105,7 +113,7 @@ private:
// previous source id.
int _pre_source_id;
SrsRequest* req;
SrsRtcPublisher* rtc_publisher_;
ISrsRtcPublisher* rtc_publisher_;
// Transmux RTMP to RTC.
SrsRtcFromRtmpBridger* bridger_;
private:
@ -145,8 +153,8 @@ public:
virtual void on_unpublish();
public:
// Get and set the publisher, passed to consumer to process requests such as PLI.
SrsRtcPublisher* rtc_publisher();
void set_rtc_publisher(SrsRtcPublisher* v);
ISrsRtcPublisher* rtc_publisher();
void set_rtc_publisher(ISrsRtcPublisher* v);
// Consume the shared RTP packet, user must free it.
srs_error_t on_rtp(SrsRtpPacket2* pkt);
};

@ -27,6 +27,7 @@
#include <srs_kernel_log.hpp>
#include <vector>
#include <algorithm>
using namespace std;
SrsCoroutineManager::SrsCoroutineManager()
@ -72,7 +73,9 @@ srs_error_t SrsCoroutineManager::cycle()
void SrsCoroutineManager::remove(ISrsConnection* c)
{
conns.push_back(c);
if (::find(conns.begin(), conns.end(), c) == conns.end()) {
conns.push_back(c);
}
srs_cond_signal(cond);
}
@ -80,8 +83,8 @@ void SrsCoroutineManager::clear()
{
// To prevent thread switch when delete connection,
// we copy all connections then free one by one.
vector<ISrsConnection*> copy = conns;
conns.clear();
vector<ISrsConnection*> copy;
copy.swap(conns);
vector<ISrsConnection*>::iterator it;
for (it = copy.begin(); it != copy.end(); ++it) {

Loading…
Cancel
Save