提交 f3ffb583 authored 作者: José Luis Millán's avatar José Luis Millán

Consumer: select a desired RTP profile

上级 652dff13
...@@ -450,6 +450,42 @@ class Consumer extends EnhancedEventEmitter ...@@ -450,6 +450,42 @@ class Consumer extends EnhancedEventEmitter
this.safeEmit('resume', 'remote', appData); this.safeEmit('resume', 'remote', appData);
} }
/**
* Sets the preferred RTP profile.
*
* @return {Boolean} true if paused.
*/
setPreferredProfile(profile)
{
logger.debug('setPreferredProfile()');
if (this._closed)
{
logger.error('setPreferredProfile() | Consumer closed');
return false;
}
const data =
{
id : this.id,
peerName : this.peer.name,
profile : profile
};
this._channel.request('consumer.setPreferredProfile', this._internal, { profile })
.then(() =>
{
logger.debug('"consumer.setPreferredProfile" request succeeded');
this.emit('@notify', 'preferredProfileSet', data);
})
.catch((error) =>
{
logger.error('"consumer.setPreferredProfile" request failed: %s', String(error));
});
}
_handleWorkerNotifications() _handleWorkerNotifications()
{ {
// Subscribe to notifications. // Subscribe to notifications.
......
...@@ -42,7 +42,8 @@ namespace Channel ...@@ -42,7 +42,8 @@ namespace Channel
CONSUMER_DUMP, CONSUMER_DUMP,
CONSUMER_ENABLE, CONSUMER_ENABLE,
CONSUMER_PAUSE, CONSUMER_PAUSE,
CONSUMER_RESUME CONSUMER_RESUME,
CONSUMER_SET_PREFERRED_PROFILE
}; };
private: private:
......
...@@ -47,12 +47,13 @@ namespace RTC ...@@ -47,12 +47,13 @@ namespace RTC
bool IsEnabled() const; bool IsEnabled() const;
const RTC::RtpParameters& GetParameters() const; const RTC::RtpParameters& GetParameters() const;
bool IsPaused() const; bool IsPaused() const;
void SendRtpPacket(RTC::RtpPacket* packet, RTC::RtpProfile profile); void SendRtpPacket(RTC::RtpPacket* packet, RTC::RtpEncodingParameters::Profile profile);
void GetRtcp(RTC::RTCP::CompoundPacket* packet, uint64_t now); void GetRtcp(RTC::RTCP::CompoundPacket* packet, uint64_t now);
void ReceiveNack(RTC::RTCP::FeedbackRtpNackPacket* nackPacket); void ReceiveNack(RTC::RTCP::FeedbackRtpNackPacket* nackPacket);
void ReceiveRtcpReceiverReport(RTC::RTCP::ReceiverReport* report); void ReceiveRtcpReceiverReport(RTC::RTCP::ReceiverReport* report);
uint32_t GetTransmissionRate(uint64_t now); uint32_t GetTransmissionRate(uint64_t now);
void RequestFullFrame(); void RequestFullFrame();
void SetPreferredProfile(const RTC::RtpEncodingParameters::Profile profile);
private: private:
void FillSupportedCodecPayloadTypes(); void FillSupportedCodecPayloadTypes();
...@@ -90,7 +91,8 @@ namespace RTC ...@@ -90,7 +91,8 @@ namespace RTC
uint32_t lastRecvRtpTimestamp{ 0 }; uint32_t lastRecvRtpTimestamp{ 0 };
bool syncRequired{ true }; bool syncRequired{ true };
// RTP profiles. // RTP profiles.
RTC::RtpProfile effectiveProfile{ RTC::RtpProfile::DEFAULT }; RTC::RtpEncodingParameters::Profile preferredProfile{ RTC::RtpEncodingParameters::Profile::DEFAULT };
RTC::RtpEncodingParameters::Profile effectiveProfile{ RTC::RtpEncodingParameters::Profile::DEFAULT };
}; };
/* Inline methods. */ /* Inline methods. */
...@@ -124,6 +126,19 @@ namespace RTC ...@@ -124,6 +126,19 @@ namespace RTC
{ {
return this->transmittedCounter.GetRate(now) + this->retransmittedCounter.GetRate(now); return this->transmittedCounter.GetRate(now) + this->retransmittedCounter.GetRate(now);
} }
inline void Consumer::SetPreferredProfile(const RTC::RtpEncodingParameters::Profile profile)
{
if (this->preferredProfile == profile)
return;
this->preferredProfile = profile;
// TODO: Set it dynamically dynamic.
this->effectiveProfile = profile;
this->syncRequired = true;
RequestFullFrame();
}
} // namespace RTC } // namespace RTC
#endif #endif
...@@ -76,7 +76,7 @@ namespace RTC ...@@ -76,7 +76,7 @@ namespace RTC
void CreateRtpStream(RTC::RtpEncodingParameters& encoding); void CreateRtpStream(RTC::RtpEncodingParameters& encoding);
void ClearRtpStreams(); void ClearRtpStreams();
void ApplyRtpMapping(RTC::RtpPacket* packet) const; void ApplyRtpMapping(RTC::RtpPacket* packet) const;
RTC::RtpProfile GetRtpProfile(RTC::RtpPacket* packet); RTC::RtpEncodingParameters::Profile GetRtpProfile(RTC::RtpPacket* packet);
/* Pure virtual methods inherited from RTC::RtpStreamRecv::Listener. */ /* Pure virtual methods inherited from RTC::RtpStreamRecv::Listener. */
public: public:
...@@ -103,7 +103,7 @@ namespace RTC ...@@ -103,7 +103,7 @@ namespace RTC
// Allocated by this. // Allocated by this.
std::map<uint32_t, RTC::RtpStreamRecv*> rtpStreams; std::map<uint32_t, RTC::RtpStreamRecv*> rtpStreams;
std::map<uint32_t, RTC::RtpStreamRecv*> mapRtxStreams; std::map<uint32_t, RTC::RtpStreamRecv*> mapRtxStreams;
std::map<uint32_t, RTC::RtpProfile> rtpProfiles; std::map<uint32_t, RTC::RtpEncodingParameters::Profile> rtpProfiles;
Timer* fullFrameRequestBlockTimer{ nullptr }; Timer* fullFrameRequestBlockTimer{ nullptr };
// Others. // Others.
std::vector<RtpEncodingParameters> outputEncodings; std::vector<RtpEncodingParameters> outputEncodings;
......
...@@ -12,11 +12,12 @@ namespace RTC ...@@ -12,11 +12,12 @@ namespace RTC
class ProducerListener class ProducerListener
{ {
public: public:
virtual void OnProducerClosed(RTC::Producer* producer) = 0; virtual void OnProducerClosed(RTC::Producer* producer) = 0;
virtual void OnProducerRtpParametersUpdated(RTC::Producer* producer) = 0; virtual void OnProducerRtpParametersUpdated(RTC::Producer* producer) = 0;
virtual void OnProducerPaused(RTC::Producer* producer) = 0; virtual void OnProducerPaused(RTC::Producer* producer) = 0;
virtual void OnProducerResumed(RTC::Producer* producer) = 0; virtual void OnProducerResumed(RTC::Producer* producer) = 0;
virtual void OnProducerRtpPacket(RTC::Producer* producer, RTC::RtpPacket* packet, RTC::RtpProfile profile) = 0; virtual void OnProducerRtpPacket(
RTC::Producer* producer, RTC::RtpPacket* packet, RTC::RtpEncodingParameters::Profile profile) = 0;
}; };
} // namespace RTC } // namespace RTC
......
...@@ -67,7 +67,10 @@ namespace RTC ...@@ -67,7 +67,10 @@ namespace RTC
void OnProducerRtpParametersUpdated(RTC::Producer* producer) override; void OnProducerRtpParametersUpdated(RTC::Producer* producer) override;
void OnProducerPaused(RTC::Producer* producer) override; void OnProducerPaused(RTC::Producer* producer) override;
void OnProducerResumed(RTC::Producer* producer) override; void OnProducerResumed(RTC::Producer* producer) override;
void OnProducerRtpPacket(RTC::Producer* producer, RTC::RtpPacket* packet, RTC::RtpProfile profile) override; void OnProducerRtpPacket(
RTC::Producer* producer,
RTC::RtpPacket* packet,
RTC::RtpEncodingParameters::Profile profile) override;
/* Pure virtual methods inherited from RTC::ConsumerListener. */ /* Pure virtual methods inherited from RTC::ConsumerListener. */
public: public:
......
...@@ -31,14 +31,6 @@ namespace RTC ...@@ -31,14 +31,6 @@ namespace RTC
static std::map<Kind, Json::StaticString> kind2Json; static std::map<Kind, Json::StaticString> kind2Json;
}; };
enum class RtpProfile : uint8_t
{
DEFAULT = 0,
LOW,
MEDIUM,
HIGH
};
class RtpCodecMimeType class RtpCodecMimeType
{ {
public: public:
...@@ -214,6 +206,19 @@ namespace RTC ...@@ -214,6 +206,19 @@ namespace RTC
class RtpEncodingParameters class RtpEncodingParameters
{ {
public:
enum class Profile : uint8_t
{
DEFAULT = 0,
LOW,
MEDIUM,
HIGH
};
public:
static std::map<std::string, Profile> string2Profile;
static std::map<Profile, std::string> profile2String;
public: public:
RtpEncodingParameters(){}; RtpEncodingParameters(){};
explicit RtpEncodingParameters(Json::Value& data); explicit RtpEncodingParameters(Json::Value& data);
...@@ -234,7 +239,7 @@ namespace RTC ...@@ -234,7 +239,7 @@ namespace RTC
bool active{ true }; bool active{ true };
std::string encodingId; std::string encodingId;
std::vector<std::string> dependencyEncodingIds; std::vector<std::string> dependencyEncodingIds;
RTC::RtpProfile profile{ RTC::RtpProfile::DEFAULT }; Profile profile{ Profile::DEFAULT };
}; };
class RtpHeaderExtensionParameters class RtpHeaderExtensionParameters
......
...@@ -153,7 +153,10 @@ namespace RTC ...@@ -153,7 +153,10 @@ namespace RTC
void OnProducerRtpParametersUpdated(RTC::Producer* producer) override; void OnProducerRtpParametersUpdated(RTC::Producer* producer) override;
void OnProducerPaused(RTC::Producer* producer) override; void OnProducerPaused(RTC::Producer* producer) override;
void OnProducerResumed(RTC::Producer* producer) override; void OnProducerResumed(RTC::Producer* producer) override;
void OnProducerRtpPacket(RTC::Producer* producer, RTC::RtpPacket* packet, RTC::RtpProfile profile) override; void OnProducerRtpPacket(
RTC::Producer* producer,
RTC::RtpPacket* packet,
RTC::RtpEncodingParameters::Profile profile) override;
/* Pure virtual methods inherited from RTC::ConsumerListener. */ /* Pure virtual methods inherited from RTC::ConsumerListener. */
public: public:
......
...@@ -37,7 +37,8 @@ namespace Channel ...@@ -37,7 +37,8 @@ namespace Channel
{ "consumer.dump", Request::MethodId::CONSUMER_DUMP }, { "consumer.dump", Request::MethodId::CONSUMER_DUMP },
{ "consumer.enable", Request::MethodId::CONSUMER_ENABLE }, { "consumer.enable", Request::MethodId::CONSUMER_ENABLE },
{ "consumer.pause", Request::MethodId::CONSUMER_PAUSE }, { "consumer.pause", Request::MethodId::CONSUMER_PAUSE },
{ "consumer.resume", Request::MethodId::CONSUMER_RESUME } { "consumer.resume", Request::MethodId::CONSUMER_RESUME },
{ "consumer.setPreferredProfile", Request::MethodId::CONSUMER_SET_PREFERRED_PROFILE }
}; };
// clang-format on // clang-format on
......
...@@ -66,6 +66,8 @@ namespace RTC ...@@ -66,6 +66,8 @@ namespace RTC
static const Json::StaticString JsonStringEnabled{ "enabled" }; static const Json::StaticString JsonStringEnabled{ "enabled" };
static const Json::StaticString JsonStringPaused{ "paused" }; static const Json::StaticString JsonStringPaused{ "paused" };
static const Json::StaticString JsonStringSourcePaused{ "sourcePaused" }; static const Json::StaticString JsonStringSourcePaused{ "sourcePaused" };
static const Json::StaticString JsonStringPreferredProfile{ "preferredProfile" };
static const Json::StaticString JsonStringEffectiveProfile{ "effectiveProfile" };
Json::Value json(Json::objectValue); Json::Value json(Json::objectValue);
...@@ -85,6 +87,12 @@ namespace RTC ...@@ -85,6 +87,12 @@ namespace RTC
json[JsonStringSourcePaused] = this->sourcePaused; json[JsonStringSourcePaused] = this->sourcePaused;
json[JsonStringPreferredProfile] =
RTC::RtpEncodingParameters::profile2String[this->preferredProfile];
json[JsonStringEffectiveProfile] =
RTC::RtpEncodingParameters::profile2String[this->effectiveProfile];
return json; return json;
} }
...@@ -245,7 +253,7 @@ namespace RTC ...@@ -245,7 +253,7 @@ namespace RTC
this->retransmittedCounter.Reset(); this->retransmittedCounter.Reset();
} }
void Consumer::SendRtpPacket(RTC::RtpPacket* packet, RTC::RtpProfile profile) void Consumer::SendRtpPacket(RTC::RtpPacket* packet, RTC::RtpEncodingParameters::Profile profile)
{ {
MS_TRACE(); MS_TRACE();
......
...@@ -303,13 +303,13 @@ namespace RTC ...@@ -303,13 +303,13 @@ namespace RTC
if (this->paused) if (this->paused)
return; return;
RTC::RtpProfile profile; RTC::RtpEncodingParameters::Profile profile;
try try
{ {
profile = GetRtpProfile(packet); profile = GetRtpProfile(packet);
} }
catch(const MediaSoupError& error) catch (const MediaSoupError& error)
{ {
return; return;
} }
...@@ -418,11 +418,9 @@ namespace RTC ...@@ -418,11 +418,9 @@ namespace RTC
return; return;
} }
else
{ // Run the timer.
// Run the timer. this->fullFrameRequestBlockTimer->Start(FullFrameRequestBlockTimeout);
this->fullFrameRequestBlockTimer->Start(FullFrameRequestBlockTimeout);
}
for (auto& kv : this->rtpStreams) for (auto& kv : this->rtpStreams)
{ {
...@@ -588,7 +586,7 @@ namespace RTC ...@@ -588,7 +586,7 @@ namespace RTC
} }
} }
RTC::RtpProfile Producer::GetRtpProfile(RTC::RtpPacket* packet) RTC::RtpEncodingParameters::Profile Producer::GetRtpProfile(RTC::RtpPacket* packet)
{ {
auto ssrc = packet->GetSsrc(); auto ssrc = packet->GetSsrc();
......
...@@ -1071,6 +1071,47 @@ namespace RTC ...@@ -1071,6 +1071,47 @@ namespace RTC
break; break;
} }
case Channel::Request::MethodId::CONSUMER_SET_PREFERRED_PROFILE:
{
static const Json::StaticString JsonStringProfile{ "profile" };
RTC::Consumer* consumer;
try
{
consumer = GetConsumerFromRequest(request);
}
catch (const MediaSoupError& error)
{
request->Reject(error.what());
return;
}
if (!request->data[JsonStringProfile].isString())
{
request->Reject("missing data.profile");
return;
}
std::string profileStr = request->data[JsonStringProfile].asString();
auto it = RTC::RtpEncodingParameters::string2Profile.find(profileStr);
if (it == RTC::RtpEncodingParameters::string2Profile.end())
{
request->Reject("unknown profile");
return;
}
consumer->SetPreferredProfile(it->second);
request->Accept();
break;
}
default: default:
{ {
MS_ERROR("unknown method"); MS_ERROR("unknown method");
...@@ -1329,7 +1370,8 @@ namespace RTC ...@@ -1329,7 +1370,8 @@ namespace RTC
} }
} }
void Router::OnProducerRtpPacket(RTC::Producer* producer, RTC::RtpPacket* packet, RTC::RtpProfile profile) void Router::OnProducerRtpPacket(
RTC::Producer* producer, RTC::RtpPacket* packet, RTC::RtpEncodingParameters::Profile profile)
{ {
MS_TRACE(); MS_TRACE();
......
...@@ -7,6 +7,26 @@ ...@@ -7,6 +7,26 @@
namespace RTC namespace RTC
{ {
/* Class static data. */
// clang-format off
std::map<std::string, RTC::RtpEncodingParameters::Profile> RTC::RtpEncodingParameters::string2Profile =
{
{ "default", RTC::RtpEncodingParameters::Profile::DEFAULT },
{ "low", RTC::RtpEncodingParameters::Profile::LOW },
{ "medium", RTC::RtpEncodingParameters::Profile::MEDIUM },
{ "high", RTC::RtpEncodingParameters::Profile::HIGH }
};
std::map<RTC::RtpEncodingParameters::Profile, std::string> RTC::RtpEncodingParameters::profile2String =
{
{ RTC::RtpEncodingParameters::Profile::DEFAULT, "default" },
{ RTC::RtpEncodingParameters::Profile::LOW, "low" },
{ RTC::RtpEncodingParameters::Profile::MEDIUM, "medium" },
{ RTC::RtpEncodingParameters::Profile::HIGH, "high" }
};
// clang-format on
/* Instance methods. */ /* Instance methods. */
RtpEncodingParameters::RtpEncodingParameters(Json::Value& data) RtpEncodingParameters::RtpEncodingParameters(Json::Value& data)
...@@ -23,6 +43,7 @@ namespace RTC ...@@ -23,6 +43,7 @@ namespace RTC
static const Json::StaticString JsonStringActive{ "active" }; static const Json::StaticString JsonStringActive{ "active" };
static const Json::StaticString JsonStringEncodingId{ "encodingId" }; static const Json::StaticString JsonStringEncodingId{ "encodingId" };
static const Json::StaticString JsonStringDependencyEncodingIds{ "dependencyEncodingIds" }; static const Json::StaticString JsonStringDependencyEncodingIds{ "dependencyEncodingIds" };
static const Json::StaticString JsonStringProfile{ "profile" };
if (!data.isObject()) if (!data.isObject())
MS_THROW_ERROR("RtpEncodingParameters is not an object"); MS_THROW_ERROR("RtpEncodingParameters is not an object");
...@@ -84,6 +105,17 @@ namespace RTC ...@@ -84,6 +105,17 @@ namespace RTC
this->dependencyEncodingIds.push_back(entry.asString()); this->dependencyEncodingIds.push_back(entry.asString());
} }
} }
// profile is optional.
if (data[JsonStringProfile].isString())
{
std::string profileStr = data[JsonStringProfile].asString();
if (string2Profile.find(profileStr) == string2Profile.end())
MS_THROW_ERROR("unknown profile");
this->profile = string2Profile[profileStr];
}
} }
Json::Value RtpEncodingParameters::ToJson() const Json::Value RtpEncodingParameters::ToJson() const
...@@ -100,6 +132,7 @@ namespace RTC ...@@ -100,6 +132,7 @@ namespace RTC
static const Json::StaticString JsonStringActive{ "active" }; static const Json::StaticString JsonStringActive{ "active" };
static const Json::StaticString JsonStringEncodingId{ "encodingId" }; static const Json::StaticString JsonStringEncodingId{ "encodingId" };
static const Json::StaticString JsonStringDependencyEncodingIds{ "dependencyEncodingIds" }; static const Json::StaticString JsonStringDependencyEncodingIds{ "dependencyEncodingIds" };
static const Json::StaticString JsonStringProfile{ "profile" };
Json::Value json(Json::objectValue); Json::Value json(Json::objectValue);
...@@ -149,6 +182,8 @@ namespace RTC ...@@ -149,6 +182,8 @@ namespace RTC
} }
} }
json[JsonStringProfile] = RtpEncodingParameters::profile2String[this->profile];
return json; return json;
} }
} // namespace RTC } // namespace RTC
...@@ -1555,7 +1555,10 @@ namespace RTC ...@@ -1555,7 +1555,10 @@ namespace RTC
// Do nothing. // Do nothing.
} }
void Transport::OnProducerRtpPacket(RTC::Producer* /*producer*/, RTC::RtpPacket* /*packet*/, RTC::RtpProfile /*profile*/) void Transport::OnProducerRtpPacket(
RTC::Producer* /*producer*/,
RTC::RtpPacket* /*packet*/,
RTC::RtpEncodingParameters::Profile /*profile*/)
{ {
// Do nothing. // Do nothing.
} }
......
...@@ -259,6 +259,7 @@ void Worker::OnChannelRequest(Channel::UnixStreamSocket* /*channel*/, Channel::R ...@@ -259,6 +259,7 @@ void Worker::OnChannelRequest(Channel::UnixStreamSocket* /*channel*/, Channel::R
case Channel::Request::MethodId::CONSUMER_ENABLE: case Channel::Request::MethodId::CONSUMER_ENABLE:
case Channel::Request::MethodId::CONSUMER_PAUSE: case Channel::Request::MethodId::CONSUMER_PAUSE:
case Channel::Request::MethodId::CONSUMER_RESUME: case Channel::Request::MethodId::CONSUMER_RESUME:
case Channel::Request::MethodId::CONSUMER_SET_PREFERRED_PROFILE:
{ {
RTC::Router* router; RTC::Router* router;
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论