From 3c3acecfe4f2dc3eb4fe8da1d537334a39d12cb1 Mon Sep 17 00:00:00 2001 From: tianduanrui Date: Tue, 11 Jun 2019 19:05:33 +0800 Subject: [PATCH] video manager module, prepare to support android. --- src/multimedia/qqtvideomanager.cpp | 55 +++++++++++++++++++-- src/multimedia/qqtvideomanager.h | 27 ++++++++-- test/videotest/android/AndroidManifest.xml | 1 + test/videotest/mainwindow.cpp | 1 + test/videotest/mainwindow.ui | 29 ++++++++--- test/videotest/videotest.pro | 2 +- test/videotest2/android/AndroidManifest.xml | 1 + test/videotest2/mainwindow.ui | 30 ++++++----- test/videotest2/videotest2.pro | 2 +- test/videotest3/android/AndroidManifest.xml | 1 + test/videotest3/videotest3.pro | 2 +- 11 files changed, 122 insertions(+), 29 deletions(-) diff --git a/src/multimedia/qqtvideomanager.cpp b/src/multimedia/qqtvideomanager.cpp index 6e46bfd5..2a63e697 100644 --- a/src/multimedia/qqtvideomanager.cpp +++ b/src/multimedia/qqtvideomanager.cpp @@ -13,7 +13,7 @@ QQtCameraVideoSurface::~QQtCameraVideoSurface() QList QQtCameraVideoSurface::supportedPixelFormats ( QAbstractVideoBuffer::HandleType handleType ) const { -#ifdef __ANDROID__ +#ifdef Q_OS_ANDROID //Android NV21 return QList() << QVideoFrame::Format_NV21; @@ -63,12 +63,52 @@ bool QQtCameraVideoSurface::present ( const QVideoFrame& frame ) return true; } +QQtVideoProbe::QQtVideoProbe ( QObject* parent ) : QQtCameraVideoSurface ( parent ) +{ + m_mediaObject = 0; + m_AndroidProber = 0; +} + +QQtVideoProbe::~QQtVideoProbe() +{ +} + +void QQtVideoProbe::setMediaObject ( QMediaObject* mediaObject ) +{ + Q_ASSERT ( mediaObject ); +#ifdef Q_OS_ANDROID + if ( m_AndroidProber ) + { + //m_AndroidProber->setSource ( nullptr ); + disconnect ( m_AndroidProber, SIGNAL ( videoFrameProbed ( const QVideoFrame& ) ), + this, SLOT ( slotVideoFrame ( const QVideoFrame& ) ) ); + m_AndroidProber->deleteLater(); + } + + m_mediaObject = mediaObject; + m_AndroidProber = new QVideoProbe ( this ); + connect ( m_AndroidProber, SIGNAL ( videoFrameProbed ( const QVideoFrame& ) ), + this, SLOT ( slotVideoFrame ( const QVideoFrame& ) ) ); + m_AndroidProber->setSource ( m_mediaObject ); +#endif +} + +QMediaObject* QQtVideoProbe::mediaObject() const +{ + return m_mediaObject; +} + +void QQtVideoProbe::slotVideoFrame ( const QVideoFrame& frame ) +{ + present ( frame ); +} + QQtVideoInput::QQtVideoInput ( QObject* parent ) : QObject ( parent ) { /** * 设置视频截图工具 */ - mSurface = new QQtCameraVideoSurface ( this ); + mSurface = new QQtVideoProbe ( this ); connect ( mSurface, SIGNAL ( readyRead ( QImage ) ), this, SIGNAL ( readyRead ( QImage ) ) ); connect ( mSurface, SIGNAL ( readyRead ( QImage ) ), this, SLOT ( slotImageCaptured ( QImage ) ) ); @@ -80,7 +120,12 @@ QQtVideoInput::QQtVideoInput ( QObject* parent ) : QObject ( parent ) //QQtCamera 默认就是使用默认照相机,所以,这里不必设置了。 mCamInfo = defaultCamera(); mCamera->setCameraInfo ( mCamInfo ); + +#ifdef Q_OS_ANDROID + mSurface->setMediaObject ( mCamera->camera() ); +#else mCamera->setViewfinder ( mSurface ); +#endif // mExposure = new QQtCameraExposure ( this ); @@ -185,14 +230,18 @@ void QQtVideoInput::start() if ( !mCamera->isCaptureModeSupported ( QCamera::CaptureVideo ) ) { pline() << mCamInfo.deviceName(); - pline() << mCamera << "Camera cannot capture video"; + //pline() << mCamera << "Camera cannot capture video"; } //播放图像 = QCamera::CaptureStillImage //播放图像 = QCamera::CaptureViewfinder mCamera->setCaptureMode ( QCamera::CaptureVideo ); //设置输出 +#ifdef Q_OS_ANDROID + mSurface->setMediaObject ( mCamera->camera() ); +#else mCamera->setViewfinder ( mSurface ); +#endif //设置ViewfinderSettings //启动后设置... diff --git a/src/multimedia/qqtvideomanager.h b/src/multimedia/qqtvideomanager.h index f1b75324..9ea7e825 100644 --- a/src/multimedia/qqtvideomanager.h +++ b/src/multimedia/qqtvideomanager.h @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -22,12 +23,13 @@ * | 使用方式 | Parent | Property Class | Childen | 备注 * --------------------------------------------------------------------------------------------------------------------- * | setViewfinder | QAbstractVideoSurface | QQtCameraVideoSurface | | 视频,快,Buffer + * | | | | QQtVideoProbe | 视频,快,Buffer,+Android支持 * --------------------------------------------------------------------------------------------------------------------- * | setViewfinder | QMediaBindableInterface | QGraphicsVideoItem | | QGraphicsItem 系统专用 * | | | QVideoWidget | QCameraViewfinder | 视频,快,属于输出位置上的 * --------------------------------------------------------------------------------------------------------------------- * | setMetaObject | QMediaBindableInterface | QCameraImageCapture | | 截图,慢,默认保存文件 - * | | | QMediaRecoder | QAudioRecoder | 录像,快,保存文件,音视频 + * | | | QMediaRecorder | QAudioRecorder | 录像,快,保存文件,音视频 * --------------------------------------------------------------------------------------------------------------------- */ @@ -42,7 +44,6 @@ * @brief The QQtVideoSurface class * 从metaObject获取视频数据,帧。 * Buffer,快速。 - * 还有一个Android平台的,QVideoProbe */ class QQTSHARED_EXPORT QQtCameraVideoSurface : public QAbstractVideoSurface { @@ -60,6 +61,26 @@ public: virtual bool present ( const QVideoFrame& frame ) override; }; +class QQTSHARED_EXPORT QQtVideoProbe : public QQtCameraVideoSurface +{ + Q_OBJECT +public: + QQtVideoProbe ( QObject* parent = 0 ); + virtual ~QQtVideoProbe(); + + void setMediaObject ( QMediaObject* mediaObject ); + QMediaObject* mediaObject() const; + + /** + * 以下与用户无关。 + */ +private slots: + void slotVideoFrame ( const QVideoFrame& frame ); +private: + QMediaObject* m_mediaObject; + QVideoProbe* m_AndroidProber; +}; + /** * @brief The QQtVideoInput class * 图像输入 @@ -140,7 +161,7 @@ private: //经过调试,QCamera句柄,一个进程只能存在一个。 QQtCamera* mCamera; QCameraInfo mCamInfo; - QQtCameraVideoSurface* mSurface; + QQtVideoProbe* mSurface; QQtCameraExposure* mExposure; QQtCameraFocus* mFocus; QQtCameraImageProcessing* mImageProcessing; diff --git a/test/videotest/android/AndroidManifest.xml b/test/videotest/android/AndroidManifest.xml index caa60f69..44733f0a 100644 --- a/test/videotest/android/AndroidManifest.xml +++ b/test/videotest/android/AndroidManifest.xml @@ -86,4 +86,5 @@ + diff --git a/test/videotest/mainwindow.cpp b/test/videotest/mainwindow.cpp index 601a1e06..aac7476d 100644 --- a/test/videotest/mainwindow.cpp +++ b/test/videotest/mainwindow.cpp @@ -10,6 +10,7 @@ MainWindow::MainWindow ( QWidget* parent ) : input = new QQtVideoInput ( this ); pline() << input->defaultCamera(); pline() << input ->availableCameras(); + return; pline() << input->viewFinderSettings().pixelFormat(); pline() << input->camera()->supportedViewfinderPixelFormats(); diff --git a/test/videotest/mainwindow.ui b/test/videotest/mainwindow.ui index dde49250..f102800f 100644 --- a/test/videotest/mainwindow.ui +++ b/test/videotest/mainwindow.ui @@ -17,19 +17,37 @@ + + 0 + + + + Camera Information + + + + + 20 + 20 + 141 + 161 + + + + Preview - + - + - + @@ -76,11 +94,6 @@ - - - Tab 2 - - diff --git a/test/videotest/videotest.pro b/test/videotest/videotest.pro index 6050d389..fa6d2c93 100644 --- a/test/videotest/videotest.pro +++ b/test/videotest/videotest.pro @@ -42,7 +42,7 @@ add_version(1,0,0,0) add_deploy() add_deploy_config($${PWD}/AppRoot) add_dependent_manager(QQt) -add_dependent_manager(QQtMediaExtention) +#add_dependent_manager(QQtMediaExtention) system(touch main.cpp) #------------------------------------------------- diff --git a/test/videotest2/android/AndroidManifest.xml b/test/videotest2/android/AndroidManifest.xml index 09b7bc85..0a81f5c7 100644 --- a/test/videotest2/android/AndroidManifest.xml +++ b/test/videotest2/android/AndroidManifest.xml @@ -86,4 +86,5 @@ + diff --git a/test/videotest2/mainwindow.ui b/test/videotest2/mainwindow.ui index d391d503..7f2e0559 100644 --- a/test/videotest2/mainwindow.ui +++ b/test/videotest2/mainwindow.ui @@ -16,10 +16,10 @@ - + - + @@ -32,10 +32,10 @@ - 10 - 10 - 71 - 16 + 0 + 0 + 81 + 31 @@ -46,9 +46,9 @@ 100 - 10 - 80 - 16 + 0 + 81 + 31 @@ -59,11 +59,17 @@ 200 - 10 - 80 - 16 + 0 + 81 + 31 + + + 0 + 0 + + Capture diff --git a/test/videotest2/videotest2.pro b/test/videotest2/videotest2.pro index 295208e5..c445affc 100644 --- a/test/videotest2/videotest2.pro +++ b/test/videotest2/videotest2.pro @@ -42,7 +42,7 @@ add_version(1,0,0,0) add_deploy() add_deploy_config($${PWD}/AppRoot) add_dependent_manager(QQt) -add_dependent_manager(QQtMediaExtention) +#add_dependent_manager(QQtMediaExtention) system(touch main.cpp) #------------------------------------------------- diff --git a/test/videotest3/android/AndroidManifest.xml b/test/videotest3/android/AndroidManifest.xml index e1ba04ff..dcf0c1e4 100644 --- a/test/videotest3/android/AndroidManifest.xml +++ b/test/videotest3/android/AndroidManifest.xml @@ -86,4 +86,5 @@ + diff --git a/test/videotest3/videotest3.pro b/test/videotest3/videotest3.pro index 584527dd..f3229f4f 100644 --- a/test/videotest3/videotest3.pro +++ b/test/videotest3/videotest3.pro @@ -45,7 +45,7 @@ add_version(1,0,0,0) add_deploy() add_deploy_config($${PWD}/AppRoot) add_dependent_manager(QQt) -add_dependent_manager(QQtMediaExtention) +#add_dependent_manager(QQtMediaExtention) system(touch main.cpp) #-------------------------------------------------