1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-03-09 15:49:59 +00:00

Merge branch '4.0release' into develop

This commit is contained in:
winlin 2022-09-10 21:25:38 +08:00
commit 6d18093e16
8 changed files with 67 additions and 35 deletions

View file

@ -65,6 +65,8 @@ The changelog for SRS.
## SRS 4.0 Changelog
* v4.0, 2022-09-09, For [#3174](https://github.com/ossrs/srs/issues/3174): WebRTC: Support Unity to publish or play stream. v4.0.264
* v4.0, 2022-09-09, Fix [#3093](https://github.com/ossrs/srs/issues/3093): WebRTC: Ignore unknown fmtp for h.264. v4.0.263
* v4.0, 2022-09-06, Fix [#3170](https://github.com/ossrs/srs/issues/3170): WebRTC: Support WHIP(WebRTC-HTTP ingestion protocol). v4.0.262
* v4.0, 2022-09-03, Fix HTTP url parsing bug. v4.0.261
* v4.0, 2022-09-03, For [#3167](https://github.com/ossrs/srs/issues/3167): WebRTC: Play stucked when republish. v4.0.260

View file

@ -580,11 +580,13 @@ srs_error_t SrsGoApiRtcPublish::http_hooks_on_publish(SrsRequest* req)
SrsGoApiRtcWhip::SrsGoApiRtcWhip(SrsRtcServer* server)
{
publish_ = new SrsGoApiRtcPublish(server);
play_ = new SrsGoApiRtcPlay(server);
}
SrsGoApiRtcWhip::~SrsGoApiRtcWhip()
{
srs_freep(publish_);
srs_freep(play_);
}
srs_error_t SrsGoApiRtcWhip::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r)
@ -617,6 +619,13 @@ srs_error_t SrsGoApiRtcWhip::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessa
string codec = r->query_get("codec");
string app = r->query_get("app");
string stream = r->query_get("stream");
string action = r->query_get("action");
if (action.empty()) {
action = "publish";
}
if (srs_string_ends_with(r->path(), "/whip-play/")) {
action = "play";
}
// The RTC user config object.
SrsRtcUserConfig ruc;
@ -632,14 +641,14 @@ srs_error_t SrsGoApiRtcWhip::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessa
ruc.req_->vhost = parsed_vhost->arg0();
}
srs_trace("RTC whip %s, clientip=%s, app=%s, stream=%s, offer=%dB, eip=%s, codec=%s",
ruc.req_->get_stream_url().c_str(), clientip.c_str(), ruc.req_->app.c_str(), ruc.req_->stream.c_str(),
srs_trace("RTC whip %s %s, clientip=%s, app=%s, stream=%s, offer=%dB, eip=%s, codec=%s",
action.c_str(), ruc.req_->get_stream_url().c_str(), clientip.c_str(), ruc.req_->app.c_str(), ruc.req_->stream.c_str(),
remote_sdp_str.length(), eip.c_str(), codec.c_str()
);
ruc.eip_ = eip;
ruc.codec_ = codec;
ruc.publish_ = true;
ruc.publish_ = (action == "publish");
ruc.dtls_ = ruc.srtp_ = true;
// TODO: FIXME: It seems remote_sdp doesn't represents the full SDP information.
@ -648,7 +657,8 @@ srs_error_t SrsGoApiRtcWhip::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessa
return srs_error_wrap(err, "parse sdp failed: %s", remote_sdp_str.c_str());
}
if ((err = publish_->serve_http(w, r, &ruc)) != srs_success) {
err = action == "publish" ? publish_->serve_http(w, r, &ruc) : play_->serve_http(w, r, &ruc);
if (err != srs_success) {
return srs_error_wrap(err, "serve");
}

View file

@ -27,7 +27,9 @@ public:
virtual srs_error_t serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r);
private:
virtual srs_error_t do_serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r, SrsJsonObject* res);
public:
virtual srs_error_t serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r, SrsRtcUserConfig* ruc);
private:
srs_error_t check_remote_sdp(const SrsSdp& remote_sdp);
private:
virtual srs_error_t http_hooks_on_play(SrsRequest* req);
@ -56,8 +58,8 @@ private:
class SrsGoApiRtcWhip : public ISrsHttpHandler
{
private:
SrsRtcServer* server_;
SrsGoApiRtcPublish* publish_;
SrsGoApiRtcPlay* play_;
public:
SrsGoApiRtcWhip(SrsRtcServer* server);
virtual ~SrsGoApiRtcWhip();

View file

@ -2693,6 +2693,9 @@ srs_error_t SrsRtcConnection::negotiate_publish_capability(SrsRtcUserConfig* ruc
SrsVideoPayload* video_payload = new SrsVideoPayload(payload.payload_type_, payload.encoding_name_, payload.clock_rate_);
video_payload->set_h264_param_desc(payload.format_specific_param_);
// Set the codec parameter for H.264, to make Unity happy.
video_payload->h264_param_ = h264_param;
// TODO: FIXME: Only support some transport algorithms.
for (int k = 0; k < (int)payload.rtcp_fb_.size(); ++k) {
const string& rtcp_fb = payload.rtcp_fb_.at(k);
@ -2742,6 +2745,7 @@ srs_error_t SrsRtcConnection::negotiate_publish_capability(SrsRtcUserConfig* ruc
}
}
track_desc->type_ = "video";
track_desc->set_codec_payload((SrsCodecPayload*)video_payload);
srs_warn("choose backup H.264 payload type=%d", payload.payload_type_);
}
@ -2750,6 +2754,11 @@ srs_error_t SrsRtcConnection::negotiate_publish_capability(SrsRtcUserConfig* ruc
//local_media_desc.payload_types_.back().rtcp_fb_.push_back("rrtr");
}
// Error if track desc is invalid, that is failed to match SDP, for example, we require H264 but no H264 found.
if (track_desc->type_.empty() || !track_desc->media_) {
return srs_error_new(ERROR_RTC_SDP_EXCHANGE, "no match for track=%s, mid=%s, tracker=%s", remote_media_desc.type_.c_str(), remote_media_desc.mid_.c_str(), remote_media_desc.msid_tracker_.c_str());
}
// TODO: FIXME: use one parse payload from sdp.
track_desc->create_auxiliary_payload(remote_media_desc.find_media_with_encoding_name("red"));
@ -2771,6 +2780,8 @@ srs_error_t SrsRtcConnection::negotiate_publish_capability(SrsRtcUserConfig* ruc
stream_desc->audio_track_desc_ = track_desc_copy;
} else if (remote_media_desc.is_video()) {
stream_desc->video_track_descs_.push_back(track_desc_copy);
} else {
srs_freep(track_desc_copy);
}
}
track_id = ssrc_info.msid_tracker_;

