From ebecb1e3f578eb38871432159e7af5d30b8f0aea Mon Sep 17 00:00:00 2001 From: Joao Carreira Date: Tue, 4 Feb 2014 23:57:43 +0000 Subject: [PATCH] Add stream information into application title --- source/ConfigureFormatDialog.cpp | 3 +- source/InputStream.cpp | 62 ++++++++++++++++-------- source/InputStream.h | 13 ++++- source/PlaYUVerFrame.cpp | 7 +++ source/PlaYUVerFrame.h | 4 ++ source/SubWindowHandle.cpp | 15 +++--- source/SubWindowHandle.h | 3 +- source/lib/ffmpeg/LibAvContextHandle.cpp | 5 ++ source/lib/ffmpeg/LibAvContextHandle.h | 6 +++ 9 files changed, 86 insertions(+), 32 deletions(-) diff --git a/source/ConfigureFormatDialog.cpp b/source/ConfigureFormatDialog.cpp index 3ac31e7..ccf282e 100755 --- a/source/ConfigureFormatDialog.cpp +++ b/source/ConfigureFormatDialog.cpp @@ -22,6 +22,7 @@ */ #include "ConfigureFormatDialog.h" +#include "PlaYUVerFrame.h" #include "InputStream.h" namespace plaYUVer @@ -168,7 +169,7 @@ ConfigureFormatDialog::ConfigureFormatDialog( QWidget *parent ) : pixelFormatBox->setSizePolicy( sizePolicyPixelFormat ); pixelFormatBox->setAcceptDrops( true ); pixelFormatBox->clear(); - pixelFormatBox->insertItems( 0, InputStream::supportedPixelFormatList() ); + pixelFormatBox->insertItems( 0, PlaYUVerFrame::supportedPixelFormatList() ); pixelFormatBox->setCurrentIndex( 0 ); pixelFormatLayout->addWidget( pixelFormatLabel ); diff --git a/source/InputStream.cpp b/source/InputStream.cpp index 672a595..e67064c 100755 --- a/source/InputStream.cpp +++ b/source/InputStream.cpp @@ -46,27 +46,25 @@ InputStream::InputStream() m_uiFrameRate = 25; m_iFileFormat = INVALID; + + m_cFilename = QString( "" ); + m_cStreamInformationString = QString( "" ); } InputStream::~InputStream() { - if( m_pFile ) - fclose( m_pFile ); - -#ifdef USE_FFMPEG - m_cLibAvContext.closeAvFormat(); -#endif - - m_iStatus = 0; + close(); } QString InputStream::supportedReadFormats() { QString formats; formats = "*.yuv " // Raw video - "*.avi "// Audio video interleaved +#ifdef USE_FFMPEG + "*.avi " // Audio video interleaved "*.wmv "// Windows media video - ; +#endif + ; return formats; } @@ -86,8 +84,10 @@ QStringList InputStream::supportedReadFormatsList() { QStringList formats; formats << "Raw video (*.yuv)" // Raw video +#ifdef USE_FFMPEG << "Audio video interleaved (*.avi)" // Audio video interleaved << "Windows media video (*.wmv)" // Windows media video +#endif ; return formats; @@ -104,13 +104,6 @@ QStringList InputStream::supportedWriteFormatsList() return formats; } -QStringList InputStream::supportedPixelFormatList() -{ - QStringList formats; - formats << "YUV420" << "YUV400"; - return formats; -} - Bool InputStream::needFormatDialog( QString filename ) { QString fileExtension = QFileInfo( filename ).completeSuffix(); @@ -128,6 +121,12 @@ Void InputStream::init( QString filename, UInt width, UInt height, Int input_for { Bool avStatus = false; + if( m_iStatus == 1 ) + { + close(); + } + + m_cFilename = filename; m_uiWidth = width; m_uiHeight = height; m_uiFrameRate = frame_rate; @@ -135,8 +134,11 @@ Void InputStream::init( QString filename, UInt width, UInt height, Int input_for m_iFileFormat = YUVFormat; m_iPixelFormat = input_format; + m_cStreamInformationString = QString( "[" ); + #ifdef USE_FFMPEG - avStatus = m_cLibAvContext.initAvFormat( filename.toLocal8Bit().data(), m_uiWidth, m_uiHeight, m_iPixelFormat, m_uiFrameRate ); + avStatus = m_cLibAvContext.initAvFormat( m_cFilename.toLocal8Bit().data(), m_uiWidth, m_uiHeight, m_iPixelFormat, m_uiFrameRate ); + m_cStreamInformationString.append( QString::fromUtf8( m_cLibAvContext.getStreamInformation() ) ); m_uiTotalFrameNum = 100; #endif @@ -152,7 +154,6 @@ Void InputStream::init( QString filename, UInt width, UInt height, Int input_for if( !avStatus ) { - m_cFilename = filename; m_pFile = fopen( m_cFilename.toLocal8Bit().data(), "rb" ); if( m_pFile == NULL ) { @@ -162,6 +163,8 @@ Void InputStream::init( QString filename, UInt width, UInt height, Int input_for fseek( m_pFile, 0, SEEK_END ); m_uiTotalFrameNum = ftell( m_pFile ) / ( frame_bytes_input ); fseek( m_pFile, 0, SEEK_SET ); + + m_cStreamInformationString.append( QString::fromUtf8("rawvideo ") ); } if( !get_mem1Dpel( &m_pInputBuffer, m_cCurrFrame->getBytesPerFrame() ) ) @@ -170,13 +173,32 @@ Void InputStream::init( QString filename, UInt width, UInt height, Int input_for return; } - m_uiCurrFrameNum = 0; + m_cStreamInformationString.append( QString("/ ")); + m_cStreamInformationString.append( PlaYUVerFrame::supportedPixelFormatList().at( m_iPixelFormat ) ); + + m_cStreamInformationString.append( "] " ); + + m_cStreamInformationString.append( QFileInfo( m_cFilename ).fileName() ); + + m_uiCurrFrameNum = 0; m_iStatus = 1; return; } +Void InputStream::close() +{ + if( m_pFile ) + fclose( m_pFile ); + +#ifdef USE_FFMPEG + m_cLibAvContext.closeAvFormat(); +#endif + + m_iStatus = 0; +} + Void InputStream::readFrame() { UInt64 bytes_read = 0; diff --git a/source/InputStream.h b/source/InputStream.h index 228a4df..9560171 100755 --- a/source/InputStream.h +++ b/source/InputStream.h @@ -64,6 +64,8 @@ private: #endif QString m_cFilename; + QString m_cStreamInformationString; + FILE* m_pFile; /**< The input file pointer >*/ Int m_iFileFormat; Int m_iPixelFormat; @@ -87,8 +89,6 @@ public: static QStringList supportedReadFormatsList(); static QStringList supportedWriteFormatsList(); - static QStringList supportedPixelFormatList(); - enum InputStreamFormats { INVALID = -1, YUVFormat = 0, // Use color space. @@ -97,6 +97,7 @@ public: Bool needFormatDialog( QString filename ); Void init( QString filename, UInt width, UInt height, Int input_format, UInt frame_rate ); + Void close(); Void readFrame(); @@ -115,6 +116,14 @@ public: { return m_iStatus; } + QString getFileName() + { + return m_cFilename; + } + QString getStreamInformationString() + { + return m_cStreamInformationString; + } UInt getFrameNum() { return m_uiTotalFrameNum; diff --git a/source/PlaYUVerFrame.cpp b/source/PlaYUVerFrame.cpp index 0532eb2..e358111 100755 --- a/source/PlaYUVerFrame.cpp +++ b/source/PlaYUVerFrame.cpp @@ -28,6 +28,13 @@ namespace plaYUVer { +QStringList PlaYUVerFrame::supportedPixelFormatList() +{ + QStringList formats; + formats << "yuv420" << "yuv400"; + return formats; +} + PlaYUVerFrame::PlaYUVerFrame( UInt width, UInt height, Int pel_format ) { m_pppcInputPel[0] = NULL; diff --git a/source/PlaYUVerFrame.h b/source/PlaYUVerFrame.h index a5f44bd..5823561 100755 --- a/source/PlaYUVerFrame.h +++ b/source/PlaYUVerFrame.h @@ -29,6 +29,8 @@ #include #include +#include + #include "TypeDef.h" namespace plaYUVer @@ -40,6 +42,8 @@ public: PlaYUVerFrame( UInt width, UInt height, Int pel_format ); ~PlaYUVerFrame(); + static QStringList supportedPixelFormatList(); + Void FrameFromBuffer( Pel *input_buffer, Int pel_format ); UInt64 getBytesPerFrame(); diff --git a/source/SubWindowHandle.cpp b/source/SubWindowHandle.cpp index 29ef138..4d21efe 100644 --- a/source/SubWindowHandle.cpp +++ b/source/SubWindowHandle.cpp @@ -46,7 +46,7 @@ SubWindowHandle::SubWindowHandle( QWidget * parent ) : // Define the cViewArea as the widget inside the scroll area m_cScrollArea->setWidget( m_cViewArea ); - m_cCurrFileName = QString( "" ); + m_cWindowName = QString( " " ); m_dScaleFactor = 1; } @@ -93,8 +93,12 @@ bool SubWindowHandle::loadFile( const QString &fileName ) normalSize(); + m_cWindowName = QString("ola"); + m_cWindowName = m_currStream.getStreamInformationString(); + m_cCurrFileName = fileName; - setWindowTitle( userFriendlyCurrentFile() + "[*]" ); + + setWindowTitle( m_cWindowName ); return true; } @@ -240,12 +244,7 @@ Void SubWindowHandle::closeEvent( QCloseEvent *event ) QString SubWindowHandle::userFriendlyCurrentFile() { - return strippedName( m_cCurrFileName ); -} - -QString SubWindowHandle::strippedName( const QString &fullFileName ) -{ - return QFileInfo( fullFileName ).fileName(); + return m_cWindowName; } } // NAMESPACE diff --git a/source/SubWindowHandle.h b/source/SubWindowHandle.h index aa86c75..99d0de7 100644 --- a/source/SubWindowHandle.h +++ b/source/SubWindowHandle.h @@ -52,7 +52,9 @@ private: InputStream m_currStream; + QString m_cWindowName; QString m_cCurrFileName; + Double m_dScaleFactor; public: @@ -114,7 +116,6 @@ public: */ //static void cascader( QList &widgets, const QRect &domain ); QString userFriendlyCurrentFile(); - QString strippedName( const QString &fullFileName ); QString currentFile() { return m_cCurrFileName; diff --git a/source/lib/ffmpeg/LibAvContextHandle.cpp b/source/lib/ffmpeg/LibAvContextHandle.cpp index 31b6fb4..5118182 100755 --- a/source/lib/ffmpeg/LibAvContextHandle.cpp +++ b/source/lib/ffmpeg/LibAvContextHandle.cpp @@ -150,6 +150,11 @@ Bool LibAvContextHandle::initAvFormat( char* filename, UInt& width, UInt& height video_dst_bufsize = ret; } + + const char *codec_name = avcodec_get_name(video_dec_ctx->codec_id); + + sprintf(m_acStreamInformationString, "%s ", codec_name); + Double fr = 30; if( video_stream->avg_frame_rate.den && video_stream->avg_frame_rate.num ) fr = av_q2d( video_stream->avg_frame_rate ); diff --git a/source/lib/ffmpeg/LibAvContextHandle.h b/source/lib/ffmpeg/LibAvContextHandle.h index 4445816..96e7460 100755 --- a/source/lib/ffmpeg/LibAvContextHandle.h +++ b/source/lib/ffmpeg/LibAvContextHandle.h @@ -63,6 +63,10 @@ public: { return m_bHasStream; } + Char* getStreamInformation() + { + return m_acStreamInformationString; + } uint8_t *video_dst_data[4]; int video_dst_linesize[4]; @@ -77,6 +81,8 @@ private: AVPacket pkt; Bool m_bHasStream; + + Char m_acStreamInformationString[20]; }; } // NAMESPACE