问题描述
到目前为止,我已经成功运行了以下示例:
I have so far managed to run the following sample:
该示例显示了如何将视频从本机C ++应用程序(peerconnection_client.exe)流到浏览器(我正在使用Chrome).效果很好,我可以在浏览器中看到自己.
The sample shows how to stream video from a native C++ application (peerconnection_client.exe) to the browser (I am using Chrome). This works fine and I can see myself in the browser.
我想做的是将音频从浏览器流式传输到本机应用程序,但是我不确定该如何做.有人可以给我一些指示吗?
What I would like to do is to stream audio from the browser to the native application but I am not sure how. Can anyone give me some pointers please?
推荐答案
我正在尝试找到一种方法,可将视频和音频从浏览器流式传输到本机程序.到目前为止,这就是我的路.
I'm trying to find a way to stream both video and audio from browser to my native program. and here is my way so far.
要将视频从浏览器流传输到不带GUI的本机程序,请按照此处的示例进行操作. https://chromium.googlesource.com/external/webrtc/+/refs/heads/master/examples/peerconnection/client/
To stream video from browser to your native program without gui, just follow the example here. https://chromium.googlesource.com/external/webrtc/+/refs/heads/master/examples/peerconnection/client/
使用AddOrUpdateSink
添加您自己的VideoSinkInterface
,您将在回调void OnFrame(const cricket::VideoFrame& frame)
中接收帧数据.除了可以像示例一样将框架呈现为GUI之外,您还可以做任何您想做的事情.
use AddOrUpdateSink
to add your own VideoSinkInterface
and you will receive your frame data in callback void OnFrame(const cricket::VideoFrame& frame)
. Instead of render the frame to GUI as the example does, you can do whatever you want.
在没有真正音频设备的情况下将音频从浏览器流式传输到您的本机程序.您可以使用假冒的音频设备.
To stream audio from browser to your native program without real audio device. you can use a fake audio device.
- 将文件rtc_use_dummy_audio_file_devices修改为
true
" rel ="nofollow noreferrer > https://chromium.googlesource.com/external/webrtc/+/master/webrtc/build/webrtc.gni - 调用全局静态函数以指定文件名
webrtc::FileAudioDeviceFactory::SetFilenamesToUse("", "file_to_save_audio");
- 使用代码自爆修补
file_audio_device.cc
. (在我编写此答案时,FileAudioDevice存在一些问题,可能已经修复) - 重新编译程序
touch file_to_save_audio
,在建立webrtc连接后,您将在file_to_save_audio
中看到pcm数据.
- modify variable
rtc_use_dummy_audio_file_devices
totrue
in file https://chromium.googlesource.com/external/webrtc/+/master/webrtc/build/webrtc.gni - invoke the global static function to specify the filename
webrtc::FileAudioDeviceFactory::SetFilenamesToUse("", "file_to_save_audio");
- patch
file_audio_device.cc
with the code blew. (as I write this answer, FileAudioDevice has some issues, may already be fixed) - recompile your program,
touch file_to_save_audio
and you will see pcm data infile_to_save_audio
after webrtc connection is established.
补丁:
diff --git a/webrtc/modules/audio_device/dummy/file_audio_device.cc b/webrtc/modules/audio_device/dummy/file_audio_device.cc
index 8b3fa5e..2717cda 100644
--- a/webrtc/modules/audio_device/dummy/file_audio_device.cc
+++ b/webrtc/modules/audio_device/dummy/file_audio_device.cc
@@ -35,6 +35,7 @@ FileAudioDevice::FileAudioDevice(const int32_t id,
_recordingBufferSizeIn10MS(0),
_recordingFramesIn10MS(0),
_playoutFramesIn10MS(0),
+ _initialized(false),
_playing(false),
_recording(false),
_lastCallPlayoutMillis(0),
@@ -135,12 +136,13 @@ int32_t FileAudioDevice::InitPlayout() {
// Update webrtc audio buffer with the selected parameters
_ptrAudioBuffer->SetPlayoutSampleRate(kPlayoutFixedSampleRate);
_ptrAudioBuffer->SetPlayoutChannels(kPlayoutNumChannels);
+ _initialized = true;
}
return 0;
}
bool FileAudioDevice::PlayoutIsInitialized() const {
- return true;
+ return _initialized;
}
int32_t FileAudioDevice::RecordingIsAvailable(bool& available) {
@@ -236,7 +238,7 @@ int32_t FileAudioDevice::StopPlayout() {
}
bool FileAudioDevice::Playing() const {
- return true;
+ return _playing;
}
int32_t FileAudioDevice::StartRecording() {
diff --git a/webrtc/modules/audio_device/dummy/file_audio_device.h b/webrtc/modules/audio_device/dummy/file_audio_device.h
index a69b47e..3f3c841 100644
--- a/webrtc/modules/audio_device/dummy/file_audio_device.h
+++ b/webrtc/modules/audio_device/dummy/file_audio_device.h
@@ -185,6 +185,7 @@ class FileAudioDevice : public AudioDeviceGeneric {
std::unique_ptr<rtc::PlatformThread> _ptrThreadRec;
std::unique_ptr<rtc::PlatformThread> _ptrThreadPlay;
+ bool _initialized;;
bool _playing;
bool _recording;
uint64_t _lastCallPlayoutMillis;
这篇关于如何将音频从浏览器流式传输到WebRTC本机C ++应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!