View file

@ -56,32 +56,39 @@ static void skip_first_spaces(std::string& str)
srs_error_t srs_parse_h264_fmtp(const std::string& fmtp, H264SpecificParam& h264_param)
{
srs_error_t err = srs_success;
std::vector<std::string> vec = split_str(fmtp, ";");
std::vector<std::string> vec = srs_string_split(fmtp, ";");
for (size_t i = 0; i < vec.size(); ++i) {
std::vector<std::string> kv = split_str(vec[i], "=");
if (kv.size() == 2) {
if (kv[0] == "profile-level-id") {
h264_param.profile_level_id = kv[1];
} else if (kv[0] == "packetization-mode") {
// 6.3. Non-Interleaved Mode
// This mode is in use when the value of the OPTIONAL packetization-mode
// media type parameter is equal to 1. This mode SHOULD be supported.
// It is primarily intended for low-delay applications. Only single NAL
// unit packets, STAP-As, and FU-As MAY be used in this mode. STAP-Bs,
// MTAPs, and FU-Bs MUST NOT be used. The transmission order of NAL
// units MUST comply with the NAL unit decoding order.
// @see https://tools.ietf.org/html/rfc6184#section-6.3
h264_param.packetization_mode = kv[1];
} else if (kv[0] == "level-asymmetry-allowed") {
h264_param.level_asymmerty_allow = kv[1];
} else {
return srs_error_new(ERROR_RTC_SDP_DECODE, "invalid h264 param=%s", kv[0].c_str());
}
} else {
return srs_error_new(ERROR_RTC_SDP_DECODE, "invalid h264 param=%s", vec[i].c_str());
std::vector<std::string> kv = srs_string_split(vec[i], "=");
if (kv.size() != 2) continue;
if (kv[0] == "profile-level-id") {
h264_param.profile_level_id = kv[1];
} else if (kv[0] == "packetization-mode") {
// 6.3. Non-Interleaved Mode
// This mode is in use when the value of the OPTIONAL packetization-mode
// media type parameter is equal to 1. This mode SHOULD be supported.
// It is primarily intended for low-delay applications. Only single NAL
// unit packets, STAP-As, and FU-As MAY be used in this mode. STAP-Bs,
// MTAPs, and FU-Bs MUST NOT be used. The transmission order of NAL
// units MUST comply with the NAL unit decoding order.
// @see https://tools.ietf.org/html/rfc6184#section-6.3
h264_param.packetization_mode = kv[1];
} else if (kv[0] == "level-asymmetry-allowed") {
h264_param.level_asymmerty_allow = kv[1];
}
}
if (h264_param.profile_level_id.empty()) {
return srs_error_new(ERROR_RTC_SDP_DECODE, "no h264 param: profile-level-id");
}
if (h264_param.packetization_mode.empty()) {
return srs_error_new(ERROR_RTC_SDP_DECODE, "no h264 param: packetization-mode");
}
if (h264_param.level_asymmerty_allow.empty()) {
return srs_error_new(ERROR_RTC_SDP_DECODE, "no h264 param: level-asymmetry-allowed");
}
return err;
}

View file

@ -469,10 +469,16 @@ srs_error_t SrsRtcServer::listen_api()
return srs_error_wrap(err, "handle publish");
}
// Generally, WHIP is a publishing protocol, but it can be also used as playing.
if ((err = http_api_mux->handle("/rtc/v1/whip/", new SrsGoApiRtcWhip(this))) != srs_success) {
return srs_error_wrap(err, "handle whip");
}
// We create another mount, to support play with the same query string as publish.
if ((err = http_api_mux->handle("/rtc/v1/whip-play/", new SrsGoApiRtcWhip(this))) != srs_success) {
return srs_error_wrap(err, "handle whip play");
}
#ifdef SRS_SIMULATOR
if ((err = http_api_mux->handle("/rtc/v1/nack/", new SrsGoApiRtcNACK(this))) != srs_success) {
return srs_error_wrap(err, "handle nack");

View file

@ -357,13 +357,7 @@ public:
class SrsVideoPayload : public SrsCodecPayload
{
public:
struct H264SpecificParameter
{
std::string profile_level_id;
std::string packetization_mode;
std::string level_asymmerty_allow;
};
H264SpecificParameter h264_param_;
H264SpecificParam h264_param_;
public:
SrsVideoPayload();

View file

@ -9,6 +9,6 @@
#define VERSION_MAJOR 4
#define VERSION_MINOR 0
#define VERSION_REVISION 262
#define VERSION_REVISION 264
#endif