[FFmpeg-devel] [PATCH] lavfi: add audio channel packing negotiation fields

Mina Nagy Zaki mnzaki at gmail.com
Wed Jul 13 18:50:26 CEST 2011


I have reordered the PACKED and PLANAR flags to make PACKED the default

PS: sorry for the broken emails, I fail at git send-email

---
 libavfilter/avfilter.h      |   16 +++++++++++++++-
 libavfilter/avfiltergraph.c |    6 ++++++
 libavfilter/defaults.c      |    8 ++++++++
 libavfilter/formats.c       |   11 +++++++++++
 4 files changed, 40 insertions(+), 1 deletions(-)

diff --git a/libavfilter/avfilter.h b/libavfilter/avfilter.h
index 0b8f2d4..a67cf8a 100644
--- a/libavfilter/avfilter.h
+++ b/libavfilter/avfilter.h
@@ -261,6 +261,11 @@ AVFilterFormats *avfilter_all_formats(enum AVMediaType type);
 AVFilterFormats *avfilter_all_channel_layouts(void);
 
 /**
+ * Return a list of all audio packing formats.
+ */
+AVFilterFormats *avfilter_all_packing_formats(void);
+
+/**
  * 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.
@@ -478,6 +483,7 @@ AVFilterBufferRef *avfilter_default_get_audio_buffer(AVFilterLink *link, int per
 void avfilter_set_common_pixel_formats(AVFilterContext *ctx, AVFilterFormats *formats);
 void avfilter_set_common_sample_formats(AVFilterContext *ctx, AVFilterFormats *formats);
 void avfilter_set_common_channel_layouts(AVFilterContext *ctx, AVFilterFormats *formats);
+void avfilter_set_common_packing_formats(AVFilterContext *ctx, AVFilterFormats *formats);
 
 /** Default handler for query_formats() */
 int avfilter_default_query_formats(AVFilterContext *ctx);
@@ -566,6 +572,11 @@ struct AVFilterContext {
     void *priv;                     ///< private data for use by the filter
 };
 
+enum AVFilterPacking {
+    AVFILTER_PACKED = 1,
+    AVFILTER_PLANAR,
+};
+
 /**
  * A link between two filters. This contains pointers to the source and
  * destination filters between which this link exists, and the indexes of
@@ -593,9 +604,10 @@ struct AVFilterLink {
     int w;                      ///< agreed upon image width
     int h;                      ///< agreed upon image height
     AVRational sample_aspect_ratio; ///< agreed upon sample aspect ratio
-    /* These two parameters apply only to audio */
+    /* These three parameters apply only to audio */
     int64_t channel_layout;     ///< channel layout of current buffer (see libavutil/audioconvert.h)
     int64_t sample_rate;        ///< samples per second
+    int planar;                 ///< agreed upon packing mode of audio buffers. true if planar.
 
     int format;                 ///< agreed upon media format
 
@@ -611,6 +623,8 @@ struct AVFilterLink {
 
     AVFilterFormats *in_chlayouts;
     AVFilterFormats *out_chlayouts;
+    AVFilterFormats *in_packing;
+    AVFilterFormats *out_packing;
 
     /**
      * The buffer reference currently being sent across the link by the source
diff --git a/libavfilter/avfiltergraph.c b/libavfilter/avfiltergraph.c
index 0476861..2561587 100644
--- a/libavfilter/avfiltergraph.c
+++ b/libavfilter/avfiltergraph.c
@@ -200,9 +200,15 @@ static void pick_format(AVFilterLink *link)
 
     if (link->type == AVMEDIA_TYPE_AUDIO) {
         link->in_chlayouts->format_count = 1;
+        link->in_packing->format_count = 1;
+
         link->channel_layout = link->in_chlayouts->formats[0];
+        link->planar = link->in_packing->formats[0] == AVFILTER_PLANAR;
+
         avfilter_formats_unref(&link->in_chlayouts);
         avfilter_formats_unref(&link->out_chlayouts);
+        avfilter_formats_unref(&link->in_packing);
+        avfilter_formats_unref(&link->out_packing);
     }
 
 }
diff --git a/libavfilter/defaults.c b/libavfilter/defaults.c
index b03816d..a7bff48 100644
--- a/libavfilter/defaults.c
+++ b/libavfilter/defaults.c
@@ -239,11 +239,19 @@ void avfilter_set_common_channel_layouts(AVFilterContext *ctx, AVFilterFormats *
                        offsetof(AVFilterLink, out_chlayouts));
 }
 
+void avfilter_set_common_packing_formats(AVFilterContext *ctx, AVFilterFormats *formats)
+{
+    set_common_formats(ctx, formats, AVMEDIA_TYPE_AUDIO,
+                      offsetof(AVFilterLink, in_packing),
+                      offsetof(AVFilterLink, out_packing));
+}
+
 int avfilter_default_query_formats(AVFilterContext *ctx)
 {
     avfilter_set_common_pixel_formats(ctx, avfilter_all_formats(AVMEDIA_TYPE_VIDEO));
     avfilter_set_common_sample_formats(ctx, avfilter_all_formats(AVMEDIA_TYPE_AUDIO));
     avfilter_set_common_channel_layouts(ctx, avfilter_all_channel_layouts());
+    avfilter_set_common_packing_formats(ctx, avfilter_all_packing_formats());
 
     return 0;
 }
diff --git a/libavfilter/formats.c b/libavfilter/formats.c
index b6e30e7..214718b 100644
--- a/libavfilter/formats.c
+++ b/libavfilter/formats.c
@@ -173,6 +173,17 @@ AVFilterFormats *avfilter_all_channel_layouts(void)
     return avfilter_make_format64_list(chlayouts);
 }
 
+AVFilterFormats *avfilter_all_packing_formats(void)
+{
+    static int packing[] = {
+        AVFILTER_PACKED,
+        AVFILTER_PLANAR,
+        -1,
+    };
+
+    return avfilter_make_format_list(packing);
+}
+
 void avfilter_formats_ref(AVFilterFormats *f, AVFilterFormats **ref)
 {
     *ref = f;
-- 
1.7.4.4



More information about the ffmpeg-devel mailing list