添加log

master
zcy 2021-12-14 23:49:52 +08:00
parent 9e1a4a28e6
commit 3117075bf0
9 changed files with 1512 additions and 363 deletions

View File

@ -3,9 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.31729.503
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "janus_win", "janus_win\janus_win.vcxproj", "{121B3566-75A1-4A81-ACA3-744FA6044718}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "usocket_test", "usocket_test\usocket_test.vcxproj", "{7921778A-8D53-4646-917C-C32D58D691B6}"
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "video_room_client", "usocket_test\usocket_test.vcxproj", "{7921778A-8D53-4646-917C-C32D58D691B6}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -15,14 +13,6 @@ Global
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{121B3566-75A1-4A81-ACA3-744FA6044718}.Debug|x64.ActiveCfg = Debug|x64
{121B3566-75A1-4A81-ACA3-744FA6044718}.Debug|x64.Build.0 = Debug|x64
{121B3566-75A1-4A81-ACA3-744FA6044718}.Debug|x86.ActiveCfg = Debug|Win32
{121B3566-75A1-4A81-ACA3-744FA6044718}.Debug|x86.Build.0 = Debug|Win32
{121B3566-75A1-4A81-ACA3-744FA6044718}.Release|x64.ActiveCfg = Release|x64
{121B3566-75A1-4A81-ACA3-744FA6044718}.Release|x64.Build.0 = Release|x64
{121B3566-75A1-4A81-ACA3-744FA6044718}.Release|x86.ActiveCfg = Release|Win32
{121B3566-75A1-4A81-ACA3-744FA6044718}.Release|x86.Build.0 = Release|Win32
{7921778A-8D53-4646-917C-C32D58D691B6}.Debug|x64.ActiveCfg = Debug|x64
{7921778A-8D53-4646-917C-C32D58D691B6}.Debug|x64.Build.0 = Debug|x64
{7921778A-8D53-4646-917C-C32D58D691B6}.Debug|x86.ActiveCfg = Debug|Win32

View File

@ -276,7 +276,6 @@ void ConductorWs::UIThreadCallback(int msg_id, void* data) {
auto* track = reinterpret_cast<webrtc::MediaStreamTrackInterface*>(pTrack->pInterface);
if (track->kind() == webrtc::MediaStreamTrackInterface::kVideoKind) {
auto* video_track = static_cast<webrtc::VideoTrackInterface*>(track);
//main_wnd_->StartRemoteRenderer(video_track);
m_peer_connection_map[handleId]->StartRenderer(MainWnd_, video_track);
}
track->Release();

View File

@ -23,6 +23,15 @@
#include "rtc_base/json.h"
#include "rtc_base/logging.h"
#include "rtc_base/refcount.h"
#include "..\usocket_test\peer_connection.h"
std::string IceGatheringStateName(webrtc::PeerConnectionInterface::IceGatheringState w);
std::string IceConnectionStateName(webrtc::PeerConnectionInterface::IceConnectionState w);
enum CallbackID {
MEDIA_CHANNELS_INITIALIZED = 1,
@ -124,11 +133,15 @@ protected:
rtc::scoped_refptr<webrtc::DataChannelInterface> channel) override {}
void OnRenegotiationNeeded() override {}
void OnIceConnectionChange(
webrtc::PeerConnectionInterface::IceConnectionState new_state) override {};
void OnIceGatheringChange(
webrtc::PeerConnectionInterface::IceGatheringState new_state) override {};
webrtc::PeerConnectionInterface::IceConnectionState new_state) override ;
void OnIceConnectionChange(webrtc::PeerConnectionInterface::IceConnectionState new_state) override;
void OnIceGatheringChange(webrtc::PeerConnectionInterface::IceGatheringState new_state) override {
RTC_LOG(WARNING) << "OnIceGatheringChange " << IceGatheringStateName(new_state);
};
void OnIceCandidate(const webrtc::IceCandidateInterface* candidate) override;
void OnIceConnectionReceivingChange(bool receiving) override {}
void OnIceConnectionReceivingChange(bool receiving) override {
RTC_LOG(WARNING) << "OnIceConnectionReceivingChange " << receiving;
}
// CreateSessionDescriptionObserver implementation.
void OnSuccess(webrtc::SessionDescriptionInterface* desc) override;

