Skip to content

Commit

Permalink
style(*): add .clang-format and format all files
Browse files Browse the repository at this point in the history
Signed-off-by: k4yt3x <i@k4yt3x.com>
  • Loading branch information
k4yt3x committed Dec 31, 2024
1 parent c95a6a4 commit a9b9a71
Show file tree
Hide file tree
Showing 28 changed files with 264 additions and 256 deletions.
8 changes: 8 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
BasedOnStyle: Chromium
AlignAfterOpenBracket: BlockIndent
AllowShortEnumsOnASingleLine: false
BinPackArguments: false
BreakStringLiterals: false
ColumnLimit: 100
IndentWidth: 4
InsertBraces: true
14 changes: 7 additions & 7 deletions include/libvideo2x/avutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@ extern "C" {
namespace video2x {
namespace avutils {

AVRational get_video_frame_rate(AVFormatContext *ifmt_ctx, int in_vstream_idx);
AVRational get_video_frame_rate(AVFormatContext* ifmt_ctx, int in_vstream_idx);

int64_t get_video_frame_count(AVFormatContext *ifmt_ctx, int in_vstream_idx);
int64_t get_video_frame_count(AVFormatContext* ifmt_ctx, int in_vstream_idx);

AVPixelFormat get_encoder_default_pix_fmt(const AVCodec *encoder, AVPixelFormat target_pix_fmt);
AVPixelFormat get_encoder_default_pix_fmt(const AVCodec* encoder, AVPixelFormat target_pix_fmt);

float get_frame_diff(AVFrame *frame1, AVFrame *frame2);
float get_frame_diff(AVFrame* frame1, AVFrame* frame2);

void av_bufferref_deleter(AVBufferRef *bufferref);
void av_bufferref_deleter(AVBufferRef* bufferref);

void av_frame_deleter(AVFrame *frame);
void av_frame_deleter(AVFrame* frame);

void av_packet_deleter(AVPacket *packet);
void av_packet_deleter(AVPacket* packet);

} // namespace avutils
} // namespace video2x
6 changes: 3 additions & 3 deletions include/libvideo2x/conversions.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ namespace video2x {
namespace conversions {

// Convert AVFrame to another pixel format
AVFrame *convert_avframe_pix_fmt(AVFrame *src_frame, AVPixelFormat pix_fmt);
AVFrame* convert_avframe_pix_fmt(AVFrame* src_frame, AVPixelFormat pix_fmt);

// Convert AVFrame to ncnn::Mat
ncnn::Mat avframe_to_ncnn_mat(AVFrame *frame);
ncnn::Mat avframe_to_ncnn_mat(AVFrame* frame);

// Convert ncnn::Mat to AVFrame
AVFrame *ncnn_mat_to_avframe(const ncnn::Mat &mat, AVPixelFormat pix_fmt);
AVFrame* ncnn_mat_to_avframe(const ncnn::Mat& mat, AVPixelFormat pix_fmt);

} // namespace conversions
} // namespace video2x
12 changes: 6 additions & 6 deletions include/libvideo2x/decoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@ class Decoder {
Decoder();
~Decoder();

int init(AVHWDeviceType hw_type, AVBufferRef *hw_ctx, const std::filesystem::path &in_fpath);
int init(AVHWDeviceType hw_type, AVBufferRef* hw_ctx, const std::filesystem::path& in_fpath);

AVFormatContext *get_format_context() const;
AVCodecContext *get_codec_context() const;
AVFormatContext* get_format_context() const;
AVCodecContext* get_codec_context() const;
int get_video_stream_index() const;

private:
static AVPixelFormat hw_pix_fmt_;
static AVPixelFormat get_hw_format(AVCodecContext *ctx, const AVPixelFormat *pix_fmts);
static AVPixelFormat get_hw_format(AVCodecContext* ctx, const AVPixelFormat* pix_fmts);

AVFormatContext *fmt_ctx_;
AVCodecContext *dec_ctx_;
AVFormatContext* fmt_ctx_;
AVCodecContext* dec_ctx_;
int in_vstream_idx_;
};

Expand Down
24 changes: 12 additions & 12 deletions include/libvideo2x/encoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,30 +54,30 @@ class Encoder {
~Encoder();

int init(
AVBufferRef *hw_ctx,
const std::filesystem::path &out_fpath,
AVFormatContext *ifmt_ctx,
AVCodecContext *dec_ctx,
EncoderConfig &enc_cfg,
AVBufferRef* hw_ctx,
const std::filesystem::path& out_fpath,
AVFormatContext* ifmt_ctx,
AVCodecContext* dec_ctx,
EncoderConfig& enc_cfg,
int width,
int height,
int frm_rate_mul,
int in_vstream_idx
);

int write_frame(AVFrame *frame, int64_t frame_idx);
int write_frame(AVFrame* frame, int64_t frame_idx);
int flush();

AVCodecContext *get_encoder_context() const;
AVFormatContext *get_format_context() const;
int *get_stream_map() const;
AVCodecContext* get_encoder_context() const;
AVFormatContext* get_format_context() const;
int* get_stream_map() const;
int get_output_video_stream_index() const;

private:
AVFormatContext *ofmt_ctx_;
AVCodecContext *enc_ctx_;
AVFormatContext* ofmt_ctx_;
AVCodecContext* enc_ctx_;
int out_vstream_idx_;
int *stream_map_;
int* stream_map_;
};

} // namespace encoder
Expand Down
20 changes: 10 additions & 10 deletions include/libvideo2x/filter_libplacebo.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class FilterLibplacebo : public Filter {
// Constructor
FilterLibplacebo(
uint32_t vk_device_index,
const std::filesystem::path &shader_path,
const std::filesystem::path& shader_path,
int width,
int height
);
Expand All @@ -28,30 +28,30 @@ class FilterLibplacebo : public Filter {
virtual ~FilterLibplacebo() override;

// Initializes the filter with decoder and encoder contexts
int init(AVCodecContext *dec_ctx, AVCodecContext *enc_ctx, AVBufferRef *hw_ctx) override;
int init(AVCodecContext* dec_ctx, AVCodecContext* enc_ctx, AVBufferRef* hw_ctx) override;

// Processes an input frame and returns the processed frame
int filter(AVFrame *in_frame, AVFrame **out_frame) override;
int filter(AVFrame* in_frame, AVFrame** out_frame) override;

// Flushes any remaining frames
int flush(std::vector<AVFrame *> &flushed_frames) override;
int flush(std::vector<AVFrame*>& flushed_frames) override;

// Returns the filter's type
ProcessorType get_processor_type() const override { return ProcessorType::Libplacebo; }

// Returns the filter's output dimensions
void get_output_dimensions(
const ProcessorConfig &proc_cfg,
const ProcessorConfig& proc_cfg,
int in_width,
int in_height,
int &out_width,
int &out_height
int& out_width,
int& out_height
) const override;

private:
AVFilterGraph *filter_graph_;
AVFilterContext *buffersrc_ctx_;
AVFilterContext *buffersink_ctx_;
AVFilterGraph* filter_graph_;
AVFilterContext* buffersrc_ctx_;
AVFilterContext* buffersink_ctx_;
uint32_t vk_device_index_;
const std::filesystem::path shader_path_;
int width_;
Expand Down
12 changes: 6 additions & 6 deletions include/libvideo2x/filter_realcugan.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,25 @@ class FilterRealcugan : public Filter {
virtual ~FilterRealcugan() override;

// Initializes the filter with decoder and encoder contexts
int init(AVCodecContext *dec_ctx, AVCodecContext *enc_ctx, AVBufferRef *hw_ctx) override;
int init(AVCodecContext* dec_ctx, AVCodecContext* enc_ctx, AVBufferRef* hw_ctx) override;

// Processes an input frame and returns the processed frame
int filter(AVFrame *in_frame, AVFrame **out_frame) override;
int filter(AVFrame* in_frame, AVFrame** out_frame) override;

// Returns the filter's type
ProcessorType get_processor_type() const override { return ProcessorType::RealCUGAN; }

// Returns the filter's output dimensions
void get_output_dimensions(
const ProcessorConfig &proc_cfg,
const ProcessorConfig& proc_cfg,
int in_width,
int in_height,
int &out_width,
int &out_height
int& out_width,
int& out_height
) const override;

private:
RealCUGAN *realcugan_;
RealCUGAN* realcugan_;
int gpuid_;
bool tta_mode_;
int scaling_factor_;
Expand Down
12 changes: 6 additions & 6 deletions include/libvideo2x/filter_realesrgan.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,25 @@ class FilterRealesrgan : public Filter {
virtual ~FilterRealesrgan() override;

// Initializes the filter with decoder and encoder contexts
int init(AVCodecContext *dec_ctx, AVCodecContext *enc_ctx, AVBufferRef *hw_ctx) override;
int init(AVCodecContext* dec_ctx, AVCodecContext* enc_ctx, AVBufferRef* hw_ctx) override;

// Processes an input frame and returns the processed frame
int filter(AVFrame *in_frame, AVFrame **out_frame) override;
int filter(AVFrame* in_frame, AVFrame** out_frame) override;

// Returns the filter's type
ProcessorType get_processor_type() const override { return ProcessorType::RealESRGAN; }

// Returns the filter's output dimensions
void get_output_dimensions(
const ProcessorConfig &proc_cfg,
const ProcessorConfig& proc_cfg,
int in_width,
int in_height,
int &out_width,
int &out_height
int& out_width,
int& out_height
) const override;

private:
RealESRGAN *realesrgan_;
RealESRGAN* realesrgan_;
int gpuid_;
bool tta_mode_;
int scaling_factor_;
Expand Down
10 changes: 5 additions & 5 deletions include/libvideo2x/fsutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ typedef std::wstring StringType;
typedef std::string StringType;
#endif

bool filepath_is_readable(const std::filesystem::path &path);
bool filepath_is_readable(const std::filesystem::path& path);

std::filesystem::path find_resource_file(const std::filesystem::path &path);
std::filesystem::path find_resource_file(const std::filesystem::path& path);

std::string path_to_u8string(const std::filesystem::path &path);
std::string path_to_u8string(const std::filesystem::path& path);

std::string wstring_to_u8string(const fsutils::StringType &wstr);
std::string wstring_to_u8string(const fsutils::StringType& wstr);

fsutils::StringType path_to_string_type(const std::filesystem::path &path);
fsutils::StringType path_to_string_type(const std::filesystem::path& path);

fsutils::StringType to_string_type(int value);

Expand Down
12 changes: 6 additions & 6 deletions include/libvideo2x/interpolator_rife.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,26 +27,26 @@ class InterpolatorRIFE : public Interpolator {
virtual ~InterpolatorRIFE() override;

// Initializes the interpolator with decoder and encoder contexts
int init(AVCodecContext *dec_ctx, AVCodecContext *enc_ctx, AVBufferRef *hw_ctx) override;
int init(AVCodecContext* dec_ctx, AVCodecContext* enc_ctx, AVBufferRef* hw_ctx) override;

// Processes an input frame and returns the processed frame
int interpolate(AVFrame *prev_frame, AVFrame *in_frame, AVFrame **out_frame, float time_step)
int interpolate(AVFrame* prev_frame, AVFrame* in_frame, AVFrame** out_frame, float time_step)
override;

// Returns the interpolator's type
ProcessorType get_processor_type() const override { return ProcessorType::RIFE; }

// Returns the interpolator's output dimensions
void get_output_dimensions(
const ProcessorConfig &proc_cfg,
const ProcessorConfig& proc_cfg,
int in_width,
int in_height,
int &out_width,
int &out_height
int& out_width,
int& out_height
) const override;

private:
RIFE *rife_;
RIFE* rife_;
int gpuid_;
bool tta_mode_;
bool tta_temporal_mode_;
Expand Down
10 changes: 5 additions & 5 deletions include/libvideo2x/libplacebo.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ namespace video2x {
namespace processors {

int init_libplacebo(
AVFilterGraph **filter_graph,
AVFilterContext **buffersrc_ctx,
AVFilterContext **buffersink_ctx,
AVCodecContext *dec_ctx,
AVFilterGraph** filter_graph,
AVFilterContext** buffersrc_ctx,
AVFilterContext** buffersink_ctx,
AVCodecContext* dec_ctx,
int out_width,
int out_height,
uint32_t vk_device_index,
const std::filesystem::path &shader_path
const std::filesystem::path& shader_path
);

} // namespace processors
Expand Down
34 changes: 17 additions & 17 deletions include/libvideo2x/libvideo2x.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,33 +51,33 @@ class LIBVIDEO2X_API VideoProcessor {

private:
[[nodiscard]] int process_frames(
decoder::Decoder &decoder,
encoder::Encoder &encoder,
std::unique_ptr<processors::Processor> &processor
decoder::Decoder& decoder,
encoder::Encoder& encoder,
std::unique_ptr<processors::Processor>& processor
);

[[nodiscard]] int write_frame(AVFrame *frame, encoder::Encoder &encoder);
[[nodiscard]] int write_frame(AVFrame* frame, encoder::Encoder& encoder);

[[nodiscard]] inline int write_raw_packet(
AVPacket *packet,
AVFormatContext *ifmt_ctx,
AVFormatContext *ofmt_ctx,
int *stream_map
AVPacket* packet,
AVFormatContext* ifmt_ctx,
AVFormatContext* ofmt_ctx,
int* stream_map
);

[[nodiscard]] inline int process_filtering(
std::unique_ptr<processors::Processor> &processor,
encoder::Encoder &encoder,
AVFrame *frame,
AVFrame *proc_frame
std::unique_ptr<processors::Processor>& processor,
encoder::Encoder& encoder,
AVFrame* frame,
AVFrame* proc_frame
);

[[nodiscard]] inline int process_interpolation(
std::unique_ptr<processors::Processor> &processor,
encoder::Encoder &encoder,
std::unique_ptr<AVFrame, decltype(&avutils::av_frame_deleter)> &prev_frame,
AVFrame *frame,
AVFrame *proc_frame
std::unique_ptr<processors::Processor>& processor,
encoder::Encoder& encoder,
std::unique_ptr<AVFrame, decltype(&avutils::av_frame_deleter)>& prev_frame,
AVFrame* frame,
AVFrame* proc_frame
);

processors::ProcessorConfig proc_cfg_;
Expand Down
14 changes: 7 additions & 7 deletions include/libvideo2x/logger_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,20 @@ namespace logger_manager {

class LIBVIDEO2X_API LoggerManager {
public:
LoggerManager(const LoggerManager &) = delete;
LoggerManager &operator=(const LoggerManager &) = delete;
LoggerManager(const LoggerManager&) = delete;
LoggerManager& operator=(const LoggerManager&) = delete;

static LoggerManager &instance();
static LoggerManager& instance();

std::shared_ptr<spdlog::logger> logger();

bool reconfigure_logger(
const std::string &logger_name,
const std::vector<spdlog::sink_ptr> &sinks,
const std::string &pattern = "%+"
const std::string& logger_name,
const std::vector<spdlog::sink_ptr>& sinks,
const std::string& pattern = "%+"
);

bool set_log_level(const std::string &level_str);
bool set_log_level(const std::string& level_str);

void hook_ffmpeg_logging();
void unhook_ffmpeg_logging();
Expand Down
Loading

0 comments on commit a9b9a71

Please sign in to comment.