diff mbox

[FFmpeg-devel,1/2] avfilter/yadif_common: Add field type tracking to help bwdif

Message ID 20181110174641.28531-2-philipl@overt.org
State Accepted
Headers show

Commit Message

Philip Langdale Nov. 10, 2018, 5:46 p.m. UTC
The bwdif filter can use common yadif frame management if we track
when a field is the first or last field in a sequence. While this
information is not used by yadif, the added benefit of removing the
duplicated frame management logic makes it worth tracking this state
in the common code.
---
 libavfilter/yadif.h        | 14 ++++++++++++++
 libavfilter/yadif_common.c | 12 +++++++++---
 2 files changed, 23 insertions(+), 3 deletions(-)

Comments

Thomas Mundt Nov. 11, 2018, 5:12 p.m. UTC | #1
Am Sa., 10. Nov. 2018 um 18:47 Uhr schrieb Philip Langdale <
philipl@overt.org>:

> The bwdif filter can use common yadif frame management if we track
> when a field is the first or last field in a sequence. While this
> information is not used by yadif, the added benefit of removing the
> duplicated frame management logic makes it worth tracking this state
> in the common code.
> ---
>  libavfilter/yadif.h        | 14 ++++++++++++++
>  libavfilter/yadif_common.c | 12 +++++++++---
>  2 files changed, 23 insertions(+), 3 deletions(-)
>
> diff --git a/libavfilter/yadif.h b/libavfilter/yadif.h
> index 32d6f4a0d4..02240a4dac 100644
> --- a/libavfilter/yadif.h
> +++ b/libavfilter/yadif.h
> @@ -41,6 +41,12 @@ enum YADIFDeint {
>      YADIF_DEINT_INTERLACED = 1, ///< only deinterlace frames marked as
> interlaced
>  };
>
> +enum YADIFCurrentField {
> +    YADIF_FIELD_LAST   = -1, ///< The last field in a sequence
> +    YADIF_FIELD_FIRST  =  0, ///< The first field in a sequence
> +    YADIF_FIELD_NORMAL =  1, ///< A normal field in the middle of a
> sequence
> +};
>

These names are confusing for the bwdif code.
current_field == 0 means first or last field detected.
current_field == -1 means last frame detected.
Suggestion:
YADIF_FIELD_BACK_END = -1, /// <The last frame in a sequence
YADIF_FIELD_END = 0, /// <The first or last field in a sequence
YADIF_FIELD_NORMAL = 1, /// <A normal field in the middle of a sequence

