简体   繁体   English

如何将音频从浏览器流式传输到WebRTC本机C ++应用程序

[英]How to stream audio from browser to WebRTC native C++ application

I have so far managed to run the following sample: 到目前为止,我已经成功运行了以下示例:

WebRTC native c++ to browser video streaming example WebRTC本机C ++到浏览器视频流的示例

The sample shows how to stream video from a native C++ application (peerconnection_client.exe) to the browser (I am using Chrome). 该示例演示如何将视频从本机C ++应用程序(peerconnection_client.exe)流到浏览器(我正在使用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. 到目前为止,这是我的方法。

To stream video from browser to your native program without gui, just follow the example here. 要将视频从浏览器流传输到不带GUI的本机程序,请按照此处的示例操作。 https://chromium.googlesource.com/external/webrtc/+/refs/heads/master/examples/peerconnection/client/ https://chromium.googlesource.com/external/webrtc/+/refs/heads/master/examples/peerconnection/client/

use AddOrUpdateSink to add your own VideoSinkInterface and you will receive your frame data in callback void OnFrame(const cricket::VideoFrame& frame) . 使用AddOrUpdateSink添加自己的VideoSinkInterface ,您将在回调void OnFrame(const cricket::VideoFrame& frame)接收帧数据。 Instead of render the frame to GUI as the example does, you can do whatever you want. 您可以执行任何您想做的事情,而不是像示例那样将框架渲染为GUI。

To stream audio from browser to your native program without real audio device. 在没有真正音频设备的情况下将音频从浏览器流式传输到本机程序。 you can use a fake audio device. 您可以使用假冒的音频设备。

  1. modify variable rtc_use_dummy_audio_file_devices to true in file https://chromium.googlesource.com/external/webrtc/+/master/webrtc/build/webrtc.gni 在文件https://chromium.googlesource.com/external/webrtc/+/master/webrtc/build/webrtc.gni rtc_use_dummy_audio_file_devices变量rtc_use_dummy_audio_file_devices修改为true
  2. invoke the global static function to specify the filename webrtc::FileAudioDeviceFactory::SetFilenamesToUse("", "file_to_save_audio"); 调用全局静态函数以指定文件名webrtc::FileAudioDeviceFactory::SetFilenamesToUse("", "file_to_save_audio");
  3. patch file_audio_device.cc with the code blew. 使用自爆代码修补file_audio_device.cc (as I write this answer, FileAudioDevice has some issues, may already be fixed) (在我编写此答案时,FileAudioDevice存在一些问题,可能已经修复)
  4. recompile your program, touch file_to_save_audio and you will see pcm data in file_to_save_audio after webrtc connection is established. 重新编译程序, touch file_to_save_audio ,在建立webrtc连接后,您将在file_to_save_audio看到pcm数据。

patch: 补丁:

    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;

you could use the following example which implement a desktop client for appRTC. 您可以使用以下示例,该示例为appRTC实现桌面客户端。

https://github.com/TemasysCommunications/appRTCDesk https://github.com/TemasysCommunications/appRTCDesk

this completes and interop with the web client, android client and iOs client provided by the open source implementation at webrtc.org, giving you a full suite of clients to work with their free server. 这样就完成了与webrtc.org的开放源代码实现所提供的Web客户端,Android客户端和iOs客户端的互操作,并为您提供了一整套可与其免费服务器一起使用的客户端。 peer connection_{client|server} is an old example from the lib jingle time (pre webrtc) and does not interop with anything else. peer connection_ {client | server}是lib jingle时代(在webrtc之前)的一个旧示例,并且不与其他任何对象互操作。

I know this is an old question, but I struggled myself to find a solution currently so I thought sharing is appreciated. 我知道这是一个古老的问题,但是我一直在努力寻找当前的解决方案,因此我认为分享值得赞赏。

There's is one more or less simple way to get an example running which streams from the browser to native code.You need the webrtc source http://www.webrtc.org/native-code/development 有一种或多或少的简单方法可以运行示例,该示例从浏览器流向本机代码。您需要webrtc源http://www.webrtc.org/native-code/development

The two tools you need are the peerconnection server and client. 您需要的两个工具是对等连接服务器和客户端。 Both can be found in the folder talk/example/peerconnection 两者都可以在文件夹talk / example / peerconnection中找到

To get it working you need to patch it to enable DTLS for the peerconnection client. 要使其正常工作,您需要对其进行修补以为对等连接客户端启用DTLS。 So patch it with the patch provided here https://code.google.com/p/webrtc/issues/detail?id=3872 and rebuild the client. 因此,请使用https://code.google.com/p/webrtc/issues/detail?id=3872此处提供的补丁对其进行修补,然后重新构建客户端。 Now you are set up on the native site! 现在您已经在本地站点上设置了!

For the browser I recommend the peer2peer example from here https://github.com/GoogleChrome/webrtc after starting the peerconnection_server and connection the peerconnection_client try to connect with the peer2peer example. 对于浏览器,在启动peerconnection_server并连接peerconnection_client并尝试与peer2peer示例连接之后,我建议从这里https://github.com/GoogleChrome/webrtc获得peer2peer示例。

Maybe a connection constraint is necessary: 也许连接约束是必要的:
{ "DtlsSrtpKeyAgreement": true } {“ DtlsSrtpKeyAgreement”:是}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM