Permalink
Browse files

DllSwResample: Use libavresample if libswresample is not available.

  • Loading branch information...
1 parent f00b0c2 commit 274679ddf932af1de2e9c3f01e9801099ff77b0c @aballier aballier committed Aug 14, 2012
Showing with 38 additions and 1 deletion.
  1. +38 −1 lib/DllSwResample.h
View
39 lib/DllSwResample.h
@@ -36,7 +36,14 @@ extern "C" {
#pragma warning(disable:4244)
#endif
#if (defined USE_EXTERNAL_FFMPEG)
- #include <libswresample/swresample.h>
+ #if HAVE_LIBSWRESAMPLE_SWRESAMPLE_H
+ #include <libswresample/swresample.h>
+ #elif HAVE_LIBAVRESAMPLE_AVRESAMPLE_H
+ #include <libavresample/avresample.h>
+ #define SwrContext AVAudioResampleContext
+ #else
+ #error "Either libswresample or libavresample is needed!"
+ #endif
#else
#include "libswresample/swresample.h"
#endif
@@ -54,6 +61,7 @@ class DllSwResampleInterface
#if (defined USE_EXTERNAL_FFMPEG) || (defined TARGET_DARWIN)
+#if HAVE_LIBSWRESAMPLE_SWRESAMPLE_H || (defined TARGET_DARWIN)
// Use direct mapping
class DllSwResample : public DllDynamic, DllSwResampleInterface
{
@@ -72,6 +80,35 @@ class DllSwResample : public DllDynamic, DllSwResampleInterface
virtual void swr_free(struct SwrContext **s){ return ::swr_free(s); }
virtual int swr_convert(struct SwrContext *s, uint8_t **out, int out_count, const uint8_t **in , int in_count){ return ::swr_convert(s, out, out_count, in, in_count); }
};
+#else
+// Wrap the same API through libavresample.
+class DllSwResample : public DllDynamic, DllSwResampleInterface
+{
+public:
+ virtual ~DllSwResample() {}
+
+ // DLL faking.
+ virtual bool ResolveExports() { return true; }
+ virtual bool Load() {
+ CLog::Log(LOGDEBUG, "DllAvFormat: Using libavresample system library");
+ return true;
+ }
+ virtual void Unload() {}
+ virtual struct SwrContext *swr_alloc_set_opts(struct SwrContext *s, int64_t out_ch_layout, enum AVSampleFormat out_sample_fmt, int out_sample_rate, int64_t in_ch_layout, enum AVSampleFormat in_sample_fmt, int in_sample_rate, int log_offset, void *log_ctx) {
+ AVAudioResampleContext *ret = ::avresample_alloc_context();
+ av_opt_set_int(ret, "out_channel_layout", out_ch_layout , 0);
+ av_opt_set_int(ret, "out_sample_fmt" , out_sample_fmt , 0);
+ av_opt_set_int(ret, "out_sample_rate" , out_sample_rate, 0);
+ av_opt_set_int(ret, "in_channel_layout" , in_ch_layout , 0);
+ av_opt_set_int(ret, "in_sample_fmt" , in_sample_fmt , 0);
+ av_opt_set_int(ret, "in_sample_rate" , in_sample_rate , 0);
+ return ret;
+ }
+ virtual int swr_init(struct SwrContext *s) { return ::avresample_open(s); }
+ virtual void swr_free(struct SwrContext **s){ ::avresample_close(*s); *s = NULL; }
+ virtual int swr_convert(struct SwrContext *s, uint8_t **out, int out_count, const uint8_t **in , int in_count){ return ::avresample_convert(s, (void**)out, 0, out_count, (void**)in, 0,in_count); }
+};
+#endif
#else

0 comments on commit 274679d

Please sign in to comment.