Skip to content

Commit

Permalink
for ossrs#133, support the rtsp options request and response.
Browse files Browse the repository at this point in the history
  • Loading branch information
winlinvip committed Feb 16, 2015
1 parent c0e5026 commit 604f4cc
Show file tree
Hide file tree
Showing 8 changed files with 849 additions and 33 deletions.
14 changes: 7 additions & 7 deletions trunk/src/app/srs_app_http.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down Expand Up @@ -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;
}
}

Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -752,15 +752,15 @@ 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;
}
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;
}

Expand Down Expand Up @@ -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)) {
Expand All @@ -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);
Expand Down
13 changes: 7 additions & 6 deletions trunk/src/app/srs_app_http.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down
14 changes: 7 additions & 7 deletions trunk/src/app/srs_app_http_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
23 changes: 23 additions & 0 deletions trunk/src/app/srs_app_rtsp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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;
}

Expand Down
120 changes: 107 additions & 13 deletions trunk/src/kernel/srs_kernel_consts.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,43 +265,137 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#define SRS_CONSTS_HTTP_Continue_str "Continue"
#define SRS_CONSTS_HTTP_SwitchingProtocols_str "Switching Protocols"
#define SRS_CONSTS_HTTP_OK_str "OK"
#define SRS_CONSTS_HTTP_Created_str "Created "
#define SRS_CONSTS_HTTP_Created_str "Created"
#define SRS_CONSTS_HTTP_Accepted_str "Accepted"
#define SRS_CONSTS_HTTP_NonAuthoritativeInformation_str "Non Authoritative Information "
#define SRS_CONSTS_HTTP_NoContent_str "No Content "
#define SRS_CONSTS_HTTP_NonAuthoritativeInformation_str "Non Authoritative Information"
#define SRS_CONSTS_HTTP_NoContent_str "No Content"
#define SRS_CONSTS_HTTP_ResetContent_str "Reset Content"
#define SRS_CONSTS_HTTP_PartialContent_str "Partial Content"
#define SRS_CONSTS_HTTP_MultipleChoices_str "Multiple Choices "
#define SRS_CONSTS_HTTP_MultipleChoices_str "Multiple Choices"
#define SRS_CONSTS_HTTP_MovedPermanently_str "Moved Permanently"
#define SRS_CONSTS_HTTP_Found_str "Found"
#define SRS_CONSTS_HTTP_SeeOther_str "See Other"
#define SRS_CONSTS_HTTP_NotModified_str "Not Modified "
#define SRS_CONSTS_HTTP_NotModified_str "Not Modified"
#define SRS_CONSTS_HTTP_UseProxy_str "Use Proxy"
#define SRS_CONSTS_HTTP_TemporaryRedirect_str "Temporary Redirect "
#define SRS_CONSTS_HTTP_TemporaryRedirect_str "Temporary Redirect"
#define SRS_CONSTS_HTTP_BadRequest_str "Bad Request"
#define SRS_CONSTS_HTTP_Unauthorized_str "Unauthorized"
#define SRS_CONSTS_HTTP_PaymentRequired_str "Payment Required "
#define SRS_CONSTS_HTTP_Forbidden_str "Forbidden "
#define SRS_CONSTS_HTTP_PaymentRequired_str "Payment Required"
#define SRS_CONSTS_HTTP_Forbidden_str "Forbidden"
#define SRS_CONSTS_HTTP_NotFound_str "Not Found"
#define SRS_CONSTS_HTTP_MethodNotAllowed_str "Method Not Allowed"
#define SRS_CONSTS_HTTP_NotAcceptable_str "Not Acceptable "
#define SRS_CONSTS_HTTP_ProxyAuthenticationRequired_str "Proxy Authentication Required "
#define SRS_CONSTS_HTTP_NotAcceptable_str "Not Acceptable"
#define SRS_CONSTS_HTTP_ProxyAuthenticationRequired_str "Proxy Authentication Required"
#define SRS_CONSTS_HTTP_RequestTimeout_str "Request Timeout"
#define SRS_CONSTS_HTTP_Conflict_str "Conflict"
#define SRS_CONSTS_HTTP_Gone_str "Gone"
#define SRS_CONSTS_HTTP_LengthRequired_str "Length Required"
#define SRS_CONSTS_HTTP_PreconditionFailed_str "Precondition Failed"
#define SRS_CONSTS_HTTP_RequestEntityTooLarge_str "Request Entity Too Large "
#define SRS_CONSTS_HTTP_RequestEntityTooLarge_str "Request Entity Too Large"
#define SRS_CONSTS_HTTP_RequestURITooLarge_str "Request URI Too Large"
#define SRS_CONSTS_HTTP_UnsupportedMediaType_str "Unsupported Media Type"
#define SRS_CONSTS_HTTP_RequestedRangeNotSatisfiable_str "Requested Range Not Satisfiable"
#define SRS_CONSTS_HTTP_ExpectationFailed_str "Expectation Failed "
#define SRS_CONSTS_HTTP_InternalServerError_str "Internal Server Error "
#define SRS_CONSTS_HTTP_ExpectationFailed_str "Expectation Failed"
#define SRS_CONSTS_HTTP_InternalServerError_str "Internal Server Error"
#define SRS_CONSTS_HTTP_NotImplemented_str "Not Implemented"
#define SRS_CONSTS_HTTP_BadGateway_str "Bad Gateway"
#define SRS_CONSTS_HTTP_ServiceUnavailable_str "Service Unavailable"
#define SRS_CONSTS_HTTP_GatewayTimeout_str "Gateway Timeout"
#define SRS_CONSTS_HTTP_HTTPVersionNotSupported_str "HTTP Version Not Supported"

