88 lines
2.9 KiB
C++
88 lines
2.9 KiB
C++
#include "mainwindow.h"
|
||
#include "ui_mainwindow.h"
|
||
|
||
MainWindow::MainWindow(QWidget *parent) :
|
||
QMainWindow(parent),
|
||
ui(new Ui::MainWindow),
|
||
m_bCameraOpen(false),
|
||
mCamera(nullptr),
|
||
m_bRtmpPushing(false),
|
||
mPlayerWidget(nullptr),
|
||
mVideoCoder(nullptr),
|
||
mPusher(nullptr)
|
||
{
|
||
ui->setupUi(this);
|
||
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()));
|
||
}
|
||
mPusher = new H264RtmpPuser();
|
||
}
|
||
|
||
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);
|
||
}
|
||
//this->mCamera->SetObserver(mPlayerWidget);
|
||
qDebug()<<ui->comboBox->currentText();
|
||
ui->pushButton->setText("关闭摄像头");
|
||
m_bCameraOpen = true;
|
||
mPlayerWidget->show();
|
||
}else{
|
||
m_bCameraOpen = false;
|
||
ui->pushButton->setText("打开摄像头");
|
||
}
|
||
}
|
||
|
||
void MainWindow::on_pushButton_2_clicked()
|
||
{
|
||
if(!m_bRtmpPushing){
|
||
if(!m_bCameraOpen){
|
||
ToastWidget::showTip("请打开摄像头",this);
|
||
return;
|
||
}else{
|
||
//
|
||
if(nullptr == mVideoCoder){
|
||
mVideoCoder = new VideoCoder(mCamera->GetWidth(),
|
||
mCamera->GetHeight(),
|
||
GUIDToAvFormat(mCamera->MediaType()));
|
||
}
|
||
mCamera->SetObserver(mVideoCoder);
|
||
|
||
// todo 根据返回结果判断是否推流
|
||
if (!mPusher->IfConnect()) {
|
||
if (0 == mPusher->RTMP264_Connect(ui->lineEdit->text().toStdString().c_str())) {
|
||
ToastWidget::showTip("已经连接上RTMP服务器",this);
|
||
mVideoCoder->SetOberver(mPusher);
|
||
mPusher->StartPush();
|
||
/*
|
||
if (nullptr != this->mAudioCoder) {
|
||
this->mAudioCoder->SetObserver(mPusher);
|
||
//音频流先不推流
|
||
}*/
|
||
}
|
||
else {
|
||
ToastWidget::showTip("连接RTMP服务器失败,请检查服务器地址",this);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|