diff --git a/app/ModulesHandle.cpp b/app/ModulesHandle.cpp index ae9b6d0..56535b5 100644 --- a/app/ModulesHandle.cpp +++ b/app/ModulesHandle.cpp @@ -470,7 +470,7 @@ Void ModulesHandle::applyAllModuleIf( PlaYUVerAppModuleIf *pcCurrModuleIf ) FrameRate = pcCurrModuleIf->m_pcSubWindow[0]->getInputStream()->getFrameRate(); pcCurrModuleIf->m_pcModuleStream = new PlaYUVerStream; - if( !pcCurrModuleIf->m_pcModuleStream->open( fileName, Width, Height, InputFormat, FrameRate, false ) ) + if( !pcCurrModuleIf->m_pcModuleStream->open( fileName.toStdString(), Width, Height, InputFormat, FrameRate, false ) ) { delete pcCurrModuleIf->m_pcModuleStream; pcCurrModuleIf->m_pcModuleStream = NULL; diff --git a/app/VideoHandle.cpp b/app/VideoHandle.cpp index 8959866..83e5b01 100644 --- a/app/VideoHandle.cpp +++ b/app/VideoHandle.cpp @@ -235,7 +235,9 @@ Void VideoHandle::update() total_frame_num = getMaxFrameNumber(); resolution.append( QString( "@%1" ).arg( pcStream->getFrameRate() ) ); - m_pcFormatCodeLabel->setText( QString( "%1 | %2" ).arg( pcStream->getFormatName() ).arg( pcStream->getCodecName() ) ); + m_pcFormatCodeLabel->setText( QString( "%1 | %2" ) + .arg( QString::fromStdString( pcStream->getFormatName() ) ) + .arg( QString::fromStdString( pcStream->getCodecName() ) ) ); } else { diff --git a/app/VideoSubWindow.cpp b/app/VideoSubWindow.cpp index 162571e..e51ce91 100644 --- a/app/VideoSubWindow.cpp +++ b/app/VideoSubWindow.cpp @@ -123,7 +123,7 @@ Bool VideoSubWindow::loadFile( QString cFilename, Bool bForceDialog ) if( m_pCurrStream ) m_pCurrStream->getFormat( Width, Height, InputFormat, FrameRate ); - if( m_pCurrStream->guessFormat( cFilename, Width, Height, InputFormat, FrameRate ) || bForceDialog ) + if( guessFormat( cFilename, Width, Height, InputFormat, FrameRate ) || bForceDialog ) { ConfigureFormatDialog formatDialog( this ); if( formatDialog.runConfigureFormatDialog( QFileInfo( cFilename ).fileName(), Width, Height, InputFormat, FrameRate ) == QDialog::Rejected ) @@ -144,7 +144,7 @@ Bool VideoSubWindow::loadFile( QString cFilename, Bool bForceDialog ) m_pCurrStream = new PlaYUVerStream; } - m_pCurrStream->open( cFilename, Width, Height, InputFormat, FrameRate ); + m_pCurrStream->open( cFilename.toStdString(), Width, Height, InputFormat, FrameRate ); m_sStreamInfo.m_cFilename = cFilename; m_sStreamInfo.m_uiWidth = Width; @@ -160,7 +160,12 @@ Bool VideoSubWindow::loadFile( QString cFilename, Bool bForceDialog ) m_cFilename = cFilename; m_cWindowShortName = QFileInfo( cFilename ).fileName(); - //setWindowName( m_pCurrStream->getStreamInformationString() ); + QString m_cFormatName = QString::fromStdString( m_pCurrStream->getFormatName() ); + QString m_cCodedName = QString::fromStdString( m_pCurrStream->getCodecName() ); + QString m_cPelFmtName = QString::fromStdString( m_pCurrStream->getPelFmtName() ); + m_cStreamInformationString = "[" + m_cFormatName + " / " + m_cCodedName + " / " + m_cPelFmtName + "] "; + m_cStreamInformationString += QFileInfo( m_cFilename ).fileName(); + setWindowName( m_cWindowShortName ); return true; } @@ -172,7 +177,7 @@ Bool VideoSubWindow::loadFile( PlaYUVerStreamInfo* streamInfo ) m_pCurrStream = new PlaYUVerStream; } - if( !m_pCurrStream->open( streamInfo->m_cFilename, streamInfo->m_uiWidth, streamInfo->m_uiHeight, streamInfo->m_iPelFormat, streamInfo->m_uiFrameRate ) ) + if( !m_pCurrStream->open( streamInfo->m_cFilename.toStdString(), streamInfo->m_uiWidth, streamInfo->m_uiHeight, streamInfo->m_iPelFormat, streamInfo->m_uiFrameRate ) ) { return false; } @@ -187,11 +192,113 @@ Bool VideoSubWindow::loadFile( PlaYUVerStreamInfo* streamInfo ) m_cFilename = streamInfo->m_cFilename; m_cWindowShortName = QFileInfo( streamInfo->m_cFilename ).fileName(); - //setWindowName( m_pCurrStream->getStreamInformationString() ); + QString m_cFormatName = QString::fromStdString( m_pCurrStream->getFormatName() ); + QString m_cCodedName = QString::fromStdString( m_pCurrStream->getCodecName() ); + QString m_cPelFmtName = QString::fromStdString( m_pCurrStream->getPelFmtName() ); + m_cStreamInformationString = "[" + m_cFormatName + " / " + m_cCodedName + " / " + m_cPelFmtName + "] "; + m_cStreamInformationString += QFileInfo( m_cFilename ).fileName(); + setWindowName( m_cWindowShortName ); return true; } +Bool VideoSubWindow::guessFormat( QString filename, UInt& rWidth, UInt& rHeight, Int& rInputFormat, UInt& rFrameRate ) +{ + std::vector stdResList = PlaYUVerStream::stdResolutionSizes(); + Bool bGuessed = true; + Bool bGuessedByFilesize = false; + QString FilenameShort = QFileInfo( filename ).fileName(); + QString fileExtension = QFileInfo( filename ).suffix(); + if( !fileExtension.compare( "yuv" ) ) + { + bGuessed = false; + // Guess pixel format + QVector formats_list = QVector::fromStdVector( PlaYUVerFrame::supportedPixelFormatListNames() ); + for( Int i = 0; i < formats_list.size(); i++ ) + { + if( FilenameShort.contains( formats_list.at( i ).data(), Qt::CaseInsensitive ) ) + { + rInputFormat = i; + break; + } + } + + if( rWidth == 0 || rHeight == 0 ) + { + // Guess resolution - match resolution name + Int iMatch = -1; + for( UInt i = 0; i < stdResList.size(); i++ ) + { + if( FilenameShort.contains( QString::fromStdString( stdResList[i].shortName ) ) ) + { + iMatch = i; + } + } + if( iMatch >= 0 ) + { + rWidth = stdResList[iMatch].uiWidth; + rHeight = stdResList[iMatch].uiHeight; + } + // Guess resolution - match %dx%d +#if( QT_VERSION_PLAYUVER == 5 ) + QRegularExpressionMatch resolutionMatch = QRegularExpression( "_\\d*x\\d*" ).match( FilenameShort ); + if( resolutionMatch.hasMatch() ) + { + QString resolutionString = resolutionMatch.captured( 0 ); + if( resolutionString.startsWith( "_" ) || resolutionString.endsWith( "_" ) ) + { + resolutionString.remove( "_" ); + QStringList resolutionArgs = resolutionString.split( "x" ); + if( resolutionArgs.size() == 2 ) + { + rWidth = resolutionArgs.at( 0 ).toUInt(); + rHeight = resolutionArgs.at( 1 ).toUInt(); + } + } + } +#endif + } + + // Guess resolution by file size + if( rWidth == 0 && rHeight == 0 ) + { + Char *filename_char = new char[filename.length() + 1]; + memcpy( filename_char, filename.toUtf8().constData(), filename.length() + 1 * sizeof(char) ); + FILE* pF = fopen( filename_char, "rb" ); + if( pF ) + { + fseek( pF, 0, SEEK_END ); + UInt64 uiFileSize = ftell( pF ); + fclose( pF ); + delete[] filename_char; + + Int count = 0, module, frame_bytes, match; + for( UInt i = 0; i < stdResList.size(); i++ ) + { + frame_bytes = PlaYUVerFrame::getBytesPerFrame( stdResList[i].uiWidth, stdResList[i].uiHeight, rInputFormat ); + module = uiFileSize % frame_bytes; + if( module == 0 ) + { + match = i; + count++; + } + } + if( count == 1 ) + { + rWidth = stdResList[match].uiWidth; + rHeight = stdResList[match].uiHeight; + bGuessedByFilesize = true; + } + } + } + + if( rWidth > 0 && rHeight > 0 && rInputFormat >= 0 ) + bGuessed = true && !bGuessedByFilesize; + } + return !bGuessed; +} + + Void VideoSubWindow::updateSelectedArea( QRect area ) { m_cSelectedArea = area; @@ -273,7 +380,7 @@ Bool VideoSubWindow::save( QString filename ) { return false; } - iRet = PlaYUVerStream::saveFrame( filename, saveFrame ); + iRet = PlaYUVerStream::saveFrame( filename.toStdString(), saveFrame ); QApplication::restoreOverrideCursor(); return iRet; } diff --git a/app/VideoSubWindow.h b/app/VideoSubWindow.h index b7c5cd9..690d4b3 100644 --- a/app/VideoSubWindow.h +++ b/app/VideoSubWindow.h @@ -64,13 +64,14 @@ private: ViewArea* m_cViewArea; + QString m_cFilename; + QString m_cStreamInformationString; PlaYUVerStreamInfo m_sStreamInfo; - PlaYUVerStream* m_pCurrStream; + PlaYUVerFrame* m_pcCurrFrame; QRect m_cSelectedArea; - QString m_cFilename; //PlaYUVerAppModuleIf* m_pcCurrentModule; QList m_apcCurrentModule; @@ -82,7 +83,7 @@ private: Bool m_bIsPlaying; Bool m_bIsModule; - + static Bool guessFormat( QString filename, UInt& rWidth, UInt& rHeight, Int& rInputFormat, UInt& rFrameRate ); /** * Private zoom function to handle diff --git a/lib/LibAvContextHandle.cpp b/lib/LibAvContextHandle.cpp index 4dcc0b9..eeccb71 100644 --- a/lib/LibAvContextHandle.cpp +++ b/lib/LibAvContextHandle.cpp @@ -96,7 +96,6 @@ Bool LibAvContextHandle::initAvFormat( const char* filename, UInt& width, UInt& frame = NULL; m_bHasStream = false; - char *src_filename = filename; AVDictionary *format_opts = NULL; /* register all formats and codecs */ @@ -117,7 +116,7 @@ Bool LibAvContextHandle::initAvFormat( const char* filename, UInt& width, UInt& } /* open input file, and allocate format context */ - if( avformat_open_input( &fmt_ctx, src_filename, NULL, &format_opts ) < 0 ) + if( avformat_open_input( &fmt_ctx, filename, NULL, &format_opts ) < 0 ) { //qDebug( ) << " Could not open source file %s !!!" << filename << endl; return false; @@ -198,7 +197,7 @@ Bool LibAvContextHandle::initAvFormat( const char* filename, UInt& width, UInt& } /* dump input information to stderr */ - av_dump_format( fmt_ctx, 0, src_filename, 0 ); + av_dump_format( fmt_ctx, 0, filename, 0 ); if( !video_stream ) { //qDebug( ) << " Could not find audio or video stream in the input, aborting !!!" << endl; diff --git a/lib/PlaYUVerStream.cpp b/lib/PlaYUVerStream.cpp index b488879..df794ff 100644 --- a/lib/PlaYUVerStream.cpp +++ b/lib/PlaYUVerStream.cpp @@ -28,6 +28,8 @@ #include "LibMemory.h" #include "PlaYUVerStream.h" #include +#include +#include #ifdef USE_FFMPEG #include "LibAvContextHandle.h" #endif @@ -181,7 +183,6 @@ PlaYUVerStream::PlaYUVerStream() m_iFileFormat = -1; m_pStreamBuffer = NULL; m_cFilename = ""; - m_cStreamInformationString = ""; m_pcCurrFrame = NULL; m_pcNextFrame = NULL; m_ppcFrameBuffer = NULL; @@ -204,6 +205,8 @@ Bool PlaYUVerStream::open( std::string filename, UInt width, UInt height, Int in close(); } + QString qtFilename = QString::fromStdString( filename ); + m_bInit = false; m_bIsInput = bInput; m_cFilename = filename; @@ -217,7 +220,7 @@ Bool PlaYUVerStream::open( std::string filename, UInt width, UInt height, Int in m_iFileFormat = INVALID_HANDLER; QStringList formatsExt = PlaYUVerStream::supportedReadFormatsExt(); - QString currExt = QFileInfo( QString::fromStdString( m_cFilename ) ).suffix(); + QString currExt = QFileInfo( qtFilename ).suffix(); if( formatsExt.contains( currExt ) ) { m_iFileFormat = formatsExt.indexOf( currExt ); @@ -339,8 +342,7 @@ Bool PlaYUVerStream::open( std::string filename, UInt width, UInt height, Int in } m_cPelFmtName = PlaYUVerFrame::supportedPixelFormatListNames()[m_iPixelFormat].data(); - m_cStreamInformationString = "[" + m_cFormatName + " / " + m_cCodedName + " / " + m_cPelFmtName + "] "; - m_cStreamInformationString += QFileInfo( QString::fromStdString( m_cFilename ) ).fileName().toStdString(); + m_iCurrFrameNum = -1; m_bInit = true; @@ -420,102 +422,6 @@ Void PlaYUVerStream::getFormat( UInt& rWidth, UInt& rHeight, Int& rInputFormat, } } -Bool PlaYUVerStream::guessFormat( QString filename, UInt& rWidth, UInt& rHeight, Int& rInputFormat, UInt& rFrameRate ) -{ - std::vector stdResList = stdResolutionSizes(); - Bool bGuessed = true; - Bool bGuessedByFilesize = false; - QString FilenameShort = QFileInfo( filename ).fileName(); - QString fileExtension = QFileInfo( filename ).suffix(); - if( !fileExtension.compare( "yuv" ) ) - { - bGuessed = false; - // Guess pixel format - QVector formats_list = QVector::fromStdVector( PlaYUVerFrame::supportedPixelFormatListNames() ); - for( Int i = 0; i < formats_list.size(); i++ ) - { - if( FilenameShort.contains( formats_list.at( i ).data(), Qt::CaseInsensitive ) ) - { - rInputFormat = i; - break; - } - } - - if( rWidth == 0 || rHeight == 0 ) - { - // Guess resolution - match resolution name - Int iMatch = -1; - for( UInt i = 0; i < stdResList.size(); i++ ) - { - if( FilenameShort.contains( QString::fromStdString( stdResList[i].shortName ) ) ) - { - iMatch = i; - } - } - if( iMatch >= 0 ) - { - rWidth = stdResList[iMatch].uiWidth; - rHeight = stdResList[iMatch].uiHeight; - } - // Guess resolution - match %dx%d -#if( QT_VERSION_PLAYUVER == 5 ) - QRegularExpressionMatch resolutionMatch = QRegularExpression( "_\\d*x\\d*" ).match( FilenameShort ); - if( resolutionMatch.hasMatch() ) - { - QString resolutionString = resolutionMatch.captured( 0 ); - if( resolutionString.startsWith( "_" ) || resolutionString.endsWith( "_" ) ) - { - resolutionString.remove( "_" ); - QStringList resolutionArgs = resolutionString.split( "x" ); - if( resolutionArgs.size() == 2 ) - { - rWidth = resolutionArgs.at( 0 ).toUInt(); - rHeight = resolutionArgs.at( 1 ).toUInt(); - } - } - } -#endif - } - - // Guess resolution by file size - if( rWidth == 0 && rHeight == 0 ) - { - Char *filename_char = new char[filename.length() + 1]; - memcpy( filename_char, filename.toUtf8().constData(), filename.length() + 1 * sizeof(char) ); - FILE* pF = fopen( filename_char, "rb" ); - if( pF ) - { - fseek( pF, 0, SEEK_END ); - UInt64 uiFileSize = ftell( pF ); - fclose( pF ); - delete[] filename_char; - - Int count = 0, module, frame_bytes, match; - for( UInt i = 0; i < stdResList.size(); i++ ) - { - frame_bytes = PlaYUVerFrame::getBytesPerFrame( stdResList[i].uiWidth, stdResList[i].uiHeight, rInputFormat ); - module = uiFileSize % frame_bytes; - if( module == 0 ) - { - match = i; - count++; - } - } - if( count == 1 ) - { - rWidth = stdResList[match].uiWidth; - rHeight = stdResList[match].uiHeight; - bGuessedByFilesize = true; - } - } - } - - if( rWidth > 0 && rHeight > 0 && rInputFormat >= 0 ) - bGuessed = true && !bGuessedByFilesize; - } - return !bGuessed; -} - Void PlaYUVerStream::loadAll() { if( m_bLoadAll || !m_bIsInput ) @@ -652,17 +558,18 @@ Void PlaYUVerStream::writeFrame( PlaYUVerFrame *pcFrame ) return; } -Bool PlaYUVerStream::saveFrame( const QString& filename ) +Bool PlaYUVerStream::saveFrame( const std::string& filename ) { return saveFrame( filename, m_pcCurrFrame ); } -Bool PlaYUVerStream::saveFrame( const QString& filename, PlaYUVerFrame *saveFrame ) +Bool PlaYUVerStream::saveFrame( const std::string& filename, PlaYUVerFrame *saveFrame ) { + QString qtString = QString::fromStdString( filename ); Int iFileFormat = INVALID_OUTPUT; QStringList formatsExt = PlaYUVerStream::supportedSaveFormatsExt(); - QString currExt = QFileInfo( filename ).suffix(); + QString currExt = QFileInfo( qtString ).suffix(); if( formatsExt.contains( currExt ) ) { iFileFormat = formatsExt.indexOf( currExt ); @@ -683,7 +590,7 @@ Bool PlaYUVerStream::saveFrame( const QString& filename, PlaYUVerFrame *saveFram { saveFrame->fillRGBBuffer(); QImage qimg = QImage( saveFrame->getRGBBuffer(), saveFrame->getWidth(), saveFrame->getHeight(), QImage::Format_RGB32 ); - return qimg.save( filename ); + return qimg.save( qtString ); } return false; } diff --git a/lib/PlaYUVerStream.h b/lib/PlaYUVerStream.h index 2b5ed7d..5dfc5dc 100644 --- a/lib/PlaYUVerStream.h +++ b/lib/PlaYUVerStream.h @@ -28,7 +28,7 @@ #include "PlaYUVerDefs.h" #include #include -#include +#include #include "PlaYUVerFrame.h" namespace plaYUVer @@ -68,7 +68,7 @@ private: std::string m_cFormatName; std::string m_cCodedName; std::string m_cPelFmtName; - QString m_cStreamInformationString; + FILE* m_pFile; /**< The input file pointer >*/ Int m_iFileFormat; @@ -117,8 +117,6 @@ public: Bool openFile(); Void closeFile(); - static Bool guessFormat( std::string filename, UInt& rWidth, UInt& rHeight, Int& rInputFormat, UInt& rFrameRate ); - Void getFormat( UInt& rWidth, UInt& rHeight, Int& rInputFormat, UInt& rFrameRate ); Void loadAll(); @@ -143,10 +141,6 @@ public: return m_bInit; } - QString getStreamInformationString() - { - return m_cStreamInformationString; - } std::string getFileName() { return m_cFilename;