diff --git a/src/debug.cpp b/src/debug.cpp index 42976deda..c8b7b774a 100644 --- a/src/debug.cpp +++ b/src/debug.cpp @@ -304,7 +304,7 @@ void Logger::preinit(bool skip_repeated, int show_timestamps) } #ifdef DEBUG -void debug_file_dump(const char *key, void (*serialize)(void *data, FILE *), void *data) { +void debug_file_dump(const char *key, void (*serialize)(const void *data, FILE *), void *data) { const char *dump_file_val = get_commandline_param("debug-dump"); static thread_local unordered_map skip_map; if (dump_file_val == nullptr) { diff --git a/src/debug.h b/src/debug.h index f5e598a10..515e1fda2 100644 --- a/src/debug.h +++ b/src/debug.h @@ -72,7 +72,7 @@ extern "C" { void debug_dump(void*lp, int len); #ifdef DEBUG -void debug_file_dump(const char *key, void (*serialize)(void *data, FILE *), void *data); +void debug_file_dump(const char *key, void (*serialize)(const void *data, FILE *), void *data); #else #define debug_file_dump(key, serialize, data) (void) (key), (void) (serialize), (void) (data) #endif diff --git a/src/libavcodec_common.c b/src/libavcodec_common.c index 5e86ec0ea..b63e19486 100644 --- a/src/libavcodec_common.c +++ b/src/libavcodec_common.c @@ -2940,6 +2940,26 @@ struct SwsContext *getSwsContext(unsigned int SrcW, unsigned int SrcH, enum AVPi } #endif // defined HAVE_SWSCALE +/** + * Serializes (prints) AVFrame f to output file out + * + * @param f actual (AVFrame *) cast to (void *) + * @param out file stream to be written to + */ +void serialize_avframe(const void *f, FILE *out) { + const AVFrame *frame = f; + for (int comp = 0; comp < AV_NUM_DATA_POINTERS; ++comp) { + if (frame->data[comp] == NULL) { + break; + } + for (int y = 0; y < frame->height; ++y) { + if (fwrite(frame->data[comp] + y * frame->linesize[comp], frame->linesize[comp], 1, out) != 1) { + log_msg(LOG_LEVEL_ERROR, "%s fwrite error\n", __func__); + } + } + } +} + #pragma GCC diagnostic pop /* vi: set expandtab sw=8: */ diff --git a/src/libavcodec_common.h b/src/libavcodec_common.h index 639bab6b8..3252774ac 100644 --- a/src/libavcodec_common.h +++ b/src/libavcodec_common.h @@ -267,6 +267,8 @@ codec_t get_av_to_ug_pixfmt(enum AVPixelFormat av_pixfmt) ATTRIBUTE(const); enum AVPixelFormat get_ug_to_av_pixfmt(codec_t ug_codec) ATTRIBUTE(const); const struct uv_to_av_pixfmt *get_av_to_ug_pixfmts(void) ATTRIBUTE(const); +void serialize_avframe(const void *f, FILE *out); + #ifdef HAVE_SWSCALE struct SwsContext; struct SwsContext *getSwsContext(unsigned int SrcW, unsigned int SrcH, enum AVPixelFormat SrcFormat, unsigned int DstW, unsigned int DstH, enum AVPixelFormat DstFormat, int64_t Flags); diff --git a/src/video_compress/libavcodec.cpp b/src/video_compress/libavcodec.cpp index fa1d15f45..83135a364 100644 --- a/src/video_compress/libavcodec.cpp +++ b/src/video_compress/libavcodec.cpp @@ -1500,6 +1500,7 @@ static shared_ptr libavcodec_compress_tile(struct module *mod, shar } } + debug_file_dump("lavc-avframe", serialize_avframe, s->in_frame); AVFrame *frame = s->in_frame; #ifdef HWACC_VAAPI if(s->hwenc){ diff --git a/src/video_decompress/libavcodec.c b/src/video_decompress/libavcodec.c index fc9e67b2f..6f62ed193 100644 --- a/src/video_decompress/libavcodec.c +++ b/src/video_decompress/libavcodec.c @@ -707,18 +707,6 @@ static bool lavd_sws_convert_to_buffer(struct state_libavcodec_decompress_sws *s } #endif -static void serialize_avframe(void *f, FILE *out) { - AVFrame *frame = f; - for (int comp = 0; comp < AV_NUM_DATA_POINTERS; ++comp) { - if (frame->data[comp] == NULL) { - break; - } - for (int y = 0; y < frame->height; ++y) { - fwrite(frame->data[comp] + y * frame->linesize[comp], frame->linesize[comp], 1, out); - } - } -} - struct convert_task_data { av_to_uv_convert_p convert; unsigned char *out_data; @@ -778,7 +766,7 @@ static int change_pixfmt(AVFrame *frame, unsigned char *dst, int av_codec, codec int pitch, int rgb_shift[static restrict 3], struct state_libavcodec_decompress_sws *sws) { av_to_uv_convert_p convert = NULL; - debug_file_dump("lavd-uncompressed", serialize_avframe, frame); + debug_file_dump("lavd-avframe", serialize_avframe, frame); if (get_av_to_ug_pixfmt(av_codec) == out_codec) { if (!codec_is_planar(out_codec)) {