mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
Free rtc publish. Refactor TAB to spaces
This commit is contained in:
parent
cd3c15ec4e
commit
ebdc03416a
6 changed files with 46 additions and 155 deletions
|
@ -149,111 +149,4 @@
|
|||
</body>
|
||||
</html>
|
||||
|
||||
<script>
|
||||
/*
|
||||
var PeerConnection = window.RTCPeerConnection || window.mozRTCPeerConnection || window.webkitRTCPeerConnection;
|
||||
var SessionDescription = window.RTCSessionDescription || window.mozRTCSessionDescription || window.webkitRTCSessionDescription;
|
||||
|
||||
var url = document.location.protocol + "//" + document.domain + ":1985/rtc/v1/publish/";
|
||||
|
||||
var method = "POST";
|
||||
var shouldBeAsync = true;
|
||||
|
||||
var request = new XMLHttpRequest();
|
||||
|
||||
request.open(method, url, shouldBeAsync);
|
||||
request.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
|
||||
|
||||
var pc = new PeerConnection();
|
||||
|
||||
var sendViewerOfferFn = function(desc) {
|
||||
console.log('sendViewerOfferFn:', desc);
|
||||
|
||||
pc.setLocalDescription(desc);
|
||||
|
||||
var sdp_json = {"sdp":desc.sdp, "app":"live", "stream":"livestream", "streamurl":"webrtc://localhost/live/livestream"};
|
||||
request.send(JSON.stringify(sdp_json));
|
||||
};
|
||||
|
||||
pc.addTransceiver("audio", {
|
||||
direction: "sendonly"
|
||||
}
|
||||
);
|
||||
|
||||
pc.addTransceiver("video", {
|
||||
direction: "sendonly"
|
||||
}
|
||||
);
|
||||
|
||||
var constraints = {
|
||||
"audio": true,
|
||||
"video": {
|
||||
"width": {
|
||||
"min": "480",
|
||||
"max": "1920"
|
||||
},
|
||||
"height": {
|
||||
"min": "320",
|
||||
"max": "1080"
|
||||
},
|
||||
"frameRate": {
|
||||
"min": "15",
|
||||
"max": "60"
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
navigator.mediaDevices.getUserMedia(constraints).then(
|
||||
function(mediaStream) {
|
||||
var video = document.getElementById('rtc_media_player');
|
||||
video.srcObject = mediaStream;
|
||||
video.onloadedmetadata = function(e) {
|
||||
console.log('play');
|
||||
video.play();
|
||||
};
|
||||
|
||||
pc.addStream(mediaStream);
|
||||
pc.createOffer(sendViewerOfferFn,
|
||||
function(error) {
|
||||
console.log('sendViewerOfferFn error:' + error);
|
||||
},
|
||||
);
|
||||
}).catch(
|
||||
function(err) {
|
||||
console.log(err);
|
||||
console.log(err.name + ": " + err.message);
|
||||
}
|
||||
);
|
||||
|
||||
pc.onicecandidate = function(event) {
|
||||
console.log('onicecandidate');
|
||||
};
|
||||
|
||||
pc.onconnectionstatechange = function(event) {
|
||||
console.log('onconnectionstatechange');
|
||||
};
|
||||
|
||||
pc.onicegatheringstatechange = function(event) {
|
||||
console.log('onicegatheringstatechange');
|
||||
};
|
||||
|
||||
pc.onsignalingstatechange = function(event) {
|
||||
console.log('onsignalingstatechange');
|
||||
};
|
||||
|
||||
request.onerror = function(event) {
|
||||
console.log('http error');
|
||||
};
|
||||
|
||||
request.onload = function () {
|
||||
console.log('onload,' , request.responseText);
|
||||
var json = JSON.parse(request.responseText);
|
||||
console.log('onmessage viewerResponse:', json.sdp);
|
||||
|
||||
pc.setRemoteDescription(new SessionDescription({type:'answer', sdp:json.sdp}));
|
||||
}
|
||||
/**/
|
||||
|
||||
</script>
|
||||
|
||||
</html>
|
||||
|
|
|
@ -2150,7 +2150,7 @@ SrsRtcSession::SrsRtcSession(SrsRtcServer* rtc_svr, const SrsRequest& req, const
|
|||
dtls_session = new SrsDtlsSession(this);
|
||||
// TODO: FIXME: Check error.
|
||||
dtls_session->initialize(req);
|
||||
strd = NULL;
|
||||
sender = NULL;
|
||||
|
||||
username = un;
|
||||
|
||||
|
@ -2165,17 +2165,14 @@ SrsRtcSession::SrsRtcSession(SrsRtcServer* rtc_svr, const SrsRequest& req, const
|
|||
// TODO: FIXME: Support reload.
|
||||
sessionStunTimeout = _srs_config->get_rtc_stun_timeout(req.vhost);
|
||||
|
||||
rtc_publisher = NULL;
|
||||
publisher = NULL;
|
||||
}
|
||||
|
||||
SrsRtcSession::~SrsRtcSession()
|
||||
{
|
||||
srs_freep(sender);
|
||||
srs_freep(publisher);
|
||||
srs_freep(dtls_session);
|
||||
|
||||
if (strd) {
|
||||
strd->stop();
|
||||
}
|
||||
srs_freep(strd);
|
||||
}
|
||||
|
||||
void SrsRtcSession::set_local_sdp(const SrsSdp& sdp)
|
||||
|
@ -2199,19 +2196,19 @@ srs_error_t SrsRtcSession::on_stun(SrsUdpMuxSocket* skt, SrsStunPacket* stun_req
|
|||
|
||||
last_stun_time = srs_get_system_time();
|
||||
|
||||
if (strd && strd->sendonly_ukt) {
|
||||
if (sender && sender->sendonly_ukt) {
|
||||
// We are running in the ice-lite(server) mode. If client have multi network interface,
|
||||
// we only choose one candidate pair which is determined by client.
|
||||
if (stun_req->get_use_candidate() && strd->sendonly_ukt->get_peer_id() != skt->get_peer_id()) {
|
||||
strd->update_sendonly_socket(skt);
|
||||
if (stun_req->get_use_candidate() && sender->sendonly_ukt->get_peer_id() != skt->get_peer_id()) {
|
||||
sender->update_sendonly_socket(skt);
|
||||
}
|
||||
}
|
||||
|
||||
if (rtc_publisher && rtc_publisher->sendonly_ukt) {
|
||||
if (publisher && publisher->sendonly_ukt) {
|
||||
// We are running in the ice-lite(server) mode. If client have multi network interface,
|
||||
// we only choose one candidate pair which is determined by client.
|
||||
if (stun_req->get_use_candidate() && rtc_publisher->sendonly_ukt->get_peer_id() != skt->get_peer_id()) {
|
||||
rtc_publisher->update_sendonly_socket(skt);
|
||||
if (stun_req->get_use_candidate() && publisher->sendonly_ukt->get_peer_id() != skt->get_peer_id()) {
|
||||
publisher->update_sendonly_socket(skt);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2428,20 +2425,20 @@ srs_error_t SrsRtcSession::on_rtcp_ps_feedback(char* buf, int nb_buf, SrsUdpMuxS
|
|||
|
||||
srs_error_t SrsRtcSession::on_rtcp_xr(char* buf, int nb_buf, SrsUdpMuxSocket* skt)
|
||||
{
|
||||
if (rtc_publisher == NULL) {
|
||||
if (publisher == NULL) {
|
||||
return srs_error_new(ERROR_RTC_RTCP, "rtc publisher null");
|
||||
}
|
||||
|
||||
return rtc_publisher->on_rtcp_xr(buf, nb_buf, skt);
|
||||
return publisher->on_rtcp_xr(buf, nb_buf, skt);
|
||||
}
|
||||
|
||||
srs_error_t SrsRtcSession::on_rtcp_sender_report(char* buf, int nb_buf, SrsUdpMuxSocket* skt)
|
||||
{
|
||||
if (rtc_publisher == NULL) {
|
||||
if (publisher == NULL) {
|
||||
return srs_error_new(ERROR_RTC_RTCP, "rtc publisher null");
|
||||
}
|
||||
|
||||
return rtc_publisher->on_rtcp_sender_report(buf, nb_buf, skt);
|
||||
return publisher->on_rtcp_sender_report(buf, nb_buf, skt);
|
||||
}
|
||||
|
||||
srs_error_t SrsRtcSession::on_rtcp_receiver_report(char* buf, int nb_buf, SrsUdpMuxSocket* skt)
|
||||
|
@ -2540,8 +2537,8 @@ srs_error_t SrsRtcSession::start_play(SrsUdpMuxSocket* skt)
|
|||
{
|
||||
srs_error_t err = srs_success;
|
||||
|
||||
srs_freep(strd);
|
||||
strd = new SrsRtcSenderThread(this, skt, _srs_context->get_id());
|
||||
srs_freep(sender);
|
||||
sender = new SrsRtcSenderThread(this, skt, _srs_context->get_id());
|
||||
|
||||
uint32_t video_ssrc = 0;
|
||||
uint32_t audio_ssrc = 0;
|
||||
|
@ -2558,11 +2555,11 @@ srs_error_t SrsRtcSession::start_play(SrsUdpMuxSocket* skt)
|
|||
}
|
||||
}
|
||||
|
||||
if ((err =strd->initialize(video_ssrc, audio_ssrc, video_payload_type, audio_payload_type)) != srs_success) {
|
||||
if ((err = sender->initialize(video_ssrc, audio_ssrc, video_payload_type, audio_payload_type)) != srs_success) {
|
||||
return srs_error_wrap(err, "SrsRtcSenderThread init");
|
||||
}
|
||||
|
||||
if ((err = strd->start()) != srs_success) {
|
||||
if ((err = sender->start()) != srs_success) {
|
||||
return srs_error_wrap(err, "start SrsRtcSenderThread");
|
||||
}
|
||||
|
||||
|
@ -2573,7 +2570,8 @@ srs_error_t SrsRtcSession::start_publish(SrsUdpMuxSocket* skt)
|
|||
{
|
||||
srs_error_t err = srs_success;
|
||||
|
||||
rtc_publisher = new SrsRtcPublisher(this);
|
||||
srs_freep(publisher);
|
||||
publisher = new SrsRtcPublisher(this);
|
||||
|
||||
uint32_t video_ssrc = 0;
|
||||
uint32_t audio_ssrc = 0;
|
||||
|
@ -2591,7 +2589,7 @@ srs_error_t SrsRtcSession::start_publish(SrsUdpMuxSocket* skt)
|
|||
}
|
||||
|
||||
// FIXME: err process.
|
||||
if ((err = rtc_publisher->initialize(skt, video_ssrc, audio_ssrc, request)) != srs_success) {
|
||||
if ((err = publisher->initialize(skt, video_ssrc, audio_ssrc, request)) != srs_success) {
|
||||
return srs_error_wrap(err, "rtc publisher init");
|
||||
}
|
||||
|
||||
|
@ -2687,7 +2685,7 @@ srs_error_t SrsRtcSession::on_rtp(SrsUdpMuxSocket* skt)
|
|||
{
|
||||
srs_error_t err = srs_success;
|
||||
|
||||
if (rtc_publisher == NULL) {
|
||||
if (publisher == NULL) {
|
||||
return srs_error_new(ERROR_RTC_RTCP, "rtc publisher null");
|
||||
}
|
||||
|
||||
|
@ -2701,7 +2699,7 @@ srs_error_t SrsRtcSession::on_rtp(SrsUdpMuxSocket* skt)
|
|||
return srs_error_wrap(err, "rtp unprotect failed");
|
||||
}
|
||||
|
||||
return rtc_publisher->on_rtp(skt, unprotected_buf, nb_unprotected_buf);
|
||||
return publisher->on_rtp(skt, unprotected_buf, nb_unprotected_buf);
|
||||
}
|
||||
|
||||
SrsUdpMuxSender::SrsUdpMuxSender(SrsRtcServer* s)
|
||||
|
|
|
@ -312,7 +312,7 @@ private:
|
|||
SrsSdp local_sdp;
|
||||
SrsRtcSessionStateType session_state;
|
||||
SrsDtlsSession* dtls_session;
|
||||
SrsRtcSenderThread* strd;
|
||||
SrsRtcSenderThread* sender;
|
||||
std::string username;
|
||||
std::string peer_id;
|
||||
srs_utime_t last_stun_time;
|
||||
|
@ -330,7 +330,7 @@ public:
|
|||
SrsRequest request;
|
||||
SrsSource* source;
|
||||
private:
|
||||
SrsRtcPublisher* rtc_publisher;
|
||||
SrsRtcPublisher* publisher;
|
||||
public:
|
||||
SrsRtcSession(SrsRtcServer* rtc_svr, const SrsRequest& req, const std::string& un, int context_id);
|
||||
virtual ~SrsRtcSession();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue