1
0
mirror of https://github.com/mpv-player/mpv synced 2025-03-19 18:05:21 +00:00

image_writer: mp_msg conversions

Adds an awkward mp_log argument for error messages.
This commit is contained in:
wm4 2013-12-21 17:59:38 +01:00
parent 38342436cd
commit 5beedf1967
4 changed files with 14 additions and 16 deletions

View File

@ -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);

View File

@ -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);
}

View File

@ -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);

View File

@ -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);