Support simulate NACK for RTC publisher

pull/1753/head
winlin 5 years ago
parent 4d33070c59
commit d125116317

@ -48,6 +48,9 @@
<label></label>
<video id="rtc_media_player" controls autoplay></video>
<label></label>
SessionID: <span id='sessionid'></span>
<footer>
<p></p>
<p><a href="https://github.com/ossrs/srs">SRS Team &copy; 2020</a></p>
@ -115,6 +118,7 @@
if (data.code) {
reject(data); return;
}
$('#sessionid').html(data.sessionid);
resolve(data.sdp);
}).fail(function(reason){
reject(reason);

@ -48,6 +48,9 @@
<label></label>
<video id="rtc_media_player" width="320" autoplay muted></video>
<label></label>
SessionID: <span id='sessionid'></span>
<footer>
<p></p>
<p><a href="https://github.com/ossrs/srs">SRS Team &copy; 2020</a></p>
@ -125,6 +128,7 @@
if (data.code) {
reject(data); return;
}
$('#sessionid').html(data.sessionid);
resolve(data.sdp);
}).fail(function(reason){
reject(reason);

@ -967,7 +967,7 @@ srs_error_t SrsGoApiRtcPlay::do_serve_http(ISrsHttpResponseWriter* w, ISrsHttpMe
// TODO: add candidates in response json?
res->set("sdp", SrsJsonAny::str(local_sdp_str.c_str()));
res->set("sessionid", SrsJsonAny::str(session->id().c_str()));
res->set("sessionid", SrsJsonAny::str(session->username().c_str()));
srs_trace("RTC username=%s, offer=%dB, answer=%dB", session->username().c_str(),
remote_sdp_str.length(), local_sdp_str.length());
@ -1309,7 +1309,7 @@ srs_error_t SrsGoApiRtcPublish::do_serve_http(ISrsHttpResponseWriter* w, ISrsHtt
// TODO: add candidates in response json?
res->set("sdp", SrsJsonAny::str(local_sdp_str.c_str()));
res->set("sessionid", SrsJsonAny::str(session->id().c_str()));
res->set("sessionid", SrsJsonAny::str(session->username().c_str()));
srs_trace("RTC username=%s, offer=%dB, answer=%dB", session->username().c_str(),
remote_sdp_str.length(), local_sdp_str.length());

@ -1553,6 +1553,7 @@ SrsRtcPublisher::SrsRtcPublisher(SrsRtcSession* session)
audio_nack_ = new SrsRtpNackForReceiver(audio_queue_, 100 * 2 / 3);
source = NULL;
nn_simulate_nack_drop = 0;
}
SrsRtcPublisher::~SrsRtcPublisher()
@ -1967,6 +1968,17 @@ srs_error_t SrsRtcPublisher::on_rtp(char* buf, int nb_buf)
return srs_error_wrap(err, "decode rtp packet");
}
// For NACK simulator, drop packet.
if (nn_simulate_nack_drop) {
SrsRtpHeader* h = &pkt->rtp_header;
srs_warn("RTC NACK simulator #%d drop seq=%u, ssrc=%u/%s, ts=%u, %d bytes", nn_simulate_nack_drop,
h->get_sequence(), h->get_ssrc(), (h->get_ssrc()==video_ssrc? "Video":"Audio"), h->get_timestamp(),
(int)nb_buf);
nn_simulate_nack_drop--;
srs_freep(pkt);
return err;
}
uint32_t ssrc = pkt->rtp_header.get_ssrc();
if (ssrc == audio_ssrc) {
return on_audio(pkt);
@ -2217,7 +2229,7 @@ srs_error_t SrsRtcPublisher::notify(int type, srs_utime_t interval, srs_utime_t
void SrsRtcPublisher::simulate_nack_drop(int nn)
{
// TODO: FIXME: Implements it.
nn_simulate_nack_drop = nn;
}
SrsRtcSession::SrsRtcSession(SrsRtcServer* s)
@ -3359,16 +3371,17 @@ srs_error_t SrsRtcServer::create_session(
return srs_error_new(ERROR_RTC_SOURCE_BUSY, "stream %s busy", req->get_stream_url().c_str());
}
// TODO: FIXME: Seems not random, please check it.
std::string local_pwd = gen_random_str(32);
std::string local_ufrag = "";
// TODO: FIXME: Rename for a better name, it's not an username.
std::string username = "";
while (true) {
local_ufrag = gen_random_str(8);
username = local_ufrag + ":" + remote_sdp.get_ice_ufrag();
if (!map_username_session.count(username))
if (!map_username_session.count(username)) {
break;
}
}
int cid = _srs_context->get_id();

@ -278,6 +278,8 @@ private:
private:
SrsRequest* req;
SrsSource* source;
// Simulators.
int nn_simulate_nack_drop;
private:
std::map<uint32_t, uint64_t> last_sender_report_sys_time;
std::map<uint32_t, SrsNtp> last_sender_report_ntp;

@ -85,6 +85,9 @@ srs_error_t do_main(int argc, char** argv)
// TODO: support both little and big endian.
srs_assert(srs_is_little_endian());
// For RTC to generating random ICE username.
::srandom((unsigned long)(srs_update_system_time() | (::getpid()<<13)));
// for gperf gmp or gcp,
// should never enable it when not enabled for performance issue.

Loading…
Cancel
Save