summaryrefslogtreecommitdiffstats
path: root/player/screenshot.c
diff options
context:
space:
mode:
authorChristoph Heinrich <christoph.heinrich@student.tugraz.at>2023-03-04 21:26:37 +0100
committerDudemanguy <random342@airmail.cc>2023-03-07 14:36:52 +0000
commit855b619cc9872a2919d071166d5b50d6a2a8a708 (patch)
tree4c171cb801fcfd91a69eb4a810efec3318de39de /player/screenshot.c
parent31160ff941e34e6a148ecac8539db3150835cdb2 (diff)
downloadmpv-855b619cc9872a2919d071166d5b50d6a2a8a708.tar.bz2
mpv-855b619cc9872a2919d071166d5b50d6a2a8a708.tar.xz
screenshot: fix segfault when taking a screenshot without video
Also a style change to exit early when nothing can be done anymore.
Diffstat (limited to 'player/screenshot.c')
-rw-r--r--player/screenshot.c54
1 files changed, 29 insertions, 25 deletions
diff --git a/player/screenshot.c b/player/screenshot.c
index 2d53a6616c..25790ef859 100644
--- a/player/screenshot.c
+++ b/player/screenshot.c
@@ -337,39 +337,43 @@ static struct mp_image *screenshot_get(struct MPContext *mpctx, int mode,
mode = 0;
bool need_add_subs = mode == MODE_SUBTITLES;
- if (mpctx->video_out && mpctx->video_out->config_ok) {
- vo_wait_frame(mpctx->video_out); // important for each-frame mode
-
- struct voctrl_screenshot ctrl = {
- .scaled = mode == MODE_FULL_WINDOW,
- .subs = mode != 0,
- .osd = mode == MODE_FULL_WINDOW,
- .high_bit_depth = high_depth && imgopts->high_bit_depth,
- .native_csp = image_writer_flexible_csp(imgopts),
- };
- if (!mpctx->opts->screenshot_sw)
- vo_control(mpctx->video_out, VOCTRL_SCREENSHOT, &ctrl);
- image = ctrl.res;
- if (image)
- need_add_subs = false;
-
- if (!image && mode != MODE_FULL_WINDOW)
- image = vo_get_current_frame(mpctx->video_out);
- if (!image) {
- vo_control(mpctx->video_out, VOCTRL_SCREENSHOT_WIN, &image);
- mode = MODE_FULL_WINDOW;
- }
+ if (!mpctx->video_out || !mpctx->video_out->config_ok)
+ return NULL;
+
+ vo_wait_frame(mpctx->video_out); // important for each-frame mode
+
+ struct voctrl_screenshot ctrl = {
+ .scaled = mode == MODE_FULL_WINDOW,
+ .subs = mode != 0,
+ .osd = mode == MODE_FULL_WINDOW,
+ .high_bit_depth = high_depth && imgopts->high_bit_depth,
+ .native_csp = image_writer_flexible_csp(imgopts),
+ };
+ if (!mpctx->opts->screenshot_sw)
+ vo_control(mpctx->video_out, VOCTRL_SCREENSHOT, &ctrl);
+ image = ctrl.res;
+ if (image)
+ need_add_subs = false;
+
+ if (!image && mode != MODE_FULL_WINDOW)
+ image = vo_get_current_frame(mpctx->video_out);
+ if (!image) {
+ vo_control(mpctx->video_out, VOCTRL_SCREENSHOT_WIN, &image);
+ mode = MODE_FULL_WINDOW;
}
+ if (!image)
+ return NULL;
- if (image && (image->fmt.flags & MP_IMGFLAG_HWACCEL)) {
+ if (image->fmt.flags & MP_IMGFLAG_HWACCEL) {
struct mp_image *nimage = mp_image_hw_download(image, NULL);
talloc_free(image);
+ if (!nimage)
+ return NULL;
image = nimage;
}
- if (image && need_add_subs)
+ if (need_add_subs)
add_subs(mpctx, image);
-
mp_image_params_guess_csp(&image->params);
return image;
}