![](/img/trans.png)
[英]WebRTC - Recording audio stream into file from within C++ application
[英]How to stream audio from browser to WebRTC native C++ application
到目前為止,我已經成功運行了以下示例:
該示例演示如何將視頻從本機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。
在沒有真正音頻設備的情況下將音頻從瀏覽器流式傳輸到本機程序。 您可以使用假冒的音頻設備。
rtc_use_dummy_audio_file_devices
變量rtc_use_dummy_audio_file_devices
修改為true
webrtc::FileAudioDeviceFactory::SetFilenamesToUse("", "file_to_save_audio");
file_audio_device.cc
。 (在我編寫此答案時,FileAudioDevice存在一些問題,可能已經修復) 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.