Skip to content

Commit e4c9cb2

Browse files
committed
Add dummy I/O support.
1 parent a4f337d commit e4c9cb2

19 files changed

+861
-113
lines changed

BUILD.gn

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ import("../webrtc.gni")
22

33
declare_args() {
44
libwebrtc_intel_media_sdk = false
5-
libwebrtc_desktop_capture = true
5+
libwebrtc_desktop_capture = false
6+
libwebrtc_video_capture = false
7+
libwebrtc_dummy_audio_device = true
68
}
79

810
if (is_android) {
@@ -41,9 +43,14 @@ rtc_shared_library("libwebrtc") {
4143

4244
defines = [
4345
"USE_LIBYUV",
44-
"WEBRTC_INCLUDE_INTERNAL_AUDIO_DEVICE",
4546
]
4647

48+
if(libwebrtc_dummy_audio_device) {
49+
defines += [ "LIB_WEBRTC_USE_DUMMY_AUDIO_DEVICE" ]
50+
} else {
51+
defines += [ "WEBRTC_INCLUDE_INTERNAL_AUDIO_DEVICE" ]
52+
}
53+
4754
if (is_win) {
4855
defines += [
4956
"LIB_WEBRTC_API_EXPORTS",
@@ -69,6 +76,7 @@ rtc_shared_library("libwebrtc") {
6976
"include/base/scoped_ref_ptr.h",
7077
"include/libwebrtc.h",
7178
"include/rtc_audio_device.h",
79+
"include/rtc_audio_frame.h",
7280
"include/rtc_audio_source.h",
7381
"include/rtc_audio_track.h",
7482
"include/rtc_data_channel.h",
@@ -88,21 +96,18 @@ rtc_shared_library("libwebrtc") {
8896
"include/rtc_rtp_transceiver.h",
8997
"include/rtc_session_description.h",
9098
"include/rtc_types.h",
91-
"include/rtc_video_device.h",
9299
"include/rtc_video_frame.h",
93100
"include/rtc_video_renderer.h",
94101
"include/rtc_video_source.h",
95102
"include/rtc_video_track.h",
96103
"include/helper.h",
97104
"src/helper.cc",
98105
"src/base/portable.cc",
99-
"src/internal/vcm_capturer.cc",
100-
"src/internal/vcm_capturer.h",
101-
"src/internal/video_capturer.cc",
102-
"src/internal/video_capturer.h",
103106
"src/libwebrtc.cc",
104107
"src/rtc_audio_device_impl.cc",
105108
"src/rtc_audio_device_impl.h",
109+
"src/rtc_audio_frame_impl.cc",
110+
"src/rtc_audio_frame_impl.h",
106111
"src/rtc_audio_source_impl.cc",
107112
"src/rtc_audio_source_impl.h",
108113
"src/rtc_audio_track_impl.cc",
@@ -137,8 +142,6 @@ rtc_shared_library("libwebrtc") {
137142
"src/rtc_rtp_transceiver_impl.h",
138143
"src/rtc_session_description_impl.cc",
139144
"src/rtc_session_description_impl.h",
140-
"src/rtc_video_device_impl.cc",
141-
"src/rtc_video_device_impl.h",
142145
"src/rtc_video_frame_impl.cc",
143146
"src/rtc_video_frame_impl.h",
144147
"src/rtc_video_sink_adapter.cc",
@@ -149,6 +152,28 @@ rtc_shared_library("libwebrtc") {
149152
"src/rtc_video_track_impl.h",
150153
]
151154

155+
if(libwebrtc_dummy_audio_device) {
156+
sources += [
157+
"src/audio_device_dummy.cc",
158+
"src/audio_device_dummy.h",
159+
]
160+
}
161+
162+
163+
# video capture device
164+
if (libwebrtc_video_capture) {
165+
defines += [ "RTC_VIDEO_CAPTURE_DEVICE" ]
166+
sources += [
167+
"include/rtc_video_capturer.h",
168+
"src/internal/video_capturer.h",
169+
"src/internal/video_capturer.cc",
170+
"src/internal/vcm_capturer.cc",
171+
"src/internal/vcm_capturer.h",
172+
"src/rtc_video_device_impl.cc",
173+
"src/rtc_video_device_impl.h",
174+
]
175+
}
176+
152177
# intel media sdk
153178
if (is_win && libwebrtc_intel_media_sdk) {
154179
sources += [
@@ -235,7 +260,7 @@ rtc_shared_library("libwebrtc") {
235260

236261
# screen capture device
237262
if (libwebrtc_desktop_capture) {
238-
defines += [ "RTC_DESKTOP_DEVICE" ]
263+
defines += [ "RTC_DESKTOP_CAPTURE_DEVICE" ]
239264
sources += [
240265
"include/rtc_desktop_capturer.h",
241266
"include/rtc_desktop_device.h",

include/rtc_audio_frame.h

Lines changed: 13 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -1,108 +1,40 @@
1-
#ifndef AUDIO_FRAME_HXX
2-
#define AUDIO_FRAME_HXX
1+
#ifndef LIB_WEBRTC_RTC_AUDIO_FRAME_HXX
2+
#define LIB_WEBRTC_RTC_AUDIO_FRAME_HXX
33

4-
#include "media_manager_types.h"
4+
#include "rtc_types.h"
55

6-
namespace b2bua {
6+
namespace libwebrtc {
77

8-
class AudioFrame {
8+
class RTCAudioFrame : public RefCountInterface {
99
public:
10-
/**
11-
* @brief Creates a new instance of AudioFrame.
12-
* @return AudioFrame*: a pointer to the newly created AudioFrame.
13-
*/
14-
MEDIA_MANAGER_API static AudioFrame* Create();
10+
LIB_WEBRTC_API static scoped_refptr<RTCAudioFrame> Create();
1511

16-
/**
17-
* @brief Creates a new instance of AudioFrame with specified parameters.
18-
* @param id: the unique identifier of the frame.
19-
* @param timestamp: the timestamp of the frame.
20-
* @param data: a pointer to the audio data buffer.
21-
* @param samples_per_channel: the number of samples per channel.
22-
* @param sample_rate_hz: the sample rate in Hz.
23-
* @param num_channels: the number of audio channels.
24-
* @return AudioFrame*: a pointer to the newly created AudioFrame.
25-
*/
26-
MEDIA_MANAGER_API static AudioFrame* Create(int id, uint32_t timestamp,
27-
const int16_t* data,
28-
size_t samples_per_channel,
29-
int sample_rate_hz,
30-
size_t num_channels = 1);
31-
32-
/**
33-
* @brief Releases the memory of this AudioFrame.
34-
*/
35-
virtual void Release() = 0;
12+
LIB_WEBRTC_API static scoped_refptr<RTCAudioFrame> Create(
13+
uint32_t timestamp, const int16_t* data, size_t samples_per_channel,
14+
int sample_rate_hz, size_t num_channels = 1);
3615

3716
public:
38-
/**
39-
* @brief Updates the audio frame with specified parameters.
40-
* @param id: the unique identifier of the frame.
41-
* @param timestamp: the timestamp of the frame.
42-
* @param data: a pointer to the audio data buffer.
43-
* @param samples_per_channel: the number of samples per channel.
44-
* @param sample_rate_hz: the sample rate in Hz.
45-
* @param num_channels: the number of audio channels.
46-
*/
47-
virtual void UpdateFrame(int id, uint32_t timestamp, const int16_t* data,
17+
virtual void UpdateFrame(uint32_t timestamp, const int16_t* data,
4818
size_t samples_per_channel, int sample_rate_hz,
4919
size_t num_channels = 1) = 0;
5020

51-
/**
52-
* @brief Copies the contents of another AudioFrame.
53-
* @param src: the source AudioFrame to copy from.
54-
*/
55-
virtual void CopyFrom(const AudioFrame& src) = 0;
21+
virtual void CopyFrom(const scoped_refptr<RTCAudioFrame> src) = 0;
5622

57-
/**
58-
* @brief Adds another AudioFrame to this one.
59-
* @param frame_to_add: the AudioFrame to add.
60-
*/
61-
virtual void Add(const AudioFrame& frame_to_add) = 0;
23+
virtual void Add(const scoped_refptr<RTCAudioFrame> frame_to_add) = 0;
6224

63-
/**
64-
* @brief Mutes the audio data in this AudioFrame.
65-
*/
6625
virtual void Mute() = 0;
6726

68-
/**
69-
* @brief Returns a pointer to the audio data buffer.
70-
* @return const int16_t*: a pointer to the audio data buffer.
71-
*/
7227
virtual const int16_t* data() = 0;
7328

74-
/**
75-
* @brief Returns the number of samples per channel.
76-
* @return size_t: the number of samples per channel.
77-
*/
7829
virtual size_t samples_per_channel() = 0;
7930

80-
/**
81-
* @brief Returns the sample rate in Hz.
82-
* @return int: the sample rate in Hz.
83-
*/
8431
virtual int sample_rate_hz() = 0;
8532

86-
/**
87-
* @brief Returns the number of audio channels.
88-
* @return size_t: the number of audio channels.
89-
*/
9033
virtual size_t num_channels() = 0;
9134

92-
/**
93-
* @brief Returns the timestamp of the AudioFrame.
94-
* @return uint32_t: the timestamp of the AudioFrame.
95-
*/
9635
virtual uint32_t timestamp() = 0;
97-
98-
/**
99-
* @brief Returns the unique identifier of the AudioFrame.
100-
* @return int: the unique identifier of the AudioFrame.
101-
*/
102-
103-
virtual int id() = 0;
10436
};
10537

106-
}; // namespace b2bua
38+
} // namespace libwebrtc
10739

10840
#endif

include/rtc_audio_source.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#define LIB_WEBRTC_RTC_AUDIO_SOURCE_HXX
33

44
#include "rtc_types.h"
5+
#include "rtc_audio_frame.h"
56

67
namespace libwebrtc {
78

@@ -20,6 +21,21 @@ class RTCAudioSource : public RefCountInterface {
2021
virtual ~RTCAudioSource() {}
2122
};
2223

24+
class VirtualAudioCapturer : public RefCountInterface {
25+
public:
26+
LIB_WEBRTC_API static scoped_refptr<VirtualAudioCapturer> Create();
27+
28+
virtual void OnFrame(scoped_refptr<RTCAudioFrame> data) = 0;
29+
30+
virtual void OnData(const void* audio_data,
31+
int bits_per_sample,
32+
int sample_rate,
33+
size_t number_of_channels,
34+
size_t number_of_frames) = 0;
35+
36+
virtual scoped_refptr<RTCAudioSource> source() = 0;
37+
};
38+
2339
} // namespace libwebrtc
2440

2541
#endif // LIB_WEBRTC_RTC_AUDIO_TRACK_HXX

include/rtc_audio_track.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,24 @@
11
#ifndef LIB_WEBRTC_RTC_AUDIO_TRACK_HXX
22
#define LIB_WEBRTC_RTC_AUDIO_TRACK_HXX
33

4+
#include "rtc_audio_frame.h"
45
#include "rtc_media_track.h"
56
#include "rtc_types.h"
67

78
namespace libwebrtc {
89

10+
template <typename AudioFrameT>
11+
class RTCAudioRenderer {
12+
public:
13+
virtual void OnFrame(AudioFrameT frame) = 0;
14+
15+
virtual void OnData(const void* audio_data, int bits_per_sample,
16+
int sample_rate, size_t number_of_channels,
17+
size_t number_of_frames) = 0;
18+
protected:
19+
virtual ~RTCAudioRenderer() {}
20+
};
21+
922
/**
1023
* The RTCAudioTrack class represents an audio track in WebRTC.
1124
* Audio tracks are used to transmit audio data over a WebRTC peer connection.
@@ -17,6 +30,12 @@ class RTCAudioTrack : public RTCMediaTrack {
1730
// volume in [0-10]
1831
virtual void SetVolume(double volume) = 0;
1932

33+
virtual void AddAudioSink(
34+
RTCAudioRenderer<scoped_refptr<RTCAudioFrame>>* sink) = 0;
35+
36+
virtual void RemoveAudioSink(
37+
RTCAudioRenderer<scoped_refptr<RTCAudioFrame>>* sink) = 0;
38+
2039
protected:
2140
/**
2241
* The destructor for the RTCAudioTrack class.

include/rtc_desktop_device.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#ifndef LIB_WEBRTC_RTC_DESKTOP_DEVICE_HXX
2-
#define LIB_WEBRTC_RTC_DESKTOP_DEVICE_HXX
1+
#ifndef LIB_WEBRTC_RTC_DESKTOP_CAPTURE_DEVICE_HXX
2+
#define LIB_WEBRTC_RTC_DESKTOP_CAPTURE_DEVICE_HXX
33

44
#include "rtc_types.h"
55

include/rtc_peerconnection_factory.h

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#include "rtc_audio_source.h"
55
#include "rtc_audio_track.h"
66
#include "rtc_types.h"
7-
#ifdef RTC_DESKTOP_DEVICE
7+
#ifdef RTC_DESKTOP_CAPTURE_DEVICE
88
#include "rtc_desktop_device.h"
99
#endif
1010
#include "rtc_media_stream.h"
@@ -31,24 +31,28 @@ class RTCPeerConnectionFactory : public RefCountInterface {
3131

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

34+
#if !defined(LIB_WEBRTC_USE_DUMMY_AUDIO_DEVICE)
3435
virtual scoped_refptr<RTCAudioDevice> GetAudioDevice() = 0;
35-
36-
virtual scoped_refptr<RTCVideoDevice> GetVideoDevice() = 0;
37-
#ifdef RTC_DESKTOP_DEVICE
38-
virtual scoped_refptr<RTCDesktopDevice> GetDesktopDevice() = 0;
3936
#endif
40-
virtual scoped_refptr<RTCAudioSource> CreateAudioSource(
41-
const string audio_source_label) = 0;
4237

38+
#ifdef RTC_VIDEO_CAPTURE_DEVICE
39+
virtual scoped_refptr<RTCVideoDevice> GetVideoDevice() = 0;
4340
virtual scoped_refptr<RTCVideoSource> CreateVideoSource(
4441
scoped_refptr<RTCVideoCapturer> capturer, const string video_source_label,
4542
scoped_refptr<RTCMediaConstraints> constraints) = 0;
46-
#ifdef RTC_DESKTOP_DEVICE
43+
#endif
44+
45+
#ifdef RTC_DESKTOP_CAPTURE_DEVICE
46+
virtual scoped_refptr<RTCDesktopDevice> GetDesktopDevice() = 0;
4747
virtual scoped_refptr<RTCVideoSource> CreateDesktopSource(
4848
scoped_refptr<RTCDesktopCapturer> capturer,
4949
const string video_source_label,
5050
scoped_refptr<RTCMediaConstraints> constraints) = 0;
5151
#endif
52+
53+
virtual scoped_refptr<RTCAudioSource> CreateAudioSource(
54+
const string audio_source_label) = 0;
55+
5256
virtual scoped_refptr<RTCAudioTrack> CreateAudioTrack(
5357
scoped_refptr<RTCAudioSource> source, const string track_id) = 0;
5458

include/rtc_video_source.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,24 @@
22
#define LIB_WEBRTC_RTC_VIDEO_SOURCE_HXX
33

44
#include "rtc_types.h"
5+
#include "rtc_video_frame.h"
56

67
namespace libwebrtc {
78

89
class RTCVideoSource : public RefCountInterface {
910
public:
1011
~RTCVideoSource() {}
1112
};
13+
14+
class VirtualVideoCapturer : public RefCountInterface {
15+
public:
16+
LIB_WEBRTC_API static scoped_refptr<VirtualVideoCapturer> Create();
17+
18+
virtual void OnFrameCaptured(scoped_refptr<RTCVideoFrame> frame) = 0;
19+
20+
virtual scoped_refptr<RTCVideoSource> source() = 0;
21+
};
22+
1223
} // namespace libwebrtc
1324

1425
#endif // LIB_WEBRTC_RTC_VIDEO_SOURCE_HXX

0 commit comments

Comments
 (0)