no message
parent
830fa0daa0
commit
40e97d314b
|
@ -36,6 +36,21 @@
|
||||||
#include "modules/video_capture/video_capture_factory.h"
|
#include "modules/video_capture/video_capture_factory.h"
|
||||||
#include "peer_connection.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 std;
|
||||||
using namespace rtc;
|
using namespace rtc;
|
||||||
|
|
||||||
|
@ -122,8 +137,22 @@ class VideoRoomClient :
|
||||||
public PeerConnectionCallback ,
|
public PeerConnectionCallback ,
|
||||||
public sigslot::has_slots<>{
|
public sigslot::has_slots<>{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
|
||||||
VideoRoomClient() {
|
VideoRoomClient() {
|
||||||
mWsClient = new PeerConnectionWsClient();
|
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) {
|
void SendBitrateConstraint(long long int handleId) {
|
||||||
std::string transactionID = RandomString(12);
|
std::string transactionID = RandomString(12);
|
||||||
|
@ -232,7 +261,7 @@ public:
|
||||||
std::move(video_device), nullptr)));
|
std::move(video_device), nullptr)));
|
||||||
//main_wnd_->StartLocalRenderer(video_track_);
|
//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 });
|
result_or_error = m_peer_connection_map[handleId]->peer_connection_->AddTrack(video_track_, { kStreamId });
|
||||||
if (!result_or_error.ok()) {
|
if (!result_or_error.ok()) {
|
||||||
|
@ -295,8 +324,10 @@ public:
|
||||||
|
|
||||||
if (!peer_connection_factory_) {
|
if (!peer_connection_factory_) {
|
||||||
peer_connection_factory_ = webrtc::CreatePeerConnectionFactory(
|
peer_connection_factory_ = webrtc::CreatePeerConnectionFactory(
|
||||||
nullptr /* network_thread */, nullptr /* worker_thread */,
|
this->m_network_thread.get() /* network_thread */,
|
||||||
nullptr /* signaling_thread */, nullptr /* default_adm */,
|
this->m_worker_thread.get() /* worker_thread */,
|
||||||
|
this->m_signaling_thread.get() /* signaling_thread */,
|
||||||
|
nullptr /* default_adm */,
|
||||||
webrtc::CreateBuiltinAudioEncoderFactory(),
|
webrtc::CreateBuiltinAudioEncoderFactory(),
|
||||||
webrtc::CreateBuiltinAudioDecoderFactory(),
|
webrtc::CreateBuiltinAudioDecoderFactory(),
|
||||||
webrtc::CreateBuiltinVideoEncoderFactory(),
|
webrtc::CreateBuiltinVideoEncoderFactory(),
|
||||||
|
@ -485,8 +516,47 @@ public:
|
||||||
//beacause the thread is on UI,so shift thread to ws thread
|
//beacause the thread is on UI,so shift thread to ws thread
|
||||||
mWsClient->SendToJanusAsync(writer.write(jmessage));
|
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:
|
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") {
|
if (sdpType == "offer") {
|
||||||
SendOffer(handleId, sdpType, sdp);
|
SendOffer(handleId, sdpType, sdp);
|
||||||
}
|
}
|
||||||
|
@ -495,12 +565,19 @@ protected:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
virtual void PCQueueUIThreadCallback(int msg_id, void* data) {
|
virtual void PCQueueUIThreadCallback(int msg_id, void* data) {
|
||||||
|
std::cout << msg_id<<std::endl;
|
||||||
|
UIThreadCallback(msg_id,
|
||||||
|
data);
|
||||||
}
|
}
|
||||||
virtual void PCTrickleCandidate(long long int handleId, const webrtc::IceCandidateInterface* candidate) {
|
virtual void PCTrickleCandidate(long long int handleId, const webrtc::IceCandidateInterface* candidate) {
|
||||||
|
std::cout << "PCTrickleCandidate" << std::endl;
|
||||||
|
trickleCandidate(handleId, candidate);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void PCTrickleCandidateComplete(long long int handleId) {
|
virtual void PCTrickleCandidateComplete(long long int handleId) {
|
||||||
|
std::cout << "PCTrickleCandidateComplete" << std::endl;
|
||||||
|
trickleCandidateComplete(handleId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -633,6 +710,9 @@ private:
|
||||||
|
|
||||||
void KeepAlive()
|
void KeepAlive()
|
||||||
{
|
{
|
||||||
|
auto signaling_thread_ = rtc::Thread::Create();
|
||||||
|
signaling_thread_->SetName("signaling_thread", nullptr);
|
||||||
|
signaling_thread_->Start();
|
||||||
if (m_SessionId > 0) {
|
if (m_SessionId > 0) {
|
||||||
std::string transactionID = RandomString(12);
|
std::string transactionID = RandomString(12);
|
||||||
Json::StyledWriter writer;
|
Json::StyledWriter writer;
|
||||||
|
@ -796,6 +876,11 @@ private:
|
||||||
std::map<long long int, std::shared_ptr<JanusHandle>> m_handleMap;
|
std::map<long long int, std::shared_ptr<JanusHandle>> m_handleMap;
|
||||||
std::map<long long int, rtc::scoped_refptr<PeerConnection>> m_peer_connection_map;
|
std::map<long long int, rtc::scoped_refptr<PeerConnection>> m_peer_connection_map;
|
||||||
rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> peer_connection_factory_;
|
rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> peer_connection_factory_;
|
||||||
|
std::unique_ptr<Thread> m_signaling_thread;
|
||||||
|
std::unique_ptr<Thread> m_worker_thread;
|
||||||
|
std::unique_ptr<Thread> m_network_thread;
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class ImplPeerConnectionWsClientObserver :
|
class ImplPeerConnectionWsClientObserver :
|
||||||
|
@ -811,10 +896,29 @@ public:
|
||||||
|
|
||||||
int main()
|
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<Thread> signaling_thread_ = rtc::Thread::Create();
|
||||||
|
signaling_thread_->SetName("signaling_thread", nullptr);
|
||||||
|
signaling_thread_->Start();
|
||||||
|
|
||||||
VideoRoomClient*client = new VideoRoomClient();
|
VideoRoomClient*client = new VideoRoomClient();
|
||||||
|
|
||||||
client->ConectToServer("janusdemo.com", 8188);
|
client->ConectToServer("janusdemo.com", 8188);
|
||||||
while (true) {
|
while (true) {
|
||||||
Sleep(1000);
|
Sleep(1000);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue