diff --git a/CMakeLists.txt b/CMakeLists.txt index cf6a1e8..3b0354f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -41,7 +41,6 @@ set(LIBWEBRTC_VERSION # option(BUILD_TESTS "Build test binaries" OFF) -option(BUILD_SAMPLES "Build samples binaries" OFF) set(NINJA_ARGS "" CACHE STRING "Ninja arguments to pass before compiling WebRTC") # diff --git a/Samples/CMakeLists.txt b/Samples/CMakeLists.txt deleted file mode 100644 index 8a79773..0000000 --- a/Samples/CMakeLists.txt +++ /dev/null @@ -1 +0,0 @@ -add_subdirectory(PeerConnection) \ No newline at end of file diff --git a/Samples/PeerConnection/CMakeLists.txt b/Samples/PeerConnection/CMakeLists.txt deleted file mode 100644 index fcfd9b5..0000000 --- a/Samples/PeerConnection/CMakeLists.txt +++ /dev/null @@ -1,75 +0,0 @@ -project(PeerConnection) - -set(THREADS_PREFER_PTHREAD_FLAG ON) -find_package(Threads REQUIRED) - -if(UNIX AND NOT APPLE) - find_package(X11 REQUIRED) -endif(UNIX AND NOT APPLE) - -if(APPLE) - find_library(AUDIOTOOLBOX_LIBRARY AudioToolbox) - find_library(COREAUDIO_LIBRARY CoreAudio) - find_library(COREFOUNDATION_LIBRARY CoreFoundation) - find_library(COREGRAPHICS_LIBRARY CoreGraphics) - find_library(FOUNDATION_LIBRARY Foundation) -endif(APPLE) - -set(PEERCONNECTION_SOURCE_FILES - main.cpp - Core.cpp - CreateSessionObserver.cpp - DataChannelObserver.cpp - Peer.cpp - PeerConnectionObserver.cpp - SetLocalSessionDescriptionObserver.cpp - SetRemoteSessionDescriptionObserver.cpp -) - -set(PEERCONNECTION_HEADER_FILES - Console.h - Core.h - CreateSessionObserver.h - DataChannelObserver.h - IPeer.h - Peer.h - PeerConnectionObserver.h - SetLocalSessionDescriptionObserver.h - SetRemoteSessionDescriptionObserver.h -) - -include_directories(${CMAKE_BINARY_DIR}/src) - -if(WIN32) - add_definitions(-DWEBRTC_WIN -DNOMINMAX) - set(PEERCONNECTION_SOURCE_FILES ${PEERCONNECTION_SOURCE_FILES} - Win32Console.cpp) -else(WIN32) - add_definitions(-DWEBRTC_POSIX -std=gnu++0x -D_GLIBCXX_USE_CXX11_ABI=0) - set(PEERCONNECTION_SOURCE_FILES ${PEERCONNECTION_SOURCE_FILES} - UnixConsole.cpp) -endif(WIN32) - -add_executable(PeerConnection - ${PEERCONNECTION_SOURCE_FILES} - ${PEERCONNECTION_HEADER_FILES}) - -set(PEERCONNECTION_LIBRARIES webrtc Threads::Threads) - -if(WIN32) - set(PEERCONNECTION_LIBRARIES ${PEERCONNECTION_LIBRARIES} msdmo.lib wmcodecdspuuid.lib dmoguids.lib ole32.lib secur32.lib) -elseif(UNIX AND NOT APPLE) - set(PEERCONNECTION_LIBRARIES ${PEERCONNECTION_LIBRARIES} - ${X11_LIBRARIES} - ${CMAKE_DL_LIBS}) -elseif(APPLE) - set(PEERCONNECTION_LIBRARIES ${PEERCONNECTION_LIBRARIES} - ${AUDIOTOOLBOX_LIBRARY} ${COREAUDIO_LIBRARY} ${COREFOUNDATION_LIBRARY} - ${COREGRAPHICS_LIBRARY} ${FOUNDATION_LIBRARY}) -endif(WIN32) - -add_library(webrtc STATIC IMPORTED) -set_property(TARGET webrtc PROPERTY IMPORTED_LOCATION "${CMAKE_BINARY_DIR}/libwebrtc/${LIBWEBRTC_LIBRARY_NAME}") - -target_link_libraries(PeerConnection ${PEERCONNECTION_LIBRARIES}) -add_dependencies(PeerConnection libwebrtc) \ No newline at end of file diff --git a/Samples/PeerConnection/Console.h b/Samples/PeerConnection/Console.h deleted file mode 100644 index ba2fb29..0000000 --- a/Samples/PeerConnection/Console.h +++ /dev/null @@ -1,20 +0,0 @@ -// -// Created by ax on 25/09/16. -// - -#ifndef LIBWEBRTC_UNIXCONSOLE_H -#define LIBWEBRTC_UNIXCONSOLE_H - -class Console { -public: - static bool Init(); - static bool Update(std::string &input); - static void Cleanup(); - static void Reset(int num); - static void Print(const std::string &line, ...); - static void Show(); - static void Hide(); - static void Back(); -}; - -#endif //LIBWEBRTC_UNIXCONSOLE_H diff --git a/Samples/PeerConnection/Core.cpp b/Samples/PeerConnection/Core.cpp deleted file mode 100644 index b66f171..0000000 --- a/Samples/PeerConnection/Core.cpp +++ /dev/null @@ -1,87 +0,0 @@ -// -// Created by ax on 24/09/16. -// - -#include "webrtc/base/ssladapter.h" -#ifdef WIN32 -#include "webrtc/base/win32socketinit.h" -#include "webrtc/base/win32socketserver.h" -#include -#endif -#include "Core.h" - -rtc::Thread *Core::_signalingThread = NULL; -rtc::Thread *Core::_workerThread = NULL; -webrtc::PeerConnectionFactoryInterface *Core::_peerConnectionFactory = NULL; - -bool Core::Init() { -#if 0 - rtc::EnsureWinsockInit(); - rtc::Win32Thread w32_thread; - rtc::ThreadManager::Instance()->SetCurrentThread(&w32_thread); -#endif - - rtc::InitializeSSL(); - rtc::InitRandom(rtc::Time()); - rtc::ThreadManager::Instance()->WrapCurrentThread(); - - _signalingThread = new rtc::Thread(); - _workerThread = new rtc::Thread(); - - _signalingThread->SetName("signaling_thread", NULL); - _workerThread->SetName("worker_thread", NULL); - - if (!_signalingThread->Start() || !_workerThread->Start()) { - return false; - } - - _peerConnectionFactory = - webrtc::CreatePeerConnectionFactory(_signalingThread, - _workerThread, - NULL, NULL, NULL).release(); - - return true; -} - -bool Core::Update() { - return rtc::Thread::Current()->ProcessMessages(0); -} - -bool Core::Cleanup() { - _peerConnectionFactory->Release(); - _peerConnectionFactory = NULL; - - _signalingThread->Stop(); - _workerThread->Stop(); - - delete _signalingThread; - delete _workerThread; - - _signalingThread = NULL; - _workerThread = NULL; - - return rtc::CleanupSSL(); -} - -rtc::Thread *Core::GetSignalingThread() { - return _signalingThread; -} - -rtc::Thread *Core::GetWorkerThread() { - return _workerThread; -} - -webrtc::PeerConnectionFactoryInterface *Core::GetPeerConnectionFactory() { - return _peerConnectionFactory; -} - - - - - - - - - - - diff --git a/Samples/PeerConnection/Core.h b/Samples/PeerConnection/Core.h deleted file mode 100644 index 006ec82..0000000 --- a/Samples/PeerConnection/Core.h +++ /dev/null @@ -1,28 +0,0 @@ -// -// Created by ax on 24/09/16. -// - -#ifndef LIBWEBRTC_CORE_H -#define LIBWEBRTC_CORE_H - -#include "webrtc/api/peerconnectioninterface.h" -#include "webrtc/base/thread.h" - -class Core { -public: - static bool Init(); - static bool Update(); - static bool Cleanup(); - - static rtc::Thread *GetSignalingThread(); - static rtc::Thread *GetWorkerThread(); - static webrtc::PeerConnectionFactoryInterface *GetPeerConnectionFactory(); - -private: - static rtc::Thread *_signalingThread; - static rtc::Thread *_workerThread; - static webrtc::PeerConnectionFactoryInterface *_peerConnectionFactory; -}; - - -#endif //LIBWEBRTC_CORE_H diff --git a/Samples/PeerConnection/CreateSessionObserver.cpp b/Samples/PeerConnection/CreateSessionObserver.cpp deleted file mode 100644 index 2c30693..0000000 --- a/Samples/PeerConnection/CreateSessionObserver.cpp +++ /dev/null @@ -1,23 +0,0 @@ -// -// Created by ax on 25/09/16. -// - -#include "CreateSessionObserver.h" -#include "Console.h" -#include "SetLocalSessionDescriptionObserver.h" - -using namespace webrtc; - -CreateSessionObserver::CreateSessionObserver(IPeer *peer): _peer(peer) { -} - -void CreateSessionObserver::OnSuccess(SessionDescriptionInterface* desc) { - rtc::scoped_refptr observer = - new rtc::RefCountedObject(desc); - - _peer->SetLocalSessionDescription(desc, observer); -} - -void CreateSessionObserver::OnFailure(const std::string& error) { - Console::Print("[CreateSessionObserver::OnFailure] %s", error.c_str()); -} \ No newline at end of file diff --git a/Samples/PeerConnection/CreateSessionObserver.h b/Samples/PeerConnection/CreateSessionObserver.h deleted file mode 100644 index f8a5321..0000000 --- a/Samples/PeerConnection/CreateSessionObserver.h +++ /dev/null @@ -1,26 +0,0 @@ -// -// Created by ax on 25/09/16. -// - -#ifndef LIBWEBRTC_CREATEOFFEROBSERVER_H -#define LIBWEBRTC_CREATEOFFEROBSERVER_H - -#include -#include "IPeer.h" - -class CreateSessionObserver: public webrtc::CreateSessionDescriptionObserver { -public: - CreateSessionObserver(IPeer *peer); - - void OnSuccess(webrtc::SessionDescriptionInterface* desc); - void OnFailure(const std::string& error); - -private: - IPeer *_peer; - -protected: - ~CreateSessionObserver() {} -}; - - -#endif //LIBWEBRTC_CREATEOFFEROBSERVER_H diff --git a/Samples/PeerConnection/DataChannelObserver.cpp b/Samples/PeerConnection/DataChannelObserver.cpp deleted file mode 100644 index 4de742f..0000000 --- a/Samples/PeerConnection/DataChannelObserver.cpp +++ /dev/null @@ -1,31 +0,0 @@ -// -// Created by ax on 25/09/16. -// - -#include "DataChannelObserver.h" -#include "Console.h" - - -DataChannelObserver::DataChannelObserver( - webrtc::DataChannelInterface *dataChannel): _dataChannel(dataChannel) { -} - -void DataChannelObserver::OnStateChange() { - Console::Print("[DataChannelObserver::OnStateChange] %s", - webrtc::DataChannelInterface::DataStateString(_dataChannel->state())); -} - -void DataChannelObserver::OnMessage(const webrtc::DataBuffer& buffer) { - size_t len = buffer.size(); - const unsigned char *data = buffer.data.cdata(); - char *message = new char[len + 1]; - - memcpy(message, data, len); - message[len] = '\0'; - - Console::Print(" %s", message); - delete[] message; -} - -void DataChannelObserver::OnBufferedAmountChange(uint64_t previous_amount) { -} diff --git a/Samples/PeerConnection/DataChannelObserver.h b/Samples/PeerConnection/DataChannelObserver.h deleted file mode 100644 index 607b116..0000000 --- a/Samples/PeerConnection/DataChannelObserver.h +++ /dev/null @@ -1,22 +0,0 @@ -// -// Created by ax on 25/09/16. -// - -#ifndef LIBWEBRTC_DATACHANNELOBSERVER_H -#define LIBWEBRTC_DATACHANNELOBSERVER_H - -#include - -class DataChannelObserver: public webrtc::DataChannelObserver { -public: - DataChannelObserver(webrtc::DataChannelInterface *dataChannel); - - void OnStateChange(); - void OnMessage(const webrtc::DataBuffer& buffer); - void OnBufferedAmountChange(uint64_t previous_amount); - -private: - webrtc::DataChannelInterface *_dataChannel; -}; - -#endif //LIBWEBRTC_DATACHANNELOBSERVER_H diff --git a/Samples/PeerConnection/IPeer.h b/Samples/PeerConnection/IPeer.h deleted file mode 100644 index 89ad821..0000000 --- a/Samples/PeerConnection/IPeer.h +++ /dev/null @@ -1,27 +0,0 @@ -// -// Created by ax on 26/09/16. -// - -#ifndef LIBWEBRTC_IPEER_H -#define LIBWEBRTC_IPEER_H - -#include "webrtc/api/peerconnectioninterface.h" - -class IPeer { -public: - virtual void CreateOffer(webrtc::CreateSessionDescriptionObserver *createSDPObserver) = 0; - virtual void CreateAnswer(webrtc::CreateSessionDescriptionObserver *createSDPObserver) = 0; - - virtual bool AddIceCandidate(webrtc::IceCandidateInterface *candidate) = 0; - - virtual void SetLocalSessionDescription(webrtc::SessionDescriptionInterface* desc, - webrtc::SetSessionDescriptionObserver *setSDPObserver) = 0; - virtual void SetRemoteSessionDescription(webrtc::SessionDescriptionInterface* desc, - webrtc::SetSessionDescriptionObserver *setSDPObserver) = 0; - - virtual bool IsConnected() = 0; - virtual void SetDataChannel(webrtc::DataChannelInterface *dataChannel) = 0; - virtual void SendMessage(const std::string& message) = 0; -}; - -#endif //LIBWEBRTC_IPEER_H diff --git a/Samples/PeerConnection/Peer.cpp b/Samples/PeerConnection/Peer.cpp deleted file mode 100644 index 384c580..0000000 --- a/Samples/PeerConnection/Peer.cpp +++ /dev/null @@ -1,115 +0,0 @@ -// -// Created by ax on 24/09/16. -// - -#include -#include - -#include "Core.h" -#include "DataChannelObserver.h" -#include "Peer.h" -#include "PeerConnectionObserver.h" - -using webrtc::DataChannelInit; -using webrtc::PeerConnectionInterface; -using webrtc::MediaConstraintsInterface; -using webrtc::SessionDescriptionInterface; - -using webrtc::MediaStreamInterface; -using webrtc::DataChannelInterface; -using webrtc::IceCandidateInterface; - -Peer::Peer() { - PeerConnectionInterface::RTCConfiguration config; - PeerConnectionInterface::IceServer googleIceServer; - - googleIceServer.uri = "stun:stun.l.google.com:19302"; - googleIceServer.urls.push_back("stun:stun.l.google.com:19302"); - googleIceServer.urls.push_back("stun:stun1.l.google.com:19302"); - googleIceServer.urls.push_back("stun:stun2.l.google.com:19302"); - googleIceServer.urls.push_back("stun:stun3.l.google.com:19302"); - googleIceServer.urls.push_back("stun:stun4.l.google.com:19302"); - - config.servers.push_back(googleIceServer); - - _dataChannel = NULL; - _dataChannelObserver = NULL; - _peerConnectionObserver = new PeerConnectionObserver(this); - _peerConnection = Core::GetPeerConnectionFactory()-> - CreatePeerConnection(config, &_mediaConstraints, - NULL, NULL, _peerConnectionObserver); - - _mediaConstraints.AddOptional( - MediaConstraintsInterface::kEnableDtlsSrtp, - MediaConstraintsInterface::kValueTrue); - - _mediaConstraints.AddMandatory( - MediaConstraintsInterface::kOfferToReceiveAudio, - MediaConstraintsInterface::kValueFalse); - - _mediaConstraints.AddMandatory( - MediaConstraintsInterface::kOfferToReceiveVideo, - MediaConstraintsInterface::kValueFalse); -} - -Peer::~Peer() { - if (_dataChannel) { - _dataChannel->Close(); - _dataChannel->UnregisterObserver(); - _dataChannel = NULL; - } - - _peerConnection->Close(); - _peerConnection = NULL; - - if (_dataChannelObserver) { - _dataChannelObserver = NULL; - } -} - -void Peer::CreateOffer(webrtc::CreateSessionDescriptionObserver *createSDPObserver) { - DataChannelInit init; - - init.reliable = true; - _dataChannel = _peerConnection->CreateDataChannel("MyDataChannel", &init); - _dataChannelObserver = new DataChannelObserver(_dataChannel); - _dataChannel->RegisterObserver(_dataChannelObserver); - - _peerConnection->CreateOffer(createSDPObserver, &_mediaConstraints); -} - -void Peer::CreateAnswer(webrtc::CreateSessionDescriptionObserver *createSDPObserver) { - _peerConnection->CreateAnswer(createSDPObserver, &_mediaConstraints); -} - -bool Peer::AddIceCandidate(webrtc::IceCandidateInterface *candidate) { - return _peerConnection->AddIceCandidate(candidate); -} - -void Peer::SetLocalSessionDescription(SessionDescriptionInterface* desc, - webrtc::SetSessionDescriptionObserver *obs) { - _peerConnection->SetLocalDescription(obs, desc); -} - -void Peer::SetRemoteSessionDescription(SessionDescriptionInterface* desc, - webrtc::SetSessionDescriptionObserver *obs) { - _peerConnection->SetRemoteDescription(obs, desc); -} - -bool Peer::IsConnected() { - if (!_dataChannel) { - return false; - } - - return _dataChannel->state() == webrtc::DataChannelInterface::kOpen; -} - -void Peer::SetDataChannel(webrtc::DataChannelInterface *dataChannel) { - _dataChannel = dataChannel; -} - -void Peer::SendMessage(const std::string& message) { - webrtc::DataBuffer buffer(message); - - _dataChannel->Send(buffer); -} \ No newline at end of file diff --git a/Samples/PeerConnection/Peer.h b/Samples/PeerConnection/Peer.h deleted file mode 100644 index f96039b..0000000 --- a/Samples/PeerConnection/Peer.h +++ /dev/null @@ -1,41 +0,0 @@ -// -// Created by ax on 24/09/16. -// - -#ifndef LIBWEBRTC_PEER_H -#define LIBWEBRTC_PEER_H - -#include -#include "webrtc/api/test/fakeconstraints.h" -#include "webrtc/api/peerconnectioninterface.h" - -#include "IPeer.h" - -class Peer: public IPeer { -public: - Peer(); - ~Peer(); - - void CreateOffer(webrtc::CreateSessionDescriptionObserver *createSDPObserver); - void CreateAnswer(webrtc::CreateSessionDescriptionObserver *createSDPObserver); - - bool AddIceCandidate(webrtc::IceCandidateInterface *candidate); - - void SetLocalSessionDescription(webrtc::SessionDescriptionInterface* desc, - webrtc::SetSessionDescriptionObserver *setSDPObserver); - void SetRemoteSessionDescription(webrtc::SessionDescriptionInterface* desc, - webrtc::SetSessionDescriptionObserver *setSDPObserver); - - bool IsConnected(); - void SetDataChannel(webrtc::DataChannelInterface *dataChannel); - void SendMessage(const std::string& message); - -private: - rtc::scoped_refptr _peerConnection; - webrtc::PeerConnectionObserver *_peerConnectionObserver; - webrtc::FakeConstraints _mediaConstraints; - rtc::scoped_refptr _dataChannel; - webrtc::DataChannelObserver *_dataChannelObserver; -}; - -#endif //LIBWEBRTC_PEER_H diff --git a/Samples/PeerConnection/PeerConnectionObserver.cpp b/Samples/PeerConnection/PeerConnectionObserver.cpp deleted file mode 100644 index 48d419d..0000000 --- a/Samples/PeerConnection/PeerConnectionObserver.cpp +++ /dev/null @@ -1,92 +0,0 @@ -// -// Created by ax on 25/09/16. -// - -#include -#include "DataChannelObserver.h" -#include "PeerConnectionObserver.h" -#include "Console.h" - -using webrtc::PeerConnectionInterface; -using webrtc::MediaStreamInterface; -using webrtc::DataChannelInterface; -using webrtc::IceCandidateInterface; - -PeerConnectionObserver::PeerConnectionObserver(IPeer *peer): - _peer(peer), _dataChannelObserver(NULL) { -} - -void PeerConnectionObserver::OnSignalingChange( - PeerConnectionInterface::SignalingState new_state) { - Console::Print("[PeerConnectionObserver::OnSignalingChange] new signaling state: %d", - new_state); -} - -void PeerConnectionObserver::OnAddStream(rtc::scoped_refptr stream) { - Console::Print("[PeerConnectionObserver::OnAddStream]"); -} - -void PeerConnectionObserver::OnRemoveStream(rtc::scoped_refptr stream) { - Console::Print("[PeerConnectionObserver::OnRemoveStream]"); -} - -void PeerConnectionObserver::OnDataChannel( - rtc::scoped_refptr data_channel) { - Console::Print("[PeerConnectionObserver::OnDataChannel] %s", data_channel->label().c_str()); - _dataChannelObserver = new DataChannelObserver(data_channel); - data_channel->RegisterObserver(_dataChannelObserver); - _peer->SetDataChannel(data_channel); -} - -void PeerConnectionObserver::OnRenegotiationNeeded() { -} - -void PeerConnectionObserver::OnIceConnectionChange( - PeerConnectionInterface::IceConnectionState new_state) { - if (new_state == PeerConnectionInterface::kIceConnectionCompleted) { - Console::Print("Connected!"); - } else if (new_state > PeerConnectionInterface::kIceConnectionCompleted) { - Console::Print("Disconnected."); - } -} - -void PeerConnectionObserver::OnIceGatheringChange( - PeerConnectionInterface::IceGatheringState new_state) { - if (new_state == PeerConnectionInterface::kIceGatheringGathering) { - Console::Print("Gathering ICE candidates, please wait."); - return; - } - - if (new_state != PeerConnectionInterface::kIceGatheringComplete) { - return; - } - - Json::FastWriter writer; - writer.write(_iceCandidates); - - Console::Print("Done, paste this array of ICE candidates once requested." \ - "\n\n%s", writer.write(_iceCandidates).c_str()); -} - -void PeerConnectionObserver::OnIceCandidate(const IceCandidateInterface* candidate) { - Json::Value jmessage; - - jmessage["sdpMid"] = candidate->sdp_mid(); - jmessage["sdpMLineIndex"] = candidate->sdp_mline_index(); - std::string sdp; - if (!candidate->ToString(&sdp)) { - Console::Print("[PeerConnectionObserver::OnIceCandidate] Failed to serialize candidate"); - return; - } - jmessage["candidate"] = sdp; - _iceCandidates.append(jmessage); -} - -void PeerConnectionObserver::OnIceCandidatesRemoved( - const std::vector& candidates) { - Console::Print("[PeerConnectionObserver::OnIceCandidatesRemoved]"); - -} - -void PeerConnectionObserver::OnIceConnectionReceivingChange(bool receiving) { -} \ No newline at end of file diff --git a/Samples/PeerConnection/PeerConnectionObserver.h b/Samples/PeerConnection/PeerConnectionObserver.h deleted file mode 100644 index 0cc14df..0000000 --- a/Samples/PeerConnection/PeerConnectionObserver.h +++ /dev/null @@ -1,44 +0,0 @@ -// -// Created by ax on 25/09/16. -// - -#ifndef LIBWEBRTC_PEERCONNECTIONOBSERVER_H -#define LIBWEBRTC_PEERCONNECTIONOBSERVER_H - -#include -#include -#include "IPeer.h" - -class PeerConnectionObserver: public webrtc::PeerConnectionObserver { -public: - PeerConnectionObserver(IPeer *peer); - - void OnSignalingChange( - webrtc::PeerConnectionInterface::SignalingState new_state); - - void OnAddStream(rtc::scoped_refptr stream); - void OnRemoveStream(rtc::scoped_refptr stream); - - void OnDataChannel( - rtc::scoped_refptr data_channel); - - void OnRenegotiationNeeded(); - - void OnIceConnectionChange( - webrtc::PeerConnectionInterface::IceConnectionState new_state); - void OnIceGatheringChange( - webrtc::PeerConnectionInterface::IceGatheringState new_state); - - void OnIceCandidate(const webrtc::IceCandidateInterface* candidate); - void OnIceCandidatesRemoved( - const std::vector& candidates); - void OnIceConnectionReceivingChange(bool receiving); - -private: - IPeer *_peer; - webrtc::DataChannelObserver *_dataChannelObserver; - Json::Value _iceCandidates; -}; - - -#endif //LIBWEBRTC_PEERCONNECTIONOBSERVER_H diff --git a/Samples/PeerConnection/SetLocalSessionDescriptionObserver.cpp b/Samples/PeerConnection/SetLocalSessionDescriptionObserver.cpp deleted file mode 100644 index 68836a4..0000000 --- a/Samples/PeerConnection/SetLocalSessionDescriptionObserver.cpp +++ /dev/null @@ -1,30 +0,0 @@ -// -// Created by ax on 25/09/16. -// - -#include -#include "SetLocalSessionDescriptionObserver.h" -#include "Console.h" - -SetLocalSessionDescriptionObserver::SetLocalSessionDescriptionObserver( - webrtc::SessionDescriptionInterface* desc): _desc(desc) { -} - -void SetLocalSessionDescriptionObserver::OnSuccess() { - std::string sdp; - - _desc->ToString(&sdp); - - Json::FastWriter writer; - Json::Value jmessage; - jmessage["type"] = _desc->type(); - jmessage["sdp"] = sdp; - - Console::Print("Here is the SDP, paste it to the remote client and paste " \ - "their answer here.\n\n%s", writer.write(jmessage).c_str()); -} - -void SetLocalSessionDescriptionObserver::OnFailure(const std::string& error) { - Console::Print("[SetLocalSessionDescriptionObserver::OnFailure] %s", - error.c_str()); -} \ No newline at end of file diff --git a/Samples/PeerConnection/SetLocalSessionDescriptionObserver.h b/Samples/PeerConnection/SetLocalSessionDescriptionObserver.h deleted file mode 100644 index 49a3cc2..0000000 --- a/Samples/PeerConnection/SetLocalSessionDescriptionObserver.h +++ /dev/null @@ -1,27 +0,0 @@ -// -// Created by ax on 25/09/16. -// - -#ifndef LIBWEBRTC_SETLOCALSESSIONDESCRIPTIONOBSERVER_H -#define LIBWEBRTC_SETLOCALSESSIONDESCRIPTIONOBSERVER_H - - -#include - -class SetLocalSessionDescriptionObserver: - public webrtc::SetSessionDescriptionObserver { -public: - SetLocalSessionDescriptionObserver(webrtc::SessionDescriptionInterface* desc); - - void OnSuccess(); - void OnFailure(const std::string& error); - -private: - webrtc::SessionDescriptionInterface* _desc; - -protected: - ~SetLocalSessionDescriptionObserver() {} -}; - - -#endif //LIBWEBRTC_SETLOCALSESSIONDESCRIPTIONOBSERVER_H diff --git a/Samples/PeerConnection/SetRemoteSessionDescriptionObserver.cpp b/Samples/PeerConnection/SetRemoteSessionDescriptionObserver.cpp deleted file mode 100644 index 0324a29..0000000 --- a/Samples/PeerConnection/SetRemoteSessionDescriptionObserver.cpp +++ /dev/null @@ -1,27 +0,0 @@ -// -// Created by ax on 25/09/16. -// - -#include "SetRemoteSessionDescriptionObserver.h" -#include "CreateSessionObserver.h" -#include "Console.h" - - -SetRemoteSessionDescriptionObserver::SetRemoteSessionDescriptionObserver( - IPeer *peer, webrtc::SessionDescriptionInterface* desc): - _peer(peer), _desc(desc) { -} - -void SetRemoteSessionDescriptionObserver::OnSuccess() { - if (_desc->type() == webrtc::SessionDescriptionInterface::kOffer) { - rtc::scoped_refptr createAnswerObserver = - new rtc::RefCountedObject(_peer); - - _peer->CreateAnswer(createAnswerObserver); - } -} - -void SetRemoteSessionDescriptionObserver::OnFailure(const std::string& error) { - Console::Print("[SetRemoteSessionDescriptionObserver::OnFailure] %s", - error.c_str()); -} diff --git a/Samples/PeerConnection/SetRemoteSessionDescriptionObserver.h b/Samples/PeerConnection/SetRemoteSessionDescriptionObserver.h deleted file mode 100644 index 0102086..0000000 --- a/Samples/PeerConnection/SetRemoteSessionDescriptionObserver.h +++ /dev/null @@ -1,28 +0,0 @@ -// -// Created by ax on 25/09/16. -// - -#ifndef LIBWEBRTC_SETREMOTESESSIONDESCRIPTIONOBSERVER_H -#define LIBWEBRTC_SETREMOTESESSIONDESCRIPTIONOBSERVER_H - -#include -#include "IPeer.h" - -class SetRemoteSessionDescriptionObserver: - public webrtc::SetSessionDescriptionObserver { -public: - SetRemoteSessionDescriptionObserver(IPeer *peer, webrtc::SessionDescriptionInterface* desc); - - void OnSuccess(); - void OnFailure(const std::string& error); - -private: - IPeer *_peer; - webrtc::SessionDescriptionInterface* _desc; - -protected: - ~SetRemoteSessionDescriptionObserver() {} -}; - - -#endif //LIBWEBRTC_SETREMOTESESSIONDESCRIPTIONOBSERVER_H diff --git a/Samples/PeerConnection/UnixConsole.cpp b/Samples/PeerConnection/UnixConsole.cpp deleted file mode 100644 index a0ac439..0000000 --- a/Samples/PeerConnection/UnixConsole.cpp +++ /dev/null @@ -1,153 +0,0 @@ -// -// Created by ax on 25/09/16. -// - -#include -#include -#include -#include -#include -#include -#include -#include -#include "Console.h" - -static int ttyErase; -static int ttyEof; -static struct termios ttyTc; - -static size_t cursor; -static std::string buffer; - -bool Console::Init() { - struct termios tc; - const char* term = getenv("TERM"); - - signal(SIGTTIN, SIG_IGN); - signal(SIGTTOU, SIG_IGN); - signal(SIGCONT, Console::Reset); - fcntl(STDIN_FILENO, F_SETFL, fcntl(STDIN_FILENO, F_GETFL, 0) | O_NONBLOCK ); - - if (!(isatty(STDIN_FILENO) && - !(term && (!strcmp(term, "raw") || !strcmp(term, "dumb"))))) { - std::cerr << "Input is not a tty." << std::endl; - return false; - } - - tcgetattr (STDIN_FILENO, &ttyTc); - ttyErase = ttyTc.c_cc[VERASE]; - ttyEof = ttyTc.c_cc[VEOF]; - - tc = ttyTc; - tc.c_lflag &= ~(ECHO | ICANON); - tc.c_iflag &= ~(ISTRIP | INPCK); - tc.c_cc[VMIN] = 1; - tc.c_cc[VTIME] = 0; - tcsetattr (STDIN_FILENO, TCSADRAIN, &tc); - - cursor = 0; - buffer.clear(); - return true; -} - -bool Console::Update(std::string &input) { - char key; - ssize_t avail = read(STDIN_FILENO, &key, 1); - - input.clear(); - if (avail == -1) { - return true; - } - - if (key == ttyEof) { - return false; - } - - if (((key == ttyErase) || (key == 127) || (key == 8)) && cursor > 0) - { - buffer.erase(--cursor, 1); - Console::Back(); - return true; - } - - if (key == '\n') { - input = buffer; - cursor = 0; - buffer.clear(); - - write(STDOUT_FILENO, &key, 1); - key = '>'; - write(STDOUT_FILENO, &key, 1); - key = ' '; - write(STDOUT_FILENO, &key, 1); - return true; - } - - if (key < ' ') { - return true; - } - - cursor++; - buffer.append(1, key); - write(STDOUT_FILENO, &key, 1); - return true; -} - -void Console::Cleanup() { - tcsetattr (STDIN_FILENO, TCSADRAIN, &ttyTc); - fcntl(STDIN_FILENO, F_SETFL, fcntl(STDIN_FILENO, F_GETFL, 0) & ~O_NONBLOCK); -} - -void Console::Reset(int num) { - Console::Init(); -} - -void Console::Show() { - char key; - - key = '>'; - write(STDOUT_FILENO, &key, 1); - key = ' '; - write(STDOUT_FILENO, &key, 1); - - - for (size_t i = 0; i < cursor; i++) { - key = buffer.at(i); - write(STDOUT_FILENO, &key, 1); - } -} - -void Console::Hide() { - for (int i = 0; i < cursor + 2; i++) { - Console::Back(); - } -} - -void Console::Print(const std::string &fmt, ...) { - va_list argptr; - char string[1024]; - - if (!fmt.length()) { - return; - } - - va_start(argptr, fmt); - vsnprintf(string, sizeof(string), fmt.c_str(), argptr); - va_end(argptr); - - Console::Hide(); - std::cout << string << std::endl; - Console::Show(); -} - -void Console::Back() -{ - char key; - - key = '\b'; - write(STDOUT_FILENO, &key, 1); - key = ' '; - write(STDOUT_FILENO, &key, 1); - key = '\b'; - write(STDOUT_FILENO, &key, 1); -} diff --git a/Samples/PeerConnection/Win32Console.cpp b/Samples/PeerConnection/Win32Console.cpp deleted file mode 100644 index 95bd42c..0000000 --- a/Samples/PeerConnection/Win32Console.cpp +++ /dev/null @@ -1,195 +0,0 @@ -#include -#include -#include -#include "Console.h" - -#define MAX_EDIT_LINE 32768 - -static HANDLE hOUT; -static HANDLE hIN; - -static DWORD dMode; -static WORD wAttrib; -static CONSOLE_CURSOR_INFO cursorInfo; - -static size_t cursor; -static std::string buffer; - -bool Console::Init() { - CONSOLE_CURSOR_INFO curs; - CONSOLE_SCREEN_BUFFER_INFO info; - - hIN = GetStdHandle(STD_INPUT_HANDLE); - if (hIN == INVALID_HANDLE_VALUE) { - return false; - } - - hOUT = GetStdHandle(STD_OUTPUT_HANDLE); - if (hOUT == INVALID_HANDLE_VALUE) { - return false; - } - - GetConsoleMode(hIN, &dMode); - SetConsoleMode(hIN, dMode & ~ENABLE_MOUSE_INPUT); - - FlushConsoleInputBuffer(hIN); - - GetConsoleScreenBufferInfo(hOUT, &info); - wAttrib = info.wAttributes; - - GetConsoleCursorInfo(hOUT, &cursorInfo); - curs.dwSize = 1; - curs.bVisible = FALSE; - SetConsoleCursorInfo(hOUT, &curs); - - cursor = 0; - buffer.clear(); - return true; -} - -bool Console::Update(std::string &input) { - INPUT_RECORD *buff; - DWORD count; - DWORD events; - char key; - int newline = -1; - int i; - - input.clear(); - if (!GetNumberOfConsoleInputEvents(hIN, &events)) { - return true; - } - - if (events < 1) { - return true; - } - - buff = new INPUT_RECORD[events]; - if (!ReadConsoleInput(hIN, buff, events, &count)) { - delete[] buff; - return true; - } - - if (count < 1) { - delete[] buff; - return true; - } - - FlushConsoleInputBuffer(hIN); - - for (i = 0; i < count; i++) { - if (buff[i].EventType != KEY_EVENT) { - continue; - } - - if (!buff[i].Event.KeyEvent.bKeyDown) { - continue; - } - - key = buff[i].Event.KeyEvent.wVirtualKeyCode; - - if (key == VK_RETURN) { - newline = i; - break; - } else if (key == VK_BACK) { - buffer.erase(--cursor, 1); - } - - char c = buff[i].Event.KeyEvent.uChar.AsciiChar; - - if (c) { - cursor++; - buffer.append(1, c); - } - } - - delete[] buff; - Console::Show(); - - if (newline < 0) { - return true; - } - newline = 0; - - if (!buffer.length()) - { - std::cout << std::endl; - return true; - } - - std::cout << buffer.c_str() << std::endl; - - input = buffer; - cursor = 0; - buffer.clear(); - return true; -} - -void Console::Cleanup() { - SetConsoleMode(hIN, dMode); - SetConsoleCursorInfo(hOUT, &cursorInfo); - CloseHandle(hOUT); - CloseHandle(hIN); -} - -void Console::Reset(int num) { - Console::Init(); -} - -void Console::Show() { - int i; - CONSOLE_SCREEN_BUFFER_INFO binfo; - COORD writeSize = { MAX_EDIT_LINE, 1 }; - COORD writePos = { 0, 0 }; - SMALL_RECT writeArea = { 0, 0, 0, 0 }; - CHAR_INFO line[MAX_EDIT_LINE]; - - GetConsoleScreenBufferInfo(hOUT, &binfo); - - if (binfo.dwCursorPosition.X != 0) { - return; - } - - writeArea.Left = 0; - writeArea.Top = binfo.dwCursorPosition.Y; - writeArea.Bottom = binfo.dwCursorPosition.Y; - writeArea.Right = MAX_EDIT_LINE; - - for (i = 0; i < MAX_EDIT_LINE; i++) { - if (i < buffer.length()) - line[i].Char.AsciiChar = buffer.at(i); - else - line[i].Char.AsciiChar = ' '; - - line[i].Attributes = wAttrib; - } - - if (buffer.length() > binfo.srWindow.Right) { - WriteConsoleOutput(hOUT, line + (buffer.length() - binfo.srWindow.Right), - writeSize, writePos, &writeArea); - } else { - WriteConsoleOutput(hOUT, line, writeSize, writePos, &writeArea); - } -} - -void Console::Hide() { -} - -void Console::Print(const std::string &fmt, ...) { - va_list argptr; - char string[1024]; - - if (!fmt.length()) { - return; - } - - va_start(argptr, fmt); - vsnprintf(string, sizeof(string), fmt.c_str(), argptr); - va_end(argptr); - - std::cout << string << std::endl; - Console::Show(); -} - -void Console::Back() { -} \ No newline at end of file diff --git a/Samples/PeerConnection/main.cpp b/Samples/PeerConnection/main.cpp deleted file mode 100644 index 6022b2c..0000000 --- a/Samples/PeerConnection/main.cpp +++ /dev/null @@ -1,134 +0,0 @@ -#include -#include -#include "Core.h" -#include "CreateSessionObserver.h" -#include "DataChannelObserver.h" -#include "Peer.h" -#include "SetRemoteSessionDescriptionObserver.h" -#include "Console.h" - -static IPeer *peer = NULL; - -void HandleSDP(Json::Value object) { - std::string type = object["type"].asString(); - std::string sdp = object["sdp"].asString(); - - webrtc::SdpParseError error; - webrtc::SessionDescriptionInterface* desc( - webrtc::CreateSessionDescription(type, sdp, &error)); - - if (!desc) { - Console::Print("Can't parse the SDP: %s", error.description.c_str()); - return; - } - - rtc::scoped_refptr observer = - new rtc::RefCountedObject(peer, desc); - - peer->SetRemoteSessionDescription(desc, observer); -} - -void HandleICECandidate(Json::Value object) { - std::string sdp_mid = object["sdpMid"].asString(); - int sdp_mlineindex = object["sdpMLineIndex"].asInt(); - std::string sdp = object["candidate"].asString(); - - webrtc::SdpParseError error; - std::unique_ptr candidate( - webrtc::CreateIceCandidate(sdp_mid, sdp_mlineindex, sdp, &error)); - - if (!candidate.get()) { - Console::Print("Can't parse the ICE candidate: %s", error.description.c_str()); - return; - } - - if (!peer->AddIceCandidate(candidate.get())) { - Console::Print("Failed to add the ICE candidate."); - return; - } -} - -void HandleObject(Json::Value object) { - if (object.isMember("type") && object["type"].isString() && - object.isMember("sdp") && object["sdp"].isString()) { - HandleSDP(object); - return; - } - - if (object.isMember("candidate") && object["candidate"].isString() && - object.isMember("sdpMLineIndex") && object["sdpMLineIndex"].isNumeric() && - object.isMember("sdpMid") && object["sdpMid"].isString()) { - HandleICECandidate(object); - return; - } - - Console::Print("Unknown object."); -} - -void HandleCommand(const std::string& input) { - Json::Reader reader; - Json::Value jmessage; - - if (peer->IsConnected()) { - peer->SendMessage(input); - return; - } - - if (!reader.parse(input, jmessage)) { - Console::Print("Invalid JSON string."); - return; - } - - if (jmessage.isArray()) { - for (Json::ValueIterator it = jmessage.begin(); - it != jmessage.end(); it++) { - if (!(*it).isObject()) { - continue; - } - - HandleObject(*it); - } - return; - } - - if (jmessage.isObject()) { - HandleObject(jmessage); - return; - } - - Console::Print("Must be an array or object."); -} - -int main(int argc, char **argv) { - std::string input; - - if (!Console::Init()) { - return EXIT_FAILURE; - } - - Core::Init(); - - peer = new Peer(); - - if (argc == 1) { - rtc::scoped_refptr createOfferObserver = - new rtc::RefCountedObject(peer); - - peer->CreateOffer(createOfferObserver); - } else { - Console::Print("Recipient mode. Paste the offer made by the emitter.\n"); - } - - while (Console::Update(input)) { - if (input.length()) { - HandleCommand(input); - } - Core::Update(); - } - - delete peer; - - Core::Cleanup(); - Console::Cleanup(); - return EXIT_SUCCESS; -}