Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[deprecated]HLS: support kick-off hls client #3353

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion trunk/src/app/srs_app_conn.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ class ISrsExpire
virtual ~ISrsExpire();
public:
// Set connection to expired to kick-off it.
virtual void expire() = 0;
virtual void expire(std::string id) = 0;
};

// The basic connection of SRS, for TCP based protocols,
Expand Down
2 changes: 1 addition & 1 deletion trunk/src/app/srs_app_http_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -847,7 +847,7 @@ srs_error_t SrsGoApiClients::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessa
}

if (client->conn) {
client->conn->expire();
client->conn->expire(client_id);
srs_warn("kickoff client id=%s ok", client_id.c_str());
} else {
srs_error("kickoff client id=%s error", client_id.c_str());
Expand Down
2 changes: 1 addition & 1 deletion trunk/src/app/srs_app_http_conn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ const SrsContextId& SrsHttpConn::get_id()
return trd->cid();
}

void SrsHttpConn::expire()
void SrsHttpConn::expire(std::string id)
{
trd->interrupt();
}
Expand Down
2 changes: 1 addition & 1 deletion trunk/src/app/srs_app_http_conn.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ class SrsHttpConn : public ISrsConnection, public ISrsStartable, public ISrsCoro
virtual const SrsContextId& get_id();
// Interface ISrsExpire.
public:
virtual void expire();
virtual void expire(std::string id);
};

// Drop body of request, only process the response.
Expand Down
31 changes: 29 additions & 2 deletions trunk/src/app/srs_app_http_static.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ using namespace std;
SrsM3u8CtxInfo::SrsM3u8CtxInfo()
{
req = NULL;
alive = true;
}

SrsM3u8CtxInfo::~SrsM3u8CtxInfo()
Expand Down Expand Up @@ -94,6 +95,10 @@ srs_error_t SrsHlsStream::serve_m3u8_ctx(ISrsHttpResponseWriter* w, ISrsHttpMess
*served = false;
return srs_success;
}

if (!can_serve_m3u8(ctx))
return srs_error_new(ERROR_HTTP_STREAM_EOF, "HTTP stream is EOF");

