te')); return $arr; } /* 遍历用户所有主题 * @param $uid 用户ID * @param int $page 页数 * @param int $pagesize 每页记录条数 * @param bool $desc 排序方式 TRUE降序 FALSE升序 * @param string $key 返回的数组用那一列的值作为 key * @param array $col 查询哪些列 */ function thread_tid_find_by_uid($uid, $page = 1, $pagesize = 1000, $desc = TRUE, $key = 'tid', $col = array()) { if (empty($uid)) return array(); $orderby = TRUE == $desc ? -1 : 1; $arr = thread_tid__find($cond = array('uid' => $uid), array('tid' => $orderby), $page, $pagesize, $key, $col); return $arr; } // 遍历栏目下tid 支持数组 $fid = array(1,2,3) function thread_tid_find_by_fid($fid, $page = 1, $pagesize = 1000, $desc = TRUE) { if (empty($fid)) return array(); $orderby = TRUE == $desc ? -1 : 1; $arr = thread_tid__find($cond = array('fid' => $fid), array('tid' => $orderby), $page, $pagesize, 'tid', array('tid', 'verify_date')); return $arr; } function thread_tid_delete($tid) { if (empty($tid)) return FALSE; $r = thread_tid__delete(array('tid' => $tid)); return $r; } function thread_tid_count() { $n = thread_tid__count(); return $n; } // 统计用户主题数 大数量下严谨使用非主键统计 function thread_uid_count($uid) { $n = thread_tid__count(array('uid' => $uid)); return $n; } // 统计栏目主题数 大数量下严谨使用非主键统计 function thread_fid_count($fid) { $n = thread_tid__count(array('fid' => $fid)); return $n; } ?>javascript - How to stream audio from browser to WebRTC native C++ application - Stack Overflow
最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to stream audio from browser to WebRTC native C++ application - Stack Overflow

programmeradmin1浏览0评论

I have so far managed to run the following sample:

WebRTC native c++ to browser video streaming example

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 have so far managed to run the following sample:

WebRTC native c++ to browser video streaming example

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?

Share Improve this question asked May 3, 2014 at 20:48 jpenjpen 2,1475 gold badges33 silver badges56 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 4

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. https://chromium.googlesource./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). 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.

  1. modify variable rtc_use_dummy_audio_file_devices to true in file https://chromium.googlesource./external/webrtc/+/master/webrtc/build/webrtc.gni
  2. invoke the global static function to specify the filename webrtc::FileAudioDeviceFactory::SetFilenamesToUse("", "file_to_save_audio");
  3. patch file_audio_device with the code blew. (as I write this answer, FileAudioDevice has some issues, may already be fixed)
  4. repile your program, touch file_to_save_audio and you will see pcm data in file_to_save_audio after webrtc connection is established.

patch:

    diff --git a/webrtc/modules/audio_device/dummy/file_audio_device b/webrtc/modules/audio_device/dummy/file_audio_device
index 8b3fa5e..2717cda 100644
--- a/webrtc/modules/audio_device/dummy/file_audio_device
+++ b/webrtc/modules/audio_device/dummy/file_audio_device
@@ -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;

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/native-code/development

The two tools you need are the peerconnection server and client. Both can be found in the folder talk/example/peerconnection

To get it working you need to patch it to enable DTLS for the peerconnection client. So patch it with the patch provided here https://code.google./p/webrtc/issues/detail?id=3872 and rebuild the client. Now you are set up on the native site!

For the browser I remend the peer2peer example from here https://github./GoogleChrome/webrtc after starting the peerconnection_server and connection the peerconnection_client try to connect with the peer2peer example.

Maybe a connection constraint is necessary:
{ "DtlsSrtpKeyAgreement": true }

you could use the following example which implement a desktop client for appRTC.

https://github./TemasysCommunications/appRTCDesk

this pletes and interop with the web client, android client and iOs client provided by the open source implementation at webrtc, giving you a full suite of clients to work with their free server. peer connection_{client|server} is an old example from the lib jingle time (pre webrtc) and does not interop with anything else.

发布评论

评论列表(0)

  1. 暂无评论