From 206613d08a891fc4b89feb1ba8418160881e25fe Mon Sep 17 00:00:00 2001 From: Joao Carreira Date: Sun, 30 May 2021 17:08:31 +0100 Subject: [PATCH] Cleanups in CalypStream --- lib/CalypStream.cpp | 48 +++++++++++++-------------------------------- lib/CalypStream.h | 2 -- 2 files changed, 14 insertions(+), 36 deletions(-) diff --git a/lib/CalypStream.cpp b/lib/CalypStream.cpp index 15dc501..467d65e 100644 --- a/lib/CalypStream.cpp +++ b/lib/CalypStream.cpp @@ -107,15 +107,14 @@ public: { for( unsigned int i = 0; i < size; i++ ) { - CalypFrame* pFrame = new CalypFrame( width, height, pelFormat, bitsPixel, hasNegative ); - m_apcFrameBuffer.push_back( pFrame ); + m_apcFrameBuffer.push_back( new CalypFrame( width, height, pelFormat, bitsPixel, hasNegative ) ); } m_uiIndex = 0; } ~CalypStreamBufferPrivate() { - while( m_apcFrameBuffer.size() > 0 ) + while( !m_apcFrameBuffer.empty() ) { delete m_apcFrameBuffer.back(); m_apcFrameBuffer.pop_back(); @@ -125,8 +124,7 @@ public: { for( unsigned int i = m_apcFrameBuffer.size(); i < newSize; i++ ) { - CalypFrame* pFrame = new CalypFrame( m_apcFrameBuffer.at( 0 ) ); - m_apcFrameBuffer.push_back( pFrame ); + m_apcFrameBuffer.push_back( new CalypFrame( m_apcFrameBuffer.at( 0 ) ) ); } } unsigned int size() { return m_apcFrameBuffer.size(); } @@ -158,8 +156,9 @@ struct CalypStreamPrivate CalypStreamPrivate() { - handler = NULL; - pfctCreateHandler = NULL; + handler = nullptr; + pfctCreateHandler = nullptr; + frameBuffer = nullptr; isInput = true; isInit = false; bLoadAll = false; @@ -227,6 +226,7 @@ CalypStream::CalypStream() CalypStream::~CalypStream() { close(); + delete d; } ClpString CalypStream::getFormatName() const @@ -389,10 +389,13 @@ void CalypStream::close() if( !d->isInit ) return; - d->handler->closeHandler(); - d->handler->Delete(); - - delete d->frameBuffer; + if( d->handler ) + { + d->handler->closeHandler(); + d->handler->Delete(); + } + if( d->frameBuffer ) + delete d->frameBuffer; d->bLoadAll = false; d->isInit = false; @@ -485,29 +488,6 @@ void CalypStream::loadAll() d->iCurrFrameNum = 0; } -void CalypStream::getDuration( int* duration_array ) const -{ - // int hours, mins, secs = 0; - // #ifdef USE_FFMPEG - // if( m_iStreamHandler == FFMPEG ) - // { - // secs = m_cLibAvContext->getStreamDuration(); - // } - // else - // #endif - // if( m_iStreamHandler == YUV_IO ) - // { - // secs = m_uiTotalFrameNum / m_dFrameRate; - // } - // mins = secs / 60; - // secs %= 60; - // hours = mins / 60; - // mins %= 60; - // *duration_array++ = hours; - // *duration_array++ = mins; - // *duration_array++ = secs; -} - bool CalypStream::readFrame( CalypFrame* frame ) { if( !d->isInit || !d->isInput || d->handler->m_uiCurrFrameFileIdx >= d->handler->m_uiTotalNumberFrames ) diff --git a/lib/CalypStream.h b/lib/CalypStream.h index e892b97..76a2046 100644 --- a/lib/CalypStream.h +++ b/lib/CalypStream.h @@ -113,8 +113,6 @@ public: bool seekInputRelative( bool bIsFoward ); bool seekInput( unsigned long new_frame_num ); - void getDuration( int* duration_array ) const; - private: bool readFrame( CalypFrame* frame );