Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/support dummy io #102

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 41 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 @@ -34,16 +36,27 @@ config("external_config") {

rtc_shared_library("libwebrtc") {
libs = []
visibility = [
"//:default",
]
#complete_static_lib = true
#suppressed_configs += [ "//build/config/compiler:thin_archive" ]
include_dirs = [
".",
"include",
]

defines = [
"USE_LIBYUV",
"WEBRTC_INCLUDE_INTERNAL_AUDIO_DEVICE",
"SHARED_BUILD",
#"USE_PORTABLE_TYPES",
]

if(!libwebrtc_dummy_audio_device) {
defines += [ "RTC_AUDIO_DEVICE" ]
defines += [ "WEBRTC_INCLUDE_INTERNAL_AUDIO_DEVICE" ]
}

if (is_win) {
defines += [
"LIB_WEBRTC_API_EXPORTS",
Expand All @@ -69,6 +82,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 +102,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 +148,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 +158,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 +266,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
22 changes: 6 additions & 16 deletions include/base/portable.h
Original file line number Diff line number Diff line change
@@ -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 <cstdlib>
#include <cstring>
Expand Down Expand Up @@ -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)); }

Expand All @@ -63,7 +55,7 @@ class string {
return *this;
}

LIB_PORTABLE_API ~string();
LIB_WEBRTC_API ~string();

inline string& operator=(const std::string& str) {
destroy();
Expand All @@ -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;
}

Expand All @@ -82,8 +74,6 @@ class string {
}
};

inline std::string to_std_string(const string& str) { return str.std_string(); }

template <typename T>
class identity {
T operator()(const T& x) { return x; }
Expand Down
2 changes: 1 addition & 1 deletion include/rtc_audio_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace libwebrtc {
*/
class RTCAudioDevice : public RefCountInterface {
public:
typedef fixed_size_function<void()> OnDeviceChangeCallback;
typedef callback_function_t<void()> OnDeviceChangeCallback;

public:
static const int kAdmMaxDeviceNameSize = 128;
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
22 changes: 22 additions & 0 deletions include/rtc_config.h
Original file line number Diff line number Diff line change
@@ -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_
Loading