+
>  typedef struct YADIFContext {
>      const AVClass *class;
>
> @@ -70,6 +76,14 @@ typedef struct YADIFContext {
>      int eof;
>      uint8_t *temp_line;
>      int temp_line_size;
> +
> +    /*
> +     * An algorithm that treats first and/or last fields in a sequence
> +     * differently can use this to detect those cases. It is the
> algorithm's
> +     * responsibility to set the value to YADIF_FIELD_NORMAL after
> processing
> +     * the first field.
> +     */
> +    int current_field;  ///< YADIFCurrentField
>  } YADIFContext;
>
>  void ff_yadif_init_x86(YADIFContext *yadif);
> diff --git a/libavfilter/yadif_common.c b/libavfilter/yadif_common.c
> index 19e8ac5281..213eca5396 100644
> --- a/libavfilter/yadif_common.c
> +++ b/libavfilter/yadif_common.c
> @@ -44,6 +44,8 @@ static int return_frame(AVFilterContext *ctx, int
> is_second)
>
>          av_frame_copy_props(yadif->out, yadif->cur);
>          yadif->out->interlaced_frame = 0;
> +        if (yadif->current_field == YADIF_FIELD_LAST)
> +            yadif->current_field = YADIF_FIELD_FIRST;
>      }
>
>      yadif->filter(ctx, yadif->out, tff ^ !is_second, tff);
> @@ -103,9 +105,12 @@ int ff_yadif_filter_frame(AVFilterLink *link, AVFrame
> *frame)
>      yadif->cur  = yadif->next;
>      yadif->next = frame;
>
> -    if (!yadif->cur &&
> -        !(yadif->cur = av_frame_clone(yadif->next)))
> -        return AVERROR(ENOMEM);
> +    if (!yadif->cur) {
> +        yadif->cur = av_frame_clone(yadif->next);
> +        if (!yadif->cur)
> +            return AVERROR(ENOMEM);
> +        yadif->current_field = YADIF_FIELD_FIRST;
> +    }
>
>      if (checkstride(yadif, yadif->next, yadif->cur)) {
>          av_log(ctx, AV_LOG_VERBOSE, "Reallocating frame due to differing
> stride\n");
> @@ -173,6 +178,7 @@ int ff_yadif_request_frame(AVFilterLink *link)
>          if (!next)
>              return AVERROR(ENOMEM);
>
> +        yadif->current_field = YADIF_FIELD_LAST;
>          next->pts = yadif->next->pts * 2 - yadif->cur->pts;
>
>          ff_yadif_filter_frame(ctx->inputs[0], next);
> --
> 2.19.1
>
diff mbox

Patch

diff --git a/libavfilter/yadif.h b/libavfilter/yadif.h
index 32d6f4a0d4..02240a4dac 100644
--- a/libavfilter/yadif.h
+++ b/libavfilter/yadif.h
@@ -41,6 +41,12 @@  enum YADIFDeint {
     YADIF_DEINT_INTERLACED = 1, ///< only deinterlace frames marked as interlaced
 };
 
+enum YADIFCurrentField {
+    YADIF_FIELD_LAST   = -1, ///< The last field in a sequence
+    YADIF_FIELD_FIRST  =  0, ///< The first field in a sequence
+    YADIF_FIELD_NORMAL =  1, ///< A normal field in the middle of a sequence
+};
+
 typedef struct YADIFContext {
     const AVClass *class;
 
@@ -70,6 +76,14 @@  typedef struct YADIFContext {
     int eof;
     uint8_t *temp_line;
     int temp_line_size;
+
+    /*
+     * An algorithm that treats first and/or last fields in a sequence
+     * differently can use this to detect those cases. It is the algorithm's
+     * responsibility to set the value to YADIF_FIELD_NORMAL after processing
+     * the first field.
+     */
+    int current_field;  ///< YADIFCurrentField
 } YADIFContext;
 
 void ff_yadif_init_x86(YADIFContext *yadif);
diff --git a/libavfilter/yadif_common.c b/libavfilter/yadif_common.c
index 19e8ac5281..213eca5396 100644
--- a/libavfilter/yadif_common.c
+++ b/libavfilter/yadif_common.c
@@ -44,6 +44,8 @@  static int return_frame(AVFilterContext *ctx, int is_second)
 
         av_frame_copy_props(yadif->out, yadif->cur);
         yadif->out->interlaced_frame = 0;
+        if (yadif->current_field == YADIF_FIELD_LAST)
+            yadif->current_field = YADIF_FIELD_FIRST;
     }
 
     yadif->filter(ctx, yadif->out, tff ^ !is_second, tff);
@@ -103,9 +105,12 @@  int ff_yadif_filter_frame(AVFilterLink *link, AVFrame *frame)
     yadif->cur  = yadif->next;
     yadif->next = frame;
 
-    if (!yadif->cur &&
-        !(yadif->cur = av_frame_clone(yadif->next)))
-        return AVERROR(ENOMEM);
+    if (!yadif->cur) {
+        yadif->cur = av_frame_clone(yadif->next);
+        if (!yadif->cur)
+            return AVERROR(ENOMEM);
+        yadif->current_field = YADIF_FIELD_FIRST;
+    }
 
     if (checkstride(yadif, yadif->next, yadif->cur)) {
         av_log(ctx, AV_LOG_VERBOSE, "Reallocating frame due to differing stride\n");
@@ -173,6 +178,7 @@  int ff_yadif_request_frame(AVFilterLink *link)
         if (!next)
             return AVERROR(ENOMEM);
 
+        yadif->current_field = YADIF_FIELD_LAST;
         next->pts = yadif->next->pts * 2 - yadif->cur->pts;
 
         ff_yadif_filter_frame(ctx->inputs[0], next);