Commit ca495147 authored by Hugo Beauzee-Luyssen's avatar Hugo Beauzee-Luyssen

Fix potential memleak (well il was most a mem torrent actually...)

parent d6c4d9a9
......@@ -178,6 +178,7 @@ void Media::setHeight( int height )
float Media::getFps() const
{
Q_ASSERT_X( m_fps > 1.0f, "Media::getFps()", "FPS can't be zero");
return m_fps;
}
......
......@@ -109,17 +109,17 @@ int WorkflowRenderer::lock( void *datas, int64_t *dts, int64_t *pts, unsigne
*flags = 0;
if ( handler->type == Video )
{
qDebug() << "entering lock video";
// qDebug() << "entering lock video";
ret = handler->self->lockVideo( pts, bufferSize, buffer );
handler->self->m_mainWorkflow->goToNextFrame( MainWorkflow::VideoTrack );
qDebug() << "leaved lock video";
// qDebug() << "leaved lock video";
}
else if ( handler->type == Audio )
{
qDebug() << "entering lock audio";
// qDebug() << "entering lock audio";
ret = handler->self->lockAudio( pts, bufferSize, buffer );
handler->self->m_mainWorkflow->goToNextFrame( MainWorkflow::AudioTrack );
qDebug() << "leaved lock audio";
// qDebug() << "leaved lock audio";
}
else
qCritical() << "Invalid ES type";
......@@ -160,9 +160,9 @@ int WorkflowRenderer::lockAudio( int64_t *pts, size_t *bufferSize, void **b
if ( m_stopping == false )
{
qDebug() << "getting MainWorkflow audio output";
// qDebug() << "getting MainWorkflow audio output";
MainWorkflow::OutputBuffers* ret = m_mainWorkflow->getOutput( MainWorkflow::AudioTrack );
qDebug() << "got mainworkflow audio output";
// qDebug() << "got mainworkflow audio output";
m_renderAudioSample = ret->audio;
}
uint32_t nbSample;
......
......@@ -57,31 +57,31 @@ void* AudioClipWorkflow::getUnlockCallback()
void* AudioClipWorkflow::getOutput( ClipWorkflow::GetMode mode )
{
qDebug() << "entering audio get output";
// qDebug() << "entering audio get output";
QMutexLocker lock( m_renderLock );
qDebug() << "got audio render lock";
// qDebug() << "got audio render lock";
QMutexLocker lock2( m_computedBuffersMutex );
qDebug() << "got computed buffers mutex";
// qDebug() << "got computed buffers mutex";
if ( preGetOutput() == false )
{
qDebug() << "audio preGetOutput() returned false";
// qDebug() << "audio preGetOutput() returned false";
return NULL;
}
qWarning() << "Audio. Available:" << m_availableBuffers.count() << "Computed:" << m_computedBuffers.count();
// qWarning() << "Audio. Available:" << m_availableBuffers.count() << "Computed:" << m_computedBuffers.count();
if ( isEndReached() == true )
{
qDebug() << "audio end is reached";
// qDebug() << "audio end is reached";
return NULL;
}
if ( mode == ClipWorkflow::Get )
qCritical() << "A sound buffer should never be asked with 'Get' mode";
::StackedBuffer<AudioSample*>* buff = new StackedBuffer(
m_computedBuffers.dequeue(), this, true );
qDebug() << "calling audio postGetOutput();";
// qDebug() << "calling audio postGetOutput();";
postGetOutput();
qDebug() << "returning audio buffer";
// qDebug() << "returning audio buffer";
return buff;
}
......@@ -103,6 +103,7 @@ void AudioClipWorkflow::initVlcOutput()
AudioClipWorkflow::AudioSample* AudioClipWorkflow::createBuffer( size_t size )
{
qDebug() << "Creating new buffer of size:" << size;
AudioSample* as = new AudioSample;
as->buff = new uchar[size];
as->size = size;
......@@ -116,7 +117,7 @@ void AudioClipWorkflow::lock( AudioClipWorkflow* cw, uint8_t** pcm_buffer
cw->m_renderLock->lock();
cw->m_computedBuffersMutex->lock();
// qWarning() << ">>>AudioGeneration. Available:" << cw->m_availableBuffers.count() << "Computed:" << cw->m_computedBuffers.count();
qWarning() << ">>>AudioGeneration. Available:" << cw->m_availableBuffers.count() << "Computed:" << cw->m_computedBuffers.count() << "position" << cw->m_mediaPlayer->getPosition();
AudioSample* as = NULL;
if ( cw->m_availableBuffers.isEmpty() == true )
{
......@@ -156,6 +157,10 @@ void AudioClipWorkflow::unlock( AudioClipWorkflow* cw, uint8_t* pcm_buffe
as->nbChannels = channels;
as->ptsDiff = cw->m_currentPts - cw->m_previousPts;
}
// if ( as->ptsDiff == 0 )
// {
// qCritical() << "PTS DIFF IS 0 !!!! ";
// }
// qWarning() << "::::Computing audio PTS: debugId:" << as->debugId << "ptsdiff:" << as->ptsDiff;
cw->commonUnlock();
cw->m_renderLock->unlock();
......@@ -180,8 +185,9 @@ void AudioClipWorkflow::releaseBuffer( AudioSample *sample )
void AudioClipWorkflow::flushComputedBuffers()
{
QMutexLocker lock( m_computedBuffersMutex );
QMutexLocker lock2( m_availableBuffersMutex );
qDebug() << "Flushing computed buffers in audio";
QMutexLocker lock( m_availableBuffersMutex );
QMutexLocker lock2( m_computedBuffersMutex );
while ( m_computedBuffers.isEmpty() == false )
{
......
......@@ -135,15 +135,15 @@ void ClipWorkflow::stop()
void
ClipWorkflow::setTime( qint64 time )
{
// qDebug() << "setting clipworkflow time:" << time;
m_mediaPlayer->setTime( time );
qDebug() << "setting clipworkflow time:" << time << "debugType:" << debugType;
flushComputedBuffers();
m_mediaPlayer->setTime( time );
QWriteLocker lock( m_stateLock );
if ( m_state == ClipWorkflow::Paused )
{
// qDebug() << "Unpausing media player after set time";
m_mediaPlayer->pause();
m_state = ClipWorkflow::PauseRequired;
m_state = ClipWorkflow::UnpauseRequired;
}
}
......@@ -209,7 +209,7 @@ void ClipWorkflow::commonUnlock()
{
//Don't test using availableBuffer, as it may evolve if a buffer is required while
//no one is available : we would spawn a new buffer, thus modifying the number of available buffers
if ( getNbComputedBuffers() == getMaxComputedBuffers() )
if ( getNbComputedBuffers() >= getMaxComputedBuffers() )
{
// qWarning() << "Pausing clip workflow. Type:" << debugType;
setState( ClipWorkflow::PauseRequired );
......
......@@ -178,15 +178,12 @@ class ClipWorkflow : public QObject
* This has to be implemented in the underlying
* clipworkflow implementation.
*/
virtual void flushComputedBuffers() = 0;
private:
LibVLCpp::MediaPlayer* m_mediaPlayer;
WaitCondition* m_initWaitCond;
WaitCondition* m_pausingStateWaitCond;
protected:
LibVLCpp::MediaPlayer* m_mediaPlayer;
Clip* m_clip;
QMutex* m_renderLock;
QReadWriteLock* m_stateLock;
......@@ -213,6 +210,7 @@ class ClipWorkflow : public QObject
void clipEndReached();
void mediaPlayerPaused();
void mediaPlayerUnpaused();
virtual void flushComputedBuffers() = 0;
};
#endif // CLIPWORKFLOW_H
......@@ -139,8 +139,8 @@ VideoClipWorkflow::lock( VideoClipWorkflow *cw, void **pp_ret, int size )
else
lvf = cw->m_availableBuffers.dequeue();
cw->m_computedBuffers.enqueue( lvf );
// qWarning() << ">>>VideoGeneration. Available:" <<
// cw->m_availableBuffers.count() << "Computed:" << cw->m_computedBuffers.count();
qWarning() << ">>>VideoGeneration. Available:" <<
cw->m_availableBuffers.count() << "Computed:" << cw->m_computedBuffers.count() << "position" << cw->m_mediaPlayer->getPosition();
// qWarning() << "feeding video buffer";
*pp_ret = (*(lvf))->frame.octets;
}
......@@ -194,6 +194,7 @@ VideoClipWorkflow::releaseBuffer( LightVideoFrame *lvf )
void
VideoClipWorkflow::flushComputedBuffers()
{
qDebug() << "Flushing computed buffers in video";
QMutexLocker lock( m_computedBuffersMutex );
QMutexLocker lock2( m_availableBuffersMutex );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment