This makes an empty list mean 'all formats supported'. This will simplify some 
things for the format negotiation later on. Before the patch, returning an 
empty list in query_formats() would simply mean no format supported, which is 
non-sensical. This way a lot of unnecessary merging of 'all formats' lists is 
avoided. 


-- 
Mina
From 46347d6ded4272430a386696065af5a6f9993abb Mon Sep 17 00:00:00 2001
From: Mina Nagy Zaki <[email protected]>
Date: Tue, 7 Jun 2011 17:42:32 +0300
Subject: [PATCH 1/2] lavfi: Make avfilter_make_format_list handle NULL lists.

---
 libavfilter/avfilter.h |    3 ++-
 libavfilter/formats.c  |   13 ++++++++-----
 2 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/libavfilter/avfilter.h b/libavfilter/avfilter.h
index 9b1ea2d..0375a38 100644
--- a/libavfilter/avfilter.h
+++ b/libavfilter/avfilter.h
@@ -233,7 +233,8 @@ typedef struct AVFilterFormats {
  * Create a list of supported formats. This is intended for use in
  * AVFilter->query_formats().
  *
- * @param fmts list of media formats, terminated by -1
+ * @param fmts list of media formats, terminated by -1. If NULL an
+ *        empty list is created.
  * @return the format list, with no existing references
  */
 AVFilterFormats *avfilter_make_format_list(const int *fmts);
diff --git a/libavfilter/formats.c b/libavfilter/formats.c
index 101ef09..ec7fca3 100644
--- a/libavfilter/formats.c
+++ b/libavfilter/formats.c
@@ -73,15 +73,18 @@ AVFilterFormats *avfilter_merge_formats(AVFilterFormats *a, AVFilterFormats *b)
 AVFilterFormats *avfilter_make_format_list(const int *fmts)
 {
     AVFilterFormats *formats;
-    int count;
+    int count = 0;
 
-    for (count = 0; fmts[count] != -1; count++)
-        ;
+    if (fmts)
+        for (count = 0; fmts[count] != -1; count++)
+            ;
 
     formats               = av_mallocz(sizeof(AVFilterFormats));
-    formats->formats      = av_malloc(sizeof(*formats->formats) * count);
     formats->format_count = count;
-    memcpy(formats->formats, fmts, sizeof(*formats->formats) * count);
+    if (count) {
+        formats->formats  = av_malloc(sizeof(*formats->formats) * count);
+        memcpy(formats->formats, fmts, sizeof(*formats->formats) * count);
+    }
 
     return formats;
 }
-- 
1.7.4.4

From 51d8dea811f2a267050d0ffa9e6521b642da363e Mon Sep 17 00:00:00 2001
From: Mina Nagy Zaki <[email protected]>
Date: Tue, 7 Jun 2011 17:43:30 +0300
Subject: [PATCH 2/2] lavfi: Make an empty AVFilterFormats mean 'all formats'
 supported.

This makes avfilter_all_formats unnecessary, and so it was removed.
---
 libavfilter/af_aconvert.c |    4 ++--
 libavfilter/avfilter.h    |   10 +++++-----
 libavfilter/defaults.c    |    6 +-----
 libavfilter/formats.c     |   34 ++++++++++++++++++----------------
 4 files changed, 26 insertions(+), 28 deletions(-)

diff --git a/libavfilter/af_aconvert.c b/libavfilter/af_aconvert.c
index e13363d..e7b4787 100644
--- a/libavfilter/af_aconvert.c
+++ b/libavfilter/af_aconvert.c
@@ -122,11 +122,11 @@ static int query_formats(AVFilterContext *ctx)
 
     /* no output format specified */
     if (aconvert->out_sample_fmt == AV_SAMPLE_FMT_NONE) {
-        avfilter_set_common_formats(ctx, avfilter_all_formats(AVMEDIA_TYPE_AUDIO));
+        avfilter_set_common_formats(ctx, avfilter_make_format_list(NULL));
         return 0;
     }
 
-    avfilter_formats_ref(avfilter_all_formats(AVMEDIA_TYPE_AUDIO),
+    avfilter_formats_ref(avfilter_make_format_list(NULL),
                          &ctx->inputs[0]->out_formats);
     avfilter_add_format(&formats, aconvert->out_sample_fmt);
     avfilter_formats_ref(formats, &ctx->outputs[0]->in_formats);
diff --git a/libavfilter/avfilter.h b/libavfilter/avfilter.h
index 0375a38..8b15554 100644
--- a/libavfilter/avfilter.h
+++ b/libavfilter/avfilter.h
@@ -250,17 +250,15 @@ AVFilterFormats *avfilter_make_format_list(const int *fmts);
 int avfilter_add_format(AVFilterFormats **avff, int fmt);
 
 /**
- * Return a list of all formats supported by FFmpeg for the given media type.
- */
-AVFilterFormats *avfilter_all_formats(enum AVMediaType type);
-
-/**
  * Return a format list which contains the intersection of the formats of
  * a and b. Also, all the references of a, all the references of b, and
  * a and b themselves will be deallocated.
  *
  * If a and b do not share any common formats, neither is modified, and NULL
  * is returned.
+ *
+ * If a or b is empty, the non-empty list is returned, with references
+ * modified.
  */
 AVFilterFormats *avfilter_merge_formats(AVFilterFormats *a, AVFilterFormats *b);
 
@@ -595,6 +593,8 @@ struct AVFilterLink {
      * Lists of formats supported by the input and output filters respectively.
      * These lists are used for negotiating the format to actually be used,
      * which will be loaded into the format member, above, when chosen.
+     *
+     * An empty list indicates that all formats are supported.
      */
     AVFilterFormats *in_formats;
     AVFilterFormats *out_formats;
diff --git a/libavfilter/defaults.c b/libavfilter/defaults.c
index a0f8f9e..797a03f 100644
--- a/libavfilter/defaults.c
+++ b/libavfilter/defaults.c
@@ -231,11 +231,7 @@ void avfilter_set_common_formats(AVFilterContext *ctx, AVFilterFormats *formats)
 
 int avfilter_default_query_formats(AVFilterContext *ctx)
 {
-    enum AVMediaType type = ctx->inputs  && ctx->inputs [0] ? ctx->inputs [0]->type :
-                            ctx->outputs && ctx->outputs[0] ? ctx->outputs[0]->type :
-                            AVMEDIA_TYPE_VIDEO;
-
-    avfilter_set_common_formats(ctx, avfilter_all_formats(type));
+    avfilter_set_common_formats(ctx, avfilter_make_format_list(NULL));
     return 0;
 }
 
diff --git a/libavfilter/formats.c b/libavfilter/formats.c
index ec7fca3..788e7d0 100644
--- a/libavfilter/formats.c
+++ b/libavfilter/formats.c
@@ -41,9 +41,26 @@ static void merge_ref(AVFilterFormats *ret, AVFilterFormats *a)
 
 AVFilterFormats *avfilter_merge_formats(AVFilterFormats *a, AVFilterFormats *b)
 {
-    AVFilterFormats *ret;
+    AVFilterFormats *ret = NULL, ***refs = NULL;
     unsigned i, j, k = 0;
 
+    if (a == b) return a;
+
+    if (!b->format_count)
+        ret = a, a = b;
+    else if (!a->format_count)
+        ret = b;
+
+    if (ret) {
+        refs = av_realloc(ret->refs,
+            sizeof(AVFilterFormats**)*(ret->refcount+a->refcount));
+        if (!refs)
+            return NULL; //FIXME?
+        ret->refs = refs;
+        merge_ref(ret, a);
+        return ret;
+    }
+
     ret = av_mallocz(sizeof(AVFilterFormats));
 
     /* merge list of formats */
@@ -106,21 +123,6 @@ int avfilter_add_format(AVFilterFormats **avff, int fmt)
     return 0;
 }
 
-AVFilterFormats *avfilter_all_formats(enum AVMediaType type)
-{
-    AVFilterFormats *ret = NULL;
-    int fmt;
-    int num_formats = type == AVMEDIA_TYPE_VIDEO ? PIX_FMT_NB    :
-                      type == AVMEDIA_TYPE_AUDIO ? AV_SAMPLE_FMT_NB : 0;
-
-    for (fmt = 0; fmt < num_formats; fmt++)
-        if ((type != AVMEDIA_TYPE_VIDEO) ||
-            (type == AVMEDIA_TYPE_VIDEO && !(av_pix_fmt_descriptors[fmt].flags & PIX_FMT_HWACCEL)))
-            avfilter_add_format(&ret, fmt);
-
-    return ret;
-}
-
 void avfilter_formats_ref(AVFilterFormats *f, AVFilterFormats **ref)
 {
     *ref = f;
-- 
1.7.4.4

_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to