mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
SquashSRS4: Refine SDK
This commit is contained in:
parent
a7ab78a588
commit
e50582f9c7
6 changed files with 102 additions and 89 deletions
|
@ -181,6 +181,7 @@ The ports used by SRS:
|
||||||
|
|
||||||
## V4 changes
|
## V4 changes
|
||||||
|
|
||||||
|
* v4.0, 2021-05-21, Fix [#2370][bug #2370] bug for Firefox play stream(published by Chrome). 4.0.121
|
||||||
* v4.0, 2021-05-21, RTC: Refine sdk, migrate from onaddstream to ontrack. 4.0.120
|
* v4.0, 2021-05-21, RTC: Refine sdk, migrate from onaddstream to ontrack. 4.0.120
|
||||||
* v4.0, 2021-05-21, Tools: Refine configure options. 4.0.119
|
* v4.0, 2021-05-21, Tools: Refine configure options. 4.0.119
|
||||||
* v4.0, 2021-05-20, Fix build fail when disable RTC by --rtc=off. 4.0.118
|
* v4.0, 2021-05-20, Fix build fail when disable RTC by --rtc=off. 4.0.118
|
||||||
|
@ -1924,6 +1925,7 @@ Winlin
|
||||||
[bug #2355]: https://github.com/ossrs/srs/issues/2355
|
[bug #2355]: https://github.com/ossrs/srs/issues/2355
|
||||||
[bug #307]: https://github.com/ossrs/srs/issues/307
|
[bug #307]: https://github.com/ossrs/srs/issues/307
|
||||||
[bug #2362]: https://github.com/ossrs/srs/issues/2362
|
[bug #2362]: https://github.com/ossrs/srs/issues/2362
|
||||||
|
[bug #2370]: https://github.com/ossrs/srs/issues/2370
|
||||||
[bug #yyyyyyyyyyyyy]: https://github.com/ossrs/srs/issues/yyyyyyyyyyyyy
|
[bug #yyyyyyyyyyyyy]: https://github.com/ossrs/srs/issues/yyyyyyyyyyyyy
|
||||||
|
|
||||||
[bug #1631]: https://github.com/ossrs/srs/issues/1631
|
[bug #1631]: https://github.com/ossrs/srs/issues/1631
|
||||||
|
|
|
@ -29,6 +29,14 @@
|
||||||
function SrsRtcPublisherAsync() {
|
function SrsRtcPublisherAsync() {
|
||||||
var self = {};
|
var self = {};
|
||||||
|
|
||||||
|
// https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getUserMedia
|
||||||
|
self.constraints = {
|
||||||
|
audio: true,
|
||||||
|
video: {
|
||||||
|
width: {ideal: 320, max: 576}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// @see https://github.com/rtcdn/rtcdn-draft
|
// @see https://github.com/rtcdn/rtcdn-draft
|
||||||
// @url The WebRTC url to play with, for example:
|
// @url The WebRTC url to play with, for example:
|
||||||
// webrtc://r.ossrs.net/live/livestream
|
// webrtc://r.ossrs.net/live/livestream
|
||||||
|
@ -56,9 +64,8 @@ function SrsRtcPublisherAsync() {
|
||||||
self.pc.addTransceiver("audio", {direction: "sendonly"});
|
self.pc.addTransceiver("audio", {direction: "sendonly"});
|
||||||
self.pc.addTransceiver("video", {direction: "sendonly"});
|
self.pc.addTransceiver("video", {direction: "sendonly"});
|
||||||
|
|
||||||
var stream = await navigator.mediaDevices.getUserMedia(
|
var stream = await navigator.mediaDevices.getUserMedia(self.constraints);
|
||||||
{audio: true, video: {width: {max: 320}}}
|
|
||||||
);
|
|
||||||
// @see https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/addStream#Migrating_to_addTrack
|
// @see https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/addStream#Migrating_to_addTrack
|
||||||
stream.getTracks().forEach(function (track) {
|
stream.getTracks().forEach(function (track) {
|
||||||
self.pc.addTrack(track);
|
self.pc.addTrack(track);
|
||||||
|
@ -500,7 +507,8 @@ function SrsRtcPlayerAsync() {
|
||||||
function SrsRtcFormatSenders(senders, kind) {
|
function SrsRtcFormatSenders(senders, kind) {
|
||||||
var codecs = [];
|
var codecs = [];
|
||||||
senders.forEach(function (sender) {
|
senders.forEach(function (sender) {
|
||||||
sender.getParameters().codecs.forEach(function(c) {
|
var params = sender.getParameters();
|
||||||
|
params && params.codecs && params.codecs.forEach(function(c) {
|
||||||
if (kind && sender.track.kind !== kind) {
|
if (kind && sender.track.kind !== kind) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,51 +64,51 @@
|
||||||
</footer>
|
</footer>
|
||||||
</div>
|
</div>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
$(function(){
|
$(function(){
|
||||||
var sdk = null; // Global handler to do cleanup when replaying.
|
var sdk = null; // Global handler to do cleanup when replaying.
|
||||||
var startPlay = function() {
|
var startPlay = function() {
|
||||||
$('#rtc_media_player').show();
|
$('#rtc_media_player').show();
|
||||||
|
|
||||||
// Close PC when user replay.
|
// Close PC when user replay.
|
||||||
if (sdk) {
|
if (sdk) {
|
||||||
sdk.close();
|
sdk.close();
|
||||||
}
|
|
||||||
sdk = new SrsRtcPlayerAsync();
|
|
||||||
|
|
||||||
// https://webrtc.org/getting-started/remote-streams
|
|
||||||
$('#rtc_media_player').prop('srcObject', sdk.stream);
|
|
||||||
// Optional callback, SDK will add track to stream.
|
|
||||||
// sdk.ontrack = function (event) { console.log('Got track', event); sdk.stream.addTrack(event.track); };
|
|
||||||
|
|
||||||
// For example: webrtc://r.ossrs.net/live/livestream
|
|
||||||
var url = $("#txt_url").val();
|
|
||||||
sdk.play(url).then(function(session){
|
|
||||||
$('#sessionid').html(session.sessionid);
|
|
||||||
$('#simulator-drop').attr('href', session.simulator + '?drop=1&username=' + session.sessionid);
|
|
||||||
}).catch(function (reason) {
|
|
||||||
sdk.close();
|
|
||||||
$('#rtc_media_player').hide();
|
|
||||||
console.error(reason);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
$('#rtc_media_player').hide();
|
|
||||||
var query = parse_query_string();
|
|
||||||
srs_init_rtc("#txt_url", query);
|
|
||||||
|
|
||||||
$("#btn_play").click(function() {
|
|
||||||
$('#rtc_media_player').prop('muted', false);
|
|
||||||
startPlay();
|
|
||||||
});
|
|
||||||
|
|
||||||
if (query.autostart === 'true') {
|
|
||||||
$('#rtc_media_player').prop('muted', true);
|
|
||||||
console.warn('For autostart, we should mute it, see https://www.jianshu.com/p/c3c6944eed5a ' +
|
|
||||||
'or https://developers.google.com/web/updates/2017/09/autoplay-policy-changes#audiovideo_elements');
|
|
||||||
|
|
||||||
startPlay();
|
|
||||||
}
|
}
|
||||||
|
sdk = new SrsRtcPlayerAsync();
|
||||||
|
|
||||||
|
// https://webrtc.org/getting-started/remote-streams
|
||||||
|
$('#rtc_media_player').prop('srcObject', sdk.stream);
|
||||||
|
// Optional callback, SDK will add track to stream.
|
||||||
|
// sdk.ontrack = function (event) { console.log('Got track', event); sdk.stream.addTrack(event.track); };
|
||||||
|
|
||||||
|
// For example: webrtc://r.ossrs.net/live/livestream
|
||||||
|
var url = $("#txt_url").val();
|
||||||
|
sdk.play(url).then(function(session){
|
||||||
|
$('#sessionid').html(session.sessionid);
|
||||||
|
$('#simulator-drop').attr('href', session.simulator + '?drop=1&username=' + session.sessionid);
|
||||||
|
}).catch(function (reason) {
|
||||||
|
sdk.close();
|
||||||
|
$('#rtc_media_player').hide();
|
||||||
|
console.error(reason);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
$('#rtc_media_player').hide();
|
||||||
|
var query = parse_query_string();
|
||||||
|
srs_init_rtc("#txt_url", query);
|
||||||
|
|
||||||
|
$("#btn_play").click(function() {
|
||||||
|
$('#rtc_media_player').prop('muted', false);
|
||||||
|
startPlay();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (query.autostart === 'true') {
|
||||||
|
$('#rtc_media_player').prop('muted', true);
|
||||||
|
console.warn('For autostart, we should mute it, see https://www.jianshu.com/p/c3c6944eed5a ' +
|
||||||
|
'or https://developers.google.com/web/updates/2017/09/autoplay-policy-changes#audiovideo_elements');
|
||||||
|
|
||||||
|
startPlay();
|
||||||
|
}
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
@ -68,53 +68,52 @@
|
||||||
</footer>
|
</footer>
|
||||||
</div>
|
</div>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
var pc = null; // Global handler to do cleanup when replaying.
|
$(function(){
|
||||||
$(function(){
|
var sdk = null; // Global handler to do cleanup when republishing.
|
||||||
var sdk = null; // Global handler to do cleanup when republishing.
|
var startPublish = function() {
|
||||||
var startPublish = function() {
|
$('#rtc_media_player').show();
|
||||||
$('#rtc_media_player').show();
|
|
||||||
|
|
||||||
// Close PC when user replay.
|
// Close PC when user replay.
|
||||||
if (sdk) {
|
if (sdk) {
|
||||||
sdk.close();
|
sdk.close();
|
||||||
|
}
|
||||||
|
sdk = new SrsRtcPublisherAsync();
|
||||||
|
|
||||||
|
// User should set the stream when publish is done, @see https://webrtc.org/getting-started/media-devices
|
||||||
|
// However SRS SDK provides a consist API like https://webrtc.org/getting-started/remote-streams
|
||||||
|
$('#rtc_media_player').prop('srcObject', sdk.stream);
|
||||||
|
// Optional callback, SDK will add track to stream.
|
||||||
|
// sdk.ontrack = function (event) { console.log('Got track', event); sdk.stream.addTrack(event.track); };
|
||||||
|
|
||||||
|
// https://developer.mozilla.org/en-US/docs/Web/Media/Formats/WebRTC_codecs#getting_the_supported_codecs
|
||||||
|
sdk.pc.onicegatheringstatechange = function (event) {
|
||||||
|
if (sdk.pc.iceGatheringState === "complete") {
|
||||||
|
$('#acodecs').html(SrsRtcFormatSenders(sdk.pc.getSenders(), "audio"));
|
||||||
|
$('#vcodecs').html(SrsRtcFormatSenders(sdk.pc.getSenders(), "video"));
|
||||||
}
|
}
|
||||||
sdk = new SrsRtcPublisherAsync();
|
|
||||||
|
|
||||||
// User should set the stream when publish is done, @see https://webrtc.org/getting-started/media-devices
|
|
||||||
// However SRS SDK provides a consist API like https://webrtc.org/getting-started/remote-streams
|
|
||||||
$('#rtc_media_player').prop('srcObject', sdk.stream);
|
|
||||||
// Optional callback, SDK will add track to stream.
|
|
||||||
// sdk.ontrack = function (event) { console.log('Got track', event); sdk.stream.addTrack(event.track); };
|
|
||||||
|
|
||||||
// https://developer.mozilla.org/en-US/docs/Web/Media/Formats/WebRTC_codecs#getting_the_supported_codecs
|
|
||||||
sdk.pc.onicegatheringstatechange = function (event) {
|
|
||||||
if (sdk.pc.iceGatheringState === "complete") {
|
|
||||||
$('#acodecs').html(SrsRtcFormatSenders(sdk.pc.getSenders(), "audio"));
|
|
||||||
$('#vcodecs').html(SrsRtcFormatSenders(sdk.pc.getSenders(), "video"));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// For example: webrtc://r.ossrs.net/live/livestream
|
|
||||||
var url = $("#txt_url").val();
|
|
||||||
sdk.publish(url).then(function(session){
|
|
||||||
$('#sessionid').html(session.sessionid);
|
|
||||||
$('#simulator-drop').attr('href', session.simulator + '?drop=1&username=' + session.sessionid);
|
|
||||||
}).catch(function (reason) {
|
|
||||||
sdk.close();
|
|
||||||
$('#rtc_media_player').hide();
|
|
||||||
console.error(reason);
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
$('#rtc_media_player').hide();
|
// For example: webrtc://r.ossrs.net/live/livestream
|
||||||
var query = parse_query_string();
|
var url = $("#txt_url").val();
|
||||||
srs_init_rtc("#txt_url", query);
|
sdk.publish(url).then(function(session){
|
||||||
|
$('#sessionid').html(session.sessionid);
|
||||||
|
$('#simulator-drop').attr('href', session.simulator + '?drop=1&username=' + session.sessionid);
|
||||||
|
}).catch(function (reason) {
|
||||||
|
sdk.close();
|
||||||
|
$('#rtc_media_player').hide();
|
||||||
|
console.error(reason);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
$("#btn_publish").click(startPublish);
|
$('#rtc_media_player').hide();
|
||||||
if (query.autostart === 'true') {
|
var query = parse_query_string();
|
||||||
startPublish();
|
srs_init_rtc("#txt_url", query);
|
||||||
}
|
|
||||||
});
|
$("#btn_publish").click(startPublish);
|
||||||
|
if (query.autostart === 'true') {
|
||||||
|
startPublish();
|
||||||
|
}
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
@ -3096,6 +3096,10 @@ srs_error_t SrsRtcConnection::negotiate_play_capability(SrsRtcUserConfig* ruc, s
|
||||||
for (int j = 0; j < (int)track_descs.size(); ++j) {
|
for (int j = 0; j < (int)track_descs.size(); ++j) {
|
||||||
SrsRtcTrackDescription* track = track_descs.at(j)->copy();
|
SrsRtcTrackDescription* track = track_descs.at(j)->copy();
|
||||||
|
|
||||||
|
// We should clear the extmaps of source(publisher).
|
||||||
|
// @see https://github.com/ossrs/srs/issues/2370
|
||||||
|
track->extmaps_.clear();
|
||||||
|
|
||||||
// Use remote/source/offer PayloadType.
|
// Use remote/source/offer PayloadType.
|
||||||
track->media_->pt_of_publisher_ = track->media_->pt_;
|
track->media_->pt_of_publisher_ = track->media_->pt_;
|
||||||
track->media_->pt_ = remote_payload.payload_type_;
|
track->media_->pt_ = remote_payload.payload_type_;
|
||||||
|
|
|
@ -26,6 +26,6 @@
|
||||||
|
|
||||||
#define VERSION_MAJOR 4
|
#define VERSION_MAJOR 4
|
||||||
#define VERSION_MINOR 0
|
#define VERSION_MINOR 0
|
||||||
#define VERSION_REVISION 120
|
#define VERSION_REVISION 121
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue