@@ -795,21 +795,13 @@ SrsGoApiSdp::~SrsGoApiSdp()
795
795
srs_error_t SrsGoApiSdp::serve_http (ISrsHttpResponseWriter* w, ISrsHttpMessage* r)
796
796
{
797
797
srs_error_t err = srs_success;
798
-
799
- SrsStatistic* stat = SrsStatistic::instance ();
800
-
801
- // path: {pattern}{stream_id}
802
- // e.g. /api/v1/streams/100 pattern= /api/v1/streams/, stream_id=100
803
- int sid = r->parse_rest_id (entry->pattern );
804
-
805
- SrsStatisticStream* stream = NULL ;
806
- if (sid >= 0 && (stream = stat->find_stream (sid)) == NULL ) {
807
- return srs_api_response_code (w, r, ERROR_RTMP_STREAM_NOT_FOUND);
808
- }
809
798
799
+ // path: {pattern}
800
+ // method: POST
801
+ // e.g. /api/v1/sdp/ args = json:{"sdp":"sdp...", "app":"webrtc", "stream":"test"}
802
+
810
803
string req_json;
811
804
r->body_read_all (req_json);
812
- srs_trace (" req_json=%s" , req_json.c_str ());
813
805
814
806
SrsJsonAny* json = SrsJsonAny::loads (req_json);
815
807
SrsJsonObject* req_obj = json->to_object ();
@@ -826,18 +818,17 @@ srs_error_t SrsGoApiSdp::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage*
826
818
string app = app_obj->to_str ();
827
819
string stream_name = stream_name_obj->to_str ();
828
820
829
- srs_trace (" remote_sdp_str=%s" , remote_sdp_str.c_str ());
830
- srs_trace (" app=%s, stream=%s" , app.c_str (), stream_name.c_str ());
831
-
832
821
SrsSdp remote_sdp;
833
822
err = remote_sdp.decode (remote_sdp_str);
834
823
if (err != srs_success) {
835
824
return srs_api_response_code (w, r, SRS_CONSTS_HTTP_BadRequest);
836
825
}
837
826
827
+ SrsRequest request;
828
+ request.app = app;
829
+ request.stream = stream_name;
838
830
SrsSdp local_sdp;
839
- SrsRtcSession* rtc_session = rtc_server->create_rtc_session (remote_sdp, local_sdp);
840
- rtc_session->set_app_stream (app, stream_name);
831
+ SrsRtcSession* rtc_session = rtc_server->create_rtc_session (request, remote_sdp, local_sdp);
841
832
842
833
string local_sdp_str = " " ;
843
834
err = local_sdp.encode (local_sdp_str);
@@ -849,22 +840,12 @@ srs_error_t SrsGoApiSdp::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage*
849
840
SrsAutoFree (SrsJsonObject, obj);
850
841
851
842
obj->set (" code" , SrsJsonAny::integer (ERROR_SUCCESS));
852
- obj->set (" server" , SrsJsonAny::integer (stat->server_id ()));
853
-
854
- // XXX: ice candidate
855
- // string candidate_str = "candidate:1 1 udp 2115783679 192.168.170.129:8000 typ host generation 0 ufrag "
856
- // + local_sdp.get_ice_ufrag() + "netwrok-cost 50";
857
-
858
- // SrsJsonObject* candidate_obj = SrsJsonAny::object();
859
- // SrsAutoFree(SrsJsonObject, candidate_obj);
843
+ obj->set (" server" , SrsJsonAny::integer (SrsStatistic::instance ()->server_id ()));
860
844
861
- // candidate_obj->set("candidate", SrsJsonAny::str(candidate_str.c_str()));
862
- // candidate_obj->set("sdpMid", SrsJsonAny::str("0"));
863
- // candidate_obj->set("sdpMLineIndex", SrsJsonAny::str("0"));
845
+ // TODO: add candidates in response json?
864
846
865
847
if (r->is_http_post ()) {
866
848
obj->set (" sdp" , SrsJsonAny::str (local_sdp_str.c_str ()));
867
- // obj->set("candidate", candidate_obj);
868
849
} else {
869
850
return srs_go_http_error (w, SRS_CONSTS_HTTP_MethodNotAllowed);
870
851
}
0 commit comments