From 5beedf1967f93ad4edfb6d1dd2edf9f4660a5afe Mon Sep 17 00:00:00 2001 From: wm4 Date: Sat, 21 Dec 2013 17:59:38 +0100 Subject: image_writer: mp_msg conversions Adds an awkward mp_log argument for error messages. --- player/screenshot.c | 4 ++-- video/image_writer.c | 18 ++++++++---------- video/image_writer.h | 6 +++--- video/out/vo_image.c | 2 +- 4 files changed, 14 insertions(+), 16 deletions(-) diff --git a/player/screenshot.c b/player/screenshot.c index d2879051b0..70a85bc80b 100644 --- a/player/screenshot.c +++ b/player/screenshot.c @@ -301,7 +301,7 @@ static void screenshot_save(struct MPContext *mpctx, struct mp_image *image) char *filename = gen_fname(ctx, image_writer_file_ext(opts)); if (filename) { screenshot_msg(ctx, SMSG_OK, "Screenshot: '%s'", filename); - if (!write_image(image, opts, filename)) + if (!write_image(image, opts, filename, mpctx->log)) screenshot_msg(ctx, SMSG_ERR, "Error writing screenshot!"); talloc_free(filename); } @@ -354,7 +354,7 @@ void screenshot_to_file(struct MPContext *mpctx, const char *filename, int mode, goto end; } screenshot_msg(ctx, SMSG_OK, "Screenshot: '%s'", filename); - if (!write_image(image, &opts, filename)) + if (!write_image(image, &opts, filename, mpctx->log)) screenshot_msg(ctx, SMSG_ERR, "Error writing screenshot!"); talloc_free(image); diff --git a/video/image_writer.c b/video/image_writer.c index 98a691d51d..7e725fe729 100644 --- a/video/image_writer.c +++ b/video/image_writer.c @@ -74,6 +74,7 @@ const struct m_sub_options image_writer_conf = { }; struct image_writer_ctx { + struct mp_log *log; const struct image_writer_opts *opts; const struct img_writer *writer; }; @@ -113,8 +114,7 @@ static int write_lavc(struct image_writer_ctx *ctx, mp_image_t *image, FILE *fp) if (avcodec_open2(avctx, codec, NULL) < 0) { print_open_fail: - mp_msg(MSGT_CPLAYER, MSGL_INFO, "Could not open libavcodec encoder" - " for saving images\n"); + MP_ERR(ctx, "Could not open libavcodec encoder for saving images\n"); goto error_exit; } @@ -256,7 +256,7 @@ const char *image_writer_file_ext(const struct image_writer_opts *opts) } int write_image(struct mp_image *image, const struct image_writer_opts *opts, - const char *filename) + const char *filename, struct mp_log *log) { struct mp_image *allocated_image = NULL; struct image_writer_opts defs = image_writer_opts_defaults; @@ -268,7 +268,7 @@ int write_image(struct mp_image *image, const struct image_writer_opts *opts, opts = &defs; const struct img_writer *writer = get_writer(opts); - struct image_writer_ctx ctx = { opts, writer }; + struct image_writer_ctx ctx = { log, opts, writer }; int destfmt = IMGFMT_RGB24; if (writer->pixfmts) { @@ -296,14 +296,12 @@ int write_image(struct mp_image *image, const struct image_writer_opts *opts, FILE *fp = fopen(filename, "wb"); int success = 0; if (fp == NULL) { - mp_msg(MSGT_CPLAYER, MSGL_ERR, - "Error opening '%s' for writing!\n", filename); + mp_err(log, "Error opening '%s' for writing!\n", filename); } else { success = writer->write(&ctx, image, fp); success = !fclose(fp) && success; if (!success) - mp_msg(MSGT_CPLAYER, MSGL_ERR, "Error writing file '%s'!\n", - filename); + mp_err(log, "Error writing file '%s'!\n", filename); } talloc_free(allocated_image); @@ -311,9 +309,9 @@ int write_image(struct mp_image *image, const struct image_writer_opts *opts, return success; } -void dump_png(struct mp_image *image, const char *filename) +void dump_png(struct mp_image *image, const char *filename, struct mp_log *log) { struct image_writer_opts opts = image_writer_opts_defaults; opts.format = "png"; - write_image(image, &opts, filename); + write_image(image, &opts, filename, log); } diff --git a/video/image_writer.h b/video/image_writer.h index 4f5942edb5..2fce63065e 100644 --- a/video/image_writer.h +++ b/video/image_writer.h @@ -16,7 +16,7 @@ */ struct mp_image; -struct mp_csp_details; +struct mp_log; struct image_writer_opts { char *format; @@ -48,7 +48,7 @@ const char *image_writer_file_ext(const struct image_writer_opts *opts); * can be used to store snapshots of anamorphic video. */ int write_image(struct mp_image *image, const struct image_writer_opts *opts, - const char *filename); + const char *filename, struct mp_log *log); // Debugging helper. -void dump_png(struct mp_image *image, const char *filename); +void dump_png(struct mp_image *image, const char *filename, struct mp_log *log); diff --git a/video/out/vo_image.c b/video/out/vo_image.c index 2bbdbcd543..c99eae49b4 100644 --- a/video/out/vo_image.c +++ b/video/out/vo_image.c @@ -114,7 +114,7 @@ static void flip_page(struct vo *vo) filename = mp_path_join(t, bstr0(p->outdir), bstr0(filename)); MP_INFO(vo, "Saving %s\n", filename); - write_image(p->current, p->opts, filename); + write_image(p->current, p->opts, filename, vo->log); talloc_free(t); mp_image_unrefp(&p->current); -- cgit v1.2.3