no message

master
zcy 2021-12-11 23:27:41 +08:00
parent 8466492420
commit cc659c89d6
5 changed files with 97 additions and 25 deletions

View File

@ -15,6 +15,7 @@ void MyCapturer::startCapturer() {
capturer_ = webrtc::DesktopCapturer::CreateScreenCapturer(options);
capturer_->Start(this);
CaptureFrame();
}
webrtc::MediaSourceInterface::SourceState MyCapturer::state() const {

View File

@ -99,9 +99,9 @@ void InitCustomMetaType(){
qRegisterMetaType<uint8_t*>("uint8_t*");
qRegisterMetaType<uint64_t>("uint64_t");
qRegisterMetaType<uint32_t>("uint32_t");
}
int main(int argc, char *argv[])
{
InitCustomMetaType();
@ -118,11 +118,6 @@ int main(int argc, char *argv[])
QApplication a(argc, argv);
MainWindow w;
// QObject::connect((VcmCapturerTest*)capturer.get(),SIGNAL(UpdateFrame(rtc::scoped_refptr<webrtc::I420BufferInterface>&)),&w,
// SLOT(OnUpdateFrame( rtc::scoped_refptr<webrtc::I420BufferInterface>&)),Qt::ConnectionType::QueuedConnection);
// QObject::connect((VcmCapturerTest*)capturer.get(),SIGNAL(UpdateFrame1(uint8_t*)),&w,
// SLOT(OnUpdateFrame1( uint8_t *)),Qt::ConnectionType::QueuedConnection);
w.show();
return a.exec();
}

View File

@ -58,15 +58,18 @@ MainWindow::MainWindow(QWidget *parent)
,mSignalClient(nullptr)
,mModel(nullptr)
,mCalling(false)
,mRemoteStream(nullptr)
,mRemoteVideoTrack(nullptr)
,mLocalVideoTrack(nullptr)
{
ui->setupUi(this);
ui->openGLWidget->show();
mHandler->InitWebrtc();
this->mLocalVideoTrack = mHandler->VideoTrack();
TCHAR username[UNLEN + 1];
DWORD size = UNLEN + 1;
GetUserName((TCHAR*)username, &size);
this->mPeerName = QString::fromWCharArray(username);
mModel = new QStandardItemModel(this);
ui->treeView->setModel(mModel);
connect(ui->treeView,SIGNAL(doubleClicked(QModelIndex)),
@ -92,6 +95,11 @@ void WebrtcHanlder::SetRemotePeerName(QString remote)
this->mRemoteName = remote;
}
WebrtcHanlder::WebrtcHanlder()
{
mVideoTrack = nullptr;
}
int WebrtcHanlder::InitWebrtc()
{
m_peer_connection_factory_ = webrtc::CreatePeerConnectionFactory(
@ -137,6 +145,7 @@ int WebrtcHanlder::InitWebrtc()
qDebug() << "Failed to add audio track to PeerConnection: "
<< result_or_error.error().message();
}
gLog()->Log((QString::asprintf("%s %d",__FILE__,__LINE__) +
" m_peer_connection_ AddTrack" + kAudioLabel).toStdString());
rtc::scoped_refptr<MyCapturer> video_device = new rtc::RefCountedObject<MyCapturer>();
@ -146,6 +155,8 @@ int WebrtcHanlder::InitWebrtc()
m_peer_connection_factory_->CreateVideoTrack(kVideoLabel, video_device));
qDebug()<<"local track is "<<video_track_->id().c_str();
result_or_error = m_peer_connection_->AddTrack(video_track_, { kStreamId });
mVideoTrack = video_track_.get();
video_track_->AddRef();
if (!result_or_error.ok()) {
qDebug() << "Failed to add video track to PeerConnection: "
<< result_or_error.error().message();
@ -253,6 +264,11 @@ void WebrtcHanlder::CreateAnwer()
" CreateAnswer ").toStdString());
}
webrtc::VideoTrackInterface *WebrtcHanlder::VideoTrack()
{
return mVideoTrack;
}
WebrtcHanlder::~WebrtcHanlder()
{
@ -291,6 +307,15 @@ void WebrtcHanlder::OnIceConnectionChange(webrtc::PeerConnectionInterface::IceCo
gLog()->Log((QString::asprintf("%s %d",__FILE__,__LINE__) +
" OnIceConnectionChange " +
IceConnectionStateName(new_state)).toStdString());
if((new_state ==
webrtc::PeerConnectionInterface::IceConnectionState::kIceConnectionDisconnected)){
m_peer_connection_->Close();
OnConectionDisconnected();
}
if((new_state ==
webrtc::PeerConnectionInterface::IceConnectionState::kIceConnectionCompleted)){
OnConectionComplete();
}
}
void WebrtcHanlder::OnIceGatheringChange(webrtc::PeerConnectionInterface::IceGatheringState new_state) {
@ -434,13 +459,14 @@ void MainWindow::itemClicked(QModelIndex index)
if(!mSignalClient->Connected()){
qDebug()<<"请先连接信令服务";
}
mHandler->CreateOffer();
//mSignalClient->SendSDPOffer();
qDebug()<<mModel->item(index.row())->text();
mRemoteName = mModel->item(index.row())->text();
if(mRemoteName == this->mPeerName){
return;
}
mHandler->CreateOffer();
mHandler->SetRemotePeerName(mRemoteName);
mCalling = true;
}
void MainWindow::on_local_sdp(QString sdp)
@ -452,12 +478,12 @@ void MainWindow::on_local_sdp(QString sdp)
void MainWindow::on_track_add(webrtc::MediaStreamTrackInterface *data)
{
qDebug()<<"on_track_add"<<data->kind().c_str();
mRemoteStream = reinterpret_cast<webrtc::MediaStreamTrackInterface*>(data);
mRemoteVideoTrack = reinterpret_cast<webrtc::VideoTrackInterface*>(data);
if (mRemoteStream->kind() == webrtc::MediaStreamTrackInterface::kVideoKind) {
auto* video_track = static_cast<webrtc::VideoTrackInterface*>(mRemoteStream);
qDebug()<<"remote trackid is "<<video_track->id().c_str();
remote_renderer_.reset(new VideoRenderer( 1, 1, video_track));
if (mRemoteVideoTrack->kind() == webrtc::MediaStreamTrackInterface::kVideoKind) {
mRemoteVideoTrack = static_cast<webrtc::VideoTrackInterface*>(mRemoteVideoTrack);
qDebug()<<"remote trackid is "<<mRemoteVideoTrack->id().c_str();
remote_renderer_.reset(new VideoRenderer( 1, 1, mRemoteVideoTrack));
connect((VideoRenderer*)(remote_renderer_.get()),
SIGNAL(UpdateFrame(rtc::scoped_refptr<webrtc::I420BufferInterface>&)),
@ -620,13 +646,29 @@ void VideoRenderer::SetSize(int width, int height)
void MainWindow::on_pushButton_3_clicked()
{
if(mRemoteStream != nullptr){
mRemoteStream->set_enabled(false);
if(mRemoteVideoTrack != nullptr){
mRemoteVideoTrack->set_enabled(false);
}
}
void MainWindow::on_pushButton_4_clicked()
{
if(mLocalVideoTrack != nullptr){
mLocalVideoTrack->set_enabled(false);
}
}
void MainWindow::on_pushButton_5_clicked()
{
if(mRemoteVideoTrack != nullptr){
mRemoteVideoTrack->set_enabled(false);
}
}
void MainWindow::on_pushButton_6_clicked()
{
if(mLocalVideoTrack != nullptr){
mLocalVideoTrack->set_enabled(true);
}
}

View File

@ -96,8 +96,11 @@ class WebrtcHanlder :public QObject,
signals:
void OnOfferSdp(QString);
void OnRemoteTrack(webrtc::MediaStreamTrackInterface*);
void OnConectionDisconnected();
void OnConectionComplete();
public:
WebrtcHanlder();
int InitWebrtc();
void SetSignalClient(SignalClient *);
void CreateOffer();
@ -106,6 +109,7 @@ public:
void SetRemoteSdp(QString);
void SetRemoteCandidate(QString);
void CreateAnwer();
webrtc::VideoTrackInterface *VideoTrack();
protected:
~WebrtcHanlder();
//
@ -137,6 +141,7 @@ private:
m_peer_connection_factory_;
SignalClient *mClient;
QString mRemoteName;
webrtc::VideoTrackInterface *mVideoTrack;
};
class MainWindow :public QMainWindow
@ -159,6 +164,12 @@ private slots:
void on_notify_size(uint32_t,uint32_t);
void on_pushButton_3_clicked();
void on_pushButton_4_clicked();
void on_pushButton_5_clicked();
void on_pushButton_6_clicked();
private:
Ui::MainWindow *ui;
rtc::scoped_refptr<WebrtcHanlder> mHandler;
@ -169,6 +180,8 @@ private:
bool mCalling;
std::unique_ptr<VideoRenderer> local_renderer_;
std::unique_ptr<VideoRenderer> remote_renderer_;
webrtc::MediaStreamTrackInterface* mRemoteStream;
webrtc::VideoTrackInterface* mRemoteVideoTrack;
webrtc::VideoTrackInterface* mLocalVideoTrack;
};
#endif // MAINWINDOW_H

View File

@ -73,7 +73,7 @@
<item>
<widget class="QLineEdit" name="lineEdit_2">
<property name="text">
<string>ws://192.168.5.192:9555/ws</string>
<string>ws://192.168.5.73:9555/ws</string>
</property>
</widget>
</item>
@ -137,7 +137,7 @@
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_4" stretch="0,0,0,8">
<layout class="QHBoxLayout" name="horizontalLayout_4" stretch="0,0,0,0,0,8">
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
@ -154,14 +154,28 @@
<item>
<widget class="QPushButton" name="pushButton_3">
<property name="text">
<string>暂停对方视频流</string>
<string>暂停对方视频接收</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_5">
<property name="text">
<string>恢复对方视频接收</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_4">
<property name="text">
<string>暂停本地视频流</string>
<string>暂停本地视频流采集</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_6">
<property name="text">
<string>恢复本地视频采集</string>
</property>
</widget>
</item>
@ -181,7 +195,7 @@
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3" stretch="0,0">
<layout class="QHBoxLayout" name="horizontalLayout_3" stretch="0,0,0">
<item>
<widget class="QLabel" name="label_6">
<property name="text">
@ -196,6 +210,13 @@
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_7">
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
</item>
</layout>