diff --git a/debug.cpp b/debug.cpp new file mode 100644 index 000000000..6645250d7 --- /dev/null +++ b/debug.cpp @@ -0,0 +1,32 @@ +#include "debug.h" + +#include +#include +#include + +#ifndef QT_DEBUG +QFile debug_file; +QDebug debug_out(&debug_file); +#endif + +void setup_debug() { +#ifndef QT_DEBUG + debug_file.setFileName(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + "/debug_log"); + if (debug_file.open(QFile::WriteOnly)) { + QString debug_intro = "Olive Session " + QString::number(QDateTime::currentMSecsSinceEpoch()); + debug_file.write(debug_intro.toLatin1()); + } else { + debug_out = QMessageLogger(QT_MESSAGELOG_FILE, QT_MESSAGELOG_LINE, QT_MESSAGELOG_FUNC).debug(); + } +#endif +} + +void close_debug() { +#ifndef QT_DEBUG + if (debug_file.isOpen()) { + debug_file.putChar(10); + debug_file.putChar(10); + debug_file.close(); + } +#endif +} diff --git a/debug.h b/debug.h new file mode 100644 index 000000000..d7161d57a --- /dev/null +++ b/debug.h @@ -0,0 +1,16 @@ +#ifndef DEBUG_H +#define DEBUG_H + +#include + +#ifndef QT_DEBUG +#define dout debug_out << "\n" +extern QDebug debug_out; +#else +#define dout qDebug() +#endif + +void setup_debug(); +void close_debug(); + +#endif // DEBUG_H diff --git a/dialogs/exportdialog.cpp b/dialogs/exportdialog.cpp index 0f7083b4d..5c0fbfa82 100644 --- a/dialogs/exportdialog.cpp +++ b/dialogs/exportdialog.cpp @@ -4,10 +4,10 @@ #include #include #include -#include #include #include +#include "debug.h" #include "panels/panels.h" #include "panels/viewer.h" #include "panels/timeline.h" @@ -279,7 +279,7 @@ void ExportDialog::on_formatCombobox_currentIndexChanged(int index) default_acodec = 1; break; default: - qDebug() << "[ERROR] Invalid format selection - this is a bug, please inform the developers"; + dout << "[ERROR] Invalid format selection - this is a bug, please inform the developers"; } AVCodec* codec_info; @@ -384,7 +384,7 @@ void ExportDialog::on_pushButton_clicked() { ext = "tif"; break; default: - qDebug() << "[ERROR] Invalid codec selection for an image sequence"; + dout << "[ERROR] Invalid codec selection for an image sequence"; QMessageBox::critical(this, "Invalid codec", "Couldn't determine output parameters for the selected codec. This is a bug, please contact the developers.", QMessageBox::Ok); return; } @@ -446,7 +446,7 @@ void ExportDialog::on_pushButton_clicked() { } break; default: - qDebug() << "[ERROR] Invalid format - this is a bug, please inform the developers"; + dout << "[ERROR] Invalid format - this is a bug, please inform the developers"; QMessageBox::critical(this, "Invalid format", "Couldn't determine output format. This is a bug, please contact the developers.", QMessageBox::Ok); return; } diff --git a/dialogs/newsequencedialog.cpp b/dialogs/newsequencedialog.cpp index 1d36e1101..1a52f3879 100644 --- a/dialogs/newsequencedialog.cpp +++ b/dialogs/newsequencedialog.cpp @@ -9,7 +9,6 @@ #include "playback/playback.h" #include -#include extern "C" { #include diff --git a/dialogs/preferencesdialog.cpp b/dialogs/preferencesdialog.cpp index 91e34731d..ce869cb12 100644 --- a/dialogs/preferencesdialog.cpp +++ b/dialogs/preferencesdialog.cpp @@ -5,7 +5,6 @@ #include #include -#include KeySequenceEditor::KeySequenceEditor(QAction* a) : QKeySequenceEdit(0), action(a) { diff --git a/dialogs/replaceclipmediadialog.cpp b/dialogs/replaceclipmediadialog.cpp index 1b95c7593..da378541c 100644 --- a/dialogs/replaceclipmediadialog.cpp +++ b/dialogs/replaceclipmediadialog.cpp @@ -16,7 +16,6 @@ #include #include #include -#include ReplaceClipMediaDialog::ReplaceClipMediaDialog(QWidget *parent, SourceTable *table, QTreeWidgetItem *old_media) : QDialog(parent), diff --git a/dialogs/speeddialog.cpp b/dialogs/speeddialog.cpp index fd235fde8..c1f8b431e 100644 --- a/dialogs/speeddialog.cpp +++ b/dialogs/speeddialog.cpp @@ -6,7 +6,6 @@ #include #include #include -#include #include "ui/labelslider.h" #include "project/clip.h" diff --git a/effects/audio/toneeffect.cpp b/effects/audio/toneeffect.cpp index ad3d03ac6..69bc0b8ec 100644 --- a/effects/audio/toneeffect.cpp +++ b/effects/audio/toneeffect.cpp @@ -6,6 +6,7 @@ #include "project/clip.h" #include "project/sequence.h" +#include "debug.h" ToneEffect::ToneEffect(Clip* c) : Effect(c, EFFECT_TYPE_AUDIO, AUDIO_TONE_EFFECT), sinX(INT_MIN) { type_val = add_row("Type:")->add_field(EFFECT_FIELD_COMBO); @@ -54,7 +55,7 @@ void ToneEffect::process_audio(double timecode_start, double timecode_end, quint int presin = sinX; sinX++; if (sinX < presin) { - qDebug() << "[WARNING] Tone effect overflowed"; + dout << "[WARNING] Tone effect overflowed"; } } } diff --git a/effects/audio/volumeeffect.cpp b/effects/audio/volumeeffect.cpp index d4fba8ac0..ab74cb942 100644 --- a/effects/audio/volumeeffect.cpp +++ b/effects/audio/volumeeffect.cpp @@ -3,7 +3,6 @@ #include #include #include -#include #include #include "ui/labelslider.h" @@ -22,7 +21,6 @@ VolumeEffect::VolumeEffect(Clip* c) : Effect(c, EFFECT_TYPE_AUDIO, AUDIO_VOLUME_ } void VolumeEffect::process_audio(double timecode_start, double timecode_end, quint8* samples, int nb_bytes, int) { -// qDebug() << timecode_start << timecode_end; double interval = (timecode_end-timecode_start)/nb_bytes; for (int i=0;iget_double_value(timecode_start+(interval*i), true)*0.01); diff --git a/effects/effect.cpp b/effects/effect.cpp index a508c509f..a168fbb32 100644 --- a/effects/effect.cpp +++ b/effects/effect.cpp @@ -16,6 +16,7 @@ #include "project/clip.h" #include "panels/timeline.h" #include "panels/effectcontrols.h" +#include "debug.h" #include "effects/video/transformeffect.h" #include "effects/video/inverteffect.h" @@ -92,7 +93,7 @@ Effect* create_effect(int effect_id, Clip* c) { case AUDIO_TONE_EFFECT: return new ToneEffect(c); break; } } - qDebug() << "[ERROR] Invalid effect ID"; + dout << "[ERROR] Invalid effect ID"; return NULL; } @@ -271,14 +272,14 @@ void Effect::load(QXmlStreamReader& stream) { } } } else { - qDebug() << "[ERROR] Too many fields for effect" << id << "row" << row_count << ". Project might be corrupt. (Got" << field_count << ", expected <" << row->fieldCount()-1 << ")"; + dout << "[ERROR] Too many fields for effect" << id << "row" << row_count << ". Project might be corrupt. (Got" << field_count << ", expected <" << row->fieldCount()-1 << ")"; } field_count++; } } } else { - qDebug() << "[ERROR] Too many rows for effect" << id << ". Project might be corrupt. (Got" << row_count << ", expected <" << rows.size()-1 << ")"; + dout << "[ERROR] Too many rows for effect" << id << ". Project might be corrupt. (Got" << row_count << ", expected <" << rows.size()-1 << ")"; } row_count++; } @@ -313,11 +314,11 @@ void Effect::save(QXmlStreamWriter& stream) { void Effect::open() { if (isOpen) { - qDebug() << "[WARNING] Tried to open an effect that was already open"; + dout << "[WARNING] Tried to open an effect that was already open"; close(); } if (QOpenGLContext::currentContext() == NULL) { - qDebug() << "[WARNING] No current context to create a shader program for - will retry next repaint"; + dout << "[WARNING] No current context to create a shader program for - will retry next repaint"; } else { glslProgram = new QOpenGLShaderProgram(); if (!vertPath.isEmpty()) glslProgram->addShaderFromSourceFile(QOpenGLShader::Vertex, vertPath); @@ -329,7 +330,7 @@ void Effect::open() { void Effect::close() { if (!isOpen) { - qDebug() << "[WARNING] Tried to close an effect that was already closed"; + dout << "[WARNING] Tried to close an effect that was already closed"; } else { delete glslProgram; } @@ -340,7 +341,7 @@ void Effect::close() { void Effect::startEffect() { if (!isOpen) { open(); - qDebug() << "[WARNING] Tried to start a closed effect - opening"; + dout << "[WARNING] Tried to start a closed effect - opening"; } bound = glslProgram->bind(); } diff --git a/effects/transition.cpp b/effects/transition.cpp index 3d2d16cb6..2309dbd9b 100644 --- a/effects/transition.cpp +++ b/effects/transition.cpp @@ -2,8 +2,7 @@ #include "project/clip.h" #include "io/config.h" - -#include +#include "debug.h" QVector video_transition_names; QVector audio_transition_names; @@ -38,6 +37,6 @@ Transition* create_transition(int transition_id, Clip* c) { case AUDIO_LINEAR_FADE_TRANSITION: return new LinearFadeTransition(); } } - qDebug() << "[ERROR] Invalid transition ID"; + dout << "[ERROR] Invalid transition ID"; return NULL; } diff --git a/effects/video/shakeeffect.cpp b/effects/video/shakeeffect.cpp index ac1c13759..cada812f7 100644 --- a/effects/video/shakeeffect.cpp +++ b/effects/video/shakeeffect.cpp @@ -4,7 +4,6 @@ #include #include #include -#include #include "ui/labelslider.h" #include "ui/collapsiblewidget.h" diff --git a/effects/video/texteffect.cpp b/effects/video/texteffect.cpp index c8bcd92be..4dba46ffd 100644 --- a/effects/video/texteffect.cpp +++ b/effects/video/texteffect.cpp @@ -9,7 +9,6 @@ #include #include #include -#include #include #include "ui/labelslider.h" diff --git a/effects/video/transformeffect.cpp b/effects/video/transformeffect.cpp index 0b27cd2ec..4fd9a1e16 100644 --- a/effects/video/transformeffect.cpp +++ b/effects/video/transformeffect.cpp @@ -1,6 +1,5 @@ #include "transformeffect.h" -#include #include #include #include @@ -16,6 +15,7 @@ #include "ui/labelslider.h" #include "ui/comboboxex.h" #include "panels/project.h" +#include "debug.h" #define BLEND_MODE_NORMAL 0 #define BLEND_MODE_SCREEN 1 @@ -143,7 +143,7 @@ void TransformEffect::process_coords(double timecode, GLTextureCoords& coords) { glBlendFunc(GL_DST_COLOR, GL_ZERO); break; default: - qDebug() << "[ERROR] Invalid blend mode. This is a bug - please contact developers"; + dout << "[ERROR] Invalid blend mode. This is a bug - please contact developers"; } // opacity diff --git a/io/config.cpp b/io/config.cpp index 11ca5add9..e98da475a 100644 --- a/io/config.cpp +++ b/io/config.cpp @@ -3,7 +3,8 @@ #include #include #include -#include + +#include "debug.h" Config config; @@ -90,7 +91,7 @@ void Config::load(QString path) { } } if (stream.hasError()) { - qDebug() << "[ERROR] Error parsing config XML." << stream.errorString(); + dout << "[ERROR] Error parsing config XML." << stream.errorString(); } f.close(); @@ -100,7 +101,7 @@ void Config::load(QString path) { void Config::save(QString path) { QFile f(path); if (!f.open(QIODevice::WriteOnly)) { - qDebug() << "[ERROR] Could not save configuration"; + dout << "[ERROR] Could not save configuration"; return; } diff --git a/io/exportthread.cpp b/io/exportthread.cpp index 3692c18d6..882b59d24 100644 --- a/io/exportthread.cpp +++ b/io/exportthread.cpp @@ -9,6 +9,7 @@ #include "playback/playback.h" #include "playback/audio.h" #include "dialogs/exportdialog.h" +#include "debug.h" extern "C" { #include @@ -18,7 +19,6 @@ extern "C" { #include } -#include #include #include #include @@ -51,7 +51,7 @@ ExportThread::ExportThread() : continueEncode(true) { bool ExportThread::encode(AVFormatContext* ofmt_ctx, AVCodecContext* codec_ctx, AVFrame* frame, AVPacket* packet, AVStream* stream) { ret = avcodec_send_frame(codec_ctx, frame); if (ret < 0) { - qDebug() << "[ERROR] Failed to send frame to encoder." << ret; + dout << "[ERROR] Failed to send frame to encoder." << ret; ed->export_error = "failed to send frame to encoder (" + QString::number(ret) + ")"; return false; } @@ -62,7 +62,7 @@ bool ExportThread::encode(AVFormatContext* ofmt_ctx, AVCodecContext* codec_ctx, return true; } else if (ret < 0) { if (ret != AVERROR_EOF) { - qDebug() << "[ERROR] Failed to receive packet from encoder." << ret; + dout << "[ERROR] Failed to receive packet from encoder." << ret; ed->export_error = "failed to receive packet from encoder (" + QString::number(ret) + ")"; } return false; @@ -82,7 +82,7 @@ bool ExportThread::setupVideo() { // find video encoder vcodec = avcodec_find_encoder((enum AVCodecID) video_codec); if (!vcodec) { - qDebug() << "[ERROR] Could not find video encoder"; + dout << "[ERROR] Could not find video encoder"; ed->export_error = "could not video encoder for " + QString::number(video_codec); return false; } @@ -91,7 +91,7 @@ bool ExportThread::setupVideo() { video_stream = avformat_new_stream(fmt_ctx, vcodec); video_stream->id = 0; if (!video_stream) { - qDebug() << "[ERROR] Could not allocate video stream"; + dout << "[ERROR] Could not allocate video stream"; ed->export_error = "could not allocate video stream"; return false; } @@ -100,7 +100,7 @@ bool ExportThread::setupVideo() { vcodec_ctx = video_stream->codec; // vcodec_ctx = avcodec_alloc_context3(vcodec); if (!vcodec_ctx) { - qDebug() << "[ERROR] Could not allocate video encoding context"; + dout << "[ERROR] Could not allocate video encoding context"; ed->export_error = "could not allocate video encoding context"; return false; } @@ -135,7 +135,7 @@ bool ExportThread::setupVideo() { ret = avcodec_open2(vcodec_ctx, vcodec, NULL); if (ret < 0) { - qDebug() << "[ERROR] Could not open output video encoder." << ret; + dout << "[ERROR] Could not open output video encoder." << ret; ed->export_error = "could not open output video encoder (" + QString::number(ret) + ")"; return false; } @@ -143,7 +143,7 @@ bool ExportThread::setupVideo() { // copy video encoder parameters to output stream ret = avcodec_parameters_from_context(video_stream->codecpar, vcodec_ctx); if (ret < 0) { - qDebug() << "[ERROR] Could not copy video encoder parameters to output stream." << ret; + dout << "[ERROR] Could not copy video encoder parameters to output stream." << ret; ed->export_error = "could not copy video encoder parameters to output stream (" + QString::number(ret) + ")"; return false; } @@ -187,7 +187,7 @@ bool ExportThread::setupAudio() { // find encoder acodec = avcodec_find_encoder(static_cast(audio_codec)); if (!acodec) { - qDebug() << "[ERROR] Could not find audio encoder"; + dout << "[ERROR] Could not find audio encoder"; ed->export_error = "could not audio encoder for " + QString::number(audio_codec); return false; } @@ -196,7 +196,7 @@ bool ExportThread::setupAudio() { audio_stream = avformat_new_stream(fmt_ctx, acodec); audio_stream->id = 1; if (!audio_stream) { - qDebug() << "[ERROR] Could not allocate audio stream"; + dout << "[ERROR] Could not allocate audio stream"; ed->export_error = "could not allocate audio stream"; return false; } @@ -205,7 +205,7 @@ bool ExportThread::setupAudio() { acodec_ctx = audio_stream->codec; // acodec_ctx = avcodec_alloc_context3(acodec); if (!acodec_ctx) { - qDebug() << "[ERROR] Could not find allocate audio encoding context"; + dout << "[ERROR] Could not find allocate audio encoding context"; ed->export_error = "could not allocate audio encoding context"; return false; } @@ -229,7 +229,7 @@ bool ExportThread::setupAudio() { // open encoder ret = avcodec_open2(acodec_ctx, acodec, NULL); if (ret < 0) { - qDebug() << "[ERROR] Could not open output audio encoder." << ret; + dout << "[ERROR] Could not open output audio encoder." << ret; ed->export_error = "could not open output audio encoder (" + QString::number(ret) + ")"; return false; } @@ -237,7 +237,7 @@ bool ExportThread::setupAudio() { // copy params to output stream ret = avcodec_parameters_from_context(audio_stream->codecpar, acodec_ctx); if (ret < 0) { - qDebug() << "[ERROR] Could not copy audio encoder parameters to output stream." << ret; + dout << "[ERROR] Could not copy audio encoder parameters to output stream." << ret; ed->export_error = "could not copy audio encoder parameters to output stream (" + QString::number(ret) + ")"; return false; } @@ -267,7 +267,7 @@ bool ExportThread::setupAudio() { av_frame_make_writable(audio_frame); ret = av_frame_get_buffer(audio_frame, 0); if (ret < 0) { - qDebug() << "[ERROR] Could not allocate audio buffer." << ret; + dout << "[ERROR] Could not allocate audio buffer." << ret; ed->export_error = "could not allocate audio buffer (" + QString::number(ret) + ")"; return false; } @@ -289,7 +289,7 @@ bool ExportThread::setupAudio() { bool ExportThread::setupContainer() { avformat_alloc_output_context2(&fmt_ctx, NULL, NULL, c_filename); if (!fmt_ctx) { - qDebug() << "[ERROR] Could not create output context"; + dout << "[ERROR] Could not create output context"; ed->export_error = "could not create output format context"; return false; } @@ -298,7 +298,7 @@ bool ExportThread::setupContainer() { ret = avio_open(&fmt_ctx->pb, c_filename, AVIO_FLAG_WRITE); if (ret < 0) { - qDebug() << "[ERROR] Could not open output file." << ret; + dout << "[ERROR] Could not open output file." << ret; ed->export_error = "could not open output file (" + QString::number(ret) + ")"; return false; } @@ -310,7 +310,7 @@ void ExportThread::run() { panel_sequence_viewer->pause(); if (!panel_sequence_viewer->viewer_widget->context()->makeCurrent(&surface)) { - qDebug() << "[ERROR] Make current failed"; + dout << "[ERROR] Make current failed"; ed->export_error = "could not make OpenGL context current"; return; } @@ -329,7 +329,7 @@ void ExportThread::run() { if (continueEncode) { ret = avformat_write_header(fmt_ctx, NULL); if (ret < 0) { - qDebug() << "[ERROR] Could not write output file header." << ret; + dout << "[ERROR] Could not write output file header." << ret; ed->export_error = "could not write output file header (" + QString::number(ret) + ")"; continueEncode = false; } @@ -418,7 +418,7 @@ void ExportThread::run() { ret = av_write_trailer(fmt_ctx); if (ret < 0) { - qDebug() << "[ERROR] Could not write output file trailer." << ret; + dout << "[ERROR] Could not write output file trailer." << ret; ed->export_error = "could not write output file trailer (" + QString::number(ret) + ")"; continueEncode = false; } diff --git a/io/previewgenerator.cpp b/io/previewgenerator.cpp index ad1c6628d..2eb9b6c5e 100644 --- a/io/previewgenerator.cpp +++ b/io/previewgenerator.cpp @@ -5,10 +5,10 @@ #include "panels/project.h" #include "io/config.h" #include "io/crc32.h" +#include "debug.h" #include #include -#include #include #include #include @@ -52,7 +52,7 @@ void PreviewGenerator::parse_media() { for (int i=0;i<(int)fmt_ctx->nb_streams;i++) { // Find the decoder for the video stream if (avcodec_find_decoder(fmt_ctx->streams[i]->codecpar->codec_id) == NULL) { - qDebug() << "[ERROR] Unsupported codec in stream" << i << "of file" << media->name; + dout << "[ERROR] Unsupported codec in stream" << i << "of file" << media->name; } else { MediaStream* ms = media->get_stream_from_file_index(fmt_ctx->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO, i); bool append = false; @@ -66,11 +66,11 @@ void PreviewGenerator::parse_media() { && fmt_ctx->streams[i]->codecpar->width > 0 && fmt_ctx->streams[i]->codecpar->height > 0) { - /*qDebug() << "avg_frame_rate was:" << fmt_ctx->streams[i]->avg_frame_rate.num << "/" << fmt_ctx->streams[i]->avg_frame_rate.den; - qDebug() << "r_frame_rate was:" << fmt_ctx->streams[i]->r_frame_rate.num << "/" << fmt_ctx->streams[i]->r_frame_rate.den; - qDebug() << "codec_frame_rate was:" << fmt_ctx->streams[i]->codec->framerate.num << "/" << fmt_ctx->streams[i]->codec->framerate.den; - qDebug() << "nb_frames was:" << fmt_ctx->streams[i]->nb_frames; - qDebug() << "duration was:" << fmt_ctx->streams[i]->duration << "OR fmt_ctx's duration is:" << fmt_ctx->duration;*/ + /*dout << "avg_frame_rate was:" << fmt_ctx->streams[i]->avg_frame_rate.num << "/" << fmt_ctx->streams[i]->avg_frame_rate.den; + dout << "r_frame_rate was:" << fmt_ctx->streams[i]->r_frame_rate.num << "/" << fmt_ctx->streams[i]->r_frame_rate.den; + dout << "codec_frame_rate was:" << fmt_ctx->streams[i]->codec->framerate.num << "/" << fmt_ctx->streams[i]->codec->framerate.den; + dout << "nb_frames was:" << fmt_ctx->streams[i]->nb_frames; + dout << "duration was:" << fmt_ctx->streams[i]->duration << "OR fmt_ctx's duration is:" << fmt_ctx->duration;*/ if (fmt_ctx->streams[i]->avg_frame_rate.den == 0 && fmt_ctx->streams[i]->duration == AV_NOPTS_VALUE) { // source is LIKELY a still image @@ -87,8 +87,11 @@ void PreviewGenerator::parse_media() { } ms->video_width = fmt_ctx->streams[i]->codecpar->width; ms->video_height = fmt_ctx->streams[i]->codecpar->height; + + // default value, we get the true value later in generate_waveform() ms->video_auto_interlacing = VIDEO_PROGRESSIVE; - ms->video_interlacing = VIDEO_PROGRESSIVE; // default value, we get the true value later in generate_waveform() + ms->video_interlacing = VIDEO_PROGRESSIVE; + if (append) media->video_tracks.append(ms); } else if (fmt_ctx->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) { ms->audio_channels = fmt_ctx->streams[i]->codecpar->channels; @@ -122,7 +125,7 @@ bool PreviewGenerator::retrieve_preview(const QString& hash) { QString thumb_path = get_thumbnail_path(hash, ms); QFile f(thumb_path); if (f.exists()) { - qDebug() << "loaded thumb" << ms->file_index << "from" << thumb_path; + dout << "loaded thumb" << ms->file_index << "from" << thumb_path; ms->video_preview.load(thumb_path); ms->preview_done = true; } else { @@ -135,7 +138,7 @@ bool PreviewGenerator::retrieve_preview(const QString& hash) { QString waveform_path = get_waveform_path(hash, ms); QFile f(waveform_path); if (f.exists()) { - qDebug() << "loaded wave" << ms->file_index << "from" << waveform_path; + dout << "loaded wave" << ms->file_index << "from" << waveform_path; f.open(QFile::ReadOnly); QByteArray data = f.readAll(); ms->audio_preview.resize(data.size()); @@ -213,13 +216,13 @@ void PreviewGenerator::generate_waveform() { int read_ret = av_read_frame(fmt_ctx, &packet); if (read_ret < 0) { end_of_file = true; - if (read_ret != AVERROR_EOF) qDebug() << "[ERROR] Failed to read packet for preview generation" << read_ret; + if (read_ret != AVERROR_EOF) dout << "[ERROR] Failed to read packet for preview generation" << read_ret; break; } if (codec_ctx[packet.stream_index] != NULL) { int send_ret = avcodec_send_packet(codec_ctx[packet.stream_index], &packet); if (send_ret < 0 && send_ret != AVERROR(EAGAIN)) { - qDebug() << "[ERROR] Failed to send packet for preview generation - aborting" << send_ret; + dout << "[ERROR] Failed to send packet for preview generation - aborting" << send_ret; end_of_file = true; break; } @@ -419,7 +422,7 @@ void PreviewGenerator::run() { for (int i=0;ivideo_tracks.size();i++) { MediaStream* ms = media->video_tracks.at(i); if (ms->video_preview.save(get_thumbnail_path(hash, ms), "PNG")) { - qDebug() << "saved" << ms->file_index << "thumb to" << get_thumbnail_path(hash, ms); + dout << "saved" << ms->file_index << "thumb to" << get_thumbnail_path(hash, ms); } } for (int i=0;iaudio_tracks.size();i++) { @@ -428,7 +431,7 @@ void PreviewGenerator::run() { f.open(QFile::WriteOnly); f.write(ms->audio_preview.constData(), ms->audio_preview.size()); f.close(); - qDebug() << "saved" << ms->file_index << "waveform to" << get_waveform_path(hash, ms); + dout << "saved" << ms->file_index << "waveform to" << get_waveform_path(hash, ms); } } diff --git a/main.cpp b/main.cpp index 60800c5db..6205d761c 100644 --- a/main.cpp +++ b/main.cpp @@ -9,7 +9,7 @@ extern "C" { int main(int argc, char *argv[]) { // init ffmpeg subsystem av_register_all(); - avfilter_register_all(); + avfilter_register_all(); QApplication a(argc, argv); MainWindow w; diff --git a/mainwindow.cpp b/mainwindow.cpp index 496992619..cc5461cd1 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -28,7 +28,8 @@ #include "ui_timeline.h" -#include +#include "debug.h" + #include #include #include @@ -69,6 +70,8 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { + setup_debug(); + mainWindow = this; // set up style? @@ -135,7 +138,7 @@ MainWindow::MainWindow(QWidget *parent) : if (QFile(file_name).remove()) deleted_ars++; } } - if (deleted_ars > 0) qDebug() << "[INFO] Deleted" << deleted_ars << "autorecovery" << ((deleted_ars == 1) ? "file that was" : "files that were") << "older than 7 days"; + if (deleted_ars > 0) dout << "[INFO] Deleted" << deleted_ars << "autorecovery" << ((deleted_ars == 1) ? "file that was" : "files that were") << "older than 7 days"; // delete previews older than 30 days QDir preview_dir = QDir(data_dir + "/previews"); @@ -149,7 +152,7 @@ MainWindow::MainWindow(QWidget *parent) : if (QFile(file_name).remove()) deleted_ars++; } } - if (deleted_ars > 0) qDebug() << "[INFO] Deleted" << deleted_ars << "preview" << ((deleted_ars == 1) ? "file that was" : "files that were") << "last read over 30 days ago"; + if (deleted_ars > 0) dout << "[INFO] Deleted" << deleted_ars << "preview" << ((deleted_ars == 1) ? "file that was" : "files that were") << "last read over 30 days ago"; } // detect auto-recovery file @@ -214,6 +217,8 @@ MainWindow::~MainWindow() { delete panel_timeline; delete panel_sequence_viewer; delete panel_footage_viewer; + + close_debug(); } void MainWindow::on_action_Import_triggered() @@ -370,7 +375,7 @@ void MainWindow::on_actionSplit_at_Playhead_triggered() void MainWindow::autorecover_interval() { if (isWindowModified()) { panel_project->save_project(true); - qDebug() << "[INFO] Auto-recovery project saved"; + dout << "[INFO] Auto-recovery project saved"; } } diff --git a/olive.pro b/olive.pro index 42bc6fefb..04c0bc627 100644 --- a/olive.pro +++ b/olive.pro @@ -86,7 +86,8 @@ SOURCES += \ effects/video/waveeffect.cpp \ effects/video/temperatureeffect.cpp \ io/crc32.cpp \ - dialogs/loaddialog.cpp + dialogs/loaddialog.cpp \ + debug.cpp HEADERS += \ mainwindow.h \ @@ -151,7 +152,8 @@ HEADERS += \ effects/video/waveeffect.h \ effects/video/temperatureeffect.h \ io/crc32.h \ - dialogs/loaddialog.h + dialogs/loaddialog.h \ + debug.h FORMS += \ mainwindow.ui \ diff --git a/panels/effectcontrols.cpp b/panels/effectcontrols.cpp index 408df6436..883d6afb8 100644 --- a/panels/effectcontrols.cpp +++ b/panels/effectcontrols.cpp @@ -2,7 +2,6 @@ #include "ui_effectcontrols.h" #include -#include #include #include #include @@ -19,6 +18,7 @@ #include "panels/timeline.h" #include "panels/viewer.h" #include "ui/viewerwidget.h" +#include "debug.h" EffectControls::EffectControls(QWidget *parent) : QDockWidget(parent), @@ -278,7 +278,7 @@ bool EffectControls::is_focused() { } } } else { - qDebug() << "[WARNING] Tried to check focus of a NULL clip"; + dout << "[WARNING] Tried to check focus of a NULL clip"; } } return false; diff --git a/panels/project.cpp b/panels/project.cpp index 592d3af66..01dc75d64 100644 --- a/panels/project.cpp +++ b/panels/project.cpp @@ -21,11 +21,11 @@ #include "dialogs/newsequencedialog.h" #include "dialogs/mediapropertiesdialog.h" #include "dialogs/loaddialog.h" +#include "debug.h" #include #include #include -#include #include #include #include @@ -573,7 +573,7 @@ void* get_media_from_tree(QTreeWidgetItem* item) { switch (type) { case MEDIA_TYPE_FOOTAGE: return get_footage_from_tree(item); case MEDIA_TYPE_SEQUENCE: return get_sequence_from_tree(item); - default: qDebug() << "[ERROR] Invalid media type when retrieving media"; + default: dout << "[ERROR] Invalid media type when retrieving media"; } return NULL;*/ } @@ -1011,7 +1011,7 @@ void Project::load_project() { QFile file(project_url); if (!file.open(QIODevice::ReadOnly)) { - qDebug() << "[ERROR] Could not open file"; + dout << "[ERROR] Could not open file"; return; } @@ -1071,7 +1071,7 @@ void Project::load_project() { if (!cont) { if (show_err) QMessageBox::critical(this, "Project Load Error", "Error loading project: " + error_str, QMessageBox::Ok); } else if (stream.hasError()) { - qDebug() << "[ERROR] Error parsing XML." << stream.errorString(); + dout << "[ERROR] Error parsing XML." << stream.errorString(); QMessageBox::critical(this, "XML Parsing Error", "Couldn't load '" + project_url + "'. " + stream.errorString(), QMessageBox::Ok); cont = false; } @@ -1251,7 +1251,7 @@ void Project::save_project(bool autorecovery) { QFile file(autorecovery ? autorecovery_filename : project_url); if (!file.open(QIODevice::WriteOnly/* | QIODevice::Text*/)) { - qDebug() << "[ERROR] Could not open file"; + dout << "[ERROR] Could not open file"; return; } @@ -1304,7 +1304,7 @@ void Project::save_recent_projects() { } f.close(); } else { - qDebug() << "[WARNING] Could not save recent projects"; + dout << "[WARNING] Could not save recent projects"; } } diff --git a/panels/viewer.cpp b/panels/viewer.cpp index 2211f8006..568240e4d 100644 --- a/panels/viewer.cpp +++ b/panels/viewer.cpp @@ -11,6 +11,7 @@ #include "project/undo.h" #include "ui/audiomonitor.h" #include "ui_timeline.h" +#include "debug.h" #define FRAMES_IN_ONE_MINUTE 1798 // 1800 - 2 #define FRAMES_IN_TEN_MINUTES 17978 // (FRAMES_IN_ONE_MINUTE * 10) - 2 @@ -98,7 +99,7 @@ long timecode_to_frame(const QString& s, int view, double frame_rate) { QList list = s.split(QRegExp("[:;]")); for (int i=0;iplayhead; diff --git a/playback/audio.cpp b/playback/audio.cpp index 0480eb576..74ed5e8d3 100644 --- a/playback/audio.cpp +++ b/playback/audio.cpp @@ -8,13 +8,13 @@ #include "panels/timeline.h" #include "panels/viewer.h" #include "ui_timeline.h" +#include "debug.h" #include #include #include #include #include -#include extern "C" { #include @@ -92,7 +92,7 @@ int get_buffer_offset_from_frame(Sequence* s, long frame) { if (frame >= audio_ibuffer_frame) { return qFloor(av_samples_get_buffer_size(NULL, av_get_channel_layout_nb_channels(s->audio_layout), qRound(((frame-audio_ibuffer_frame)/s->frame_rate)*s->audio_frequency), AV_SAMPLE_FMT_S16, 1)/4)*4; } else { - qDebug() << "[WARNING] Invalid values passed to get_buffer_offset_from_frame"; + dout << "[WARNING] Invalid values passed to get_buffer_offset_from_frame"; return 0; } #endif @@ -264,14 +264,14 @@ void write_wave_trailer(QFile& f) { bool start_recording() { if (sequence == NULL) { - qDebug() << "[ERROR] No active sequence to record into"; + dout << "[ERROR] No active sequence to record into"; return false; } QString audio_path = project_url + " Audio"; QDir audio_dir(audio_path); if (!audio_dir.exists() && !audio_dir.mkpath(".")) { - qDebug() << "[ERROR] Failed to create audio directory"; + dout << "[ERROR] Failed to create audio directory"; return false; } @@ -284,7 +284,7 @@ bool start_recording() { output_recording.setFileName(audio_filename); if (!output_recording.open(QFile::WriteOnly)) { - qDebug() << "[ERROR] Failed to open output file. Does Olive have permission to write to this directory?"; + dout << "[ERROR] Failed to open output file. Does Olive have permission to write to this directory?"; return false; } @@ -294,7 +294,7 @@ bool start_recording() { } QAudioDeviceInfo info = QAudioDeviceInfo::defaultInputDevice(); if (!info.isFormatSupported(audio_format)) { - qDebug() << "[WARNING] Default format not supported, using nearest"; + dout << "[WARNING] Default format not supported, using nearest"; audio_format = info.nearestFormat(audio_format); } write_wave_header(output_recording, audio_format); diff --git a/playback/cacher.cpp b/playback/cacher.cpp index c5719949e..d62ab5599 100644 --- a/playback/cacher.cpp +++ b/playback/cacher.cpp @@ -9,6 +9,7 @@ #include "panels/timeline.h" #include "panels/project.h" #include "effects/transition.h" +#include "debug.h" extern "C" { #include @@ -21,7 +22,6 @@ extern "C" { #include } -#include #include #include #include @@ -103,7 +103,7 @@ void cache_audio_worker(Clip* c, Clip* nest) { av_seek_frame(c->formatCtx, c->stream->index, backtrack_seek, AVSEEK_FLAG_BACKWARD); #ifdef AUDIOWARNINGS if (backtrack_seek == 0) { - qDebug() << "backtracked to 0"; + dout << "backtracked to 0"; } #endif } @@ -117,13 +117,13 @@ void cache_audio_worker(Clip* c, Clip* nest) { ret = retrieve_next_frame(c, c->frame); if (ret >= 0) { if ((ret = av_buffersrc_add_frame_flags(c->buffersrc_ctx, c->frame, AV_BUFFERSRC_FLAG_KEEP_REF)) < 0) { - qDebug() << "[ERROR] Could not feed filtergraph -" << ret; + dout << "[ERROR] Could not feed filtergraph -" << ret; break; } } else { if (ret == AVERROR_EOF) { #ifdef AUDIOWARNINGS - qDebug() << "reached EOF while reading"; + dout << "reached EOF while reading"; #endif // TODO revise usage of reached_end in audio if (!c->reverse) { @@ -131,7 +131,7 @@ void cache_audio_worker(Clip* c, Clip* nest) { } else { } } else { - qDebug() << "[WARNING] Raw audio frame data could not be retrieved." << ret; + dout << "[WARNING] Raw audio frame data could not be retrieved." << ret; c->reached_end = true; } break; @@ -140,12 +140,12 @@ void cache_audio_worker(Clip* c, Clip* nest) { if (ret < 0) { if (ret != AVERROR_EOF) { - qDebug() << "[ERROR] Could not pull from filtergraph"; + dout << "[ERROR] Could not pull from filtergraph"; c->reached_end = true; break; } else { #ifdef AUDIOWARNINGS - qDebug() << "reached EOF while pulling from filtergraph"; + dout << "reached EOF while pulling from filtergraph"; #endif if (!c->reverse) break; } @@ -157,15 +157,15 @@ void cache_audio_worker(Clip* c, Clip* nest) { if (ret != AVERROR_EOF) { if (loop == 2) { #ifdef AUDIOWARNINGS - qDebug() << "starting rev_frame"; + dout << "starting rev_frame"; #endif rev_frame->nb_samples = 0; rev_frame->pts = c->frame->pkt_pts; } int offset = rev_frame->nb_samples * av_get_bytes_per_sample(static_cast(rev_frame->format)) * rev_frame->channels; #ifdef AUDIOWARNINGS - qDebug() << "offset 1:" << offset; - qDebug() << "retrieved samples:" << frame->nb_samples << "size:" << (frame->nb_samples * av_get_bytes_per_sample(static_cast(frame->format)) * frame->channels); + dout << "offset 1:" << offset; + dout << "retrieved samples:" << frame->nb_samples << "size:" << (frame->nb_samples * av_get_bytes_per_sample(static_cast(frame->format)) * frame->channels); #endif memcpy( rev_frame->data[0]+offset, @@ -173,7 +173,7 @@ void cache_audio_worker(Clip* c, Clip* nest) { (frame->nb_samples * av_get_bytes_per_sample(static_cast(frame->format)) * frame->channels) ); #ifdef AUDIOWARNINGS - qDebug() << "pts:" << c->frame->pts << "dur:" << c->frame->pkt_duration << "rev_target:" << c->reverse_target << "offset:" << offset << "limit:" << rev_frame->linesize[0]; + dout << "pts:" << c->frame->pts << "dur:" << c->frame->pkt_duration << "rev_target:" << c->reverse_target << "offset:" << offset << "limit:" << rev_frame->linesize[0]; #endif } @@ -181,20 +181,20 @@ void cache_audio_worker(Clip* c, Clip* nest) { // if (c->frame->pts == c->rev_target) { if ((c->frame->pts >= c->reverse_target) || (ret == AVERROR_EOF)) { - /*qDebug() << "time for the end of rev cache" << rev_frame->nb_samples << c->rev_target << c->frame->pts << c->frame->pkt_duration << c->frame->nb_samples; - qDebug() << "diff:" << (c->frame->pkt_pts + c->frame->pkt_duration) - c->rev_target; + /*dout << "time for the end of rev cache" << rev_frame->nb_samples << c->rev_target << c->frame->pts << c->frame->pkt_duration << c->frame->nb_samples; + dout << "diff:" << (c->frame->pkt_pts + c->frame->pkt_duration) - c->rev_target; int cutoff = qRound64 ((((c->frame->pkt_pts + c->frame->pkt_duration) - c->rev_target) * timebase) * c->sequence->audio_frequency); if (cutoff > 0) { - qDebug() << "cut off" << cutoff << "samples (rate:" << c->sequence->audio_frequency << ")"; + dout << "cut off" << cutoff << "samples (rate:" << c->sequence->audio_frequency << ")"; rev_frame->nb_samples -= cutoff; }*/ #ifdef AUDIOWARNINGS - qDebug() << "pre cutoff deets::: rev_frame.pts:" << rev_frame->pts << "rev_frame.nb_samples" << rev_frame->nb_samples << "rev_target:" << c->reverse_target; + dout << "pre cutoff deets::: rev_frame.pts:" << rev_frame->pts << "rev_frame.nb_samples" << rev_frame->nb_samples << "rev_target:" << c->reverse_target; #endif rev_frame->nb_samples = qRound64(static_cast(c->reverse_target - rev_frame->pts) / c->stream->codecpar->sample_rate * c->sequence->audio_frequency); #ifdef AUDIOWARNINGS - qDebug() << "post cutoff deets::" << rev_frame->nb_samples; + dout << "post cutoff deets::" << rev_frame->nb_samples; #endif int frame_size = rev_frame->nb_samples * rev_frame->channels * av_get_bytes_per_sample(static_cast(rev_frame->format)); @@ -224,7 +224,7 @@ void cache_audio_worker(Clip* c, Clip* nest) { loop++; #ifdef AUDIOWARNINGS - qDebug() << "loop" << loop; + dout << "loop" << loop; #endif } else { frame->pts = c->frame->pts; @@ -253,15 +253,15 @@ void cache_audio_worker(Clip* c, Clip* nest) { int nb_samples = qRound64((target_sts - frame_sts)*c->sequence->audio_frequency); c->frame_sample_index = nb_samples * 4; #ifdef AUDIOWARNINGS - qDebug() << "fsts:" << frame_sts << "tsts:" << target_sts << "nbs:" << nb_samples << "nbb:" << nb_bytes << "rev_targetToSec:" << (c->reverse_target * timebase); - qDebug() << "fsi-calc:" << c->frame_sample_index; + dout << "fsts:" << frame_sts << "tsts:" << target_sts << "nbs:" << nb_samples << "nbb:" << nb_bytes << "rev_targetToSec:" << (c->reverse_target * timebase); + dout << "fsi-calc:" << c->frame_sample_index; #endif if (c->reverse) c->frame_sample_index = nb_bytes - c->frame_sample_index; c->audio_just_reset = false; } #ifdef AUDIOWARNINGS - qDebug() << "fsi-post-post:" << c->frame_sample_index; + dout << "fsi-post-post:" << c->frame_sample_index; #endif if (c->audio_buffer_write == 0) c->audio_buffer_write = get_buffer_offset_from_frame(c->sequence, qMax(timeline_in, c->audio_target_frame)); @@ -281,7 +281,7 @@ void cache_audio_worker(Clip* c, Clip* nest) { if (c->reverse) frame = c->queue.at(1); #ifdef AUDIOWARNINGS - qDebug() << "j" << c->frame_sample_index << nb_bytes; + dout << "j" << c->frame_sample_index << nb_bytes; #endif // apply any audio effects to the data @@ -309,7 +309,7 @@ void cache_audio_worker(Clip* c, Clip* nest) { } break; default: // shouldn't ever get here - qDebug() << "[ERROR] Tried to cache a non-footage/tone clip"; + dout << "[ERROR] Tried to cache a non-footage/tone clip"; return; } @@ -335,7 +335,7 @@ void cache_audio_worker(Clip* c, Clip* nest) { c->frame_sample_index+=2; } #ifdef AUDIOWARNINGS - if (c->audio_buffer_write >= buffer_timeline_out) qDebug() << "timeline out at fsi" << c->frame_sample_index << "of frame ts" << c->frame->pts; + if (c->audio_buffer_write >= buffer_timeline_out) dout << "timeline out at fsi" << c->frame_sample_index << "of frame ts" << c->frame->pts; #endif audio_write_lock.unlock(); @@ -346,7 +346,7 @@ void cache_audio_worker(Clip* c, Clip* nest) { break; } -// qDebug() << "ended" << c->frame_sample_index << nb_bytes; +// dout << "ended" << c->frame_sample_index << nb_bytes; } if (c->reached_end) { frame->nb_samples = 0; @@ -408,12 +408,12 @@ void cache_video_worker(Clip* c, long playhead) { } else if (static_cast(c->media)->get_stream_from_file_index(true, c->media_stream)->infinite_length) { send_it = true; } else { - qDebug() << "skipped adding a frame to the queue - fpts:" << send_frame->pts << "target:" << target_pts; + dout << "skipped adding a frame to the queue - fpts:" << send_frame->pts << "target:" << target_pts; } if (send_it) { if ((send_ret = av_buffersrc_add_frame_flags(c->buffersrc_ctx, send_frame, AV_BUFFERSRC_FLAG_KEEP_REF)) < 0) { - qDebug() << "[ERROR] Failed to add frame to buffer source." << send_ret; + dout << "[ERROR] Failed to add frame to buffer source." << send_ret; break; } } @@ -423,7 +423,7 @@ void cache_video_worker(Clip* c, long playhead) { if (read_ret == AVERROR_EOF) { c->reached_end = true; } else { - qDebug() << "[ERROR] Failed to read frame." << read_ret; + dout << "[ERROR] Failed to read frame." << read_ret; } break; } @@ -433,7 +433,7 @@ void cache_video_worker(Clip* c, long playhead) { if (retr_ret == AVERROR_EOF) { c->reached_end = true; } else { - qDebug() << "[ERROR] Failed to retrieve frame from buffersink." << retr_ret; + dout << "[ERROR] Failed to retrieve frame from buffersink." << retr_ret; } av_frame_free(&frame); break; @@ -503,7 +503,7 @@ void reset_cache(Clip* c, long target_frame) { av_frame_unref(c->frame); int ret = retrieve_next_frame(c, c->frame); if (ret < 0) { - qDebug() << "[WARNING] Seeking terminated prematurely"; + dout << "[WARNING] Seeking terminated prematurely"; break; } if (c->frame->pts <= target_ts) { @@ -532,9 +532,9 @@ void reset_cache(Clip* c, long target_frame) { c->reverse_target = timestamp; timestamp -= av_q2d(av_inv_q(c->stream->time_base)); #ifdef AUDIOWARNINGS - qDebug() << "seeking to" << timestamp << "(originally" << c->reverse_target << ")"; + dout << "seeking to" << timestamp << "(originally" << c->reverse_target << ")"; } else { - qDebug() << "reset called; seeking to" << timestamp; + dout << "reset called; seeking to" << timestamp; #endif } av_seek_frame(c->formatCtx, ms->file_index, timestamp, AVSEEK_FLAG_BACKWARD); @@ -577,14 +577,14 @@ void open_clip_worker(Clip* clip) { if (errCode != 0) { char err[1024]; av_strerror(errCode, err, 1024); - qDebug() << "[ERROR] Could not open" << filename << "-" << err; + dout << "[ERROR] Could not open" << filename << "-" << err; } errCode = avformat_find_stream_info(clip->formatCtx, NULL); if (errCode < 0) { char err[1024]; av_strerror(errCode, err, 1024); - qDebug() << "[ERROR] Could not open" << filename << "-" << err; + dout << "[ERROR] Could not open" << filename << "-" << err; } av_dump_format(clip->formatCtx, 0, filename, 0); @@ -613,13 +613,13 @@ void open_clip_worker(Clip* clip) { // Open codec if (avcodec_open2(clip->codecCtx, clip->codec, &opts) < 0) { - qDebug() << "[ERROR] Could not open codec"; + dout << "[ERROR] Could not open codec"; } // allocate filtergraph clip->filter_graph = avfilter_graph_alloc(); if (clip->filter_graph == NULL) { - qDebug() << "[ERROR] Could not create filtergraph"; + dout << "[ERROR] Could not create filtergraph"; } char filter_args[512]; @@ -659,7 +659,7 @@ void open_clip_worker(Clip* clip) { enum AVPixelFormat pix_fmts[] = { static_cast(dest_format), AV_PIX_FMT_NONE }; if (av_opt_set_int_list(clip->buffersink_ctx, "pix_fmts", pix_fmts, AV_PIX_FMT_NONE, AV_OPT_SEARCH_CHILDREN) < 0) { - qDebug() << "[ERROR] Could not set output pixel format"; + dout << "[ERROR] Could not set output pixel format"; } if (ms->video_interlacing == VIDEO_PROGRESSIVE) { @@ -705,12 +705,12 @@ void open_clip_worker(Clip* clip) { enum AVSampleFormat sample_fmts[] = { sample_format, static_cast(-1) }; if (av_opt_set_int_list(clip->buffersink_ctx, "sample_fmts", sample_fmts, -1, AV_OPT_SEARCH_CHILDREN) < 0) { - qDebug() << "[ERROR] Could not set output sample format"; + dout << "[ERROR] Could not set output sample format"; } int64_t channel_layouts[] = { AV_CH_LAYOUT_STEREO, static_cast(-1) }; if (av_opt_set_int_list(clip->buffersink_ctx, "channel_layouts", channel_layouts, -1, AV_OPT_SEARCH_CHILDREN) < 0) { - qDebug() << "[ERROR] Could not set output sample format"; + dout << "[ERROR] Could not set output sample format"; } int target_sample_rate = clip->sequence->audio_frequency; @@ -732,7 +732,7 @@ void open_clip_worker(Clip* clip) { int sample_rates[] = { target_sample_rate, 0 }; if (av_opt_set_int_list(clip->buffersink_ctx, "sample_rates", sample_rates, 0, AV_OPT_SEARCH_CHILDREN) < 0) { - qDebug() << "[ERROR] Could not set output sample rates"; + dout << "[ERROR] Could not set output sample rates"; } avfilter_graph_config(clip->filter_graph, NULL); @@ -752,7 +752,7 @@ void open_clip_worker(Clip* clip) { clip->frame->nb_samples = 2048; av_frame_make_writable(clip->frame); if (av_frame_get_buffer(clip->frame, 0)) { - qDebug() << "[ERROR] Could not allocate buffer for tone clip"; + dout << "[ERROR] Could not allocate buffer for tone clip"; } clip->audio_reset = true; break; @@ -764,7 +764,7 @@ void open_clip_worker(Clip* clip) { clip->finished_opening = true; - qDebug() << "[INFO] Clip opened on track" << clip->track; + dout << "[INFO] Clip opened on track" << clip->track; } void cache_clip_worker(Clip* clip, long playhead, bool reset, Clip* nest) { @@ -805,7 +805,7 @@ void close_clip_worker(Clip* clip) { clip->reset(); - qDebug() << "[INFO] Clip closed on track" << clip->track; + dout << "[INFO] Clip closed on track" << clip->track; } void Cacher::run() { diff --git a/playback/playback.cpp b/playback/playback.cpp index fe7c6e294..4f66e1f36 100644 --- a/playback/playback.cpp +++ b/playback/playback.cpp @@ -10,6 +10,7 @@ #include "panels/viewer.h" #include "effects/effect.h" #include "panels/effectcontrols.h" +#include "debug.h" extern "C" { #include @@ -21,7 +22,6 @@ extern "C" { #include #include #include -#include #include #include @@ -130,18 +130,18 @@ void get_clip_frame(Clip* c, long playhead) { if (ms->infinite_length) { target_frame = c->queue.at(0); #ifdef GCF_DEBUG - qDebug() << "GCF ==> USE PRECISE (INFINITE)"; + dout << "GCF ==> USE PRECISE (INFINITE)"; #endif } else { // correct frame may be somewhere else in the queue int closest_frame = 0; for (int i=1;iqueue.size();i++) { - //qDebug() << "results for" << i << qAbs(c->queue.at(i)->pts - target_pts) << qAbs(c->queue.at(closest_frame)->pts - target_pts) << c->queue.at(i)->pts << target_pts; + //dout << "results for" << i << qAbs(c->queue.at(i)->pts - target_pts) << qAbs(c->queue.at(closest_frame)->pts - target_pts) << c->queue.at(i)->pts << target_pts; if (c->queue.at(i)->pts == target_pts) { #ifdef GCF_DEBUG - qDebug() << "GCF ==> USE PRECISE"; + dout << "GCF ==> USE PRECISE"; #endif closest_frame = i; break; @@ -152,42 +152,51 @@ void get_clip_frame(Clip* c, long playhead) { // remove all frames earlier than this one from the queue target_frame = c->queue.at(closest_frame); + int64_t next_pts = INT64_MAX; int64_t minimum_ts = target_frame->pts; - if (c->reverse) minimum_ts += quarter_pts; else minimum_ts -= quarter_pts; - //qDebug() << "closest frame was" << closest_frame << "with" << target_frame->pts << "/" << target_pts; + /*if (c->reverse) { + minimum_ts += quarter_pts; + } else { + minimum_ts -= quarter_pts; + }*/ + //dout << "closest frame was" << closest_frame << "with" << target_frame->pts << "/" << target_pts; for (int i=0;iqueue.size();i++) { + if (c->queue.at(i)->pts > target_frame->pts && c->queue.at(i)->pts < next_pts) { + next_pts = c->queue.at(i)->pts; + } if (c->queue.at(i) != target_frame && ((c->queue.at(i)->pts > minimum_ts) == c->reverse)) { - //qDebug() << "removed frame at" << i << "because its pts was" << c->queue.at(i)->pts << "compared to" << target_frame->pts; + //dout << "removed frame at" << i << "because its pts was" << c->queue.at(i)->pts << "compared to" << target_frame->pts; av_frame_free(&c->queue[i]); // may be a little heavy for the UI thread? c->queue.removeAt(i); i--; } } + if (next_pts == INT64_MAX) next_pts = target_frame->pts + target_frame->pkt_duration; - // we didn't get the exact frame + // we didn't get the exact timestamp if (target_frame->pts != target_pts) { - if (target_pts > target_frame->pts && target_pts <= target_frame->pts + target_frame->pkt_duration) { + if (target_pts > target_frame->pts && target_pts <= next_pts) { #ifdef GCF_DEBUG - qDebug() << "GCF ==> USE IMPRECISE"; + dout << "GCF ==> USE IMPRECISE"; #endif } else { int64_t pts_diff = qAbs(target_pts - target_frame->pts); if (c->reached_end && target_pts > target_frame->pts) { #ifdef GCF_DEBUG - qDebug() << "GCF ==> EOF TOLERANT"; + dout << "GCF ==> EOF TOLERANT"; #endif c->reached_end = false; cache = false; } else if (target_pts < target_frame->pts || pts_diff > second_pts) { #ifdef GCF_DEBUG - qDebug() << "GCF ==> RESET" << target_pts << "(" << target_frame->pts << "-" << target_frame->pts+target_frame->pkt_duration << ")"; + dout << "GCF ==> RESET" << target_pts << "(" << target_frame->pts << "-" << target_frame->pts+target_frame->pkt_duration << ")"; #endif target_frame = NULL; reset = true; } else { #ifdef GCF_DEBUG - qDebug() << "GCF ==> WAIT - target:" << target_pts << "closest frame:" << target_frame->pts; + dout << "GCF ==> WAIT - target pts:" << target_pts << "closest frame:" << target_frame->pts; #endif //if (c->queue.size() >= c->max_queue_size) c->queue_remove_earliest(); target_frame = NULL; @@ -202,7 +211,7 @@ void get_clip_frame(Clip* c, long playhead) { if (target_frame == NULL || reset) { // reset cache texture_failed = true; - qDebug() << "[INFO] Frame queue couldn't keep up - either the user seeked or the system is overloaded (queue size:" << c->queue.size() << ")"; + dout << "[INFO] Frame queue couldn't keep up - either the user seeked or the system is overloaded (queue size:" << c->queue.size() << ")"; } if (target_frame != NULL) { @@ -260,24 +269,24 @@ int retrieve_next_frame(Clip* c, AVFrame* f) { if (read_ret >= 0) { int send_ret = avcodec_send_packet(c->codecCtx, c->pkt); if (send_ret < 0) { - qDebug() << "[ERROR] Failed to send packet to decoder." << send_ret; + dout << "[ERROR] Failed to send packet to decoder." << send_ret; return send_ret; } } else { if (read_ret == AVERROR_EOF) { int send_ret = avcodec_send_packet(c->codecCtx, NULL); if (send_ret < 0) { - qDebug() << "[ERROR] Failed to send packet to decoder." << send_ret; + dout << "[ERROR] Failed to send packet to decoder." << send_ret; return send_ret; } } else { - qDebug() << "[ERROR] Could not read frame." << read_ret; + dout << "[ERROR] Could not read frame." << read_ret; return read_ret; // skips trying to find a frame at all } } } if (receive_ret < 0) { - if (receive_ret != AVERROR_EOF) qDebug() << "[ERROR] Failed to receive packet from decoder." << receive_ret; + if (receive_ret != AVERROR_EOF) dout << "[ERROR] Failed to receive packet from decoder." << receive_ret; result = receive_ret; } diff --git a/project/clip.cpp b/project/clip.cpp index 5bfc55525..6d2bc4829 100644 --- a/project/clip.cpp +++ b/project/clip.cpp @@ -11,8 +11,6 @@ #include "panels/timeline.h" #include "undo.h" -#include - extern "C" { #include } diff --git a/project/sequence.cpp b/project/sequence.cpp index b29a20884..86619a02c 100644 --- a/project/sequence.cpp +++ b/project/sequence.cpp @@ -3,8 +3,6 @@ #include "project/clip.h" #include "effects/transition.h" -#include - Sequence::Sequence() : playhead(0), using_workarea(false), diff --git a/project/undo.cpp b/project/undo.cpp index ffec52dcf..7235745eb 100644 --- a/project/undo.cpp +++ b/project/undo.cpp @@ -1,6 +1,5 @@ #include "undo.h" -#include #include #include #include diff --git a/ui/audiomonitor.cpp b/ui/audiomonitor.cpp index a296fd56e..5e136aada 100644 --- a/ui/audiomonitor.cpp +++ b/ui/audiomonitor.cpp @@ -8,7 +8,6 @@ #include #include #include -#include #define AUDIO_MONITOR_PEAK_HEIGHT 15 #define AUDIO_MONITOR_GAP 3 diff --git a/ui/timelinewidget.cpp b/ui/timelinewidget.cpp index f441858ba..0d949b0db 100644 --- a/ui/timelinewidget.cpp +++ b/ui/timelinewidget.cpp @@ -15,6 +15,7 @@ #include "ui_timeline.h" #include "mainwindow.h" #include "ui/viewerwidget.h" +#include "debug.h" #include "effects/effect.h" #include "effects/transition.h" @@ -22,7 +23,6 @@ #include #include -#include #include #include #include @@ -231,20 +231,17 @@ void TimelineWidget::dragEnterEvent(QDragEnterEvent *event) { } } - /*if (config.enable_drag_files_to_timeline && event->mimeData()->hasUrls()) { - // TODO for this to work, we need a way to abort PreviewGenerator - - - qDebug() << "TODO get data for:"; + if (config.enable_drag_files_to_timeline && event->mimeData()->hasUrls()) { + dout << "TODO get data for:"; QList urls = event->mimeData()->urls(); if (!urls.isEmpty()) { for (int i=0;iaccept(); @@ -1965,7 +1962,7 @@ void draw_waveform(Clip* clip, MediaStream* ms, long media_length, QPainter *p, p->drawLine(clip_rect.left()+i, mid+min, clip_rect.left()+i, mid+max); } }/* else { - qDebug() << "[WARNING] Tried to reach" << offset + 1 << ", limit:" << ms->audio_preview.size(); + dout << "[WARNING] Tried to reach" << offset + 1 << ", limit:" << ms->audio_preview.size(); }*/ } } diff --git a/ui/viewerwidget.cpp b/ui/viewerwidget.cpp index 8d5efd057..bd681128b 100644 --- a/ui/viewerwidget.cpp +++ b/ui/viewerwidget.cpp @@ -13,8 +13,8 @@ #include "ui_timeline.h" #include "playback/cacher.h" #include "io/config.h" +#include "debug.h" -#include #include #include #include @@ -279,7 +279,7 @@ GLuint ViewerWidget::compose_sequence(Clip* nest, bool render_audio) { Clip* c = current_clips.at(i); if (c->media_type == MEDIA_TYPE_FOOTAGE && !c->finished_opening) { - qDebug() << "[WARNING] Tried to display clip" << i << "but it's closed"; + dout << "[WARNING] Tried to display clip" << i << "but it's closed"; texture_failed = true; } else { if (c->track < 0) { @@ -306,7 +306,7 @@ GLuint ViewerWidget::compose_sequence(Clip* nest, bool render_audio) { if (!texture_failed) { if (textureID == 0 && c->media_type != MEDIA_TYPE_SOLID) { - qDebug() << "[WARNING] Texture hasn't been created yet"; + dout << "[WARNING] Texture hasn't been created yet"; texture_failed = true; } else if (playhead >= c->timeline_in) { glPushMatrix(); @@ -514,7 +514,7 @@ void ViewerWidget::paintGL() { if (texture_failed) { if (rendering) { - qDebug() << "[INFO] Texture failed - looping"; + dout << "[INFO] Texture failed - looping"; loop = true; } else { retry_timer.start();