summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2013-02-24 22:52:47 +0100
committerwm4 <wm4@nowhere>2013-02-26 01:55:52 +0100
commit90425522091ecd8aa1e91868e519c3ac62dad4f0 (patch)
tree19e3173e34f197c293fea6843f7ffe3572e6cca3
parentf47ead1509bd63785a0b6deb67e05e02b56fc474 (diff)
downloadmpv-90425522091ecd8aa1e91868e519c3ac62dad4f0.tar.bz2
mpv-90425522091ecd8aa1e91868e519c3ac62dad4f0.tar.xz
screenshot: show a message on each screenshot taken
The message reads: "Screenshot: filename", where the filename is what mpv passes to fopen(). It will also show error messages when saving the screenshot fails.
-rw-r--r--core/command.c3
-rw-r--r--core/screenshot.c53
-rw-r--r--core/screenshot.h4
3 files changed, 45 insertions, 15 deletions
diff --git a/core/command.c b/core/command.c
index cb6843eab4..8cd9ed07d1 100644
--- a/core/command.c
+++ b/core/command.c
@@ -2166,7 +2166,8 @@ void run_command(MPContext *mpctx, mp_cmd_t *cmd)
}
case MP_CMD_SCREENSHOT:
- screenshot_request(mpctx, cmd->args[0].v.i, cmd->args[1].v.i);
+ screenshot_request(mpctx, cmd->args[0].v.i, cmd->args[1].v.i,
+ !!(cmd->on_osd & MP_ON_OSD_MSG));
break;
case MP_CMD_RUN:
diff --git a/core/screenshot.c b/core/screenshot.c
index e5f15948e5..4f7a0dbcdd 100644
--- a/core/screenshot.c
+++ b/core/screenshot.c
@@ -30,6 +30,7 @@
#include "core/command.h"
#include "core/bstr.h"
#include "core/mp_msg.h"
+#include "core/mp_osd.h"
#include "core/path.h"
#include "video/mp_image.h"
#include "video/decode/dec_video.h"
@@ -47,7 +48,8 @@ typedef struct screenshot_ctx {
struct MPContext *mpctx;
int mode;
- int each_frame;
+ bool each_frame;
+ bool osd;
int frameno;
} screenshot_ctx;
@@ -61,6 +63,31 @@ void screenshot_init(struct MPContext *mpctx)
};
}
+#define SMSG_OK 0
+#define SMSG_ERR 1
+
+static void screenshot_msg(screenshot_ctx *ctx, int status, const char *msg,
+ ...) PRINTF_ATTRIBUTE(3,4);
+
+static void screenshot_msg(screenshot_ctx *ctx, int status, const char *msg,
+ ...)
+{
+ va_list ap;
+ char *s;
+
+ va_start(ap, msg);
+ s = talloc_vasprintf(NULL, msg, ap);
+ va_end(ap);
+
+ mp_msg(MSGT_CPLAYER, status == SMSG_ERR ? MSGL_ERR : MSGL_INFO, "%s\n", s);
+ if (ctx->osd) {
+ set_osd_tmsg(ctx->mpctx, OSD_MSG_TEXT, 1, ctx->mpctx->opts.osd_duration,
+ "%s", s);
+ }
+
+ talloc_free(s);
+}
+
static char *stripext(void *talloc_ctx, const char *s)
{
const char *end = strrchr(s, '.');
@@ -213,9 +240,9 @@ static char *gen_fname(screenshot_ctx *ctx, const char *file_ext)
&ctx->frameno);
if (!fname) {
- mp_msg(MSGT_CPLAYER, MSGL_ERR, "Invalid screenshot filename "
- "template! Fix or remove the --screenshot-template option."
- "\n");
+ screenshot_msg(ctx, SMSG_ERR, "Invalid screenshot filename "
+ "template! Fix or remove the --screenshot-template "
+ "option.");
return NULL;
}
@@ -223,8 +250,8 @@ static char *gen_fname(screenshot_ctx *ctx, const char *file_ext)
return fname;
if (sequence == prev_sequence) {
- mp_msg(MSGT_CPLAYER, MSGL_ERR, "Can't save screenshot, file '%s' "
- "already exists!\n", fname);
+ screenshot_msg(ctx, SMSG_ERR, "Can't save screenshot, file '%s' "
+ "already exists!", fname);
talloc_free(fname);
return NULL;
}
@@ -263,21 +290,21 @@ static void screenshot_save(struct MPContext *mpctx, struct mp_image *image,
char *filename = gen_fname(ctx, image_writer_file_ext(opts));
if (filename) {
- mp_msg(MSGT_CPLAYER, MSGL_INFO, "*** screenshot '%s' ***\n", filename);
+ screenshot_msg(ctx, SMSG_OK, "Screenshot: '%s'", filename);
if (!write_image(image, opts, filename))
- mp_msg(MSGT_CPLAYER, MSGL_ERR, "\nError writing screenshot!\n");
+ screenshot_msg(ctx, SMSG_ERR, "Error writing screenshot!");
talloc_free(filename);
}
talloc_free(image);
}
-void screenshot_request(struct MPContext *mpctx, int mode, bool each_frame)
+void screenshot_request(struct MPContext *mpctx, int mode, bool each_frame,
+ bool osd)
{
if (mpctx->video_out && mpctx->video_out->config_ok) {
screenshot_ctx *ctx = mpctx->screenshot_ctx;
-
if (mode == MODE_SUBTITLES && mpctx->osd->render_subs_in_filter)
mode = 0;
@@ -290,6 +317,7 @@ void screenshot_request(struct MPContext *mpctx, int mode, bool each_frame)
}
ctx->mode = mode;
+ ctx->osd = osd;
struct voctrl_screenshot_args args =
{ .full_window = (mode == MODE_FULL_WINDOW) };
@@ -305,8 +333,7 @@ void screenshot_request(struct MPContext *mpctx, int mode, bool each_frame)
mode = 0;
screenshot_save(mpctx, args.out_image, mode == MODE_SUBTITLES);
} else {
- mp_msg(MSGT_CPLAYER, MSGL_INFO,
- "Taking screenshot failed (need --vf=screenshot?)\n");
+ screenshot_msg(ctx, SMSG_ERR, "Taking screenshot failed.");
}
}
}
@@ -319,5 +346,5 @@ void screenshot_flip(struct MPContext *mpctx)
return;
ctx->each_frame = false;
- screenshot_request(mpctx, ctx->mode, true);
+ screenshot_request(mpctx, ctx->mode, true, ctx->osd);
}
diff --git a/core/screenshot.h b/core/screenshot.h
index 266077a107..916a875505 100644
--- a/core/screenshot.h
+++ b/core/screenshot.h
@@ -30,7 +30,9 @@ void screenshot_init(struct MPContext *mpctx);
// mode: 0: -, 1: save the actual output window contents, 2: with subtitles.
// each_frame: If set, this toggles per-frame screenshots, exactly like the
// screenshot slave command (MP_CMD_SCREENSHOT).
-void screenshot_request(struct MPContext *mpctx, int mode, bool each_frame);
+// osd: show status on OSD
+void screenshot_request(struct MPContext *mpctx, int mode, bool each_frame,
+ bool osd);
// Called by the playback core code when a new frame is displayed.
void screenshot_flip(struct MPContext *mpctx);