Skip to content

Commit

Permalink
Add dummy I/O support.
Browse files Browse the repository at this point in the history
  • Loading branch information
cloudwebrtc committed Aug 16, 2024
1 parent a4f337d commit e4c9cb2
Show file tree
Hide file tree
Showing 19 changed files with 861 additions and 113 deletions.
45 changes: 35 additions & 10 deletions BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -88,21 +96,18 @@ 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",
"include/rtc_video_track.h",
"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",
Expand Down Expand Up @@ -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",
Expand All @@ -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 += [
Expand Down Expand Up @@ -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",
Expand Down
94 changes: 13 additions & 81 deletions include/rtc_audio_frame.h
Original file line number Diff line number Diff line change
@@ -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<RTCAudioFrame> 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<RTCAudioFrame> 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<RTCAudioFrame> 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<RTCAudioFrame> 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
16 changes: 16 additions & 0 deletions include/rtc_audio_source.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define LIB_WEBRTC_RTC_AUDIO_SOURCE_HXX

#include "rtc_types.h"
#include "rtc_audio_frame.h"

namespace libwebrtc {

Expand All @@ -20,6 +21,21 @@ class RTCAudioSource : public RefCountInterface {
virtual ~RTCAudioSource() {}
};

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

virtual void OnFrame(scoped_refptr<RTCAudioFrame> 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<RTCAudioSource> source() = 0;
};

} // namespace libwebrtc

#endif // LIB_WEBRTC_RTC_AUDIO_TRACK_HXX
19 changes: 19 additions & 0 deletions include/rtc_audio_track.h
Original file line number Diff line number Diff line change
@@ -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 <typename AudioFrameT>
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.
Expand All @@ -17,6 +30,12 @@ class RTCAudioTrack : public RTCMediaTrack {
// volume in [0-10]
virtual void SetVolume(double volume) = 0;

virtual void AddAudioSink(
RTCAudioRenderer<scoped_refptr<RTCAudioFrame>>* sink) = 0;

virtual void RemoveAudioSink(
RTCAudioRenderer<scoped_refptr<RTCAudioFrame>>* sink) = 0;

protected:
/**
* The destructor for the RTCAudioTrack class.
Expand Down
4 changes: 2 additions & 2 deletions include/rtc_desktop_device.h
Original file line number Diff line number Diff line change
@@ -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"

Expand Down
20 changes: 12 additions & 8 deletions include/rtc_peerconnection_factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -31,24 +31,28 @@ class RTCPeerConnectionFactory : public RefCountInterface {

virtual void Delete(scoped_refptr<RTCPeerConnection> peerconnection) = 0;

#if !defined(LIB_WEBRTC_USE_DUMMY_AUDIO_DEVICE)
virtual scoped_refptr<RTCAudioDevice> GetAudioDevice() = 0;

virtual scoped_refptr<RTCVideoDevice> GetVideoDevice() = 0;
#ifdef RTC_DESKTOP_DEVICE
virtual scoped_refptr<RTCDesktopDevice> GetDesktopDevice() = 0;
#endif
virtual scoped_refptr<RTCAudioSource> CreateAudioSource(
const string audio_source_label) = 0;

#ifdef RTC_VIDEO_CAPTURE_DEVICE
virtual scoped_refptr<RTCVideoDevice> GetVideoDevice() = 0;
virtual scoped_refptr<RTCVideoSource> CreateVideoSource(
scoped_refptr<RTCVideoCapturer> capturer, const string video_source_label,
scoped_refptr<RTCMediaConstraints> constraints) = 0;
#ifdef RTC_DESKTOP_DEVICE
#endif

#ifdef RTC_DESKTOP_CAPTURE_DEVICE
virtual scoped_refptr<RTCDesktopDevice> GetDesktopDevice() = 0;
virtual scoped_refptr<RTCVideoSource> CreateDesktopSource(
scoped_refptr<RTCDesktopCapturer> capturer,
const string video_source_label,
scoped_refptr<RTCMediaConstraints> constraints) = 0;
#endif

virtual scoped_refptr<RTCAudioSource> CreateAudioSource(
const string audio_source_label) = 0;

virtual scoped_refptr<RTCAudioTrack> CreateAudioTrack(
scoped_refptr<RTCAudioSource> source, const string track_id) = 0;

Expand Down
11 changes: 11 additions & 0 deletions include/rtc_video_source.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,24 @@
#define LIB_WEBRTC_RTC_VIDEO_SOURCE_HXX

#include "rtc_types.h"
#include "rtc_video_frame.h"

namespace libwebrtc {

class RTCVideoSource : public RefCountInterface {
public:
~RTCVideoSource() {}
};

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

virtual void OnFrameCaptured(scoped_refptr<RTCVideoFrame> frame) = 0;

virtual scoped_refptr<RTCVideoSource> source() = 0;
};

} // namespace libwebrtc

#endif // LIB_WEBRTC_RTC_VIDEO_SOURCE_HXX
Loading

0 comments on commit e4c9cb2

Please sign in to comment.