err = serve_exists_session(w, r, factory, fullpath);
} else {
// Create a m3u8 in memory, contains the session id(ctx).
Expand Down Expand Up @@ -147,7 +152,7 @@ srs_error_t SrsHlsStream::serve_new_session(ISrsHttpResponseWriter* w, ISrsHttpM

// We must do stat the client before hooks, because hooks depends on it.
SrsStatistic* stat = SrsStatistic::instance();
if ((err = stat->on_client(ctx, req, NULL, SrsHlsPlay)) != srs_success) {
if ((err = stat->on_client(ctx, req, this, SrsHlsPlay)) != srs_success) {
return srs_error_wrap(err, "stat on client");
}

Expand Down Expand Up @@ -251,7 +256,8 @@ void SrsHlsStream::alive(std::string ctx, SrsRequest* req)

// Update alive time of context.
SrsM3u8CtxInfo* info = it->second;
info->request_time = srs_get_system_time();
if (info->alive)
info->request_time = srs_get_system_time();
}

srs_error_t SrsHlsStream::http_hooks_on_play(SrsRequest* req)
Expand Down Expand Up @@ -347,6 +353,27 @@ srs_error_t SrsHlsStream::on_timer(srs_utime_t interval)
return err;
}

void SrsHlsStream::expire(std::string id)
{
std::map<std::string, SrsM3u8CtxInfo*>::iterator it = map_ctx_info_.find(id);
if (it != map_ctx_info_.end()) {
SrsM3u8CtxInfo* info = it->second;
info->alive = false;

// remove statistic quickly
SrsStatistic* stat = SrsStatistic::instance();
stat->on_disconnect(id, srs_success);
}
}

bool SrsHlsStream::can_serve_m3u8(std::string id) {
std::map<std::string, SrsM3u8CtxInfo*>::iterator it = map_ctx_info_.find(id);
if (it != map_ctx_info_.end()) {
return it->second->alive;
}
return true;
}

SrsVodStream::SrsVodStream(string root_dir) : SrsHttpFileServer(root_dir)
{
}
Expand Down
7 changes: 6 additions & 1 deletion trunk/src/app/srs_app_http_static.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@ struct SrsM3u8CtxInfo
{
srs_utime_t request_time;
SrsRequest* req;
bool alive;
SrsM3u8CtxInfo();
virtual ~SrsM3u8CtxInfo();
};

// Server HLS streaming.
class SrsHlsStream : public ISrsFastTimer
class SrsHlsStream : public ISrsFastTimer, public ISrsExpire
{
private:
// The period of validity of the ctx
Expand All @@ -33,13 +34,17 @@ class SrsHlsStream : public ISrsFastTimer
public:
virtual srs_error_t serve_m3u8_ctx(ISrsHttpResponseWriter* w, ISrsHttpMessage* r, ISrsFileReaderFactory* factory, std::string fullpath, SrsRequest* req, bool* served);
virtual void on_serve_ts_ctx(ISrsHttpResponseWriter* w, ISrsHttpMessage* r);
// Interface ISrsExpire.
public:
virtual void expire(std::string id);
private:
srs_error_t serve_new_session(ISrsHttpResponseWriter* w, ISrsHttpMessage* r, SrsRequest *req, std::string& ctx);
srs_error_t serve_exists_session(ISrsHttpResponseWriter* w, ISrsHttpMessage* r, ISrsFileReaderFactory* factory, std::string fullpath);
bool ctx_is_exist(std::string ctx);
void alive(std::string ctx, SrsRequest* req);
srs_error_t http_hooks_on_play(SrsRequest* req);
void http_hooks_on_stop(SrsRequest* req);
bool can_serve_m3u8(std::string id);
// interface ISrsFastTimer
private:
srs_error_t on_timer(srs_utime_t interval);
Expand Down
2 changes: 1 addition & 1 deletion trunk/src/app/srs_app_rtc_conn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1871,7 +1871,7 @@ std::string SrsRtcConnection::desc()
return "RtcConn";
}

void SrsRtcConnection::expire()
void SrsRtcConnection::expire(std::string id)
{
_srs_rtc_manager->remove(this);
}
Expand Down
2 changes: 1 addition & 1 deletion trunk/src/app/srs_app_rtc_conn.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ class SrsRtcConnection : public ISrsResource, public ISrsDisposingHandler, publi
virtual std::string desc();
// Interface ISrsExpire.
public:
virtual void expire();
virtual void expire(std::string id);
public:
void switch_to_context();
const SrsContextId& context_id();
Expand Down
2 changes: 1 addition & 1 deletion trunk/src/app/srs_app_rtmp_conn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1635,7 +1635,7 @@ const SrsContextId& SrsRtmpConn::get_id()
return trd->cid();
}

void SrsRtmpConn::expire()
void SrsRtmpConn::expire(std::string id)
{
trd->interrupt();
}
Expand Down
2 changes: 1 addition & 1 deletion trunk/src/app/srs_app_rtmp_conn.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ class SrsRtmpConn : public ISrsConnection, public ISrsStartable, public ISrsRelo
virtual const SrsContextId& get_id();
// Interface ISrsExpire.
public:
virtual void expire();
virtual void expire(std::string id);
};

#endif
Expand Down
2 changes: 1 addition & 1 deletion trunk/src/app/srs_app_srt_conn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ ISrsKbpsDelta* SrsMpegtsSrtConn::delta()
return delta_;
}

void SrsMpegtsSrtConn::expire()
void SrsMpegtsSrtConn::expire(std::string id)
{
trd_->interrupt();
}
Expand Down
2 changes: 1 addition & 1 deletion trunk/src/app/srs_app_srt_conn.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class SrsMpegtsSrtConn : public ISrsConnection, public ISrsStartable, public ISr
ISrsKbpsDelta* delta();
// Interface ISrsExpire
public:
virtual void expire();
virtual void expire(std::string id);
public:
virtual srs_error_t start();
// Interface ISrsConnection.
Expand Down