繁体   English   中英

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

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

到目前为止,我已经成功运行了以下示例:

WebRTC本机C ++到浏览器视频流的示例

该示例演示如何将视频从本机C ++应用程序(peerconnection_client.exe)流到浏览器(我正在使用Chrome)。 这个工作正常,我可以在浏览器中看到自己。

我想做的是将音频从浏览器流式传输到本机应用程序,但是我不确定如何。 任何人都可以给我一些指示吗?

我正在尝试找到一种将视频和音频从浏览器流式传输到本机程序的方法。 到目前为止,这是我的方法。

要将视频从浏览器流传输到不带GUI的本机程序,请按照此处的示例操作。 https://chromium.googlesource.com/external/webrtc/+/refs/heads/master/examples/peerconnection/client/

使用AddOrUpdateSink添加自己的VideoSinkInterface ,您将在回调void OnFrame(const cricket::VideoFrame& frame)接收帧数据。 您可以执行任何您想做的事情,而不是像示例那样将框架渲染为GUI。

在没有真正音频设备的情况下将音频从浏览器流式传输到本机程序。 您可以使用假冒的音频设备。

  1. 在文件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. 调用全局静态函数以指定文件名webrtc::FileAudioDeviceFactory::SetFilenamesToUse("", "file_to_save_audio");
  3. 使用自爆代码修补file_audio_device.cc (在我编写此答案时,FileAudioDevice存在一些问题,可能已经修复)
  4. 重新编译程序, touch file_to_save_audio ,在建立webrtc连接后,您将在file_to_save_audio看到pcm数据。

补丁:

    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;

您可以使用以下示例,该示例为appRTC实现桌面客户端。

https://github.com/TemasysCommunications/appRTCDesk

这样就完成了与webrtc.org的开放源代码实现所提供的Web客户端,Android客户端和iOs客户端的互操作,并为您提供了一整套可与其免费服务器一起使用的客户端。 peer connection_ {client | server}是lib jingle时代(在webrtc之前)的一个旧示例,并且不与其他任何对象互操作。

我知道这是一个古老的问题,但是我一直在努力寻找当前的解决方案,因此我认为分享值得赞赏。

有一种或多或少的简单方法可以运行示例,该示例从浏览器流向本机代码。您需要webrtc源http://www.webrtc.org/native-code/development

您需要的两个工具是对等连接服务器和客户端。 两者都可以在文件夹talk / example / peerconnection中找到

要使其正常工作,您需要对其进行修补以为对等连接客户端启用DTLS。 因此,请使用https://code.google.com/p/webrtc/issues/detail?id=3872此处提供的补丁对其进行修补,然后重新构建客户端。 现在您已经在本地站点上设置了!

对于浏览器,在启动peerconnection_server并连接peerconnection_client并尝试与peer2peer示例连接之后,我建议从这里https://github.com/GoogleChrome/webrtc获得peer2peer示例。

也许连接约束是必要的:
{“ DtlsSrtpKeyAgreement”:是}

暂无
暂无

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

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