SlideShare a Scribd company logo
C++ WebRTC
(DataChannel)
/ @llamerada_jp
WebRTC Meetup Tokyo #20
SE
/ /
GitHub : llamerada-jp
facebook : ito.yuuji
twitter : @llamerada_jp
blog : http://llamerad-jp.hatenablog.com/
/
PROCESSWARP
Web /
/
www.oinari.app
libvein
Server
/
libvein
Web /
2 PubSub
KVS
Seed / Server
Documents /
https://webrtc.org/native-code/development/
&
API code reading
WebRTC ( )
 https://gist.github.com/szktty/
a47213f0077294c64ea58621c2dcfaf2
android iOS
CUI WebRTC
https://github.com/llamerada-jp/webrtc-cpp-sample
WebRTC
https://github.com/llamerada-jp/libwebrtc
Native APIs
WebRTC Native APIs ?
WebView / Electron
WebSocket
iOS / Android (C++ )
WebRTC Native APIs
API
API
WebRTC API ( )
connect

SDP

ICE

send data

disconnect

event

change status

recv data

raise error
libuv
libuv
main Thread
rtc::Runnable Thread
webrtc::

CreatePeerConnectionFactory
rtc::Runnable::Run
uv_loop
uv_async_send Event!
libvein
JavaScritp
WebAssembly
WebRTC/WebSocket API
SDP / ICE (Server /
Seed )
libvein core (C++)

WebSocket

Wrapper
WebRTC

Wrapper
Native
WebRTC
Browser

WebRTC
Browser

WebSocket
WebSocket++
C++

API
C

API
Python JavaScript
https://webrtc.org/native-code/development/
http://commondatastorage.googleapis.com/chrome-infra-docs/flat/depot_tools/
docs/html/depot_tools_tutorial.html
$ cd <workdir>

$ git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git

$ export PATH=$PATH:`pwd`/depot_tools

$ cd <workdir>

$ mkdir webrtc-checkout

$ cd webrtc-checkout

$ fetch --nohooks webrtc

$ gclient sync

$ gn gen out/Default --args=‘is_debug=false’

$ ninja -C out/Default
Chrome WebRTC
@ WebRTC

Σ( ω )
chromium URL
https://omahaproxy.appspot.com/all
OS stable
branch_commit

HASH of chromium
$ cd <workdir>

$ git clone https://chromium.googlesource.com/chromium/src chromium

$ cd chromium

$ git show <HASH of chromium>:DEPS

< >

‘src/third_party/webrtc':

Var('webrtc_git') + '/src.git' + '@' + ‘784fccbd71c0130b32345d81459b5d0cb07ff6e5',

< >
HASH of webrtc
< gclient sync >
$ git fetch
$ git checkout <HASH of webrtc>
$ gclient sync
$ gn gen out/Default [--args='is_debug=false']
$ ninja -C out/Default [<target>]
@ Linux
static library(.a ) .o
.a
ar 1 .a
src/out/Default/obj/examples/peerconnection_client.ninja

build <target>: link <obj1> <obj2> … 

build ./peerconnection_client: link obj/examples/
peerconnection_client/conductor.o obj/examples/
peerconnection_client/defaults.o obj/examples/
peerconnection_client/peer_connection_client.o obj/
examples/peerconnection_client/main.o obj/examples/
peerconnection_client/main_wnd.o obj/api/video/
video_frame_i420/i420_buffer.o obj/rtc_base/checks/
checks.o obj/rtc_base/stringutils/string_to_number.o
@ macOS
obj/sdk/mac_framework_objc_shared_library/WebRTC
obj/api/video_codecs/libbuiltin_video_encoder_factory.a
obj/api/video_codecs/libbuiltin_video_decoder_factory.a
src/out/Default/obj/sdk/mac_framework_objc_shared_library.ninja
src/obj/api/video_codecs/libbuiltin_video_encoder_factory.a
src/obj/api/video_codecs/libbuiltin_video_decoder_factory.a
nm
https://github.com/llamerada-jp/search-
symbol
chromium
peerconnection_client
https://github.com/llamerada-jp/webrtc-cpp-sample
API JavaScript JavaScript
C++ API
PeerConnectionObserver
class PCO : public webrtc::PeerConnectionObserver {

void OnSignalingChange(webrtc::PeerConnectionInterface::SignalingState new_state) override;

void OnAddStream(rtc::scoped_refptr<webrtc::MediaStreamInterface> stream) override;

void OnRemoveStream(rtc::scoped_refptr<webrtc::MediaStreamInterface> stream) override;

// DataChannel !

void OnDataChannel(rtc::scoped_refptr<webrtc::DataChannelInterface> data_channel) override;

void OnRenegotiationNeeded() override;

void OnIceConnectionChange(webrtc::PeerConnectionInterface::IceConnectionState new_state) override;

void OnIceGatheringChange(webrtc::PeerConnectionInterface::IceGatheringState new_state) override;

// ICE 

void OnIceCandidate(const webrtc::IceCandidateInterface* candidate) override;

};
DataChannelObserver
class DCO : public webrtc::DataChannelObserver {

// 

void OnStateChange() override;

// 

void OnMessage(const webrtc::DataBuffer& buffer) override;

void OnBufferedAmountChange(uint64_t previous_amount) override;

};
SessionDescriptionObserver
class CSDO : public webrtc::CreateSessionDescriptionObserver {

void OnSuccess(webrtc::SessionDescriptionInterface* desc) override;

void OnFailure(const std::string& error) override;

};

