X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavdevice%2Fgdigrab.c;h=c0692324725e2daa94f6dcd6a500a51d844941c3;hb=d92f38c179591a608390ffa9fee59c309142e79d;hp=ab08c1178848143bad92fbaba126fb40b2404525;hpb=41cd5af3250ef976f0a48adeb6dbccc9b2683e58;p=ffmpeg diff --git a/libavdevice/gdigrab.c b/libavdevice/gdigrab.c index ab08c117884..c0692324725 100644 --- a/libavdevice/gdigrab.c +++ b/libavdevice/gdigrab.c @@ -32,6 +32,7 @@ #include "libavformat/internal.h" #include "libavutil/opt.h" #include "libavutil/time.h" +#include "libavutil/wchar_filename.h" #include /** @@ -245,8 +246,20 @@ gdigrab_read_header(AVFormatContext *s1) int ret; if (!strncmp(filename, "title=", 6)) { + wchar_t *name_w = NULL; name = filename + 6; - hwnd = FindWindow(NULL, name); + + if(utf8towchar(name, &name_w)) { + ret = AVERROR(errno); + goto error; + } + if(!name_w) { + ret = AVERROR(EINVAL); + goto error; + } + + hwnd = FindWindowW(NULL, name_w); + av_freep(&name_w); if (!hwnd) { av_log(s1, AV_LOG_ERROR, "Can't find window '%s', aborting.\n", name); @@ -277,14 +290,20 @@ gdigrab_read_header(AVFormatContext *s1) } bpp = GetDeviceCaps(source_hdc, BITSPIXEL); + horzres = GetDeviceCaps(source_hdc, HORZRES); + vertres = GetDeviceCaps(source_hdc, VERTRES); + desktophorzres = GetDeviceCaps(source_hdc, DESKTOPHORZRES); + desktopvertres = GetDeviceCaps(source_hdc, DESKTOPVERTRES); + if (hwnd) { GetClientRect(hwnd, &virtual_rect); + /* window -- get the right height and width for scaling DPI */ + virtual_rect.left = virtual_rect.left * desktophorzres / horzres; + virtual_rect.right = virtual_rect.right * desktophorzres / horzres; + virtual_rect.top = virtual_rect.top * desktopvertres / vertres; + virtual_rect.bottom = virtual_rect.bottom * desktopvertres / vertres; } else { /* desktop -- get the right height and width for scaling DPI */ - horzres = GetDeviceCaps(source_hdc, HORZRES); - vertres = GetDeviceCaps(source_hdc, VERTRES); - desktophorzres = GetDeviceCaps(source_hdc, DESKTOPHORZRES); - desktopvertres = GetDeviceCaps(source_hdc, DESKTOPVERTRES); virtual_rect.left = GetSystemMetrics(SM_XVIRTUALSCREEN); virtual_rect.top = GetSystemMetrics(SM_YVIRTUALSCREEN); virtual_rect.right = (virtual_rect.left + GetSystemMetrics(SM_CXVIRTUALSCREEN)) * desktophorzres / horzres; @@ -388,7 +407,7 @@ gdigrab_read_header(AVFormatContext *s1) gdigrab->header_size = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + (bpp <= 8 ? (1 << bpp) : 0) * sizeof(RGBQUAD) /* palette size */; gdigrab->time_base = av_inv_q(gdigrab->framerate); - gdigrab->time_frame = av_gettime() / av_q2d(gdigrab->time_base); + gdigrab->time_frame = av_gettime_relative() / av_q2d(gdigrab->time_base); gdigrab->hwnd = hwnd; gdigrab->source_hdc = source_hdc; @@ -473,25 +492,26 @@ static void paint_mouse_pointer(AVFormatContext *s1, struct gdigrab *gdigrab) goto icon_error; } - pos.x = ci.ptScreenPos.x - clip_rect.left - info.xHotspot; - pos.y = ci.ptScreenPos.y - clip_rect.top - info.yHotspot; - if (hwnd) { RECT rect; if (GetWindowRect(hwnd, &rect)) { - pos.x -= rect.left; - pos.y -= rect.top; + pos.x = ci.ptScreenPos.x - clip_rect.left - info.xHotspot - rect.left; + pos.y = ci.ptScreenPos.y - clip_rect.top - info.yHotspot - rect.top; + + //that would keep the correct location of mouse with hidpi screens + pos.x = pos.x * desktophorzres / horzres; + pos.y = pos.y * desktopvertres / vertres; } else { CURSOR_ERROR("Couldn't get window rectangle"); goto icon_error; } + } else { + //that would keep the correct location of mouse with hidpi screens + pos.x = ci.ptScreenPos.x * desktophorzres / horzres - clip_rect.left - info.xHotspot; + pos.y = ci.ptScreenPos.y * desktopvertres / vertres - clip_rect.top - info.yHotspot; } - //that would keep the correct location of mouse with hidpi screens - pos.x = pos.x * desktophorzres / horzres; - pos.y = pos.y * desktopvertres / vertres; - av_log(s1, AV_LOG_DEBUG, "Cursor pos (%li,%li) -> (%li,%li)\n", ci.ptScreenPos.x, ci.ptScreenPos.y, pos.x, pos.y); @@ -544,7 +564,7 @@ static int gdigrab_read_packet(AVFormatContext *s1, AVPacket *pkt) /* wait based on the frame rate */ for (;;) { - curtime = av_gettime(); + curtime = av_gettime_relative(); delay = time_frame * av_q2d(time_base) - curtime; if (delay <= 0) { if (delay < INT64_C(-1000000) * av_q2d(time_base)) { @@ -561,7 +581,7 @@ static int gdigrab_read_packet(AVFormatContext *s1, AVPacket *pkt) if (av_new_packet(pkt, file_size) < 0) return AVERROR(ENOMEM); - pkt->pts = curtime; + pkt->pts = av_gettime(); /* Blit screen grab */ if (!BitBlt(dest_hdc, 0, 0, @@ -640,10 +660,11 @@ static const AVClass gdigrab_class = { .item_name = av_default_item_name, .option = options, .version = LIBAVUTIL_VERSION_INT, + .category = AV_CLASS_CATEGORY_DEVICE_VIDEO_INPUT, }; /** gdi grabber device demuxer declaration */ -AVInputFormat ff_gdigrab_demuxer = { +const AVInputFormat ff_gdigrab_demuxer = { .name = "gdigrab", .long_name = NULL_IF_CONFIG_SMALL("GDI API Windows frame grabber"), .priv_data_size = sizeof(struct gdigrab),