完善capturer
parent
4b75ee116a
commit
e8fd8f8195
|
@ -43,7 +43,7 @@ QWidget#qssTitleBar >QPushButton#titlebarrestorebtn{
|
||||||
image: url(":/qss/icon/btn_max_normal.svg");
|
image: url(":/qss/icon/btn_max_normal.svg");
|
||||||
background: rgb(187, 212, 238);
|
background: rgb(187, 212, 238);
|
||||||
width: 25px;
|
width: 25px;
|
||||||
height:25px;
|
height:25pt;
|
||||||
margin-left: 1px;
|
margin-left: 1px;
|
||||||
margin-right: 2px;
|
margin-right: 2px;
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,7 @@ QPushButton:enabled:pressed {
|
||||||
QPushButton#pushButton:enabled {
|
QPushButton#pushButton:enabled {
|
||||||
background: white;
|
background: white;
|
||||||
color: black;
|
color: black;
|
||||||
border-radius:3px;
|
border-radius:3pd;
|
||||||
}
|
}
|
||||||
|
|
||||||
QPushButton#pushButton:!enabled {
|
QPushButton#pushButton:!enabled {
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
#include "camera_video_sink.h"
|
#include "camera_video_sink.h"
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
CameraVideoSink::CameraVideoSink() : m_vcm(nullptr) {
|
CameraVideoSink::CameraVideoSink() : m_vcm(nullptr) {
|
||||||
rtc::LogMessage::SetLogToStderr(true);
|
rtc::LogMessage::SetLogToStderr(true);
|
||||||
|
@ -75,30 +76,52 @@ void CameraVideoSink::OnFrame(const webrtc::VideoFrame& frame) {
|
||||||
std::chrono::system_clock::now().time_since_epoch()).count();
|
std::chrono::system_clock::now().time_since_epoch()).count();
|
||||||
static size_t cnt = 0;
|
static size_t cnt = 0;
|
||||||
|
|
||||||
rtc::scoped_refptr<webrtc::I420BufferInterface> frameBuffer = frame.video_frame_buffer()->ToI420();
|
qDebug()<<int(frame.video_frame_buffer()->type());
|
||||||
|
rtc::scoped_refptr<webrtc::I420BufferInterface> frameBuffer =
|
||||||
|
frame.video_frame_buffer()->ToI420();
|
||||||
cnt++;
|
cnt++;
|
||||||
m_buf.PushFirst(&frameBuffer);
|
int width = this->m_capability.width;
|
||||||
|
int height = this->m_capability.height;
|
||||||
|
qDebug()<<this->Capability().height<<this->Capability().width
|
||||||
|
<<int(this->Capability().videoType)
|
||||||
|
<<int(webrtc::VideoType::kI420)
|
||||||
|
<<this->Capability().interlaced<<width * height*4;
|
||||||
|
|
||||||
|
uint8_t *data =
|
||||||
|
new uint8_t[width * height*4];
|
||||||
|
qDebug()<<width*height<<int(frameBuffer->GetI420()->type());
|
||||||
|
memcpy(data,frameBuffer->GetI420()->DataY(),width*height);
|
||||||
|
memcpy(data + width*height ,frameBuffer->GetI420()->DataU(),width*height/4);
|
||||||
|
memcpy(data + width*height + width*height/4,
|
||||||
|
frameBuffer->GetI420()->DataY(),width*height/4);
|
||||||
|
|
||||||
|
m_buf.PushFirst(data);
|
||||||
auto timestamp_curr = std::chrono::duration_cast<std::chrono::milliseconds>(
|
auto timestamp_curr = std::chrono::duration_cast<std::chrono::milliseconds>(
|
||||||
std::chrono::system_clock::now().time_since_epoch()).count();
|
std::chrono::system_clock::now().time_since_epoch()).count();
|
||||||
if(timestamp_curr - timestamp > 1000) {
|
if(timestamp_curr - timestamp > 1000) {
|
||||||
RTC_LOG(LS_INFO) << "FPS: " << cnt<<m_buf.Size();
|
RTC_LOG(LS_INFO) << "FPS: " << cnt<<m_buf.Size();
|
||||||
cnt = 0;
|
cnt = 0;
|
||||||
timestamp = timestamp_curr;
|
timestamp = timestamp_curr;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
rtc::scoped_refptr<webrtc::I420BufferInterface> *FrameBufferList::TakeLast()
|
|
||||||
|
webrtc::VideoCaptureCapability CameraVideoSink::Capability()
|
||||||
|
{
|
||||||
|
return this->m_capability;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t *FrameBufferList::TakeLast()
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> guard(this->m_mutex);
|
std::lock_guard<std::mutex> guard(this->m_mutex);
|
||||||
if(m_data.size() != 0){
|
if(m_data.size() != 0){
|
||||||
rtc::scoped_refptr<webrtc::I420BufferInterface> * ret = *m_data.begin();
|
auto ret = *m_data.begin();
|
||||||
m_data.pop_front();
|
m_data.pop_front();
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void FrameBufferList::PushFirst(rtc::scoped_refptr<webrtc::I420BufferInterface> *v)
|
void FrameBufferList::PushFirst(uint8_t*v)
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> guard(this->m_mutex);
|
std::lock_guard<std::mutex> guard(this->m_mutex);
|
||||||
m_data.push_back(v);
|
m_data.push_back(v);
|
||||||
|
|
|
@ -12,11 +12,11 @@
|
||||||
|
|
||||||
class FrameBufferList{
|
class FrameBufferList{
|
||||||
public:
|
public:
|
||||||
rtc::scoped_refptr<webrtc::I420BufferInterface>* TakeLast();
|
uint8_t* TakeLast();
|
||||||
void PushFirst(rtc::scoped_refptr<webrtc::I420BufferInterface>*);
|
void PushFirst(uint8_t*);
|
||||||
uint16_t Size();
|
uint16_t Size();
|
||||||
private:
|
private:
|
||||||
std::list<rtc::scoped_refptr<webrtc::I420BufferInterface>*> m_data;
|
std::list<uint8_t*> m_data;
|
||||||
std::mutex m_mutex;
|
std::mutex m_mutex;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -33,6 +33,10 @@ public:
|
||||||
size_t capture_device_index);
|
size_t capture_device_index);
|
||||||
virtual ~CameraVideoSink();
|
virtual ~CameraVideoSink();
|
||||||
void OnFrame(const webrtc::VideoFrame& frame) override;
|
void OnFrame(const webrtc::VideoFrame& frame) override;
|
||||||
|
webrtc::VideoCaptureCapability Capability();
|
||||||
|
FrameBufferList *VideoBuffer(){
|
||||||
|
return &this->m_buf;
|
||||||
|
}
|
||||||
signals:
|
signals:
|
||||||
void UpdateFrame(rtc::scoped_refptr<webrtc::I420BufferInterface>& buffer);
|
void UpdateFrame(rtc::scoped_refptr<webrtc::I420BufferInterface>& buffer);
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -107,7 +107,7 @@ CPlayWidget::CPlayWidget(QWidget *parent):QOpenGLWidget(parent) {
|
||||||
m_pTextureV = NULL;
|
m_pTextureV = NULL;
|
||||||
m_nVideoH = 0;
|
m_nVideoH = 0;
|
||||||
m_nVideoW = 0;
|
m_nVideoW = 0;
|
||||||
mType = TYPE_UNSET;
|
mType = TYPE_I420;
|
||||||
}
|
}
|
||||||
|
|
||||||
CPlayWidget::~CPlayWidget() {
|
CPlayWidget::~CPlayWidget() {
|
||||||
|
@ -116,6 +116,7 @@ CPlayWidget::~CPlayWidget() {
|
||||||
|
|
||||||
int CPlayWidget::SetDataType(CPlayWidget::IMG_TYPE type){
|
int CPlayWidget::SetDataType(CPlayWidget::IMG_TYPE type){
|
||||||
this->mType = type;
|
this->mType = type;
|
||||||
|
// initializeGL();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -132,7 +133,7 @@ void CPlayWidget::OnCameraData( rtc::scoped_refptr<webrtc::I420BufferInterface>
|
||||||
|
|
||||||
int CPlayWidget::OnCameraData(uint8_t *p)
|
int CPlayWidget::OnCameraData(uint8_t *p)
|
||||||
{
|
{
|
||||||
memcpy(m_pBufYuv420p,p,640*480/2*3);
|
memcpy(m_pBufYuv420p,p,m_nVideoH*m_nVideoW/2*3);
|
||||||
update();
|
update();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -180,7 +181,7 @@ void CPlayWidget::initializeGL()
|
||||||
bool bCompile = m_pVSHader->compileSourceCode(vsrcyuv);
|
bool bCompile = m_pVSHader->compileSourceCode(vsrcyuv);
|
||||||
if(!bCompile)
|
if(!bCompile)
|
||||||
{
|
{
|
||||||
// todo ?????????
|
|
||||||
}
|
}
|
||||||
m_pFSHader = new QOpenGLShader(QOpenGLShader::Fragment, this);
|
m_pFSHader = new QOpenGLShader(QOpenGLShader::Fragment, this);
|
||||||
if(mType == TYPE_RGB32){
|
if(mType == TYPE_RGB32){
|
||||||
|
@ -194,6 +195,7 @@ void CPlayWidget::initializeGL()
|
||||||
}
|
}
|
||||||
if(!bCompile)
|
if(!bCompile)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
#define PROGRAM_VERTEX_ATTRIBUTE 0
|
#define PROGRAM_VERTEX_ATTRIBUTE 0
|
||||||
#define PROGRAM_TEXCOORD_ATTRIBUTE 1
|
#define PROGRAM_TEXCOORD_ATTRIBUTE 1
|
||||||
|
|
|
@ -77,7 +77,7 @@ int main(int argc, char *argv[])
|
||||||
qRegisterMetaType<rtc::scoped_refptr<webrtc::I420BufferInterface>>("rtc::scoped_refptr<webrtc::I420BufferInterface>");
|
qRegisterMetaType<rtc::scoped_refptr<webrtc::I420BufferInterface>>("rtc::scoped_refptr<webrtc::I420BufferInterface>");
|
||||||
qRegisterMetaType<rtc::scoped_refptr<webrtc::I420BufferInterface>>("rtc::scoped_refptr<webrtc::I420BufferInterface>&");
|
qRegisterMetaType<rtc::scoped_refptr<webrtc::I420BufferInterface>>("rtc::scoped_refptr<webrtc::I420BufferInterface>&");
|
||||||
|
|
||||||
QCoreApplication::setAttribute(Qt::AA_DisableHighDpiScaling);
|
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
|
||||||
QApplication a(argc, argv);
|
QApplication a(argc, argv);
|
||||||
MainWindow w;
|
MainWindow w;
|
||||||
// QObject::connect((CameraVideoSink*)capturer.get(),SIGNAL(UpdateFrame(rtc::scoped_refptr<webrtc::I420BufferInterface>&)),&w,
|
// QObject::connect((CameraVideoSink*)capturer.get(),SIGNAL(UpdateFrame(rtc::scoped_refptr<webrtc::I420BufferInterface>&)),&w,
|
||||||
|
|
|
@ -1,12 +1,51 @@
|
||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
#include "ui_mainwindow.h"
|
#include "ui_mainwindow.h"
|
||||||
#
|
#include "camera_video_sink.h"
|
||||||
|
|
||||||
|
class AsyncRennder :public QSSASyncProcess{
|
||||||
|
public:
|
||||||
|
AsyncRennder(QWidget * parent,FrameBufferList* p,CPlayWidget *render_ui){
|
||||||
|
this->mParent = parent;
|
||||||
|
this->mfbs = p;
|
||||||
|
mUI = render_ui;
|
||||||
|
this->state = true;
|
||||||
|
}
|
||||||
|
// 停止渲染
|
||||||
|
void StopRender(){
|
||||||
|
state = false;
|
||||||
|
}
|
||||||
|
void Run(void *) override{
|
||||||
|
QEventLoop eventLoop;
|
||||||
|
auto qtimer = new QTimer(this);
|
||||||
|
qtimer->setSingleShot(false);
|
||||||
|
|
||||||
|
QObject::connect(qtimer, SIGNAL(timeout()), &eventLoop, SLOT(quit()));
|
||||||
|
qtimer->start(10);
|
||||||
|
|
||||||
|
while(state){
|
||||||
|
if(mfbs ->Size() > 0){
|
||||||
|
uint8_t *frame = this->mfbs->TakeLast();
|
||||||
|
mUI->OnCameraData(frame);
|
||||||
|
eventLoop.exec(); // 渲染一次
|
||||||
|
delete frame;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private:
|
||||||
|
FrameBufferList *mfbs;
|
||||||
|
bool state = false;
|
||||||
|
CPlayWidget *mUI;
|
||||||
|
};
|
||||||
|
|
||||||
|
AsyncRennder *gRender;
|
||||||
|
|
||||||
MainWindow::MainWindow(QWidget *parent)
|
MainWindow::MainWindow(QWidget *parent)
|
||||||
: QssMainWindow(parent)
|
: QssMainWindow(parent)
|
||||||
, ui(new Ui::MainWindow)
|
, ui(new Ui::MainWindow)
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
ui->openGLWidget->SetImgSize(640,480);
|
// ui->openGLWidget->SetImgSize(640,480);
|
||||||
ui->openGLWidget->show();
|
ui->openGLWidget->show();
|
||||||
|
|
||||||
std::unique_ptr<webrtc::VideoCaptureModule::DeviceInfo> info(
|
std::unique_ptr<webrtc::VideoCaptureModule::DeviceInfo> info(
|
||||||
|
@ -24,6 +63,7 @@ MainWindow::MainWindow(QWidget *parent)
|
||||||
// break;
|
// break;
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
MainWindow::~MainWindow()
|
MainWindow::~MainWindow()
|
||||||
|
@ -36,7 +76,6 @@ void MainWindow::OnUpdateFrame( rtc::scoped_refptr<webrtc::I420BufferInterface>&
|
||||||
ui->openGLWidget->OnCameraData(buffer);
|
ui->openGLWidget->OnCameraData(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void MainWindow::on_pushButton_clicked()
|
void MainWindow::on_pushButton_clicked()
|
||||||
{
|
{
|
||||||
int id = ui->comboBox->currentData().toInt();
|
int id = ui->comboBox->currentData().toInt();
|
||||||
|
@ -45,5 +84,19 @@ void MainWindow::on_pushButton_clicked()
|
||||||
if (!m_capturer) {
|
if (!m_capturer) {
|
||||||
qDebug()<<"error";
|
qDebug()<<"error";
|
||||||
}
|
}
|
||||||
|
ui->openGLWidget->SetDataType(CPlayWidget::TYPE_YUV420P);
|
||||||
|
ui->openGLWidget->SetImgSize(m_capturer->Capability().width,
|
||||||
|
m_capturer->Capability().height);
|
||||||
|
// ui->openGLWidget->moveToThread(&gRender->Thread());
|
||||||
|
if(gRender == nullptr){
|
||||||
|
gRender = new AsyncRennder(this,m_capturer->VideoBuffer(),ui->openGLWidget);
|
||||||
|
gRender->Start(this);
|
||||||
|
connect(gRender,&QSSASyncProcess::Done,this,&MainWindow::RenderDone);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::RenderDone()
|
||||||
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@ public slots:
|
||||||
void OnUpdateFrame( rtc::scoped_refptr<webrtc::I420BufferInterface>& buffer);
|
void OnUpdateFrame( rtc::scoped_refptr<webrtc::I420BufferInterface>& buffer);
|
||||||
private slots:
|
private slots:
|
||||||
void on_pushButton_clicked();
|
void on_pushButton_clicked();
|
||||||
|
void RenderDone();
|
||||||
private:
|
private:
|
||||||
Ui::MainWindow *ui;
|
Ui::MainWindow *ui;
|
||||||
std::unique_ptr<CameraVideoSink> m_capturer;
|
std::unique_ptr<CameraVideoSink> m_capturer;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
QT += core gui
|
QT += core gui
|
||||||
|
|
||||||
include(D:\\project\\c++qt\\qsswraper\\qsswraper.pri)
|
include(D:\\project\\qt_project\\qsswraper\\qsswraper.pri)
|
||||||
RESOURCES += $$PWD/qss/qss.qrc
|
RESOURCES += $$PWD/qss/qss.qrc
|
||||||
|
|
||||||
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
|
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
|
||||||
|
|
Loading…
Reference in New Issue