File diff suppressed because it is too large Load Diff

View File

@ -1,7 +1,4 @@
// usocket_test.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//
#include <iostream>
#include <iostream>
#include "defaults.h"
#include "uWS.h"
#include <iostream>
@ -30,10 +27,69 @@
#include "rtc_base/win32.h"
#endif // WEBRTC_WIN
void ConfigWebrtcFileLog() {
class FileLog : public rtc::LogSink {
public:
FileLog(const std::string& LogPath)
:logfile_(NULL),
log_path_(LogPath) {}
virtual ~FileLog() {
if (logfile_) {
fclose(logfile_);
logfile_ = NULL;
}
}
inline void Start(void)
{
#define MAX_LOG_FILE_SIZE (1024*1024)
if (NULL == logfile_) {
logfile_ = fopen(logfileName_.c_str(), "w");
}
}
inline void Close(void)
{
if (logfile_) {
fclose(logfile_);
logfile_ = NULL;
}
}
virtual void OnLogMessage(const std::string& message) {
rtc::CritScope lock(&log_crit_);
Start();
if (NULL == logfile_)
return;
string msgString;
msgString = message;
if (fwrite(msgString.c_str(), 1, msgString.length(), logfile_) < 0) {
Close();
}
else if (fflush(logfile_) < 0) {
Close();
}
}
private:
FILE* logfile_;
const std::string log_path_;
std::string logfileName_ = "webrtclog.txt";
rtc::CriticalSection log_crit_;
};
rtc::LoggingSeverity min_sev = rtc::LS_WARNING;
min_sev = rtc::LS_INFO;
FileLog* _LogStream = new FileLog("logs");
rtc::LogMessage::AddLogToStream(_LogStream, min_sev);
}
int main()
{
ConfigWebrtcFileLog();
rtc::EnsureWinsockInit();
rtc::Win32SocketServer w32_ss;
rtc::Win32Thread w32_thread(&w32_ss);
@ -54,9 +110,19 @@ int main()
VideoRoomClient*client = new VideoRoomClient();
client->ConectToServer("janusdemo.com", 8188);
while (true) {
Sleep(1000);
while (true) {
Sleep(500);
for (auto x : client->m_peer_connection_map) {
RTC_LOG(INFO) << "list client: "
<< x.first ;
RTC_LOG(INFO) << "transceivers: " <<
x.second->peer_connection_->GetTransceivers().size()
<< "receivers: "
<< x.second->peer_connection_->GetTransceivers().size();
RTC_LOG(INFO) << "signal state: " << x.second->peer_connection_->signaling_state();
RTC_LOG(INFO) << "ice_connection_state: " << x.second->peer_connection_->ice_connection_state();
RTC_LOG(INFO) << "ice_gathering_state: " << x.second->peer_connection_->ice_gathering_state();
}
}
}

View File

@ -10,6 +10,44 @@
#include "modules/audio_processing/include/audio_processing.h"
#include "modules/video_capture/video_capture_factory.h"
std::string IceGatheringStateName(webrtc::PeerConnectionInterface::IceGatheringState w) {
switch (w) {
case webrtc::PeerConnectionInterface::IceGatheringState::kIceGatheringNew:
return "kIceGatheringNew";
case webrtc::PeerConnectionInterface::IceGatheringState::kIceGatheringGathering:
return "kIceGatheringGathering";
case webrtc::PeerConnectionInterface::IceGatheringState::kIceGatheringComplete:
return "kIceGatheringComplete";
}
}
std::string IceConnectionStateName(webrtc::PeerConnectionInterface::IceConnectionState w) {
switch (w) {
case webrtc::PeerConnectionInterface::IceConnectionState::kIceConnectionNew:
return "kIceConnectionNew";
case webrtc::PeerConnectionInterface::IceConnectionState::kIceConnectionChecking:
return "kIceConnectionChecking";
case webrtc::PeerConnectionInterface::IceConnectionState::kIceConnectionConnected:
return "kIceConnectionConnected";
case webrtc::PeerConnectionInterface::IceConnectionState::kIceConnectionCompleted:
return "kIceConnectionCompleted";
case webrtc::PeerConnectionInterface::IceConnectionState::kIceConnectionFailed:
return "kIceConnectionFailed";
case webrtc::PeerConnectionInterface::IceConnectionState::kIceConnectionDisconnected:
return "kIceConnectionDisconnected";
case webrtc::PeerConnectionInterface::IceConnectionState::kIceConnectionClosed:
return "kIceConnectionClosed";
case webrtc::PeerConnectionInterface::IceConnectionState::kIceConnectionMax:
return "kIceConnectionMax";
}
}
class DummySetSessionDescriptionObserver
: public webrtc::SetSessionDescriptionObserver {
public:
@ -23,6 +61,8 @@ public:
}
};
PeerConnection::PeerConnection()
{
}
@ -55,35 +95,46 @@ void PeerConnection::OnSuccess(webrtc::SessionDescriptionInterface* desc) {
}
void PeerConnection::OnFailure(webrtc::RTCError error) {
RTC_LOG(LERROR) << ToString(error.type()) << ": " << error.message();
RTC_LOG(LERROR) << "OnFailure" << ToString(error.type()) << ": " << error.message();
}
// PeerConnectionObserver implementation.
//
void PeerConnection::OnSignalingChange(webrtc::PeerConnectionInterface::SignalingState new_state) {
RTC_LOG(WARNING) << "OnSignalingChange " << new_state;
}
void PeerConnection::OnAddTrack(
rtc::scoped_refptr<webrtc::RtpReceiverInterface> receiver,
const std::vector<rtc::scoped_refptr<webrtc::MediaStreamInterface>>&
streams) {
RTC_LOG(INFO) << __FUNCTION__ << " " << receiver->id();
RTC_LOG(INFO) <<this->m_HandleId <<" " << __FUNCTION__ << " " << receiver->id()
<< receiver->media_type();
NEW_TRACK* pTrack = new NEW_TRACK;
pTrack->handleId = m_HandleId;
pTrack->pInterface = receiver->track().release();
m_pConductorCallback->PCQueueUIThreadCallback(NEW_TRACK_ADDED,
(void*)pTrack);
/*main_wnd_->QueueUIThreadCallback(NEW_TRACK_ADDED,
receiver->track().release());*/
}
void PeerConnection::OnRemoveTrack(
rtc::scoped_refptr<webrtc::RtpReceiverInterface> receiver) {
void PeerConnection::OnIceConnectionChange(
webrtc::PeerConnectionInterface::IceConnectionState new_state) {
RTC_LOG(WARNING) << "OnIceConnectionChange " << IceConnectionStateName(new_state);
};
void PeerConnection::OnRemoveTrack( rtc::scoped_refptr<webrtc::RtpReceiverInterface> receiver) {
RTC_LOG(INFO) << __FUNCTION__ << " " << receiver->id();
m_pConductorCallback->PCQueueUIThreadCallback(TRACK_REMOVED, receiver->track().release());
m_pConductorCallback->PCQueueUIThreadCallback(TRACK_REMOVED,
receiver->track().release());
}
void PeerConnection::OnIceCandidate(const webrtc::IceCandidateInterface* candidate) {
RTC_LOG(INFO) << __FUNCTION__ << " " << candidate->sdp_mline_index();
RTC_LOG(INFO) << __FUNCTION__ << " " << this->m_HandleId << " " << candidate->sdp_mline_index();
if (candidate) {
m_pConductorCallback->PCTrickleCandidate(m_HandleId, candidate);

View File

@ -23,6 +23,14 @@
#include "rtc_base/logging.h"
#include "rtc_base/refcount.h"
std::string IceGatheringStateName(webrtc::PeerConnectionInterface::IceGatheringState w);
std::string IceConnectionStateName(webrtc::PeerConnectionInterface::IceConnectionState w);
enum CallbackID {
MEDIA_CHANNELS_INITIALIZED = 1,
PEER_CONNECTION_CLOSED,
@ -95,7 +103,7 @@ protected:
virtual ~PeerConnectionCallback() {}
};
class PeerConnection:public webrtc::PeerConnectionObserver,
class PeerConnection :public webrtc::PeerConnectionObserver,
public webrtc::CreateSessionDescriptionObserver
{
public:
@ -107,12 +115,12 @@ public:
void CreateOffer();
void CreateAnswer();
void SetRemoteDescription(webrtc::SessionDescriptionInterface* session_description);
void StartRenderer(HWND wnd,webrtc::VideoTrackInterface* remote_video);
void StartRenderer(HWND wnd, webrtc::VideoTrackInterface* remote_video);
void StopRenderer();
protected:
// PeerConnectionObserver implementation.
void OnSignalingChange(
webrtc::PeerConnectionInterface::SignalingState new_state) override {};
webrtc::PeerConnectionInterface::SignalingState new_state) override;
void OnAddTrack(
rtc::scoped_refptr<webrtc::RtpReceiverInterface> receiver,
const std::vector<rtc::scoped_refptr<webrtc::MediaStreamInterface>>&
@ -120,24 +128,33 @@ protected:
void OnRemoveTrack(
rtc::scoped_refptr<webrtc::RtpReceiverInterface> receiver) override;
void OnDataChannel(
rtc::scoped_refptr<webrtc::DataChannelInterface> channel) override {}
void OnRenegotiationNeeded() override {}
rtc::scoped_refptr<webrtc::DataChannelInterface> channel) override {
};
void OnRenegotiationNeeded() override {
};
void OnIceConnectionChange(
webrtc::PeerConnectionInterface::IceConnectionState new_state) override {};
webrtc::PeerConnectionInterface::IceConnectionState new_state) override;
void OnIceGatheringChange(
webrtc::PeerConnectionInterface::IceGatheringState new_state) override {};
webrtc::PeerConnectionInterface::IceGatheringState new_state) override {
RTC_LOG(WARNING) << "IceGatheringStateName " << IceGatheringStateName(new_state);
};
void OnIceCandidate(const webrtc::IceCandidateInterface* candidate) override;
void OnIceConnectionReceivingChange(bool receiving) override {}
void OnIceConnectionReceivingChange(bool receiving) override {
};
// CreateSessionDescriptionObserver implementation.
void OnSuccess(webrtc::SessionDescriptionInterface* desc) override;
void OnFailure(webrtc::RTCError error) override;
public:
rtc::scoped_refptr<webrtc::PeerConnectionInterface> peer_connection_;
bool b_publisher_=false;//pub or sub
bool b_publisher_ = false;//pub or sub
std::unique_ptr<VideoRenderer> renderer_;//b_publisher decide local_render or remote_render
private:
PeerConnectionCallback *m_pConductorCallback=NULL;
long long int m_HandleId=0;//coresponding to the janus handleId
PeerConnectionCallback *m_pConductorCallback = NULL;
long long int m_HandleId=0;
//coresponding to the janus handleId
};

