- void MyThread::run()
- {
- if (!f.open( IO_WriteOnly )) {
- kdDebug()<<"++++++++ ERROR WRITING TO FILE: "<<f.name()<<endl;
- kdDebug()<<"++++++++ DISABLING AUDIO THUMBS"<<endl;
- KdenliveSettings::setAudiothumbnails(false);
- return;
- }
- m_isWorking = true;
- char *tmp = KRender::decodedString(m_url.path());
- Mlt::Producer m_producer(tmp);
- delete tmp;
-
- if (KdenliveSettings::normaliseaudiothumbs()) {
- Mlt::Filter m_convert("volume");
- m_convert.set("gain", "normalise");
- m_producer.attach(m_convert);
- }
-
- if (qApp->mainWidget())
- QApplication::postEvent(qApp->mainWidget(), new ProgressEvent(-1, 10005));
-
- int last_val = 0;
- int val = 0;
- for (int z=(int) m_frame;z<(int) (m_frame+m_frameLength) && m_producer.is_valid();z++){
- if (stop_me) break;
- val=(int)((z-m_frame)/(m_frame+m_frameLength)*100.0);
- if (last_val!=val & val > 1){
- QApplication::postEvent(qApp->mainWidget(), new ProgressEvent(val, 10005));
- last_val=val;
- }
- m_producer.seek( z );
- Mlt::Frame *mlt_frame = m_producer.get_frame();
- if ( mlt_frame->is_valid() )
- {
- double m_framesPerSecond = mlt_producer_get_fps( m_producer.get_producer() ); //mlt_frame->get_double( "fps" );
- int m_samples = mlt_sample_calculator( m_framesPerSecond, m_frequency, mlt_frame_get_position(mlt_frame->get_frame()) );
- mlt_audio_format m_audioFormat = mlt_audio_pcm;
-
- int16_t* m_pcm = mlt_frame->get_audio(m_audioFormat, m_frequency, m_channels, m_samples );
-
- for (int c=0;c< m_channels;c++){
- QByteArray m_array(m_arrayWidth);
- for (uint i = 0; i < m_array.size(); i++){
- m_array[i] = QABS((*( m_pcm + c + i * m_samples / m_array.size() ))>>8);
- }
- f.writeBlock(m_array);
- }
- } else{
- f.writeBlock(QByteArray(m_arrayWidth));
- }
- if (mlt_frame)
- delete mlt_frame;
- }
- f.close();
- m_isWorking = false;
- if (stop_me) {
- f.remove();
- QApplication::postEvent(qApp->mainWidget(), new ProgressEvent(-1, 10005));
- }
- else QApplication::postEvent(qApp->mainWidget(), new ProgressEvent(0, 10005));
+KThumb::KThumb(ClipManager *clipManager, KUrl url, const QString &id, const QString &hash, QObject * parent, const char */*name*/) :
+ QObject(parent),
+ m_audioThumbProducer(),
+ m_url(url),
+ m_thumbFile(),
+ m_dar(1),
+ m_producer(NULL),
+ m_clipManager(clipManager),
+ m_id(id)
+{
+ m_thumbFile = clipManager->projectFolder() + "/thumbs/" + hash + ".thumb";
+ connect(&m_audioThumbProducer, SIGNAL(audioThumbProgress(const int)), this, SLOT(slotAudioThumbProgress(const int)));
+ connect(&m_audioThumbProducer, SIGNAL(audioThumbOver()), this, SLOT(slotAudioThumbOver()));
+}
+
+KThumb::~KThumb()
+{
+ m_requestedThumbs.clear();
+ if (m_audioThumbProducer.isRunning()) {
+ m_audioThumbProducer.stop_me = true;
+ m_audioThumbProducer.wait();
+ slotAudioThumbOver();