1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-03-09 15:49:59 +00:00

for #133, support the rtsp options request and response.

This commit is contained in:
winlin 2015-02-16 22:15:59 +08:00
parent c0e50265bd
commit 604f4cc57b
8 changed files with 849 additions and 33 deletions

View file

@ -62,7 +62,7 @@ int srs_go_http_response_json(ISrsGoHttpResponseWriter* w, string data)
}
// get the status text of code.
string srs_generate_status_text(int status)
string srs_generate_http_status_text(int status)
{
static std::map<int, std::string> _status_map;
if (_status_map.empty()) {
@ -212,7 +212,7 @@ void SrsGoHttpHeader::write(stringstream& ss)
{
std::map<std::string, std::string>::iterator it;
for (it = headers.begin(); it != headers.end(); ++it) {
ss << it->first << ": " << it->second << __SRS_CRLF;
ss << it->first << ": " << it->second << __SRS_HTTP_CRLF;
}
}
@ -711,7 +711,7 @@ int SrsGoHttpResponseWriter::final_request()
// complete the chunked encoding.
if (content_length == -1) {
std::stringstream ss;
ss << 0 << __SRS_CRLF << __SRS_CRLF;
ss << 0 << __SRS_HTTP_CRLF << __SRS_HTTP_CRLF;
std::string ch = ss.str();
return skt->write((void*)ch.data(), (int)ch.length(), NULL);
}
@ -752,7 +752,7 @@ int SrsGoHttpResponseWriter::write(char* data, int size)
// send in chunked encoding.
std::stringstream ss;
ss << hex << size << __SRS_CRLF;
ss << hex << size << __SRS_HTTP_CRLF;
std::string ch = ss.str();
if ((ret = skt->write((void*)ch.data(), (int)ch.length(), NULL)) != ERROR_SUCCESS) {
return ret;
@ -760,7 +760,7 @@ int SrsGoHttpResponseWriter::write(char* data, int size)
if ((ret = skt->write((void*)data, size, NULL)) != ERROR_SUCCESS) {
return ret;
}
if ((ret = skt->write((void*)__SRS_CRLF, 2, NULL)) != ERROR_SUCCESS) {
if ((ret = skt->write((void*)__SRS_HTTP_CRLF, 2, NULL)) != ERROR_SUCCESS) {
return ret;
}
@ -794,7 +794,7 @@ int SrsGoHttpResponseWriter::send_header(char* data, int size)
// status_line
ss << "HTTP/1.1 " << status << " "
<< srs_generate_status_text(status) << __SRS_CRLF;
<< srs_generate_http_status_text(status) << __SRS_HTTP_CRLF;
// detect content type
if (srs_go_http_body_allowd(status)) {
@ -820,7 +820,7 @@ int SrsGoHttpResponseWriter::send_header(char* data, int size)
hdr->write(ss);
// header_eof
ss << __SRS_CRLF;
ss << __SRS_HTTP_CRLF;
std::string buf = ss.str();
return skt->write((void*)buf.c_str(), buf.length(), NULL);

View file

@ -39,6 +39,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include <http_parser.h>
#include <srs_app_st.hpp>
#include <srs_kernel_consts.hpp>
class SrsRequest;
class SrsStSocket;
@ -51,19 +52,19 @@ class ISrsGoHttpResponseWriter;
// http specification
// CR = <US-ASCII CR, carriage return (13)>
#define __SRS_CR SRS_CONSTS_CR // 0x0D
#define __SRS_HTTP_CR SRS_CONSTS_CR // 0x0D
// LF = <US-ASCII LF, linefeed (10)>
#define __SRS_LF SRS_CONSTS_LF // 0x0A
#define __SRS_HTTP_LF SRS_CONSTS_LF // 0x0A
// SP = <US-ASCII SP, space (32)>
#define __SRS_SP ' ' // 0x20
#define __SRS_HTTP_SP ' ' // 0x20
// HT = <US-ASCII HT, horizontal-tab (9)>
#define __SRS_HT '\x09' // 0x09
#define __SRS_HTTP_HT '\x09' // 0x09
// HTTP/1.1 defines the sequence CR LF as the end-of-line marker for all
// protocol elements except the entity-body (see appendix 19.3 for
// tolerant applications).
#define __SRS_CRLF "\r\n" // 0x0D0A
#define __SRS_CRLFCRLF "\r\n\r\n" // 0x0D0A0D0A
#define __SRS_HTTP_CRLF "\r\n" // 0x0D0A
#define __SRS_HTTP_CRLFCRLF "\r\n\r\n" // 0x0D0A0D0A
// @see SrsHttpMessage._http_ts_send_buffer
#define __SRS_HTTP_TS_SEND_BUFFER_SIZE 4096

View file

@ -76,13 +76,13 @@ int SrsHttpClient::post(SrsHttpUri* uri, string req, int& status_code, string& r
// POST %s HTTP/1.1\r\nHost: %s\r\nContent-Length: %d\r\n\r\n%s
std::stringstream ss;
ss << "POST " << uri->get_path() << " "
<< "HTTP/1.1" << __SRS_CRLF
<< "Host: " << uri->get_host() << __SRS_CRLF
<< "Connection: Keep-Alive" << __SRS_CRLF
<< "Content-Length: " << std::dec << req.length() << __SRS_CRLF
<< "User-Agent: " << RTMP_SIG_SRS_NAME << RTMP_SIG_SRS_VERSION << __SRS_CRLF
<< "Content-Type: application/json" << __SRS_CRLF
<< __SRS_CRLF
<< "HTTP/1.1" << __SRS_HTTP_CRLF
<< "Host: " << uri->get_host() << __SRS_HTTP_CRLF
<< "Connection: Keep-Alive" << __SRS_HTTP_CRLF
<< "Content-Length: " << std::dec << req.length() << __SRS_HTTP_CRLF
<< "User-Agent: " << RTMP_SIG_SRS_NAME << RTMP_SIG_SRS_VERSION << __SRS_HTTP_CRLF
<< "Content-Type: application/json" << __SRS_HTTP_CRLF
<< __SRS_HTTP_CRLF
<< req;
SrsStSocket skt(stfd);

View file

@ -32,6 +32,7 @@ using namespace std;
#include <srs_app_st_socket.hpp>
#include <srs_kernel_log.hpp>
#include <srs_app_utility.hpp>
#include <srs_core_autofree.hpp>
#ifdef SRS_AUTO_STREAM_CASTER
@ -76,6 +77,28 @@ int SrsRtspConn::do_cycle()
std::string ip = srs_get_peer_ip(st_netfd_fileno(stfd));
srs_trace("rtsp: serve %s", ip.c_str());
// consume all rtsp messages.
for (;;) {
SrsRtspRequest* req = NULL;
if ((ret = rtsp->recv_message(&req)) != ERROR_SUCCESS) {
if (!srs_is_client_gracefully_close(ret)) {
srs_error("rtsp: recv request failed. ret=%d", ret);
}
return ret;
}
SrsAutoFree(SrsRtspRequest, req);
srs_info("rtsp: got rtsp request");
if (req->is_options()) {
if ((ret = rtsp->send_message(new SrsRtspOptionsResponse(req->seq))) != ERROR_SUCCESS) {
if (!srs_is_client_gracefully_close(ret)) {
srs_error("rtsp: send response failed. ret=%d", ret);
}
return ret;
}
}
}
return ret;
}