[FFmpeg-devel] [PATCH] gdigrab: Allow capturing a window by its handle

2023-12-10 Thread Lena via ffmpeg-devel
x11grab can capture windows by their ID, but gdigrab can only capture 
windows by their names, internally calling FindWindowW to lookup its handle.


This patch simply allows the user to specify a window handle directly.
Signed-off-by: Lena 
---
 libavdevice/gdigrab.c | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/libavdevice/gdigrab.c b/libavdevice/gdigrab.c
index c069232472..05d3c0c929 100644
--- a/libavdevice/gdigrab.c
+++ b/libavdevice/gdigrab.c
@@ -273,9 +273,13 @@ gdigrab_read_header(AVFormatContext *s1)
 }
 } else if (!strcmp(filename, "desktop")) {
 hwnd = NULL;
+} else if (!strncmp(filename, "hwnd=", 5)) {
+name = filename + 5;
++hwnd = strtol(name, NULL, 0);
 } else {
 av_log(s1, AV_LOG_ERROR,
-   "Please use \"desktop\" or \"title=\" to 
specify your target.\n");
+   "Please use \"desktop\", \"title=\" or 
\"hwnd=\" to specify your target.\n");

 ret = AVERROR(EIO);
 goto error;
 }
--
2.43.0

___
ffmpeg-devel mailing list
[email protected]
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
[email protected] with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH] gdigrab: Allow capturing a window by its handle

2023-12-10 Thread Lena via ffmpeg-devel

I'm so sorry, will resend immediately.


Andreas Rheinhardt via ffmpeg-devel:


Lena via ffmpeg-devel:

x11grab can capture windows by their ID, but gdigrab can only capture
windows by their names, internally calling FindWindowW to lookup its
handle.

This patch simply allows the user to specify a window handle directly.
Signed-off-by: Lena 
---
  libavdevice/gdigrab.c | 6 +-
  1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/libavdevice/gdigrab.c b/libavdevice/gdigrab.c
index c069232472..05d3c0c929 100644
--- a/libavdevice/gdigrab.c
+++ b/libavdevice/gdigrab.c
@@ -273,9 +273,13 @@ gdigrab_read_header(AVFormatContext *s1)
  }
  } else if (!strcmp(filename, "desktop")) {
  hwnd = NULL;
+    } else if (!strncmp(filename, "hwnd=", 5)) {
+    name = filename + 5;
+    +    hwnd = strtol(name, NULL, 0);

This won't even compile due to the extra '+'.


  } else {
  av_log(s1, AV_LOG_ERROR,
-   "Please use \"desktop\" or \"title=\" to
specify your target.\n");
+   "Please use \"desktop\", \"title=\" or
\"hwnd=\" to specify your target.\n");
  ret = AVERROR(EIO);
  goto error;
  }

___
ffmpeg-devel mailing list
[email protected]
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
[email protected] with subject "unsubscribe".

___
ffmpeg-devel mailing list
[email protected]
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
[email protected] with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH] gdigrab: Allow capturing a window by its handle

2023-12-10 Thread Lena via ffmpeg-devel
x11grab can capture windows by their ID, but gdigrab can only capture windows 
by their names, internally calling FindWindowW to lookup its handle.

This patch simply allows the user to specify a window handle directly.
Signed-off-by: Lena 
---
 libavdevice/gdigrab.c | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/libavdevice/gdigrab.c b/libavdevice/gdigrab.c
index c069232472..05d3c0c929 100644
--- a/libavdevice/gdigrab.c
+++ b/libavdevice/gdigrab.c
@@ -273,9 +273,13 @@ gdigrab_read_header(AVFormatContext *s1)
 }
 } else if (!strcmp(filename, "desktop")) {
 hwnd = NULL;
+} else if (!strncmp(filename, "hwnd=", 5)) {
+name = filename + 5;
+
+hwnd = strtol(name, NULL, 0);
 } else {
 av_log(s1, AV_LOG_ERROR,
-   "Please use \"desktop\" or \"title=\" to specify 
your target.\n");
+   "Please use \"desktop\", \"title=\" or 
\"hwnd=\" to specify your target.\n");
 ret = AVERROR(EIO);
 goto error;
 }
-- 
2.43.0

___
ffmpeg-devel mailing list
[email protected]
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
[email protected] with subject "unsubscribe".


