添加详细日志以免后期严格测试
parent
37f7640556
commit
c790786f55
|
@ -3,6 +3,7 @@
|
|||
#include <modules/desktop_capture/desktop_capture_options.h>
|
||||
#include <QDebug>
|
||||
#include <iostream>
|
||||
#include "easylog.h"
|
||||
|
||||
MyCapturer::MyCapturer() {
|
||||
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
#include "easylog.h"
|
||||
|
||||
EasyLog *gLog(){
|
||||
static EasyLog *gsLog ;
|
||||
if (gsLog == nullptr)
|
||||
gsLog = new EasyLog("d://peerconection.txt");
|
||||
return gsLog;
|
||||
}
|
||||
|
||||
EasyLog::EasyLog(std::string path):
|
||||
mFile(nullptr)
|
||||
{
|
||||
mFile = fopen(path.c_str(),"w+");
|
||||
if(mFile == nullptr){
|
||||
qDebug()<<"easylog";
|
||||
}
|
||||
}
|
||||
|
||||
int EasyLog::Log(std::string data)
|
||||
{
|
||||
std::unique_lock<std::mutex> mutex(mMux);
|
||||
if((mFile == nullptr)){
|
||||
return -1;
|
||||
}
|
||||
int ret = fwrite(data.c_str(),data.size(),1,mFile);
|
||||
fwrite("\r\n",2,1,mFile);
|
||||
|
||||
fflush(mFile);
|
||||
return ret;
|
||||
};
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
#ifndef EASYLOG_H
|
||||
#define EASYLOG_H
|
||||
#include <stdio.h>
|
||||
#include <string>
|
||||
#include <QDebug>
|
||||
#include <mutex>
|
||||
class EasyLog
|
||||
{
|
||||
public:
|
||||
EasyLog(std::string path);
|
||||
int Log(std::string data);
|
||||
FILE *mFile;
|
||||
std::mutex mMux;
|
||||
};
|
||||
|
||||
EasyLog *gLog();
|
||||
|
||||
#endif // EASYLOG_H
|
|
@ -1,7 +1,6 @@
|
|||
#include "mainwindow.h"
|
||||
|
||||
#include "easylog.h"
|
||||
#include <QApplication>
|
||||
|
||||
#include "modules/video_capture/video_capture.h"
|
||||
#include "video_capturer_test.h"
|
||||
#include <QString>
|
||||
|
@ -66,6 +65,7 @@ BOOLEAN WINAPI SystemFunction036(PVOID, ULONG);
|
|||
#pragma comment(lib, "dxgi.lib")
|
||||
#pragma comment(lib, "Gdi32.lib")
|
||||
|
||||
|
||||
void EnumCapture()
|
||||
{
|
||||
std::unique_ptr<webrtc::VideoCaptureModule::DeviceInfo> info(
|
||||
|
|
|
@ -10,13 +10,47 @@
|
|||
#include "video_capture.h"
|
||||
#include "video_capturer_test.h"
|
||||
#include <iostream>
|
||||
|
||||
#include "easylog.h"
|
||||
|
||||
const char kCandidateSdpMidName[] = "sdpMid";
|
||||
const char kCandidateSdpMlineIndexName[] = "sdpMLineIndex";
|
||||
const char kCandidateSdpName[] = "candidate";
|
||||
|
||||
|
||||
QString 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";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
QString 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";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
MainWindow::MainWindow(QWidget *parent)
|
||||
: QMainWindow(parent)
|
||||
, ui(new Ui::MainWindow)
|
||||
|
@ -102,8 +136,8 @@ int WebrtcHanlder::InitWebrtc()
|
|||
qDebug() << "Failed to add audio track to PeerConnection: "
|
||||
<< result_or_error.error().message();
|
||||
}
|
||||
//rtc::scoped_refptr<CapturerTrackSource> video_device =
|
||||
// CapturerTrackSource::Create();
|
||||
gLog()->Log((QString::asprintf("%s %d",__FILE__,__LINE__) +
|
||||
" m_peer_connection_ AddTrack" + kAudioLabel).toStdString());
|
||||
rtc::scoped_refptr<MyCapturer> video_device = new rtc::RefCountedObject<MyCapturer>();
|
||||
if (video_device) {
|
||||
video_device->startCapturer();
|
||||
|
@ -115,47 +149,14 @@ int WebrtcHanlder::InitWebrtc()
|
|||
qDebug() << "Failed to add video track to PeerConnection: "
|
||||
<< result_or_error.error().message();
|
||||
}
|
||||
gLog()->Log((QString::asprintf("%s %d",__FILE__,__LINE__) +
|
||||
" m_peer_connection_ AddTrack" + kVideoLabel).toStdString());
|
||||
} else {
|
||||
qDebug()<< "OpenVideoCaptureDevice failed";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int WebrtcHanlder::AddTrack()
|
||||
{
|
||||
if (!m_peer_connection_->GetSenders().empty()) {
|
||||
return -1; // Already added tracks.
|
||||
}
|
||||
// add audio tracks
|
||||
rtc::scoped_refptr<webrtc::AudioTrackInterface> audio_track(
|
||||
m_peer_connection_factory_->CreateAudioTrack(
|
||||
kAudioLabel, m_peer_connection_factory_->CreateAudioSource(
|
||||
cricket::AudioOptions())));
|
||||
|
||||
auto result_or_error = m_peer_connection_->AddTrack(audio_track, {kStreamId});
|
||||
if (!result_or_error.ok()) {
|
||||
RTC_LOG(LS_ERROR) << "Failed to add audio track to PeerConnection: "
|
||||
<< result_or_error.error().message();
|
||||
}
|
||||
//rtc::scoped_refptr<CapturerTrackSource> video_device =
|
||||
// CapturerTrackSource::Create();
|
||||
rtc::scoped_refptr<MyCapturer> video_device = new rtc::RefCountedObject<MyCapturer>();
|
||||
if (video_device) {
|
||||
video_device->startCapturer();
|
||||
rtc::scoped_refptr<webrtc::VideoTrackInterface> video_track_(
|
||||
m_peer_connection_factory_->CreateVideoTrack(kVideoLabel, video_device));
|
||||
|
||||
result_or_error = m_peer_connection_->AddTrack(video_track_, { kStreamId });
|
||||
if (!result_or_error.ok()) {
|
||||
RTC_LOG(LS_ERROR) << "Failed to add video track to PeerConnection: "
|
||||
<< result_or_error.error().message();
|
||||
}
|
||||
} else {
|
||||
RTC_LOG(LS_ERROR) << "OpenVideoCaptureDevice failed";
|
||||
}
|
||||
webrtc::DataChannelInit config;
|
||||
}
|
||||
|
||||
void WebrtcHanlder::SetSignalClient(SignalClient * cli)
|
||||
{
|
||||
this->mClient = cli;
|
||||
|
@ -168,6 +169,8 @@ void WebrtcHanlder::CreateOffer()
|
|||
m_peer_connection_->CreateOffer(this,
|
||||
webrtc::PeerConnectionInterface::RTCOfferAnswerOptions());
|
||||
}
|
||||
gLog()->Log((QString::asprintf("%s %d",__FILE__,__LINE__) +
|
||||
" CreateOffer").toStdString());
|
||||
}
|
||||
|
||||
class DummySetSessionDescriptionObserver
|
||||
|
@ -211,6 +214,9 @@ void WebrtcHanlder::SetRemoteSdp(QString sdp)
|
|||
DummySetSessionDescriptionObserver::Create(),
|
||||
session_description.release());;
|
||||
}
|
||||
gLog()->Log((QString::asprintf("%s %d",__FILE__,__LINE__) +
|
||||
" SetRemoteSdp " + type + ": " +
|
||||
ssdp).toStdString());
|
||||
}
|
||||
|
||||
|
||||
|
@ -232,6 +238,9 @@ void WebrtcHanlder::SetRemoteCandidate(QString sdp)
|
|||
if(nullptr != m_peer_connection_){
|
||||
m_peer_connection_->AddIceCandidate(candidate.get());
|
||||
}
|
||||
gLog()->Log((QString::asprintf("%s %d",__FILE__,__LINE__) +
|
||||
" SetRemoteCandidate&&CreateIceCandidate " + ": " +
|
||||
ssdp).toStdString());
|
||||
}
|
||||
|
||||
void WebrtcHanlder::CreateAnwer()
|
||||
|
@ -239,6 +248,8 @@ void WebrtcHanlder::CreateAnwer()
|
|||
qDebug()<<"create answer";
|
||||
m_peer_connection_->CreateAnswer(
|
||||
this, webrtc::PeerConnectionInterface::RTCOfferAnswerOptions());
|
||||
gLog()->Log((QString::asprintf("%s %d",__FILE__,__LINE__) +
|
||||
" CreateAnswer ").toStdString());
|
||||
}
|
||||
|
||||
WebrtcHanlder::~WebrtcHanlder()
|
||||
|
@ -253,25 +264,38 @@ void WebrtcHanlder::OnSignalingChange(webrtc::PeerConnectionInterface::Signaling
|
|||
void WebrtcHanlder::OnAddTrack(rtc::scoped_refptr<webrtc::RtpReceiverInterface> receiver, const std::vector<rtc::scoped_refptr<webrtc::MediaStreamInterface> > &streams)
|
||||
{
|
||||
qDebug()<<"OnAddTrack"<<receiver->id().c_str();
|
||||
if (receiver->track().release()->kind() == webrtc::MediaStreamTrackInterface::kVideoKind)
|
||||
if (receiver->track().release()->kind() ==
|
||||
webrtc::MediaStreamTrackInterface::kVideoKind)
|
||||
OnRemoteTrack(receiver->track().release());
|
||||
|
||||
gLog()->Log((QString::asprintf("%s %d",__FILE__,__LINE__) +
|
||||
" OnAddTrack ").toStdString());
|
||||
}
|
||||
|
||||
void WebrtcHanlder::OnRemoveTrack(rtc::scoped_refptr<webrtc::RtpReceiverInterface> receiver)
|
||||
{
|
||||
qDebug()<<"OnRemoveTrack";
|
||||
gLog()->Log((QString::asprintf("%s %d",__FILE__,__LINE__) +
|
||||
" OnRemoveTrack ").toStdString());
|
||||
}
|
||||
|
||||
void WebrtcHanlder::OnDataChannel(rtc::scoped_refptr<webrtc::DataChannelInterface> channel) {
|
||||
qDebug()<<"OnRemoveTrack";
|
||||
qDebug()<<"OnDataChannel";
|
||||
gLog()->Log((QString::asprintf("%s %d",__FILE__,__LINE__) +
|
||||
" OnDataChannel ").toStdString());
|
||||
}
|
||||
|
||||
void WebrtcHanlder::OnIceConnectionChange(webrtc::PeerConnectionInterface::IceConnectionState new_state) {
|
||||
qDebug()<<"OnIceConnectionChange"<<new_state;
|
||||
gLog()->Log((QString::asprintf("%s %d",__FILE__,__LINE__) +
|
||||
" OnIceConnectionChange " +
|
||||
IceConnectionStateName(new_state)).toStdString());
|
||||
}
|
||||
|
||||
void WebrtcHanlder::OnIceGatheringChange(webrtc::PeerConnectionInterface::IceGatheringState new_state) {
|
||||
|
||||
qDebug()<<"OnIceGatheringChange"<<new_state;
|
||||
gLog()->Log((QString::asprintf("%s %d",__FILE__,__LINE__) +
|
||||
" OnIceGatheringChange " + IceGatheringStateName(new_state)).toStdString());
|
||||
}
|
||||
|
||||
void WebrtcHanlder::OnIceCandidate(const webrtc::IceCandidateInterface *candidate)
|
||||
|
@ -289,10 +313,14 @@ void WebrtcHanlder::OnIceCandidate(const webrtc::IceCandidateInterface *candidat
|
|||
addr.insert(kCandidateSdpName,sdp.c_str());
|
||||
qDebug()<<"condidate:\r\n"<< QString(QJsonDocument(addr).toJson());
|
||||
this->mClient->SendICECandidate(mRemoteName,QString(QJsonDocument(addr).toJson()));
|
||||
gLog()->Log((QString::asprintf("%s %d",__FILE__,__LINE__) +
|
||||
" OnIceCandidate " + QString(QJsonDocument(addr).toJson())).toStdString());
|
||||
}
|
||||
|
||||
void WebrtcHanlder::OnIceConnectionReceivingChange(bool receiving) {
|
||||
|
||||
gLog()->Log((QString::asprintf("%s %d",__FILE__,__LINE__) +
|
||||
" OnIceConnectionReceivingChange " +\
|
||||
QString::asprintf("%d",receiving)).toStdString());
|
||||
}
|
||||
|
||||
|
||||
|
@ -316,11 +344,15 @@ void WebrtcHanlder::OnSuccess(webrtc::SessionDescriptionInterface *desc)
|
|||
if(QString(desc->type().c_str()) == "answer"){
|
||||
OnOfferSdp(QJsonDocument(addr).toJson());
|
||||
}
|
||||
gLog()->Log((QString::asprintf("%s %d",__FILE__,__LINE__) +
|
||||
"PeerConnectionObserver::OnSuccess " + QJsonDocument(addr).toJson()).toStdString());
|
||||
}
|
||||
|
||||
void WebrtcHanlder::OnFailure(webrtc::RTCError error)
|
||||
{
|
||||
qDebug()<<error.message();
|
||||
gLog()->Log((QString::asprintf("%s %d",__FILE__,__LINE__) +
|
||||
"PeerConnectionObserver::OnSuccess " + error.message()).toStdString());
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -93,14 +93,12 @@ class WebrtcHanlder :public QObject,
|
|||
public webrtc::PeerConnectionObserver,
|
||||
public webrtc::CreateSessionDescriptionObserver{
|
||||
Q_OBJECT
|
||||
|
||||
signals:
|
||||
void OnOfferSdp(QString);
|
||||
void OnRemoteTrack(webrtc::MediaStreamTrackInterface*);
|
||||
|
||||
public:
|
||||
int InitWebrtc();
|
||||
int AddTrack();
|
||||
void SetSignalClient(SignalClient *);
|
||||
void CreateOffer();
|
||||
void CreateAnswer();
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#include <QJsonDocument>
|
||||
#include <windows.h>
|
||||
#include <Lmcons.h>
|
||||
#include "easylog.h"
|
||||
|
||||
SignalClient::SignalClient(const QUrl &url, bool debug, QObject *parent):
|
||||
QObject(parent),
|
||||
|
@ -39,6 +40,9 @@ void SignalClient::SendLogin()
|
|||
obj.insert("data",data);
|
||||
m_peer_name = QString::fromWCharArray(username);
|
||||
m_webSocket.sendTextMessage(QJsonDocument(obj).toJson());
|
||||
gLog()->Log((QString::asprintf("%s %d",__FILE__,__LINE__) +" send:\r\n" +
|
||||
QString(QJsonDocument(obj).toJson())).toStdString());
|
||||
|
||||
}
|
||||
|
||||
#define REQ_INROOM 1001
|
||||
|
@ -52,6 +56,8 @@ void SignalClient::SendInRoom(QString room)
|
|||
obj.insert("type",REQ_INROOM);
|
||||
obj.insert("data",data);
|
||||
m_webSocket.sendTextMessage(QString(QJsonDocument(obj).toJson()));
|
||||
gLog()->Log((QString::asprintf("%s %d",__FILE__,__LINE__) +" send:\r\n" +
|
||||
QString(QJsonDocument(obj).toJson())).toStdString());
|
||||
}
|
||||
|
||||
#define REQ_INROOM 1004
|
||||
|
@ -64,6 +70,8 @@ void SignalClient::SendListRoom(QString room)
|
|||
obj.insert("type",REQ_INROOM);
|
||||
obj.insert("data",data);
|
||||
m_webSocket.sendTextMessage(QString(QJsonDocument(obj).toJson()));
|
||||
gLog()->Log((QString::asprintf("%s %d",__FILE__,__LINE__) +" send:\r\n" +
|
||||
QString(QJsonDocument(obj).toJson())).toStdString());
|
||||
}
|
||||
|
||||
bool SignalClient::Connected()
|
||||
|
@ -89,7 +97,8 @@ void SignalClient::SendSDPOffer(QString peer, QString sdp)
|
|||
qDebug()<<QString(QJsonDocument(obj).toJson());
|
||||
m_webSocket.sendTextMessage(QString(QJsonDocument(obj).toJson()));
|
||||
|
||||
qDebug()<<QString(QJsonDocument(obj).toJson());
|
||||
gLog()->Log((QString::asprintf("%s %d",__FILE__,__LINE__) +" send:\r\n" +
|
||||
QString(QJsonDocument(obj).toJson())).toStdString());
|
||||
}
|
||||
#define REQ_CANDIDATE 1006
|
||||
void SignalClient::SendICECandidate(QString peer, QString candidate)
|
||||
|
@ -103,6 +112,8 @@ void SignalClient::SendICECandidate(QString peer, QString candidate)
|
|||
obj.insert("data",data);
|
||||
qDebug()<<QString(QJsonDocument(obj).toJson());
|
||||
m_webSocket.sendTextMessage(QString(QJsonDocument(obj).toJson()));
|
||||
gLog()->Log((QString::asprintf("%s %d",__FILE__,__LINE__) +" send:\r\n" +
|
||||
QString(QJsonDocument(obj).toJson())).toStdString());
|
||||
}
|
||||
|
||||
QString SignalClient::PeerName()
|
||||
|
@ -118,6 +129,8 @@ void SignalClient::onConnected()
|
|||
m_connected = true;
|
||||
m_timer.stop();
|
||||
connected();
|
||||
gLog()->Log((QString::asprintf("%s %d",__FILE__,__LINE__) +" +"
|
||||
" WebSocket connected").toStdString());
|
||||
}
|
||||
|
||||
void SignalClient::onUnConnected()
|
||||
|
@ -127,6 +140,9 @@ void SignalClient::onUnConnected()
|
|||
m_timer.setSingleShot(false);
|
||||
m_webSocket.open(QUrl(m_url));
|
||||
closed();
|
||||
gLog()->Log((QString::asprintf("%s %d",__FILE__,__LINE__) +
|
||||
" WebSocket unconnected").toStdString());
|
||||
|
||||
}
|
||||
|
||||
void SignalClient::onTextMessageReceived(QString message)
|
||||
|
@ -135,11 +151,16 @@ void SignalClient::onTextMessageReceived(QString message)
|
|||
auto obj = QJsonDocument::fromJson(message.toUtf8()).object();
|
||||
qDebug()<<obj["type"];
|
||||
response(obj["type"].toInt(),obj["data"].toObject());
|
||||
gLog()->Log((QString::asprintf("%s %d",__FILE__,__LINE__) + " recv:\r\n" +
|
||||
QString(QJsonDocument(obj).toJson())).toStdString());
|
||||
}
|
||||
|
||||
void SignalClient::onSocketError(QAbstractSocket::SocketError error)
|
||||
{
|
||||
qDebug()<<error;
|
||||
gLog()->Log((QString::asprintf("%s %d",__FILE__,__LINE__) +
|
||||
" WebSocket unconnected").toStdString());
|
||||
|
||||
}
|
||||
|
||||
void SignalClient::onReconenectTimeout()
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
#define VIDEO_CAPTURE_H
|
||||
|
||||
// vcm_capturer_test.h
|
||||
|
||||
#include "easylog.h"
|
||||
|
||||
#include <memory>
|
||||
#include <QObject>
|
||||
|
|
|
@ -23,6 +23,7 @@ LIBS += -L$$PWD/third/lib libwebrtc.lib ole32.lib oleaut32.lib strmiids.lib yuv
|
|||
SOURCES += \
|
||||
src/MyCapturer.cpp \
|
||||
src/cplaywidget.cpp \
|
||||
src/easylog.cpp \
|
||||
src/main.cpp \
|
||||
src/mainwindow.cpp \
|
||||
src/signal_client.cpp \
|
||||
|
@ -32,6 +33,7 @@ SOURCES += \
|
|||
HEADERS += \
|
||||
src/MyCapturer.h \
|
||||
src/cplaywidget.h \
|
||||
src/easylog.h \
|
||||
src/mainwindow.h \
|
||||
src/signal_client.h \
|
||||
src/video_capture.h \
|
||||
|
|
Loading…
Reference in New Issue