mirror of
https://github.com/k4yt3x/video2x.git
synced 2026-02-04 03:22:07 +08:00
style(*): add .clang-format and format all files
Signed-off-by: k4yt3x <i@k4yt3x.com>
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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_;
|
||||
};
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
);
|
||||
@@ -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_;
|
||||
|
||||
@@ -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_;
|
||||
|
||||
@@ -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_;
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -27,10 +27,10 @@ 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
|
||||
@@ -38,15 +38,15 @@ class InterpolatorRIFE : public Interpolator {
|
||||
|
||||
// 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_;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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_;
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -66,16 +66,16 @@ struct ProcessorConfig {
|
||||
class Processor {
|
||||
public:
|
||||
virtual ~Processor() = default;
|
||||
virtual int init(AVCodecContext *dec_ctx, AVCodecContext *enc_ctx, AVBufferRef *hw_ctx) = 0;
|
||||
virtual int flush(std::vector<AVFrame *> &) { return 0; }
|
||||
virtual int init(AVCodecContext* dec_ctx, AVCodecContext* enc_ctx, AVBufferRef* hw_ctx) = 0;
|
||||
virtual int flush(std::vector<AVFrame*>&) { return 0; }
|
||||
virtual ProcessingMode get_processing_mode() const = 0;
|
||||
virtual ProcessorType get_processor_type() const = 0;
|
||||
virtual void get_output_dimensions(
|
||||
const ProcessorConfig &proc_cfg,
|
||||
const ProcessorConfig& proc_cfg,
|
||||
int in_width,
|
||||
int in_height,
|
||||
int &width,
|
||||
int &height
|
||||
int& width,
|
||||
int& height
|
||||
) const = 0;
|
||||
};
|
||||
|
||||
@@ -83,7 +83,7 @@ class Processor {
|
||||
class Filter : public Processor {
|
||||
public:
|
||||
ProcessingMode get_processing_mode() const override { return ProcessingMode::Filter; }
|
||||
virtual int filter(AVFrame *in_frame, AVFrame **out_frame) = 0;
|
||||
virtual int filter(AVFrame* in_frame, AVFrame** out_frame) = 0;
|
||||
};
|
||||
|
||||
// Abstract base class for interpolators
|
||||
@@ -91,7 +91,7 @@ class Interpolator : public Processor {
|
||||
public:
|
||||
ProcessingMode get_processing_mode() const override { return ProcessingMode::Interpolate; }
|
||||
virtual int
|
||||
interpolate(AVFrame *prev_frame, AVFrame *in_frame, AVFrame **out_frame, float time_step) = 0;
|
||||
interpolate(AVFrame* prev_frame, AVFrame* in_frame, AVFrame** out_frame, float time_step) = 0;
|
||||
};
|
||||
|
||||
} // namespace processors
|
||||
|
||||
@@ -12,17 +12,17 @@ namespace processors {
|
||||
// Processor Factory Class
|
||||
class ProcessorFactory {
|
||||
public:
|
||||
using Creator = std::function<std::unique_ptr<Processor>(const ProcessorConfig &, uint32_t)>;
|
||||
using Creator = std::function<std::unique_ptr<Processor>(const ProcessorConfig&, uint32_t)>;
|
||||
|
||||
// Singleton instance accessor
|
||||
static ProcessorFactory &instance();
|
||||
static ProcessorFactory& instance();
|
||||
|
||||
// Register a processor type with its creation function
|
||||
void register_processor(ProcessorType type, Creator creator);
|
||||
|
||||
// Create a processor instance based on configuration
|
||||
std::unique_ptr<Processor>
|
||||
create_processor(const ProcessorConfig &proc_cfg, uint32_t vk_device_index) const;
|
||||
create_processor(const ProcessorConfig& proc_cfg, uint32_t vk_device_index) const;
|
||||
|
||||
private:
|
||||
// Private constructor for Singleton
|
||||
@@ -32,7 +32,7 @@ class ProcessorFactory {
|
||||
std::unordered_map<ProcessorType, Creator> creators;
|
||||
|
||||
// Static initializer for default processors
|
||||
static void init_default_processors(ProcessorFactory &factory);
|
||||
static void init_default_processors(ProcessorFactory& factory);
|
||||
};
|
||||
|
||||
} // namespace processors
|
||||
|
||||
Reference in New Issue
Block a user