[MPlayer-cvslog] r32992 - in trunk: fmt-conversion.c fmt-conversion.h

reimar subversion at mplayerhq.hu
Tue Mar 1 22:44:15 CET 2011


Author: reimar
Date: Tue Mar  1 22:44:15 2011
New Revision: 32992

Log:
Add conversion functions to and from AVSampleFormat.

Modified:
   trunk/fmt-conversion.c
   trunk/fmt-conversion.h

Modified: trunk/fmt-conversion.c
==============================================================================
--- trunk/fmt-conversion.c	Tue Mar  1 12:02:48 2011	(r32991)
+++ trunk/fmt-conversion.c	Tue Mar  1 22:44:15 2011	(r32992)
@@ -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 @@ int pixfmt2imgfmt(enum PixelFormat pix_f
         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;
+}

Modified: trunk/fmt-conversion.h
==============================================================================
--- trunk/fmt-conversion.h	Tue Mar  1 12:02:48 2011	(r32991)
+++ trunk/fmt-conversion.h	Tue Mar  1 22:44:15 2011	(r32992)
@@ -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 */


More information about the MPlayer-cvslog mailing list