Skip to content

Commit

Permalink
Feat/expose set codec preferences and get capabilities (#60)
Browse files Browse the repository at this point in the history
* feat: capabilities.

* fix: fix crash.

* update.

* update.
  • Loading branch information
cloudwebrtc authored Feb 1, 2023
1 parent 3a92a24 commit ae76f52
Show file tree
Hide file tree
Showing 12 changed files with 419 additions and 109 deletions.
3 changes: 3 additions & 0 deletions BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ rtc_shared_library("libwebrtc") {
"include/rtc_mediaconstraints.h",
"include/rtc_peerconnection.h",
"include/rtc_peerconnection_factory.h",
"include/rtc_rtp_capabilities.h",
"include/rtc_rtp_parameters.h",
"include/rtc_rtp_receiver.h",
"include/rtc_rtp_sender.h",
Expand Down Expand Up @@ -109,6 +110,8 @@ rtc_shared_library("libwebrtc") {
"src/rtc_peerconnection_factory_impl.h",
"src/rtc_peerconnection_impl.cc",
"src/rtc_peerconnection_impl.h",
"src/rtc_rtp_capabilities_impl.cc",
"src/rtc_rtp_capabilities_impl.h",
"src/rtc_rtp_parameters_impl.cc",
"src/rtc_rtp_parameters_impl.h",
"src/rtc_rtp_receiver_impl.cc",
Expand Down
7 changes: 7 additions & 0 deletions include/rtc_peerconnection_factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ namespace libwebrtc {
class RTCPeerConnection;
class RTCAudioDevice;
class RTCVideoDevice;
class RTCRtpCapabilities;

class RTCPeerConnectionFactory : public RefCountInterface {
public:
Expand Down Expand Up @@ -60,6 +61,12 @@ class RTCPeerConnectionFactory : public RefCountInterface {

virtual scoped_refptr<RTCMediaStream> CreateStream(
const string stream_id) = 0;

virtual scoped_refptr<RTCRtpCapabilities> GetRtpSenderCapabilities(
RTCMediaType media_type) = 0;

virtual scoped_refptr<RTCRtpCapabilities> GetRtpReceiverCapabilities(
RTCMediaType media_type) = 0;
};

} // namespace libwebrtc
Expand Down
62 changes: 62 additions & 0 deletions include/rtc_rtp_capabilities.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#ifndef LIB_WBBRTC_RTC_RTP_CAPABILITIES_HXX
#define LIB_WBBRTC_RTC_RTP_CAPABILITIES_HXX

#include "base/refcount.h"
#include "base/scoped_ref_ptr.h"

#include "rtc_rtp_parameters.h"
#include "rtc_types.h"


namespace libwebrtc {

class RTCRtpCodecCapability : public RefCountInterface {
public:
LIB_WEBRTC_API static scoped_refptr<RTCRtpCodecCapability> Create();

virtual void set_mime_type(const string& mime_type) = 0;
virtual void set_clock_rate(int clock_rate) = 0;
virtual void set_channels(int channels) = 0;
virtual void set_sdp_fmtp_line(const string& sdp_fmtp_line) = 0;

virtual string mime_type() const = 0;
virtual int clock_rate() const = 0;
virtual int channels() const = 0;
virtual string sdp_fmtp_line() const = 0;

protected:
virtual ~RTCRtpCodecCapability() {}
};

class RTCRtpHeaderExtensionCapability : public RefCountInterface {
public:
virtual const string uri() = 0;
virtual void set_uri(const string uri) = 0;

virtual int preferred_id() = 0;
virtual void set_preferred_id(int value) = 0;

virtual bool preferred_encrypt() = 0;
virtual void set_preferred_encrypt(bool value) = 0;
};

class RTCRtpCapabilities : public RefCountInterface {
public:
virtual const vector<scoped_refptr<RTCRtpCodecCapability>> codecs() = 0;
virtual void set_codecs(
const vector<scoped_refptr<RTCRtpCodecCapability>> codecs) = 0;

virtual const vector<scoped_refptr<RTCRtpHeaderExtensionCapability>>
header_extensions() = 0;

virtual void set_header_extensions(
const vector<scoped_refptr<RTCRtpHeaderExtensionCapability>>
header_extensions) = 0;

//virtual const vector<scoped_refptr<RTCFecMechanism>> fec() = 0;
//virtual void set_fec(const vector<scoped_refptr<RTCFecMechanism>> fec) = 0;
};

} // namespace libwebrtc

#endif // LIB_WBBRTC_RTC_RTP_CAPABILITIES_HXX
90 changes: 3 additions & 87 deletions include/rtc_rtp_parameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,73 +59,6 @@ class RTCRtcpFeedback : public RefCountInterface {
virtual bool operator!=(scoped_refptr<RTCRtcpFeedback> o) = 0;
};

/* class RTCRtpCodecCapability : public RefCountInterface {
virtual const string mine_type() const = 0;
virtual const string name() = 0;
virtual void set_name(const string name) = 0;
virtual RTCMediaType kind() = 0;
virtual void set_kind(RTCMediaType value) = 0;
virtual int clock_rate() = 0;
virtual void set_clock_rate(int value) = 0;
virtual int preferred_payload_type() = 0;
virtual void set_preferred_payload_type(int value) = 0;
virtual int max_ptime() = 0;
virtual void set_max_ptime(int value) = 0;
virtual int ptime() = 0;
virtual void set_ptime(int value) = 0;
virtual int num_channels() = 0;
virtual void set_num_channels(int value) = 0;
virtual vector<scoped_refptr<RTCRtcpFeedback>> rtcp_feedback() = 0;
virtual void set_rtcp_feedback(vector<scoped_refptr<RTCRtcpFeedback>>
rtcp_feecbacks) = 0;
virtual const map<string,string> parameters() = 0;
virtual void set_parameters(const map<string, string> parameters) = 0;
virtual const map<string, string> ptions() = 0;
virtual void set_options(map<string, string> options) = 0;
virtual int max_temporal_layer_extensions() = 0;
virtual void set_max_temporal_layer_extensions(int value) = 0;
virtual int max_spatial_layer_extensions() = 0;
virtual void set_max_spatial_layer_extensions(int value) = 0;
virtual bool svc_multi_stream_support() = 0;
virtual void set_svc_multi_stream_support(bool value) = 0;
virtual bool operator==(scoped_refptr<RTCRtpCodecCapability> o) const = 0;
virtual bool operator!=(scoped_refptr<RTCRtpCodecCapability> o) const = 0;
};*/

class RTCRtpHeaderExtensionCapability : public RefCountInterface {
virtual const string uri() = 0;
virtual void set_uri(const string uri) = 0;

virtual int preferred_id() = 0;
virtual void set_preferred_id(int value) = 0;

virtual bool preferred_encrypt() = 0;
virtual void set_preferred_encrypt(bool value) = 0;

virtual RTCRtpTransceiverDirection direction() = 0;
virtual void set_direction(RTCRtpTransceiverDirection value) = 0;

virtual bool operator==(
scoped_refptr<RTCRtpHeaderExtensionCapability> o) const = 0;
virtual bool operator!=(
scoped_refptr<RTCRtpHeaderExtensionCapability> o) const = 0;
};

class RTCRtpExtension : public RefCountInterface {
public:
enum RTCFilter {
Expand Down Expand Up @@ -201,27 +134,10 @@ class RTCRtpCodecParameters : public RefCountInterface {

virtual bool operator==(scoped_refptr<RTCRtpCodecParameters> o) = 0;
virtual bool operator!=(scoped_refptr<RTCRtpCodecParameters> o) = 0;
};

/*
class RTCRtpCapabilities : public RefCountInterface {
virtual const vector<scoped_refptr<RTCRtpCodecCapability>> codecs() = 0;
virtual void set_codecs(
const vector<scoped_refptr<RTCRtpCodecCapability>> codecs) = 0;

virtual const vector<scoped_refptr<RTCRtpHeaderExtensionCapability>>
header_extensions() = 0;
virtual void set_header_extensions(
const vector<scoped_refptr<RTCRtpHeaderExtensionCapability>>
header_extensions) = 0;
virtual const vector<scoped_refptr<RTCFecMechanism>> fec() = 0;
virtual void set_fec(const vector<scoped_refptr<RTCFecMechanism>> fec) = 0;
virtual bool operator==(scoped_refptr<RTCRtpCapabilities> o) = 0;
virtual bool operator!=(scoped_refptr<RTCRtpCapabilities> o) = 0;
};*/
protected:
virtual ~RTCRtpCodecParameters() {}
};

class RTCRtcpParameters : public RefCountInterface {
public:
Expand Down
16 changes: 3 additions & 13 deletions include/rtc_rtp_transceiver.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define LIB_WEBRTC_RTC_RTP_TRANSCEIVER_HXX

#include "base/refcount.h"
#include "rtc_rtp_capabilities.h"
#include "rtc_rtp_parameters.h"
#include "rtc_rtp_receiver.h"
#include "rtc_rtp_sender.h"
Expand Down Expand Up @@ -55,19 +56,8 @@ class RTCRtpTransceiver : public RefCountInterface {

virtual void StopInternal() = 0;

// virtual string set_codec_preferences(vector<RTCRtpCodecCapability> codecs)
// = 0;

// virtual vector<RTCRtpCodecCapability> codec_preferences() const = 0;

// virtual vector<RTCRtpHeaderExtensionCapability> HeaderExtensionsToOffer()
// const = 0;

// virtual std::vector<RTCRtpHeaderExtensionCapability>
// HeaderExtensionsNegotiated() const = 0;

// virtual webrtc::RTCError SetOfferedRtpHeaderExtensions(vector<const
// RTCRtpHeaderExtensionCapability> header_extensions_to_offer);
virtual void SetCodecPreferences(
vector<scoped_refptr<RTCRtpCodecCapability>> codecs) = 0;
};

} // namespace libwebrtc
Expand Down
59 changes: 59 additions & 0 deletions src/rtc_peerconnection_factory_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
#include "rtc_media_stream_impl.h"
#include "rtc_mediaconstraints_impl.h"
#include "rtc_peerconnection_impl.h"
#include "rtc_rtp_capabilities_impl.h"
#include "rtc_video_device_impl.h"
#include "rtc_video_source_impl.h"


#include "api/audio_codecs/builtin_audio_decoder_factory.h"
#include "api/audio_codecs/builtin_audio_encoder_factory.h"
#include "api/create_peerconnection_factory.h"
Expand Down Expand Up @@ -296,4 +298,61 @@ scoped_refptr<RTCAudioTrack> RTCPeerConnectionFactoryImpl::CreateAudioTrack(
return track;
}

scoped_refptr<RTCRtpCapabilities>
RTCPeerConnectionFactoryImpl::GetRtpSenderCapabilities(
RTCMediaType media_type) {
if (rtc::Thread::Current() != signaling_thread_) {
scoped_refptr<RTCRtpCapabilities> capabilities =
signaling_thread_->Invoke<scoped_refptr<RTCRtpCapabilities>>(
RTC_FROM_HERE, [this, media_type] {
return GetRtpSenderCapabilities(media_type);
});
return capabilities;
}

cricket::MediaType type = cricket::MediaType::MEDIA_TYPE_AUDIO;
switch (media_type) {
case RTCMediaType::AUDIO:
type = cricket::MediaType::MEDIA_TYPE_AUDIO;
break;
case RTCMediaType::VIDEO:
type = cricket::MediaType::MEDIA_TYPE_VIDEO;
break;
default:
break;
}
webrtc::RtpCapabilities rtp_capabilities =
rtc_peerconnection_factory_->GetRtpSenderCapabilities(type);
return scoped_refptr<RTCRtpCapabilities>(
new RefCountedObject<RTCRtpCapabilitiesImpl>(rtp_capabilities));
}

scoped_refptr<RTCRtpCapabilities>
RTCPeerConnectionFactoryImpl::GetRtpReceiverCapabilities(
RTCMediaType media_type) {
if (rtc::Thread::Current() != signaling_thread_) {
scoped_refptr<RTCRtpCapabilities> capabilities =
signaling_thread_->Invoke<scoped_refptr<RTCRtpCapabilities>>(
RTC_FROM_HERE, [this, media_type] {
return GetRtpSenderCapabilities(media_type);
});
return capabilities;
}
cricket::MediaType type = cricket::MediaType::MEDIA_TYPE_AUDIO;
switch (media_type) {
case RTCMediaType::AUDIO:
type = cricket::MediaType::MEDIA_TYPE_AUDIO;
break;
case RTCMediaType::VIDEO:
type = cricket::MediaType::MEDIA_TYPE_VIDEO;
break;
default:
break;
}
webrtc::RtpCapabilities rtp_capabilities =
rtc_peerconnection_factory_->GetRtpReceiverCapabilities(type);
return scoped_refptr<RTCRtpCapabilities>(
new RefCountedObject<RTCRtpCapabilitiesImpl>(rtp_capabilities));
}

} // namespace libwebrtc
6 changes: 6 additions & 0 deletions src/rtc_peerconnection_factory_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ class RTCPeerConnectionFactoryImpl : public RTCPeerConnectionFactory {
return rtc_peerconnection_factory_;
}

scoped_refptr<RTCRtpCapabilities> GetRtpSenderCapabilities(
RTCMediaType media_type) override;

scoped_refptr<RTCRtpCapabilities> GetRtpReceiverCapabilities(
RTCMediaType media_type) override;

protected:
void CreateAudioDeviceModule_w();

Expand Down
Loading

0 comments on commit ae76f52

Please sign in to comment.