///////////////////////////////////////////////////////////
// RTSP consts values
///////////////////////////////////////////////////////////
// 7.1.1 Status Code and Reason Phrase
#define SRS_CONSTS_RTSP_Continue 100
#define SRS_CONSTS_RTSP_OK 200
#define SRS_CONSTS_RTSP_Created 201
#define SRS_CONSTS_RTSP_LowOnStorageSpace 250
#define SRS_CONSTS_RTSP_MultipleChoices 300
#define SRS_CONSTS_RTSP_MovedPermanently 301
#define SRS_CONSTS_RTSP_MovedTemporarily 302
#define SRS_CONSTS_RTSP_SeeOther 303
#define SRS_CONSTS_RTSP_NotModified 304
#define SRS_CONSTS_RTSP_UseProxy 305
#define SRS_CONSTS_RTSP_BadRequest 400
#define SRS_CONSTS_RTSP_Unauthorized 401
#define SRS_CONSTS_RTSP_PaymentRequired 402
#define SRS_CONSTS_RTSP_Forbidden 403
#define SRS_CONSTS_RTSP_NotFound 404
#define SRS_CONSTS_RTSP_MethodNotAllowed 405
#define SRS_CONSTS_RTSP_NotAcceptable 406
#define SRS_CONSTS_RTSP_ProxyAuthenticationRequired 407
#define SRS_CONSTS_RTSP_RequestTimeout 408
#define SRS_CONSTS_RTSP_Gone 410
#define SRS_CONSTS_RTSP_LengthRequired 411
#define SRS_CONSTS_RTSP_PreconditionFailed 412
#define SRS_CONSTS_RTSP_RequestEntityTooLarge 413
#define SRS_CONSTS_RTSP_RequestURITooLarge 414
#define SRS_CONSTS_RTSP_UnsupportedMediaType 415
#define SRS_CONSTS_RTSP_ParameterNotUnderstood 451
#define SRS_CONSTS_RTSP_ConferenceNotFound 452
#define SRS_CONSTS_RTSP_NotEnoughBandwidth 453
#define SRS_CONSTS_RTSP_SessionNotFound 454
#define SRS_CONSTS_RTSP_MethodNotValidInThisState 455
#define SRS_CONSTS_RTSP_HeaderFieldNotValidForResource 456
#define SRS_CONSTS_RTSP_InvalidRange 457
#define SRS_CONSTS_RTSP_ParameterIsReadOnly 458
#define SRS_CONSTS_RTSP_AggregateOperationNotAllowed 459
#define SRS_CONSTS_RTSP_OnlyAggregateOperationAllowed 460
#define SRS_CONSTS_RTSP_UnsupportedTransport 461
#define SRS_CONSTS_RTSP_DestinationUnreachable 462
#define SRS_CONSTS_RTSP_InternalServerError 500
#define SRS_CONSTS_RTSP_NotImplemented 501
#define SRS_CONSTS_RTSP_BadGateway 502
#define SRS_CONSTS_RTSP_ServiceUnavailable 503
#define SRS_CONSTS_RTSP_GatewayTimeout 504
#define SRS_CONSTS_RTSP_RTSPVersionNotSupported 505
#define SRS_CONSTS_RTSP_OptionNotSupported 551

