2020-06-04 15:28:45 +00:00
|
|
|
|
#include "mainwindow.h"
|
|
|
|
|
#include "ui_mainwindow.h"
|
2020-07-05 14:35:35 +00:00
|
|
|
|
#include <QDesktopWidget>
|
2020-12-06 16:01:38 +00:00
|
|
|
|
#include <QPaintDevice>
|
2020-06-04 15:28:45 +00:00
|
|
|
|
|
|
|
|
|
MainWindow::MainWindow(QWidget *parent) :
|
2020-06-06 07:39:55 +00:00
|
|
|
|
QssMainWindow(parent),
|
2020-06-04 15:28:45 +00:00
|
|
|
|
ui(new Ui::MainWindow),
|
|
|
|
|
m_bCameraOpen(false),
|
2020-06-05 02:18:37 +00:00
|
|
|
|
mCamera(nullptr),
|
2020-06-05 15:59:47 +00:00
|
|
|
|
m_bRtmpPushing(false),
|
|
|
|
|
mPlayerWidget(nullptr),
|
|
|
|
|
mVideoCoder(nullptr),
|
2020-06-19 09:30:29 +00:00
|
|
|
|
mPusher(nullptr),
|
2020-12-06 16:01:38 +00:00
|
|
|
|
mAudioCapture(nullptr),
|
|
|
|
|
mTimer(nullptr)
|
2020-06-04 15:28:45 +00:00
|
|
|
|
{
|
|
|
|
|
ui->setupUi(this);
|
2020-07-05 14:35:35 +00:00
|
|
|
|
this->move(50,50);
|
|
|
|
|
int i(0);
|
|
|
|
|
QDesktopWidget* desktopWidget = QApplication::desktop();
|
|
|
|
|
QRect clientRect = desktopWidget->availableGeometry();
|
|
|
|
|
QRect applicationRect = desktopWidget->screenGeometry();
|
|
|
|
|
|
|
|
|
|
qDebug()<<this->pos()<<clientRect<<applicationRect<<this->m_frame->geometry()<<this->centralWidget()->geometry();
|
|
|
|
|
|
2020-06-04 15:28:45 +00:00
|
|
|
|
std::vector<std::wstring> cameras = Camera::EnumAllCamera();
|
|
|
|
|
for(std::wstring x : cameras){
|
|
|
|
|
ui->comboBox->addItem(QString::fromWCharArray(x.c_str(),x.size()),
|
|
|
|
|
QString::fromWCharArray(x.c_str(),x.size()));
|
|
|
|
|
}
|
2020-06-19 17:10:03 +00:00
|
|
|
|
mAudioCapture = new CaptureAudioFfmpeg(44100, 2);
|
2020-06-19 09:30:29 +00:00
|
|
|
|
mMic = mAudioCapture->EnumSpeakers();
|
|
|
|
|
qDebug()<<"capture "<<mMic.size()<<"mic";
|
2020-06-19 17:10:03 +00:00
|
|
|
|
for(vector<CaptureAudioFfmpeg::MICInfo>::iterator itr = mMic.begin();itr != mMic.end();itr++){
|
2020-07-05 14:35:35 +00:00
|
|
|
|
|
|
|
|
|
|
2020-06-19 09:30:29 +00:00
|
|
|
|
}
|
|
|
|
|
//mAudioCapture->SetObserver(mAudioCoder);
|
|
|
|
|
//mAudioCapture->InitCapture(0, 44100, 2);
|
|
|
|
|
//mAudioCapture->StartCapture();
|
2020-06-05 15:59:47 +00:00
|
|
|
|
mPusher = new H264RtmpPuser();
|
2020-12-06 16:01:38 +00:00
|
|
|
|
mTimer = new QTimer(this);
|
|
|
|
|
connect(mTimer, SIGNAL(timeout()), this, SLOT(DetectDpi()));
|
|
|
|
|
mTimer->start(1000);
|
|
|
|
|
|
2020-06-04 15:28:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MainWindow::~MainWindow(){
|
|
|
|
|
delete ui;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MainWindow::on_pushButton_clicked(){
|
|
|
|
|
if(nullptr == mPlayerWidget){
|
|
|
|
|
mPlayerWidget = new CPlayWidget(nullptr);
|
|
|
|
|
}
|
|
|
|
|
if(!m_bCameraOpen){
|
|
|
|
|
mPlayerWidget->SetDataType(CPlayWidget::IMG_TYPE::TYPE_RGB32);
|
|
|
|
|
mPlayerWidget->SetImgSize(640,480);
|
|
|
|
|
|
|
|
|
|
qDebug()<<ui->comboBox->currentText().size()<<ui->comboBox->currentText();
|
|
|
|
|
wchar_t *opencamera = new wchar_t[ui->comboBox->currentText().size()];
|
|
|
|
|
ui->comboBox->currentText().toWCharArray(opencamera);
|
|
|
|
|
wstring ss = wstring(opencamera,ui->comboBox->currentText().size());
|
|
|
|
|
if(nullptr == mCamera){
|
|
|
|
|
this->mCamera = new Camera(ss);
|
|
|
|
|
}
|
2020-06-06 07:39:55 +00:00
|
|
|
|
this->mCamera->SetObserver(mPlayerWidget);
|
2020-06-04 15:28:45 +00:00
|
|
|
|
qDebug()<<ui->comboBox->currentText();
|
|
|
|
|
ui->pushButton->setText("关闭摄像头");
|
|
|
|
|
m_bCameraOpen = true;
|
|
|
|
|
mPlayerWidget->show();
|
2020-06-06 07:39:55 +00:00
|
|
|
|
ui->verticalLayout->addWidget(mPlayerWidget);
|
2020-07-05 14:35:35 +00:00
|
|
|
|
qDebug()<<ui->verticalLayout->layout();
|
2020-06-06 07:39:55 +00:00
|
|
|
|
ui->verticalLayout->setStretch(0,1);
|
|
|
|
|
ui->verticalLayout->setStretch(1,0);
|
|
|
|
|
ui->verticalLayout->setStretch(2,9);
|
|
|
|
|
|
|
|
|
|
} else{
|
2020-06-04 15:28:45 +00:00
|
|
|
|
m_bCameraOpen = false;
|
|
|
|
|
ui->pushButton->setText("打开摄像头");
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-06-05 02:18:37 +00:00
|
|
|
|
|
|
|
|
|
void MainWindow::on_pushButton_2_clicked()
|
|
|
|
|
{
|
|
|
|
|
if(!m_bRtmpPushing){
|
|
|
|
|
if(!m_bCameraOpen){
|
|
|
|
|
ToastWidget::showTip("请打开摄像头",this);
|
2020-06-05 15:59:47 +00:00
|
|
|
|
return;
|
|
|
|
|
}else{
|
|
|
|
|
//
|
|
|
|
|
if(nullptr == mVideoCoder){
|
|
|
|
|
mVideoCoder = new VideoCoder(mCamera->GetWidth(),
|
|
|
|
|
mCamera->GetHeight(),
|
|
|
|
|
GUIDToAvFormat(mCamera->MediaType()));
|
|
|
|
|
}
|
|
|
|
|
mCamera->SetObserver(mVideoCoder);
|
|
|
|
|
|
|
|
|
|
// todo 根据返回结果判断是否推流
|
2020-06-06 15:22:37 +00:00
|
|
|
|
qDebug()<<"连接RTMP服务器"<<ui->lineEdit->text();
|
2020-06-05 15:59:47 +00:00
|
|
|
|
if (!mPusher->IfConnect()) {
|
2020-06-05 17:51:09 +00:00
|
|
|
|
const char* address = ui->lineEdit->text().toLocal8Bit().data();
|
2020-07-07 16:04:24 +00:00
|
|
|
|
qDebug()<<address;
|
|
|
|
|
if (0 == mPusher->RTMP264_Connect("rtmp://127.0.0.1:1939/live/1")) {
|
2020-06-05 15:59:47 +00:00
|
|
|
|
ToastWidget::showTip("已经连接上RTMP服务器",this);
|
|
|
|
|
mVideoCoder->SetOberver(mPusher);
|
|
|
|
|
mPusher->StartPush();
|
2020-06-18 17:14:18 +00:00
|
|
|
|
ui->pushButton_2->setText("关闭推流");
|
2020-06-05 15:59:47 +00:00
|
|
|
|
/*
|
|
|
|
|
if (nullptr != this->mAudioCoder) {
|
|
|
|
|
this->mAudioCoder->SetObserver(mPusher);
|
|
|
|
|
//音频流先不推流
|
|
|
|
|
}*/
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
ToastWidget::showTip("连接RTMP服务器失败,请检查服务器地址",this);
|
|
|
|
|
}
|
2020-06-18 17:14:18 +00:00
|
|
|
|
}else{
|
|
|
|
|
ToastWidget::showTip("正在推流,请先关闭",this);
|
|
|
|
|
|
2020-06-05 15:59:47 +00:00
|
|
|
|
}
|
2020-06-05 02:18:37 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-06-05 15:59:47 +00:00
|
|
|
|
|
2020-06-19 09:30:29 +00:00
|
|
|
|
|
|
|
|
|
void MainWindow::on_pushButton_3_clicked()
|
|
|
|
|
{
|
2020-06-21 17:13:44 +00:00
|
|
|
|
qDebug()<<ui->comboBox_2->currentText();
|
2020-06-19 09:30:29 +00:00
|
|
|
|
}
|
2020-12-06 16:01:38 +00:00
|
|
|
|
|
|
|
|
|
void MainWindow::DetectDpi()
|
|
|
|
|
{
|
|
|
|
|
qDebug()<<"detect dpi";
|
|
|
|
|
int horizontalDPI = logicalDpiX();
|
|
|
|
|
int verticalDPI = logicalDpiY();
|
|
|
|
|
|
|
|
|
|
qDebug()<<horizontalDPI<<verticalDPI<<physicalDpiX()<<physicalDpiY();
|
|
|
|
|
|
|
|
|
|
}
|