winlin

refine code for hooks and http core.

@@ -147,7 +147,7 @@ int main(int argc, char** argv) @@ -147,7 +147,7 @@ int main(int argc, char** argv)
147 goto rtmp_destroy; 147 goto rtmp_destroy;
148 } 148 }
149 149
150 - if ((timestamp - basetime) > duration * 1000) { 150 + if (timestamp > basetime && (timestamp - basetime) > duration * 1000) {
151 srs_human_trace("duration exceed, terminate."); 151 srs_human_trace("duration exceed, terminate.");
152 goto rtmp_destroy; 152 goto rtmp_destroy;
153 } 153 }
@@ -4522,19 +4522,21 @@ bool SrsConfig::get_mix_correct(string vhost) @@ -4522,19 +4522,21 @@ bool SrsConfig::get_mix_correct(string vhost)
4522 4522
4523 double SrsConfig::get_queue_length(string vhost) 4523 double SrsConfig::get_queue_length(string vhost)
4524 { 4524 {
  4525 + static double DEFAULT = SRS_PERF_PLAY_QUEUE;
  4526 +
4525 SrsConfDirective* conf = get_vhost(vhost); 4527 SrsConfDirective* conf = get_vhost(vhost);
4526 if (!conf) { 4528 if (!conf) {
4527 - return SRS_PERF_PLAY_QUEUE; 4529 + return DEFAULT;
4528 } 4530 }
4529 4531
4530 conf = conf->get("play"); 4532 conf = conf->get("play");
4531 if (!conf || conf->arg0().empty()) { 4533 if (!conf || conf->arg0().empty()) {
4532 - return SRS_PERF_GOP_CACHE; 4534 + return DEFAULT;
4533 } 4535 }
4534 4536
4535 conf = conf->get("queue_length"); 4537 conf = conf->get("queue_length");
4536 if (!conf || conf->arg0().empty()) { 4538 if (!conf || conf->arg0().empty()) {
4537 - return SRS_PERF_PLAY_QUEUE; 4539 + return DEFAULT;
4538 } 4540 }
4539 4541
4540 return ::atoi(conf->arg0().c_str()); 4542 return ::atoi(conf->arg0().c_str());
@@ -48,16 +48,16 @@ using namespace std; @@ -48,16 +48,16 @@ using namespace std;
48 #include <srs_app_rtmp_conn.hpp> 48 #include <srs_app_rtmp_conn.hpp>
49 49
50 // when error, edge ingester sleep for a while and retry. 50 // when error, edge ingester sleep for a while and retry.
51 -#define SRS_EDGE_INGESTER_SLEEP_US (int64_t)(1*1000*1000LL) 51 +#define SRS_EDGE_INGESTER_SLEEP_US (int64_t)(3*1000*1000LL)
52 52
53 // when edge timeout, retry next. 53 // when edge timeout, retry next.
54 -#define SRS_EDGE_INGESTER_TIMEOUT_US (int64_t)(3*1000*1000LL) 54 +#define SRS_EDGE_INGESTER_TIMEOUT_US (int64_t)(5*1000*1000LL)
55 55
56 // when error, edge ingester sleep for a while and retry. 56 // when error, edge ingester sleep for a while and retry.
57 -#define SRS_EDGE_FORWARDER_SLEEP_US (int64_t)(1*1000*1000LL) 57 +#define SRS_EDGE_FORWARDER_SLEEP_US (int64_t)(3*1000*1000LL)
58 58
59 // when edge timeout, retry next. 59 // when edge timeout, retry next.
60 -#define SRS_EDGE_FORWARDER_TIMEOUT_US (int64_t)(3*1000*1000LL) 60 +#define SRS_EDGE_FORWARDER_TIMEOUT_US (int64_t)(5*1000*1000LL)
61 61
62 // when edge error, wait for quit 62 // when edge error, wait for quit
63 #define SRS_EDGE_FORWARDER_ERROR_US (int64_t)(50*1000LL) 63 #define SRS_EDGE_FORWARDER_ERROR_US (int64_t)(50*1000LL)
@@ -36,10 +36,12 @@ using namespace std; @@ -36,10 +36,12 @@ using namespace std;
36 #include <srs_app_utility.hpp> 36 #include <srs_app_utility.hpp>
37 #include <srs_core_autofree.hpp> 37 #include <srs_core_autofree.hpp>
38 #include <srs_app_http_conn.hpp> 38 #include <srs_app_http_conn.hpp>
  39 +#include <srs_protocol_kbps.hpp>
39 40
40 SrsHttpClient::SrsHttpClient() 41 SrsHttpClient::SrsHttpClient()
41 { 42 {
42 transport = new SrsTcpClient(); 43 transport = new SrsTcpClient();
  44 + kbps = new SrsKbps();
43 parser = NULL; 45 parser = NULL;
44 timeout_us = 0; 46 timeout_us = 0;
45 port = 0; 47 port = 0;
@@ -49,6 +51,7 @@ SrsHttpClient::~SrsHttpClient() @@ -49,6 +51,7 @@ SrsHttpClient::~SrsHttpClient()
49 { 51 {
50 disconnect(); 52 disconnect();
51 53
  54 + srs_freep(kbps);
52 srs_freep(transport); 55 srs_freep(transport);
53 srs_freep(parser); 56 srs_freep(parser);
54 } 57 }
@@ -74,15 +77,37 @@ int SrsHttpClient::initialize(string h, int p, int64_t t_us) @@ -74,15 +77,37 @@ int SrsHttpClient::initialize(string h, int p, int64_t t_us)
74 port = p; 77 port = p;
75 timeout_us = t_us; 78 timeout_us = t_us;
76 79
  80 + // ep used for host in header.
  81 + string ep = host;
  82 + if (port > 0 && port != SRS_CONSTS_HTTP_DEFAULT_PORT) {
  83 + ep += ":" + srs_int2str(port);
  84 + }
  85 +
  86 + // set default value for headers.
  87 + headers["Host"] = ep;
  88 + headers["Connection"] = "Keep-Alive";
  89 + headers["User-Agent"] = RTMP_SIG_SRS_SERVER;
  90 + headers["Content-Type"] = "application/json";
  91 +
77 return ret; 92 return ret;
78 } 93 }
79 94
  95 +SrsHttpClient* SrsHttpClient::set_header(string k, string v)
  96 +{
  97 + headers[k] = v;
  98 +
  99 + return this;
  100 +}
  101 +
80 int SrsHttpClient::post(string path, string req, ISrsHttpMessage** ppmsg) 102 int SrsHttpClient::post(string path, string req, ISrsHttpMessage** ppmsg)
81 { 103 {
82 *ppmsg = NULL; 104 *ppmsg = NULL;
83 105
84 int ret = ERROR_SUCCESS; 106 int ret = ERROR_SUCCESS;
85 107
  108 + // always set the content length.
  109 + headers["Content-Length"] = srs_int2str(req.length());
  110 +
86 if ((ret = connect()) != ERROR_SUCCESS) { 111 if ((ret = connect()) != ERROR_SUCCESS) {
87 srs_warn("http connect server failed. ret=%d", ret); 112 srs_warn("http connect server failed. ret=%d", ret);
88 return ret; 113 return ret;
@@ -91,15 +116,13 @@ int SrsHttpClient::post(string path, string req, ISrsHttpMessage** ppmsg) @@ -91,15 +116,13 @@ int SrsHttpClient::post(string path, string req, ISrsHttpMessage** ppmsg)
91 // send POST request to uri 116 // send POST request to uri
92 // POST %s HTTP/1.1\r\nHost: %s\r\nContent-Length: %d\r\n\r\n%s 117 // POST %s HTTP/1.1\r\nHost: %s\r\nContent-Length: %d\r\n\r\n%s
93 std::stringstream ss; 118 std::stringstream ss;
94 - ss << "POST " << path << " "  
95 - << "HTTP/1.1" << SRS_HTTP_CRLF  
96 - << "Host: " << host << SRS_HTTP_CRLF  
97 - << "Connection: Keep-Alive" << SRS_HTTP_CRLF  
98 - << "Content-Length: " << std::dec << req.length() << SRS_HTTP_CRLF  
99 - << "User-Agent: " << RTMP_SIG_SRS_NAME << RTMP_SIG_SRS_VERSION << SRS_HTTP_CRLF  
100 - << "Content-Type: application/json" << SRS_HTTP_CRLF  
101 - << SRS_HTTP_CRLF  
102 - << req; 119 + ss << "POST " << path << " " << "HTTP/1.1" << SRS_HTTP_CRLF;
  120 + for (map<string, string>::iterator it = headers.begin(); it != headers.end(); ++it) {
  121 + string key = it->first;
  122 + string value = it->second;
  123 + ss << key << ": " << value << SRS_HTTP_CRLF;
  124 + }
  125 + ss << SRS_HTTP_CRLF << req;
103 126
104 std::string data = ss.str(); 127 std::string data = ss.str();
105 if ((ret = transport->write((void*)data.c_str(), data.length(), NULL)) != ERROR_SUCCESS) { 128 if ((ret = transport->write((void*)data.c_str(), data.length(), NULL)) != ERROR_SUCCESS) {
@@ -123,11 +146,14 @@ int SrsHttpClient::post(string path, string req, ISrsHttpMessage** ppmsg) @@ -123,11 +146,14 @@ int SrsHttpClient::post(string path, string req, ISrsHttpMessage** ppmsg)
123 return ret; 146 return ret;
124 } 147 }
125 148
126 -int SrsHttpClient::get(string path, std::string req, ISrsHttpMessage** ppmsg) 149 +int SrsHttpClient::get(string path, string req, ISrsHttpMessage** ppmsg)
127 { 150 {
128 *ppmsg = NULL; 151 *ppmsg = NULL;
129 152
130 int ret = ERROR_SUCCESS; 153 int ret = ERROR_SUCCESS;
  154 +
  155 + // always set the content length.
  156 + headers["Content-Length"] = srs_int2str(req.length());
131 157
132 if ((ret = connect()) != ERROR_SUCCESS) { 158 if ((ret = connect()) != ERROR_SUCCESS) {
133 srs_warn("http connect server failed. ret=%d", ret); 159 srs_warn("http connect server failed. ret=%d", ret);
@@ -137,15 +163,13 @@ int SrsHttpClient::get(string path, std::string req, ISrsHttpMessage** ppmsg) @@ -137,15 +163,13 @@ int SrsHttpClient::get(string path, std::string req, ISrsHttpMessage** ppmsg)
137 // send POST request to uri 163 // send POST request to uri
138 // GET %s HTTP/1.1\r\nHost: %s\r\nContent-Length: %d\r\n\r\n%s 164 // GET %s HTTP/1.1\r\nHost: %s\r\nContent-Length: %d\r\n\r\n%s
139 std::stringstream ss; 165 std::stringstream ss;
140 - ss << "GET " << path << " "  
141 - << "HTTP/1.1" << SRS_HTTP_CRLF  
142 - << "Host: " << host << SRS_HTTP_CRLF  
143 - << "Connection: Keep-Alive" << SRS_HTTP_CRLF  
144 - << "Content-Length: " << std::dec << req.length() << SRS_HTTP_CRLF  
145 - << "User-Agent: " << RTMP_SIG_SRS_NAME << RTMP_SIG_SRS_VERSION << SRS_HTTP_CRLF  
146 - << "Content-Type: application/json" << SRS_HTTP_CRLF  
147 - << SRS_HTTP_CRLF  
148 - << req; 166 + ss << "GET " << path << " " << "HTTP/1.1" << SRS_HTTP_CRLF;
  167 + for (map<string, string>::iterator it = headers.begin(); it != headers.end(); ++it) {
  168 + string key = it->first;
  169 + string value = it->second;
  170 + ss << key << ": " << value << SRS_HTTP_CRLF;
  171 + }
  172 + ss << SRS_HTTP_CRLF << req;
149 173
150 std::string data = ss.str(); 174 std::string data = ss.str();
151 if ((ret = transport->write((void*)data.c_str(), data.length(), NULL)) != ERROR_SUCCESS) { 175 if ((ret = transport->write((void*)data.c_str(), data.length(), NULL)) != ERROR_SUCCESS) {
@@ -169,8 +193,28 @@ int SrsHttpClient::get(string path, std::string req, ISrsHttpMessage** ppmsg) @@ -169,8 +193,28 @@ int SrsHttpClient::get(string path, std::string req, ISrsHttpMessage** ppmsg)
169 return ret; 193 return ret;
170 } 194 }
171 195
  196 +void SrsHttpClient::set_recv_timeout(int64_t timeout)
  197 +{
  198 + transport->set_recv_timeout(timeout);
  199 +}
  200 +
  201 +void SrsHttpClient::kbps_sample(const char* label, int64_t age)
  202 +{
  203 + kbps->sample();
  204 +
  205 + int sr = kbps->get_send_kbps();
  206 + int sr30s = kbps->get_send_kbps_30s();
  207 + int sr5m = kbps->get_send_kbps_5m();
  208 + int rr = kbps->get_recv_kbps();
  209 + int rr30s = kbps->get_recv_kbps_30s();
  210 + int rr5m = kbps->get_recv_kbps_5m();
  211 +
  212 + srs_trace("<- %s time=%"PRId64", okbps=%d,%d,%d, ikbps=%d,%d,%d", label, age, sr, sr30s, sr5m, rr, rr30s, rr5m);
  213 +}
  214 +
172 void SrsHttpClient::disconnect() 215 void SrsHttpClient::disconnect()
173 { 216 {
  217 + kbps->set_io(NULL, NULL);
174 transport->close(); 218 transport->close();
175 } 219 }
176 220
@@ -196,6 +240,8 @@ int SrsHttpClient::connect() @@ -196,6 +240,8 @@ int SrsHttpClient::connect()
196 transport->set_recv_timeout(timeout_us); 240 transport->set_recv_timeout(timeout_us);
197 transport->set_send_timeout(timeout_us); 241 transport->set_send_timeout(timeout_us);
198 242
  243 + kbps->set_io(transport, transport);
  244 +
199 return ret; 245 return ret;
200 } 246 }
201 247
@@ -30,6 +30,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. @@ -30,6 +30,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 #include <srs_core.hpp> 30 #include <srs_core.hpp>
31 31
32 #include <string> 32 #include <string>
  33 +#include <map>
33 34
34 #ifdef SRS_AUTO_HTTP_CORE 35 #ifdef SRS_AUTO_HTTP_CORE
35 36
@@ -39,6 +40,7 @@ class SrsHttpUri; @@ -39,6 +40,7 @@ class SrsHttpUri;
39 class SrsHttpParser; 40 class SrsHttpParser;
40 class ISrsHttpMessage; 41 class ISrsHttpMessage;
41 class SrsStSocket; 42 class SrsStSocket;
  43 +class SrsKbps;
42 44
43 // the default timeout for http client. 45 // the default timeout for http client.
44 #define SRS_HTTP_CLIENT_TIMEOUT_US (int64_t)(30*1000*1000LL) 46 #define SRS_HTTP_CLIENT_TIMEOUT_US (int64_t)(30*1000*1000LL)
@@ -51,6 +53,8 @@ class SrsHttpClient @@ -51,6 +53,8 @@ class SrsHttpClient
51 private: 53 private:
52 SrsTcpClient* transport; 54 SrsTcpClient* transport;
53 SrsHttpParser* parser; 55 SrsHttpParser* parser;
  56 + std::map<std::string, std::string> headers;
  57 + SrsKbps* kbps;
54 private: 58 private:
55 int64_t timeout_us; 59 int64_t timeout_us;
56 // host name or ip. 60 // host name or ip.
@@ -61,24 +65,34 @@ public: @@ -61,24 +65,34 @@ public:
61 virtual ~SrsHttpClient(); 65 virtual ~SrsHttpClient();
62 public: 66 public:
63 /** 67 /**
64 - * initialize the client, connect to host and port.  
65 - */ 68 + * initialize the client, connect to host and port.
  69 + * @remark we will set default values in headers, which can be override by set_header.
  70 + */
66 virtual int initialize(std::string h, int p, int64_t t_us = SRS_HTTP_CLIENT_TIMEOUT_US); 71 virtual int initialize(std::string h, int p, int64_t t_us = SRS_HTTP_CLIENT_TIMEOUT_US);
  72 + /**
  73 + * set the header[k]=v and return the client itself.
  74 + */
  75 + virtual SrsHttpClient* set_header(std::string k, std::string v);
67 public: 76 public:
68 /** 77 /**
69 - * to post data to the uri.  
70 - * @param the path to request on.  
71 - * @param req the data post to uri. empty string to ignore.  
72 - * @param ppmsg output the http message to read the response.  
73 - */ 78 + * to post data to the uri.
  79 + * @param the path to request on.
  80 + * @param req the data post to uri. empty string to ignore.
  81 + * @param ppmsg output the http message to read the response.
  82 + * @remark user must free the ppmsg if not NULL.
  83 + */
74 virtual int post(std::string path, std::string req, ISrsHttpMessage** ppmsg); 84 virtual int post(std::string path, std::string req, ISrsHttpMessage** ppmsg);
75 /** 85 /**
76 - * to get data from the uri.  
77 - * @param the path to request on.  
78 - * @param req the data post to uri. empty string to ignore.  
79 - * @param ppmsg output the http message to read the response.  
80 - */ 86 + * to get data from the uri.
  87 + * @param the path to request on.
  88 + * @param req the data post to uri. empty string to ignore.
  89 + * @param ppmsg output the http message to read the response.
  90 + * @remark user must free the ppmsg if not NULL.
  91 + */
81 virtual int get(std::string path, std::string req, ISrsHttpMessage** ppmsg); 92 virtual int get(std::string path, std::string req, ISrsHttpMessage** ppmsg);
  93 +public:
  94 + virtual void set_recv_timeout(int64_t timeout);
  95 + virtual void kbps_sample(const char* label, int64_t age);
82 private: 96 private:
83 virtual void disconnect(); 97 virtual void disconnect();
84 virtual int connect(); 98 virtual int connect();
@@ -344,6 +344,12 @@ int SrsHttpResponseReader::read(char* data, int nb_data, int* nb_read) @@ -344,6 +344,12 @@ int SrsHttpResponseReader::read(char* data, int nb_data, int* nb_read)
344 return ret; 344 return ret;
345 } 345 }
346 346
  347 + // for some server, content-length is -1, while not chunked, directly read
  348 + // everything as body.
  349 + if (owner->content_length() == -1 && !owner->is_chunked()) {
  350 + return read_specified(data, nb_data, nb_read);
  351 + }
  352 +
347 // chunked encoding. 353 // chunked encoding.
348 if (owner->is_chunked()) { 354 if (owner->is_chunked()) {
349 return read_chunked(data, nb_data, nb_read); 355 return read_chunked(data, nb_data, nb_read);
@@ -483,8 +489,8 @@ int SrsHttpResponseReader::read_specified(char* data, int nb_data, int* nb_read) @@ -483,8 +489,8 @@ int SrsHttpResponseReader::read_specified(char* data, int nb_data, int* nb_read)
483 // increase the total read to determine whether EOF. 489 // increase the total read to determine whether EOF.
484 nb_total_read += nb_bytes; 490 nb_total_read += nb_bytes;
485 491
486 - // for not chunked  
487 - if (!owner->is_chunked()) { 492 + // for not chunked and specified content length.
  493 + if (!owner->is_chunked() && owner->content_length() != -1) {
488 // when read completed, eof. 494 // when read completed, eof.
489 if (nb_total_read >= (int)owner->content_length()) { 495 if (nb_total_read >= (int)owner->content_length()) {
490 is_eof = true; 496 is_eof = true;
@@ -1207,6 +1213,11 @@ int SrsResponseOnlyHttpConn::on_got_http_message(ISrsHttpMessage* msg) @@ -1207,6 +1213,11 @@ int SrsResponseOnlyHttpConn::on_got_http_message(ISrsHttpMessage* msg)
1207 1213
1208 ISrsHttpResponseReader* br = msg->body_reader(); 1214 ISrsHttpResponseReader* br = msg->body_reader();
1209 1215
  1216 + // when not specified the content length, ignore.
  1217 + if (msg->content_length() == -1) {
  1218 + return ret;
  1219 + }
  1220 +
1210 // drop all request body. 1221 // drop all request body.
1211 while (!br->eof()) { 1222 while (!br->eof()) {
1212 char body[4096]; 1223 char body[4096];
@@ -327,6 +327,7 @@ public: @@ -327,6 +327,7 @@ public:
327 * that is, the *ppmsg always NOT-NULL when return success. 327 * that is, the *ppmsg always NOT-NULL when return success.
328 * or error and *ppmsg must be NULL. 328 * or error and *ppmsg must be NULL.
329 * @remark, if success, *ppmsg always NOT-NULL, *ppmsg always is_complete(). 329 * @remark, if success, *ppmsg always NOT-NULL, *ppmsg always is_complete().
  330 + * @remark user must free the ppmsg if not NULL.
330 */ 331 */
331 virtual int parse_message(ISrsProtocolReaderWriter* io, SrsConnection* conn, ISrsHttpMessage** ppmsg); 332 virtual int parse_message(ISrsProtocolReaderWriter* io, SrsConnection* conn, ISrsHttpMessage** ppmsg);
332 private: 333 private:
@@ -334,7 +334,7 @@ int SrsHttpHooks::on_hls(int cid, string url, SrsRequest* req, string file, stri @@ -334,7 +334,7 @@ int SrsHttpHooks::on_hls(int cid, string url, SrsRequest* req, string file, stri
334 obj->set("duration", SrsJsonAny::number(duration)); 334 obj->set("duration", SrsJsonAny::number(duration));
335 obj->set("cwd", SrsJsonAny::str(cwd.c_str())); 335 obj->set("cwd", SrsJsonAny::str(cwd.c_str()));
336 obj->set("file", SrsJsonAny::str(file.c_str())); 336 obj->set("file", SrsJsonAny::str(file.c_str()));
337 - obj->set("url", SrsJsonAny::str(url.c_str())); 337 + obj->set("url", SrsJsonAny::str(ts_url.c_str()));
338 obj->set("m3u8", SrsJsonAny::str(m3u8.c_str())); 338 obj->set("m3u8", SrsJsonAny::str(m3u8.c_str()));
339 obj->set("m3u8_url", SrsJsonAny::str(m3u8_url.c_str())); 339 obj->set("m3u8_url", SrsJsonAny::str(m3u8_url.c_str()));
340 obj->set("seq_no", SrsJsonAny::integer(sn)); 340 obj->set("seq_no", SrsJsonAny::integer(sn));
@@ -453,7 +453,7 @@ int SrsHttpHooks::do_post(SrsHttpClient* hc, std::string url, std::string req, i @@ -453,7 +453,7 @@ int SrsHttpHooks::do_post(SrsHttpClient* hc, std::string url, std::string req, i
453 453
454 // ensure the http status is ok. 454 // ensure the http status is ok.
455 // https://github.com/ossrs/srs/issues/158 455 // https://github.com/ossrs/srs/issues/158
456 - if (code != SRS_CONSTS_HTTP_OK) { 456 + if (code != SRS_CONSTS_HTTP_OK && code != SRS_CONSTS_HTTP_Created) {
457 ret = ERROR_HTTP_STATUS_INVALID; 457 ret = ERROR_HTTP_STATUS_INVALID;
458 srs_error("invalid response status=%d. ret=%d", code, ret); 458 srs_error("invalid response status=%d. ret=%d", code, ret);
459 return ret; 459 return ret;
@@ -213,6 +213,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. @@ -213,6 +213,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
213 /////////////////////////////////////////////////////////// 213 ///////////////////////////////////////////////////////////
214 // HTTP consts values 214 // HTTP consts values
215 /////////////////////////////////////////////////////////// 215 ///////////////////////////////////////////////////////////
  216 +// the default http port.
  217 +#define SRS_CONSTS_HTTP_DEFAULT_PORT 80
216 // linux path seprator 218 // linux path seprator
217 #define SRS_CONSTS_HTTP_PATH_SEP '/' 219 #define SRS_CONSTS_HTTP_PATH_SEP '/'
218 // query string seprator 220 // query string seprator
@@ -102,6 +102,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. @@ -102,6 +102,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
102 #define ERROR_SYSTEM_CONFIG_RAW_DISABLED 1061 102 #define ERROR_SYSTEM_CONFIG_RAW_DISABLED 1061
103 #define ERROR_SYSTEM_CONFIG_RAW_NOT_ALLOWED 1062 103 #define ERROR_SYSTEM_CONFIG_RAW_NOT_ALLOWED 1062
104 #define ERROR_SYSTEM_CONFIG_RAW_PARAMS 1063 104 #define ERROR_SYSTEM_CONFIG_RAW_PARAMS 1063
  105 +#define ERROR_SYSTEM_FILE_NOT_EXISTS 1064
105 106
106 /////////////////////////////////////////////////////// 107 ///////////////////////////////////////////////////////
107 // RTMP protocol error. 108 // RTMP protocol error.
@@ -234,6 +235,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. @@ -234,6 +235,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
234 #define ERROR_RESPONSE_CODE 3064 235 #define ERROR_RESPONSE_CODE 3064
235 #define ERROR_RESPONSE_DATA 3065 236 #define ERROR_RESPONSE_DATA 3065
236 #define ERROR_REQUEST_DATA 3066 237 #define ERROR_REQUEST_DATA 3066
  238 +#define ERROR_EDGE_PORT_INVALID 3067
237 239
238 /////////////////////////////////////////////////////// 240 ///////////////////////////////////////////////////////
239 // HTTP/StreamCaster/KAFKA protocol error. 241 // HTTP/StreamCaster/KAFKA protocol error.
@@ -276,6 +278,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. @@ -276,6 +278,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
276 #define ERROR_KAFKA_CODEC_METADATA 4035 278 #define ERROR_KAFKA_CODEC_METADATA 4035
277 #define ERROR_KAFKA_CODEC_MESSAGE 4036 279 #define ERROR_KAFKA_CODEC_MESSAGE 4036
278 #define ERROR_KAFKA_CODEC_PRODUCER 4037 280 #define ERROR_KAFKA_CODEC_PRODUCER 4037
  281 +#define ERROR_HTTP_302_INVALID 4038
279 282
280 /////////////////////////////////////////////////////// 283 ///////////////////////////////////////////////////////
281 // HTTP API error. 284 // HTTP API error.
@@ -178,6 +178,20 @@ void SrsCommonMessage::create_payload(int size) @@ -178,6 +178,20 @@ void SrsCommonMessage::create_payload(int size)
178 #endif 178 #endif
179 } 179 }
180 180
  181 +int SrsCommonMessage::create(SrsMessageHeader* pheader, char* body, int size)
  182 +{
  183 + int ret = ERROR_SUCCESS;
  184 +
  185 + // drop previous payload.
  186 + srs_freepa(payload);
  187 +
  188 + this->header = *pheader;
  189 + this->payload = body;
  190 + this->size = size;
  191 +
  192 + return ret;
  193 +}
  194 +
181 SrsSharedPtrMessage::SrsSharedPtrPayload::SrsSharedPtrPayload() 195 SrsSharedPtrMessage::SrsSharedPtrPayload::SrsSharedPtrPayload()
182 { 196 {
183 payload = NULL; 197 payload = NULL;
@@ -289,6 +289,14 @@ public: @@ -289,6 +289,14 @@ public:
289 * alloc the payload to specified size of bytes. 289 * alloc the payload to specified size of bytes.
290 */ 290 */
291 virtual void create_payload(int size); 291 virtual void create_payload(int size);
  292 +public:
  293 + /**
  294 + * create common message,
  295 + * from the header and body.
  296 + * @remark user should never free the body.
  297 + * @param pheader, the header to copy to the message. NULL to ignore.
  298 + */
  299 + virtual int create(SrsMessageHeader* pheader, char* body, int size);
292 }; 300 };
293 301
294 /** 302 /**