[libav-devel] [PATCH 1/9] libavutil: add planar sample formats and av_sample_fmt_is_planar()

Justin Ruggles justin.ruggles at gmail.com
Sat Nov 12 23:35:47 CET 2011


---
 doc/APIchanges        |    3 +++
 libavutil/avutil.h    |    2 +-
 libavutil/samplefmt.c |   23 ++++++++++++++++++-----
 libavutil/samplefmt.h |   15 +++++++++++++++
 4 files changed, 37 insertions(+), 6 deletions(-)

diff --git a/doc/APIchanges b/doc/APIchanges
index 5ef1fa5..4549415 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -13,6 +13,9 @@ libavutil:   2011-04-18
 
 API changes, most recent first:
 
+2011-xx-xx - xxxxxxx - lavu 51.15.0
+  Add planar sample formats and av_sample_fmt_is_planar() to samplefmt.h.
+
 2011-11-06 - ba04ecf - lavu 51.14.0
   Add av_strcasecmp() and av_strncasecmp() to avstring.h.
 
diff --git a/libavutil/avutil.h b/libavutil/avutil.h
index 5ad7034..4b226e0 100644
--- a/libavutil/avutil.h
+++ b/libavutil/avutil.h
@@ -40,7 +40,7 @@
 #define AV_VERSION(a, b, c) AV_VERSION_DOT(a, b, c)
 
 #define LIBAVUTIL_VERSION_MAJOR 51
-#define LIBAVUTIL_VERSION_MINOR 14
+#define LIBAVUTIL_VERSION_MINOR 15
 #define LIBAVUTIL_VERSION_MICRO  0
 
 #define LIBAVUTIL_VERSION_INT   AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
diff --git a/libavutil/samplefmt.c b/libavutil/samplefmt.c
index 5b0bfa0..d47c5e7 100644
--- a/libavutil/samplefmt.c
+++ b/libavutil/samplefmt.c
@@ -25,15 +25,21 @@
 typedef struct SampleFmtInfo {
     const char *name;
     int bits;
+    int planar;
 } SampleFmtInfo;
 
 /** this table gives more information about formats */
 static const SampleFmtInfo sample_fmt_info[AV_SAMPLE_FMT_NB] = {
-    [AV_SAMPLE_FMT_U8]  = { .name = "u8",  .bits = 8 },
-    [AV_SAMPLE_FMT_S16] = { .name = "s16", .bits = 16 },
-    [AV_SAMPLE_FMT_S32] = { .name = "s32", .bits = 32 },
-    [AV_SAMPLE_FMT_FLT] = { .name = "flt", .bits = 32 },
-    [AV_SAMPLE_FMT_DBL] = { .name = "dbl", .bits = 64 },
+    [AV_SAMPLE_FMT_U8]         = { .name =   "u8", .bits =  8, .planar = 0 },
+    [AV_SAMPLE_FMT_S16]        = { .name =  "s16", .bits = 16, .planar = 0 },
+    [AV_SAMPLE_FMT_S32]        = { .name =  "s32", .bits = 32, .planar = 0 },
+    [AV_SAMPLE_FMT_FLT]        = { .name =  "flt", .bits = 32, .planar = 0 },
+    [AV_SAMPLE_FMT_DBL]        = { .name =  "dbl", .bits = 64, .planar = 0 },
+    [AV_SAMPLE_FMT_U8_PLANAR]  = { .name =  "u8p", .bits =  8, .planar = 1 },
+    [AV_SAMPLE_FMT_S16_PLANAR] = { .name = "s16p", .bits = 16, .planar = 1 },
+    [AV_SAMPLE_FMT_S32_PLANAR] = { .name = "s32p", .bits = 32, .planar = 1 },
+    [AV_SAMPLE_FMT_FLT_PLANAR] = { .name = "fltp", .bits = 32, .planar = 1 },
+    [AV_SAMPLE_FMT_DBL_PLANAR] = { .name = "dblp", .bits = 64, .planar = 1 },
 };
 
 const char *av_get_sample_fmt_name(enum AVSampleFormat sample_fmt)
@@ -79,3 +85,10 @@ int av_get_bits_per_sample_fmt(enum AVSampleFormat sample_fmt)
         0 : sample_fmt_info[sample_fmt].bits;
 }
 #endif
+
+int av_sample_fmt_is_planar(enum AVSampleFormat sample_fmt)
+{
+     if (sample_fmt < 0 || sample_fmt >= AV_SAMPLE_FMT_NB)
+         return 0;
+     return sample_fmt_info[sample_fmt].planar;
+}
diff --git a/libavutil/samplefmt.h b/libavutil/samplefmt.h
index e382149..5dfd7a6 100644
--- a/libavutil/samplefmt.h
+++ b/libavutil/samplefmt.h
@@ -31,6 +31,13 @@ enum AVSampleFormat {
     AV_SAMPLE_FMT_S32,         ///< signed 32 bits
     AV_SAMPLE_FMT_FLT,         ///< float
     AV_SAMPLE_FMT_DBL,         ///< double
+
+    AV_SAMPLE_FMT_U8_PLANAR,   ///< unsigned 8 bits, planar
+    AV_SAMPLE_FMT_S16_PLANAR,  ///< signed 16 bits, planar
+    AV_SAMPLE_FMT_S32_PLANAR,  ///< signed 32 bits, planar
+    AV_SAMPLE_FMT_FLT_PLANAR,  ///< float, planar
+    AV_SAMPLE_FMT_DBL_PLANAR,  ///< double, planar
+
     AV_SAMPLE_FMT_NB           ///< Number of sample formats. DO NOT USE if linking dynamically
 };
 
@@ -77,4 +84,12 @@ int av_get_bits_per_sample_fmt(enum AVSampleFormat sample_fmt);
  */
 int av_get_bytes_per_sample(enum AVSampleFormat sample_fmt);
 
+/**
+ * Check if the sample format is planar.
+ *
+ * @param sample_fmt the sample format to inspect
+ * @return 1 if the sample format is planar, 0 if it is interleaved
+ */
+int av_sample_fmt_is_planar(enum AVSampleFormat sample_fmt);
+
 #endif /* AVUTIL_SAMPLEFMT_H */
-- 
1.7.1



More information about the libav-devel mailing list