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

HLS: support kick-off hls client #3371

Merged
merged 6 commits into from
Jan 29, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
34 changes: 33 additions & 1 deletion trunk/src/app/srs_app_http_static.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,23 @@ using namespace std;
SrsM3u8CtxInfo::SrsM3u8CtxInfo()
{
req = NULL;
interrupt = false;
}

SrsM3u8CtxInfo::~SrsM3u8CtxInfo()
{
srs_freep(req);
}

void SrsM3u8CtxInfo::expire()
{
interrupt = true;

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

SrsHlsStream::SrsHlsStream()
{
_srs_hybrid->timer5s()->subscribe(this);
Expand Down Expand Up @@ -94,6 +104,10 @@ srs_error_t SrsHlsStream::serve_m3u8_ctx(ISrsHttpResponseWriter* w, ISrsHttpMess
*served = false;
return srs_success;
}

if (is_interrupt(ctx))
return srs_error_new(ERROR_HTTP_STREAM_EOF, "HTTP stream is EOF");
duiniuluantanqin marked this conversation as resolved.
Show resolved Hide resolved
duiniuluantanqin marked this conversation as resolved.
Show resolved Hide resolved

err = serve_exists_session(w, r, factory, fullpath);
} else {
// Create a m3u8 in memory, contains the session id(ctx).
Expand Down Expand Up @@ -244,14 +258,24 @@ void SrsHlsStream::alive(std::string ctx, SrsRequest* req)
if (it == map_ctx_info_.end()) {
SrsM3u8CtxInfo *info = new SrsM3u8CtxInfo();
info->req = req->copy();
info->ctx = ctx;
info->request_time = srs_get_system_time();
map_ctx_info_.insert(make_pair(ctx, info));

// update conn of stat
SrsStatistic* stat = SrsStatistic::instance();
SrsStatisticClient* client = stat->find_client(ctx);
if (client) {
client->conn = info;
winlinvip marked this conversation as resolved.
Show resolved Hide resolved
}

return;
}

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

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

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

SrsVodStream::SrsVodStream(string root_dir) : SrsHttpFileServer(root_dir)
{
}
Expand Down
8 changes: 7 additions & 1 deletion trunk/src/app/srs_app_http_static.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,17 @@

class ISrsFileReaderFactory;

struct SrsM3u8CtxInfo
struct SrsM3u8CtxInfo: public ISrsExpire
{
srs_utime_t request_time;
SrsRequest* req;
std::string ctx;
bool interrupt;
SrsM3u8CtxInfo();
virtual ~SrsM3u8CtxInfo();
// Interface ISrsExpire.
public:
virtual void expire();
};

// Server HLS streaming.
Expand All @@ -40,6 +45,7 @@ class SrsHlsStream : public ISrsFastTimer
void alive(std::string ctx, SrsRequest* req);
srs_error_t http_hooks_on_play(SrsRequest* req);
void http_hooks_on_stop(SrsRequest* req);
bool is_interrupt(std::string id);
// interface ISrsFastTimer
private:
srs_error_t on_timer(srs_utime_t interval);
Expand Down