Add PeerConnection GetRtpSender/ReceiverCapabilities
Those are static functions in the spec, so implemented as member functions of the PeerConnectionFactory instead. Bug: webrtc:7577, webrtc:9441 Change-Id: Iccb24180e096e713d24e7e25ecfd5d7bbd7638f9 Reviewed-on: https://webrtc-review.googlesource.com/85341 Commit-Queue: Florent Castelli <orphis@webrtc.org> Reviewed-by: Taylor Brandstetter <deadbeef@webrtc.org> Reviewed-by: Steve Anton <steveanton@webrtc.org> Cr-Commit-Position: refs/heads/master@{#23768}
This commit is contained in:

committed by
Commit Bot

parent
0d4070a18c
commit
72b751af0b
@ -48,6 +48,12 @@ PROXY_METHOD2(rtc::scoped_refptr<PeerConnectionInterface>,
|
||||
CreatePeerConnection,
|
||||
const PeerConnectionInterface::RTCConfiguration&,
|
||||
PeerConnectionDependencies);
|
||||
PROXY_CONSTMETHOD1(webrtc::RtpCapabilities,
|
||||
GetRtpSenderCapabilities,
|
||||
cricket::MediaType);
|
||||
PROXY_CONSTMETHOD1(webrtc::RtpCapabilities,
|
||||
GetRtpReceiverCapabilities,
|
||||
cricket::MediaType);
|
||||
PROXY_METHOD1(rtc::scoped_refptr<MediaStreamInterface>,
|
||||
CreateLocalMediaStream,
|
||||
const std::string&)
|
||||
|
@ -1307,6 +1307,22 @@ class PeerConnectionFactoryInterface : public rtc::RefCountInterface {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Returns the capabilities of an RTP sender of type |kind|.
|
||||
// If for some reason you pass in MEDIA_TYPE_DATA, returns an empty structure.
|
||||
// TODO(orphis): Make pure virtual when all subclasses implement it.
|
||||
virtual RtpCapabilities GetRtpSenderCapabilities(
|
||||
cricket::MediaType kind) const {
|
||||
return {};
|
||||
}
|
||||
|
||||
// Returns the capabilities of an RTP receiver of type |kind|.
|
||||
// If for some reason you pass in MEDIA_TYPE_DATA, returns an empty structure.
|
||||
// TODO(orphis): Make pure virtual when all subclasses implement it.
|
||||
virtual RtpCapabilities GetRtpReceiverCapabilities(
|
||||
cricket::MediaType kind) const {
|
||||
return {};
|
||||
}
|
||||
|
||||
virtual rtc::scoped_refptr<MediaStreamInterface> CreateLocalMediaStream(
|
||||
const std::string& stream_id) = 0;
|
||||
|
||||
|
@ -21,8 +21,6 @@ rtc_static_library("ortc") {
|
||||
"ortcrtpreceiveradapter.h",
|
||||
"ortcrtpsenderadapter.cc",
|
||||
"ortcrtpsenderadapter.h",
|
||||
"rtpparametersconversion.cc",
|
||||
"rtpparametersconversion.h",
|
||||
"rtptransportadapter.cc",
|
||||
"rtptransportadapter.h",
|
||||
"rtptransportcontrolleradapter.cc",
|
||||
@ -71,7 +69,6 @@ if (rtc_include_tests) {
|
||||
"ortcfactory_unittest.cc",
|
||||
"ortcrtpreceiver_unittest.cc",
|
||||
"ortcrtpsender_unittest.cc",
|
||||
"rtpparametersconversion_unittest.cc",
|
||||
"rtptransport_unittest.cc",
|
||||
"rtptransportcontroller_unittest.cc",
|
||||
"srtptransport_unittest.cc",
|
||||
|
@ -26,7 +26,6 @@
|
||||
#include "modules/audio_processing/include/audio_processing.h"
|
||||
#include "ortc/ortcrtpreceiveradapter.h"
|
||||
#include "ortc/ortcrtpsenderadapter.h"
|
||||
#include "ortc/rtpparametersconversion.h"
|
||||
#include "ortc/rtptransportadapter.h"
|
||||
#include "ortc/rtptransportcontrolleradapter.h"
|
||||
#include "p2p/base/basicpacketsocketfactory.h"
|
||||
@ -34,6 +33,7 @@
|
||||
#include "pc/audiotrack.h"
|
||||
#include "pc/channelmanager.h"
|
||||
#include "pc/localaudiosource.h"
|
||||
#include "pc/rtpparametersconversion.h"
|
||||
#include "pc/videotrack.h"
|
||||
#include "rtc_base/asyncpacketsocket.h"
|
||||
#include "rtc_base/bind.h"
|
||||
|
@ -20,9 +20,9 @@
|
||||
#include "media/base/mediaconstants.h"
|
||||
#include "ortc/ortcrtpreceiveradapter.h"
|
||||
#include "ortc/ortcrtpsenderadapter.h"
|
||||
#include "ortc/rtpparametersconversion.h"
|
||||
#include "ortc/rtptransportadapter.h"
|
||||
#include "pc/rtpmediautils.h"
|
||||
#include "pc/rtpparametersconversion.h"
|
||||
#include "rtc_base/checks.h"
|
||||
#include "rtc_base/ptr_util.h"
|
||||
|
||||
|
@ -153,6 +153,8 @@ rtc_static_library("peerconnection") {
|
||||
"rtcstatscollector.h",
|
||||
"rtcstatstraversal.cc",
|
||||
"rtcstatstraversal.h",
|
||||
"rtpparametersconversion.cc",
|
||||
"rtpparametersconversion.h",
|
||||
"rtpreceiver.cc",
|
||||
"rtpreceiver.h",
|
||||
"rtpsender.cc",
|
||||
@ -487,6 +489,7 @@ if (rtc_include_tests) {
|
||||
"rtcstatscollector_unittest.cc",
|
||||
"rtcstatstraversal_unittest.cc",
|
||||
"rtpmediautils_unittest.cc",
|
||||
"rtpparametersconversion_unittest.cc",
|
||||
"rtpsenderreceiver_unittest.cc",
|
||||
"sctputils_unittest.cc",
|
||||
"statscollector_unittest.cc",
|
||||
|
@ -11,6 +11,7 @@
|
||||
#include "pc/peerconnectionfactory.h"
|
||||
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "api/fec_controller.h"
|
||||
#include "api/mediaconstraintsinterface.h"
|
||||
@ -23,6 +24,7 @@
|
||||
#include "logging/rtc_event_log/rtc_event_log.h"
|
||||
#include "media/base/rtpdataengine.h"
|
||||
#include "media/sctp/sctptransport.h"
|
||||
#include "pc/rtpparametersconversion.h"
|
||||
#include "rtc_base/bind.h"
|
||||
#include "rtc_base/checks.h"
|
||||
#include "rtc_base/ptr_util.h"
|
||||
@ -231,6 +233,60 @@ void PeerConnectionFactory::SetOptions(const Options& options) {
|
||||
options_ = options;
|
||||
}
|
||||
|
||||
RtpCapabilities PeerConnectionFactory::GetRtpSenderCapabilities(
|
||||
cricket::MediaType kind) const {
|
||||
RTC_DCHECK_RUN_ON(signaling_thread_);
|
||||
switch (kind) {
|
||||
case cricket::MEDIA_TYPE_AUDIO: {
|
||||
cricket::AudioCodecs cricket_codecs;
|
||||
cricket::RtpHeaderExtensions cricket_extensions;
|
||||
channel_manager_->GetSupportedAudioSendCodecs(&cricket_codecs);
|
||||
channel_manager_->GetSupportedAudioRtpHeaderExtensions(
|
||||
&cricket_extensions);
|
||||
return ToRtpCapabilities(cricket_codecs, cricket_extensions);
|
||||
}
|
||||
case cricket::MEDIA_TYPE_VIDEO: {
|
||||
cricket::VideoCodecs cricket_codecs;
|
||||
cricket::RtpHeaderExtensions cricket_extensions;
|
||||
channel_manager_->GetSupportedVideoCodecs(&cricket_codecs);
|
||||
channel_manager_->GetSupportedVideoRtpHeaderExtensions(
|
||||
&cricket_extensions);
|
||||
return ToRtpCapabilities(cricket_codecs, cricket_extensions);
|
||||
}
|
||||
case cricket::MEDIA_TYPE_DATA:
|
||||
return RtpCapabilities();
|
||||
}
|
||||
// Not reached; avoids compile warning.
|
||||
FATAL();
|
||||
}
|
||||
|
||||
RtpCapabilities PeerConnectionFactory::GetRtpReceiverCapabilities(
|
||||
cricket::MediaType kind) const {
|
||||
RTC_DCHECK_RUN_ON(signaling_thread_);
|
||||
switch (kind) {
|
||||
case cricket::MEDIA_TYPE_AUDIO: {
|
||||
cricket::AudioCodecs cricket_codecs;
|
||||
cricket::RtpHeaderExtensions cricket_extensions;
|
||||
channel_manager_->GetSupportedAudioReceiveCodecs(&cricket_codecs);
|
||||
channel_manager_->GetSupportedAudioRtpHeaderExtensions(
|
||||
&cricket_extensions);
|
||||
return ToRtpCapabilities(cricket_codecs, cricket_extensions);
|
||||
}
|
||||
case cricket::MEDIA_TYPE_VIDEO: {
|
||||
cricket::VideoCodecs cricket_codecs;
|
||||
cricket::RtpHeaderExtensions cricket_extensions;
|
||||
channel_manager_->GetSupportedVideoCodecs(&cricket_codecs);
|
||||
channel_manager_->GetSupportedVideoRtpHeaderExtensions(
|
||||
&cricket_extensions);
|
||||
return ToRtpCapabilities(cricket_codecs, cricket_extensions);
|
||||
}
|
||||
case cricket::MEDIA_TYPE_DATA:
|
||||
return RtpCapabilities();
|
||||
}
|
||||
// Not reached; avoids compile warning.
|
||||
FATAL();
|
||||
}
|
||||
|
||||
rtc::scoped_refptr<AudioSourceInterface>
|
||||
PeerConnectionFactory::CreateAudioSource(const cricket::AudioOptions& options) {
|
||||
RTC_DCHECK(signaling_thread_->IsCurrent());
|
||||
|
@ -62,6 +62,12 @@ class PeerConnectionFactory : public PeerConnectionFactoryInterface {
|
||||
|
||||
bool Initialize();
|
||||
|
||||
RtpCapabilities GetRtpSenderCapabilities(
|
||||
cricket::MediaType kind) const override;
|
||||
|
||||
RtpCapabilities GetRtpReceiverCapabilities(
|
||||
cricket::MediaType kind) const override;
|
||||
|
||||
rtc::scoped_refptr<MediaStreamInterface> CreateLocalMediaStream(
|
||||
const std::string& stream_id) override;
|
||||
|
||||
|
@ -130,6 +130,19 @@ class PeerConnectionFactoryTest : public testing::Test {
|
||||
}
|
||||
}
|
||||
|
||||
void VerifyAudioCodecCapability(const webrtc::RtpCodecCapability& codec) {
|
||||
EXPECT_EQ(codec.kind, cricket::MEDIA_TYPE_AUDIO);
|
||||
EXPECT_FALSE(codec.name.empty());
|
||||
EXPECT_GT(codec.clock_rate, 0);
|
||||
EXPECT_GT(codec.num_channels, 0);
|
||||
}
|
||||
|
||||
void VerifyVideoCodecCapability(const webrtc::RtpCodecCapability& codec) {
|
||||
EXPECT_EQ(codec.kind, cricket::MEDIA_TYPE_VIDEO);
|
||||
EXPECT_FALSE(codec.name.empty());
|
||||
EXPECT_GT(codec.clock_rate, 0);
|
||||
}
|
||||
|
||||
rtc::scoped_refptr<PeerConnectionFactoryInterface> factory_;
|
||||
NullPeerConnectionObserver observer_;
|
||||
std::unique_ptr<cricket::FakePortAllocator> port_allocator_;
|
||||
@ -170,6 +183,72 @@ TEST(PeerConnectionFactoryTestInternal, DISABLED_CreatePCUsingInternalModules) {
|
||||
EXPECT_TRUE(pc.get() != nullptr);
|
||||
}
|
||||
|
||||
TEST_F(PeerConnectionFactoryTest, CheckRtpSenderAudioCapabilities) {
|
||||
webrtc::RtpCapabilities audio_capabilities =
|
||||
factory_->GetRtpSenderCapabilities(cricket::MEDIA_TYPE_AUDIO);
|
||||
EXPECT_FALSE(audio_capabilities.codecs.empty());
|
||||
for (const auto& codec : audio_capabilities.codecs) {
|
||||
VerifyAudioCodecCapability(codec);
|
||||
}
|
||||
EXPECT_FALSE(audio_capabilities.header_extensions.empty());
|
||||
for (const auto& header_extension : audio_capabilities.header_extensions) {
|
||||
EXPECT_FALSE(header_extension.uri.empty());
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(PeerConnectionFactoryTest, CheckRtpSenderVideoCapabilities) {
|
||||
webrtc::RtpCapabilities video_capabilities =
|
||||
factory_->GetRtpSenderCapabilities(cricket::MEDIA_TYPE_VIDEO);
|
||||
EXPECT_FALSE(video_capabilities.codecs.empty());
|
||||
for (const auto& codec : video_capabilities.codecs) {
|
||||
VerifyVideoCodecCapability(codec);
|
||||
}
|
||||
EXPECT_FALSE(video_capabilities.header_extensions.empty());
|
||||
for (const auto& header_extension : video_capabilities.header_extensions) {
|
||||
EXPECT_FALSE(header_extension.uri.empty());
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(PeerConnectionFactoryTest, CheckRtpSenderDataCapabilities) {
|
||||
webrtc::RtpCapabilities data_capabilities =
|
||||
factory_->GetRtpSenderCapabilities(cricket::MEDIA_TYPE_DATA);
|
||||
EXPECT_TRUE(data_capabilities.codecs.empty());
|
||||
EXPECT_TRUE(data_capabilities.header_extensions.empty());
|
||||
}
|
||||
|
||||
TEST_F(PeerConnectionFactoryTest, CheckRtpReceiverAudioCapabilities) {
|
||||
webrtc::RtpCapabilities audio_capabilities =
|
||||
factory_->GetRtpReceiverCapabilities(cricket::MEDIA_TYPE_AUDIO);
|
||||
EXPECT_FALSE(audio_capabilities.codecs.empty());
|
||||
for (const auto& codec : audio_capabilities.codecs) {
|
||||
VerifyAudioCodecCapability(codec);
|
||||
}
|
||||
EXPECT_FALSE(audio_capabilities.header_extensions.empty());
|
||||
for (const auto& header_extension : audio_capabilities.header_extensions) {
|
||||
EXPECT_FALSE(header_extension.uri.empty());
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(PeerConnectionFactoryTest, CheckRtpReceiverVideoCapabilities) {
|
||||
webrtc::RtpCapabilities video_capabilities =
|
||||
factory_->GetRtpReceiverCapabilities(cricket::MEDIA_TYPE_VIDEO);
|
||||
EXPECT_FALSE(video_capabilities.codecs.empty());
|
||||
for (const auto& codec : video_capabilities.codecs) {
|
||||
VerifyVideoCodecCapability(codec);
|
||||
}
|
||||
EXPECT_FALSE(video_capabilities.header_extensions.empty());
|
||||
for (const auto& header_extension : video_capabilities.header_extensions) {
|
||||
EXPECT_FALSE(header_extension.uri.empty());
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(PeerConnectionFactoryTest, CheckRtpReceiverDataCapabilities) {
|
||||
webrtc::RtpCapabilities data_capabilities =
|
||||
factory_->GetRtpReceiverCapabilities(cricket::MEDIA_TYPE_DATA);
|
||||
EXPECT_TRUE(data_capabilities.codecs.empty());
|
||||
EXPECT_TRUE(data_capabilities.header_extensions.empty());
|
||||
}
|
||||
|
||||
// This test verifies creation of PeerConnection with valid STUN and TURN
|
||||
// configuration. Also verifies the URL's parsed correctly as expected.
|
||||
TEST_F(PeerConnectionFactoryTest, CreatePCUsingIceServers) {
|
||||
|
@ -8,10 +8,9 @@
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
#include "ortc/rtpparametersconversion.h"
|
||||
#include "pc/rtpparametersconversion.h"
|
||||
|
||||
#include <set>
|
||||
#include <sstream>
|
||||
#include <utility>
|
||||
|
||||
#include "media/base/rtputils.h"
|
||||
@ -136,9 +135,10 @@ RTCErrorOr<C> ToCricketCodec(const RtpCodecParameters& codec) {
|
||||
}
|
||||
cricket_codec.name = codec.name;
|
||||
if (!cricket::IsValidRtpPayloadType(codec.payload_type)) {
|
||||
std::ostringstream oss;
|
||||
oss << "Invalid payload type: " << codec.payload_type;
|
||||
LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_RANGE, oss.str());
|
||||
char buf[40];
|
||||
rtc::SimpleStringBuilder sb(buf);
|
||||
sb << "Invalid payload type: " << codec.payload_type;
|
||||
LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_RANGE, sb.str());
|
||||
}
|
||||
cricket_codec.id = codec.payload_type;
|
||||
for (const RtcpFeedback& feedback : codec.rtcp_feedback) {
|
||||
@ -168,9 +168,10 @@ RTCErrorOr<std::vector<C>> ToCricketCodecs(
|
||||
return result.MoveError();
|
||||
}
|
||||
if (!seen_payload_types.insert(codec.payload_type).second) {
|
||||
std::ostringstream oss;
|
||||
oss << "Duplicate payload type: " << codec.payload_type;
|
||||
LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_PARAMETER, oss.str());
|
||||
char buf[40];
|
||||
rtc::SimpleStringBuilder sb(buf);
|
||||
sb << "Duplicate payload type: " << codec.payload_type;
|
||||
LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_PARAMETER, sb.str());
|
||||
}
|
||||
cricket_codecs.push_back(result.MoveValue());
|
||||
}
|
||||
@ -186,17 +187,20 @@ template RTCErrorOr<std::vector<cricket::VideoCodec>> ToCricketCodecs<
|
||||
RTCErrorOr<cricket::RtpHeaderExtensions> ToCricketRtpHeaderExtensions(
|
||||
const std::vector<RtpHeaderExtensionParameters>& extensions) {
|
||||
cricket::RtpHeaderExtensions cricket_extensions;
|
||||
std::ostringstream err_writer;
|
||||
std::set<int> seen_header_extension_ids;
|
||||
for (const RtpHeaderExtensionParameters& extension : extensions) {
|
||||
if (extension.id < RtpHeaderExtensionParameters::kMinId ||
|
||||
extension.id > RtpHeaderExtensionParameters::kMaxId) {
|
||||
err_writer << "Invalid header extension id: " << extension.id;
|
||||
LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_RANGE, err_writer.str());
|
||||
char buf[50];
|
||||
rtc::SimpleStringBuilder sb(buf);
|
||||
sb << "Invalid header extension id: " << extension.id;
|
||||
LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_RANGE, sb.str());
|
||||
}
|
||||
if (!seen_header_extension_ids.insert(extension.id).second) {
|
||||
err_writer << "Duplicate header extension id: " << extension.id;
|
||||
LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_PARAMETER, err_writer.str());
|
||||
char buf[50];
|
||||
rtc::SimpleStringBuilder sb(buf);
|
||||
sb << "Duplicate header extension id: " << extension.id;
|
||||
LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_PARAMETER, sb.str());
|
||||
}
|
||||
cricket_extensions.push_back(extension);
|
||||
}
|
@ -8,8 +8,8 @@
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
#ifndef ORTC_RTPPARAMETERSCONVERSION_H_
|
||||
#define ORTC_RTPPARAMETERSCONVERSION_H_
|
||||
#ifndef PC_RTPPARAMETERSCONVERSION_H_
|
||||
#define PC_RTPPARAMETERSCONVERSION_H_
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
@ -105,4 +105,4 @@ RtpParameters ToRtpParameters(
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
#endif // ORTC_RTPPARAMETERSCONVERSION_H_
|
||||
#endif // PC_RTPPARAMETERSCONVERSION_H_
|
@ -10,8 +10,7 @@
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include "ortc/rtpparametersconversion.h"
|
||||
#include "ortc/testrtpparameters.h"
|
||||
#include "pc/rtpparametersconversion.h"
|
||||
#include "rtc_base/gunit.h"
|
||||
|
||||
namespace webrtc {
|
Reference in New Issue
Block a user