View File

@ -1,5 +1,30 @@
#include "video_room_client.h"
std::string wstring2string(std::wstring wstr)
{
std::string result;
//获取缓冲区大小,并申请空间,缓冲区大小事按字节计算的
int len = WideCharToMultiByte(CP_ACP, 0, wstr.c_str(), wstr.size(), NULL, 0, NULL, NULL);
char* buffer = new char[len + 1];
//宽字节编码转换成多字节编码
WideCharToMultiByte(CP_ACP, 0, wstr.c_str(), wstr.size(), buffer, len, NULL, NULL);
buffer[len] = '\0';
//删除缓冲区并返回值
result.append(buffer);
delete[] buffer;
return result;
}
std::string ComputerName() {
TCHAR username[100 + 1];
DWORD size = 100 + 1;
GetUserName((TCHAR*)username, &size);
return wstring2string(std::wstring(username));
}
static std::string OptString(std::string message, list<string> keyList) {
//parse json
Json::Reader reader;
@ -24,6 +49,8 @@ static std::string OptString(std::string message, list<string> keyList) {
//std::string tmp_str = rtc::JsonValueToString(jvalue);//this result sdp parse error beacause /r/n
return tmp_str;
}
static Json::Value optJSONValue(std::string message, list<string> keyList) {
//parse json
Json::Reader reader;
@ -181,7 +208,7 @@ static long long int OptLLInt(std::string message, list<string> keyList) {
//set media constraints
std::map<std::string, std::string> opts;
opts[webrtc::MediaConstraintsInterface::kMaxFrameRate] = 18;
opts[webrtc::MediaConstraintsInterface::kMaxFrameRate] = 30;
opts[webrtc::MediaConstraintsInterface::kMaxWidth] = 1280;
opts[webrtc::MediaConstraintsInterface::kMaxHeight] = 720;
@ -209,7 +236,7 @@ static long long int OptLLInt(std::string message, list<string> keyList) {
}
}
bool VideoRoomClient::CreatePeerConnection(long long int handleId, bool dtls) {
bool VideoRoomClient::CreatePeerConnection(long long int handleId, bool dtls){
RTC_DCHECK(peer_connection_factory_);
if (m_peer_connection_map.find(handleId) != m_peer_connection_map.end()) {
//existed
@ -241,8 +268,7 @@ static long long int OptLLInt(std::string message, list<string> keyList) {
rtc::scoped_refptr<PeerConnection> peer_connection(
new rtc::RefCountedObject<PeerConnection>());
peer_connection->peer_connection_ = peer_connection_factory_->CreatePeerConnection(
config, nullptr, nullptr, peer_connection);
peer_connection->peer_connection_ = peer_connection_factory_->CreatePeerConnection(config, nullptr, nullptr, peer_connection);
//set max/min bitrate
peer_connection->peer_connection_->SetBitrate(bitrateParam);
//add to the map
@ -645,7 +671,6 @@ static long long int OptLLInt(std::string message, list<string> keyList) {
// janus session¶Ô½Ó
this->CreateSession();
}
void VideoRoomClient::OnJanusDisconnected() {
@ -700,7 +725,6 @@ static long long int OptLLInt(std::string message, list<string> keyList) {
if (videoroom == "joined") {
UIThreadCallback(CREATE_OFFER, (void*)(&handleId));
//for each search every publisher and create handle to attach them
}
//joined the room as a subscriber
if (videoroom == "attached") {
@ -724,7 +748,7 @@ static long long int OptLLInt(std::string message, list<string> keyList) {
jbody["room"] = 1234;//FIXME should be variable
if (feedId == 0) {
jbody["ptype"] = "publisher";
jbody["display"] = "pcg";//FIXME should be variable
jbody["display"] = ComputerName();//FIXME should be variable
}
else {
jbody["ptype"] = "subscriber";
@ -806,14 +830,13 @@ static long long int OptLLInt(std::string message, list<string> keyList) {
m_SessionId = OptLLInt(message, sessionList);
//lauch the timer for keep alive breakheart
//Then Create the handle
CreateHandle("janus.plugin.videoroom", 0, "pcg");
CreateHandle("janus.plugin.videoroom", 0, ComputerName());
};
jt->Error = [=](std::string code, std::string reason) {
RTC_LOG(INFO) << "Ooops: " << code << " " << reason;
};
m_transactionMap[transactionID] = jt;
Json::StyledWriter writer;
Json::Value jmessage;

View File

@ -35,7 +35,6 @@
#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"
@ -47,11 +46,8 @@
#if defined(WEBRTC_WIN)
#include "rtc_base/win32.h"
#endif
using namespace std;
using namespace rtc;
@ -60,9 +56,6 @@ struct REMOTE_SDP_INFO {
std::string jsep_str;
};
class ImplPeerConnectionWsClientObserver :
public sigslot::has_slots<>,
public PeerConnectionWsClientObserver {
@ -110,7 +103,7 @@ protected:
virtual void OnJanusDisconnected();
virtual void OnSendKeepAliveToJanus();
private:
public:
void KeepAlive();
void JoinRoom(std::string pluginName, long long int handleId, long long int feedId);