#define SRS_CONSTS_RTSP_Continue_str "Continue"
#define SRS_CONSTS_RTSP_OK_str "OK"
#define SRS_CONSTS_RTSP_Created_str "Created"
#define SRS_CONSTS_RTSP_LowOnStorageSpace_str "Low on Storage Space"
#define SRS_CONSTS_RTSP_MultipleChoices_str "Multiple Choices"
#define SRS_CONSTS_RTSP_MovedPermanently_str "Moved Permanently"
#define SRS_CONSTS_RTSP_MovedTemporarily_str "Moved Temporarily"
#define SRS_CONSTS_RTSP_SeeOther_str "See Other"
#define SRS_CONSTS_RTSP_NotModified_str "Not Modified"
#define SRS_CONSTS_RTSP_UseProxy_str "Use Proxy"
#define SRS_CONSTS_RTSP_BadRequest_str "Bad Request"
#define SRS_CONSTS_RTSP_Unauthorized_str "Unauthorized"
#define SRS_CONSTS_RTSP_PaymentRequired_str "Payment Required"
#define SRS_CONSTS_RTSP_Forbidden_str "Forbidden"
#define SRS_CONSTS_RTSP_NotFound_str "Not Found"
#define SRS_CONSTS_RTSP_MethodNotAllowed_str "Method Not Allowed"
#define SRS_CONSTS_RTSP_NotAcceptable_str "Not Acceptable"
#define SRS_CONSTS_RTSP_ProxyAuthenticationRequired_str "Proxy Authentication Required"
#define SRS_CONSTS_RTSP_RequestTimeout_str "Request Timeout"
#define SRS_CONSTS_RTSP_Gone_str "Gone"
#define SRS_CONSTS_RTSP_LengthRequired_str "Length Required"
#define SRS_CONSTS_RTSP_PreconditionFailed_str "Precondition Failed"
#define SRS_CONSTS_RTSP_RequestEntityTooLarge_str "Request Entity Too Large"
#define SRS_CONSTS_RTSP_RequestURITooLarge_str "Request URI Too Large"
#define SRS_CONSTS_RTSP_UnsupportedMediaType_str "Unsupported Media Type"
#define SRS_CONSTS_RTSP_ParameterNotUnderstood_str "Invalid parameter"
#define SRS_CONSTS_RTSP_ConferenceNotFound_str "Illegal Conference Identifier"
#define SRS_CONSTS_RTSP_NotEnoughBandwidth_str "Not Enough Bandwidth"
#define SRS_CONSTS_RTSP_SessionNotFound_str "Session Not Found"
#define SRS_CONSTS_RTSP_MethodNotValidInThisState_str "Method Not Valid In This State"
#define SRS_CONSTS_RTSP_HeaderFieldNotValidForResource_str "Header Field Not Valid"
#define SRS_CONSTS_RTSP_InvalidRange_str "Invalid Range"
#define SRS_CONSTS_RTSP_ParameterIsReadOnly_str "Parameter Is Read-Only"
#define SRS_CONSTS_RTSP_AggregateOperationNotAllowed_str "Aggregate Operation Not Allowed"
#define SRS_CONSTS_RTSP_OnlyAggregateOperationAllowed_str "Only Aggregate Operation Allowed"
#define SRS_CONSTS_RTSP_UnsupportedTransport_str "Unsupported Transport"
#define SRS_CONSTS_RTSP_DestinationUnreachable_str "Destination Unreachable"
#define SRS_CONSTS_RTSP_InternalServerError_str "Internal Server Error"
#define SRS_CONSTS_RTSP_NotImplemented_str "Not Implemented"
#define SRS_CONSTS_RTSP_BadGateway_str "Bad Gateway"
#define SRS_CONSTS_RTSP_ServiceUnavailable_str "Service Unavailable"
#define SRS_CONSTS_RTSP_GatewayTimeout_str "Gateway Timeout"
#define SRS_CONSTS_RTSP_RTSPVersionNotSupported_str "RTSP Version Not Supported"
#define SRS_CONSTS_RTSP_OptionNotSupported_str "Option not support"

#endif

2 changes: 2 additions & 0 deletions trunk/src/kernel/srs_kernel_error.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#define ERROR_OpenSslComputeSharedKey 2039
#define ERROR_RTMP_MIC_CHUNKSIZE_CHANGED 2040
#define ERROR_RTMP_MIC_CACHE_OVERFLOW 2041
#define ERROR_RTSP_TOKEN_NOT_NORMAL 2042
#define ERROR_RTSP_REQUEST_HEADER_EOF 2043
//
// system control message,
// not an error, but special control logic.
Expand Down
Loading

0 comments on commit 604f4cc

Please sign in to comment.