diff --git a/client/janus_gateway_win/usocket_test/usocket_test.cpp b/client/janus_gateway_win/usocket_test/usocket_test.cpp index 04fb09f..8dc8bc4 100644 --- a/client/janus_gateway_win/usocket_test/usocket_test.cpp +++ b/client/janus_gateway_win/usocket_test/usocket_test.cpp @@ -36,6 +36,21 @@ #include "modules/video_capture/video_capture_factory.h" #include "peer_connection.h" + +#include "rtc_base/arraysize.h" +#include "rtc_base/checks.h" +#include "rtc_base/logging.h" +#include "rtc_base/stringutils.h" +#include "rtc_base/win32socketserver.h" +#include "rtc_base/win32socketinit.h" + +#include "third_party/libyuv/include/libyuv/convert_argb.h" + +#if defined(WEBRTC_WIN) +#include "rtc_base/win32.h" +#endif // WEBRTC_WIN + + using namespace std; using namespace rtc; @@ -122,8 +137,22 @@ class VideoRoomClient : public PeerConnectionCallback , public sigslot::has_slots<>{ public: + + VideoRoomClient() { mWsClient = new PeerConnectionWsClient(); + + m_network_thread = rtc::Thread::CreateWithSocketServer(); + m_network_thread->SetName("network_thread", nullptr); + m_network_thread->Start(); + + m_worker_thread = rtc::Thread::Create(); + m_worker_thread->SetName("worker_thread", nullptr); + m_worker_thread->Start(); + + m_signaling_thread = rtc::Thread::Create(); + m_signaling_thread->SetName("signaling_thread", nullptr); + m_signaling_thread->Start(); } void SendBitrateConstraint(long long int handleId) { std::string transactionID = RandomString(12); @@ -232,7 +261,7 @@ public: std::move(video_device), nullptr))); //main_wnd_->StartLocalRenderer(video_track_); // - m_peer_connection_map[handleId]->StartRenderer(MainWnd_, video_track_); + //m_peer_connection_map[handleId]->StartRenderer(MainWnd_, video_track_); result_or_error = m_peer_connection_map[handleId]->peer_connection_->AddTrack(video_track_, { kStreamId }); if (!result_or_error.ok()) { @@ -295,8 +324,10 @@ public: if (!peer_connection_factory_) { peer_connection_factory_ = webrtc::CreatePeerConnectionFactory( - nullptr /* network_thread */, nullptr /* worker_thread */, - nullptr /* signaling_thread */, nullptr /* default_adm */, + this->m_network_thread.get() /* network_thread */, + this->m_worker_thread.get() /* worker_thread */, + this->m_signaling_thread.get() /* signaling_thread */, + nullptr /* default_adm */, webrtc::CreateBuiltinAudioEncoderFactory(), webrtc::CreateBuiltinAudioDecoderFactory(), webrtc::CreateBuiltinVideoEncoderFactory(), @@ -485,8 +516,47 @@ public: //beacause the thread is on UI,so shift thread to ws thread mWsClient->SendToJanusAsync(writer.write(jmessage)); } + void trickleCandidate(long long int handleId, const webrtc::IceCandidateInterface* candidate) { + std::string transactionID = RandomString(12); + Json::StyledWriter writer; + Json::Value jmessage; + Json::Value jcandidate; + + std::string sdp; + if (!candidate->ToString(&sdp)) { + RTC_LOG(LS_ERROR) << "Failed to serialize candidate"; + return; + } + + jcandidate["sdpMid"] = candidate->sdp_mid(); + jcandidate["sdpMLineIndex"] = candidate->sdp_mline_index(); + jcandidate["candidate"] = sdp; + + jmessage["janus"] = "trickle"; + jmessage["candidate"] = jcandidate; + jmessage["transaction"] = transactionID; + jmessage["session_id"] = m_SessionId; + jmessage["handle_id"] = handleId; + mWsClient->SendToJanusAsync(writer.write(jmessage)); + } + void trickleCandidateComplete(long long int handleId) { + std::string transactionID = RandomString(12); + Json::StyledWriter writer; + Json::Value jmessage; + Json::Value jcandidate; + + jcandidate["completed"] = true; + + jmessage["janus"] = "trickle"; + jmessage["candidate"] = jcandidate; + jmessage["transaction"] = transactionID; + jmessage["session_id"] = m_SessionId; + jmessage["handle_id"] = handleId; + mWsClient->SendToJanusAsync(writer.write(jmessage)); + } + protected: - virtual void PCSendSDP(long long int handleId, std::string sdpType, std::string sdp) { + void PCSendSDP(long long int handleId, std::string sdpType, std::string sdp) { if (sdpType == "offer") { SendOffer(handleId, sdpType, sdp); } @@ -495,12 +565,19 @@ protected: } } virtual void PCQueueUIThreadCallback(int msg_id, void* data) { - + std::cout << msg_id<SetName("signaling_thread", nullptr); + signaling_thread_->Start(); if (m_SessionId > 0) { std::string transactionID = RandomString(12); Json::StyledWriter writer; @@ -796,6 +876,11 @@ private: std::map> m_handleMap; std::map> m_peer_connection_map; rtc::scoped_refptr peer_connection_factory_; + std::unique_ptr m_signaling_thread; + std::unique_ptr m_worker_thread; + std::unique_ptr m_network_thread; + + }; class ImplPeerConnectionWsClientObserver : @@ -811,10 +896,29 @@ public: int main() { + rtc::EnsureWinsockInit(); + rtc::Win32SocketServer w32_ss; + rtc::Win32Thread w32_thread(&w32_ss); + rtc::ThreadManager::Instance()->SetCurrentThread(&w32_thread); + + auto network_thread_ = rtc::Thread::CreateWithSocketServer(); + network_thread_->SetName("network_thread", nullptr); + network_thread_->Start(); + + auto worker_thread_ = rtc::Thread::Create(); + worker_thread_->SetName("worker_thread", nullptr); + worker_thread_->Start(); + + std::unique_ptr signaling_thread_ = rtc::Thread::Create(); + signaling_thread_->SetName("signaling_thread", nullptr); + signaling_thread_->Start(); + VideoRoomClient*client = new VideoRoomClient(); + client->ConectToServer("janusdemo.com", 8188); while (true) { Sleep(1000); + } }