mirror of
https://gitee.com/drabel/LibQQt.git
synced 2025-01-04 10:18:44 +08:00
update videotest5 code.
This commit is contained in:
parent
248bd8397e
commit
5ebd3df8bd
@ -74,7 +74,7 @@ static int init_mmap ( struct cap_handle* handle )
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
handle->buffers = (buffer_t*)calloc ( req.count, sizeof ( struct buffer_t ) );
|
handle->buffers = ( buffer_t* ) calloc ( req.count, sizeof ( struct buffer_t ) );
|
||||||
if ( !handle->buffers )
|
if ( !handle->buffers )
|
||||||
{
|
{
|
||||||
printf ( "--- Calloc memory failed\n" );
|
printf ( "--- Calloc memory failed\n" );
|
||||||
@ -250,7 +250,7 @@ static int init_device ( struct cap_handle* handle )
|
|||||||
struct cap_handle* capture_open ( struct cap_param param )
|
struct cap_handle* capture_open ( struct cap_param param )
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
struct cap_handle* handle = (struct cap_handle*)malloc ( sizeof ( struct cap_handle ) );
|
struct cap_handle* handle = ( struct cap_handle* ) malloc ( sizeof ( struct cap_handle ) );
|
||||||
if ( !handle )
|
if ( !handle )
|
||||||
{
|
{
|
||||||
printf ( "--- malloc capture handle failed\n" );
|
printf ( "--- malloc capture handle failed\n" );
|
||||||
|
@ -1,14 +1,32 @@
|
|||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
#include "ui_mainwindow.h"
|
#include "ui_mainwindow.h"
|
||||||
|
|
||||||
MainWindow::MainWindow(QWidget *parent) :
|
MainWindow::MainWindow ( QWidget* parent ) :
|
||||||
QMainWindow(parent),
|
QMainWindow ( parent ),
|
||||||
ui(new Ui::MainWindow)
|
ui ( new Ui::MainWindow )
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi ( this );
|
||||||
|
|
||||||
|
manager = new QQtV4L2VideoManager ( this );
|
||||||
|
connect ( manager, SIGNAL ( readyRead ( QImage ) ), this, SLOT ( slotCaptured ( QImage ) ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
MainWindow::~MainWindow()
|
MainWindow::~MainWindow()
|
||||||
{
|
{
|
||||||
delete ui;
|
delete ui;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::on_pushButton_clicked()
|
||||||
|
{
|
||||||
|
manager->startCapture();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::on_pushButton_2_clicked()
|
||||||
|
{
|
||||||
|
manager->stopCapture();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::slotCaptured ( const QImage& img )
|
||||||
|
{
|
||||||
|
ui->widget->setPixmap ( img );
|
||||||
|
}
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
#define MAINWINDOW_H
|
#define MAINWINDOW_H
|
||||||
|
|
||||||
#include <QMainWindow>
|
#include <QMainWindow>
|
||||||
|
#include <qqtv4l2videomanager.h>
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
class MainWindow;
|
class MainWindow;
|
||||||
@ -12,11 +13,18 @@ class MainWindow : public QMainWindow
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit MainWindow(QWidget *parent = 0);
|
explicit MainWindow ( QWidget* parent = 0 );
|
||||||
~MainWindow();
|
~MainWindow();
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void on_pushButton_clicked();
|
||||||
|
void on_pushButton_2_clicked();
|
||||||
|
|
||||||
|
void slotCaptured ( const QImage& img );
|
||||||
private:
|
private:
|
||||||
Ui::MainWindow *ui;
|
Ui::MainWindow* ui;
|
||||||
|
|
||||||
|
QQtV4L2VideoManager* manager;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // MAINWINDOW_H
|
#endif // MAINWINDOW_H
|
||||||
|
@ -6,20 +6,52 @@
|
|||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>400</width>
|
<width>176</width>
|
||||||
<height>300</height>
|
<height>328</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
<string>videotest5</string>
|
<string>videotest5</string>
|
||||||
</property>
|
</property>
|
||||||
<widget class="QWidget" name="centralWidget"/>
|
<widget class="QWidget" name="centralWidget">
|
||||||
|
<layout class="QGridLayout" name="gridLayout">
|
||||||
|
<item row="0" column="0" colspan="2">
|
||||||
|
<widget class="QQtWidget" name="widget" native="true"/>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="0">
|
||||||
|
<widget class="QPushButton" name="pushButton">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Start</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="1">
|
||||||
|
<widget class="QPushButton" name="pushButton_2">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Stop</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
<widget class="QMenuBar" name="menuBar">
|
<widget class="QMenuBar" name="menuBar">
|
||||||
<property name="geometry">
|
<property name="geometry">
|
||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>400</width>
|
<width>176</width>
|
||||||
<height>17</height>
|
<height>17</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
@ -35,6 +67,14 @@
|
|||||||
<widget class="QStatusBar" name="statusBar"/>
|
<widget class="QStatusBar" name="statusBar"/>
|
||||||
</widget>
|
</widget>
|
||||||
<layoutdefault spacing="6" margin="11"/>
|
<layoutdefault spacing="6" margin="11"/>
|
||||||
|
<customwidgets>
|
||||||
|
<customwidget>
|
||||||
|
<class>QQtWidget</class>
|
||||||
|
<extends>QWidget</extends>
|
||||||
|
<header>qqtwidget.h</header>
|
||||||
|
<container>1</container>
|
||||||
|
</customwidget>
|
||||||
|
</customwidgets>
|
||||||
<resources/>
|
<resources/>
|
||||||
<connections/>
|
<connections/>
|
||||||
</ui>
|
</ui>
|
||||||
|
@ -1,19 +1,22 @@
|
|||||||
#include <qqtv4l2videomanager.h>
|
#include <qqtv4l2videomanager.h>
|
||||||
|
|
||||||
|
#include <linux/videodev2.h>
|
||||||
|
|
||||||
QQtV4L2VideoManager::QQtV4L2VideoManager ( QObject* parent ) : QObject ( parent )
|
QQtV4L2VideoManager::QQtV4L2VideoManager ( QObject* parent ) : QObject ( parent )
|
||||||
{
|
{
|
||||||
handler = 0;
|
handler = 0;
|
||||||
|
pp = 0;
|
||||||
|
frame = 0;
|
||||||
|
|
||||||
mDevName = "/dev/video0";
|
mDevName = "/dev/video0";
|
||||||
mSize = QSize ( 720, 480 );
|
mSize = QSize ( 720, 480 );
|
||||||
mFormat = 0; //NV21? YUV? RGB?
|
mFormat = V4L2_PIX_FMT_NV21; //NV21? YUV? RGB?
|
||||||
mRate = 30;
|
mRate = 10;
|
||||||
|
|
||||||
timer = new QTimer(this);
|
timer = new QTimer ( this );
|
||||||
timer->setSingleShot(false);
|
timer->setSingleShot ( false );
|
||||||
timer->setInterval(200);
|
timer->setInterval ( 100 );
|
||||||
connect(timer, SIGNAL(timeout()), this, SLOT(slotGetCapture()));
|
connect ( timer, SIGNAL ( timeout() ), this, SLOT ( slotGetCapture() ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
QQtV4L2VideoManager::~QQtV4L2VideoManager() {}
|
QQtV4L2VideoManager::~QQtV4L2VideoManager() {}
|
||||||
@ -40,14 +43,16 @@ void QQtV4L2VideoManager::setVideoRate ( int rate )
|
|||||||
|
|
||||||
void QQtV4L2VideoManager::startCapture()
|
void QQtV4L2VideoManager::startCapture()
|
||||||
{
|
{
|
||||||
if(handler)
|
if ( handler )
|
||||||
capture_close(handler);
|
capture_close ( handler );
|
||||||
|
|
||||||
struct cap_param param;
|
struct cap_param param;
|
||||||
param.dev_name = mDevName.toLocal8Bit().data();
|
param.dev_name = mDevName.toLocal8Bit().data();
|
||||||
param.width = mSize.width();
|
param.width = mSize.width();
|
||||||
param.height = mSize.height();
|
param.height = mSize.height();
|
||||||
param.rate = mRate;
|
param.rate = mRate;
|
||||||
handler = capture_open(param);
|
param.pixfmt = mFormat;
|
||||||
|
handler = capture_open ( param );
|
||||||
|
|
||||||
pp = ( unsigned char* ) malloc ( param.width * param.height * 3 * sizeof ( char ) );
|
pp = ( unsigned char* ) malloc ( param.width * param.height * 3 * sizeof ( char ) );
|
||||||
frame = new QImage ( pp, param.width, param.height, QImage::Format_RGB888 );
|
frame = new QImage ( pp, param.width, param.height, QImage::Format_RGB888 );
|
||||||
@ -56,11 +61,17 @@ void QQtV4L2VideoManager::startCapture()
|
|||||||
|
|
||||||
void QQtV4L2VideoManager::stopCapture()
|
void QQtV4L2VideoManager::stopCapture()
|
||||||
{
|
{
|
||||||
if(handler)
|
timer->stop();
|
||||||
capture_close(handler);
|
|
||||||
|
if ( handler )
|
||||||
|
capture_close ( handler );
|
||||||
|
if ( pp )
|
||||||
|
free ( pp );
|
||||||
|
if ( frame )
|
||||||
|
delete frame;
|
||||||
}
|
}
|
||||||
|
|
||||||
int QQtV4L2VideoManager::convert_yuv_to_rgb_pixel(int y, int u, int v)
|
int QQtV4L2VideoManager::convert_yuv_to_rgb_pixel ( int y, int u, int v )
|
||||||
{
|
{
|
||||||
unsigned int pixel32 = 0;
|
unsigned int pixel32 = 0;
|
||||||
unsigned char* pixel = ( unsigned char* ) &pixel32;
|
unsigned char* pixel = ( unsigned char* ) &pixel32;
|
||||||
@ -77,7 +88,7 @@ int QQtV4L2VideoManager::convert_yuv_to_rgb_pixel(int y, int u, int v)
|
|||||||
return pixel32;
|
return pixel32;
|
||||||
}
|
}
|
||||||
|
|
||||||
int QQtV4L2VideoManager::convert_yuv_to_rgb_buffer(unsigned char *yuv, unsigned char *rgb, unsigned int width, unsigned int height)
|
int QQtV4L2VideoManager::convert_yuv_to_rgb_buffer ( unsigned char* yuv, unsigned char* rgb, unsigned int width, unsigned int height )
|
||||||
{
|
{
|
||||||
unsigned int in, out = 0;
|
unsigned int in, out = 0;
|
||||||
unsigned int pixel_16;
|
unsigned int pixel_16;
|
||||||
@ -88,10 +99,10 @@ int QQtV4L2VideoManager::convert_yuv_to_rgb_buffer(unsigned char *yuv, unsigned
|
|||||||
for ( in = 0; in < width * height * 2; in += 4 )
|
for ( in = 0; in < width * height * 2; in += 4 )
|
||||||
{
|
{
|
||||||
pixel_16 =
|
pixel_16 =
|
||||||
yuv[in + 3] << 24 |
|
yuv[in + 3] << 24 |
|
||||||
yuv[in + 2] << 16 |
|
yuv[in + 2] << 16 |
|
||||||
yuv[in + 1] << 8 |
|
yuv[in + 1] << 8 |
|
||||||
yuv[in + 0];
|
yuv[in + 0];
|
||||||
y0 = ( pixel_16 & 0x000000ff );
|
y0 = ( pixel_16 & 0x000000ff );
|
||||||
u = ( pixel_16 & 0x0000ff00 ) >> 8;
|
u = ( pixel_16 & 0x0000ff00 ) >> 8;
|
||||||
y1 = ( pixel_16 & 0x00ff0000 ) >> 16;
|
y1 = ( pixel_16 & 0x00ff0000 ) >> 16;
|
||||||
@ -118,7 +129,7 @@ int QQtV4L2VideoManager::convert_yuv_to_rgb_buffer(unsigned char *yuv, unsigned
|
|||||||
void QQtV4L2VideoManager::slotGetCapture()
|
void QQtV4L2VideoManager::slotGetCapture()
|
||||||
{
|
{
|
||||||
int len = 0;
|
int len = 0;
|
||||||
capture_get_data(handler, (void**)&p, &len);
|
capture_get_data ( handler, ( void** ) &p, &len );
|
||||||
convert_yuv_to_rgb_buffer(p, pp, mSize.width(), mSize.height());
|
convert_yuv_to_rgb_buffer ( p, pp, mSize.width(), mSize.height() );
|
||||||
emit readyRead ( *frame );
|
emit readyRead ( *frame );
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user