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

MetadataWorker: Don't compute snapshot when gui is off.

Commented out audio spectrum code.
parent f9cf2653
......@@ -21,9 +21,7 @@
*****************************************************************************/
#include <QtDebug>
#include <QPainter>
#include <QLabel>
#include <QImage>
#include "vlmc.h"
#include "MetaDataWorker.h"
#include "Library.h"
......@@ -32,8 +30,11 @@
#include "VLCMedia.h"
#include "Clip.h"
#include <QThreadPool>
#include <QRunnable>
#ifdef WITH_GUI
# include <QPainter>
# include <QLabel>
# include <QImage>
#endif
MetaDataWorker::MetaDataWorker( LibVLCpp::MediaPlayer* mediaPlayer, Media* media ) :
m_mediaPlayer( mediaPlayer ),
......@@ -89,20 +90,6 @@ MetaDataWorker::computeImageMetaData()
m_lengthHasChanged = true;
}
void
MetaDataWorker::prepareAudioSpectrumComputing()
{
m_media->vlcMedia()->addOption( ":no-sout-video" );
m_media->vlcMedia()->addOption( ":sout=#transcode{}:smem" );
m_media->vlcMedia()->setAudioDataCtx( this );
m_media->vlcMedia()->setAudioLockCallback( reinterpret_cast<void*>( lock ) );
m_media->vlcMedia()->setAudioUnlockCallback( reinterpret_cast<void*>( unlock ) );
m_media->vlcMedia()->addOption( ":sout-transcode-acodec=fl32" );
m_media->vlcMedia()->addOption( ":no-sout-smem-time-sync" );
m_media->vlcMedia()->addOption( ":no-sout-keep" );
connect( m_mediaPlayer, SIGNAL( endReached() ), this, SLOT( generateAudioSpectrum() ), Qt::QueuedConnection );
}
void
MetaDataWorker::metaDataAvailable()
{
......@@ -149,6 +136,7 @@ MetaDataWorker::metaDataAvailable()
m_media->setNbFrames( (m_media->lengthMS() / 1000) * m_media->fps() );
m_media->emitMetaDataComputed();
#ifdef WITH_GUI
//Setting time for snapshot :
if ( m_media->fileType() == Media::Video ||
m_media->fileType() == Media::Image )
......@@ -157,9 +145,11 @@ MetaDataWorker::metaDataAvailable()
m_mediaPlayer->setTime( m_mediaPlayer->getLength() / 3 );
}
else
#endif
finalize();
}
#ifdef WITH_GUI
void
MetaDataWorker::renderSnapshot()
{
......@@ -200,6 +190,7 @@ MetaDataWorker::setSnapshot( const char* filename )
m_media->emitSnapshotComputed();
finalize();
}
#endif
void
MetaDataWorker::finalize()
......@@ -230,72 +221,87 @@ MetaDataWorker::entrypointPlaying()
metaDataAvailable();
}
void
MetaDataWorker::lock( MetaDataWorker* metaDataWorker, uint8_t** pcm_buffer , unsigned int size )
{
if ( metaDataWorker->m_audioBuffer == NULL )
metaDataWorker->m_audioBuffer = new unsigned char[size];
*pcm_buffer = metaDataWorker->m_audioBuffer;
}
void
MetaDataWorker::unlock( MetaDataWorker* metaDataWorker, uint8_t* pcm_buffer,
unsigned int channels, unsigned int rate,
unsigned int nb_samples, unsigned int bits_per_sample,
unsigned int size, int pts )
{
Q_UNUSED( rate );
Q_UNUSED( size );
Q_UNUSED( pts );
int bytePerChannelPerSample = bits_per_sample / 8;
int leftAverage = 0;
int rightAverage = 0;
int it = 0;
for ( unsigned int i = 0; i < nb_samples; i++)
{
int left = 0;
int right = 0;
for ( int u = 0 ; u < bytePerChannelPerSample; u++, it++ )
{
int increment = 0;
if ( channels == 2 )
increment = bytePerChannelPerSample;
left <<= 8;
left += pcm_buffer[ it ];
right <<= 8;
right += pcm_buffer[ it + increment ];
}
leftAverage += left;
rightAverage += right;
}
leftAverage /= nb_samples;
metaDataWorker->addAudioValue( leftAverage );
}
void
MetaDataWorker::generateAudioSpectrum()
{
disconnect( m_mediaPlayer, SIGNAL( endReached() ), this, SLOT( generateAudioSpectrum() ) );
m_mediaPlayer->stop();
// AudioSpectrumHelper* audioSpectrum = new AudioSpectrumHelper( m_media->getAudioValues() );
// audioSpectrum->setAutoDelete( true );
// QThreadPool::globalInstance()->start( audioSpectrum );
m_media->emitAudioSpectrumComuted();
delete this;
}
void
MetaDataWorker::addAudioValue( int value )
{
m_media->audioValues()->append( value );
}
void
MetaDataWorker::failure()
{
emit failed( m_media );
deleteLater();
}
//void
//MetaDataWorker::prepareAudioSpectrumComputing()
//{
// m_media->vlcMedia()->addOption( ":no-sout-video" );
// m_media->vlcMedia()->addOption( ":sout=#transcode{}:smem" );
// m_media->vlcMedia()->setAudioDataCtx( this );
// m_media->vlcMedia()->setAudioLockCallback( reinterpret_cast<void*>( lock ) );
// m_media->vlcMedia()->setAudioUnlockCallback( reinterpret_cast<void*>( unlock ) );
// m_media->vlcMedia()->addOption( ":sout-transcode-acodec=fl32" );
// m_media->vlcMedia()->addOption( ":no-sout-smem-time-sync" );
// m_media->vlcMedia()->addOption( ":no-sout-keep" );
// connect( m_mediaPlayer, SIGNAL( endReached() ), this, SLOT( generateAudioSpectrum() ), Qt::QueuedConnection );
//}
//
//void
//MetaDataWorker::lock( MetaDataWorker* metaDataWorker, uint8_t** pcm_buffer , unsigned int size )
//{
// if ( metaDataWorker->m_audioBuffer == NULL )
// metaDataWorker->m_audioBuffer = new unsigned char[size];
// *pcm_buffer = metaDataWorker->m_audioBuffer;
//}
//
//void
//MetaDataWorker::unlock( MetaDataWorker* metaDataWorker, uint8_t* pcm_buffer,
// unsigned int channels, unsigned int rate,
// unsigned int nb_samples, unsigned int bits_per_sample,
// unsigned int size, int pts )
//{
// Q_UNUSED( rate );
// Q_UNUSED( size );
// Q_UNUSED( pts );
//
// int bytePerChannelPerSample = bits_per_sample / 8;
//
// int leftAverage = 0;
// int rightAverage = 0;
//
// int it = 0;
// for ( unsigned int i = 0; i < nb_samples; i++)
// {
// int left = 0;
// int right = 0;
// for ( int u = 0 ; u < bytePerChannelPerSample; u++, it++ )
// {
// int increment = 0;
// if ( channels == 2 )
// increment = bytePerChannelPerSample;
// left <<= 8;
// left += pcm_buffer[ it ];
// right <<= 8;
// right += pcm_buffer[ it + increment ];
// }
// leftAverage += left;
// rightAverage += right;
// }
// leftAverage /= nb_samples;
// metaDataWorker->addAudioValue( leftAverage );
//}
//
//void
//MetaDataWorker::generateAudioSpectrum()
//{
// disconnect( m_mediaPlayer, SIGNAL( endReached() ), this, SLOT( generateAudioSpectrum() ) );
// m_mediaPlayer->stop();
//// AudioSpectrumHelper* audioSpectrum = new AudioSpectrumHelper( m_media->getAudioValues() );
//// audioSpectrum->setAutoDelete( true );
//// QThreadPool::globalInstance()->start( audioSpectrum );
// m_media->emitAudioSpectrumComuted();
// delete this;
//}
//
//void
//MetaDataWorker::addAudioValue( int value )
//{
// m_media->audioValues()->append( value );
//}
//
//void
//MetaDataWorker::failure()
//{
// emit failed( m_media );
// deleteLater();
//}
......@@ -24,6 +24,7 @@
#ifndef METADATAWORKER_H
#define METADATAWORKER_H
#include "config.h"
#include "Media.h"
#include <QList>
......@@ -48,17 +49,17 @@ class MetaDataWorker : public QObject
private:
void computeDynamicFileMetaData();
void computeImageMetaData();
void prepareAudioSpectrumComputing();
void addAudioValue( int value );
// void prepareAudioSpectrumComputing();
// void addAudioValue( int value );
void finalize();
private:
void metaDataAvailable();
static void lock( MetaDataWorker* metaDataWorker, quint8** pcm_buffer , unsigned int size );
static void unlock( MetaDataWorker* metaDataWorker, quint8* pcm_buffer,
unsigned int channels, unsigned int rate,
unsigned int nb_samples, unsigned int bits_per_sample,
unsigned int size, int pts );
// static void lock( MetaDataWorker* metaDataWorker, quint8** pcm_buffer , unsigned int size );
// static void unlock( MetaDataWorker* metaDataWorker, quint8* pcm_buffer,
// unsigned int channels, unsigned int rate,
// unsigned int nb_samples, unsigned int bits_per_sample,
// unsigned int size, int pts );
private:
LibVLCpp::MediaPlayer* m_mediaPlayer;
......@@ -71,16 +72,21 @@ class MetaDataWorker : public QObject
QTime m_timer;
private slots:
void renderSnapshot();
void setSnapshot( const char* );
void entrypointPlaying();
void entrypointLengthChanged( qint64 );
void generateAudioSpectrum();
// void generateAudioSpectrum();
void failure();
signals:
void computed();
void failed( Media* media );
//GUI Stuff:
#ifdef WITH_GUI
private slots:
void renderSnapshot();
void setSnapshot( const char* );
#endif
};
#endif // METADATAWORKER_H
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