mirror of
https://github.com/ossrs/srs.git
synced 2025-02-13 20:01:56 +00:00
parse sdp
This commit is contained in:
parent
62563bdd81
commit
30d8b2209f
3 changed files with 122 additions and 8 deletions
|
@ -47,6 +47,7 @@ using namespace std;
|
|||
#include <srs_protocol_utility.hpp>
|
||||
#include <srs_app_coworkers.hpp>
|
||||
#include <srs_app_rtc.hpp>
|
||||
#include <srs_app_rtc_conn.hpp>
|
||||
|
||||
string test_sdp =
|
||||
"v=0\\r\\n"
|
||||
|
@ -872,6 +873,34 @@ srs_error_t SrsGoApiSdp::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage*
|
|||
return srs_api_response_code(w, r, ERROR_RTMP_STREAM_NOT_FOUND);
|
||||
}
|
||||
|
||||
string req_json;
|
||||
r->body_read_all(req_json);
|
||||
srs_trace("req_json=%s", req_json.c_str());
|
||||
|
||||
SrsJsonAny* json = SrsJsonAny::loads(req_json);
|
||||
SrsJsonObject* req_obj = json->to_object();
|
||||
|
||||
SrsJsonAny* remote_sdp_obj = req_obj->get_property("sdp");
|
||||
SrsJsonAny* app_obj = req_obj->get_property("app");
|
||||
SrsJsonAny* stream_name_obj = req_obj->get_property("stream");
|
||||
|
||||
if (remote_sdp_obj == NULL || app_obj == NULL || stream_name_obj == NULL) {
|
||||
return srs_api_response_code(w, r, SRS_CONSTS_HTTP_BadRequest);
|
||||
}
|
||||
|
||||
string remote_sdp = remote_sdp_obj->to_str();
|
||||
string app = app_obj->to_str();
|
||||
string stream_name = stream_name_obj->to_str();
|
||||
|
||||
srs_trace("remote_sdp=%s", remote_sdp.c_str());
|
||||
srs_trace("app=%s, stream=%s", app.c_str(), stream_name.c_str());
|
||||
|
||||
SrsSdp srs_sdp;
|
||||
err = srs_sdp.parse(remote_sdp);
|
||||
if (err != srs_success) {
|
||||
return srs_api_response_code(w, r, SRS_CONSTS_HTTP_BadRequest);
|
||||
}
|
||||
|
||||
SrsJsonObject* obj = SrsJsonAny::object();
|
||||
SrsAutoFree(SrsJsonObject, obj);
|
||||
|
||||
|
|
|
@ -25,6 +25,8 @@
|
|||
|
||||
using namespace std;
|
||||
|
||||
#include <sstream>
|
||||
|
||||
#include <srs_kernel_log.hpp>
|
||||
#include <srs_kernel_error.hpp>
|
||||
#include <srs_stun_stack.hpp>
|
||||
|
@ -41,14 +43,77 @@ static bool is_dtls(const char* data, const int size) {
|
|||
return data != NULL && size > 0 && (data[0] >= 20 && data[0] <= 64);
|
||||
}
|
||||
|
||||
SrsSDP::SrsSDP()
|
||||
SrsSdpMediaInfo::SrsSdpMediaInfo()
|
||||
{
|
||||
}
|
||||
|
||||
SrsSDP::~SrsSDP()
|
||||
SrsSdpMediaInfo::~SrsSdpMediaInfo()
|
||||
{
|
||||
}
|
||||
|
||||
SrsSdp::SrsSdp()
|
||||
{
|
||||
}
|
||||
|
||||
SrsSdp::~SrsSdp()
|
||||
{
|
||||
}
|
||||
|
||||
srs_error_t SrsSdp::parse(const string& sdp)
|
||||
{
|
||||
srs_error_t err = srs_success;
|
||||
|
||||
if (sdp.size() < 2 || sdp[0] != 'v' || sdp[1] != '=') {
|
||||
return srs_error_wrap(err, "invalid sdp");
|
||||
}
|
||||
|
||||
string line;
|
||||
istringstream is(sdp);
|
||||
while (getline(is, line)) {
|
||||
srs_trace("line=%s", line.c_str());
|
||||
|
||||
if (line.size() < 2 || line[1] != '=') {
|
||||
return srs_error_wrap(err, "invalid sdp line=%s", line.c_str());
|
||||
}
|
||||
|
||||
switch (line[1]) {
|
||||
case 'v' :{
|
||||
break;
|
||||
}
|
||||
case 'o' :{
|
||||
break;
|
||||
}
|
||||
case 's' :{
|
||||
break;
|
||||
}
|
||||
case 't' :{
|
||||
break;
|
||||
}
|
||||
case 'c' :{
|
||||
break;
|
||||
}
|
||||
case 'a' :{
|
||||
if (parse_attr(line) != srs_success) {
|
||||
return srs_error_wrap(err, "parse sdp line=%s failed", line.c_str());
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'm' :{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
srs_error_t SrsSdp::parse_attr(const string& line)
|
||||
{
|
||||
srs_error_t err = srs_success;
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
SrsRtcSession::SrsRtcSession()
|
||||
{
|
||||
session_state = INIT;
|
||||
|
|
|
@ -28,16 +28,36 @@
|
|||
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
class SrsServer;
|
||||
class SrsStunPacket;
|
||||
|
||||
class SrsSDP
|
||||
class SrsSdpMediaInfo
|
||||
{
|
||||
private:
|
||||
public:
|
||||
SrsSDP();
|
||||
virtual ~SrsSDP();
|
||||
SrsSdpMediaInfo();
|
||||
virtual ~SrsSdpMediaInfo();
|
||||
};
|
||||
|
||||
class SrsSdp
|
||||
{
|
||||
private:
|
||||
std::string sdp;
|
||||
int version;
|
||||
std::string ice_ufrag;
|
||||
std::string ice_pwd;
|
||||
std::string fingerprint;
|
||||
std::string setup;
|
||||
std::vector<SrsSdpMediaInfo> media_infos;
|
||||
public:
|
||||
SrsSdp();
|
||||
virtual ~SrsSdp();
|
||||
|
||||
srs_error_t parse(const std::string& sdp);
|
||||
private:
|
||||
srs_error_t parse_attr(const std::string& line);
|
||||
};
|
||||
|
||||
enum SrsRtcSessionStateType
|
||||
|
@ -53,8 +73,8 @@ class SrsRtcSession
|
|||
{
|
||||
public:
|
||||
private:
|
||||
SrsSDP peer_sdp;
|
||||
SrsSDP offer_sdp;
|
||||
SrsSdp peer_sdp;
|
||||
SrsSdp offer_sdp;
|
||||
SrsRtcSessionStateType session_state;
|
||||
public:
|
||||
SrsRtcSession();
|
||||
|
|
Loading…
Reference in a new issue