Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

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

429 views

Published on

WebRTC Meetup Tokyo #20

Published in: Internet
  • Be the first to comment

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

  1. 1. C++ WebRTC (DataChannel) / @llamerada_jp WebRTC Meetup Tokyo #20
  2. 2. SE / / GitHub : llamerada-jp facebook : ito.yuuji twitter : @llamerada_jp blog : http://llamerad-jp.hatenablog.com/
  3. 3. / PROCESSWARP Web /
  4. 4. / www.oinari.app libvein Server
  5. 5. / libvein Web / 2 PubSub KVS Seed / Server
  6. 6. 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
  7. 7. Native APIs
  8. 8. WebRTC Native APIs ? WebView / Electron WebSocket iOS / Android (C++ ) WebRTC Native APIs API API
  9. 9. WebRTC API ( ) connect SDP ICE send data disconnect event change status recv data raise error
  10. 10. libuv libuv main Thread rtc::Runnable Thread webrtc:: CreatePeerConnectionFactory rtc::Runnable::Run uv_loop uv_async_send Event!
  11. 11. 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
  12. 12. https://webrtc.org/native-code/development/ http://commondatastorage.googleapis.com/chrome-infra-docs/flat/depot_tools/ docs/html/depot_tools_tutorial.html
  13. 13. $ 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
  14. 14. Chrome WebRTC
  15. 15. @ WebRTC Σ( ω )
  16. 16. chromium URL https://omahaproxy.appspot.com/all OS stable branch_commit HASH of chromium
  17. 17. $ 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
  18. 18. < gclient sync > $ git fetch $ git checkout <HASH of webrtc> $ gclient sync $ gn gen out/Default [--args='is_debug=false'] $ ninja -C out/Default [<target>]
  19. 19. @ 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
  20. 20. @ 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
  21. 21. nm https://github.com/llamerada-jp/search- symbol chromium
  22. 22. peerconnection_client https://github.com/llamerada-jp/webrtc-cpp-sample API JavaScript JavaScript C++ API
  23. 23. 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; };
  24. 24. DataChannelObserver class DCO : public webrtc::DataChannelObserver { // void OnStateChange() override; // void OnMessage(const webrtc::DataBuffer& buffer) override; void OnBufferedAmountChange(uint64_t previous_amount) override; };
  25. 25. 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>());
  26. 26. & 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(); } };
  27. 27. 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());
  28. 28. std::string message(“hello!!”,); webrtc::DataBuffer buffer( rtc::CopyOnWriteBuffer( message.c_str(), message.size()), true); data_channel->Send(buffer);
  29. 29. 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; } };
  30. 30. // Close peer_connection->Close(); peer_connection = nullptr; data_channel = nullptr; peer_connection_factory = nullptr; thread->Quit(); thread.reset(); rtc::CleanupSSL();
  31. 31. 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
  32. 32. $ 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
  33. 33. OpenSSL BoringSSL API HTTP WebSocket BoringSSL WebRTC Third party src/third_party
  34. 34. WebRTC BSD src/third_party OSS WebRTC
  35. 35. WebRTC C++

×