Skip to content

Commit

Permalink
style(libvideo2x): improved resource cleaning and error handling
Browse files Browse the repository at this point in the history
Signed-off-by: k4yt3x <i@k4yt3x.com>
  • Loading branch information
k4yt3x committed Oct 29, 2024
1 parent 613b75f commit d50cf54
Show file tree
Hide file tree
Showing 8 changed files with 146 additions and 155 deletions.
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,15 @@ debian:
cmake --build /tmp/build --config Release --target install --parallel

clean:
rm -rf $(BINDIR)
rm -vrf $(BINDIR) data/output*.* heaptrack*.zst valgrind.log

test-realesrgan:
LD_LIBRARY_PATH=$(BINDIR) $(BINDIR)/video2x -i $(TEST_VIDEO) -o $(TEST_OUTPUT) \
-f realesrgan -r 4 -m realesr-animevideov3

test-libplacebo:
LD_LIBRARY_PATH=$(BINDIR) $(BINDIR)/video2x -i $(TEST_VIDEO) -o $(TEST_OUTPUT) \
-f libplacebo -w 1920 -h 1080 -s anime4k-mode-a
-f libplacebo -w 1920 -h 1080 -s anime4k-v4-a

memcheck-realesrgan:
LD_LIBRARY_PATH=$(BINDIR) valgrind \
Expand All @@ -94,7 +94,7 @@ memcheck-libplacebo:
--verbose --log-file="valgrind.log" \
$(BINDIR)/video2x \
-i $(TEST_VIDEO) -o $(TEST_OUTPUT) \
-f libplacebo -w 1920 -h 1080 -s anime4k-mode-a \
-f libplacebo -w 1920 -h 1080 -s anime4k-v4-a \
-p veryfast -b 1000000 -q 30

heaptrack-realesrgan:
Expand All @@ -108,5 +108,5 @@ heaptrack-libplacebo:
LD_LIBRARY_PATH=$(BINDIR) HEAPTRACK_ENABLE_DEBUGINFOD=1 heaptrack \
$(BINDIR)/video2x \
-i $(TEST_VIDEO) -o $(TEST_OUTPUT) \
-f libplacebo -w 1920 -h 1080 -s anime4k-mode-a \
-f libplacebo -w 1920 -h 1080 -s anime4k-v4-a \
-p veryfast -b 1000000 -q 30
2 changes: 1 addition & 1 deletion include/libvideo2x/encoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ int init_encoder(
int **stream_map
);

int encode_and_write_frame(
int write_frame(
AVFrame *frame,
AVCodecContext *enc_ctx,
AVFormatContext *ofmt_ctx,
Expand Down
2 changes: 1 addition & 1 deletion include/libvideo2x/filter.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Filter {
virtual ~Filter() = default;
virtual int init(AVCodecContext *dec_ctx, AVCodecContext *enc_ctx, AVBufferRef *hw_ctx) = 0;
virtual int process_frame(AVFrame *in_frame, AVFrame **out_frame) = 0;
virtual int flush(std::vector<AVFrame *> &flushed_frames) { return 0; }
virtual int flush(std::vector<AVFrame *> &_) { return 0; }
};

#endif // FILTER_H
2 changes: 1 addition & 1 deletion src/encoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ int init_encoder(
return 0;
}

int encode_and_write_frame(
int write_frame(
AVFrame *frame,
AVCodecContext *enc_ctx,
AVFormatContext *ofmt_ctx,
Expand Down
2 changes: 1 addition & 1 deletion src/getopt.c
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ int getopt_long(
return (-1);
}
if ((has_equal = strchr(current_argv, '=')) != NULL) {
current_argv_len = has_equal - current_argv;
current_argv_len = (size_t)(has_equal - current_argv);
has_equal++;
} else {
current_argv_len = strlen(current_argv);
Expand Down
1 change: 1 addition & 0 deletions src/libplacebo_filter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ int LibplaceboFilter::process_frame(AVFrame *in_frame, AVFrame **out_frame) {
ret = av_buffersrc_add_frame(buffersrc_ctx, in_frame);
if (ret < 0) {
spdlog::error("Error while feeding the filter graph");
av_frame_free(out_frame);
return ret;
}

Expand Down
Loading

0 comments on commit d50cf54

Please sign in to comment.