提交 a6fb5aef authored 作者: Iñaki Baz Castillo's avatar Iñaki Baz Castillo

Working on #420: Notify Consumers about all Producer layers/scores:

- Add rtpStreamsByEncodingIdx vector in Producer to hold RecvStreams
  indexed by their corresponding encoding index (they may be nullptr).

- Use it to make producer.dump() and .getStats() obtain streams info
  in the same order as the order of the given encodings.

- Add encodingIdx field to RtpStream params.
上级 636632fa
...@@ -161,6 +161,7 @@ namespace RTC ...@@ -161,6 +161,7 @@ namespace RTC
RTC::RtpParameters rtpParameters; RTC::RtpParameters rtpParameters;
RTC::RtpParameters::Type type{ RTC::RtpParameters::Type::NONE }; RTC::RtpParameters::Type type{ RTC::RtpParameters::Type::NONE };
struct RtpMapping rtpMapping; struct RtpMapping rtpMapping;
std::vector<RTC::RtpStreamRecv*> rtpStreamsByEncodingIdx;
std::map<uint32_t, RTC::RtpStreamRecv*> mapRtxSsrcRtpStream; std::map<uint32_t, RTC::RtpStreamRecv*> mapRtxSsrcRtpStream;
std::map<RTC::RtpStreamRecv*, uint32_t> mapRtpStreamMappedSsrc; std::map<RTC::RtpStreamRecv*, uint32_t> mapRtpStreamMappedSsrc;
std::map<uint32_t, uint32_t> mapMappedSsrcSsrc; std::map<uint32_t, uint32_t> mapMappedSsrcSsrc;
......
...@@ -34,21 +34,22 @@ namespace RTC ...@@ -34,21 +34,22 @@ namespace RTC
{ {
void FillJson(json& jsonObject) const; void FillJson(json& jsonObject) const;
uint32_t ssrc{ 0 }; size_t encodingIdx{ 0u };
uint8_t payloadType{ 0 }; uint32_t ssrc{ 0u };
uint8_t payloadType{ 0u };
RTC::RtpCodecMimeType mimeType; RTC::RtpCodecMimeType mimeType;
uint32_t clockRate{ 0 }; uint32_t clockRate{ 0u };
std::string rid; std::string rid;
std::string cname; std::string cname;
uint32_t rtxSsrc{ 0 }; uint32_t rtxSsrc{ 0u };
uint8_t rtxPayloadType{ 0 }; uint8_t rtxPayloadType{ 0u };
bool useNack{ false }; bool useNack{ false };
bool usePli{ false }; bool usePli{ false };
bool useFir{ false }; bool useFir{ false };
bool useInBandFec{ false }; bool useInBandFec{ false };
bool useDtx{ false }; bool useDtx{ false };
uint8_t spatialLayers{ 1 }; uint8_t spatialLayers{ 1u };
uint8_t temporalLayers{ 1 }; uint8_t temporalLayers{ 1u };
}; };
public: public:
......
...@@ -477,8 +477,9 @@ namespace RTC ...@@ -477,8 +477,9 @@ namespace RTC
// NOTE: Here we know that SSRCs in Consumer's rtpParameters must be the same // NOTE: Here we know that SSRCs in Consumer's rtpParameters must be the same
// as in the given consumableRtpEncodings. // as in the given consumableRtpEncodings.
for (auto& encoding : this->rtpParameters.encodings) for (size_t idx{ 0u }; idx < this->rtpParameters.encodings.size(); ++idx)
{ {
auto& encoding = this->rtpParameters.encodings[idx];
auto* mediaCodec = this->rtpParameters.GetCodecForEncoding(encoding); auto* mediaCodec = this->rtpParameters.GetCodecForEncoding(encoding);
MS_DEBUG_TAG( MS_DEBUG_TAG(
...@@ -487,6 +488,7 @@ namespace RTC ...@@ -487,6 +488,7 @@ namespace RTC
// Set stream params. // Set stream params.
RTC::RtpStream::Params params; RTC::RtpStream::Params params;
params.encodingIdx = idx;
params.ssrc = encoding.ssrc; params.ssrc = encoding.ssrc;
params.payloadType = mediaCodec->payloadType; params.payloadType = mediaCodec->payloadType;
params.mimeType = mediaCodec->mimeType; params.mimeType = mediaCodec->mimeType;
......
...@@ -111,6 +111,9 @@ namespace RTC ...@@ -111,6 +111,9 @@ namespace RTC
for (auto& encoding : *jsonEncodingsIt) for (auto& encoding : *jsonEncodingsIt)
{ {
// Reserve a slot in rtpStreamsByEncodingIdx vector.
this->rtpStreamsByEncodingIdx.emplace_back(nullptr);
if (!encoding.is_object()) if (!encoding.is_object())
MS_THROW_TYPE_ERROR("wrong entry in rtpMapping.encodings"); MS_THROW_TYPE_ERROR("wrong entry in rtpMapping.encodings");
...@@ -289,6 +292,7 @@ namespace RTC ...@@ -289,6 +292,7 @@ namespace RTC
} }
this->mapSsrcRtpStream.clear(); this->mapSsrcRtpStream.clear();
this->rtpStreamsByEncodingIdx.clear();
this->mapRtxSsrcRtpStream.clear(); this->mapRtxSsrcRtpStream.clear();
this->mapRtpStreamMappedSsrc.clear(); this->mapRtpStreamMappedSsrc.clear();
this->mapMappedSsrcSsrc.clear(); this->mapMappedSsrcSsrc.clear();
...@@ -367,18 +371,17 @@ namespace RTC ...@@ -367,18 +371,17 @@ namespace RTC
// Add rtpStreams. // Add rtpStreams.
jsonObject["rtpStreams"] = json::array(); jsonObject["rtpStreams"] = json::array();
auto jsonRtpStreamsIt = jsonObject.find("rtpStreams"); auto jsonRtpStreamsIt = jsonObject.find("rtpStreams");
size_t rtpStreamIdx{ 0 };
for (auto& kv : this->mapSsrcRtpStream) for (auto* rtpStream : this->rtpStreamsByEncodingIdx)
{ {
if (!rtpStream)
continue;
jsonRtpStreamsIt->emplace_back(json::value_t::object); jsonRtpStreamsIt->emplace_back(json::value_t::object);
auto& jsonEntry = (*jsonRtpStreamsIt)[rtpStreamIdx]; auto& jsonEntry = (*jsonRtpStreamsIt)[jsonRtpStreamsIt->size() - 1];
auto* rtpStream = kv.second;
rtpStream->FillJson(jsonEntry); rtpStream->FillJson(jsonEntry);
++rtpStreamIdx;
} }
// Add paused. // Add paused.
...@@ -415,12 +418,14 @@ namespace RTC ...@@ -415,12 +418,14 @@ namespace RTC
{ {
MS_TRACE(); MS_TRACE();
for (auto& kv : this->mapSsrcRtpStream) for (auto* rtpStream : this->rtpStreamsByEncodingIdx)
{ {
if (!rtpStream)
continue;
jsonArray.emplace_back(json::value_t::object); jsonArray.emplace_back(json::value_t::object);
auto& jsonEntry = jsonArray[jsonArray.size() - 1]; auto& jsonEntry = jsonArray[jsonArray.size() - 1];
auto* rtpStream = kv.second;
rtpStream->FillJsonStats(jsonEntry); rtpStream->FillJsonStats(jsonEntry);
} }
...@@ -1028,14 +1033,20 @@ namespace RTC ...@@ -1028,14 +1033,20 @@ namespace RTC
uint32_t ssrc = packet->GetSsrc(); uint32_t ssrc = packet->GetSsrc();
MS_ASSERT( MS_ASSERT(
this->mapSsrcRtpStream.find(ssrc) == this->mapSsrcRtpStream.end(), "RtpStream already exists"); this->mapSsrcRtpStream.find(ssrc) == this->mapSsrcRtpStream.end(),
"RtpStream with given SSRC already exists");
MS_ASSERT(
!this->rtpStreamsByEncodingIdx[encodingIdx],
"RtpStream for given encoding index already exists");
auto& encoding = this->rtpParameters.encodings[encodingIdx]; auto& encoding = this->rtpParameters.encodings[encodingIdx];
auto& encodingMapping = this->rtpMapping.encodings[encodingIdx]; auto& encodingMapping = this->rtpMapping.encodings[encodingIdx];
MS_DEBUG_TAG( MS_DEBUG_TAG(
rtp, rtp,
"[ssrc:%" PRIu32 ", rid:%s, payloadType:%" PRIu8 "]", "[encodingIdx:%zu, ssrc:%" PRIu32 ", rid:%s, payloadType:%" PRIu8 "]",
encodingIdx,
ssrc, ssrc,
encoding.rid.c_str(), encoding.rid.c_str(),
mediaCodec.payloadType); mediaCodec.payloadType);
...@@ -1043,6 +1054,7 @@ namespace RTC ...@@ -1043,6 +1054,7 @@ namespace RTC
// Set stream params. // Set stream params.
RTC::RtpStream::Params params; RTC::RtpStream::Params params;
params.encodingIdx = encodingIdx;
params.ssrc = ssrc; params.ssrc = ssrc;
params.payloadType = mediaCodec.payloadType; params.payloadType = mediaCodec.payloadType;
params.mimeType = mediaCodec.mimeType; params.mimeType = mediaCodec.mimeType;
...@@ -1101,8 +1113,9 @@ namespace RTC ...@@ -1101,8 +1113,9 @@ namespace RTC
// Create a RtpStreamRecv for receiving a media stream. // Create a RtpStreamRecv for receiving a media stream.
auto* rtpStream = new RTC::RtpStreamRecv(this, params); auto* rtpStream = new RTC::RtpStreamRecv(this, params);
// Insert into the map. // Insert into the maps.
this->mapSsrcRtpStream[ssrc] = rtpStream; this->mapSsrcRtpStream[ssrc] = rtpStream;
this->rtpStreamsByEncodingIdx[encodingIdx] = rtpStream;
// Set the mapped SSRC. // Set the mapped SSRC.
this->mapRtpStreamMappedSsrc[rtpStream] = encodingMapping.mappedSsrc; this->mapRtpStreamMappedSsrc[rtpStream] = encodingMapping.mappedSsrc;
......
...@@ -335,6 +335,7 @@ namespace RTC ...@@ -335,6 +335,7 @@ namespace RTC
{ {
MS_TRACE(); MS_TRACE();
jsonObject["encodingIdx"] = this->encodingIdx;
jsonObject["ssrc"] = this->ssrc; jsonObject["ssrc"] = this->ssrc;
jsonObject["payloadType"] = this->payloadType; jsonObject["payloadType"] = this->payloadType;
jsonObject["mimeType"] = this->mimeType.ToString(); jsonObject["mimeType"] = this->mimeType.ToString();
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论