From b2b3f5a14e8446757e340407e371e735c0bb140e Mon Sep 17 00:00:00 2001 From: itsmattkc Date: Wed, 6 Jun 2018 10:54:17 -0700 Subject: [PATCH] commit before audio rewrite --- mainwindow.cpp | 4 ++-- olive.pro.user | 2 +- panels/timeline.cpp | 4 +++- panels/timeline.h | 1 + panels/viewer.cpp | 8 ++++++++ panels/viewer.h | 2 ++ playback/audio.h | 7 +++++-- playback/cacher.cpp | 7 +++---- ui/viewerwidget.cpp | 14 ++++++++++---- 9 files changed, 35 insertions(+), 14 deletions(-) diff --git a/mainwindow.cpp b/mainwindow.cpp index 4d6234e4b..1dcc99353 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -105,7 +105,7 @@ void MainWindow::on_actionSelect_All_triggered() void MainWindow::on_actionSequence_triggered() { - NewSequenceDialog nsd; + NewSequenceDialog nsd(this); nsd.set_sequence_name(panel_project->get_next_sequence_name()); nsd.exec(); } @@ -132,7 +132,7 @@ void MainWindow::on_actionTimeline_Track_Lines_toggled(bool e) void MainWindow::on_actionExport_triggered() { - ExportDialog e; + ExportDialog e(this); if (panel_timeline->sequence != NULL) e.set_defaults(panel_timeline->sequence); e.exec(); } diff --git a/olive.pro.user b/olive.pro.user index de193c163..e57423a29 100644 --- a/olive.pro.user +++ b/olive.pro.user @@ -1,6 +1,6 @@ - + EnvironmentId diff --git a/panels/timeline.cpp b/panels/timeline.cpp index bee7a2ab3..9c3056d6d 100644 --- a/panels/timeline.cpp +++ b/panels/timeline.cpp @@ -90,6 +90,7 @@ bool Timeline::toggle_play() { void Timeline::play() { playhead_start = playhead; playback_timer.start(); + start_msecs = QDateTime::currentMSecsSinceEpoch(); playback_updater.start(); playing = true; @@ -143,7 +144,8 @@ bool Timeline::focused() { void Timeline::repaint_timeline() { if (playing) { - playhead = playhead_start + (playback_timer.elapsed() * 0.001 * sequence->frame_rate); +// playhead = playhead_start + (playback_timer.elapsed() * 0.001 * sequence->frame_rate); + playhead = round(playhead_start + ((QDateTime::currentMSecsSinceEpoch()-start_msecs) * 0.001 * sequence->frame_rate)); } ui->video_area->update(); ui->audio_area->update(); diff --git a/panels/timeline.h b/panels/timeline.h index 76a7124c6..f7b6aa3b3 100644 --- a/panels/timeline.h +++ b/panels/timeline.h @@ -77,6 +77,7 @@ public: void go_to_end(); bool playing; long playhead_start; + qint64 start_msecs; QTime playback_timer; QTimer playback_updater; diff --git a/panels/viewer.cpp b/panels/viewer.cpp index 5afee6c74..d2a8698b3 100644 --- a/panels/viewer.cpp +++ b/panels/viewer.cpp @@ -10,6 +10,8 @@ extern "C" { #include } +#include + Viewer::Viewer(QWidget *parent) : QDockWidget(parent), ui(new Ui::Viewer) @@ -27,6 +29,10 @@ Viewer::~Viewer() delete ui; } +void Viewer::receiver() { + qDebug() << "callback?"; +} + void Viewer::set_sequence(Sequence* s) { bool null_sequence = (s == NULL); sequence = s; @@ -45,6 +51,8 @@ void Viewer::set_sequence(Sequence* s) { } init_audio(s); + connect(audio_output, SIGNAL(notify()), this, SLOT(receiver())); + update(); } diff --git a/panels/viewer.h b/panels/viewer.h index 8ef7a4f69..f1681d6ca 100644 --- a/panels/viewer.h +++ b/panels/viewer.h @@ -35,6 +35,8 @@ private slots: void on_pushButton_3_clicked(); + void receiver(); + private: Ui::Viewer *ui; }; diff --git a/playback/audio.h b/playback/audio.h index 7296872a9..093b4f0a1 100644 --- a/playback/audio.h +++ b/playback/audio.h @@ -1,11 +1,14 @@ #ifndef AUDIO_H #define AUDIO_H -#include -#include +#include + +class QAudioOutput; +class QIODevice; struct Sequence; +extern QAudioOutput* audio_output; extern QIODevice* audio_io_device; extern uint8_t* audio_cache_A; diff --git a/playback/cacher.cpp b/playback/cacher.cpp index 866fe1a87..8d68216ed 100644 --- a/playback/cacher.cpp +++ b/playback/cacher.cpp @@ -33,7 +33,7 @@ void cache_audio_worker(Clip* c, bool write_A) { int nb_bytes = av_samples_get_buffer_size(NULL, frame->channels, frame->nb_samples, static_cast(frame->format), 1); int limit = std::min(c->frame_sample_index + audio_cache_size - bytes_written, nb_bytes); // perform all audio effects - for (unsigned int j=0;jeffects.size();j++) { + for (int j=0;jeffects.size();j++) { c->effects.at(j)->process_audio(frame->data[0], limit); } // mix audio into cache @@ -84,8 +84,7 @@ void reset_cache(Clip* c, long target_frame) { do { retrieve_next_frame(c, temp); if (retrieved_frame == 0) { - if (target_frame != 0) { -// retrieved_frame = floor(av_frame_get_best_effort_timestamp(temp) * timebase * av_q2d(c->stream->avg_frame_rate)); + if (target_frame != 0) { retrieved_frame = floor(temp->pts * timebase * av_q2d(av_guess_frame_rate(c->formatCtx, c->stream, temp))); } } else { @@ -273,7 +272,7 @@ void cache_clip_worker(Clip* clip, long playhead, bool write_A, bool write_B, bo } if (write_B) { cache_audio_worker(clip, false); - } + } } } diff --git a/ui/viewerwidget.cpp b/ui/viewerwidget.cpp index f894a0847..270145d50 100644 --- a/ui/viewerwidget.cpp +++ b/ui/viewerwidget.cpp @@ -76,7 +76,7 @@ void ViewerWidget::paintGL() clear_cache(!reading_audio_cache_A, reading_audio_cache_A); } - qDebug() << audio_bytes_written << "/" << audio_cache_size; +// qDebug() << audio_bytes_written << "/" << audio_cache_size; cc_lock.lock(); for (int i=0;ieffects.size();j++) { + for (int j=0;jeffects.size();j++) { c->effects.at(j)->process_gl(&anchor_x, &anchor_y); } @@ -134,7 +134,8 @@ void ViewerWidget::paintGL() // cache audio if (c->lock.tryLock()) { // clip is not caching, start cache - c->lock.unlock(); + c->lock.unlock(); + cache_clip(c, playhead, !reading_audio_cache_A, reading_audio_cache_A, c->reset_audio); } } @@ -147,7 +148,12 @@ void ViewerWidget::paintGL() if (audio_cache_A != NULL && audio_bytes_written < audio_cache_size) { // send cached/buffered audio to QIODevice/QAudioOutput uint8_t* cache = reading_audio_cache_A ? audio_cache_A : audio_cache_B; - if (panel_timeline->playing) audio_bytes_written += audio_io_device->write((const char*) cache+audio_bytes_written, audio_cache_size-audio_bytes_written); + if (panel_timeline->playing) { + int max_w = audio_cache_size-audio_bytes_written; + int w = audio_io_device->write((const char*) cache+audio_bytes_written, max_w); + qDebug() << w << max_w; + audio_bytes_written += w; + } } }