changeset 32905:fd60388d370a

Add conversion functions to and from AVSampleFormat.
author reimar
date Tue, 01 Mar 2011 21:44:15 +0000
parents e67931f380a3
children b623edea8e3c
files fmt-conversion.c fmt-conversion.h
diffstat 2 files changed, 44 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/fmt-conversion.c	Tue Mar 01 11:02:48 2011 +0000
+++ b/fmt-conversion.c	Tue Mar 01 21:44:15 2011 +0000
@@ -19,6 +19,8 @@
 #include "mp_msg.h"
 #include "libavutil/avutil.h"
 #include "libmpcodecs/img_format.h"
+#include "libavutil/samplefmt.h"
+#include "libaf/af_format.h"
 #include "fmt-conversion.h"
 
 static const struct {
@@ -123,3 +125,42 @@
         mp_msg(MSGT_GLOBAL, MSGL_ERR, "Unsupported PixelFormat %i\n", pix_fmt);
     return fmt;
 }
+
+static const struct {
+    int fmt;
+    enum AVSampleFormat sample_fmt;
+} samplefmt_conversion_map[] = {
+    {AF_FORMAT_U8, AV_SAMPLE_FMT_U8},
+    {AF_FORMAT_S16_NE, AV_SAMPLE_FMT_S16},
+    {AF_FORMAT_S32_NE, AV_SAMPLE_FMT_S32},
+    {AF_FORMAT_FLOAT_NE, AV_SAMPLE_FMT_FLT},
+    {0, AV_SAMPLE_FMT_NONE}
+};
+
+enum AVSampleFormat affmt2samplefmt(int fmt)
+{
+    char str[50];
+    int i;
+    enum AVSampleFormat sample_fmt;
+    for (i = 0; samplefmt_conversion_map[i].fmt; i++)
+        if (samplefmt_conversion_map[i].fmt == fmt)
+            break;
+    sample_fmt = samplefmt_conversion_map[i].sample_fmt;
+    if (sample_fmt == PIX_FMT_NONE)
+        mp_msg(MSGT_GLOBAL, MSGL_ERR, "Unsupported format %s\n",
+               af_fmt2str(fmt, str, sizeof(str)));
+    return sample_fmt;
+}
+
+int samplefmt2affmt(enum AVSampleFormat sample_fmt)
+{
+    int i;
+    int fmt;
+    for (i = 0; samplefmt_conversion_map[i].sample_fmt != AV_SAMPLE_FMT_NONE; i++)
+        if (samplefmt_conversion_map[i].sample_fmt == sample_fmt)
+            break;
+    fmt = samplefmt_conversion_map[i].fmt;
+    if (!fmt)
+        mp_msg(MSGT_GLOBAL, MSGL_ERR, "Unsupported AVSampleFormat %i\n", sample_fmt);
+    return fmt;
+}
--- a/fmt-conversion.h	Tue Mar 01 11:02:48 2011 +0000
+++ b/fmt-conversion.h	Tue Mar 01 21:44:15 2011 +0000
@@ -21,8 +21,11 @@
 
 #include "config.h"
 #include "libavutil/avutil.h"
+#include "libavutil/samplefmt.h"
 
 enum PixelFormat imgfmt2pixfmt(int fmt);
 int pixfmt2imgfmt(enum PixelFormat pix_fmt);
+enum AVSampleFormat affmt2samplefmt(int fmt);
+int samplefmt2affmt(enum AVSampleFormat sample_fmt);
 
 #endif /* MPLAYER_FMT_CONVERSION_H */