class SSDO : public webrtc::SetSessionDescriptionObserver {

void OnSuccess() override;

void OnFailure(const std::string& error) override;

};

rtc::scoped_refptr<CSDO> csdo (new rtc::RefCountedObject<CSDO>());

rtc::scoped_refptr<SSDO> ssdo (new rtc::RefCountedObject<SSDO>());
&
CreatePeerConnectionFactory
class CustomRunnable : public rtc::Runnable {

public:

void Run(rtc::Thread* subthread) override {

peer_connection_factory = webrtc::CreatePeerConnectionFactory(

nullptr /* network_thread */, nullptr /* worker_thread */,

nullptr /* signaling_thread */, nullptr /* default_adm */,

webrtc::CreateBuiltinAudioEncoderFactory(),

webrtc::CreateBuiltinAudioDecoderFactory(),

webrtc::CreateBuiltinVideoEncoderFactory(),

webrtc::CreateBuiltinVideoDecoderFactory(),

nullptr /* audio_mixer */, nullptr /* audio_processing */);

if (peer_connection_factory.get() == nullptr) {

// Error

}

subthread->Run();

}

};
rtc::PhysicalSocketServer socket_server;

thread.reset(new rtc::Thread(&socket_server));

rtc::InitializeSSL();

CustomRunnable runnable;

thread->Start(&runnable);

< peer_connection_factory >

peer_connection = peer_connection_factory->CreatePeerConnection(configuration, nullptr, nullptr, &pco);

webrtc::DataChannelInit config;

// DataChannel 

data_channel = peer_connection->CreateDataChannel("data_channel", &config);

data_channel->RegisterObserver(&dco);

peer_connection->CreateOffer(csdo, webrtc::PeerConnectionInterface::RTCOfferAnswerOptions());
std::string message(“hello!!”,);

webrtc::DataBuffer buffer(

rtc::CopyOnWriteBuffer(

message.c_str(),

message.size()),

true);

data_channel->Send(buffer);
class DCO : public webrtc::DataChannelObserver {

// 

void OnMessage(const webrtc::DataBuffer& buffer) override {

std::cout << std::string(buffer.data.data<char>(), buffer.data.size()) << std::endl;

}

};
// Close 

peer_connection->Close();

peer_connection = nullptr;

data_channel = nullptr;

peer_connection_factory = nullptr;

thread->Quit();

thread.reset();

rtc::CleanupSSL();
macOS : WEBRTC_MAC=1 WEBRTC_POSIX=1
Linux : WEBRTC_LINUX=1 WEBRTC_POSIX=1
clang (libc++ )
-stdlib=libc++
C++ RTTI -fno-rtti
typeinfo dynamic_cast
--start-group --end-group
$ clang++ -I<workdir/webrtc-checkout/src> -I<workdir/webrtc-checkout/src/
third_party/abseil-cpp> -DWEBRTC_MAC=1 -DWEBRTC_POSIX=1 -std=c++11 -W -Wall -
Wno-unused-parameter -O0 -g -fno-rtti -o <output> -o <source>

(github ) build
./build.sh 

$ cd <path to build>

$ make clean

$ make VERBOSE=1
OpenSSL BoringSSL API
HTTP WebSocket
BoringSSL
WebRTC Third party src/third_party
WebRTC BSD
src/third_party
OSS WebRTC
WebRTC C++

More Related Content

