From cd5b92f41bd40529a4b8a5fe08c59f6d21bc4ccc Mon Sep 17 00:00:00 2001 From: Joao Carreira Date: Mon, 31 Mar 2014 00:06:06 +0100 Subject: [PATCH] Add function to return current format and set initial parameters --- source/app/InputStream.cpp | 100 +++++++++++++++++++-------------- source/app/InputStream.h | 6 +- source/app/SubWindowHandle.cpp | 2 + 3 files changed, 64 insertions(+), 44 deletions(-) diff --git a/source/app/InputStream.cpp b/source/app/InputStream.cpp index 25f4897..60ccfd3 100755 --- a/source/app/InputStream.cpp +++ b/source/app/InputStream.cpp @@ -111,47 +111,6 @@ QStringList InputStream::supportedWriteFormatsList() return formats; } -Bool InputStream::guessFormat( QString filename, UInt& rWidth, UInt& rHeight, Int& rInputFormat, UInt& rFrameRate ) -{ - Bool bRet = false; - QString fileExtension = QFileInfo( filename ).completeSuffix(); - if( !fileExtension.compare( "yuv" ) ) - { - bRet = true; - // Guess resolution - match %dx%d -#if( QT_VERSION_PLAYUVER == 5 ) - QRegularExpressionMatch resolutionMatch = QRegularExpression( "_\\d*x\\d*_" ).match( filename ); - if( resolutionMatch.hasMatch() ) - { - QString resolutionString = resolutionMatch.captured( 0 ); - if( resolutionString.startsWith( "_" ) && resolutionString.endsWith( "_" ) ) - { - resolutionString.remove( "_" ); - QStringList resolutionArgs = resolutionString.split( "x" ); - qDebug( ) << "Found resolution = " - << resolutionArgs; - if( resolutionArgs.size() == 2 ) - { - rWidth = resolutionArgs.at( 0 ).toUInt(); - rHeight = resolutionArgs.at( 1 ).toUInt(); - } - } - } -#endif - // Guess pixel format - QStringList formats_list = PlaYUVerFrame::supportedPixelFormatList(); - for( Int i = 0; i < formats_list.size(); i++ ) - { - if( filename.contains( formats_list.at( i ), Qt::CaseInsensitive ) ) - { - rInputFormat = i; - break; - } - } - } - return bRet; -} - Bool InputStream::open( QString filename, UInt width, UInt height, Int input_format, UInt frame_rate ) { Bool avStatus = false; @@ -264,6 +223,65 @@ Void InputStream::close() m_bInit = false; } +Void InputStream::getFormat( UInt& rWidth, UInt& rHeight, Int& rInputFormat, UInt& rFrameRate ) +{ + if( m_bInit ) + { + rWidth = m_uiWidth; + rHeight = m_uiHeight; + rInputFormat = m_iPixelFormat; + rFrameRate = m_uiFrameRate; + } + else + { + rWidth = 0; + rHeight = 0; + rInputFormat = -1; + rFrameRate = 30; + } +} + +Bool InputStream::guessFormat( QString filename, UInt& rWidth, UInt& rHeight, Int& rInputFormat, UInt& rFrameRate ) +{ + Bool bRet = false; + QString fileExtension = QFileInfo( filename ).completeSuffix(); + if( !fileExtension.compare( "yuv" ) ) + { + bRet = true; + // Guess resolution - match %dx%d +#if( QT_VERSION_PLAYUVER == 5 ) + QRegularExpressionMatch resolutionMatch = QRegularExpression( "_\\d*x\\d*_" ).match( filename ); + if( resolutionMatch.hasMatch() ) + { + QString resolutionString = resolutionMatch.captured( 0 ); + if( resolutionString.startsWith( "_" ) && resolutionString.endsWith( "_" ) ) + { + resolutionString.remove( "_" ); + QStringList resolutionArgs = resolutionString.split( "x" ); + qDebug( ) << "Found resolution = " + << resolutionArgs; + if( resolutionArgs.size() == 2 ) + { + rWidth = resolutionArgs.at( 0 ).toUInt(); + rHeight = resolutionArgs.at( 1 ).toUInt(); + } + } + } +#endif + // Guess pixel format + QStringList formats_list = PlaYUVerFrame::supportedPixelFormatList(); + for( Int i = 0; i < formats_list.size(); i++ ) + { + if( filename.contains( formats_list.at( i ), Qt::CaseInsensitive ) ) + { + rInputFormat = i; + break; + } + } + } + return bRet; +} + Void InputStream::readNextFrame() { UInt64 bytes_read = 0; diff --git a/source/app/InputStream.h b/source/app/InputStream.h index 9485095..c068468 100755 --- a/source/app/InputStream.h +++ b/source/app/InputStream.h @@ -104,12 +104,12 @@ public: YUVFormat = 0, // Use color space. }; - Bool needFormatDialog( QString filename ); - Bool guessFormat( QString filename, UInt& rWidth, UInt& rHeight, Int& rInputFormat, UInt& rFrameRate ); - Bool open( QString filename, UInt width, UInt height, Int input_format, UInt frame_rate ); Void close(); + Bool guessFormat( QString filename, UInt& rWidth, UInt& rHeight, Int& rInputFormat, UInt& rFrameRate ); + Void getFormat( UInt& rWidth, UInt& rHeight, Int& rInputFormat, UInt& rFrameRate ); + Void readNextFrame(); Bool writeFrame( const QString& filename ); diff --git a/source/app/SubWindowHandle.cpp b/source/app/SubWindowHandle.cpp index a4db459..439b103 100644 --- a/source/app/SubWindowHandle.cpp +++ b/source/app/SubWindowHandle.cpp @@ -75,6 +75,8 @@ Bool SubWindowHandle::loadFile( const QString &fileName ) UInt Width = 0, Height = 0, FrameRate = 30; Int InputFormat = -1; + m_pCurrStream->getFormat( Width, Height, InputFormat, FrameRate ); + if( m_pCurrStream->guessFormat( fileName, Width, Height, InputFormat, FrameRate ) ) { ConfigureFormatDialog formatDialog( this );