[FFmpeg-devel] [PATCH v2] gdigrab: Allow capturing a window by its handle

2023-12-12 Thread Lena via ffmpeg-devel
Added the change to the documentation and added error checking on `strtol`, 
according to the stdlib documentation.

The documentation for `strtol` says that on error, 0 is returned. This makes it 
impossible to specify a window handle of 0 (the whole desktop), but that case 
is already covered by the "desktop" input filename, so it should be fine.


x11grab can capture windows by their ID, but gdigrab can only capture windows 
by their names, internally calling FindWindowW to lookup its handle.

This patch simply allows the user to specify a window handle directly.
Signed-off-by: Lena 
---
 doc/indevs.texi   |  8 ++--
 libavdevice/gdigrab.c | 13 -
 2 files changed, 18 insertions(+), 3 deletions(-)

diff --git a/doc/indevs.texi b/doc/indevs.texi
index 863536a34d..6da0ccac62 100644
--- a/doc/indevs.texi
+++ b/doc/indevs.texi
@@ -722,7 +722,7 @@ Win32 GDI-based screen capture device.
 
 This device allows you to capture a region of the display on Windows.
 
-There are two options for the input filename:
+There are three options for the input filename:
 @example
 desktop
 @end example
@@ -730,9 +730,13 @@ or
 @example
 title=@var{window_title}
 @end example
+or
+@example
+hwnd=@var{window_hwnd}
+@end example
 
 The first option will capture the entire desktop, or a fixed region of the
-desktop. The second option will instead capture the contents of a single
+desktop. The second and third options will instead capture the contents of a 
single
 window, regardless of its position on the screen.
 
 For example, to grab the entire desktop using @command{ffmpeg}:
diff --git a/libavdevice/gdigrab.c b/libavdevice/gdigrab.c
index c069232472..f310d8f3d7 100644
--- a/libavdevice/gdigrab.c
+++ b/libavdevice/gdigrab.c
@@ -273,9 +273,20 @@ gdigrab_read_header(AVFormatContext *s1)
 }
 } else if (!strcmp(filename, "desktop")) {
 hwnd = NULL;
+} else if (!strncmp(filename, "hwnd=", 5)) {
+name = filename + 5;
+
+hwnd = strtol(name, NULL, 0);
+
+if (hwnd == NULL) {
+av_log(s1, AV_LOG_ERROR,
+   "Invalid window handle.\n");
+ret = AVERROR(EINVAL);
+goto error;
+}
 } else {
 av_log(s1, AV_LOG_ERROR,
-   "Please use \"desktop\" or \"title=\" to specify 
your target.\n");
+   "Please use \"desktop\", \"title=\" or 
\"hwnd=\" to specify your target.\n");
 ret = AVERROR(EIO);
 goto error;
 }
-- 
2.43.0

___
ffmpeg-devel mailing list
[email protected]
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
[email protected] with subject "unsubscribe".


[FFmpeg-devel] [PATCH v3] gdigrab: Allow capturing a window by its handle

2023-12-14 Thread Lena via ffmpeg-devel
Updated the wording of the documentation, and added error checking for strtol.

I looked at how other parts of the codebase check for errors on strtol and 
implemented it that way (iec61883, filter_units_bsf, etc).

As for checking if the string value is larger/smaller than a long, i don't 
think there's a need, as the documentation says it'd just get set to 
LONG_MIN/LONG_MAX and fail anyway.


x11grab can capture windows by their ID, but gdigrab can only capture windows 
by their names, internally calling FindWindowW to lookup its handle.

This patch simply allows the user to specify a window handle directly.
Signed-off-by: Lena 
---
 doc/indevs.texi   |  8 ++--
 libavdevice/gdigrab.c | 15 ++-
 2 files changed, 20 insertions(+), 3 deletions(-)

diff --git a/doc/indevs.texi b/doc/indevs.texi
index 863536a34d..a0c684f545 100644
--- a/doc/indevs.texi
+++ b/doc/indevs.texi
@@ -722,7 +722,7 @@ Win32 GDI-based screen capture device.
 
 This device allows you to capture a region of the display on Windows.
 
-There are two options for the input filename:
+Amongst options for the imput filenames are such elements as:
 @example
 desktop
 @end example
@@ -730,9 +730,13 @@ or
 @example
 title=@var{window_title}
 @end example
