From fba9223dd99865e3cb90dc353f928ac3da3ac81e Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Sun, 14 Oct 2018 15:38:11 +0200 Subject: [PATCH] Assorted clang-format fixes (not complete). --- chroma_subsampler.cpp | 8 +++---- chroma_subsampler.h | 4 ++-- clip_list.cpp | 46 +++++++++++++++++++++++++--------------- clip_list.h | 13 ++++++------ context.cpp | 6 ++---- db.cpp | 2 +- db.h | 1 + disk_space_estimator.cpp | 6 +++--- disk_space_estimator.h | 11 +++++----- eval.cpp | 7 +++--- flow.cpp | 20 ++++++++--------- flow.h | 13 ++++++------ flow_main.cpp | 23 +++++++++----------- gpu_timers.cpp | 7 +++--- gpu_timers.h | 3 +-- httpd.cpp | 10 ++++----- httpd.h | 15 +++++++------ jpeg_frame_view.cpp | 39 +++++++++++++++++----------------- jpeg_frame_view.h | 15 ++++++------- main.cpp | 20 ++++++++--------- mainwindow.cpp | 35 ++++++++++++++++-------------- mainwindow.h | 15 ++++++------- memcpy_interleaved.cpp | 8 +++---- mux.cpp | 7 +++--- player.cpp | 29 ++++++++++++------------- ref_counted_gl_sync.h | 2 +- util.cpp | 7 +++--- util.h | 28 +++++++++++++++--------- vaapi_jpeg_decoder.cpp | 34 ++++++++++++++++------------- vaapi_jpeg_decoder.h | 9 ++++---- video_stream.cpp | 15 ++++++------- video_stream.h | 20 ++++++++--------- vis.cpp | 7 +++--- ycbcr_converter.cpp | 4 ++-- ycbcr_converter.h | 5 ++--- 35 files changed, 250 insertions(+), 244 deletions(-) diff --git a/chroma_subsampler.cpp b/chroma_subsampler.cpp index 28bd0a3..04fd594 100644 --- a/chroma_subsampler.cpp +++ b/chroma_subsampler.cpp @@ -1,7 +1,7 @@ #include "chroma_subsampler.h" -#include #include +#include #define BUFFER_OFFSET(i) ((char *)nullptr + (i)) @@ -83,10 +83,10 @@ ChromaSubsampler::ChromaSubsampler() 2.0f, 0.0f }; glCreateBuffers(1, &vbo); - glNamedBufferData(vbo, sizeof(vertices), vertices, GL_STATIC_DRAW); + glNamedBufferData(vbo, sizeof(vertices), vertices, GL_STATIC_DRAW); glBindBuffer(GL_ARRAY_BUFFER, vbo); - GLint position_attrib = 0; // Hard-coded in every vertex shader. + GLint position_attrib = 0; // Hard-coded in every vertex shader. glEnableVertexArrayAttrib(vao, position_attrib); glVertexAttribPointer(position_attrib, 2, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(0)); @@ -112,7 +112,7 @@ void ChromaSubsampler::subsample_chroma(GLuint cbcr_tex, unsigned width, unsigne glProgramUniform2f(cbcr_program, uniform_chroma_offset_0, -1.0f / width, 0.0f); glProgramUniform2f(cbcr_program, uniform_chroma_offset_1, -0.0f / width, 0.0f); - glViewport(0, 0, width/2, height); + glViewport(0, 0, width / 2, height); fbos.render_to(cb_tex, cr_tex); glBindVertexArray(vao); diff --git a/chroma_subsampler.h b/chroma_subsampler.h index 84351c9..ec43fe0 100644 --- a/chroma_subsampler.h +++ b/chroma_subsampler.h @@ -1,10 +1,10 @@ #ifndef _CHROMA_SUBSAMPLER_H #define _CHROMA_SUBSAMPLER_H 1 -#include - #include "flow.h" +#include + class ChromaSubsampler { public: ChromaSubsampler(); diff --git a/clip_list.cpp b/clip_list.cpp index cdffba9..5ee36df 100644 --- a/clip_list.cpp +++ b/clip_list.cpp @@ -1,13 +1,13 @@ +#include "clip_list.h" + #include "mainwindow.h" +#include "timebase.h" +#include "ui_mainwindow.h" #include #include #include -#include "clip_list.h" -#include "timebase.h" -#include "ui_mainwindow.h" - using namespace std; string pts_to_string(int64_t pts) @@ -40,27 +40,36 @@ string duration_to_string(int64_t pts_diff) return buf; } -int ClipList::rowCount(const QModelIndex &parent) const { - if (parent.isValid()) return 0; +int ClipList::rowCount(const QModelIndex &parent) const +{ + if (parent.isValid()) + return 0; return clips.size(); } -int PlayList::rowCount(const QModelIndex &parent) const { - if (parent.isValid()) return 0; +int PlayList::rowCount(const QModelIndex &parent) const +{ + if (parent.isValid()) + return 0; return clips.size(); } -int ClipList::columnCount(const QModelIndex &parent) const { - if (parent.isValid()) return 0; +int ClipList::columnCount(const QModelIndex &parent) const +{ + if (parent.isValid()) + return 0; return int(Column::NUM_COLUMNS); } -int PlayList::columnCount(const QModelIndex &parent) const { - if (parent.isValid()) return 0; +int PlayList::columnCount(const QModelIndex &parent) const +{ + if (parent.isValid()) + return 0; return int(Column::NUM_COLUMNS); } -QVariant ClipList::data(const QModelIndex &parent, int role) const { +QVariant ClipList::data(const QModelIndex &parent, int role) const +{ if (!parent.isValid()) return QVariant(); const int row = parent.row(), column = parent.column(); @@ -108,7 +117,8 @@ QVariant ClipList::data(const QModelIndex &parent, int role) const { } } -QVariant PlayList::data(const QModelIndex &parent, int role) const { +QVariant PlayList::data(const QModelIndex &parent, int role) const +{ if (!parent.isValid()) return QVariant(); const int row = parent.row(), column = parent.column(); @@ -186,7 +196,8 @@ QVariant PlayList::data(const QModelIndex &parent, int role) const { } } -QVariant ClipList::headerData(int section, Qt::Orientation orientation, int role) const { +QVariant ClipList::headerData(int section, Qt::Orientation orientation, int role) const +{ if (role != Qt::DisplayRole) return QVariant(); if (orientation != Qt::Horizontal) @@ -212,7 +223,8 @@ QVariant ClipList::headerData(int section, Qt::Orientation orientation, int role } } -QVariant PlayList::headerData(int section, Qt::Orientation orientation, int role) const { +QVariant PlayList::headerData(int section, Qt::Orientation orientation, int role) const +{ if (role != Qt::DisplayRole) return QVariant(); if (orientation != Qt::Horizontal) @@ -379,7 +391,7 @@ void PlayList::move_clips(size_t first, size_t last, int delta) beginMoveRows(QModelIndex(), first, last, QModelIndex(), first - 1); rotate(clips.begin() + first - 1, clips.begin() + first, clips.begin() + last + 1); } else { - beginMoveRows(QModelIndex(), first, last, QModelIndex(), first + (last-first+1) + 1); + beginMoveRows(QModelIndex(), first, last, QModelIndex(), first + (last - first + 1) + 1); first = clips.size() - first - 1; last = clips.size() - last - 1; rotate(clips.rbegin() + last - 1, clips.rbegin() + last, clips.rbegin() + first + 1); diff --git a/clip_list.h b/clip_list.h index c853263..6644982 100644 --- a/clip_list.h +++ b/clip_list.h @@ -1,15 +1,13 @@ #ifndef _CLIP_LIST_H #define _CLIP_LIST_H 1 -#include +#include "defs.h" +#include "state.pb.h" +#include #include - -#include #include - -#include "defs.h" -#include "state.pb.h" +#include struct Clip { int64_t pts_in = -1, pts_out = -1; // pts_in is inclusive, pts_out is exclusive. @@ -28,7 +26,8 @@ struct ClipProxy { public: ClipProxy(Clip &clip, DataChangedReceiver *clip_list, size_t row) : clip(clip), clip_list(clip_list), row(row) {} - ~ClipProxy() { + ~ClipProxy() + { if (clip_list != nullptr) { clip_list->emit_data_changed(row); } diff --git a/context.cpp b/context.cpp index ac8c97b..0b17bfa 100644 --- a/context.cpp +++ b/context.cpp @@ -1,12 +1,10 @@ -#include - -#include - #include #include #include #include #include +#include +#include QGLWidget *global_share_widget = nullptr; diff --git a/db.cpp b/db.cpp index c999a1d..77e3b73 100644 --- a/db.cpp +++ b/db.cpp @@ -67,7 +67,7 @@ void DB::store_state(const StateProto &state) } sqlite3_stmt *stmt; - ret = sqlite3_prepare(db, "INSERT INTO state VALUES (?)", -1, &stmt, 0); + ret = sqlite3_prepare(db, "INSERT INTO state VALUES (?)", -1, &stmt, 0); if (ret != SQLITE_OK) { fprintf(stderr, "INSERT prepare: %s\n", sqlite3_errmsg(db)); exit(1); diff --git a/db.h b/db.h index 826ab3f..13a7e51 100644 --- a/db.h +++ b/db.h @@ -2,6 +2,7 @@ #define DB_H 1 #include "state.pb.h" + #include class DB { diff --git a/disk_space_estimator.cpp b/disk_space_estimator.cpp index 50460f9..5ce5070 100644 --- a/disk_space_estimator.cpp +++ b/disk_space_estimator.cpp @@ -1,11 +1,11 @@ #include "disk_space_estimator.h" +#include "timebase.h" + +#include #include #include #include -#include - -#include "timebase.h" DiskSpaceEstimator::DiskSpaceEstimator(DiskSpaceEstimator::callback_t callback) : callback(callback) diff --git a/disk_space_estimator.h b/disk_space_estimator.h index c7f1df5..a86ee2e 100644 --- a/disk_space_estimator.h +++ b/disk_space_estimator.h @@ -9,16 +9,15 @@ // // The bitrate is measured over a simple 30-second sliding window. -#include -#include +#include "timebase.h" + #include #include +#include #include +#include -#include "timebase.h" - -class DiskSpaceEstimator -{ +class DiskSpaceEstimator { public: typedef std::function callback_t; DiskSpaceEstimator(callback_t callback); diff --git a/eval.cpp b/eval.cpp index 8161527..85783bb 100644 --- a/eval.cpp +++ b/eval.cpp @@ -1,12 +1,11 @@ // Evaluate a .flo file against ground truth, // outputting the average end-point error. -#include -#include +#include "util.h" +#include #include - -#include "util.h" +#include using namespace std; diff --git a/flow.cpp b/flow.cpp index 68392dc..e672fe6 100644 --- a/flow.cpp +++ b/flow.cpp @@ -1,21 +1,20 @@ #define NO_SDL_GLEXT 1 -#include - -#include -#include -#include -#include - #include "flow.h" + #include "gpu_timers.h" #include "util.h" #include +#include #include -#include +#include #include +#include #include +#include +#include +#include #include #define BUFFER_OFFSET(i) ((char *)nullptr + (i)) @@ -80,7 +79,7 @@ string read_file(const string &filename) } if (ret == 0) { fprintf(stderr, "Short read when trying to read %d bytes from %s\n", - size, filename.c_str()); + size, filename.c_str()); exit(1); } fclose(fp); @@ -88,11 +87,10 @@ string read_file(const string &filename) return str; } - GLuint compile_shader(const string &shader_src, GLenum type) { GLuint obj = glCreateShader(type); - const GLchar* source[] = { shader_src.data() }; + const GLchar *source[] = { shader_src.data() }; const GLint length[] = { (GLint)shader_src.size() }; glShaderSource(obj, 1, source, length); glCompileShader(obj); diff --git a/flow.h b/flow.h index af3f810..08b2590 100644 --- a/flow.h +++ b/flow.h @@ -5,13 +5,13 @@ // in-between frames. The main user interface is the DISComputeFlow and Interpolate // classes (also GrayscaleConversion can be useful). -#include -#include #include +#include #include #include -#include +#include #include +#include class ScopedTimer; @@ -111,7 +111,6 @@ private: std::map, GLuint> fbos; }; - // Same, but with a depth texture. template class PersistentFBOSetWithDepth { @@ -422,7 +421,8 @@ public: // after use. GLuint exec(GLuint tex, FlowDirection flow_direction, ResizeStrategy resize_strategy); - void release_texture(GLuint tex) { + void release_texture(GLuint tex) + { pool.release_texture(tex); } @@ -548,7 +548,8 @@ public: // two-layer RGBA8 texture with mipmaps (unless flow_level == 0). std::pair exec(GLuint image_tex, GLuint gray_tex, GLuint bidirectional_flow_tex, GLuint width, GLuint height, float alpha); - void release_texture(GLuint tex) { + void release_texture(GLuint tex) + { pool.release_texture(tex); } diff --git a/flow_main.cpp b/flow_main.cpp index ecaee05..1ef44ac 100644 --- a/flow_main.cpp +++ b/flow_main.cpp @@ -1,6 +1,8 @@ #define NO_SDL_GLEXT 1 -#include +#include "flow.h" +#include "gpu_timers.h" +#include "util.h" #include #include @@ -9,21 +11,16 @@ #include #include #include - -#include -#include -#include -#include - -#include "flow.h" -#include "gpu_timers.h" -#include "util.h" - #include +#include #include -#include +#include +#include #include +#include #include +#include +#include #include #define BUFFER_OFFSET(i) ((char *)nullptr + (i)) @@ -418,7 +415,7 @@ void interpolate_image(int argc, char **argv, int optind) int main(int argc, char **argv) { - static const option long_options[] = { + static const option long_options[] = { { "smoothness-relative-weight", required_argument, 0, 's' }, // alpha. { "intensity-relative-weight", required_argument, 0, 'i' }, // delta. { "gradient-relative-weight", required_argument, 0, 'g' }, // gamma. diff --git a/gpu_timers.cpp b/gpu_timers.cpp index 1e20cc1..ad747ae 100644 --- a/gpu_timers.cpp +++ b/gpu_timers.cpp @@ -1,7 +1,7 @@ -#include - #include "gpu_timers.h" +#include + using namespace std; bool enable_timing = false; @@ -54,7 +54,8 @@ void GPUTimers::print() size_t num_subtimers = 0; GLint64 sum_subtimers = 0; for (size_t j = i + 1; j < timers.size() && timers[j].level > timers[i].level; ++j) { - if (timers[j].level != timers[i].level + 1) continue; + if (timers[j].level != timers[i].level + 1) + continue; ++num_subtimers; sum_subtimers += find_elapsed(timers[j].query); } diff --git a/gpu_timers.h b/gpu_timers.h index e843fea..a8c626e 100644 --- a/gpu_timers.h +++ b/gpu_timers.h @@ -1,12 +1,11 @@ #ifndef _GPU_TIMERS_H #define _GPU_TIMERS_H 1 +#include #include #include #include -#include - extern bool enable_timing; extern bool detailed_timing; extern bool in_warmup; diff --git a/httpd.cpp b/httpd.cpp index fddc45a..36d2874 100644 --- a/httpd.cpp +++ b/httpd.cpp @@ -3,13 +3,13 @@ #include #include #include +#include #include #include #include #include #include #include -#include extern "C" { #include } @@ -75,8 +75,8 @@ int HTTPD::answer_to_connection_thunk(void *cls, MHD_Connection *connection, int HTTPD::answer_to_connection(MHD_Connection *connection, const char *url, const char *method, - const char *version, const char *upload_data, - size_t *upload_data_size, void **con_cls) + const char *version, const char *upload_data, + size_t *upload_data_size, void **con_cls) { // See if the URL ends in “.metacube”. HTTPD::Stream::Framing framing; @@ -154,7 +154,7 @@ ssize_t HTTPD::Stream::reader_callback_thunk(void *cls, uint64_t pos, char *buf, ssize_t HTTPD::Stream::reader_callback(uint64_t pos, char *buf, size_t max) { unique_lock lock(buffer_mutex); - has_buffered_data.wait(lock, [this]{ return should_quit || !buffered_data.empty(); }); + has_buffered_data.wait(lock, [this] { return should_quit || !buffered_data.empty(); }); if (should_quit) { return 0; } @@ -253,7 +253,7 @@ void HTTPD::Stream::add_data(const char *buf, size_t buf_size, HTTPD::Stream::Da buffered_data.emplace_back((char *)&packet, sizeof(packet)); } - has_buffered_data.notify_all(); + has_buffered_data.notify_all(); } void HTTPD::Stream::stop() diff --git a/httpd.h b/httpd.h index 57c649b..9901814 100644 --- a/httpd.h +++ b/httpd.h @@ -3,16 +3,16 @@ // A class dealing with stream output to HTTP. -#include -#include -#include #include #include #include #include #include #include +#include +#include #include +#include #include #include @@ -32,7 +32,8 @@ public: ~HTTPD(); // Should be called before start(). - void set_header(const std::string &data) { + void set_header(const std::string &data) + { header = data; } @@ -41,14 +42,16 @@ public: NO_CORS_POLICY, ALLOW_ALL_ORIGINS }; - void add_endpoint(const std::string &url, const EndpointCallback &callback, CORSPolicy cors_policy) { + void add_endpoint(const std::string &url, const EndpointCallback &callback, CORSPolicy cors_policy) + { endpoints[url] = Endpoint{ callback, cors_policy }; } void start(int port); void stop(); void add_data(const char *buf, size_t size, bool keyframe, int64_t time, AVRational timebase); - int64_t get_num_connected_clients() const { + int64_t get_num_connected_clients() const + { return metric_num_connected_clients.load(); } diff --git a/jpeg_frame_view.cpp b/jpeg_frame_view.cpp index 905249a..b33b76b 100644 --- a/jpeg_frame_view.cpp +++ b/jpeg_frame_view.cpp @@ -1,28 +1,27 @@ #include "jpeg_frame_view.h" -#include -#include -#include +#include "defs.h" +#include "post_to_main_thread.h" +#include "video_stream.h" +#include "ycbcr_converter.h" +#include +#include #include #include #include +#include +#include +#include +#include #include +#include #include +#include #include -#include -#include - -#include -#include -#include - -#include "defs.h" -#include "post_to_main_thread.h" +// Must come after the Qt stuff. #include "vaapi_jpeg_decoder.h" -#include "video_stream.h" -#include "ycbcr_converter.h" using namespace movit; using namespace std; @@ -146,7 +145,7 @@ shared_ptr decode_jpeg(const string &filename) jpeg_read_raw_data(&dinfo, data, v_mcu_size); } - (void) jpeg_finish_decompress(&dinfo); + (void)jpeg_finish_decompress(&dinfo); jpeg_destroy_decompress(&dinfo); fclose(fp); @@ -215,7 +214,8 @@ void jpeg_decoder_thread_func() any_pending_decodes.wait(lock, [] { return !pending_decodes.empty() || should_quit.load(); }); - if (should_quit.load()) break; + if (should_quit.load()) + break; decode = pending_decodes.front(); pending_decodes.pop_front(); @@ -248,7 +248,8 @@ void jpeg_decoder_thread_func() cache_updated.wait(lock, [id] { return cache.count(id) != 0 || should_quit.load(); }); - if (should_quit.load()) break; + if (should_quit.load()) + break; found_in_cache = true; // Don't count it as a decode. auto it = cache.find(id); @@ -302,7 +303,8 @@ void JPEGFrameView::shutdown() } JPEGFrameView::JPEGFrameView(QWidget *parent) - : QGLWidget(parent, global_share_widget) { + : QGLWidget(parent, global_share_widget) +{ } void JPEGFrameView::setFrame(unsigned stream_idx, int64_t pts, bool interpolated, int secondary_stream_idx, int64_t secondary_pts, float fade_alpha) @@ -399,7 +401,6 @@ void JPEGFrameView::paintGL() namespace { - } // namespace void JPEGFrameView::setDecodedFrame(shared_ptr frame, shared_ptr secondary_frame, float fade_alpha) diff --git a/jpeg_frame_view.h b/jpeg_frame_view.h index b8e26c4..1047e0b 100644 --- a/jpeg_frame_view.h +++ b/jpeg_frame_view.h @@ -1,22 +1,19 @@ #ifndef _JPEG_FRAME_VIEW_H #define _JPEG_FRAME_VIEW_H 1 -#include -#include - -#include +#include "jpeg_frame.h" +#include "ycbcr_converter.h" +#include +#include +#include #include #include #include #include - -#include +#include #include -#include "jpeg_frame.h" -#include "ycbcr_converter.h" - struct JPEGID { unsigned stream_idx; int64_t pts; diff --git a/main.cpp b/main.cpp index b7ae8f0..da2340b 100644 --- a/main.cpp +++ b/main.cpp @@ -1,15 +1,14 @@ #include -#include -#include -#include -#include - #include #include #include +#include #include #include +#include +#include #include +#include #include #include @@ -17,18 +16,13 @@ extern "C" { #include } -#include - -#include -#include - #include "clip_list.h" #include "context.h" #include "defs.h" #include "disk_space_estimator.h" -#include "mainwindow.h" #include "ffmpeg_raii.h" #include "httpd.h" +#include "mainwindow.h" #include "player.h" #include "post_to_main_thread.h" #include "ref_counted_gl_sync.h" @@ -36,6 +30,10 @@ extern "C" { #include "ui_mainwindow.h" #include "vaapi_jpeg_decoder.h" +#include +#include +#include + using namespace std; using namespace std::chrono; diff --git a/mainwindow.cpp b/mainwindow.cpp index 8f63bee..0932a75 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -7,16 +7,14 @@ #include "timebase.h" #include "ui_mainwindow.h" -#include -#include -#include - #include -#include #include #include - +#include +#include #include +#include +#include using namespace std; using namespace std::placeholders; @@ -199,7 +197,8 @@ void MainWindow::queue_clicked() void MainWindow::preview_clicked() { - if (cliplist_clips->empty()) return; + if (cliplist_clips->empty()) + return; QItemSelectionModel *selected = ui->clip_list->selectionModel(); if (!selected->hasSelection()) { @@ -315,7 +314,8 @@ void MainWindow::state_changed(const StateProto &state) void MainWindow::play_clicked() { - if (playlist_clips->empty()) return; + if (playlist_clips->empty()) + return; QItemSelectionModel *selected = ui->playlist->selectionModel(); int row; @@ -366,7 +366,7 @@ void MainWindow::live_player_clip_progress(double played_this_clip, double total double remaining = total_length - played_this_clip; for (int row = playlist_clips->get_currently_playing() + 1; row < int(playlist_clips->size()); ++row) { const Clip clip = *playlist_clips->clip(row); - remaining += double(clip.pts_out - clip.pts_in) / TIMEBASE / 0.5; // FIXME: stop hardcoding speed. + remaining += double(clip.pts_out - clip.pts_in) / TIMEBASE / 0.5; // FIXME: stop hardcoding speed. } int remaining_ms = lrint(remaining * 1e3); @@ -444,7 +444,8 @@ bool MainWindow::eventFilter(QObject *watched, QEvent *event) } int column = destination->columnAt(mouse->x()); int row = destination->rowAt(mouse->y()); - if (column == -1 || row == -1) return false; + if (column == -1 || row == -1) + return false; if (type == SCRUBBING_CLIP_LIST) { if (ClipList::Column(column) == ClipList::Column::IN) { @@ -596,7 +597,8 @@ void MainWindow::preview_single_frame(int64_t pts, unsigned stream_idx, MainWind { if (rounding == LAST_BEFORE) { lock_guard lock(frame_mu); - if (frames[stream_idx].empty()) return; + if (frames[stream_idx].empty()) + return; auto it = lower_bound(frames[stream_idx].begin(), frames[stream_idx].end(), pts); if (it != frames[stream_idx].end()) { pts = *it; @@ -604,7 +606,8 @@ void MainWindow::preview_single_frame(int64_t pts, unsigned stream_idx, MainWind } else { assert(rounding == FIRST_AT_OR_AFTER); lock_guard lock(frame_mu); - if (frames[stream_idx].empty()) return; + if (frames[stream_idx].empty()) + return; auto it = upper_bound(frames[stream_idx].begin(), frames[stream_idx].end(), pts - 1); if (it != frames[stream_idx].end()) { pts = *it; @@ -667,10 +670,10 @@ void MainWindow::report_disk_space(off_t free_bytes, double estimated_seconds_le std::string label = buf; - post_to_main_thread([this, label]{ - disk_free_label->setText(QString::fromStdString(label)); - ui->menuBar->setCornerWidget(disk_free_label); // Need to set this again for the sizing to get right. - }); + post_to_main_thread([this, label] { + disk_free_label->setText(QString::fromStdString(label)); + ui->menuBar->setCornerWidget(disk_free_label); // Need to set this again for the sizing to get right. + }); } void MainWindow::exit_triggered() diff --git a/mainwindow.h b/mainwindow.h index 7f77273..103dd83 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -1,24 +1,22 @@ #ifndef MAINWINDOW_H #define MAINWINDOW_H -#include -#include - -#include -#include - #include "clip_list.h" #include "db.h" #include "state.pb.h" +#include +#include +#include +#include + namespace Ui { class MainWindow; } // namespace Ui class Player; -class MainWindow : public QMainWindow -{ +class MainWindow : public QMainWindow { Q_OBJECT public: @@ -102,4 +100,3 @@ private slots: extern MainWindow *global_mainwindow; #endif - diff --git a/memcpy_interleaved.cpp b/memcpy_interleaved.cpp index 9a41cdd..9634fd2 100644 --- a/memcpy_interleaved.cpp +++ b/memcpy_interleaved.cpp @@ -1,6 +1,6 @@ -#include #include #include +#include #if __SSE2__ #include #endif @@ -56,9 +56,9 @@ size_t memcpy_interleaved_fastpath(uint8_t *dest1, uint8_t *dest2, const uint8_t assert(((limit - src) % 64) == 0); #if __AVX2__ - const __m256i * __restrict in = (const __m256i *)src; - __m256i * __restrict out1 = (__m256i *)dest1; - __m256i * __restrict out2 = (__m256i *)dest2; + const __m256i *__restrict in = (const __m256i *)src; + __m256i *__restrict out1 = (__m256i *)dest1; + __m256i *__restrict out2 = (__m256i *)dest2; __m256i shuffle_cw = _mm256_set_epi8( 15, 13, 11, 9, 7, 5, 3, 1, 14, 12, 10, 8, 6, 4, 2, 0, diff --git a/mux.cpp b/mux.cpp index a459c45..2be0fe4 100644 --- a/mux.cpp +++ b/mux.cpp @@ -1,12 +1,12 @@ #include "mux.h" +#include #include +#include #include #include #include #include -#include -#include #include #include #include @@ -171,7 +171,8 @@ void Mux::add_packet(const AVPacket &pkt, int64_t pts, int64_t dts, AVRational t lock_guard lock(mu); if (write_strategy == WriteStrategy::WRITE_BACKGROUND) { packet_queue.push_back(QueuedPacket{ av_packet_clone(&pkt_copy), pts }); - if (plug_count == 0) packet_queue_ready.notify_all(); + if (plug_count == 0) + packet_queue_ready.notify_all(); } else if (plug_count > 0) { packet_queue.push_back(QueuedPacket{ av_packet_clone(&pkt_copy), pts }); } else { diff --git a/player.cpp b/player.cpp index b3cc769..dc619f4 100644 --- a/player.cpp +++ b/player.cpp @@ -1,13 +1,4 @@ -#include -#include -#include -#include -#include -#include - -#include - -#include +#include "player.h" #include "clip_list.h" #include "context.h" @@ -16,10 +7,18 @@ #include "httpd.h" #include "jpeg_frame_view.h" #include "mux.h" -#include "player.h" #include "timebase.h" #include "video_stream.h" +#include +#include +#include +#include +#include +#include +#include +#include + using namespace std; using namespace std::chrono; @@ -45,7 +44,7 @@ void Player::thread_func(bool also_output_to_stream) video_stream.reset(new VideoStream); video_stream->start(); } - + check_error(); constexpr double output_framerate = 60000.0 / 1001.0; // FIXME: make configurable @@ -61,7 +60,7 @@ void Player::thread_func(bool also_output_to_stream) // Wait until we're supposed to play something. { unique_lock lock(queue_state_mu); - clip_ready = new_clip_changed.wait_for(lock, milliseconds(100), [this]{ + clip_ready = new_clip_changed.wait_for(lock, milliseconds(100), [this] { return new_clip_ready && current_clip.pts_in != -1; }); new_clip_ready = false; @@ -331,7 +330,7 @@ void Player::play_clip(const Clip &clip, unsigned stream_idx) void Player::override_angle(unsigned stream_idx) { - // Corner case: If a new clip is waiting to be played, change its stream and then we're done. + // Corner case: If a new clip is waiting to be played, change its stream and then we're done. { unique_lock lock(queue_state_mu); if (new_clip_ready) { @@ -362,7 +361,7 @@ void Player::override_angle(unsigned stream_idx) } pts_out = current_clip.pts_out; } - + lock_guard lock(frame_mu); auto it = upper_bound(frames[stream_idx].begin(), frames[stream_idx].end(), pts_out); if (it == frames[stream_idx].end()) { diff --git a/ref_counted_gl_sync.h b/ref_counted_gl_sync.h index 8b6db68..5604e9e 100644 --- a/ref_counted_gl_sync.h +++ b/ref_counted_gl_sync.h @@ -16,7 +16,7 @@ class RefCountedGLsync : public RefCountedGLsyncBase { public: RefCountedGLsync() {} - RefCountedGLsync(GLenum condition, GLbitfield flags) + RefCountedGLsync(GLenum condition, GLbitfield flags) : RefCountedGLsyncBase(locked_glFenceSync(condition, flags), glDeleteSync) {} private: diff --git a/util.cpp b/util.cpp index 3701d62..061408d 100644 --- a/util.cpp +++ b/util.cpp @@ -1,9 +1,8 @@ -#include -#include +#include "util.h" +#include #include - -#include "util.h" +#include using namespace std; diff --git a/util.h b/util.h index 91ed0a2..4a0aed8 100644 --- a/util.h +++ b/util.h @@ -1,10 +1,10 @@ #ifndef _UTIL_H #define _UTIL_H 1 -#include -#include #include +#include #include +#include struct Vec2 { float du, dv; @@ -22,29 +22,37 @@ inline void flow2rgb(float du, float dv, uint8_t *rr, uint8_t *gg, uint8_t *bb) { float angle = atan2(dv, du); float magnitude = std::min(hypot(du, dv) / 20.0, 1.0); - + // HSV to RGB (from Wikipedia). Saturation is 1. float c = magnitude; float h = (angle + M_PI) * 6.0 / (2.0 * M_PI); float X = c * (1.0 - fabs(fmod(h, 2.0) - 1.0)); float r = 0.0f, g = 0.0f, b = 0.0f; if (h <= 1.0f) { - r = c; g = X; + r = c; + g = X; } else if (h <= 2.0f) { - r = X; g = c; + r = X; + g = c; } else if (h <= 3.0f) { - g = c; b = X; + g = c; + b = X; } else if (h <= 4.0f) { - g = X; b = c; + g = X; + b = c; } else if (h <= 5.0f) { - r = X; b = c; + r = X; + b = c; } else if (h <= 6.0f) { - r = c; b = X; + r = c; + b = X; } else { // h is NaN, so black is fine. } float m = magnitude - c; - r += m; g += m; b += m; + r += m; + g += m; + b += m; r = std::max(std::min(r, 1.0f), 0.0f); g = std::max(std::min(g, 1.0f), 0.0f); b = std::max(std::min(b, 1.0f), 0.0f); diff --git a/vaapi_jpeg_decoder.cpp b/vaapi_jpeg_decoder.cpp index b6f9c50..70b5f37 100644 --- a/vaapi_jpeg_decoder.cpp +++ b/vaapi_jpeg_decoder.cpp @@ -1,33 +1,32 @@ #include "vaapi_jpeg_decoder.h" +#include "jpeg_frame.h" +#include "memcpy_interleaved.h" + #include #include #include #include #include #include +#include +#include #include #include #include +#include #include #include #include #include -#include -#include -#include - -#include "jpeg_frame.h" -#include "memcpy_interleaved.h" - using namespace std; static unique_ptr va_dpy; static VAConfigID config_id; static VAImageFormat uyvy_format; bool vaapi_jpeg_decoding_usable = false; - + struct VAResources { unsigned width, height; VASurfaceID surface; @@ -108,7 +107,8 @@ class ReleaseVAResources { public: ReleaseVAResources(const VAResources &resources) : resources(resources) {} - ~ReleaseVAResources() { + ~ReleaseVAResources() + { if (!committed) { release_va_resources(resources); } @@ -170,7 +170,8 @@ unique_ptr try_open_va(const string &va_display, string *e { unique_ptr va_dpy = va_open_display(va_display); if (va_dpy == nullptr) { - if (error) *error = "Opening VA display failed"; + if (error) + *error = "Opening VA display failed"; return nullptr; } int major_ver, minor_ver; @@ -178,14 +179,16 @@ unique_ptr try_open_va(const string &va_display, string *e if (va_status != VA_STATUS_SUCCESS) { char buf[256]; snprintf(buf, sizeof(buf), "vaInitialize() failed with status %d\n", va_status); - if (error != nullptr) *error = buf; + if (error != nullptr) + *error = buf; return nullptr; } int num_entrypoints = vaMaxNumEntrypoints(va_dpy->va_dpy); unique_ptr entrypoints(new VAEntrypoint[num_entrypoints]); if (entrypoints == nullptr) { - if (error != nullptr) *error = "Failed to allocate memory for VA entry points"; + if (error != nullptr) + *error = "Failed to allocate memory for VA entry points"; return nullptr; } @@ -199,7 +202,8 @@ unique_ptr try_open_va(const string &va_display, string *e return va_dpy; } - if (error != nullptr) *error = "Can't find VAEntrypointVLD for the JPEG profile"; + if (error != nullptr) + *error = "Can't find VAEntrypointVLD for the JPEG profile"; return nullptr; } @@ -422,7 +426,7 @@ shared_ptr decode_jpeg_vaapi(const string &filename) memset(&parms, 0, sizeof(parms)); parms.slice_data_size = str.size(); parms.slice_data_offset = 0; - parms.slice_data_flag = VA_SLICE_DATA_FLAG_ALL; + parms.slice_data_flag = VA_SLICE_DATA_FLAG_ALL; parms.slice_horizontal_position = 0; parms.slice_vertical_position = 0; for (int component_idx = 0; component_idx < dinfo.num_components; ++component_idx) { @@ -431,7 +435,7 @@ shared_ptr decode_jpeg_vaapi(const string &filename) parms.components[component_idx].dc_table_selector = comp->dc_tbl_no; parms.components[component_idx].ac_table_selector = comp->ac_tbl_no; if (parms.components[component_idx].dc_table_selector > 1 || - parms.components[component_idx].ac_table_selector > 1) { + parms.components[component_idx].ac_table_selector > 1) { fprintf(stderr, "Uses too many Huffman tables\n"); return nullptr; } diff --git a/vaapi_jpeg_decoder.h b/vaapi_jpeg_decoder.h index 4ab957e..2009a56 100644 --- a/vaapi_jpeg_decoder.h +++ b/vaapi_jpeg_decoder.h @@ -2,13 +2,12 @@ #define _VAAPI_JPEG_DECODER_H 1 #include -#include - -#include #include +#include +#include struct Frame; - + struct VADisplayWithCleanup { ~VADisplayWithCleanup(); @@ -23,5 +22,5 @@ void init_jpeg_vaapi(); std::shared_ptr decode_jpeg_vaapi(const std::string &filename); extern bool vaapi_jpeg_decoding_usable; - + #endif // !defined(_VAAPI_JPEG_DECODER_H) diff --git a/video_stream.cpp b/video_stream.cpp index 39b5b6c..e89839a 100644 --- a/video_stream.cpp +++ b/video_stream.cpp @@ -5,9 +5,6 @@ extern "C" { #include } -#include -#include - #include "chroma_subsampler.h" #include "context.h" #include "flow.h" @@ -20,6 +17,8 @@ extern "C" { #include "ycbcr_converter.h" #include +#include +#include using namespace std; @@ -134,8 +133,8 @@ vector encode_jpeg(const uint8_t *y_data, const uint8_t *cb_data, const for (unsigned y = 0; y < height; y += 8) { for (unsigned yy = 0; yy < 8; ++yy) { yptr[yy] = const_cast(&y_data[(y + yy) * width]); - cbptr[yy] = const_cast(&cb_data[(y + yy) * width/2]); - crptr[yy] = const_cast(&cr_data[(y + yy) * width/2]); + cbptr[yy] = const_cast(&cb_data[(y + yy) * width / 2]); + crptr[yy] = const_cast(&cr_data[(y + yy) * width / 2]); } jpeg_write_raw_data(&cinfo, data, /*num_lines=*/8); @@ -217,7 +216,7 @@ VideoStream::VideoStream() check_error(); glNamedBufferStorage(resource.pbo, width * height * 4, nullptr, GL_MAP_READ_BIT | GL_MAP_PERSISTENT_BIT); check_error(); - resource.pbo_contents = glMapNamedBufferRange(resource.pbo, 0, width * height * 4, GL_MAP_READ_BIT | GL_MAP_PERSISTENT_BIT); + resource.pbo_contents = glMapNamedBufferRange(resource.pbo, 0, width * height * 4, GL_MAP_READ_BIT | GL_MAP_PERSISTENT_BIT); interpolate_resources.push_back(resource); } @@ -276,7 +275,7 @@ void VideoStream::schedule_original_frame(int64_t output_pts, unsigned stream_id qf.type = QueuedFrame::ORIGINAL; qf.output_pts = output_pts; qf.stream_idx = stream_idx; - qf.input_first_pts = input_pts; + qf.input_first_pts = input_pts; unique_lock lock(queue_lock); frame_queue.push_back(qf); @@ -437,7 +436,6 @@ void VideoStream::schedule_interpolated_frame(int64_t output_pts, unsigned strea chroma_subsampler->subsample_chroma(qf.cbcr_tex, 1280, 720, resources.cb_tex, resources.cr_tex); } - // We could have released qf.flow_tex here, but to make sure we don't cause a stall // when trying to reuse it for the next frame, we can just as well hold on to it // and release it only when the readback is done. @@ -618,4 +616,3 @@ int VideoStream::write_packet2(uint8_t *buf, int buf_size, AVIODataMarkerType ty } return buf_size; } - diff --git a/video_stream.h b/video_stream.h index 8ac3bcf..2bac2ad 100644 --- a/video_stream.h +++ b/video_stream.h @@ -1,25 +1,24 @@ #ifndef _VIDEO_STREAM_H #define _VIDEO_STREAM_H 1 -#include #include +#include extern "C" { #include } +#include "jpeg_frame_view.h" +#include "ref_counted_gl_sync.h" + #include #include -#include -#include -#include - #include #include #include - -#include "jpeg_frame_view.h" -#include "ref_counted_gl_sync.h" +#include +#include +#include class ChromaSubsampler; class DISComputeFlow; @@ -38,11 +37,10 @@ public: void schedule_original_frame(int64_t output_pts, unsigned stream_idx, int64_t input_pts); void schedule_faded_frame(int64_t output_pts, unsigned stream_idx, int64_t input_pts, int secondary_stream_idx, int64_t secondary_input_pts, float fade_alpha); - void schedule_interpolated_frame(int64_t output_pts, unsigned stream_idx, int64_t input_first_pts, int64_t input_second_pts, float alpha, int secondary_stream_idx = -1, int64_t secondary_inputs_pts = -1, float fade_alpha = 0.0f); // -1 = no secondary frame. + void schedule_interpolated_frame(int64_t output_pts, unsigned stream_idx, int64_t input_first_pts, int64_t input_second_pts, float alpha, int secondary_stream_idx = -1, int64_t secondary_inputs_pts = -1, float fade_alpha = 0.0f); // -1 = no secondary frame. void schedule_refresh_frame(int64_t output_pts); private: - void encode_thread_func(); std::thread encode_thread; @@ -72,7 +70,7 @@ private: int64_t output_pts; enum Type { ORIGINAL, FADED, INTERPOLATED, FADED_INTERPOLATED } type; unsigned stream_idx; - int64_t input_first_pts; // The only pts for original frames. + int64_t input_first_pts; // The only pts for original frames. // For fades only (including fades against interpolated frames). int secondary_stream_idx = -1; diff --git a/vis.cpp b/vis.cpp index 8ecf297..c67a0cc 100644 --- a/vis.cpp +++ b/vis.cpp @@ -1,11 +1,10 @@ // Visualize a .flo file. -#include -#include +#include "util.h" +#include #include - -#include "util.h" +#include using namespace std; diff --git a/ycbcr_converter.cpp b/ycbcr_converter.cpp index 40d1a9c..143c471 100644 --- a/ycbcr_converter.cpp +++ b/ycbcr_converter.cpp @@ -1,10 +1,10 @@ #include "ycbcr_converter.h" +#include "jpeg_frame.h" + #include #include -#include "jpeg_frame.h" - using namespace std; using namespace movit; diff --git a/ycbcr_converter.h b/ycbcr_converter.h index a7a6179..12dc61c 100644 --- a/ycbcr_converter.h +++ b/ycbcr_converter.h @@ -1,9 +1,8 @@ #ifndef _YCBCR_CONVERTER_H #define _YCBCR_CONVERTER_H 1 -#include - #include +#include #include namespace movit { @@ -58,4 +57,4 @@ private: // TODO: make private void setup_input_for_frame(std::shared_ptr frame, const movit::YCbCrFormat &ycbcr_format, movit::YCbCrInput *input); -#endif // !defined(_YCBCR_CONVERTER_H) +#endif // !defined(_YCBCR_CONVERTER_H) -- 2.39.2