PPTX
世界一わかりやすいClean Architecture
PDF
WebRTCの技術解説 公開版
PDF
Dockerからcontainerdへの移行
PDF
コンテナの作り方「Dockerは裏方で何をしているのか?」
PDF
ドメイン駆動設計のための Spring の上手な使い方
PDF
YugabyteDBを使ってみよう(NewSQL/分散SQLデータベースよろず勉強会 #1 発表資料)
PDF
CEDEC 2018 最速のC#の書き方 - C#大統一理論へ向けて性能的課題を払拭する
PDF
Javaコードが速く実⾏される秘密 - JITコンパイラ⼊⾨(JJUG CCC 2020 Fall講演資料)
世界一わかりやすいClean Architecture
WebRTCの技術解説 公開版
Dockerからcontainerdへの移行
コンテナの作り方「Dockerは裏方で何をしているのか?」
ドメイン駆動設計のための Spring の上手な使い方
YugabyteDBを使ってみよう(NewSQL/分散SQLデータベースよろず勉強会 #1 発表資料)
CEDEC 2018 最速のC#の書き方 - C#大統一理論へ向けて性能的課題を払拭する
Javaコードが速く実⾏される秘密 - JITコンパイラ⼊⾨(JJUG CCC 2020 Fall講演資料)

What's hot (20)

PPTX
本当は恐ろしい分散システムの話
PDF
Grafana LokiではじめるKubernetesロギングハンズオン(NTT Tech Conference #4 ハンズオン資料)
PPTX
イベント駆動プログラミングとI/O多重化
PDF
ドメイン駆動設計のためのオブジェクト指向入門
PDF
SFUの話
PDF
WebSocket / WebRTCの技術紹介
PDF
それはYAGNIか? それとも思考停止か?
PDF
WebRTC と Native とそれから、それから。
PDF
Tackling Complexity
PDF
なぜ初心者は webpackが解らないのか?- Why can’t you understand the webpack? -
PDF
SQLアンチパターン - 開発者を待ち受ける25の落とし穴 (拡大版)
PPTX
Amazon EKS によるスマホゲームのバックエンド運用事例
PDF
劇的改善 Ci4時間から5分へ〜私がやった10のこと〜
PDF
マイクロサービス 4つの分割アプローチ
PDF
BGP Unnumbered で遊んでみた
PDF
ゲーム開発者のための C++11/C++14
PDF
できる!並列・並行プログラミング
PDF
SQLアンチパターン 幻の第26章「とりあえず削除フラグ」
PPTX
Apache Spark on Kubernetes入門(Open Source Conference 2021 Online Hiroshima 発表資料)
PDF
わかる!metadata.managedFields / Kubernetes Meetup Tokyo 48
本当は恐ろしい分散システムの話
Grafana LokiではじめるKubernetesロギングハンズオン(NTT Tech Conference #4 ハンズオン資料)
イベント駆動プログラミングとI/O多重化
ドメイン駆動設計のためのオブジェクト指向入門
SFUの話
WebSocket / WebRTCの技術紹介
それはYAGNIか? それとも思考停止か?
WebRTC と Native とそれから、それから。
Tackling Complexity
なぜ初心者は webpackが解らないのか?- Why can’t you understand the webpack? -
SQLアンチパターン - 開発者を待ち受ける25の落とし穴 (拡大版)
Amazon EKS によるスマホゲームのバックエンド運用事例
劇的改善 Ci4時間から5分へ〜私がやった10のこと〜
マイクロサービス 4つの分割アプローチ
BGP Unnumbered で遊んでみた
ゲーム開発者のための C++11/C++14
できる!並列・並行プログラミング
SQLアンチパターン 幻の第26章「とりあえず削除フラグ」
Apache Spark on Kubernetes入門(Open Source Conference 2021 Online Hiroshima 発表資料)
わかる!metadata.managedFields / Kubernetes Meetup Tokyo 48
Ad

Similar to C++からWebRTC (DataChannel)を利用する (20)

PDF
WebRTC Standards & Implementation Q&A - The Internals of WebRTC Browsers Impl...
PDF
DevCon 5 (December 2013) - WebRTC & WebSockets
PDF
WebRTC 101 - How to get started building your first WebRTC application
PPTX
Practical webRTC - from API to Solution - webRTC Summit 2014 @ NYC
PDF
Spring Boot for WebRTC Signaling Servers: A Comprehensive Guide
PPTX
DeveloperWeek 2015 - WebRTC - Where to start and how to scale
PDF
WebRTC, Whats in it for me?
PDF
[workshop] The Revolutionary WebRTC
PDF
WHIP WebRTC Broadcasting @ FOSDEM 2022
PDF
WebRTC standards update - November 2014
PDF
WebRTC support in WebKitGTK and WPEWebKit with GStreamer: Status update
PPTX
How to Architect your WebRTC application, Alberto Gonzalez and Arin Sime, Web...
PPTX
WebRTC Seminar Report
PDF
FOSDEM 2020: How can we make WebRTC Easier?
PDF
BWE in Janus
PDF
WebRTC Standards Update (October 2014)
PDF
WebRTC
PPTX
WebRTC overview
PDF
Testing WebRTC applications at scale.pdf
PDF
WebRTC: A front-end perspective
WebRTC Standards & Implementation Q&A - The Internals of WebRTC Browsers Impl...
DevCon 5 (December 2013) - WebRTC & WebSockets
WebRTC 101 - How to get started building your first WebRTC application
Practical webRTC - from API to Solution - webRTC Summit 2014 @ NYC
Spring Boot for WebRTC Signaling Servers: A Comprehensive Guide
DeveloperWeek 2015 - WebRTC - Where to start and how to scale
WebRTC, Whats in it for me?
[workshop] The Revolutionary WebRTC
WHIP WebRTC Broadcasting @ FOSDEM 2022
WebRTC standards update - November 2014
WebRTC support in WebKitGTK and WPEWebKit with GStreamer: Status update
How to Architect your WebRTC application, Alberto Gonzalez and Arin Sime, Web...
WebRTC Seminar Report
FOSDEM 2020: How can we make WebRTC Easier?
BWE in Janus
WebRTC Standards Update (October 2014)
WebRTC
WebRTC overview
Testing WebRTC applications at scale.pdf
WebRTC: A front-end perspective
Ad

More from 祐司 伊藤 (11)

PDF
Container Storage Interface のすべて
PDF
C/C++とWebAssemblyを利用したライブラリ開発
PDF
詳説WebAssembly
PDF
シンプル Processing !
PDF
PROCESS WARP「プロセスがデバイス間で移動する」仕組みを作る
PDF
PROCESS WARP
PDF
Webブラウザで使えるいろんな処理系
PDF
PROCESS WARP
PDF
PIAXで作る P2Pネットワーク
PDF
新しい分散実行の仕組み PROCESS WARPについて
PDF
emscriptenでC/C++プログラムをwebブラウザから使うまでの難所攻略
Container Storage Interface のすべて
C/C++とWebAssemblyを利用したライブラリ開発
詳説WebAssembly
シンプル Processing !
PROCESS WARP「プロセスがデバイス間で移動する」仕組みを作る
PROCESS WARP
Webブラウザで使えるいろんな処理系
PROCESS WARP
PIAXで作る P2Pネットワーク
新しい分散実行の仕組み PROCESS WARPについて
emscriptenでC/C++プログラムをwebブラウザから使うまでの難所攻略

Recently uploaded (20)

PPTX
PptxGenJS_Demo_Chart_20250317130215833.pptx
PDF
Sims 4 Historia para lo sims 4 para jugar
PPTX
Job_Card_System_Styled_lorem_ipsum_.pptx
PPTX
Introduction to Information and Communication Technology
PDF
The New Creative Director: How AI Tools for Social Media Content Creation Are...
PDF
Triggering QUIC, presented by Geoff Huston at IETF 123
PPTX
Funds Management Learning Material for Beg
PDF
Decoding a Decade: 10 Years of Applied CTI Discipline
PPTX
CHE NAA, , b,mn,mblblblbljb jb jlb ,j , ,C PPT.pptx
PPT
Design_with_Watersergyerge45hrbgre4top (1).ppt
PPTX
June-4-Sermon-Powerpoint.pptx USE THIS FOR YOUR MOTIVATION
PPTX
innovation process that make everything different.pptx
PPTX
Introuction about ICD -10 and ICD-11 PPT.pptx
PDF
APNIC Update, presented at PHNOG 2025 by Shane Hermoso
PDF
WebRTC in SignalWire - troubleshooting media negotiation
PPT
tcp ip networks nd ip layering assotred slides
PPTX
artificial intelligence overview of it and more
PDF
Unit-1 introduction to cyber security discuss about how to secure a system
PPTX
SAP Ariba Sourcing PPT for learning material
PDF
Best Practices for Testing and Debugging Shopify Third-Party API Integrations...
PptxGenJS_Demo_Chart_20250317130215833.pptx
Sims 4 Historia para lo sims 4 para jugar
Job_Card_System_Styled_lorem_ipsum_.pptx
Introduction to Information and Communication Technology
The New Creative Director: How AI Tools for Social Media Content Creation Are...
Triggering QUIC, presented by Geoff Huston at IETF 123
Funds Management Learning Material for Beg
Decoding a Decade: 10 Years of Applied CTI Discipline
CHE NAA, , b,mn,mblblblbljb jb jlb ,j , ,C PPT.pptx
Design_with_Watersergyerge45hrbgre4top (1).ppt
June-4-Sermon-Powerpoint.pptx USE THIS FOR YOUR MOTIVATION
innovation process that make everything different.pptx
Introuction about ICD -10 and ICD-11 PPT.pptx
APNIC Update, presented at PHNOG 2025 by Shane Hermoso
WebRTC in SignalWire - troubleshooting media negotiation
tcp ip networks nd ip layering assotred slides
artificial intelligence overview of it and more
Unit-1 introduction to cyber security discuss about how to secure a system
SAP Ariba Sourcing PPT for learning material
Best Practices for Testing and Debugging Shopify Third-Party API Integrations...

C++からWebRTC (DataChannel)を利用する