+or
+@example
+hwnd=@var{window_hwnd}
+@end example
 
 The first option will capture the entire desktop, or a fixed region of the
-desktop. The second option will instead capture the contents of a single
+desktop. The second and third options will instead capture the contents of a 
single
 window, regardless of its position on the screen.
 
 For example, to grab the entire desktop using @command{ffmpeg}:
diff --git a/libavdevice/gdigrab.c b/libavdevice/gdigrab.c
index c069232472..3153b6f711 100644
--- a/libavdevice/gdigrab.c
+++ b/libavdevice/gdigrab.c
@@ -273,9 +273,22 @@ gdigrab_read_header(AVFormatContext *s1)
 }
 } else if (!strcmp(filename, "desktop")) {
 hwnd = NULL;
+} else if (!strncmp(filename, "hwnd=", 5)) {
+name = filename + 5;
+char *p;
+
+hwnd = strtol(name, &p, 0);
+
+if (p == NULL || p == name || p[0] == '\0')
+{
+av_log(s1, AV_LOG_ERROR,
+   "Invalid window handle.\n");
+ret = AVERROR(EINVAL);
+goto error;
+}
 } else {
 av_log(s1, AV_LOG_ERROR,
-   "Please use \"desktop\" or \"title=\" to specify 
your target.\n");
+   "Please use \"desktop\", \"title=\" or 
\"hwnd=\" to specify your target.\n");
 ret = AVERROR(EIO);
 goto error;
 }
-- 
2.43.0

___
ffmpeg-devel mailing list
[email protected]
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
[email protected] with subject "unsubscribe".


[FFmpeg-devel] [PATCH v4] gdigrab: Allow capturing a window by its handle

2023-12-17 Thread Lena via ffmpeg-devel
Added more context in the error message and did a final test that it all works.

Thanks for the smooth patch submission process!


x11grab can capture windows by their ID, but gdigrab can only capture windows 
by their names, internally calling FindWindowW to lookup its handle.

This patch simply allows the user to specify a window handle directly.
Signed-off-by: Lena 
---
 doc/indevs.texi   |  8 ++--
 libavdevice/gdigrab.c | 15 ++-
 2 files changed, 20 insertions(+), 3 deletions(-)

diff --git a/doc/indevs.texi b/doc/indevs.texi
index 863536a34d..a0c684f545 100644
--- a/doc/indevs.texi
+++ b/doc/indevs.texi
@@ -722,7 +722,7 @@ Win32 GDI-based screen capture device.
 
 This device allows you to capture a region of the display on Windows.
 
-There are two options for the input filename:
+Amongst options for the imput filenames are such elements as:
 @example
 desktop
 @end example
@@ -730,9 +730,13 @@ or
 @example
 title=@var{window_title}
 @end example
+or
+@example
+hwnd=@var{window_hwnd}
+@end example
 
 The first option will capture the entire desktop, or a fixed region of the
-desktop. The second option will instead capture the contents of a single
+desktop. The second and third options will instead capture the contents of a 
single
 window, regardless of its position on the screen.
 
 For example, to grab the entire desktop using @command{ffmpeg}:
diff --git a/libavdevice/gdigrab.c b/libavdevice/gdigrab.c
index c069232472..aa909a9392 100644
--- a/libavdevice/gdigrab.c
+++ b/libavdevice/gdigrab.c
@@ -273,9 +273,22 @@ gdigrab_read_header(AVFormatContext *s1)
 }
 } else if (!strcmp(filename, "desktop")) {
 hwnd = NULL;
+} else if (!strncmp(filename, "hwnd=", 5)) {
+name = filename + 5;
+char *p;
+
+hwnd = strtol(name, &p, 0);
+
+if (p == NULL || p == name || p[0] == '\0')
+{
+av_log(s1, AV_LOG_ERROR,
+   "Invalid window handle '%s', must be an valid integer.\n", 
name);
+ret = AVERROR(EINVAL);
+goto error;
+}
 } else {
 av_log(s1, AV_LOG_ERROR,
-   "Please use \"desktop\" or \"title=\" to specify 
your target.\n");
+   "Please use \"desktop\", \"title=\" or 
\"hwnd=\" to specify your target.\n");
 ret = AVERROR(EIO);
 goto error;
 }
-- 
2.43.0

___
ffmpeg-devel mailing list
[email protected]
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
[email protected] with subject "unsubscribe".