diff mbox series

[FFmpeg-devel] lavfi/vsrc_ddagrab: add an option to avoid duplicating frames

Message ID 20240129190316.17750-1-anton@khirnov.net
State Accepted
Commit 0291b6f824c5cbae5d919559845df4e73dcc459a
Headers show
Series [FFmpeg-devel] lavfi/vsrc_ddagrab: add an option to avoid duplicating frames | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Anton Khirnov Jan. 29, 2024, 7:03 p.m. UTC
Tested-by: Jiří Eliášek, Misha Aizatulin
---
 doc/filters.texi           | 15 +++++++++++----
 libavfilter/vsrc_ddagrab.c |  7 ++++++-
 2 files changed, 17 insertions(+), 5 deletions(-)

Comments

Timo Rothenpieler Jan. 29, 2024, 7:40 p.m. UTC | #1
On 29.01.2024 20:03, Anton Khirnov wrote:
> Tested-by: Jiří Eliášek, Misha Aizatulin
> ---
>   doc/filters.texi           | 15 +++++++++++----
>   libavfilter/vsrc_ddagrab.c |  7 ++++++-
>   2 files changed, 17 insertions(+), 5 deletions(-)
> 
> diff --git a/doc/filters.texi b/doc/filters.texi
> index 1d70f4d934..b9b539acee 100644
> --- a/doc/filters.texi
> +++ b/doc/filters.texi
> @@ -28713,10 +28713,10 @@ it'll always be captured.
>   @item framerate
>   Maximum framerate at which the desktop will be captured - the interval between
>   successive frames will not be smaller than the inverse of the framerate. When
> -the desktop is not being updated often enough, the filter will duplicate
> -a previous frame. Note that there is no background buffering going on, so when
> -the filter is not polled often enough then the actual inter-frame interval may
> -be significantly larger.
> +@var{dup_frames} is true (the default) and the desktop is not being updated
> +often enough, the filter will duplicate a previous frame. Note that there is no
> +background buffering going on, so when the filter is not polled often enough
> +then the actual inter-frame interval may be significantly larger.
>   
>   Defaults to 30 FPS.
>   
> @@ -28749,6 +28749,13 @@ Passes all supported output formats to DDA and returns what DDA decides to use.
>   Filter initialization will fail if 10 bit format is requested but unavailable.
>   @end table
>   
> +@item dup_frames
> +When this option is set to true (the default), the filter will duplicate frames
> +when the desktop has not been updated in order to maintain approximately
> +constant target framerate. When this option is set to false, the filter will
> +wait for the desktop to be updated (inter-frame intervals may vary significantly
> +in this case).
> +
>   @end table
>   
>   @subsection Examples
> diff --git a/libavfilter/vsrc_ddagrab.c b/libavfilter/vsrc_ddagrab.c
> index 9c59faf53e..51e928d785 100644
> --- a/libavfilter/vsrc_ddagrab.c
> +++ b/libavfilter/vsrc_ddagrab.c
> @@ -101,6 +101,7 @@ typedef struct DdagrabContext {
>       int        out_fmt;
>       int        allow_fallback;
>       int        force_fmt;
> +    int        dup_frames;
>   } DdagrabContext;
>   
>   #define OFFSET(x) offsetof(DdagrabContext, x)
> @@ -124,6 +125,8 @@ static const AVOption ddagrab_options[] = {
>                                                      OFFSET(allow_fallback), AV_OPT_TYPE_BOOL,   { .i64 = 0    },       0,       1, FLAGS },
>       { "force_fmt",  "exclude BGRA from format list (experimental, discouraged by Microsoft)",
>                                                      OFFSET(force_fmt),  AV_OPT_TYPE_BOOL,       { .i64 = 0    },       0,       1, FLAGS },
> +    { "dup_frames", "duplicate frames to maintain framerate",
> +                                                   OFFSET(dup_frames), AV_OPT_TYPE_BOOL,       { .i64 = 1    },       0,       1, FLAGS },
>       { NULL }
>   };
>   
> @@ -1067,7 +1070,9 @@ static int ddagrab_request_frame(AVFilterLink *outlink)
>       now -= dda->first_pts;
>   
>       if (!dda->probed_texture) {
> -        ret = next_frame_internal(avctx, &cur_texture, 0);
> +        do {
> +            ret = next_frame_internal(avctx, &cur_texture, 0);
> +        } while (ret == AVERROR(EAGAIN) && !dda->dup_frames);
>       } else {
>           cur_texture = dda->probed_texture;
>           dda->probed_texture = NULL;

looks good to me
diff mbox series

Patch

diff --git a/doc/filters.texi b/doc/filters.texi
index 1d70f4d934..b9b539acee 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -28713,10 +28713,10 @@  it'll always be captured.
 @item framerate
 Maximum framerate at which the desktop will be captured - the interval between
 successive frames will not be smaller than the inverse of the framerate. When
-the desktop is not being updated often enough, the filter will duplicate
-a previous frame. Note that there is no background buffering going on, so when
-the filter is not polled often enough then the actual inter-frame interval may
-be significantly larger.
+@var{dup_frames} is true (the default) and the desktop is not being updated
+often enough, the filter will duplicate a previous frame. Note that there is no
+background buffering going on, so when the filter is not polled often enough
+then the actual inter-frame interval may be significantly larger.
 
 Defaults to 30 FPS.
 
@@ -28749,6 +28749,13 @@  Passes all supported output formats to DDA and returns what DDA decides to use.
 Filter initialization will fail if 10 bit format is requested but unavailable.
 @end table
 
+@item dup_frames
+When this option is set to true (the default), the filter will duplicate frames
+when the desktop has not been updated in order to maintain approximately
+constant target framerate. When this option is set to false, the filter will
+wait for the desktop to be updated (inter-frame intervals may vary significantly
+in this case).
+
 @end table
 
 @subsection Examples
diff --git a/libavfilter/vsrc_ddagrab.c b/libavfilter/vsrc_ddagrab.c
index 9c59faf53e..51e928d785 100644
--- a/libavfilter/vsrc_ddagrab.c
+++ b/libavfilter/vsrc_ddagrab.c
@@ -101,6 +101,7 @@  typedef struct DdagrabContext {
     int        out_fmt;
     int        allow_fallback;
     int        force_fmt;
+    int        dup_frames;
 } DdagrabContext;
 
 #define OFFSET(x) offsetof(DdagrabContext, x)
@@ -124,6 +125,8 @@  static const AVOption ddagrab_options[] = {
                                                    OFFSET(allow_fallback), AV_OPT_TYPE_BOOL,   { .i64 = 0    },       0,       1, FLAGS },
     { "force_fmt",  "exclude BGRA from format list (experimental, discouraged by Microsoft)",
                                                    OFFSET(force_fmt),  AV_OPT_TYPE_BOOL,       { .i64 = 0    },       0,       1, FLAGS },
+    { "dup_frames", "duplicate frames to maintain framerate",
+                                                   OFFSET(dup_frames), AV_OPT_TYPE_BOOL,       { .i64 = 1    },       0,       1, FLAGS },
     { NULL }
 };
 
@@ -1067,7 +1070,9 @@  static int ddagrab_request_frame(AVFilterLink *outlink)
     now -= dda->first_pts;
 
     if (!dda->probed_texture) {
-        ret = next_frame_internal(avctx, &cur_texture, 0);
+        do {
+            ret = next_frame_internal(avctx, &cur_texture, 0);
+        } while (ret == AVERROR(EAGAIN) && !dda->dup_frames);
     } else {
         cur_texture = dda->probed_texture;
         dda->probed_texture = NULL;