-void MyThread::run() {
-
- if (!f.open(QIODevice::WriteOnly)) {
- kDebug() << "++++++++ ERROR WRITING TO FILE: " << f.fileName() << endl;
- kDebug() << "++++++++ DISABLING AUDIO THUMBS" << endl;
- KdenliveSettings::setAudiothumbnails(false);
- return;
- }
- m_isWorking = true;
- Mlt::Profile prof((char*) KdenliveSettings::current_profile().toUtf8().data());
- Mlt::Producer m_producer(prof, m_url.path().toUtf8().data());
-
-
- if (KdenliveSettings::normaliseaudiothumbs()) {
- Mlt::Filter m_convert(prof, "volume");
- m_convert.set("gain", "normalise");
- m_producer.attach(m_convert);
- }
-
- //QApplication::postEvent(m_parent, new ProgressEvent(-1, (QEvent::Type)10005));
-
- int last_val = 0;
- int val = 0;
- kDebug() << "for " << m_frame << " " << m_frameLength << " " << m_producer.is_valid();
- 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(m_parent, new ProgressEvent(val, (QEvent::Type)10005));
-
- last_val = val;
- }
- m_producer.seek(z);
- Mlt::Frame *mlt_frame = m_producer.get_frame();
- if (mlt_frame && 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_array.resize(m_arrayWidth);
- for (uint i = 0; i < m_array.size(); i++) {
- m_array[i] = ((*(m_pcm + c + i * m_samples / m_array.size())) >> 9) + 127 / 2 ;
- }
- f.write(m_array);
-
- }
- } else {
- f.write(QByteArray(m_arrayWidth, '\x00'));
- }
- if (mlt_frame)
- delete mlt_frame;
- }
- kDebug() << "done";
- f.close();
- m_isWorking = false;
- if (stop_me) {
- f.remove();
+void KThumb::setProducer(Mlt::Producer *producer)
+{
+ if (m_producer) m_clipManager->stopThumbs(m_id);
+ m_intraFramesQueue.clear();
+ m_intra.waitForFinished();
+ QMutexLocker lock(&m_mutex);
+ m_producer = producer;
+ // FIXME: the profile() call leaks an object, but trying to free
+ // it leads to a double-free in Profile::~Profile()
+ if (producer) {
+ Mlt::Profile *profile = producer->profile();
+ m_dar = profile->dar();
+ m_ratio = (double) profile->width() / profile->height();