commit before audio rewrite

This commit is contained in:
itsmattkc
2018-06-06 10:54:17 -07:00
parent 0ea7c43e53
commit b2b3f5a14e
9 changed files with 35 additions and 14 deletions
+2 -2
View File
@@ -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();
}
+1 -1
View File
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 4.6.1, 2018-06-05T16:19:18. -->
<!-- Written by QtCreator 4.6.1, 2018-06-06T05:46:13. -->
<qtcreator>
<data>
<variable>EnvironmentId</variable>
+3 -1
View File
@@ -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();
+1
View File
@@ -77,6 +77,7 @@ public:
void go_to_end();
bool playing;
long playhead_start;
qint64 start_msecs;
QTime playback_timer;
QTimer playback_updater;
+8
View File
@@ -10,6 +10,8 @@ extern "C" {
#include <libavcodec/avcodec.h>
}
#include <QAudioOutput>
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();
}
+2
View File
@@ -35,6 +35,8 @@ private slots:
void on_pushButton_3_clicked();
void receiver();
private:
Ui::Viewer *ui;
};
+5 -2
View File
@@ -1,11 +1,14 @@
#ifndef AUDIO_H
#define AUDIO_H
#include <QIODevice>
#include <QMutex>
#include <stdint.h>
class QAudioOutput;
class QIODevice;
struct Sequence;
extern QAudioOutput* audio_output;
extern QIODevice* audio_io_device;
extern uint8_t* audio_cache_A;
+3 -4
View File
@@ -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<AVSampleFormat>(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;j<c->effects.size();j++) {
for (int j=0;j<c->effects.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);
}
}
}
}
+10 -4
View File
@@ -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;i<current_clips.size();i++) {
@@ -102,7 +102,7 @@ void ViewerWidget::paintGL()
int anchor_y = 0;
// perform all transform effects
for (unsigned int j=0;j<c->effects.size();j++) {
for (int j=0;j<c->effects.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;
}
}
}