[FFmpeg-cvslog] avformat/libopenmpt: Update to libopenmpt 0.3 API

Jörn Heusipp git at videolan.org
Fri Jan 12 13:54:09 EET 2018


ffmpeg | branch: master | Jörn Heusipp <osmanx at problemloesungsmaschine.de> | Thu Jan 11 09:11:30 2018 +0100| [8b1b25a86f1b3c61f1c9742c9b7fff5baa5f1bc7] | committer: Michael Niedermayer

avformat/libopenmpt: Update to libopenmpt 0.3 API

libopenmpt 0.3 deprecates openmpt_module_create_from_memory() and
provides a replacement function openmpt_module_create_from_memory2().

Detecting libopenmpt 0.3 can be done at build time via the API
version macros provided by libopenmpt. libopenmpt 0.2 did not provide
all required macros, however libopenmpt documents the required #define
shims that can be safely added for libopenmpt 0.2.

Using openmpt_module_create_from_memory2() instead of
openmpt_module_create_from_memory() avoids the deprecation warning
when building ffmpeg with libopenmpt 0.3.

openmpt_module_create_from_memory2() provides more fine-grained error
reporting and in particular allows distinguishing out-of-memory from
input file parsing errors. Return appropriate ffmpeg errors
accordingly.

libopenmpt 0.3 is ABI and API compatible with applications built
against libopenmpt 0.2. Building ffmpeg with libopenmpt 0.2 is still
supported.

Signed-off-by: Jörn Heusipp <osmanx at problemloesungsmaschine.de>
Signed-off-by: Michael Niedermayer <michael at niedermayer.cc>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=8b1b25a86f1b3c61f1c9742c9b7fff5baa5f1bc7
---

 libavformat/libopenmpt.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/libavformat/libopenmpt.c b/libavformat/libopenmpt.c
index 2e22290003..30c3d6e646 100644
--- a/libavformat/libopenmpt.c
+++ b/libavformat/libopenmpt.c
@@ -21,6 +21,14 @@
 
 #include <libopenmpt/libopenmpt.h>
 #include <libopenmpt/libopenmpt_stream_callbacks_file.h>
+#include <libopenmpt/libopenmpt_version.h>
+/* Shims to support libopenmpt < 0.3.0 (as documented by libopenmpt) */
+#if !defined(OPENMPT_API_VERSION_MAKE)
+#define OPENMPT_API_VERSION_MAKE(major, minor, patch) (((major)<<24)|((minor)<<16)|((patch)<<0))
+#endif
+#if !defined(OPENMPT_API_VERSION_AT_LEAST)
+#define OPENMPT_API_VERSION_AT_LEAST(major, minor, patch) (OPENMPT_API_VERSION >= OPENMPT_API_VERSION_MAKE((major), (minor), (patch)))
+#endif
 
 #include "libavutil/avstring.h"
 #include "libavutil/opt.h"
@@ -74,6 +82,9 @@ static int read_header_openmpt(AVFormatContext *s)
     OpenMPTContext *openmpt = s->priv_data;
     int64_t size;
     char *buf;
+#if OPENMPT_API_VERSION_AT_LEAST(0,3,0)
+    int error;
+#endif
     int ret;
 
     size = avio_size(s->pb);
@@ -89,10 +100,24 @@ static int read_header_openmpt(AVFormatContext *s)
         return size;
     }
 
+#if OPENMPT_API_VERSION_AT_LEAST(0,3,0)
+    error = OPENMPT_ERROR_OK;
+    openmpt->module = openmpt_module_create_from_memory2(buf, size, openmpt_logfunc, s, NULL, NULL, &error, NULL, NULL);
+    av_freep(&buf);
+    if (!openmpt->module) {
+        if (error == OPENMPT_ERROR_OUT_OF_MEMORY)
+            return AVERROR(ENOMEM);
+        else if (error >= OPENMPT_ERROR_GENERAL)
+            return AVERROR_INVALIDDATA;
+        else
+            return AVERROR_UNKNOWN;
+    }
+#else
     openmpt->module = openmpt_module_create_from_memory(buf, size, openmpt_logfunc, s, NULL);
     av_freep(&buf);
     if (!openmpt->module)
             return AVERROR_INVALIDDATA;
+#endif
 
     openmpt->channels = av_get_channel_layout_nb_channels(openmpt->layout);
 



More information about the ffmpeg-cvslog mailing list