mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
refine hls notify, support timeout.
This commit is contained in:
parent
d8988da0ea
commit
1f93fb3399
4 changed files with 19 additions and 10 deletions
|
@ -37,15 +37,13 @@ using namespace std;
|
||||||
#include <srs_app_utility.hpp>
|
#include <srs_app_utility.hpp>
|
||||||
#include <srs_core_autofree.hpp>
|
#include <srs_core_autofree.hpp>
|
||||||
|
|
||||||
// when error, http client sleep for a while and retry.
|
|
||||||
#define SRS_HTTP_CLIENT_SLEEP_US (int64_t)(3*1000*1000LL)
|
|
||||||
|
|
||||||
SrsHttpClient::SrsHttpClient()
|
SrsHttpClient::SrsHttpClient()
|
||||||
{
|
{
|
||||||
connected = false;
|
connected = false;
|
||||||
stfd = NULL;
|
stfd = NULL;
|
||||||
skt = NULL;
|
skt = NULL;
|
||||||
parser = NULL;
|
parser = NULL;
|
||||||
|
timeout_us = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsHttpClient::~SrsHttpClient()
|
SrsHttpClient::~SrsHttpClient()
|
||||||
|
@ -54,7 +52,7 @@ SrsHttpClient::~SrsHttpClient()
|
||||||
srs_freep(parser);
|
srs_freep(parser);
|
||||||
}
|
}
|
||||||
|
|
||||||
int SrsHttpClient::initialize(string h, int p)
|
int SrsHttpClient::initialize(string h, int p, int64_t t_us)
|
||||||
{
|
{
|
||||||
int ret = ERROR_SUCCESS;
|
int ret = ERROR_SUCCESS;
|
||||||
|
|
||||||
|
@ -68,6 +66,7 @@ int SrsHttpClient::initialize(string h, int p)
|
||||||
|
|
||||||
host = h;
|
host = h;
|
||||||
port = p;
|
port = p;
|
||||||
|
timeout_us = t_us;
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -183,10 +182,9 @@ int SrsHttpClient::connect()
|
||||||
disconnect();
|
disconnect();
|
||||||
|
|
||||||
// open socket.
|
// open socket.
|
||||||
int64_t timeout = SRS_HTTP_CLIENT_SLEEP_US;
|
if ((ret = srs_socket_connect(host, port, timeout_us, &stfd)) != ERROR_SUCCESS) {
|
||||||
if ((ret = srs_socket_connect(host, port, timeout, &stfd)) != ERROR_SUCCESS) {
|
|
||||||
srs_warn("http client failed, server=%s, port=%d, timeout=%"PRId64", ret=%d",
|
srs_warn("http client failed, server=%s, port=%d, timeout=%"PRId64", ret=%d",
|
||||||
host.c_str(), port, timeout, ret);
|
host.c_str(), port, timeout_us, ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
srs_info("connect to server success. server=%s, port=%d", host, port);
|
srs_info("connect to server success. server=%s, port=%d", host, port);
|
||||||
|
@ -195,6 +193,10 @@ int SrsHttpClient::connect()
|
||||||
skt = new SrsStSocket(stfd);
|
skt = new SrsStSocket(stfd);
|
||||||
connected = true;
|
connected = true;
|
||||||
|
|
||||||
|
// set the recv/send timeout in us.
|
||||||
|
skt->set_recv_timeout(timeout_us);
|
||||||
|
skt->set_send_timeout(timeout_us);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,6 +40,9 @@ class SrsHttpParser;
|
||||||
class SrsHttpMessage;
|
class SrsHttpMessage;
|
||||||
class SrsStSocket;
|
class SrsStSocket;
|
||||||
|
|
||||||
|
// the default timeout for http client.
|
||||||
|
#define SRS_HTTP_CLIENT_TIMEOUT_US (int64_t)(30*1000*1000LL)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* http client to GET/POST/PUT/DELETE uri
|
* http client to GET/POST/PUT/DELETE uri
|
||||||
*/
|
*/
|
||||||
|
@ -51,6 +54,7 @@ private:
|
||||||
SrsStSocket* skt;
|
SrsStSocket* skt;
|
||||||
SrsHttpParser* parser;
|
SrsHttpParser* parser;
|
||||||
private:
|
private:
|
||||||
|
int64_t timeout_us;
|
||||||
// host name or ip.
|
// host name or ip.
|
||||||
std::string host;
|
std::string host;
|
||||||
int port;
|
int port;
|
||||||
|
@ -61,7 +65,7 @@ public:
|
||||||
/**
|
/**
|
||||||
* initialize the client, connect to host and port.
|
* initialize the client, connect to host and port.
|
||||||
*/
|
*/
|
||||||
virtual int initialize(std::string h, int p);
|
virtual int initialize(std::string h, int p, int64_t t_us = SRS_HTTP_CLIENT_TIMEOUT_US);
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* to post data to the uri.
|
* to post data to the uri.
|
||||||
|
|
|
@ -44,6 +44,9 @@ using namespace std;
|
||||||
#define SRS_HTTP_HEADER_BUFFER 1024
|
#define SRS_HTTP_HEADER_BUFFER 1024
|
||||||
#define SRS_HTTP_BODY_BUFFER 32 * 1024
|
#define SRS_HTTP_BODY_BUFFER 32 * 1024
|
||||||
|
|
||||||
|
// the timeout for hls notify, in us.
|
||||||
|
#define SRS_HLS_NOTIFY_TIMEOUT_US (int64_t)(10*1000*1000LL)
|
||||||
|
|
||||||
SrsHttpHooks::SrsHttpHooks()
|
SrsHttpHooks::SrsHttpHooks()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -350,7 +353,7 @@ int SrsHttpHooks::on_hls_notify(std::string url, SrsRequest* req, std::string ts
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsHttpClient http;
|
SrsHttpClient http;
|
||||||
if ((ret = http.initialize(uri.get_host(), uri.get_port())) != ERROR_SUCCESS) {
|
if ((ret = http.initialize(uri.get_host(), uri.get_port(), SRS_HLS_NOTIFY_TIMEOUT_US)) != ERROR_SUCCESS) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -390,7 +390,7 @@ bool srs_aac_startswith_adts(SrsStream* stream)
|
||||||
char* bytes = stream->data() + stream->pos();
|
char* bytes = stream->data() + stream->pos();
|
||||||
char* p = bytes;
|
char* p = bytes;
|
||||||
|
|
||||||
if (!stream->require(p - bytes + 2)) {
|
if (!stream->require((int)(p - bytes) + 2)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue