From e4c9cb270c0c7942d08249d766883df1e31db167 Mon Sep 17 00:00:00 2001 From: cloudwebrtc Date: Thu, 15 Aug 2024 16:57:56 +0800 Subject: [PATCH 1/2] Add dummy I/O support. --- BUILD.gn | 45 +++- include/rtc_audio_frame.h | 94 +------- include/rtc_audio_source.h | 16 ++ include/rtc_audio_track.h | 19 ++ include/rtc_desktop_device.h | 4 +- include/rtc_peerconnection_factory.h | 20 +- include/rtc_video_source.h | 11 + src/audio_device_dummy.cc | 318 +++++++++++++++++++++++++ src/audio_device_dummy.h | 115 +++++++++ src/rtc_audio_frame_impl.cc | 62 +++++ src/rtc_audio_frame_impl.h | 37 +++ src/rtc_audio_source_impl.cc | 69 ++++++ src/rtc_audio_track_impl.cc | 28 +++ src/rtc_audio_track_impl.h | 16 +- src/rtc_peerconnection_factory_impl.cc | 31 ++- src/rtc_peerconnection_factory_impl.h | 34 ++- src/rtc_video_frame_impl.h | 2 + src/rtc_video_source_impl.cc | 52 ++++ src/rtc_video_source_impl.h | 1 + 19 files changed, 861 insertions(+), 113 deletions(-) create mode 100644 src/audio_device_dummy.cc create mode 100644 src/audio_device_dummy.h create mode 100644 src/rtc_audio_frame_impl.cc create mode 100644 src/rtc_audio_frame_impl.h diff --git a/BUILD.gn b/BUILD.gn index bcb7ce7ac1..967f2a12e0 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -2,7 +2,9 @@ import("../webrtc.gni") declare_args() { libwebrtc_intel_media_sdk = false - libwebrtc_desktop_capture = true + libwebrtc_desktop_capture = false + libwebrtc_video_capture = false + libwebrtc_dummy_audio_device = true } if (is_android) { @@ -41,9 +43,14 @@ rtc_shared_library("libwebrtc") { defines = [ "USE_LIBYUV", - "WEBRTC_INCLUDE_INTERNAL_AUDIO_DEVICE", ] + if(libwebrtc_dummy_audio_device) { + defines += [ "LIB_WEBRTC_USE_DUMMY_AUDIO_DEVICE" ] + } else { + defines += [ "WEBRTC_INCLUDE_INTERNAL_AUDIO_DEVICE" ] + } + if (is_win) { defines += [ "LIB_WEBRTC_API_EXPORTS", @@ -69,6 +76,7 @@ rtc_shared_library("libwebrtc") { "include/base/scoped_ref_ptr.h", "include/libwebrtc.h", "include/rtc_audio_device.h", + "include/rtc_audio_frame.h", "include/rtc_audio_source.h", "include/rtc_audio_track.h", "include/rtc_data_channel.h", @@ -88,7 +96,6 @@ rtc_shared_library("libwebrtc") { "include/rtc_rtp_transceiver.h", "include/rtc_session_description.h", "include/rtc_types.h", - "include/rtc_video_device.h", "include/rtc_video_frame.h", "include/rtc_video_renderer.h", "include/rtc_video_source.h", @@ -96,13 +103,11 @@ rtc_shared_library("libwebrtc") { "include/helper.h", "src/helper.cc", "src/base/portable.cc", - "src/internal/vcm_capturer.cc", - "src/internal/vcm_capturer.h", - "src/internal/video_capturer.cc", - "src/internal/video_capturer.h", "src/libwebrtc.cc", "src/rtc_audio_device_impl.cc", "src/rtc_audio_device_impl.h", + "src/rtc_audio_frame_impl.cc", + "src/rtc_audio_frame_impl.h", "src/rtc_audio_source_impl.cc", "src/rtc_audio_source_impl.h", "src/rtc_audio_track_impl.cc", @@ -137,8 +142,6 @@ rtc_shared_library("libwebrtc") { "src/rtc_rtp_transceiver_impl.h", "src/rtc_session_description_impl.cc", "src/rtc_session_description_impl.h", - "src/rtc_video_device_impl.cc", - "src/rtc_video_device_impl.h", "src/rtc_video_frame_impl.cc", "src/rtc_video_frame_impl.h", "src/rtc_video_sink_adapter.cc", @@ -149,6 +152,28 @@ rtc_shared_library("libwebrtc") { "src/rtc_video_track_impl.h", ] + if(libwebrtc_dummy_audio_device) { + sources += [ + "src/audio_device_dummy.cc", + "src/audio_device_dummy.h", + ] + } + + + # video capture device + if (libwebrtc_video_capture) { + defines += [ "RTC_VIDEO_CAPTURE_DEVICE" ] + sources += [ + "include/rtc_video_capturer.h", + "src/internal/video_capturer.h", + "src/internal/video_capturer.cc", + "src/internal/vcm_capturer.cc", + "src/internal/vcm_capturer.h", + "src/rtc_video_device_impl.cc", + "src/rtc_video_device_impl.h", + ] + } + # intel media sdk if (is_win && libwebrtc_intel_media_sdk) { sources += [ @@ -235,7 +260,7 @@ rtc_shared_library("libwebrtc") { # screen capture device if (libwebrtc_desktop_capture) { - defines += [ "RTC_DESKTOP_DEVICE" ] + defines += [ "RTC_DESKTOP_CAPTURE_DEVICE" ] sources += [ "include/rtc_desktop_capturer.h", "include/rtc_desktop_device.h", diff --git a/include/rtc_audio_frame.h b/include/rtc_audio_frame.h index 3f276a1676..b591e4dc66 100644 --- a/include/rtc_audio_frame.h +++ b/include/rtc_audio_frame.h @@ -1,108 +1,40 @@ -#ifndef AUDIO_FRAME_HXX -#define AUDIO_FRAME_HXX +#ifndef LIB_WEBRTC_RTC_AUDIO_FRAME_HXX +#define LIB_WEBRTC_RTC_AUDIO_FRAME_HXX -#include "media_manager_types.h" +#include "rtc_types.h" -namespace b2bua { +namespace libwebrtc { -class AudioFrame { +class RTCAudioFrame : public RefCountInterface { public: - /** - * @brief Creates a new instance of AudioFrame. - * @return AudioFrame*: a pointer to the newly created AudioFrame. - */ - MEDIA_MANAGER_API static AudioFrame* Create(); + LIB_WEBRTC_API static scoped_refptr Create(); - /** - * @brief Creates a new instance of AudioFrame with specified parameters. - * @param id: the unique identifier of the frame. - * @param timestamp: the timestamp of the frame. - * @param data: a pointer to the audio data buffer. - * @param samples_per_channel: the number of samples per channel. - * @param sample_rate_hz: the sample rate in Hz. - * @param num_channels: the number of audio channels. - * @return AudioFrame*: a pointer to the newly created AudioFrame. - */ - MEDIA_MANAGER_API static AudioFrame* Create(int id, uint32_t timestamp, - const int16_t* data, - size_t samples_per_channel, - int sample_rate_hz, - size_t num_channels = 1); - - /** - * @brief Releases the memory of this AudioFrame. - */ - virtual void Release() = 0; + LIB_WEBRTC_API static scoped_refptr Create( + uint32_t timestamp, const int16_t* data, size_t samples_per_channel, + int sample_rate_hz, size_t num_channels = 1); public: - /** - * @brief Updates the audio frame with specified parameters. - * @param id: the unique identifier of the frame. - * @param timestamp: the timestamp of the frame. - * @param data: a pointer to the audio data buffer. - * @param samples_per_channel: the number of samples per channel. - * @param sample_rate_hz: the sample rate in Hz. - * @param num_channels: the number of audio channels. - */ - virtual void UpdateFrame(int id, uint32_t timestamp, const int16_t* data, + virtual void UpdateFrame(uint32_t timestamp, const int16_t* data, size_t samples_per_channel, int sample_rate_hz, size_t num_channels = 1) = 0; - /** - * @brief Copies the contents of another AudioFrame. - * @param src: the source AudioFrame to copy from. - */ - virtual void CopyFrom(const AudioFrame& src) = 0; + virtual void CopyFrom(const scoped_refptr src) = 0; - /** - * @brief Adds another AudioFrame to this one. - * @param frame_to_add: the AudioFrame to add. - */ - virtual void Add(const AudioFrame& frame_to_add) = 0; + virtual void Add(const scoped_refptr frame_to_add) = 0; - /** - * @brief Mutes the audio data in this AudioFrame. - */ virtual void Mute() = 0; - /** - * @brief Returns a pointer to the audio data buffer. - * @return const int16_t*: a pointer to the audio data buffer. - */ virtual const int16_t* data() = 0; - /** - * @brief Returns the number of samples per channel. - * @return size_t: the number of samples per channel. - */ virtual size_t samples_per_channel() = 0; - /** - * @brief Returns the sample rate in Hz. - * @return int: the sample rate in Hz. - */ virtual int sample_rate_hz() = 0; - /** - * @brief Returns the number of audio channels. - * @return size_t: the number of audio channels. - */ virtual size_t num_channels() = 0; - /** - * @brief Returns the timestamp of the AudioFrame. - * @return uint32_t: the timestamp of the AudioFrame. - */ virtual uint32_t timestamp() = 0; - - /** - * @brief Returns the unique identifier of the AudioFrame. - * @return int: the unique identifier of the AudioFrame. - */ - - virtual int id() = 0; }; -}; // namespace b2bua +} // namespace libwebrtc #endif diff --git a/include/rtc_audio_source.h b/include/rtc_audio_source.h index 43e39fd801..f4427694de 100644 --- a/include/rtc_audio_source.h +++ b/include/rtc_audio_source.h @@ -2,6 +2,7 @@ #define LIB_WEBRTC_RTC_AUDIO_SOURCE_HXX #include "rtc_types.h" +#include "rtc_audio_frame.h" namespace libwebrtc { @@ -20,6 +21,21 @@ class RTCAudioSource : public RefCountInterface { virtual ~RTCAudioSource() {} }; +class VirtualAudioCapturer : public RefCountInterface { + public: + LIB_WEBRTC_API static scoped_refptr Create(); + + virtual void OnFrame(scoped_refptr data) = 0; + + virtual void OnData(const void* audio_data, + int bits_per_sample, + int sample_rate, + size_t number_of_channels, + size_t number_of_frames) = 0; + + virtual scoped_refptr source() = 0; +}; + } // namespace libwebrtc #endif // LIB_WEBRTC_RTC_AUDIO_TRACK_HXX diff --git a/include/rtc_audio_track.h b/include/rtc_audio_track.h index c64e4bc4a5..c3d40b60b1 100644 --- a/include/rtc_audio_track.h +++ b/include/rtc_audio_track.h @@ -1,11 +1,24 @@ #ifndef LIB_WEBRTC_RTC_AUDIO_TRACK_HXX #define LIB_WEBRTC_RTC_AUDIO_TRACK_HXX +#include "rtc_audio_frame.h" #include "rtc_media_track.h" #include "rtc_types.h" namespace libwebrtc { +template +class RTCAudioRenderer { + public: + virtual void OnFrame(AudioFrameT frame) = 0; + + virtual void OnData(const void* audio_data, int bits_per_sample, + int sample_rate, size_t number_of_channels, + size_t number_of_frames) = 0; + protected: + virtual ~RTCAudioRenderer() {} +}; + /** * The RTCAudioTrack class represents an audio track in WebRTC. * Audio tracks are used to transmit audio data over a WebRTC peer connection. @@ -17,6 +30,12 @@ class RTCAudioTrack : public RTCMediaTrack { // volume in [0-10] virtual void SetVolume(double volume) = 0; + virtual void AddAudioSink( + RTCAudioRenderer>* sink) = 0; + + virtual void RemoveAudioSink( + RTCAudioRenderer>* sink) = 0; + protected: /** * The destructor for the RTCAudioTrack class. diff --git a/include/rtc_desktop_device.h b/include/rtc_desktop_device.h index e3e4c6fab1..cd5a326b99 100644 --- a/include/rtc_desktop_device.h +++ b/include/rtc_desktop_device.h @@ -1,5 +1,5 @@ -#ifndef LIB_WEBRTC_RTC_DESKTOP_DEVICE_HXX -#define LIB_WEBRTC_RTC_DESKTOP_DEVICE_HXX +#ifndef LIB_WEBRTC_RTC_DESKTOP_CAPTURE_DEVICE_HXX +#define LIB_WEBRTC_RTC_DESKTOP_CAPTURE_DEVICE_HXX #include "rtc_types.h" diff --git a/include/rtc_peerconnection_factory.h b/include/rtc_peerconnection_factory.h index cb024672c2..be52805893 100644 --- a/include/rtc_peerconnection_factory.h +++ b/include/rtc_peerconnection_factory.h @@ -4,7 +4,7 @@ #include "rtc_audio_source.h" #include "rtc_audio_track.h" #include "rtc_types.h" -#ifdef RTC_DESKTOP_DEVICE +#ifdef RTC_DESKTOP_CAPTURE_DEVICE #include "rtc_desktop_device.h" #endif #include "rtc_media_stream.h" @@ -31,24 +31,28 @@ class RTCPeerConnectionFactory : public RefCountInterface { virtual void Delete(scoped_refptr peerconnection) = 0; +#if !defined(LIB_WEBRTC_USE_DUMMY_AUDIO_DEVICE) virtual scoped_refptr GetAudioDevice() = 0; - - virtual scoped_refptr GetVideoDevice() = 0; -#ifdef RTC_DESKTOP_DEVICE - virtual scoped_refptr GetDesktopDevice() = 0; #endif - virtual scoped_refptr CreateAudioSource( - const string audio_source_label) = 0; +#ifdef RTC_VIDEO_CAPTURE_DEVICE + virtual scoped_refptr GetVideoDevice() = 0; virtual scoped_refptr CreateVideoSource( scoped_refptr capturer, const string video_source_label, scoped_refptr constraints) = 0; -#ifdef RTC_DESKTOP_DEVICE +#endif + +#ifdef RTC_DESKTOP_CAPTURE_DEVICE + virtual scoped_refptr GetDesktopDevice() = 0; virtual scoped_refptr CreateDesktopSource( scoped_refptr capturer, const string video_source_label, scoped_refptr constraints) = 0; #endif + + virtual scoped_refptr CreateAudioSource( + const string audio_source_label) = 0; + virtual scoped_refptr CreateAudioTrack( scoped_refptr source, const string track_id) = 0; diff --git a/include/rtc_video_source.h b/include/rtc_video_source.h index cb61abbb49..3343966265 100644 --- a/include/rtc_video_source.h +++ b/include/rtc_video_source.h @@ -2,6 +2,7 @@ #define LIB_WEBRTC_RTC_VIDEO_SOURCE_HXX #include "rtc_types.h" +#include "rtc_video_frame.h" namespace libwebrtc { @@ -9,6 +10,16 @@ class RTCVideoSource : public RefCountInterface { public: ~RTCVideoSource() {} }; + +class VirtualVideoCapturer : public RefCountInterface { + public: + LIB_WEBRTC_API static scoped_refptr Create(); + + virtual void OnFrameCaptured(scoped_refptr frame) = 0; + + virtual scoped_refptr source() = 0; +}; + } // namespace libwebrtc #endif // LIB_WEBRTC_RTC_VIDEO_SOURCE_HXX diff --git a/src/audio_device_dummy.cc b/src/audio_device_dummy.cc new file mode 100644 index 0000000000..3f33b1a194 --- /dev/null +++ b/src/audio_device_dummy.cc @@ -0,0 +1,318 @@ +#include "audio_device_dummy.h" + +const int kSampleRate = 48000; +const int kChannels = 2; +const int kBytesPerSample = kChannels * sizeof(int16_t); +const int kSamplesPer10Ms = kSampleRate / 100; + +namespace libwebrtc { + +AudioDeviceDummy::AudioDeviceDummy(webrtc::TaskQueueFactory* task_queue_factory) + : data_(kSamplesPer10Ms * kChannels), + task_queue_factory_(task_queue_factory) {} + +AudioDeviceDummy::~AudioDeviceDummy() { + Terminate(); +} + +int32_t AudioDeviceDummy::ActiveAudioLayer(AudioLayer* audioLayer) const { + *audioLayer = AudioLayer::kDummyAudio; + return 0; +} + +int32_t AudioDeviceDummy::RegisterAudioCallback(webrtc::AudioTransport* transport) { + webrtc::MutexLock lock(&mutex_); + audio_transport_ = transport; + return 0; +} + +int32_t AudioDeviceDummy::Init() { + webrtc::MutexLock lock(&mutex_); + if (initialized_) + return 0; + + audio_queue_ = task_queue_factory_->CreateTaskQueue( + "AudioDevice", webrtc::TaskQueueFactory::Priority::NORMAL); + + audio_task_ = + webrtc::RepeatingTaskHandle::Start(audio_queue_.get(), [this]() { + webrtc::MutexLock lock(&mutex_); + + if (playing_) { + int64_t elapsed_time_ms = -1; + int64_t ntp_time_ms = -1; + size_t n_samples_out = 0; + void* data = data_.data(); + + // Request the AudioData, otherwise WebRTC will ignore the packets. + // 10ms of audio data. + audio_transport_->NeedMorePlayData( + kSamplesPer10Ms, kBytesPerSample, kChannels, kSampleRate, data, + n_samples_out, &elapsed_time_ms, &ntp_time_ms); + } + + return webrtc::TimeDelta::Millis(10); + }); + + initialized_ = true; + return 0; +} + +int32_t AudioDeviceDummy::Terminate() { + { + webrtc::MutexLock lock(&mutex_); + if (!initialized_) + return 0; + + initialized_ = false; + } + audio_queue_ = nullptr; + return 0; +} + +bool AudioDeviceDummy::Initialized() const { + webrtc::MutexLock lock(&mutex_); + return initialized_; +} + +int16_t AudioDeviceDummy::PlayoutDevices() { + return 0; +} + +int16_t AudioDeviceDummy::RecordingDevices() { + return 0; +} + +int32_t AudioDeviceDummy::PlayoutDeviceName(uint16_t index, + char name[webrtc::kAdmMaxDeviceNameSize], + char guid[webrtc::kAdmMaxGuidSize]) { + return 0; +} + +int32_t AudioDeviceDummy::RecordingDeviceName( + uint16_t index, + char name[webrtc::kAdmMaxDeviceNameSize], + char guid[webrtc::kAdmMaxGuidSize]) { + return 0; +} + +int32_t AudioDeviceDummy::SetPlayoutDevice(uint16_t index) { + return 0; +} + +int32_t AudioDeviceDummy::SetPlayoutDevice(WindowsDeviceType device) { + return 0; +} + +int32_t AudioDeviceDummy::SetRecordingDevice(uint16_t index) { + return 0; +} + +int32_t AudioDeviceDummy::SetRecordingDevice(WindowsDeviceType device) { + return 0; +} + +int32_t AudioDeviceDummy::PlayoutIsAvailable(bool* available) { + return 0; +} + +int32_t AudioDeviceDummy::InitPlayout() { + return 0; +} + +bool AudioDeviceDummy::PlayoutIsInitialized() const { + return false; +} + +int32_t AudioDeviceDummy::RecordingIsAvailable(bool* available) { + return 0; +} + +int32_t AudioDeviceDummy::InitRecording() { + return 0; +} + +bool AudioDeviceDummy::RecordingIsInitialized() const { + return false; +} + +int32_t AudioDeviceDummy::StartPlayout() { + webrtc::MutexLock lock(&mutex_); + playing_ = true; + return 0; +} + +int32_t AudioDeviceDummy::StopPlayout() { + webrtc::MutexLock lock(&mutex_); + playing_ = false; + return 0; +} + +bool AudioDeviceDummy::Playing() const { + webrtc::MutexLock lock(&mutex_); + return playing_; +} + +int32_t AudioDeviceDummy::StartRecording() { + return 0; +} + +int32_t AudioDeviceDummy::StopRecording() { + return 0; +} + +bool AudioDeviceDummy::Recording() const { + return false; +} + +int32_t AudioDeviceDummy::InitSpeaker() { + return 0; +} + +bool AudioDeviceDummy::SpeakerIsInitialized() const { + return false; +} + +int32_t AudioDeviceDummy::InitMicrophone() { + return 0; +} + +bool AudioDeviceDummy::MicrophoneIsInitialized() const { + return false; +} + +int32_t AudioDeviceDummy::SpeakerVolumeIsAvailable(bool* available) { + return 0; +} + +int32_t AudioDeviceDummy::SetSpeakerVolume(uint32_t volume) { + return 0; +} + +int32_t AudioDeviceDummy::SpeakerVolume(uint32_t* volume) const { + return 0; +} + +int32_t AudioDeviceDummy::MaxSpeakerVolume(uint32_t* maxVolume) const { + return 0; +} + +int32_t AudioDeviceDummy::MinSpeakerVolume(uint32_t* minVolume) const { + return 0; +} + +int32_t AudioDeviceDummy::MicrophoneVolumeIsAvailable(bool* available) { + return 0; +} + +int32_t AudioDeviceDummy::SetMicrophoneVolume(uint32_t volume) { + return 0; +} + +int32_t AudioDeviceDummy::MicrophoneVolume(uint32_t* volume) const { + return 0; +} + +int32_t AudioDeviceDummy::MaxMicrophoneVolume(uint32_t* maxVolume) const { + return 0; +} + +int32_t AudioDeviceDummy::MinMicrophoneVolume(uint32_t* minVolume) const { + return 0; +} + +int32_t AudioDeviceDummy::SpeakerMuteIsAvailable(bool* available) { + return 0; +} + +int32_t AudioDeviceDummy::SetSpeakerMute(bool enable) { + return 0; +} + +int32_t AudioDeviceDummy::SpeakerMute(bool* enabled) const { + return 0; +} + +int32_t AudioDeviceDummy::MicrophoneMuteIsAvailable(bool* available) { + return 0; +} + +int32_t AudioDeviceDummy::SetMicrophoneMute(bool enable) { + return 0; +} + +int32_t AudioDeviceDummy::MicrophoneMute(bool* enabled) const { + return 0; +} + +int32_t AudioDeviceDummy::StereoPlayoutIsAvailable(bool* available) const { + *available = true; + return 0; +} + +int32_t AudioDeviceDummy::SetStereoPlayout(bool enable) { + return 0; +} + +int32_t AudioDeviceDummy::StereoPlayout(bool* enabled) const { + return 0; +} + +int32_t AudioDeviceDummy::StereoRecordingIsAvailable(bool* available) const { + return 0; +} + +int32_t AudioDeviceDummy::SetStereoRecording(bool enable) { + return 0; +} + +int32_t AudioDeviceDummy::StereoRecording(bool* enabled) const { + *enabled = true; + return 0; +} + +int32_t AudioDeviceDummy::PlayoutDelay(uint16_t* delayMS) const { + return 0; +} + +bool AudioDeviceDummy::BuiltInAECIsAvailable() const { + return false; +} + +bool AudioDeviceDummy::BuiltInAGCIsAvailable() const { + return false; +} + +bool AudioDeviceDummy::BuiltInNSIsAvailable() const { + return false; +} + +int32_t AudioDeviceDummy::EnableBuiltInAEC(bool enable) { + return 0; +} + +int32_t AudioDeviceDummy::EnableBuiltInAGC(bool enable) { + return 0; +} + +int32_t AudioDeviceDummy::EnableBuiltInNS(bool enable) { + return 0; +} + +#if defined(WEBRTC_IOS) +int AudioDeviceDummy::GetPlayoutAudioParameters( + webrtc::AudioParameters* params) const { + return 0; +} + +int AudioDeviceDummy::GetRecordAudioParameters( + webrtc::AudioParameters* params) const { + return 0; +} +#endif // WEBRTC_IOS + +int32_t AudioDeviceDummy::SetAudioDeviceSink(webrtc::AudioDeviceSink* sink) const { + return 0; +} + +} // namespace libwebrtc diff --git a/src/audio_device_dummy.h b/src/audio_device_dummy.h new file mode 100644 index 0000000000..00d344420a --- /dev/null +++ b/src/audio_device_dummy.h @@ -0,0 +1,115 @@ +#ifndef AUDIO_DEVICE_AUDIO_DEVICE_DUMMY_H_ +#define AUDIO_DEVICE_AUDIO_DEVICE_DUMMY_H_ + +#include + +#include "api/task_queue/task_queue_factory.h" +#include "modules/audio_device/include/audio_device.h" +#include "rtc_base/synchronization/mutex.h" +#include "rtc_base/task_utils/repeating_task.h" + +namespace libwebrtc { + + class AudioDeviceDummy : public webrtc::AudioDeviceModule { + public: + AudioDeviceDummy(webrtc::TaskQueueFactory* task_queue_factory); + ~AudioDeviceDummy() override; + + int32_t ActiveAudioLayer(AudioLayer* audioLayer) const override; + int32_t RegisterAudioCallback(webrtc::AudioTransport* transport) override; + + int32_t Init() override; + int32_t Terminate() override; + bool Initialized() const override; + + int16_t PlayoutDevices() override; + int16_t RecordingDevices() override; + int32_t PlayoutDeviceName(uint16_t index, + char name[webrtc::kAdmMaxDeviceNameSize], + char guid[webrtc::kAdmMaxGuidSize]) override; + + int32_t RecordingDeviceName(uint16_t index, + char name[webrtc::kAdmMaxDeviceNameSize], + char guid[webrtc::kAdmMaxGuidSize]) override; + + int32_t SetPlayoutDevice(uint16_t index) override; + int32_t SetPlayoutDevice(WindowsDeviceType device) override; + int32_t SetRecordingDevice(uint16_t index) override; + int32_t SetRecordingDevice(WindowsDeviceType device) override; + + int32_t PlayoutIsAvailable(bool* available) override; + int32_t InitPlayout() override; + bool PlayoutIsInitialized() const override; + int32_t RecordingIsAvailable(bool* available) override; + int32_t InitRecording() override; + bool RecordingIsInitialized() const override; + + int32_t StartPlayout() override; + int32_t StopPlayout() override; + bool Playing() const override; + int32_t StartRecording() override; + int32_t StopRecording() override; + bool Recording() const override; + + int32_t InitSpeaker() override; + bool SpeakerIsInitialized() const override; + int32_t InitMicrophone() override; + bool MicrophoneIsInitialized() const override; + + int32_t SpeakerVolumeIsAvailable(bool* available) override; + int32_t SetSpeakerVolume(uint32_t volume) override; + int32_t SpeakerVolume(uint32_t* volume) const override; + int32_t MaxSpeakerVolume(uint32_t* maxVolume) const override; + int32_t MinSpeakerVolume(uint32_t* minVolume) const override; + + int32_t MicrophoneVolumeIsAvailable(bool* available) override; + int32_t SetMicrophoneVolume(uint32_t volume) override; + int32_t MicrophoneVolume(uint32_t* volume) const override; + int32_t MaxMicrophoneVolume(uint32_t* maxVolume) const override; + int32_t MinMicrophoneVolume(uint32_t* minVolume) const override; + + int32_t SpeakerMuteIsAvailable(bool* available) override; + int32_t SetSpeakerMute(bool enable) override; + int32_t SpeakerMute(bool* enabled) const override; + + int32_t MicrophoneMuteIsAvailable(bool* available) override; + int32_t SetMicrophoneMute(bool enable) override; + int32_t MicrophoneMute(bool* enabled) const override; + + int32_t StereoPlayoutIsAvailable(bool* available) const override; + int32_t SetStereoPlayout(bool enable) override; + int32_t StereoPlayout(bool* enabled) const override; + int32_t StereoRecordingIsAvailable(bool* available) const override; + int32_t SetStereoRecording(bool enable) override; + int32_t StereoRecording(bool* enabled) const override; + + int32_t PlayoutDelay(uint16_t* delayMS) const override; + + bool BuiltInAECIsAvailable() const override; + bool BuiltInAGCIsAvailable() const override; + bool BuiltInNSIsAvailable() const override; + + int32_t EnableBuiltInAEC(bool enable) override; + int32_t EnableBuiltInAGC(bool enable) override; + int32_t EnableBuiltInNS(bool enable) override; + +#if defined(WEBRTC_IOS) + int GetPlayoutAudioParameters(webrtc::AudioParameters* params) const override; + int GetRecordAudioParameters(webrtc::AudioParameters* params) const override; +#endif // WEBRTC_IOS + + int32_t SetAudioDeviceSink(webrtc::AudioDeviceSink* sink) const override; + + private: + mutable webrtc::Mutex mutex_; + std::vector data_; + std::unique_ptr audio_queue_; + webrtc::RepeatingTaskHandle audio_task_; + webrtc::AudioTransport* audio_transport_; + webrtc::TaskQueueFactory* task_queue_factory_; + bool playing_{false}; + bool initialized_{false}; +}; +} // namespace webrtc + +#endif // AUDIO_DEVICE_AUDIO_DEVICE_DUMMY_H_ diff --git a/src/rtc_audio_frame_impl.cc b/src/rtc_audio_frame_impl.cc new file mode 100644 index 0000000000..754e0b4b11 --- /dev/null +++ b/src/rtc_audio_frame_impl.cc @@ -0,0 +1,62 @@ +#include "rtc_audio_frame_impl.h" + +#include "audio/utility/audio_frame_operations.h" + +namespace libwebrtc { + +scoped_refptr RTCAudioFrame::Create() { + return scoped_refptr( + new RefCountedObject()); +} + +scoped_refptr RTCAudioFrame::Create( + uint32_t timestamp, const int16_t* data, size_t samples_per_channel, + int sample_rate_hz, size_t num_channels /*= 1*/) { + auto audio_frame = + scoped_refptr(new RefCountedObject()); + audio_frame->UpdateFrame(timestamp, data, samples_per_channel, sample_rate_hz, + num_channels); + return audio_frame; +} + +RTCAudioFrameImpl::RTCAudioFrameImpl(webrtc::AudioFrame& buffer) { + buffer_.CopyFrom(buffer); +} + +RTCAudioFrameImpl::~RTCAudioFrameImpl() {} + +void RTCAudioFrameImpl::UpdateFrame(uint32_t timestamp, const int16_t* data, + size_t samples_per_channel, + int sample_rate_hz, + size_t num_channels /*= 1*/) { + buffer_.UpdateFrame(timestamp, data, samples_per_channel, sample_rate_hz, + webrtc::AudioFrame::kNormalSpeech, + webrtc::AudioFrame::kVadUnknown, num_channels); +} + +void RTCAudioFrameImpl::CopyFrom(const scoped_refptr src) { + RTCAudioFrameImpl* frame = static_cast(src.get()); + buffer_.CopyFrom(frame->buffer_); +} + +void RTCAudioFrameImpl::Add(const scoped_refptr frame_to_add) { + RTCAudioFrameImpl* frame = + static_cast(frame_to_add.get()); + webrtc::AudioFrameOperations::Add(frame->buffer_, &buffer_); +} + +void RTCAudioFrameImpl::Mute() { buffer_.Mute(); } + +const int16_t* RTCAudioFrameImpl::data() { return buffer_.data(); } + +size_t RTCAudioFrameImpl::samples_per_channel() { + return buffer_.samples_per_channel_; +} + +int RTCAudioFrameImpl::sample_rate_hz() { return buffer_.sample_rate_hz_; } + +size_t RTCAudioFrameImpl::num_channels() { return buffer_.num_channels_; } + +uint32_t RTCAudioFrameImpl::timestamp() { return buffer_.timestamp_; } + +} // namespace libwebrtc diff --git a/src/rtc_audio_frame_impl.h b/src/rtc_audio_frame_impl.h new file mode 100644 index 0000000000..5fe9f1b18b --- /dev/null +++ b/src/rtc_audio_frame_impl.h @@ -0,0 +1,37 @@ +#include "api/audio/audio_frame.h" +#include "include/rtc_audio_frame.h" + +namespace libwebrtc { + +class RTCAudioFrameImpl : public RTCAudioFrame { + public: + RTCAudioFrameImpl() {} + RTCAudioFrameImpl(webrtc::AudioFrame& buffer); + ~RTCAudioFrameImpl(); + + public: + virtual void UpdateFrame(uint32_t timestamp, const int16_t* data, + size_t samples_per_channel, int sample_rate_hz, + size_t num_channels = 1) override; + + virtual void CopyFrom(const scoped_refptr src) override; + + virtual void Add(const scoped_refptr frame_to_add) override; + + virtual void Mute() override; + + virtual const int16_t* data() override; + + virtual size_t samples_per_channel() override; + + virtual int sample_rate_hz() override; + + virtual size_t num_channels() override; + + virtual uint32_t timestamp() override; + + private: + webrtc::AudioFrame buffer_; +}; + +} // namespace libwebrtc diff --git a/src/rtc_audio_source_impl.cc b/src/rtc_audio_source_impl.cc index a9e2526c80..72bfcd4ca7 100644 --- a/src/rtc_audio_source_impl.cc +++ b/src/rtc_audio_source_impl.cc @@ -1,5 +1,7 @@ #include "rtc_audio_source_impl.h" +#include "pc/local_audio_source.h" + namespace libwebrtc { RTCAudioSourceImpl::RTCAudioSourceImpl( @@ -12,4 +14,71 @@ RTCAudioSourceImpl::~RTCAudioSourceImpl() { RTC_LOG(LS_INFO) << __FUNCTION__ << ": dtor "; } +class AdaptedVirtualAudioCapturer : public webrtc::LocalAudioSource { + public: + AdaptedVirtualAudioCapturer() {} + ~AdaptedVirtualAudioCapturer() {} + + void AddSink(webrtc::AudioTrackSinkInterface* sink) override { + webrtc::MutexLock lock(&mutex_); + sinks_.push_back(sink); + } + + void RemoveSink(webrtc::AudioTrackSinkInterface* sink) override { + webrtc::MutexLock lock(&mutex_); + sinks_.erase(std::remove(sinks_.begin(), sinks_.end(), sink), sinks_.end()); + } + + void OnFrame(scoped_refptr frame) { + webrtc::MutexLock lock(&mutex_); + for (auto sink : sinks_) { + sink->OnData((const void*)frame->data(), 16, frame->sample_rate_hz(), + frame->num_channels(), frame->samples_per_channel()); + } + } + + void OnData(const void* audio_data, int bits_per_sample, int sample_rate, + size_t number_of_channels, size_t number_of_frames) { + webrtc::MutexLock lock(&mutex_); + for (auto sink : sinks_) { + sink->OnData(audio_data, bits_per_sample, sample_rate, number_of_channels, + number_of_frames); + } + } + + private: + mutable webrtc::Mutex mutex_; + std::vector sinks_; +}; + +class VirtualAudioCapturerImpl : public VirtualAudioCapturer { + public: + VirtualAudioCapturerImpl() {} + virtual ~VirtualAudioCapturerImpl() {} + + virtual void OnFrame(scoped_refptr frame) override { + adapted_source_->OnFrame(frame); + } + + virtual void OnData(const void* audio_data, int bits_per_sample, + int sample_rate, size_t number_of_channels, + size_t number_of_frames) override { + adapted_source_->OnData(audio_data, bits_per_sample, sample_rate, + number_of_channels, number_of_frames); + } + + virtual scoped_refptr source() override { + return rtc_audio_source_; + } + + private: + scoped_refptr rtc_audio_source_; + rtc::scoped_refptr adapted_source_; +}; + +scoped_refptr VirtualAudioCapturer::Create() { + return scoped_refptr( + new RefCountedObject()); +} + } // namespace libwebrtc diff --git a/src/rtc_audio_track_impl.cc b/src/rtc_audio_track_impl.cc index 802a3e272a..0024b2a2b2 100644 --- a/src/rtc_audio_track_impl.cc +++ b/src/rtc_audio_track_impl.cc @@ -18,4 +18,32 @@ void AudioTrackImpl::SetVolume(double volume) { rtc_track_->GetSource()->SetVolume(volume); } +void AudioTrackImpl::AddAudioSink( + RTCAudioRenderer>* sink) { + webrtc::MutexLock lock(&mutex_); + renderers_.push_back(sink); +} + +void AudioTrackImpl::RemoveAudioSink( + RTCAudioRenderer>* sink) { + webrtc::MutexLock lock(&mutex_); + renderers_.erase( + std::remove_if( + renderers_.begin(), renderers_.end(), + [sink](const RTCAudioRenderer>* sink_) { + return sink_ == sink; + }), + renderers_.end()); +} + +void AudioTrackImpl::OnData(const void* audio_data, int bits_per_sample, + int sample_rate, size_t number_of_channels, + size_t number_of_frames) { + webrtc::MutexLock lock(&mutex_); + for (auto sink : renderers_) { + sink->OnData(audio_data, bits_per_sample, sample_rate, + number_of_channels, number_of_frames); + } +} + } // namespace libwebrtc diff --git a/src/rtc_audio_track_impl.h b/src/rtc_audio_track_impl.h index 1fd120ea9f..ce00c2b350 100644 --- a/src/rtc_audio_track_impl.h +++ b/src/rtc_audio_track_impl.h @@ -14,7 +14,7 @@ namespace libwebrtc { -class AudioTrackImpl : public RTCAudioTrack { +class AudioTrackImpl : public RTCAudioTrack, public webrtc::AudioTrackSinkInterface { public: AudioTrackImpl(rtc::scoped_refptr audio_track); @@ -22,6 +22,18 @@ class AudioTrackImpl : public RTCAudioTrack { virtual void SetVolume(double volume) override; + virtual void AddAudioSink( + RTCAudioRenderer>* sink) override; + + virtual void RemoveAudioSink( + RTCAudioRenderer>* sink) override; + + virtual void OnData(const void* audio_data, + int bits_per_sample, + int sample_rate, + size_t number_of_channels, + size_t number_of_frames) override; + virtual const string kind() const override { return kind_; } virtual const string id() const override { return id_; } @@ -43,6 +55,8 @@ class AudioTrackImpl : public RTCAudioTrack { private: rtc::scoped_refptr rtc_track_; string id_, kind_; + mutable webrtc::Mutex mutex_; + std::list>*> renderers_; }; } // namespace libwebrtc diff --git a/src/rtc_peerconnection_factory_impl.cc b/src/rtc_peerconnection_factory_impl.cc index 7c7fe2d452..d3a84809da 100644 --- a/src/rtc_peerconnection_factory_impl.cc +++ b/src/rtc_peerconnection_factory_impl.cc @@ -12,7 +12,11 @@ #include "rtc_mediaconstraints_impl.h" #include "rtc_peerconnection_impl.h" #include "rtc_rtp_capabilities_impl.h" + +#ifdef RTC_VIDEO_CAPTURE_DEVICE #include "rtc_video_device_impl.h" +#endif + #include "rtc_video_source_impl.h" #if defined(USE_INTEL_MEDIA_SDK) #include "src/win/mediacapabilities.h" @@ -23,6 +27,9 @@ #include "engine/sdk/objc/Framework/Classes/videotoolboxvideocodecfactory.h" #endif #include +#if defined(LIB_WEBRTC_USE_DUMMY_AUDIO_DEVICE) +#include "src/audio_device_dummy.h" +#endif namespace libwebrtc { @@ -87,8 +94,12 @@ bool RTCPeerConnectionFactoryImpl::Initialize() { bool RTCPeerConnectionFactoryImpl::Terminate() { worker_thread_->BlockingCall([&] { +#if !defined(LIB_WEBRTC_USE_DUMMY_AUDIO_DEVICE) audio_device_impl_ = nullptr; +#endif + #ifdef RTC_VIDEO_CAPTURE_DEVICE video_device_impl_ = nullptr; + #endif }); rtc_peerconnection_factory_ = NULL; if (audio_device_module_) { @@ -100,9 +111,15 @@ bool RTCPeerConnectionFactoryImpl::Terminate() { void RTCPeerConnectionFactoryImpl::CreateAudioDeviceModule_w() { if (!audio_device_module_) +#if defined(LIB_WEBRTC_USE_DUMMY_AUDIO_DEVICE) + audio_device_module_ = + rtc::make_ref_counted( + task_queue_factory_.get()); +#else audio_device_module_ = webrtc::AudioDeviceModule::Create( webrtc::AudioDeviceModule::kPlatformDefaultAudio, task_queue_factory_.get()); +#endif } void RTCPeerConnectionFactoryImpl::DestroyAudioDeviceModule_w() { @@ -131,6 +148,7 @@ void RTCPeerConnectionFactoryImpl::Delete( peerconnections_.end()); } +#if !defined(LIB_WEBRTC_USE_DUMMY_AUDIO_DEVICE) scoped_refptr RTCPeerConnectionFactoryImpl::GetAudioDevice() { if (!audio_device_module_) { worker_thread_->BlockingCall([this] { CreateAudioDeviceModule_w(); }); @@ -143,7 +161,9 @@ scoped_refptr RTCPeerConnectionFactoryImpl::GetAudioDevice() { return audio_device_impl_; } +#endif +#ifdef RTC_VIDEO_CAPTURE_DEVICE scoped_refptr RTCPeerConnectionFactoryImpl::GetVideoDevice() { if (!video_device_impl_) video_device_impl_ = scoped_refptr( @@ -151,6 +171,8 @@ scoped_refptr RTCPeerConnectionFactoryImpl::GetVideoDevice() { return video_device_impl_; } +#endif + scoped_refptr RTCPeerConnectionFactoryImpl::CreateAudioSource( const string audio_source_label) { @@ -162,7 +184,7 @@ scoped_refptr RTCPeerConnectionFactoryImpl::CreateAudioSource( return source; } -#ifdef RTC_DESKTOP_DEVICE +#ifdef RTC_DESKTOP_CAPTURE_DEVICE scoped_refptr RTCPeerConnectionFactoryImpl::GetDesktopDevice() { if (!desktop_device_impl_) { @@ -173,6 +195,7 @@ RTCPeerConnectionFactoryImpl::GetDesktopDevice() { } #endif +#ifdef RTC_VIDEO_CAPTURE_DEVICE scoped_refptr RTCPeerConnectionFactoryImpl::CreateVideoSource( scoped_refptr capturer, const string video_source_label, scoped_refptr constraints) { @@ -188,7 +211,10 @@ scoped_refptr RTCPeerConnectionFactoryImpl::CreateVideoSource( return CreateVideoSource_s( capturer, to_std_string(video_source_label).c_str(), constraints); } +#endif + +#ifdef RTC_VIDEO_CAPTURE_DEVICE scoped_refptr RTCPeerConnectionFactoryImpl::CreateVideoSource_s( scoped_refptr capturer, const char* video_source_label, scoped_refptr constraints) { @@ -204,8 +230,9 @@ scoped_refptr RTCPeerConnectionFactoryImpl::CreateVideoSource_s( new RefCountedObject(rtc_source_track)); return source; } +#endif -#ifdef RTC_DESKTOP_DEVICE +#ifdef RTC_DESKTOP_CAPTURE_DEVICE scoped_refptr RTCPeerConnectionFactoryImpl::CreateDesktopSource( scoped_refptr capturer, const string video_source_label, scoped_refptr constraints) { diff --git a/src/rtc_peerconnection_factory_impl.h b/src/rtc_peerconnection_factory_impl.h index f87bba67ff..b66396234b 100644 --- a/src/rtc_peerconnection_factory_impl.h +++ b/src/rtc_peerconnection_factory_impl.h @@ -10,9 +10,12 @@ #include "rtc_base/thread.h" #include "rtc_peerconnection.h" #include "rtc_peerconnection_factory.h" + +#ifdef RTC_VIDEO_CAPTURE_DEVICE #include "rtc_video_device_impl.h" +#endif -#ifdef RTC_DESKTOP_DEVICE +#ifdef RTC_DESKTOP_CAPTURE_DEVICE #include "rtc_desktop_capturer_impl.h" #include "rtc_desktop_device_impl.h" #include "src/internal/desktop_capturer.h" @@ -36,28 +39,36 @@ class RTCPeerConnectionFactoryImpl : public RTCPeerConnectionFactory { void Delete(scoped_refptr peerconnection) override; +#if !defined(LIB_WEBRTC_USE_DUMMY_AUDIO_DEVICE) scoped_refptr GetAudioDevice() override; +#endif +#ifdef RTC_VIDEO_CAPTURE_DEVICE scoped_refptr GetVideoDevice() override; +#endif virtual scoped_refptr CreateAudioSource( const string audio_source_label) override; + virtual scoped_refptr CreateAudioTrack( + scoped_refptr source, const string track_id) override; + + virtual scoped_refptr CreateVideoTrack( + scoped_refptr source, const string track_id) override; + +#ifdef RTC_VIDEO_CAPTURE_DEVICE virtual scoped_refptr CreateVideoSource( scoped_refptr capturer, const string video_source_label, scoped_refptr constraints) override; -#ifdef RTC_DESKTOP_DEVICE +#endif + +#ifdef RTC_DESKTOP_CAPTURE_DEVICE virtual scoped_refptr GetDesktopDevice() override; virtual scoped_refptr CreateDesktopSource( scoped_refptr capturer, const string video_source_label, scoped_refptr constraints) override; #endif - virtual scoped_refptr CreateAudioTrack( - scoped_refptr source, const string track_id) override; - - virtual scoped_refptr CreateVideoTrack( - scoped_refptr source, const string track_id) override; virtual scoped_refptr CreateStream( const string stream_id) override; @@ -83,7 +94,7 @@ class RTCPeerConnectionFactoryImpl : public RTCPeerConnectionFactory { scoped_refptr CreateVideoSource_s( scoped_refptr capturer, const char* video_source_label, scoped_refptr constraints); -#ifdef RTC_DESKTOP_DEVICE +#ifdef RTC_DESKTOP_CAPTURE_DEVICE scoped_refptr CreateDesktopSource_d( scoped_refptr capturer, const char* video_source_label, @@ -95,10 +106,15 @@ class RTCPeerConnectionFactoryImpl : public RTCPeerConnectionFactory { std::unique_ptr network_thread_; rtc::scoped_refptr rtc_peerconnection_factory_; + rtc::scoped_refptr audio_device_module_; +#if !defined(LIB_WEBRTC_USE_DUMMY_AUDIO_DEVICE) scoped_refptr audio_device_impl_; +#endif +#ifdef RTC_VIDEO_CAPTURE_DEVICE scoped_refptr video_device_impl_; -#ifdef RTC_DESKTOP_DEVICE +#endif +#ifdef RTC_DESKTOP_CAPTURE_DEVICE scoped_refptr desktop_device_impl_; #endif std::list> peerconnections_; diff --git a/src/rtc_video_frame_impl.h b/src/rtc_video_frame_impl.h index 3af6845abb..0fbe094ee1 100644 --- a/src/rtc_video_frame_impl.h +++ b/src/rtc_video_frame_impl.h @@ -51,6 +51,8 @@ class VideoFrameBufferImpl : public RTCVideoFrame { void set_rotation(webrtc::VideoRotation rotation) { rotation_ = rotation; } + webrtc::VideoRotation rtc_rotation() { return rotation_; } + private: rtc::scoped_refptr buffer_; int64_t timestamp_us_ = 0; diff --git a/src/rtc_video_source_impl.cc b/src/rtc_video_source_impl.cc index ef4ec9c5a6..df3c438f2b 100644 --- a/src/rtc_video_source_impl.cc +++ b/src/rtc_video_source_impl.cc @@ -6,6 +6,58 @@ namespace libwebrtc { +class AdaptedVirtualVideoCapturer : public rtc::AdaptedVideoTrackSource { + public: + AdaptedVirtualVideoCapturer() {} + ~AdaptedVirtualVideoCapturer() override {} + + bool is_screencast() const override { return false; } + + absl::optional needs_denoising() const override { return false; } + + SourceState state() const override { return kLive; } + + bool remote() const override { return false; } + + void OnFrameCaptured(scoped_refptr frame) { + VideoFrameBufferImpl* impl = + static_cast(frame.get()); + auto newFrame = webrtc::VideoFrame::Builder() + .set_video_frame_buffer(impl->buffer()) + .set_rotation(impl->rtc_rotation()) + .set_timestamp_us(impl->timestamp_us()) + .build(); + OnFrame(newFrame); + } +}; + +class VirtualVideoCapturerImpl : public VirtualVideoCapturer { + public: + VirtualVideoCapturerImpl() { + adapted_source_ = new rtc::RefCountedObject(); + rtc_source_ = scoped_refptr( + new RefCountedObject(adapted_source_)); + } + virtual ~VirtualVideoCapturerImpl() {} + + virtual scoped_refptr source() override { + return rtc_source_; + } + + virtual void OnFrameCaptured(scoped_refptr frame) override { + adapted_source_->OnFrameCaptured(frame); + } + + private: + rtc::scoped_refptr adapted_source_; + scoped_refptr rtc_source_; +}; + +scoped_refptr VirtualVideoCapturer::Create() { + return scoped_refptr( + new RefCountedObject()); +} + RTCVideoSourceImpl::RTCVideoSourceImpl( rtc::scoped_refptr rtc_source_track) : rtc_source_track_(rtc_source_track) { diff --git a/src/rtc_video_source_impl.h b/src/rtc_video_source_impl.h index 568355701c..9433379d3f 100644 --- a/src/rtc_video_source_impl.h +++ b/src/rtc_video_source_impl.h @@ -2,6 +2,7 @@ #define LIB_WEBRTC_VIDEO_SOURCE_IMPL_HXX #include "api/media_stream_interface.h" +#include "media/base/adapted_video_track_source.h" #include "media/base/video_broadcaster.h" #include "media/base/video_source_base.h" #include "rtc_peerconnection_factory_impl.h" From ac9688615a0b1ec81f590b13e8aed2e965fc98ab Mon Sep 17 00:00:00 2001 From: cloudwebrtc Date: Fri, 16 Aug 2024 21:21:41 +0800 Subject: [PATCH 2/2] support swig. --- BUILD.gn | 12 +++- include/base/portable.h | 22 ++----- include/rtc_audio_device.h | 2 +- include/rtc_audio_frame.h | 4 +- include/rtc_config.h | 22 +++++++ include/rtc_desktop_media_list.h | 2 +- include/rtc_dtls_transport.h | 4 +- include/rtc_ice_candidate.h | 2 +- include/rtc_mediaconstraints.h | 50 +++++++------- include/rtc_peerconnection.h | 16 ++--- include/rtc_peerconnection_factory.h | 12 +++- include/rtc_rtp_transceiver.h | 6 +- include/rtc_session_description.h | 2 +- include/rtc_types.h | 91 +++++++++++++++++++++----- include/rtc_video_frame.h | 4 +- include/rtc_video_source.h | 2 +- src/rtc_desktop_media_list_impl.h | 2 +- src/rtc_frame_cryptor_impl.cc | 4 +- src/rtc_frame_cryptor_impl.h | 14 ++-- src/rtc_media_stream_impl.cc | 4 +- src/rtc_media_stream_impl.h | 27 +++++--- src/rtc_mediaconstraints_impl.cc | 42 ++++++------ src/rtc_peerconnection_factory_impl.cc | 8 +-- src/rtc_peerconnection_factory_impl.h | 13 ++-- src/rtc_peerconnection_impl.cc | 14 ++-- src/rtc_peerconnection_impl.h | 6 +- src/rtc_rtp_capabilities_impl.cc | 10 +-- src/rtc_rtp_parameters_impl.cc | 8 +-- src/rtc_rtp_sender_impl.cc | 6 +- src/rtc_rtp_transceiver_impl.cc | 12 ++-- swig/Makefile | 5 ++ swig/libwebrtc.i | 82 +++++++++++++++++++++++ swig/rtc_test.py | 46 +++++++++++++ 33 files changed, 389 insertions(+), 167 deletions(-) create mode 100644 include/rtc_config.h create mode 100644 swig/Makefile create mode 100644 swig/libwebrtc.i create mode 100644 swig/rtc_test.py diff --git a/BUILD.gn b/BUILD.gn index 967f2a12e0..06e39f5f22 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -36,6 +36,11 @@ config("external_config") { rtc_shared_library("libwebrtc") { libs = [] + visibility = [ + "//:default", + ] + #complete_static_lib = true + #suppressed_configs += [ "//build/config/compiler:thin_archive" ] include_dirs = [ ".", "include", @@ -43,11 +48,12 @@ rtc_shared_library("libwebrtc") { defines = [ "USE_LIBYUV", + "SHARED_BUILD", + #"USE_PORTABLE_TYPES", ] - if(libwebrtc_dummy_audio_device) { - defines += [ "LIB_WEBRTC_USE_DUMMY_AUDIO_DEVICE" ] - } else { + if(!libwebrtc_dummy_audio_device) { + defines += [ "RTC_AUDIO_DEVICE" ] defines += [ "WEBRTC_INCLUDE_INTERNAL_AUDIO_DEVICE" ] } diff --git a/include/base/portable.h b/include/base/portable.h index b403af9cd3..70d9df9fc0 100644 --- a/include/base/portable.h +++ b/include/base/portable.h @@ -1,15 +1,7 @@ #ifndef INFINISPAN_HOTROD_PORTABLE_H #define INFINISPAN_HOTROD_PORTABLE_H -#ifdef LIB_WEBRTC_API_EXPORTS -#define LIB_PORTABLE_API __declspec(dllexport) -#elif defined(LIB_WEBRTC_API_DLL) -#define LIB_PORTABLE_API __declspec(dllimport) -#elif !defined(WIN32) -#define LIB_PORTABLE_API __attribute__((visibility("default"))) -#else -#define LIB_PORTABLE_API -#endif +#include "../rtc_config.h" #include #include @@ -45,9 +37,9 @@ class string { size_t m_length; public: - LIB_PORTABLE_API string(); - LIB_PORTABLE_API void init(const char* str, size_t len); - LIB_PORTABLE_API void destroy(); + LIB_WEBRTC_API string(); + LIB_WEBRTC_API void init(const char* str, size_t len); + LIB_WEBRTC_API void destroy(); inline string(const char* str) { init(str, strlen(str)); } @@ -63,7 +55,7 @@ class string { return *this; } - LIB_PORTABLE_API ~string(); + LIB_WEBRTC_API ~string(); inline string& operator=(const std::string& str) { destroy(); @@ -73,7 +65,7 @@ class string { inline size_t size() { return m_length; } - inline const char* c_string() const { + inline const char* c_str() const { return m_dynamic == 0 ? m_buf : m_dynamic; } @@ -82,8 +74,6 @@ class string { } }; -inline std::string to_std_string(const string& str) { return str.std_string(); } - template class identity { T operator()(const T& x) { return x; } diff --git a/include/rtc_audio_device.h b/include/rtc_audio_device.h index cff7b4a6ac..c89afdbea9 100644 --- a/include/rtc_audio_device.h +++ b/include/rtc_audio_device.h @@ -12,7 +12,7 @@ namespace libwebrtc { */ class RTCAudioDevice : public RefCountInterface { public: - typedef fixed_size_function OnDeviceChangeCallback; + typedef callback_function_t OnDeviceChangeCallback; public: static const int kAdmMaxDeviceNameSize = 128; diff --git a/include/rtc_audio_frame.h b/include/rtc_audio_frame.h index b591e4dc66..1103fbf2c1 100644 --- a/include/rtc_audio_frame.h +++ b/include/rtc_audio_frame.h @@ -7,9 +7,9 @@ namespace libwebrtc { class RTCAudioFrame : public RefCountInterface { public: - LIB_WEBRTC_API static scoped_refptr Create(); + LIB_WEBRTC_API static scoped_refptr Create(); - LIB_WEBRTC_API static scoped_refptr Create( + LIB_WEBRTC_API static scoped_refptr Create( uint32_t timestamp, const int16_t* data, size_t samples_per_channel, int sample_rate_hz, size_t num_channels = 1); diff --git a/include/rtc_config.h b/include/rtc_config.h new file mode 100644 index 0000000000..74311fa5ff --- /dev/null +++ b/include/rtc_config.h @@ -0,0 +1,22 @@ +#ifndef WEBRTC_CONFIG_H_ +#define WEBRTC_CONFIG_H_ + +#ifdef SHARED_BUILD + +#ifdef LIB_WEBRTC_API_EXPORTS +#define LIB_WEBRTC_API __declspec(dllexport) +#elif defined(LIB_WEBRTC_API_DLL) +#define LIB_WEBRTC_API __declspec(dllimport) +#elif !defined(WIN32) +#define LIB_WEBRTC_API __attribute__((visibility("default"))) +#else +#define LIB_WEBRTC_API +#endif + +#else + +#define LIB_WEBRTC_API + +#endif + +#endif // WEBRTC_CONFIG_H_ \ No newline at end of file diff --git a/include/rtc_desktop_media_list.h b/include/rtc_desktop_media_list.h index 48faf2a959..db4beaeec1 100644 --- a/include/rtc_desktop_media_list.h +++ b/include/rtc_desktop_media_list.h @@ -14,7 +14,7 @@ class MediaSource : public RefCountInterface { virtual string name() const = 0; // Returns the thumbnail of the source, jpeg format. - virtual portable::vector thumbnail() const = 0; + virtual vector thumbnail() const = 0; virtual DesktopType type() const = 0; diff --git a/include/rtc_dtls_transport.h b/include/rtc_dtls_transport.h index fe7adad7f0..ba10d5d07c 100644 --- a/include/rtc_dtls_transport.h +++ b/include/rtc_dtls_transport.h @@ -27,7 +27,7 @@ class RTCDtlsTransportInformation : public RefCountInterface { class RTCDtlsTransportObserver { public: - virtual void OnStateChange(RTCDtlsTransportInformation info) = 0; + virtual void OnStateChange(scoped_refptr info) = 0; virtual void OnError(const int type, const char* message) = 0; @@ -36,7 +36,7 @@ class RTCDtlsTransportObserver { }; class RTCDtlsTransport : public RefCountInterface { - LIB_WEBRTC_API static scoped_refptr Create(); + LIB_WEBRTC_API static scoped_refptr Create(); public: virtual scoped_refptr GetInformation() = 0; diff --git a/include/rtc_ice_candidate.h b/include/rtc_ice_candidate.h index 82da46edb4..3cc75eec9a 100644 --- a/include/rtc_ice_candidate.h +++ b/include/rtc_ice_candidate.h @@ -7,7 +7,7 @@ namespace libwebrtc { class RTCIceCandidate : public RefCountInterface { public: - static LIB_WEBRTC_API scoped_refptr Create( + LIB_WEBRTC_API static scoped_refptr Create( const string sdp, const string sdp_mid, int sdp_mline_index, SdpParseError* error); diff --git a/include/rtc_mediaconstraints.h b/include/rtc_mediaconstraints.h index 2596e6153f..2c87be5f8d 100644 --- a/include/rtc_mediaconstraints.h +++ b/include/rtc_mediaconstraints.h @@ -8,60 +8,54 @@ namespace libwebrtc { class RTCMediaConstraints : public RefCountInterface { public: // These keys are google specific. - LIB_WEBRTC_API static const char* + LIB_WEBRTC_API static string kGoogEchoCancellation; // googEchoCancellation - - LIB_WEBRTC_API static const char* - kExtendedFilterEchoCancellation; // googEchoCancellation2 - LIB_WEBRTC_API static const char* - kDAEchoCancellation; // googDAEchoCancellation - LIB_WEBRTC_API static const char* kAutoGainControl; // googAutoGainControl - LIB_WEBRTC_API static const char* kNoiseSuppression; // googNoiseSuppression - LIB_WEBRTC_API static const char* kHighpassFilter; // googHighpassFilter - LIB_WEBRTC_API static const char* kAudioMirroring; // googAudioMirroring - LIB_WEBRTC_API static const char* + LIB_WEBRTC_API static string + kDAEchoCancellation; // googDAEchoCancellation + LIB_WEBRTC_API static string kAutoGainControl; // googAutoGainControl + LIB_WEBRTC_API static string kNoiseSuppression; // googNoiseSuppression + LIB_WEBRTC_API static string kHighpassFilter; // googHighpassFilter + LIB_WEBRTC_API static string kAudioMirroring; // googAudioMirroring + LIB_WEBRTC_API static string kAudioNetworkAdaptorConfig; // goodAudioNetworkAdaptorConfig // Constraint keys for CreateOffer / CreateAnswer // Specified by the W3C PeerConnection spec - LIB_WEBRTC_API static const char* + LIB_WEBRTC_API static string kOfferToReceiveVideo; // OfferToReceiveVideo - LIB_WEBRTC_API static const char* + LIB_WEBRTC_API static string kOfferToReceiveAudio; // OfferToReceiveAudio - LIB_WEBRTC_API static const char* + LIB_WEBRTC_API static string kVoiceActivityDetection; // VoiceActivityDetection - LIB_WEBRTC_API static const char* kIceRestart; // IceRestart + LIB_WEBRTC_API static string kIceRestart; // IceRestart // These keys are google specific. - LIB_WEBRTC_API static const char* kUseRtpMux; // googUseRtpMUX + LIB_WEBRTC_API static string kUseRtpMux; // googUseRtpMUX // Constraints values. - LIB_WEBRTC_API static const char* kValueTrue; // true - LIB_WEBRTC_API static const char* kValueFalse; // false + LIB_WEBRTC_API static string kValueTrue; // true + LIB_WEBRTC_API static string kValueFalse; // false // PeerConnection constraint keys. - // Temporary pseudo-constraints used to enable DataChannels - LIB_WEBRTC_API static const char* - kEnableRtpDataChannels; // Enable RTP DataChannels // Google-specific constraint keys. // Temporary pseudo-constraint for enabling DSCP through JS. - LIB_WEBRTC_API static const char* kEnableDscp; // googDscp + LIB_WEBRTC_API static string kEnableDscp; // googDscp // Constraint to enable IPv6 through JS. - LIB_WEBRTC_API static const char* kEnableIPv6; // googIPv6 + LIB_WEBRTC_API static string kEnableIPv6; // googIPv6 // Temporary constraint to enable suspend below min bitrate feature. - LIB_WEBRTC_API static const char* kEnableVideoSuspendBelowMinBitrate; + LIB_WEBRTC_API static string kEnableVideoSuspendBelowMinBitrate; // googSuspendBelowMinBitrate // Constraint to enable combined audio+video bandwidth estimation. - //LIB_WEBRTC_API static const char* + //LIB_WEBRTC_API static string // kCombinedAudioVideoBwe; // googCombinedAudioVideoBwe - LIB_WEBRTC_API static const char* + LIB_WEBRTC_API static string kScreencastMinBitrate; // googScreencastMinBitrate - LIB_WEBRTC_API static const char* + LIB_WEBRTC_API static string kCpuOveruseDetection; // googCpuOveruseDetection // Specifies number of simulcast layers for all video tracks // with a Plan B offer/answer // (see RTCOfferAnswerOptions::num_simulcast_layers). - LIB_WEBRTC_API static const char* kNumSimulcastLayers; + LIB_WEBRTC_API static string kNumSimulcastLayers; public: LIB_WEBRTC_API static scoped_refptr Create(); diff --git a/include/rtc_peerconnection.h b/include/rtc_peerconnection.h index 35ea2ad3ea..2799ca34b1 100644 --- a/include/rtc_peerconnection.h +++ b/include/rtc_peerconnection.h @@ -118,25 +118,25 @@ class MediaRTCStats : public RefCountInterface { virtual const vector> Members() = 0; }; -typedef fixed_size_function> reports)> OnStatsCollectorSuccess; -typedef fixed_size_function OnStatsCollectorFailure; +typedef callback_function_t OnStatsCollectorFailure; -typedef fixed_size_function +typedef callback_function_t OnSdpCreateSuccess; -typedef fixed_size_function OnSdpCreateFailure; +typedef callback_function_t OnSdpCreateFailure; -typedef fixed_size_function OnSetSdpSuccess; +typedef callback_function_t OnSetSdpSuccess; -typedef fixed_size_function OnSetSdpFailure; +typedef callback_function_t OnSetSdpFailure; -typedef fixed_size_function +typedef callback_function_t OnGetSdpSuccess; -typedef fixed_size_function OnGetSdpFailure; +typedef callback_function_t OnGetSdpFailure; class RTCPeerConnectionObserver { public: diff --git a/include/rtc_peerconnection_factory.h b/include/rtc_peerconnection_factory.h index be52805893..f394308287 100644 --- a/include/rtc_peerconnection_factory.h +++ b/include/rtc_peerconnection_factory.h @@ -9,14 +9,20 @@ #endif #include "rtc_media_stream.h" #include "rtc_mediaconstraints.h" +#ifdef RTC_VIDEO_CAPTURE_DEVICE #include "rtc_video_device.h" +#endif #include "rtc_video_source.h" namespace libwebrtc { class RTCPeerConnection; +#ifdef RTC_AUDIO_DEVICE class RTCAudioDevice; +#endif +#ifdef RTC_VIDEO_CAPTURE_DEVICE class RTCVideoDevice; +#endif class RTCRtpCapabilities; class RTCPeerConnectionFactory : public RefCountInterface { @@ -26,12 +32,12 @@ class RTCPeerConnectionFactory : public RefCountInterface { virtual bool Terminate() = 0; virtual scoped_refptr Create( - const RTCConfiguration& configuration, - scoped_refptr constraints) = 0; + const RTCConfiguration* configuration = nullptr, + scoped_refptr constraints = nullptr) = 0; virtual void Delete(scoped_refptr peerconnection) = 0; -#if !defined(LIB_WEBRTC_USE_DUMMY_AUDIO_DEVICE) +#ifdef RTC_AUDIO_DEVICE virtual scoped_refptr GetAudioDevice() = 0; #endif diff --git a/include/rtc_rtp_transceiver.h b/include/rtc_rtp_transceiver.h index ecf24f45b6..3c27e22178 100644 --- a/include/rtc_rtp_transceiver.h +++ b/include/rtc_rtp_transceiver.h @@ -1,18 +1,18 @@ #ifndef LIB_WEBRTC_RTC_RTP_TRANSCEIVER_HXX #define LIB_WEBRTC_RTC_RTP_TRANSCEIVER_HXX -#include "base/refcount.h" +#include "rtc_types.h" + #include "rtc_rtp_capabilities.h" #include "rtc_rtp_parameters.h" #include "rtc_rtp_receiver.h" #include "rtc_rtp_sender.h" -#include "rtc_types.h" namespace libwebrtc { class RTCRtpTransceiverInit : public RefCountInterface { public: - LIB_WEBRTC_API static scoped_refptr Create( + LIB_WEBRTC_API static scoped_refptr Create( RTCRtpTransceiverDirection direction, const vector stream_ids, const vector> encodings); diff --git a/include/rtc_session_description.h b/include/rtc_session_description.h index 84aa2abbc9..9db6258a8e 100644 --- a/include/rtc_session_description.h +++ b/include/rtc_session_description.h @@ -9,7 +9,7 @@ class RTCSessionDescription : public RefCountInterface { public: enum SdpType { kOffer = 0, kPrAnswer, kAnswer }; - static LIB_WEBRTC_API scoped_refptr Create( + LIB_WEBRTC_API static scoped_refptr Create( const string type, const string sdp, SdpParseError* error); public: diff --git a/include/rtc_types.h b/include/rtc_types.h index 017386d071..0b0aadff99 100644 --- a/include/rtc_types.h +++ b/include/rtc_types.h @@ -1,42 +1,62 @@ #ifndef LIB_WEBRTC_RTC_TYPES_HXX #define LIB_WEBRTC_RTC_TYPES_HXX -#ifdef LIB_WEBRTC_API_EXPORTS -#define LIB_WEBRTC_API __declspec(dllexport) -#elif defined(LIB_WEBRTC_API_DLL) -#define LIB_WEBRTC_API __declspec(dllimport) -#elif !defined(WIN32) -#define LIB_WEBRTC_API __attribute__((visibility("default"))) +#include "rtc_config.h" + +#include + +#ifdef USE_PORTABLE_TYPES +#include "base/portable.h" +#include "base/fixed_size_function.h" #else -#define LIB_WEBRTC_API +#include +#include +#include #endif -#include "base/fixed_size_function.h" -#include "base/portable.h" #include "base/refcount.h" #include "base/scoped_ref_ptr.h" namespace libwebrtc { -enum { kMaxIceServerSize = 8 }; +#ifdef USE_PORTABLE_TYPES +using string = portable::string; -// template -// using vector = bsp::inlined_vector; +inline std::string to_std_string(const string& str) { return str.std_string(); } template using map = std::map; -enum class MediaSecurityType { kSRTP_None = 0, kSDES_SRTP, kDTLS_SRTP }; +template +using vector = portable::vector; -enum class RTCMediaType { AUDIO, VIDEO, DATA, UNSUPPORTED }; +template +inline std::vector to_std_vector(const vector& vec) { + return vec.std_vector(); +} -using string = portable::string; +#define callback_function_t fixed_size_function -// template -// using map = portable::map; +#else +using string = std::string; +#define to_std_string(str) str template -using vector = portable::vector; +using vector = std::vector; +#define to_std_vector(vec) vec + +template +using map = std::map; + +#define callback_function_t std::function + +#endif + +enum { kMaxIceServerSize = 8 }; + +enum class MediaSecurityType { kSRTP_None = 0, kSDES_SRTP, kDTLS_SRTP }; + +enum class RTCMediaType { AUDIO, VIDEO, DATA, UNSUPPORTED }; struct IceServer { string uri; @@ -96,6 +116,41 @@ struct RTCConfiguration { bool use_rtp_mux = true; uint32_t local_audio_bandwidth = 128; uint32_t local_video_bandwidth = 512; + public: + RTCConfiguration() { + for (int i = 0; i < kMaxIceServerSize; i++) { + ice_servers[i].uri = ""; + ice_servers[i].username = ""; + ice_servers[i].password = ""; + } + } + + RTCConfiguration& operator=(const RTCConfiguration& other) { + for (int i = 0; i < kMaxIceServerSize; i++) { + ice_servers[i].uri = other.ice_servers[i].uri; + ice_servers[i].username = other.ice_servers[i].username; + ice_servers[i].password = other.ice_servers[i].password; + } + type = other.type; + bundle_policy = other.bundle_policy; + rtcp_mux_policy = other.rtcp_mux_policy; + candidate_network_policy = other.candidate_network_policy; + tcp_candidate_policy = other.tcp_candidate_policy; + ice_candidate_pool_size = other.ice_candidate_pool_size; + srtp_type = other.srtp_type; + sdp_semantics = other.sdp_semantics; + offer_to_receive_audio = other.offer_to_receive_audio; + offer_to_receive_video = other.offer_to_receive_video; + disable_ipv6 = other.disable_ipv6; + disable_ipv6_on_wifi = other.disable_ipv6_on_wifi; + max_ipv6_networks = other.max_ipv6_networks; + disable_link_local_networks = other.disable_link_local_networks; + screencast_min_bitrate = other.screencast_min_bitrate; + use_rtp_mux = other.use_rtp_mux; + local_audio_bandwidth = other.local_audio_bandwidth; + local_video_bandwidth = other.local_video_bandwidth; + return *this; + } }; struct SdpParseError { diff --git a/include/rtc_video_frame.h b/include/rtc_video_frame.h index a69023f052..35b648b2e6 100644 --- a/include/rtc_video_frame.h +++ b/include/rtc_video_frame.h @@ -17,10 +17,10 @@ class RTCVideoFrame : public RefCountInterface { }; public: - LIB_WEBRTC_API static scoped_refptr Create( + LIB_WEBRTC_API static scoped_refptr Create( int width, int height, const uint8_t* buffer, int length); - LIB_WEBRTC_API static scoped_refptr Create( + LIB_WEBRTC_API static scoped_refptr Create( int width, int height, const uint8_t* data_y, int stride_y, const uint8_t* data_u, int stride_u, const uint8_t* data_v, int stride_v); diff --git a/include/rtc_video_source.h b/include/rtc_video_source.h index 3343966265..0411b37ed0 100644 --- a/include/rtc_video_source.h +++ b/include/rtc_video_source.h @@ -13,7 +13,7 @@ class RTCVideoSource : public RefCountInterface { class VirtualVideoCapturer : public RefCountInterface { public: - LIB_WEBRTC_API static scoped_refptr Create(); + LIB_WEBRTC_API static scoped_refptr Create(); virtual void OnFrameCaptured(scoped_refptr frame) = 0; diff --git a/src/rtc_desktop_media_list_impl.h b/src/rtc_desktop_media_list_impl.h index bfd6561bc7..07b0a619b8 100644 --- a/src/rtc_desktop_media_list_impl.h +++ b/src/rtc_desktop_media_list_impl.h @@ -50,7 +50,7 @@ class MediaSourceImpl : public MediaSource { string name() const override { return string(source.title); } // Returns the thumbnail of the source, jpeg format. - portable::vector thumbnail() const override { + vector thumbnail() const override { return thumbnail_; } diff --git a/src/rtc_frame_cryptor_impl.cc b/src/rtc_frame_cryptor_impl.cc index b720e44368..675f49f490 100644 --- a/src/rtc_frame_cryptor_impl.cc +++ b/src/rtc_frame_cryptor_impl.cc @@ -52,7 +52,7 @@ RTCFrameCryptorImpl::RTCFrameCryptorImpl( : webrtc::FrameCryptorTransformer::MediaType::kVideoFrame; e2ee_transformer_ = rtc::scoped_refptr( new webrtc::FrameCryptorTransformer( - factoryImpl->signaling_thread(), participant_id_.std_string(), + factoryImpl->signaling_thread(), to_std_string(participant_id_), mediaType, AlgorithmToFrameCryptorAlgorithm(algorithm), keyImpl->rtc_key_provider())); e2ee_transformer_->RegisterFrameCryptorTransformerObserver(observer_); @@ -82,7 +82,7 @@ RTCFrameCryptorImpl::RTCFrameCryptorImpl( : webrtc::FrameCryptorTransformer::MediaType::kVideoFrame; e2ee_transformer_ = rtc::scoped_refptr( new webrtc::FrameCryptorTransformer( - factoryImpl->signaling_thread(), participant_id_.std_string(), + factoryImpl->signaling_thread(), to_std_string(participant_id_), mediaType, AlgorithmToFrameCryptorAlgorithm(algorithm), keyImpl->rtc_key_provider())); e2ee_transformer_->RegisterFrameCryptorTransformerObserver(observer_); diff --git a/src/rtc_frame_cryptor_impl.h b/src/rtc_frame_cryptor_impl.h index b44d887d31..28718532bc 100644 --- a/src/rtc_frame_cryptor_impl.h +++ b/src/rtc_frame_cryptor_impl.h @@ -14,9 +14,9 @@ class DefaultKeyProviderImpl : public KeyProvider { DefaultKeyProviderImpl(KeyProviderOptions* options) { webrtc::KeyProviderOptions rtc_options; rtc_options.shared_key = options->shared_key; - rtc_options.ratchet_salt = options->ratchet_salt.std_vector(); + rtc_options.ratchet_salt = to_std_vector(options->ratchet_salt); rtc_options.uncrypted_magic_bytes = - options->uncrypted_magic_bytes.std_vector(); + to_std_vector(options->uncrypted_magic_bytes); rtc_options.ratchet_window_size = options->ratchet_window_size; rtc_options.failure_tolerance = options->failure_tolerance; rtc_options.key_ring_size = options->key_ring_size; @@ -28,7 +28,7 @@ class DefaultKeyProviderImpl : public KeyProvider { ~DefaultKeyProviderImpl() {} bool SetSharedKey(int index, vector key) override { - return impl_->SetSharedKey(index, key.std_vector()); + return impl_->SetSharedKey(index, to_std_vector(key)); } vector RatchetSharedKey(int key_index) override { @@ -42,21 +42,21 @@ class DefaultKeyProviderImpl : public KeyProvider { /// Set the key at the given index. bool SetKey(const string participant_id, int index, vector key) override { - return impl_->SetKey(participant_id.std_string(), index, key.std_vector()); + return impl_->SetKey(to_std_string(participant_id), index, to_std_vector(key)); } vector RatchetKey(const string participant_id, int key_index) override { - return impl_->RatchetKey(participant_id.std_string(), key_index); + return impl_->RatchetKey(to_std_string(participant_id), key_index); } vector ExportKey(const string participant_id, int key_index) override { - return impl_->ExportKey(participant_id.std_string(), key_index); + return impl_->ExportKey(to_std_string(participant_id), key_index); } void SetSifTrailer(vector trailer) override { - impl_->SetSifTrailer(trailer.std_vector()); + impl_->SetSifTrailer(to_std_vector(trailer)); } rtc::scoped_refptr rtc_key_provider() { return impl_; } diff --git a/src/rtc_media_stream_impl.cc b/src/rtc_media_stream_impl.cc index f5d6072a4b..ecf812a43c 100644 --- a/src/rtc_media_stream_impl.cc +++ b/src/rtc_media_stream_impl.cc @@ -96,7 +96,7 @@ vector> MediaStreamImpl::tracks() { scoped_refptr MediaStreamImpl::FindAudioTrack( const string track_id) { for (auto track : audio_tracks_) { - if (track->id().std_string() == track_id.std_string()) return track; + if (to_std_string(track->id()) == to_std_string(track_id)) return track; } return scoped_refptr(); @@ -105,7 +105,7 @@ scoped_refptr MediaStreamImpl::FindAudioTrack( scoped_refptr MediaStreamImpl::FindVideoTrack( const string track_id) { for (auto track : video_tracks_) { - if (track->id().std_string() == track_id.std_string()) return track; + if (to_std_string(track->id()) == to_std_string(track_id)) return track; } return scoped_refptr(); diff --git a/src/rtc_media_stream_impl.h b/src/rtc_media_stream_impl.h index 011efc90af..901f0f274a 100644 --- a/src/rtc_media_stream_impl.h +++ b/src/rtc_media_stream_impl.h @@ -135,21 +135,30 @@ class RTCStatsMemberImpl : public RTCStatsMember { } vector ValueSequenceString() const override { - return attr_.get>(); + auto val = attr_.get>(); + vector out; + for (const auto& v : val) { + out.push_back(v); + } + return out; } map ValueMapStringUint64() const override { - // const std::map& mapout = *member_->cast_to< - // webrtc::RTCStatsMember>>(); - return map(); + auto val = attr_.get>(); + map out; + for (const auto& v : val) { + out[v.first] = v.second; + } + return out; } map ValueMapStringDouble() const override { - // const std::map& mapout = - // *member_ - // ->cast_to>>(); - return map(); + auto val = attr_.get>(); + map out; + for (const auto& v : val) { + out[v.first] = v.second; + } + return out; } private: diff --git a/src/rtc_mediaconstraints_impl.cc b/src/rtc_mediaconstraints_impl.cc index 19205ef8d7..042a6d98da 100644 --- a/src/rtc_mediaconstraints_impl.cc +++ b/src/rtc_mediaconstraints_impl.cc @@ -9,44 +9,46 @@ scoped_refptr RTCMediaConstraints::Create() { return constraints; } -const char* RTCMediaConstraints::kGoogEchoCancellation = +string RTCMediaConstraints::kDAEchoCancellation = "googDAEchoCancellation"; + +string RTCMediaConstraints::kGoogEchoCancellation = webrtc::MediaConstraints::kGoogEchoCancellation; -const char* RTCMediaConstraints::kAutoGainControl = +string RTCMediaConstraints::kAutoGainControl = webrtc::MediaConstraints::kAutoGainControl; -const char* RTCMediaConstraints::kNoiseSuppression = +string RTCMediaConstraints::kNoiseSuppression = webrtc::MediaConstraints::kNoiseSuppression; -const char* RTCMediaConstraints::kHighpassFilter = +string RTCMediaConstraints::kHighpassFilter = webrtc::MediaConstraints::kHighpassFilter; -const char* RTCMediaConstraints::kAudioMirroring = +string RTCMediaConstraints::kAudioMirroring = webrtc::MediaConstraints::kAudioMirroring; -const char* RTCMediaConstraints::kAudioNetworkAdaptorConfig = +string RTCMediaConstraints::kAudioNetworkAdaptorConfig = webrtc::MediaConstraints::kAudioNetworkAdaptorConfig; -const char* RTCMediaConstraints::kOfferToReceiveVideo = +string RTCMediaConstraints::kOfferToReceiveVideo = webrtc::MediaConstraints::kOfferToReceiveVideo; -const char* RTCMediaConstraints::kOfferToReceiveAudio = +string RTCMediaConstraints::kOfferToReceiveAudio = webrtc::MediaConstraints::kOfferToReceiveAudio; -const char* RTCMediaConstraints::kVoiceActivityDetection = +string RTCMediaConstraints::kVoiceActivityDetection = webrtc::MediaConstraints::kVoiceActivityDetection; -const char* RTCMediaConstraints::kIceRestart = +string RTCMediaConstraints::kIceRestart = webrtc::MediaConstraints::kIceRestart; -const char* RTCMediaConstraints::kUseRtpMux = +string RTCMediaConstraints::kUseRtpMux = webrtc::MediaConstraints::kUseRtpMux; -const char* RTCMediaConstraints::kValueTrue = +string RTCMediaConstraints::kValueTrue = webrtc::MediaConstraints::kValueTrue; -const char* RTCMediaConstraints::kValueFalse = +string RTCMediaConstraints::kValueFalse = webrtc::MediaConstraints::kValueFalse; -const char* RTCMediaConstraints::kEnableDscp = +string RTCMediaConstraints::kEnableDscp = webrtc::MediaConstraints::kEnableDscp; -const char* RTCMediaConstraints::kEnableIPv6 = "enable_ipv6"; -const char* RTCMediaConstraints::kEnableVideoSuspendBelowMinBitrate = +string RTCMediaConstraints::kEnableIPv6 = "enable_ipv6"; +string RTCMediaConstraints::kEnableVideoSuspendBelowMinBitrate = webrtc::MediaConstraints::kEnableVideoSuspendBelowMinBitrate; -//const char* RTCMediaConstraints::kCombinedAudioVideoBwe = +//string RTCMediaConstraints::kCombinedAudioVideoBwe = // webrtc::MediaConstraints::kCombinedAudioVideoBwe; -const char* RTCMediaConstraints::kScreencastMinBitrate = +string RTCMediaConstraints::kScreencastMinBitrate = webrtc::MediaConstraints::kScreencastMinBitrate; -const char* RTCMediaConstraints::kCpuOveruseDetection = +string RTCMediaConstraints::kCpuOveruseDetection = webrtc::MediaConstraints::kCpuOveruseDetection; -const char* RTCMediaConstraints::kNumSimulcastLayers = +string RTCMediaConstraints::kNumSimulcastLayers = webrtc::MediaConstraints::kNumSimulcastLayers; void RTCMediaConstraintsImpl::AddMandatoryConstraint(const string key, diff --git a/src/rtc_peerconnection_factory_impl.cc b/src/rtc_peerconnection_factory_impl.cc index d3a84809da..3b564d164c 100644 --- a/src/rtc_peerconnection_factory_impl.cc +++ b/src/rtc_peerconnection_factory_impl.cc @@ -94,7 +94,7 @@ bool RTCPeerConnectionFactoryImpl::Initialize() { bool RTCPeerConnectionFactoryImpl::Terminate() { worker_thread_->BlockingCall([&] { -#if !defined(LIB_WEBRTC_USE_DUMMY_AUDIO_DEVICE) +#ifdef RTC_AUDIO_DEVICE audio_device_impl_ = nullptr; #endif #ifdef RTC_VIDEO_CAPTURE_DEVICE @@ -127,7 +127,7 @@ void RTCPeerConnectionFactoryImpl::DestroyAudioDeviceModule_w() { } scoped_refptr RTCPeerConnectionFactoryImpl::Create( - const RTCConfiguration& configuration, + const RTCConfiguration* configuration, scoped_refptr constraints) { scoped_refptr peerconnection = scoped_refptr( @@ -148,7 +148,7 @@ void RTCPeerConnectionFactoryImpl::Delete( peerconnections_.end()); } -#if !defined(LIB_WEBRTC_USE_DUMMY_AUDIO_DEVICE) +#ifdef RTC_AUDIO_DEVICE scoped_refptr RTCPeerConnectionFactoryImpl::GetAudioDevice() { if (!audio_device_module_) { worker_thread_->BlockingCall([this] { CreateAudioDeviceModule_w(); }); @@ -282,7 +282,7 @@ scoped_refptr RTCPeerConnectionFactoryImpl::CreateVideoTrack( static_cast(source.get())); rtc::scoped_refptr rtc_video_track = rtc_peerconnection_factory_->CreateVideoTrack( - source_adapter->rtc_source_track(), track_id.std_string()); + source_adapter->rtc_source_track(), to_std_string(track_id)); scoped_refptr video_track = scoped_refptr( new RefCountedObject(rtc_video_track)); diff --git a/src/rtc_peerconnection_factory_impl.h b/src/rtc_peerconnection_factory_impl.h index b66396234b..0a7090961f 100644 --- a/src/rtc_peerconnection_factory_impl.h +++ b/src/rtc_peerconnection_factory_impl.h @@ -34,12 +34,12 @@ class RTCPeerConnectionFactoryImpl : public RTCPeerConnectionFactory { bool Terminate() override; scoped_refptr Create( - const RTCConfiguration& configuration, - scoped_refptr constraints) override; + const RTCConfiguration* configuration = nullptr, + scoped_refptr constraints = nullptr) override; void Delete(scoped_refptr peerconnection) override; -#if !defined(LIB_WEBRTC_USE_DUMMY_AUDIO_DEVICE) +#ifdef RTC_AUDIO_DEVICE scoped_refptr GetAudioDevice() override; #endif @@ -90,11 +90,12 @@ class RTCPeerConnectionFactoryImpl : public RTCPeerConnectionFactory { void CreateAudioDeviceModule_w(); void DestroyAudioDeviceModule_w(); - + +#ifdef RTC_DESKTOP_CAPTURE_DEVICE scoped_refptr CreateVideoSource_s( scoped_refptr capturer, const char* video_source_label, scoped_refptr constraints); -#ifdef RTC_DESKTOP_CAPTURE_DEVICE + scoped_refptr CreateDesktopSource_d( scoped_refptr capturer, const char* video_source_label, @@ -108,7 +109,7 @@ class RTCPeerConnectionFactoryImpl : public RTCPeerConnectionFactory { rtc_peerconnection_factory_; rtc::scoped_refptr audio_device_module_; -#if !defined(LIB_WEBRTC_USE_DUMMY_AUDIO_DEVICE) +#ifdef RTC_AUDIO_DEVICE scoped_refptr audio_device_impl_; #endif #ifdef RTC_VIDEO_CAPTURE_DEVICE diff --git a/src/rtc_peerconnection_impl.cc b/src/rtc_peerconnection_impl.cc index 609287bdcf..064dfbae54 100644 --- a/src/rtc_peerconnection_impl.cc +++ b/src/rtc_peerconnection_impl.cc @@ -183,15 +183,19 @@ class CreateSessionDescriptionObserverProxy }; RTCPeerConnectionImpl::RTCPeerConnectionImpl( - const RTCConfiguration& configuration, + const RTCConfiguration* configuration, scoped_refptr constraints, rtc::scoped_refptr peer_connection_factory) : rtc_peerconnection_factory_(peer_connection_factory), - configuration_(configuration), - constraints_(constraints), callback_crt_sec_(new webrtc::Mutex()) { RTC_LOG(LS_INFO) << __FUNCTION__ << ": ctor"; + if (configuration) { + configuration_ = *configuration; + } + if (constraints) { + constraints_ = constraints; + } Initialize(); } @@ -669,7 +673,7 @@ scoped_refptr RTCPeerConnectionImpl::CreateLocalMediaStream( return nullptr; } auto stream = - rtc_peerconnection_factory_->CreateLocalMediaStream(stream_id.c_string()); + rtc_peerconnection_factory_->CreateLocalMediaStream(stream_id.c_str()); auto rtc_stream = new RefCountedObject(stream); local_streams_.push_back(rtc_stream); return rtc_stream; @@ -806,7 +810,7 @@ scoped_refptr RTCPeerConnectionImpl::AddTrack( webrtc::RTCErrorOr> errorOr; std::vector stream_ids; - for (auto id : streamIds.std_vector()) { + for (auto id : to_std_vector(streamIds)) { stream_ids.push_back(to_std_string(id)); } std::string kind = to_std_string(track->kind()); diff --git a/src/rtc_peerconnection_impl.h b/src/rtc_peerconnection_impl.h index 7920bd5fc3..2a01f372ee 100644 --- a/src/rtc_peerconnection_impl.h +++ b/src/rtc_peerconnection_impl.h @@ -137,7 +137,7 @@ class RTCPeerConnectionImpl : public RTCPeerConnection, public: RTCPeerConnectionImpl( - const RTCConfiguration& configuration, + const RTCConfiguration* configuration, scoped_refptr constraints, rtc::scoped_refptr peer_connection_factory); @@ -186,8 +186,8 @@ class RTCPeerConnectionImpl : public RTCPeerConnection, rtc::scoped_refptr rtc_peerconnection_factory_; rtc::scoped_refptr rtc_peerconnection_; - const RTCConfiguration& configuration_; - scoped_refptr constraints_; + RTCConfiguration configuration_ = RTCConfiguration(); + scoped_refptr constraints_ = RTCMediaConstraints::Create(); webrtc::PeerConnectionInterface::RTCOfferAnswerOptions offer_answer_options_; RTCPeerConnectionObserver* observer_ = nullptr; std::unique_ptr callback_crt_sec_; diff --git a/src/rtc_rtp_capabilities_impl.cc b/src/rtc_rtp_capabilities_impl.cc index ce502f609d..a912efc46f 100644 --- a/src/rtc_rtp_capabilities_impl.cc +++ b/src/rtc_rtp_capabilities_impl.cc @@ -51,7 +51,7 @@ RTCRtpCapabilitiesImpl::codecs() { void RTCRtpCapabilitiesImpl::set_codecs( vector> codecs) { rtp_capabilities_.codecs.clear(); - for (auto& codec : codecs.std_vector()) { + for (auto& codec : to_std_vector(codecs)) { auto impl = static_cast(codec.get()); rtp_capabilities_.codecs.push_back(impl->rtp_codec_capability()); } @@ -71,7 +71,7 @@ RTCRtpCapabilitiesImpl::header_extensions() { void RTCRtpCapabilitiesImpl::set_header_extensions( vector> header_extensions) { rtp_capabilities_.header_extensions.clear(); - for (auto& header_extension : header_extensions.std_vector()) { + for (auto& header_extension : to_std_vector(header_extensions)) { auto impl = static_cast( header_extension.get()); rtp_capabilities_.header_extensions.push_back( @@ -92,7 +92,7 @@ string RTCRtpCodecCapabilityImpl::mime_type() const { } void RTCRtpCodecCapabilityImpl::set_mime_type(const string& mime_type) { - std::vector mime_type_split = split(mime_type.std_string(), "/"); + std::vector mime_type_split = split(to_std_string(mime_type), "/"); rtp_codec_capability_.name = mime_type_split[1]; cricket::MediaType kind = cricket::MEDIA_TYPE_AUDIO; if (mime_type_split[0] == "audio") { @@ -134,7 +134,7 @@ string RTCRtpCodecCapabilityImpl::sdp_fmtp_line() const { } void RTCRtpCodecCapabilityImpl::set_sdp_fmtp_line(const string& sdp_fmtp_line) { - std::vector parameters = split(sdp_fmtp_line.std_string(), ";"); + std::vector parameters = split(to_std_string(sdp_fmtp_line), ";"); for (auto parameter : parameters) { if (parameter.find("=") != std::string::npos) { std::vector parameter_split = split(parameter, "="); @@ -158,7 +158,7 @@ const string RTCRtpHeaderExtensionCapabilityImpl::uri() { } void RTCRtpHeaderExtensionCapabilityImpl::set_uri(const string uri) { - rtp_header_extension_capability_.uri = uri.c_string(); + rtp_header_extension_capability_.uri = uri.c_str(); } webrtc::RtpHeaderExtensionCapability diff --git a/src/rtc_rtp_parameters_impl.cc b/src/rtc_rtp_parameters_impl.cc index ac4aec8a25..f56555d533 100644 --- a/src/rtc_rtp_parameters_impl.cc +++ b/src/rtc_rtp_parameters_impl.cc @@ -160,7 +160,7 @@ RTCRtpParametersImpl::codecs() { void RTCRtpParametersImpl::set_codecs( const vector> codecs) { std::vector list; - for (auto item : codecs.std_vector()) { + for (auto item : to_std_vector(codecs)) { auto impl = static_cast(item.get()); list.push_back(impl->rtp_codec_parameters()); } @@ -179,7 +179,7 @@ RTCRtpParametersImpl::header_extensions() { void RTCRtpParametersImpl::set_header_extensions( vector> header_extensions) { std::vector list; - for (auto item : header_extensions.std_vector()) { + for (auto item : to_std_vector(header_extensions)) { auto impl = static_cast(item.get()); list.push_back(impl->rtp_extension()); } @@ -198,7 +198,7 @@ RTCRtpParametersImpl::encodings() { void RTCRtpParametersImpl::set_encodings( vector> encodings) { std::vector list; - for (auto item : encodings.std_vector()) { + for (auto item : to_std_vector(encodings)) { auto impl = static_cast(item.get()); list.push_back(impl->rtp_parameters()); } @@ -413,7 +413,7 @@ RTCRtpCodecParametersImpl::rtcp_feedback() { void RTCRtpCodecParametersImpl::set_rtcp_feedback( const vector> rtcp_feedbacks) { std::vector rtcp_feedback; - for (scoped_refptr item : rtcp_feedbacks.std_vector()) { + for (scoped_refptr item : to_std_vector(rtcp_feedbacks)) { auto impl = static_cast(item.get()); rtcp_feedback.push_back(impl->rtcp_feedback()); } diff --git a/src/rtc_rtp_sender_impl.cc b/src/rtc_rtp_sender_impl.cc index 5785b9c370..1744697d9d 100644 --- a/src/rtc_rtp_sender_impl.cc +++ b/src/rtc_rtp_sender_impl.cc @@ -16,11 +16,11 @@ bool RTCRtpSenderImpl::set_track(scoped_refptr track) { return rtp_sender_->SetTrack(nullptr); } if (std::string(webrtc::MediaStreamTrackInterface::kVideoKind) == - track->kind().std_string()) { + to_std_string(track->kind())) { VideoTrackImpl* impl = static_cast(track.get()); return rtp_sender_->SetTrack(impl->rtc_track().get()); } else if (std::string(webrtc::MediaStreamTrackInterface::kAudioKind) == - track->kind().std_string()) { + to_std_string(track->kind())) { AudioTrackImpl* impl = static_cast(track.get()); return rtp_sender_->SetTrack(impl->rtc_track().get()); } @@ -74,7 +74,7 @@ const vector RTCRtpSenderImpl::stream_ids() const { void RTCRtpSenderImpl::set_stream_ids(const vector stream_ids) const { std::vector list; - for (auto id : stream_ids.std_vector()) { + for (auto id : to_std_vector(stream_ids)) { list.push_back(to_std_string(id)); } rtp_sender_->SetStreams(list); diff --git a/src/rtc_rtp_transceiver_impl.cc b/src/rtc_rtp_transceiver_impl.cc index 301d78691f..89a84ea3fc 100644 --- a/src/rtc_rtp_transceiver_impl.cc +++ b/src/rtc_rtp_transceiver_impl.cc @@ -9,10 +9,10 @@ namespace libwebrtc { -LIB_WEBRTC_API scoped_refptr +scoped_refptr RTCRtpTransceiverInit::Create( - RTCRtpTransceiverDirection direction, const vector stream_ids, - const vector> encodings) { + RTCRtpTransceiverDirection direction, const vector stream_ids, + const vector> encodings) { auto init = new RefCountedObject(); init->set_direction(direction); init->set_stream_ids(stream_ids); @@ -43,7 +43,7 @@ const vector RTCRtpTransceiverInitImpl::stream_ids() { void RTCRtpTransceiverInitImpl::set_stream_ids(const vector ids) { std::vector list; - for (auto id : ids.std_vector()) { + for (auto id : to_std_vector(ids)) { list.push_back(to_std_string(id)); } rtp_transceiver_init_.stream_ids = list; @@ -61,7 +61,7 @@ RTCRtpTransceiverInitImpl::send_encodings() { void RTCRtpTransceiverInitImpl::set_send_encodings( const vector> send_encodings) { std::vector list; - for (auto param : send_encodings.std_vector()) { + for (auto param : to_std_vector(send_encodings)) { auto impl = static_cast(param.get()); list.push_back(impl->rtp_parameters()); } @@ -153,7 +153,7 @@ RTCMediaType RTCRtpTransceiverImpl::media_type() const { void RTCRtpTransceiverImpl::SetCodecPreferences( vector> codecs) { std::vector list; - for (auto codec : codecs.std_vector()) { + for (auto codec : to_std_vector(codecs)) { auto impl = static_cast(codec.get()); list.push_back(impl->rtp_codec_capability()); } diff --git a/swig/Makefile b/swig/Makefile new file mode 100644 index 0000000000..3b45e58e53 --- /dev/null +++ b/swig/Makefile @@ -0,0 +1,5 @@ +all: + g++ -O2 -fPIC -c libwebrtc_wrap.cxx -I/opt/homebrew/opt/python@3.12/Frameworks/Python.framework/Versions/3.12/include/python3.12 -I. -std=c++17 + g++ -shared libwebrtc_wrap.o -o _libwebrtc.so -L/opt/homebrew/opt/python@3.12/Frameworks/Python.framework/Versions/3.12/lib -lpython3.12 -L. -lwebrtc +swig: + swig -c++ -python libwebrtc.i \ No newline at end of file diff --git a/swig/libwebrtc.i b/swig/libwebrtc.i new file mode 100644 index 0000000000..3e978d2026 --- /dev/null +++ b/swig/libwebrtc.i @@ -0,0 +1,82 @@ +/* libwebrtc.i */ +%module libwebrtc + +%include +%include + +%{ + #include "../include/base/atomicops.h" + #include "../include/base/refcount.h" + #include "../include/base/refcountedobject.h" + #include "../include/base/scoped_ref_ptr.h" + + #include "../include/rtc_media_track.h" + #include "../include/rtc_audio_frame.h" + #include "../include/rtc_audio_source.h" + #include "../include/rtc_audio_track.h" + #include "../include/rtc_data_channel.h" + #include "../include/rtc_dtmf_sender.h" + #include "../include/rtc_dtls_transport.h" + #include "../include/rtc_frame_cryptor.h" + #include "../include/rtc_media_stream.h" + #include "../include/rtc_ice_candidate.h" + #include "../include/rtc_mediaconstraints.h" + #include "../include/rtc_peerconnection_factory.h" + #include "../include/rtc_peerconnection.h" + #include "../include/rtc_rtp_capabilities.h" + #include "../include/rtc_rtp_parameters.h" + #include "../include/rtc_rtp_receiver.h" + #include "../include/rtc_rtp_sender.h" + #include "../include/rtc_rtp_transceiver.h" + #include "../include/rtc_session_description.h" + #include "../include/rtc_types.h" + #include "../include/rtc_video_frame.h" + #include "../include/rtc_video_renderer.h" + #include "../include/rtc_video_source.h" + #include "../include/rtc_video_track.h" + #include "../include/libwebrtc.h" + #include "../include/helper.h" +%} + +%include ../include/base/atomicops.h +%include ../include/base/refcount.h +%include ../include/base/refcountedobject.h +%include ../include/base/scoped_ref_ptr.h +%include ../include/rtc_config.h +%include ../include/rtc_types.h +%include ../include/rtc_media_track.h +%include ../include/rtc_audio_frame.h +%include ../include/rtc_audio_source.h +%include ../include/rtc_audio_track.h +%include ../include/rtc_data_channel.h +%include ../include/rtc_dtmf_sender.h +%include ../include/rtc_dtls_transport.h +%include ../include/rtc_video_frame.h +%include ../include/rtc_video_renderer.h +%include ../include/rtc_video_source.h +%include ../include/rtc_video_track.h +%include ../include/rtc_media_stream.h +%include ../include/rtc_rtp_capabilities.h +%include ../include/rtc_rtp_parameters.h +%include ../include/rtc_rtp_receiver.h +%include ../include/rtc_rtp_sender.h +%include ../include/rtc_rtp_transceiver.h +%include ../include/rtc_session_description.h +%include ../include/rtc_ice_candidate.h +%include ../include/rtc_mediaconstraints.h +%include ../include/rtc_peerconnection.h +%include ../include/rtc_peerconnection_factory.h +%include ../include/rtc_frame_cryptor.h +%include ../include/libwebrtc.h +%include ../include/helper.h + +%inline %{ + using namespace libwebrtc; + RTCPeerConnectionFactory* factoryFromPtr(scoped_refptr ptr) { + return ptr.get(); + } + + RTCMediaConstraints* constraintsFromPtr(scoped_refptr ptr) { + return ptr.get(); + } +%} \ No newline at end of file diff --git a/swig/rtc_test.py b/swig/rtc_test.py new file mode 100644 index 0000000000..f4886f3a82 --- /dev/null +++ b/swig/rtc_test.py @@ -0,0 +1,46 @@ + +from libwebrtc import * +import sys + +ret = LibWebRTC.Initialize() + +print(ret) + +ptr = LibWebRTC.CreateRTCPeerConnectionFactory() + +pcFactory = factoryFromPtr(ptr) + +ret = pcFactory.Initialize() + +print(ret) + +cfg = RTCConfiguration() +cfg.sdp_semantics = SdpSemantics_kUnifiedPlan +cfg.bundle_policy = kBundlePolicyBalanced +cfg.rtcp_mux_policy = RtcpMuxPolicy_kRtcpMuxPolicyNegotiate +cfg.ice_candidate_pool_size = 1 +cfg.disable_ipv6 = False +cfg.disable_ipv6_on_wifi = False +cfg.disable_link_local_networks = False +cfg.max_ipv6_networks = 5 +cfg.srtp_type = MediaSecurityType_kDTLS_SRTP +cfg.screencast_min_bitrate = 0 +cfg.use_rtp_mux = True +cfg.tcp_candidate_policy = TcpCandidatePolicy_kTcpCandidatePolicyDisabled + +constraintsPtr = RTCMediaConstraints.Create() + +constraints = constraintsFromPtr(constraintsPtr) + +constraints.AddMandatoryConstraint("OfferToReceiveAudio", "true") +constraints.AddMandatoryConstraint("OfferToReceiveVideo", "true") + +#pc = pcFactory.Create(None, constraintsPtr) + +for line in sys.stdin: + if 'q' == line.rstrip(): + break + print(f'Input : {line}') + +constraintsPtr.disown() +ptr.disown() \ No newline at end of file