diff options
-rw-r--r-- | Android.mk | 2 | ||||
-rw-r--r-- | configure.ac | 4 | ||||
-rw-r--r-- | docs/plugins/Makefile.am | 1 | ||||
-rw-r--r-- | docs/plugins/gst-plugins-bad-plugins-docs.sgml | 1 | ||||
-rw-r--r-- | docs/plugins/gst-plugins-bad-plugins-sections.txt | 14 | ||||
-rw-r--r-- | docs/plugins/inspect/plugin-legacyresample.xml | 34 | ||||
-rw-r--r-- | gst-plugins-bad.spec.in | 1 | ||||
-rw-r--r-- | gst/legacyresample/Makefile.am | 35 | ||||
-rw-r--r-- | gst/legacyresample/buffer.c | 253 | ||||
-rw-r--r-- | gst/legacyresample/buffer.h | 51 | ||||
-rw-r--r-- | gst/legacyresample/debug.c | 65 | ||||
-rw-r--r-- | gst/legacyresample/debug.h | 51 | ||||
-rw-r--r-- | gst/legacyresample/functable.c | 254 | ||||
-rw-r--r-- | gst/legacyresample/functable.h | 61 | ||||
-rw-r--r-- | gst/legacyresample/gstlegacyresample.c | 878 | ||||
-rw-r--r-- | gst/legacyresample/gstlegacyresample.h | 79 | ||||
-rw-r--r-- | gst/legacyresample/resample.c | 312 | ||||
-rw-r--r-- | gst/legacyresample/resample.h | 131 | ||||
-rw-r--r-- | gst/legacyresample/resample_functable.c | 274 | ||||
-rw-r--r-- | gst/legacyresample/resample_ref.c | 224 | ||||
-rw-r--r-- | tests/check/Makefile.am | 8 | ||||
-rw-r--r-- | tests/check/elements/legacyresample.c | 574 |
22 files changed, 1 insertions, 3306 deletions
diff --git a/Android.mk b/Android.mk index c18e9ddc0..59f96e112 100644 --- a/Android.mk +++ b/Android.mk @@ -42,7 +42,6 @@ GST_PLUGINS_BAD_BUILT_SOURCES := \ gst/mxf/Android.mk \ gst/cdxaparse/Android.mk \ gst/mpegpsmux/Android.mk \ - gst/legacyresample/Android.mk \ gst/gaudieffects/Android.mk \ gst/liveadder/Android.mk \ gst/nsf/Android.mk \ @@ -137,7 +136,6 @@ CONFIGURE_TARGETS += gst-plugins-bad-configure -include $(GST_PLUGINS_BAD_TOP)/gst/mxf/Android.mk -include $(GST_PLUGINS_BAD_TOP)/gst/cdxaparse/Android.mk -include $(GST_PLUGINS_BAD_TOP)/gst/mpegpsmux/Android.mk --include $(GST_PLUGINS_BAD_TOP)/gst/legacyresample/Android.mk -include $(GST_PLUGINS_BAD_TOP)/gst/gaudieffects/Android.mk -include $(GST_PLUGINS_BAD_TOP)/gst/liveadder/Android.mk -include $(GST_PLUGINS_BAD_TOP)/gst/nsf/Android.mk diff --git a/configure.ac b/configure.ac index 4f06a6b0d..895605488 100644 --- a/configure.ac +++ b/configure.ac @@ -315,7 +315,7 @@ GST_PLUGINS_NONPORTED=" aiff \ dccp faceoverlay festival \ fieldanalysis freeverb freeze frei0r \ hdvparse id3tag inter interlace ivfparse jpegformat jp2kdecimator \ - kate liveadder legacyresample librfb mpegtsmux \ + kate liveadder librfb mpegtsmux \ mpegpsmux mve mxf mythtv nsf nuvdemux \ patchdetect pnm real \ sdi siren speed subenc stereo tta videofilters \ @@ -361,7 +361,6 @@ AG_GST_CHECK_PLUGIN(interlace) AG_GST_CHECK_PLUGIN(ivfparse) AG_GST_CHECK_PLUGIN(jp2kdecimator) AG_GST_CHECK_PLUGIN(jpegformat) -AG_GST_CHECK_PLUGIN(legacyresample) AG_GST_CHECK_PLUGIN(librfb) AG_GST_CHECK_PLUGIN(liveadder) AG_GST_CHECK_PLUGIN(mpegdemux) @@ -1974,7 +1973,6 @@ gst/interlace/Makefile gst/ivfparse/Makefile gst/jp2kdecimator/Makefile gst/jpegformat/Makefile -gst/legacyresample/Makefile gst/librfb/Makefile gst/liveadder/Makefile gst/mpegdemux/Makefile diff --git a/docs/plugins/Makefile.am b/docs/plugins/Makefile.am index 5a0978c89..e0ff6f497 100644 --- a/docs/plugins/Makefile.am +++ b/docs/plugins/Makefile.am @@ -159,7 +159,6 @@ EXTRA_HFILES = \ $(top_srcdir)/gst/geometrictransform/gstwaterripple.h \ $(top_srcdir)/gst/ivfparse/gstivfparse.h \ $(top_srcdir)/gst/jpegformat/gstjpegparse.h \ - $(top_srcdir)/gst/legacyresample/gstlegacyresample.h \ $(top_srcdir)/gst/liveadder/liveadder.h \ $(top_srcdir)/gst/mxf/mxfdemux.h \ $(top_srcdir)/gst/mxf/mxfmux.h \ diff --git a/docs/plugins/gst-plugins-bad-plugins-docs.sgml b/docs/plugins/gst-plugins-bad-plugins-docs.sgml index 16d8d7c2b..c427e6637 100644 --- a/docs/plugins/gst-plugins-bad-plugins-docs.sgml +++ b/docs/plugins/gst-plugins-bad-plugins-docs.sgml @@ -71,7 +71,6 @@ <xi:include href="xml/element-kateparse.xml" /> <xi:include href="xml/element-katetag.xml" /> <xi:include href="xml/element-ladspa.xml" /> - <xi:include href="xml/element-legacyresample.xml" /> <xi:include href="xml/element-liveadder.xml" /> <xi:include href="xml/element-marble.xml" /> <xi:include href="xml/element-mimenc.xml" /> diff --git a/docs/plugins/gst-plugins-bad-plugins-sections.txt b/docs/plugins/gst-plugins-bad-plugins-sections.txt index 575c440f5..6b69d05c8 100644 --- a/docs/plugins/gst-plugins-bad-plugins-sections.txt +++ b/docs/plugins/gst-plugins-bad-plugins-sections.txt @@ -750,20 +750,6 @@ gst_jpeg_parse_get_type </SECTION> <SECTION> -<FILE>element-legacyresample</FILE> -<TITLE>legacyresample</TITLE> -GstLegacyresample -<SUBSECTION Standard> -GstLegacyresampleClass -GST_LEGACYRESAMPLE -GST_LEGACYRESAMPLE_CLASS -GST_IS_LEGACYRESAMPLE -GST_IS_LEGACYRESAMPLE_CLASS -GST_TYPE_LEGACYRESAMPLE -gst_legacyresample_get_type -</SECTION> - -<SECTION> <FILE>element-liveadder</FILE> <TITLE>liveadder</TITLE> GstLiveAdder diff --git a/docs/plugins/inspect/plugin-legacyresample.xml b/docs/plugins/inspect/plugin-legacyresample.xml deleted file mode 100644 index 77451a30b..000000000 --- a/docs/plugins/inspect/plugin-legacyresample.xml +++ /dev/null @@ -1,34 +0,0 @@ -<plugin> - <name>legacyresample</name> - <description>Resamples audio</description> - <filename>../../gst/legacyresample/.libs/libgstlegacyresample.so</filename> - <basename>libgstlegacyresample.so</basename> - <version>0.10.23.1</version> - <license>LGPL</license> - <source>gst-plugins-bad</source> - <package>GStreamer Bad Plug-ins git</package> - <origin>Unknown package origin</origin> - <elements> - <element> - <name>legacyresample</name> - <longname>Audio scaler</longname> - <class>Filter/Converter/Audio</class> - <description>Resample audio</description> - <author>David Schleef <ds@schleef.org></author> - <pads> - <caps> - <name>sink</name> - <direction>sink</direction> - <presence>always</presence> - <details>audio/x-raw-int, rate=(int)[ 1, 2147483647 ], channels=(int)[ 1, 2147483647 ], endianness=(int)1234, width=(int)16, depth=(int)16, signed=(boolean)true; audio/x-raw-int, rate=(int)[ 1, 2147483647 ], channels=(int)[ 1, 2147483647 ], endianness=(int)1234, width=(int)32, depth=(int)32, signed=(boolean)true; audio/x-raw-float, rate=(int)[ 1, 2147483647 ], channels=(int)[ 1, 2147483647 ], endianness=(int)1234, width=(int)32; audio/x-raw-float, rate=(int)[ 1, 2147483647 ], channels=(int)[ 1, 2147483647 ], endianness=(int)1234, width=(int)64</details> - </caps> - <caps> - <name>src</name> - <direction>source</direction> - <presence>always</presence> - <details>audio/x-raw-int, rate=(int)[ 1, 2147483647 ], channels=(int)[ 1, 2147483647 ], endianness=(int)1234, width=(int)16, depth=(int)16, signed=(boolean)true; audio/x-raw-int, rate=(int)[ 1, 2147483647 ], channels=(int)[ 1, 2147483647 ], endianness=(int)1234, width=(int)32, depth=(int)32, signed=(boolean)true; audio/x-raw-float, rate=(int)[ 1, 2147483647 ], channels=(int)[ 1, 2147483647 ], endianness=(int)1234, width=(int)32; audio/x-raw-float, rate=(int)[ 1, 2147483647 ], channels=(int)[ 1, 2147483647 ], endianness=(int)1234, width=(int)64</details> - </caps> - </pads> - </element> - </elements> -</plugin>
\ No newline at end of file diff --git a/gst-plugins-bad.spec.in b/gst-plugins-bad.spec.in index 2964e0042..4ef937883 100644 --- a/gst-plugins-bad.spec.in +++ b/gst-plugins-bad.spec.in @@ -228,7 +228,6 @@ make ERROR_CFLAGS='' ERROR_CXXFLAGS='' # %{_libdir}/gstreamer-%{majorminor}/libgstid3tag.so # %{_libdir}/gstreamer-%{majorminor}/libgstivfparse.so # %{_libdir}/gstreamer-%{majorminor}/libgstjpegformat.so -# %{_libdir}/gstreamer-%{majorminor}/libgstlegacyresample.so # %{_libdir}/gstreamer-%{majorminor}/libgstliveadder.so %{_libdir}/gstreamer-%{majorminor}/libgstmpegdemux.so # %{_libdir}/gstreamer-%{majorminor}/libgstmve.so diff --git a/gst/legacyresample/Makefile.am b/gst/legacyresample/Makefile.am deleted file mode 100644 index 13985affe..000000000 --- a/gst/legacyresample/Makefile.am +++ /dev/null @@ -1,35 +0,0 @@ -plugin_LTLIBRARIES = libgstlegacyresample.la - -resample_SOURCES = \ - functable.c \ - resample.c \ - resample_functable.c \ - resample_ref.c \ - resample.h \ - buffer.c - -noinst_HEADERS = \ - gstlegacyresample.h \ - functable.h \ - debug.h \ - buffer.h - -libgstlegacyresample_la_SOURCES = gstlegacyresample.c $(resample_SOURCES) -libgstlegacyresample_la_CFLAGS = $(GST_PLUGINS_BASE_CFLAGS) $(GST_BASE_CFLAGS) $(GST_CFLAGS) -libgstlegacyresample_la_LIBADD = $(GST_BASE_LIBS) $(GST_LIBS) $(LIBM) -libgstlegacyresample_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS) -libgstlegacyresample_la_LIBTOOLFLAGS = --tag=disable-static - -Android.mk: Makefile.am $(BUILT_SOURCES) - androgenizer \ - -:PROJECT libgstlegacyresample -:SHARED libgstlegacyresample \ - -:TAGS eng debug \ - -:REL_TOP $(top_srcdir) -:ABS_TOP $(abs_top_srcdir) \ - -:SOURCES $(libgstlegacyresample_la_SOURCES) \ - -:CFLAGS $(DEFS) $(DEFAULT_INCLUDES) $(libgstlegacyresample_la_CFLAGS) \ - -:LDFLAGS $(libgstlegacyresample_la_LDFLAGS) \ - $(libgstlegacyresample_la_LIBADD) \ - -ldl \ - -:PASSTHROUGH LOCAL_ARM_MODE:=arm \ - LOCAL_MODULE_PATH:='$$(TARGET_OUT)/lib/gstreamer-0.10' \ - > $@
\ No newline at end of file diff --git a/gst/legacyresample/buffer.c b/gst/legacyresample/buffer.c deleted file mode 100644 index 442b4f8c5..000000000 --- a/gst/legacyresample/buffer.c +++ /dev/null @@ -1,253 +0,0 @@ - -#ifndef HAVE_CONFIG_H -#include "config.h" -#endif - -#include <glib.h> -#include <string.h> - -#include "buffer.h" -#include "debug.h" - -static void audioresample_buffer_free_mem (AudioresampleBuffer * buffer, - void *); -static void audioresample_buffer_free_subbuffer (AudioresampleBuffer * buffer, - void *priv); - - -AudioresampleBuffer * -audioresample_buffer_new (void) -{ - AudioresampleBuffer *buffer; - - buffer = g_new0 (AudioresampleBuffer, 1); - buffer->ref_count = 1; - return buffer; -} - -AudioresampleBuffer * -audioresample_buffer_new_and_alloc (int size) -{ - AudioresampleBuffer *buffer = audioresample_buffer_new (); - - buffer->data = g_malloc (size); - buffer->length = size; - buffer->free = audioresample_buffer_free_mem; - - return buffer; -} - -AudioresampleBuffer * -audioresample_buffer_new_with_data (void *data, int size) -{ - AudioresampleBuffer *buffer = audioresample_buffer_new (); - - buffer->data = data; - buffer->length = size; - buffer->free = audioresample_buffer_free_mem; - - return buffer; -} - -AudioresampleBuffer * -audioresample_buffer_new_subbuffer (AudioresampleBuffer * buffer, int offset, - int length) -{ - AudioresampleBuffer *subbuffer = audioresample_buffer_new (); - - if (buffer->parent) { - audioresample_buffer_ref (buffer->parent); - subbuffer->parent = buffer->parent; - } else { - audioresample_buffer_ref (buffer); - subbuffer->parent = buffer; - } - subbuffer->data = buffer->data + offset; - subbuffer->length = length; - subbuffer->free = audioresample_buffer_free_subbuffer; - - return subbuffer; -} - -void -audioresample_buffer_ref (AudioresampleBuffer * buffer) -{ - buffer->ref_count++; -} - -void -audioresample_buffer_unref (AudioresampleBuffer * buffer) -{ - buffer->ref_count--; - if (buffer->ref_count == 0) { - if (buffer->free) - buffer->free (buffer, buffer->priv); - g_free (buffer); - } -} - -static void -audioresample_buffer_free_mem (AudioresampleBuffer * buffer, void *priv) -{ - g_free (buffer->data); -} - -static void -audioresample_buffer_free_subbuffer (AudioresampleBuffer * buffer, void *priv) -{ - audioresample_buffer_unref (buffer->parent); -} - - -AudioresampleBufferQueue * -audioresample_buffer_queue_new (void) -{ - return g_new0 (AudioresampleBufferQueue, 1); -} - -int -audioresample_buffer_queue_get_depth (AudioresampleBufferQueue * queue) -{ - return queue->depth; -} - -int -audioresample_buffer_queue_get_offset (AudioresampleBufferQueue * queue) -{ - return queue->offset; -} - -void -audioresample_buffer_queue_free (AudioresampleBufferQueue * queue) -{ - GList *g; - - for (g = g_list_first (queue->buffers); g; g = g_list_next (g)) { - audioresample_buffer_unref ((AudioresampleBuffer *) g->data); - } - g_list_free (queue->buffers); - g_free (queue); -} - -void -audioresample_buffer_queue_push (AudioresampleBufferQueue * queue, - AudioresampleBuffer * buffer) -{ - queue->buffers = g_list_append (queue->buffers, buffer); - queue->depth += buffer->length; -} - -AudioresampleBuffer * -audioresample_buffer_queue_pull (AudioresampleBufferQueue * queue, int length) -{ - GList *g; - AudioresampleBuffer *newbuffer; - AudioresampleBuffer *buffer; - AudioresampleBuffer *subbuffer; - - g_return_val_if_fail (length > 0, NULL); - - if (queue->depth < length) { - return NULL; - } - - RESAMPLE_LOG ("pulling %d, %d available", length, queue->depth); - - g = g_list_first (queue->buffers); - buffer = g->data; - - if (buffer->length > length) { - newbuffer = audioresample_buffer_new_subbuffer (buffer, 0, length); - - subbuffer = audioresample_buffer_new_subbuffer (buffer, length, - buffer->length - length); - g->data = subbuffer; - audioresample_buffer_unref (buffer); - } else { - int offset = 0; - - newbuffer = audioresample_buffer_new_and_alloc (length); - - while (offset < length) { - g = g_list_first (queue->buffers); - buffer = g->data; - - if (buffer->length > length - offset) { - int n = length - offset; - - memcpy (newbuffer->data + offset, buffer->data, n); - subbuffer = - audioresample_buffer_new_subbuffer (buffer, n, buffer->length - n); - g->data = subbuffer; - audioresample_buffer_unref (buffer); - offset += n; - } else { - memcpy (newbuffer->data + offset, buffer->data, buffer->length); - - queue->buffers = g_list_delete_link (queue->buffers, g); - offset += buffer->length; - audioresample_buffer_unref (buffer); - } - } - } - - queue->depth -= length; - queue->offset += length; - - return newbuffer; -} - -AudioresampleBuffer * -audioresample_buffer_queue_peek (AudioresampleBufferQueue * queue, int length) -{ - GList *g; - AudioresampleBuffer *newbuffer; - AudioresampleBuffer *buffer; - int offset = 0; - - g_return_val_if_fail (length > 0, NULL); - - if (queue->depth < length) { - return NULL; - } - - RESAMPLE_LOG ("peeking %d, %d available", length, queue->depth); - - g = g_list_first (queue->buffers); - buffer = g->data; - if (buffer->length > length) { - newbuffer = audioresample_buffer_new_subbuffer (buffer, 0, length); - } else { - newbuffer = audioresample_buffer_new_and_alloc (length); - while (offset < length) { - buffer = g->data; - - if (buffer->length > length - offset) { - int n = length - offset; - - memcpy (newbuffer->data + offset, buffer->data, n); - offset += n; - } else { - memcpy (newbuffer->data + offset, buffer->data, buffer->length); - offset += buffer->length; - } - g = g_list_next (g); - } - } - - return newbuffer; -} - -void -audioresample_buffer_queue_flush (AudioresampleBufferQueue * queue) -{ - GList *g; - - for (g = g_list_first (queue->buffers); g; g = g_list_next (g)) { - audioresample_buffer_unref ((AudioresampleBuffer *) g->data); - } - g_list_free (queue->buffers); - queue->buffers = NULL; - queue->depth = 0; - queue->offset = 0; -} diff --git a/gst/legacyresample/buffer.h b/gst/legacyresample/buffer.h deleted file mode 100644 index 4cf1fd943..000000000 --- a/gst/legacyresample/buffer.h +++ /dev/null @@ -1,51 +0,0 @@ - -#ifndef __AUDIORESAMPLE_BUFFER_H__ -#define __AUDIORESAMPLE_BUFFER_H__ - -#include <glib.h> - -typedef struct _AudioresampleBuffer AudioresampleBuffer; -typedef struct _AudioresampleBufferQueue AudioresampleBufferQueue; - -struct _AudioresampleBuffer -{ - unsigned char *data; - int length; - - int ref_count; - - AudioresampleBuffer *parent; - - void (*free) (AudioresampleBuffer *, void *); - void *priv; - void *priv2; -}; - -struct _AudioresampleBufferQueue -{ - GList *buffers; - int depth; - int offset; -}; - -AudioresampleBuffer * audioresample_buffer_new (void); -AudioresampleBuffer * audioresample_buffer_new_and_alloc (int size); -AudioresampleBuffer * audioresample_buffer_new_with_data (void *data, int size); -AudioresampleBuffer * audioresample_buffer_new_subbuffer (AudioresampleBuffer * buffer, - int offset, - int length); -void audioresample_buffer_ref (AudioresampleBuffer * buffer); -void audioresample_buffer_unref (AudioresampleBuffer * buffer); - -AudioresampleBufferQueue * - audioresample_buffer_queue_new (void); -void audioresample_buffer_queue_free (AudioresampleBufferQueue * queue); -int audioresample_buffer_queue_get_depth (AudioresampleBufferQueue * queue); -int audioresample_buffer_queue_get_offset (AudioresampleBufferQueue * queue); -void audioresample_buffer_queue_push (AudioresampleBufferQueue * queue, - AudioresampleBuffer * buffer); -AudioresampleBuffer * audioresample_buffer_queue_pull (AudioresampleBufferQueue * queue, int len); -AudioresampleBuffer * audioresample_buffer_queue_peek (AudioresampleBufferQueue * queue, int len); -void audioresample_buffer_queue_flush (AudioresampleBufferQueue * queue); - -#endif diff --git a/gst/legacyresample/debug.c b/gst/legacyresample/debug.c deleted file mode 100644 index 278772777..000000000 --- a/gst/legacyresample/debug.c +++ /dev/null @@ -1,65 +0,0 @@ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include <glib.h> -#include <stdio.h> -#include <debug.h> - -static const char *resample_debug_level_names[] = { - "NONE", - "ERROR", - "WARNING", - "INFO", - "DEBUG", - "LOG" -}; - -static int resample_debug_level = RESAMPLE_LEVEL_ERROR; - -void -resample_debug_log (int level, const char *file, const char *function, - int line, const char *format, ...) -{ -#ifndef GLIB_COMPAT - va_list varargs; - char *s; - - if (level > resample_debug_level) - return; - - va_start (varargs, format); - s = g_strdup_vprintf (format, varargs); - va_end (varargs); - - fprintf (stderr, "RESAMPLE: %s: %s(%d): %s: %s\n", - resample_debug_level_names[level], file, line, function, s); - g_free (s); -#else - va_list varargs; - char s[1000]; - - if (level > resample_debug_level) - return; - - va_start (varargs, format); - vsnprintf (s, 999, format, varargs); - va_end (varargs); - - fprintf (stderr, "RESAMPLE: %s: %s(%d): %s: %s\n", - resample_debug_level_names[level], file, line, function, s); -#endif -} - -void -resample_debug_set_level (int level) -{ - resample_debug_level = level; -} - -int -resample_debug_get_level (void) -{ - return resample_debug_level; -} diff --git a/gst/legacyresample/debug.h b/gst/legacyresample/debug.h deleted file mode 100644 index ff7deafbd..000000000 --- a/gst/legacyresample/debug.h +++ /dev/null @@ -1,51 +0,0 @@ - -#ifndef __RESAMPLE_DEBUG_H__ -#define __RESAMPLE_DEBUG_H__ - -#if 0 -enum -{ - RESAMPLE_LEVEL_NONE = 0, - RESAMPLE_LEVEL_ERROR, - RESAMPLE_LEVEL_WARNING, - RESAMPLE_LEVEL_INFO, - RESAMPLE_LEVEL_DEBUG, - RESAMPLE_LEVEL_LOG -}; - -#define RESAMPLE_ERROR(...) \ - RESAMPLE_DEBUG_LEVEL(RESAMPLE_LEVEL_ERROR, __VA_ARGS__) -#define RESAMPLE_WARNING(...) \ - RESAMPLE_DEBUG_LEVEL(RESAMPLE_LEVEL_WARNING, __VA_ARGS__) -#define RESAMPLE_INFO(...) \ - RESAMPLE_DEBUG_LEVEL(RESAMPLE_LEVEL_INFO, __VA_ARGS__) -#define RESAMPLE_DEBUG(...) \ - RESAMPLE_DEBUG_LEVEL(RESAMPLE_LEVEL_DEBUG, __VA_ARGS__) -#define RESAMPLE_LOG(...) \ - RESAMPLE_DEBUG_LEVEL(RESAMPLE_LEVEL_LOG, __VA_ARGS__) - -#define RESAMPLE_DEBUG_LEVEL(level,...) \ - resample_debug_log ((level), __FILE__, __FUNCTION__, __LINE__, __VA_ARGS__) - -void resample_debug_log (int level, const char *file, const char *function, - int line, const char *format, ...); -void resample_debug_set_level (int level); -int resample_debug_get_level (void); -#else - -#include <gst/gst.h> - -GST_DEBUG_CATEGORY_EXTERN (libaudioresample_debug); -#define GST_CAT_DEFAULT libaudioresample_debug - -#define RESAMPLE_ERROR GST_ERROR -#define RESAMPLE_WARNING GST_WARNING -#define RESAMPLE_INFO GST_INFO -#define RESAMPLE_DEBUG GST_DEBUG -#define RESAMPLE_LOG GST_LOG - -#define resample_debug_set_level(x) do { } while (0) - -#endif - -#endif diff --git a/gst/legacyresample/functable.c b/gst/legacyresample/functable.c deleted file mode 100644 index d627361f3..000000000 --- a/gst/legacyresample/functable.c +++ /dev/null @@ -1,254 +0,0 @@ -/* Resampling library - * Copyright (C) <2001> David A. Schleef <ds@schleef.org> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <string.h> -#include <math.h> -#include <stdio.h> -#include <stdlib.h> - -#include "functable.h" -#include "debug.h" - - - -void -functable_func_sinc (double *fx, double *dfx, double x, void *closure) -{ - if (x == 0) { - *fx = 1; - *dfx = 0; - return; - } - - *fx = sin (x) / x; - *dfx = (cos (x) - sin (x) / x) / x; -} - -void -functable_func_boxcar (double *fx, double *dfx, double x, void *closure) -{ - double width = *(double *) closure; - - if (x < width && x > -width) { - *fx = 1; - } else { - *fx = 0; - } - *dfx = 0; -} - -void -functable_func_hanning (double *fx, double *dfx, double x, void *closure) -{ - double width = *(double *) closure; - - if (x < width && x > -width) { - x /= width; - *fx = (1 - x * x) * (1 - x * x); - *dfx = -2 * 2 * x / width * (1 - x * x); - } else { - *fx = 0; - *dfx = 0; - } -} - - -Functable * -functable_new (void) -{ - Functable *ft; - - ft = malloc (sizeof (Functable)); - memset (ft, 0, sizeof (Functable)); - - return ft; -} - -void -functable_free (Functable * ft) -{ - free (ft); -} - -void -functable_set_length (Functable * t, int length) -{ - t->length = length; -} - -void -functable_set_offset (Functable * t, double offset) -{ - t->offset = offset; -} - -void -functable_set_multiplier (Functable * t, double multiplier) -{ - t->multiplier = multiplier; -} - -void -functable_calculate (Functable * t, FunctableFunc func, void *closure) -{ - int i; - double x; - - if (t->fx) - free (t->fx); - if (t->dfx) - free (t->dfx); - - t->fx = malloc (sizeof (double) * (t->length + 1)); - t->dfx = malloc (sizeof (double) * (t->length + 1)); - - t->inv_multiplier = 1.0 / t->multiplier; - - for (i = 0; i < t->length + 1; i++) { - x = t->offset + t->multiplier * i; - - func (&t->fx[i], &t->dfx[i], x, closure); - } -} - -void -functable_calculate_multiply (Functable * t, FunctableFunc func, void *closure) -{ - int i; - double x; - - for (i = 0; i < t->length + 1; i++) { - double afx, adfx, bfx, bdfx; - - afx = t->fx[i]; - adfx = t->dfx[i]; - x = t->offset + t->multiplier * i; - func (&bfx, &bdfx, x, closure); - t->fx[i] = afx * bfx; - t->dfx[i] = afx * bdfx + adfx * bfx; - } - -} - -double -functable_evaluate (Functable * t, double x) -{ - int i; - double f0, f1, w0, w1; - double x2, x3; - double w; - - if (x < t->offset || x > (t->offset + t->length * t->multiplier)) { - RESAMPLE_DEBUG ("x out of range %g", x); - } - - x -= t->offset; - x *= t->inv_multiplier; - i = floor (x); - x -= i; - - x2 = x * x; - x3 = x2 * x; - - f1 = 3 * x2 - 2 * x3; - f0 = 1 - f1; - w0 = (x - 2 * x2 + x3) * t->multiplier; - w1 = (-x2 + x3) * t->multiplier; - - w = t->fx[i] * f0 + t->fx[i + 1] * f1 + t->dfx[i] * w0 + t->dfx[i + 1] * w1; - - /*w = t->fx[i] * (1-x) + t->fx[i+1] * x; */ - - return w; -} - - -double -functable_fir (Functable * t, double x, int n, double *data, int len) -{ - int i, j; - double f0, f1, w0, w1; - double x2, x3; - double w; - double sum; - - x -= t->offset; - x /= t->multiplier; - i = floor (x); - x -= i; - - x2 = x * x; - x3 = x2 * x; - - f1 = 3 * x2 - 2 * x3; - f0 = 1 - f1; - w0 = (x - 2 * x2 + x3) * t->multiplier; - w1 = (-x2 + x3) * t->multiplier; - - sum = 0; - for (j = 0; j < len; j++) { - w = t->fx[i] * f0 + t->fx[i + 1] * f1 + t->dfx[i] * w0 + t->dfx[i + 1] * w1; - sum += data[j * 2] * w; - i += n; - } - - return sum; -} - -void -functable_fir2 (Functable * t, double *r0, double *r1, double x, - int n, double *data, int len) -{ - int i, j; - double f0, f1, w0, w1; - double x2, x3; - double w; - double sum0, sum1; - double floor_x; - - x -= t->offset; - x *= t->inv_multiplier; - floor_x = floor (x); - i = floor_x; - x -= floor_x; - - x2 = x * x; - x3 = x2 * x; - - f1 = 3 * x2 - 2 * x3; - f0 = 1 - f1; - w0 = (x - 2 * x2 + x3) * t->multiplier; - w1 = (-x2 + x3) * t->multiplier; - - sum0 = 0; - sum1 = 0; - for (j = 0; j < len; j++) { - w = t->fx[i] * f0 + t->fx[i + 1] * f1 + t->dfx[i] * w0 + t->dfx[i + 1] * w1; - sum0 += data[j * 2] * w; - sum1 += data[j * 2 + 1] * w; - i += n; - } - - *r0 = sum0; - *r1 = sum1; -} diff --git a/gst/legacyresample/functable.h b/gst/legacyresample/functable.h deleted file mode 100644 index 5f56e2bd8..000000000 --- a/gst/legacyresample/functable.h +++ /dev/null @@ -1,61 +0,0 @@ -/* Resampling library - * Copyright (C) <2001> David Schleef <ds@schleef.org> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - - -#ifndef __FUNCTABLE_H__ -#define __FUNCTABLE_H__ - -typedef void FunctableFunc (double *fx, double *dfx, double x, void *closure); - -typedef struct _Functable Functable; -struct _Functable { - int length; - - double offset; - double multiplier; - - double inv_multiplier; - - double *fx; - double *dfx; -}; - -Functable *functable_new (void); -void functable_setup (Functable *t); -void functable_free (Functable *t); - -void functable_set_length (Functable *t, int length); -void functable_set_offset (Functable *t, double offset); -void functable_set_multiplier (Functable *t, double multiplier); -void functable_calculate (Functable *t, FunctableFunc func, void *closure); -void functable_calculate_multiply (Functable *t, FunctableFunc func, void *closure); - - -double functable_evaluate (Functable *t,double x); - -double functable_fir(Functable *t,double x0,int n,double *data,int len); -void functable_fir2(Functable *t,double *r0, double *r1, double x0, - int n,double *data,int len); - -void functable_func_sinc(double *fx, double *dfx, double x, void *closure); -void functable_func_boxcar(double *fx, double *dfx, double x, void *closure); -void functable_func_hanning(double *fx, double *dfx, double x, void *closure); - -#endif /* __PRIVATE_H__ */ - diff --git a/gst/legacyresample/gstlegacyresample.c b/gst/legacyresample/gstlegacyresample.c deleted file mode 100644 index 56e58f9dc..000000000 --- a/gst/legacyresample/gstlegacyresample.c +++ /dev/null @@ -1,878 +0,0 @@ -/* GStreamer - * Copyright (C) 1999 Erik Walthinsen <omega@cse.ogi.edu> - * Copyright (C) 2003,2004 David A. Schleef <ds@schleef.org> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ -/* Element-Checklist-Version: 5 */ - -/** - * SECTION:element-legacyresample - * - * legacyresample resamples raw audio buffers to different sample rates using - * a configurable windowing function to enhance quality. - * - * <refsect2> - * <title>Example launch line</title> - * |[ - * gst-launch -v filesrc location=sine.ogg ! oggdemux ! vorbisdec ! audioconvert ! legacyresample ! audio/x-raw-int, rate=8000 ! alsasink - * ]| Decode an Ogg/Vorbis downsample to 8Khz and play sound through alsa. - * To create the Ogg/Vorbis file refer to the documentation of vorbisenc. - * </refsect2> - * - * Last reviewed on 2006-03-02 (0.10.4) - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include <string.h> -#include <math.h> - -/*#define DEBUG_ENABLED */ -#include "gstlegacyresample.h" -#include <gst/audio/audio.h> -#include <gst/base/gstbasetransform.h> - -GST_DEBUG_CATEGORY_STATIC (legacyresample_debug); -#define GST_CAT_DEFAULT legacyresample_debug - -#define DEFAULT_FILTERLEN 16 - -enum -{ - PROP_0, - PROP_FILTERLEN -}; - -#define SUPPORTED_CAPS \ -GST_STATIC_CAPS ( \ - "audio/x-raw-int, " \ - "rate = (int) [ 1, MAX ], " \ - "channels = (int) [ 1, MAX ], " \ - "endianness = (int) BYTE_ORDER, " \ - "width = (int) 16, " \ - "depth = (int) 16, " \ - "signed = (boolean) true;" \ - "audio/x-raw-int, " \ - "rate = (int) [ 1, MAX ], " \ - "channels = (int) [ 1, MAX ], " \ - "endianness = (int) BYTE_ORDER, " \ - "width = (int) 32, " \ - "depth = (int) 32, " \ - "signed = (boolean) true;" \ - "audio/x-raw-float, " \ - "rate = (int) [ 1, MAX ], " \ - "channels = (int) [ 1, MAX ], " \ - "endianness = (int) BYTE_ORDER, " \ - "width = (int) 32; " \ - "audio/x-raw-float, " \ - "rate = (int) [ 1, MAX ], " \ - "channels = (int) [ 1, MAX ], " \ - "endianness = (int) BYTE_ORDER, " \ - "width = (int) 64" \ -) - -static GstStaticPadTemplate gst_legacyresample_sink_template = -GST_STATIC_PAD_TEMPLATE ("sink", - GST_PAD_SINK, GST_PAD_ALWAYS, SUPPORTED_CAPS); - -static GstStaticPadTemplate gst_legacyresample_src_template = -GST_STATIC_PAD_TEMPLATE ("src", - GST_PAD_SRC, GST_PAD_ALWAYS, SUPPORTED_CAPS); - -static void gst_legacyresample_set_property (GObject * object, - guint prop_id, const GValue * value, GParamSpec * pspec); -static void gst_legacyresample_get_property (GObject * object, - guint prop_id, GValue * value, GParamSpec * pspec); - -/* vmethods */ -static gboolean legacyresample_get_unit_size (GstBaseTransform * base, - GstCaps * caps, guint * size); -static GstCaps *legacyresample_transform_caps (GstBaseTransform * base, - GstPadDirection direction, GstCaps * caps); -static void legacyresample_fixate_caps (GstBaseTransform * base, - GstPadDirection direction, GstCaps * caps, GstCaps * othercaps); -static gboolean legacyresample_transform_size (GstBaseTransform * trans, - GstPadDirection direction, GstCaps * incaps, guint insize, - GstCaps * outcaps, guint * outsize); -static gboolean legacyresample_set_caps (GstBaseTransform * base, - GstCaps * incaps, GstCaps * outcaps); -static GstFlowReturn legacyresample_pushthrough (GstLegacyresample * - legacyresample); -static GstFlowReturn legacyresample_transform (GstBaseTransform * base, - GstBuffer * inbuf, GstBuffer * outbuf); -static gboolean legacyresample_event (GstBaseTransform * base, - GstEvent * event); -static gboolean legacyresample_start (GstBaseTransform * base); -static gboolean legacyresample_stop (GstBaseTransform * base); - -static gboolean legacyresample_query (GstPad * pad, GstQuery * query); -static const GstQueryType *legacyresample_query_type (GstPad * pad); - -#define DEBUG_INIT(bla) \ - GST_DEBUG_CATEGORY_INIT (legacyresample_debug, "legacyresample", 0, "audio resampling element"); - -GST_BOILERPLATE_FULL (GstLegacyresample, gst_legacyresample, GstBaseTransform, - GST_TYPE_BASE_TRANSFORM, DEBUG_INIT); - -static void -gst_legacyresample_base_init (gpointer g_class) -{ - GstElementClass *gstelement_class = GST_ELEMENT_CLASS (g_class); - - gst_element_class_add_pad_template (gstelement_class, - gst_static_pad_template_get (&gst_legacyresample_src_template)); - gst_element_class_add_pad_template (gstelement_class, - gst_static_pad_template_get (&gst_legacyresample_sink_template)); - - gst_element_class_set_details_simple (gstelement_class, "Audio scaler", - "Filter/Converter/Audio", - "Resample audio", "David Schleef <ds@schleef.org>"); -} - -static void -gst_legacyresample_class_init (GstLegacyresampleClass * klass) -{ - GObjectClass *gobject_class; - - gobject_class = (GObjectClass *) klass; - - gobject_class->set_property = gst_legacyresample_set_property; - gobject_class->get_property = gst_legacyresample_get_property; - - g_object_class_install_property (gobject_class, PROP_FILTERLEN, - g_param_spec_int ("filter-length", "filter length", - "Length of the resample filter", 0, G_MAXINT, DEFAULT_FILTERLEN, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS)); - - GST_BASE_TRANSFORM_CLASS (klass)->start = - GST_DEBUG_FUNCPTR (legacyresample_start); - GST_BASE_TRANSFORM_CLASS (klass)->stop = - GST_DEBUG_FUNCPTR (legacyresample_stop); - GST_BASE_TRANSFORM_CLASS (klass)->transform_size = - GST_DEBUG_FUNCPTR (legacyresample_transform_size); - GST_BASE_TRANSFORM_CLASS (klass)->get_unit_size = - GST_DEBUG_FUNCPTR (legacyresample_get_unit_size); - GST_BASE_TRANSFORM_CLASS (klass)->transform_caps = - GST_DEBUG_FUNCPTR (legacyresample_transform_caps); - GST_BASE_TRANSFORM_CLASS (klass)->fixate_caps = - GST_DEBUG_FUNCPTR (legacyresample_fixate_caps); - GST_BASE_TRANSFORM_CLASS (klass)->set_caps = - GST_DEBUG_FUNCPTR (legacyresample_set_caps); - GST_BASE_TRANSFORM_CLASS (klass)->transform = - GST_DEBUG_FUNCPTR (legacyresample_transform); - GST_BASE_TRANSFORM_CLASS (klass)->event = - GST_DEBUG_FUNCPTR (legacyresample_event); - - GST_BASE_TRANSFORM_CLASS (klass)->passthrough_on_same_caps = TRUE; -} - -static void -gst_legacyresample_init (GstLegacyresample * legacyresample, - GstLegacyresampleClass * klass) -{ - GstBaseTransform *trans; - - trans = GST_BASE_TRANSFORM (legacyresample); - - /* buffer alloc passthrough is too impossible. FIXME, it - * is trivial in the passthrough case. */ - gst_pad_set_bufferalloc_function (trans->sinkpad, NULL); - - legacyresample->filter_length = DEFAULT_FILTERLEN; - - legacyresample->need_discont = FALSE; - - gst_pad_set_query_function (trans->srcpad, legacyresample_query); - gst_pad_set_query_type_function (trans->srcpad, legacyresample_query_type); -} - -/* vmethods */ -static gboolean -legacyresample_start (GstBaseTransform * base) -{ - GstLegacyresample *legacyresample = GST_LEGACYRESAMPLE (base); - - legacyresample->resample = resample_new (); - legacyresample->ts_offset = -1; - legacyresample->offset = -1; - legacyresample->next_ts = -1; - - resample_set_filter_length (legacyresample->resample, - legacyresample->filter_length); - - return TRUE; -} - -static gboolean -legacyresample_stop (GstBaseTransform * base) -{ - GstLegacyresample *legacyresample = GST_LEGACYRESAMPLE (base); - - if (legacyresample->resample) { - resample_free (legacyresample->resample); - legacyresample->resample = NULL; - } - - gst_caps_replace (&legacyresample->sinkcaps, NULL); - gst_caps_replace (&legacyresample->srccaps, NULL); - - return TRUE; -} - -static gboolean -legacyresample_get_unit_size (GstBaseTransform * base, GstCaps * caps, - guint * size) -{ - gint width, channels; - GstStructure *structure; - gboolean ret; - - g_assert (size); - - /* this works for both float and int */ - structure = gst_caps_get_structure (caps, 0); - ret = gst_structure_get_int (structure, "width", &width); - ret &= gst_structure_get_int (structure, "channels", &channels); - g_return_val_if_fail (ret, FALSE); - - *size = width * channels / 8; - - return TRUE; -} - -static GstCaps * -legacyresample_transform_caps (GstBaseTransform * base, - GstPadDirection direction, GstCaps * caps) -{ - const GValue *val; - GstStructure *s; - GstCaps *res; - - /* transform single caps into input_caps + input_caps with the rate - * field set to our supported range. This ensures that upstream knows - * about downstream's prefered rate(s) and can negotiate accordingly. */ - res = gst_caps_copy (caps); - - /* first, however, check if the caps contain a range for the rate field, in - * which case that side isn't going to care much about the exact sample rate - * chosen and we should just assume things will get fixated to something sane - * and we may just as well offer our full range instead of the range in the - * caps. If the rate is not an int range value, it's likely to express a - * real preference or limitation and we should maintain that structure as - * preference by putting it first into the transformed caps, and only add - * our full rate range as second option */ - s = gst_caps_get_structure (res, 0); - val = gst_structure_get_value (s, "rate"); - if (val == NULL || GST_VALUE_HOLDS_INT_RANGE (val)) { - /* overwrite existing range, or add field if it doesn't exist yet */ - gst_structure_set (s, "rate", GST_TYPE_INT_RANGE, 1, G_MAXINT, NULL); - } else { - /* append caps with full range to existing caps with non-range rate field */ - s = gst_structure_copy (s); - gst_structure_set (s, "rate", GST_TYPE_INT_RANGE, 1, G_MAXINT, NULL); - gst_caps_append_structure (res, s); - } - - return res; -} - -/* Fixate rate to the allowed rate that has the smallest difference */ -static void -legacyresample_fixate_caps (GstBaseTransform * base, - GstPadDirection direction, GstCaps * caps, GstCaps * othercaps) -{ - GstStructure *s; - gint rate; - - s = gst_caps_get_structure (caps, 0); - if (!gst_structure_get_int (s, "rate", &rate)) - return; - - s = gst_caps_get_structure (othercaps, 0); - gst_structure_fixate_field_nearest_int (s, "rate", rate); -} - -static gboolean -resample_set_state_from_caps (ResampleState * state, GstCaps * incaps, - GstCaps * outcaps, gint * channels, gint * inrate, gint * outrate) -{ - GstStructure *structure; - gboolean ret; - gint myinrate, myoutrate; - int mychannels; - gint width, depth; - ResampleFormat format; - - GST_DEBUG ("incaps %" GST_PTR_FORMAT ", outcaps %" - GST_PTR_FORMAT, incaps, outcaps); - - structure = gst_caps_get_structure (incaps, 0); - - /* get width */ - ret = gst_structure_get_int (structure, "width", &width); - if (!ret) - goto no_width; - - /* figure out the format */ - if (g_str_equal (gst_structure_get_name (structure), "audio/x-raw-float")) { - if (width == 32) - format = RESAMPLE_FORMAT_F32; - else if (width == 64) - format = RESAMPLE_FORMAT_F64; - else - goto wrong_depth; - } else { - /* for int, depth and width must be the same */ - ret = gst_structure_get_int (structure, "depth", &depth); - if (!ret || width != depth) - goto not_equal; - - if (width == 16) - format = RESAMPLE_FORMAT_S16; - else if (width == 32) - format = RESAMPLE_FORMAT_S32; - else - goto wrong_depth; - } - ret = gst_structure_get_int (structure, "rate", &myinrate); - ret &= gst_structure_get_int (structure, "channels", &mychannels); - if (!ret) - goto no_in_rate_channels; - - structure = gst_caps_get_structure (outcaps, 0); - ret = gst_structure_get_int (structure, "rate", &myoutrate); - if (!ret) - goto no_out_rate; - - if (channels) - *channels = mychannels; - if (inrate) - *inrate = myinrate; - if (outrate) - *outrate = myoutrate; - - resample_set_format (state, format); - resample_set_n_channels (state, mychannels); - resample_set_input_rate (state, myinrate); - resample_set_output_rate (state, myoutrate); - - return TRUE; - - /* ERRORS */ -no_width: - { - GST_DEBUG ("failed to get width from caps"); - return FALSE; - } -not_equal: - { - GST_DEBUG ("width %d and depth %d must be the same", width, depth); - return FALSE; - } -wrong_depth: - { - GST_DEBUG ("unknown depth %d found", depth); - return FALSE; - } -no_in_rate_channels: - { - GST_DEBUG ("could not get input rate and channels"); - return FALSE; - } -no_out_rate: - { - GST_DEBUG ("could not get output rate"); - return FALSE; - } -} - -static gboolean -legacyresample_transform_size (GstBaseTransform * base, - GstPadDirection direction, GstCaps * caps, guint size, GstCaps * othercaps, - guint * othersize) -{ - GstLegacyresample *legacyresample = GST_LEGACYRESAMPLE (base); - ResampleState *state; - GstCaps *srccaps, *sinkcaps; - gboolean use_internal = FALSE; /* whether we use the internal state */ - gboolean ret = TRUE; - - GST_LOG_OBJECT (base, "asked to transform size %d in direction %s", - size, direction == GST_PAD_SINK ? "SINK" : "SRC"); - if (direction == GST_PAD_SINK) { - sinkcaps = caps; - srccaps = othercaps; - } else { - sinkcaps = othercaps; - srccaps = caps; - } - - /* if the caps are the ones that _set_caps got called with; we can use - * our own state; otherwise we'll have to create a state */ - if (gst_caps_is_equal (sinkcaps, legacyresample->sinkcaps) && - gst_caps_is_equal (srccaps, legacyresample->srccaps)) { - use_internal = TRUE; - state = legacyresample->resample; - } else { - GST_DEBUG_OBJECT (legacyresample, - "caps are not the set caps, creating state"); - state = resample_new (); - resample_set_filter_length (state, legacyresample->filter_length); - resample_set_state_from_caps (state, sinkcaps, srccaps, NULL, NULL, NULL); - } - - if (direction == GST_PAD_SINK) { - /* asked to convert size of an incoming buffer */ - *othersize = resample_get_output_size_for_input (state, size); - } else { - /* asked to convert size of an outgoing buffer */ - *othersize = resample_get_input_size_for_output (state, size); - } - g_assert (*othersize % state->sample_size == 0); - - /* we make room for one extra sample, given that the resampling filter - * can output an extra one for non-integral i_rate/o_rate */ - GST_LOG_OBJECT (base, "transformed size %d to %d", size, *othersize); - - if (!use_internal) { - resample_free (state); - } - - return ret; -} - -static gboolean -legacyresample_set_caps (GstBaseTransform * base, GstCaps * incaps, - GstCaps * outcaps) -{ - gboolean ret; - gint inrate, outrate; - int channels; - GstLegacyresample *legacyresample = GST_LEGACYRESAMPLE (base); - - GST_DEBUG_OBJECT (base, "incaps %" GST_PTR_FORMAT ", outcaps %" - GST_PTR_FORMAT, incaps, outcaps); - - ret = resample_set_state_from_caps (legacyresample->resample, incaps, outcaps, - &channels, &inrate, &outrate); - - g_return_val_if_fail (ret, FALSE); - - legacyresample->channels = channels; - GST_DEBUG_OBJECT (legacyresample, "set channels to %d", channels); - legacyresample->i_rate = inrate; - GST_DEBUG_OBJECT (legacyresample, "set i_rate to %d", inrate); - legacyresample->o_rate = outrate; - GST_DEBUG_OBJECT (legacyresample, "set o_rate to %d", outrate); - - /* save caps so we can short-circuit in the size_transform if the caps - * are the same */ - gst_caps_replace (&legacyresample->sinkcaps, incaps); - gst_caps_replace (&legacyresample->srccaps, outcaps); - - return TRUE; -} - -static gboolean -legacyresample_event (GstBaseTransform * base, GstEvent * event) -{ - GstLegacyresample *legacyresample; - - legacyresample = GST_LEGACYRESAMPLE (base); - - switch (GST_EVENT_TYPE (event)) { - case GST_EVENT_FLUSH_START: - break; - case GST_EVENT_FLUSH_STOP: - if (legacyresample->resample) - resample_input_flush (legacyresample->resample); - legacyresample->ts_offset = -1; - legacyresample->next_ts = -1; - legacyresample->offset = -1; - break; - case GST_EVENT_NEWSEGMENT: - resample_input_pushthrough (legacyresample->resample); - legacyresample_pushthrough (legacyresample); - legacyresample->ts_offset = -1; - legacyresample->next_ts = -1; - legacyresample->offset = -1; - break; - case GST_EVENT_EOS: - resample_input_eos (legacyresample->resample); - legacyresample_pushthrough (legacyresample); - break; - default: - break; - } - return parent_class->event (base, event); -} - -static GstFlowReturn -legacyresample_do_output (GstLegacyresample * legacyresample, - GstBuffer * outbuf) -{ - int outsize; - int outsamples; - ResampleState *r; - - r = legacyresample->resample; - - outsize = resample_get_output_size (r); - GST_LOG_OBJECT (legacyresample, "legacyresample can give me %d bytes", - outsize); - - /* protect against mem corruption */ - if (outsize > GST_BUFFER_SIZE (outbuf)) { - GST_WARNING_OBJECT (legacyresample, - "overriding legacyresample's outsize %d with outbuffer's size %d", - outsize, GST_BUFFER_SIZE (outbuf)); - outsize = GST_BUFFER_SIZE (outbuf); - } - /* catch possibly wrong size differences */ - if (GST_BUFFER_SIZE (outbuf) - outsize > r->sample_size) { - GST_WARNING_OBJECT (legacyresample, - "legacyresample's outsize %d too far from outbuffer's size %d", - outsize, GST_BUFFER_SIZE (outbuf)); - } - - outsize = resample_get_output_data (r, GST_BUFFER_DATA (outbuf), outsize); - outsamples = outsize / r->sample_size; - GST_LOG_OBJECT (legacyresample, "resample gave me %d bytes or %d samples", - outsize, outsamples); - - GST_BUFFER_OFFSET (outbuf) = legacyresample->offset; - GST_BUFFER_TIMESTAMP (outbuf) = legacyresample->next_ts; - - if (legacyresample->ts_offset != -1) { - legacyresample->offset += outsamples; - legacyresample->ts_offset += outsamples; - legacyresample->next_ts = - gst_util_uint64_scale_int (legacyresample->ts_offset, GST_SECOND, - legacyresample->o_rate); - GST_BUFFER_OFFSET_END (outbuf) = legacyresample->offset; - - /* we calculate DURATION as the difference between "next" timestamp - * and current timestamp so we ensure a contiguous stream, instead of - * having rounding errors. */ - GST_BUFFER_DURATION (outbuf) = legacyresample->next_ts - - GST_BUFFER_TIMESTAMP (outbuf); - } else { - /* no valid offset know, we can still sortof calculate the duration though */ - GST_BUFFER_DURATION (outbuf) = - gst_util_uint64_scale_int (outsamples, GST_SECOND, - legacyresample->o_rate); - } - - /* check for possible mem corruption */ - if (outsize > GST_BUFFER_SIZE (outbuf)) { - /* this is an error that when it happens, would need fixing in the - * resample library; we told it we wanted only GST_BUFFER_SIZE (outbuf), - * and it gave us more ! */ - GST_WARNING_OBJECT (legacyresample, - "legacyresample, you memory corrupting bastard. " - "you gave me outsize %d while my buffer was size %d", - outsize, GST_BUFFER_SIZE (outbuf)); - return GST_FLOW_ERROR; - } - /* catch possibly wrong size differences */ - if (GST_BUFFER_SIZE (outbuf) - outsize > r->sample_size) { - GST_WARNING_OBJECT (legacyresample, - "legacyresample's written outsize %d too far from outbuffer's size %d", - outsize, GST_BUFFER_SIZE (outbuf)); - } - GST_BUFFER_SIZE (outbuf) = outsize; - - if (G_UNLIKELY (legacyresample->need_discont)) { - GST_DEBUG_OBJECT (legacyresample, - "marking this buffer with the DISCONT flag"); - GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_FLAG_DISCONT); - legacyresample->need_discont = FALSE; - } - - GST_LOG_OBJECT (legacyresample, "transformed to buffer of %d bytes, ts %" - GST_TIME_FORMAT ", duration %" GST_TIME_FORMAT ", offset %" - G_GINT64_FORMAT ", offset_end %" G_GINT64_FORMAT, - outsize, GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (outbuf)), - GST_TIME_ARGS (GST_BUFFER_DURATION (outbuf)), - GST_BUFFER_OFFSET (outbuf), GST_BUFFER_OFFSET_END (outbuf)); - - - return GST_FLOW_OK; -} - -static gboolean -legacyresample_check_discont (GstLegacyresample * legacyresample, - GstClockTime timestamp) -{ - if (timestamp != GST_CLOCK_TIME_NONE && - legacyresample->prev_ts != GST_CLOCK_TIME_NONE && - legacyresample->prev_duration != GST_CLOCK_TIME_NONE && - timestamp != legacyresample->prev_ts + legacyresample->prev_duration) { - /* Potentially a discontinuous buffer. However, it turns out that many - * elements generate imperfect streams due to rounding errors, so we permit - * a small error (up to one sample) without triggering a filter - * flush/restart (if triggered incorrectly, this will be audible) */ - GstClockTimeDiff diff = timestamp - - (legacyresample->prev_ts + legacyresample->prev_duration); - - if (ABS (diff) > GST_SECOND / legacyresample->i_rate) { - GST_WARNING_OBJECT (legacyresample, - "encountered timestamp discontinuity of %" G_GINT64_FORMAT, diff); - return TRUE; - } - } - - return FALSE; -} - -static GstFlowReturn -legacyresample_transform (GstBaseTransform * base, GstBuffer * inbuf, - GstBuffer * outbuf) -{ - GstLegacyresample *legacyresample; - ResampleState *r; - guchar *data, *datacopy; - gulong size; - GstClockTime timestamp; - - legacyresample = GST_LEGACYRESAMPLE (base); - r = legacyresample->resample; - - data = GST_BUFFER_DATA (inbuf); - size = GST_BUFFER_SIZE (inbuf); - timestamp = GST_BUFFER_TIMESTAMP (inbuf); - - GST_LOG_OBJECT (legacyresample, "transforming buffer of %ld bytes, ts %" - GST_TIME_FORMAT ", duration %" GST_TIME_FORMAT ", offset %" - G_GINT64_FORMAT ", offset_end %" G_GINT64_FORMAT, - size, GST_TIME_ARGS (timestamp), - GST_TIME_ARGS (GST_BUFFER_DURATION (inbuf)), - GST_BUFFER_OFFSET (inbuf), GST_BUFFER_OFFSET_END (inbuf)); - - /* check for timestamp discontinuities and flush/reset if needed */ - if (G_UNLIKELY (legacyresample_check_discont (legacyresample, timestamp))) { - /* Flush internal samples */ - legacyresample_pushthrough (legacyresample); - /* Inform downstream element about discontinuity */ - legacyresample->need_discont = TRUE; - /* We want to recalculate the offset */ - legacyresample->ts_offset = -1; - } - - if (legacyresample->ts_offset == -1) { - /* if we don't know the initial offset yet, calculate it based on the - * input timestamp. */ - if (GST_CLOCK_TIME_IS_VALID (timestamp)) { - GstClockTime stime; - - /* offset used to calculate the timestamps. We use the sample offset for - * this to make it more accurate. We want the first buffer to have the - * same timestamp as the incoming timestamp. */ - legacyresample->next_ts = timestamp; - legacyresample->ts_offset = - gst_util_uint64_scale_int (timestamp, r->o_rate, GST_SECOND); - /* offset used to set as the buffer offset, this offset is always - * relative to the stream time, note that timestamp is not... */ - stime = (timestamp - base->segment.start) + base->segment.time; - legacyresample->offset = - gst_util_uint64_scale_int (stime, r->o_rate, GST_SECOND); - } - } - legacyresample->prev_ts = timestamp; - legacyresample->prev_duration = GST_BUFFER_DURATION (inbuf); - - /* need to memdup, resample takes ownership. */ - datacopy = g_memdup (data, size); - resample_add_input_data (r, datacopy, size, g_free, datacopy); - - return legacyresample_do_output (legacyresample, outbuf); -} - -/* push remaining data in the buffers out */ -static GstFlowReturn -legacyresample_pushthrough (GstLegacyresample * legacyresample) -{ - int outsize; - ResampleState *r; - GstBuffer *outbuf; - GstFlowReturn res = GST_FLOW_OK; - GstBaseTransform *trans; - - r = legacyresample->resample; - - outsize = resample_get_output_size (r); - if (outsize == 0) { - GST_DEBUG_OBJECT (legacyresample, "no internal buffers needing flush"); - goto done; - } - - trans = GST_BASE_TRANSFORM (legacyresample); - - res = gst_pad_alloc_buffer (trans->srcpad, GST_BUFFER_OFFSET_NONE, outsize, - GST_PAD_CAPS (trans->srcpad), &outbuf); - if (G_UNLIKELY (res != GST_FLOW_OK)) { - GST_WARNING_OBJECT (legacyresample, "failed allocating buffer of %d bytes", - outsize); - goto done; - } - - res = legacyresample_do_output (legacyresample, outbuf); - if (G_UNLIKELY (res != GST_FLOW_OK)) - goto done; - - res = gst_pad_push (trans->srcpad, outbuf); - -done: - return res; -} - -static gboolean -legacyresample_query (GstPad * pad, GstQuery * query) -{ - GstLegacyresample *legacyresample = - GST_LEGACYRESAMPLE (gst_pad_get_parent (pad)); - GstBaseTransform *trans = GST_BASE_TRANSFORM (legacyresample); - gboolean res = TRUE; - - switch (GST_QUERY_TYPE (query)) { - case GST_QUERY_LATENCY: - { - GstClockTime min, max; - gboolean live; - guint64 latency; - GstPad *peer; - gint rate = legacyresample->i_rate; - gint resampler_latency = legacyresample->filter_length / 2; - - if (gst_base_transform_is_passthrough (trans)) - resampler_latency = 0; - - if ((peer = gst_pad_get_peer (trans->sinkpad))) { - if ((res = gst_pad_query (peer, query))) { - gst_query_parse_latency (query, &live, &min, &max); - - GST_DEBUG ("Peer latency: min %" - GST_TIME_FORMAT " max %" GST_TIME_FORMAT, - GST_TIME_ARGS (min), GST_TIME_ARGS (max)); - - /* add our own latency */ - if (rate != 0 && resampler_latency != 0) - latency = - gst_util_uint64_scale (resampler_latency, GST_SECOND, rate); - else - latency = 0; - - GST_DEBUG ("Our latency: %" GST_TIME_FORMAT, GST_TIME_ARGS (latency)); - - min += latency; - if (max != GST_CLOCK_TIME_NONE) - max += latency; - - GST_DEBUG ("Calculated total latency : min %" - GST_TIME_FORMAT " max %" GST_TIME_FORMAT, - GST_TIME_ARGS (min), GST_TIME_ARGS (max)); - - gst_query_set_latency (query, live, min, max); - } - gst_object_unref (peer); - } - break; - } - default: - res = gst_pad_query_default (pad, query); - break; - } - gst_object_unref (legacyresample); - return res; -} - -static const GstQueryType * -legacyresample_query_type (GstPad * pad) -{ - static const GstQueryType types[] = { - GST_QUERY_LATENCY, - 0 - }; - - return types; -} - -static void -gst_legacyresample_set_property (GObject * object, guint prop_id, - const GValue * value, GParamSpec * pspec) -{ - GstLegacyresample *legacyresample; - - legacyresample = GST_LEGACYRESAMPLE (object); - - switch (prop_id) { - case PROP_FILTERLEN: - legacyresample->filter_length = g_value_get_int (value); - GST_DEBUG_OBJECT (GST_ELEMENT (legacyresample), "new filter length %d", - legacyresample->filter_length); - if (legacyresample->resample) { - resample_set_filter_length (legacyresample->resample, - legacyresample->filter_length); - gst_element_post_message (GST_ELEMENT (legacyresample), - gst_message_new_latency (GST_OBJECT (legacyresample))); - } - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static void -gst_legacyresample_get_property (GObject * object, guint prop_id, - GValue * value, GParamSpec * pspec) -{ - GstLegacyresample *legacyresample; - - legacyresample = GST_LEGACYRESAMPLE (object); - - switch (prop_id) { - case PROP_FILTERLEN: - g_value_set_int (value, legacyresample->filter_length); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - - -static gboolean -plugin_init (GstPlugin * plugin) -{ - resample_init (); - - if (!gst_element_register (plugin, "legacyresample", GST_RANK_MARGINAL, - GST_TYPE_LEGACYRESAMPLE)) { - return FALSE; - } - - return TRUE; -} - -GST_PLUGIN_DEFINE (GST_VERSION_MAJOR, - GST_VERSION_MINOR, - legacyresample, - "Resamples audio", plugin_init, VERSION, "LGPL", GST_PACKAGE_NAME, - GST_PACKAGE_ORIGIN); diff --git a/gst/legacyresample/gstlegacyresample.h b/gst/legacyresample/gstlegacyresample.h deleted file mode 100644 index 59babc171..000000000 --- a/gst/legacyresample/gstlegacyresample.h +++ /dev/null @@ -1,79 +0,0 @@ -/* GStreamer - * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - - -#ifndef __LEGACYRESAMPLE_H__ -#define __LEGACYRESAMPLE_H__ - -#include <gst/gst.h> -#include <gst/base/gstbasetransform.h> - -#include "resample.h" - -G_BEGIN_DECLS - -#define GST_TYPE_LEGACYRESAMPLE \ - (gst_legacyresample_get_type()) -#define GST_LEGACYRESAMPLE(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_LEGACYRESAMPLE,GstLegacyresample)) -#define GST_LEGACYRESAMPLE_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_LEGACYRESAMPLE,GstLegacyresampleClass)) -#define GST_IS_LEGACYRESAMPLE(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_LEGACYRESAMPLE)) -#define GST_IS_LEGACYRESAMPLE_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_LEGACYRESAMPLE)) - -typedef struct _GstLegacyresample GstLegacyresample; -typedef struct _GstLegacyresampleClass GstLegacyresampleClass; - -/** - * GstLegacyresample: - * - * Opaque data structure. - */ -struct _GstLegacyresample { - GstBaseTransform element; - - GstCaps *srccaps, *sinkcaps; - - gboolean passthru; - gboolean need_discont; - - guint64 offset; - guint64 ts_offset; - GstClockTime next_ts; - GstClockTime prev_ts, prev_duration; - int channels; - - int i_rate; - int o_rate; - int filter_length; - - ResampleState * resample; -}; - -struct _GstLegacyresampleClass { - GstBaseTransformClass parent_class; -}; - -GType gst_legacyresample_get_type(void); - -G_END_DECLS - -#endif /* __LEGACYRESAMPLE_H__ */ diff --git a/gst/legacyresample/resample.c b/gst/legacyresample/resample.c deleted file mode 100644 index 0de6524db..000000000 --- a/gst/legacyresample/resample.c +++ /dev/null @@ -1,312 +0,0 @@ -/* Resampling library - * Copyright (C) <2001> David A. Schleef <ds@schleef.org> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - - -#include <string.h> -#include <math.h> -#include <stdio.h> -#include <stdlib.h> -#include <limits.h> - -#include "resample.h" -#include "buffer.h" -#include "debug.h" - -GST_DEBUG_CATEGORY (libaudioresample_debug); - -void -resample_init (void) -{ - static int inited = 0; - - if (!inited) { - inited = 1; - GST_DEBUG_CATEGORY_INIT (libaudioresample_debug, "libaudioresample", 0, - "audio resampling library"); - - } -} - -ResampleState * -resample_new (void) -{ - ResampleState *r; - - r = malloc (sizeof (ResampleState)); - memset (r, 0, sizeof (ResampleState)); - - r->filter_length = 16; - - r->i_start = 0; - if (r->filter_length & 1) { - r->o_start = 0; - } else { - r->o_start = r->o_inc * 0.5; - } - - r->queue = audioresample_buffer_queue_new (); - r->out_tmp = malloc (10000 * sizeof (double)); - - r->need_reinit = 1; - - return r; -} - -void -resample_free (ResampleState * r) -{ - if (r->buffer) { - free (r->buffer); - } - if (r->ft) { - functable_free (r->ft); - } - if (r->queue) { - audioresample_buffer_queue_free (r->queue); - } - if (r->out_tmp) { - free (r->out_tmp); - } - - free (r); -} - -static void -resample_buffer_free (AudioresampleBuffer * buffer, void *priv) -{ - if (buffer->priv2) { - ((void (*)(void *)) buffer->priv2) (buffer->priv); - } -} - -/* - * free_func: a function that frees the given closure. If NULL, caller is - * responsible for freeing. - */ -void -resample_add_input_data (ResampleState * r, void *data, int size, - void (*free_func) (void *), void *closure) -{ - AudioresampleBuffer *buffer; - - RESAMPLE_DEBUG ("data %p size %d", data, size); - - buffer = audioresample_buffer_new_with_data (data, size); - buffer->free = resample_buffer_free; - buffer->priv2 = (void *) free_func; - buffer->priv = closure; - - audioresample_buffer_queue_push (r->queue, buffer); -} - -void -resample_input_flush (ResampleState * r) -{ - RESAMPLE_DEBUG ("flush"); - - audioresample_buffer_queue_flush (r->queue); - r->buffer_filled = 0; - r->need_reinit = 1; -} - -void -resample_input_pushthrough (ResampleState * r) -{ - AudioresampleBuffer *buffer; - int filter_bytes; - int buffer_filled; - - if (r->sample_size == 0) - return; - - filter_bytes = r->filter_length * r->sample_size; - buffer_filled = r->buffer_filled; - - RESAMPLE_DEBUG ("pushthrough filter_bytes %d, filled %d", - filter_bytes, buffer_filled); - - /* if we have no pending samples, we don't need to do anything. */ - if (buffer_filled <= 0) - return; - - /* send filter_length/2 number of samples so we can get to the - * last queued samples */ - buffer = audioresample_buffer_new_and_alloc (filter_bytes / 2); - memset (buffer->data, 0, buffer->length); - - RESAMPLE_DEBUG ("pushthrough %u", buffer->length); - - audioresample_buffer_queue_push (r->queue, buffer); -} - -void -resample_input_eos (ResampleState * r) -{ - RESAMPLE_DEBUG ("EOS"); - resample_input_pushthrough (r); - r->eos = 1; -} - -int -resample_get_output_size_for_input (ResampleState * r, int size) -{ - int outsize; - double outd; - int avail; - int filter_bytes; - int buffer_filled; - - if (r->sample_size == 0) - return 0; - - filter_bytes = r->filter_length * r->sample_size; - buffer_filled = filter_bytes / 2 - r->buffer_filled / 2; - - avail = - audioresample_buffer_queue_get_depth (r->queue) + size - buffer_filled; - - RESAMPLE_DEBUG ("avail %d, o_rate %f, i_rate %f, filter_bytes %d, filled %d", - avail, r->o_rate, r->i_rate, filter_bytes, buffer_filled); - if (avail <= 0) - return 0; - - outd = (double) avail *r->o_rate / r->i_rate; - - outsize = (int) floor (outd); - - /* round off for sample size */ - outsize -= outsize % r->sample_size; - - return outsize; -} - -int -resample_get_input_size_for_output (ResampleState * r, int size) -{ - int outsize; - double outd; - int avail; - - if (r->sample_size == 0) - return 0; - - avail = size; - - RESAMPLE_DEBUG ("size %d, o_rate %f, i_rate %f", avail, r->o_rate, r->i_rate); - outd = (double) avail *r->i_rate / r->o_rate; - - outsize = (int) ceil (outd); - - /* round off for sample size */ - outsize -= outsize % r->sample_size; - - return outsize; -} - -int -resample_get_output_size (ResampleState * r) -{ - return resample_get_output_size_for_input (r, 0); -} - -int -resample_get_output_data (ResampleState * r, void *data, int size) -{ - r->o_buf = data; - r->o_size = size; - - if (size == 0) - return 0; - - switch (r->method) { - case 0: - resample_scale_ref (r); - break; - case 1: - resample_scale_functable (r); - break; - default: - break; - } - - return size - r->o_size; -} - -void -resample_set_filter_length (ResampleState * r, int length) -{ - r->filter_length = length; - r->need_reinit = 1; -} - -void -resample_set_input_rate (ResampleState * r, double rate) -{ - r->i_rate = rate; - r->need_reinit = 1; -} - -void -resample_set_output_rate (ResampleState * r, double rate) -{ - r->o_rate = rate; - r->need_reinit = 1; -} - -void -resample_set_n_channels (ResampleState * r, int n_channels) -{ - r->n_channels = n_channels; - r->sample_size = r->n_channels * resample_format_size (r->format); - r->need_reinit = 1; -} - -void -resample_set_format (ResampleState * r, ResampleFormat format) -{ - r->format = format; - r->sample_size = r->n_channels * resample_format_size (r->format); - r->need_reinit = 1; -} - -void -resample_set_method (ResampleState * r, int method) -{ - r->method = method; - r->need_reinit = 1; -} - -int -resample_format_size (ResampleFormat format) -{ - switch (format) { - case RESAMPLE_FORMAT_S16: - return 2; - case RESAMPLE_FORMAT_S32: - case RESAMPLE_FORMAT_F32: - return 4; - case RESAMPLE_FORMAT_F64: - return 8; - } - return 0; -} diff --git a/gst/legacyresample/resample.h b/gst/legacyresample/resample.h deleted file mode 100644 index ba14983b6..000000000 --- a/gst/legacyresample/resample.h +++ /dev/null @@ -1,131 +0,0 @@ -/* Resampling library - * Copyright (C) <2001> David Schleef <ds@schleef.org> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - - -#ifndef __RESAMPLE_H__ -#define __RESAMPLE_H__ - -#include "functable.h" -#include "buffer.h" - -#ifndef M_PI -#define M_PI 3.14159265358979323846 -#endif - -#ifdef WIN32 -#define rint(x) (floor((x)+0.5)) -#endif - -typedef enum { - RESAMPLE_FORMAT_S16 = 0, - RESAMPLE_FORMAT_S32, - RESAMPLE_FORMAT_F32, - RESAMPLE_FORMAT_F64 -} ResampleFormat; - -typedef void (*ResampleCallback) (void *); - -typedef struct _ResampleState ResampleState; - -struct _ResampleState { - /* parameters */ - - int n_channels; - ResampleFormat format; - - int filter_length; - - double i_rate; - double o_rate; - - int method; - - /* internal parameters */ - - int need_reinit; - - double halftaps; - - /* filter state */ - - unsigned char *o_buf; - int o_size; - - AudioresampleBufferQueue *queue; - int eos; - int started; - - int sample_size; - - unsigned char *buffer; - int buffer_len; - int buffer_filled; - - double i_start; - double o_start; - - double i_inc; - double o_inc; - - double sinc_scale; - - double i_end; - double o_end; - - int i_samples; - int o_samples; - - //void *i_buf; - - Functable *ft; - - double *out_tmp; -}; - -void resample_init (void); -void resample_cleanup (void); - -ResampleState *resample_new (void); -void resample_free (ResampleState *state); - -void resample_add_input_data (ResampleState * r, void *data, int size, - ResampleCallback free_func, void *closure); -void resample_input_eos (ResampleState *r); -void resample_input_flush (ResampleState *r); -void resample_input_pushthrough (ResampleState *r); - -int resample_get_output_size_for_input (ResampleState * r, int size); -int resample_get_input_size_for_output (ResampleState * r, int size); - -int resample_get_output_size (ResampleState *r); -int resample_get_output_data (ResampleState *r, void *data, int size); - -void resample_set_filter_length (ResampleState *r, int length); -void resample_set_input_rate (ResampleState *r, double rate); -void resample_set_output_rate (ResampleState *r, double rate); -void resample_set_n_channels (ResampleState *r, int n_channels); -void resample_set_format (ResampleState *r, ResampleFormat format); -void resample_set_method (ResampleState *r, int method); -int resample_format_size (ResampleFormat format); - -void resample_scale_ref (ResampleState * r); -void resample_scale_functable (ResampleState * r); - -#endif /* __RESAMPLE_H__ */ - diff --git a/gst/legacyresample/resample_functable.c b/gst/legacyresample/resample_functable.c deleted file mode 100644 index fc3e38a8b..000000000 --- a/gst/legacyresample/resample_functable.c +++ /dev/null @@ -1,274 +0,0 @@ -/* Resampling library - * Copyright (C) <2001> David A. Schleef <ds@schleef.org> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - - -#include <string.h> -#include <math.h> -#include <stdio.h> -#include <stdlib.h> -#include <limits.h> - -#include <gst/math-compat.h> - -#include "_stdint.h" - -#include "resample.h" -#include "buffer.h" -#include "debug.h" - -static void -func_sinc (double *fx, double *dfx, double x, void *closure) -{ - //double scale = *(double *)closure; - double scale = M_PI; - - if (x == 0) { - *fx = 1; - *dfx = 0; - return; - } - - x *= scale; - *fx = sin (x) / x; - *dfx = scale * (cos (x) - sin (x) / x) / x; -} - -static void -func_hanning (double *fx, double *dfx, double x, void *closure) -{ - double width = *(double *) closure; - - if (x < width && x > -width) { - x /= width; - *fx = (1 - x * x) * (1 - x * x); - *dfx = -2 * 2 * x / width * (1 - x * x); - } else { - *fx = 0; - *dfx = 0; - } -} - -#if 0 -static double -resample_sinc_window (double x, double halfwidth, double scale) -{ - double y; - - if (x == 0) - return 1.0; - if (x < -halfwidth || x > halfwidth) - return 0.0; - - y = sin (x * M_PI * scale) / (x * M_PI * scale) * scale; - - x /= halfwidth; - y *= (1 - x * x) * (1 - x * x); - - return y; -} -#endif - -#if 0 -static void -functable_test (Functable * ft, double halfwidth) -{ - int i; - double x; - - for (i = 0; i < 100; i++) { - x = i * 0.1; - printf ("%d %g %g\n", i, resample_sinc_window (x, halfwidth, 1.0), - functable_evaluate (ft, x)); - } - exit (0); - -} -#endif - - -void -resample_scale_functable (ResampleState * r) -{ - if (r->need_reinit) { - double hanning_width; - - RESAMPLE_DEBUG ("sample size %d", r->sample_size); - - if (r->buffer) - free (r->buffer); - r->buffer_len = r->sample_size * r->filter_length; - r->buffer = malloc (r->buffer_len); - memset (r->buffer, 0, r->buffer_len); - - r->i_inc = r->o_rate / r->i_rate; - r->o_inc = r->i_rate / r->o_rate; - RESAMPLE_DEBUG ("i_inc %g o_inc %g", r->i_inc, r->o_inc); - - r->i_start = -r->i_inc * r->filter_length; - - if (r->ft) { - functable_free (r->ft); - } - r->ft = functable_new (); - functable_set_length (r->ft, r->filter_length * 16); - functable_set_offset (r->ft, -r->filter_length / 2); - functable_set_multiplier (r->ft, 1 / 16.0); - - hanning_width = r->filter_length / 2; - functable_calculate (r->ft, func_sinc, NULL); - functable_calculate_multiply (r->ft, func_hanning, &hanning_width); - - //functable_test(r->ft, 0.5 * r->filter_length); -#if 0 - if (r->i_inc < 1.0) { - r->sinc_scale = r->i_inc; - if (r->sinc_scale == 0.5) { - /* strange things happen at integer multiples */ - r->sinc_scale = 1.0; - } - } else { - r->sinc_scale = 1.0; - } -#else - r->sinc_scale = 1.0; -#endif - - r->need_reinit = 0; - } - - while (r->o_size > 0) { - double midpoint; - int i; - int j; - - RESAMPLE_DEBUG ("i_start %g", r->i_start); - midpoint = r->i_start + (r->filter_length - 1) * 0.5 * r->i_inc; - if (midpoint > 0.5 * r->i_inc) { - RESAMPLE_ERROR ("inconsistent state"); - } - while (midpoint < -0.5 * r->i_inc) { - AudioresampleBuffer *buffer; - - buffer = audioresample_buffer_queue_pull (r->queue, r->sample_size); - if (buffer == NULL) { - RESAMPLE_ERROR ("buffer_queue_pull returned NULL"); - return; - } - - r->i_start += r->i_inc; - RESAMPLE_DEBUG ("pulling (i_start = %g)", r->i_start); - - midpoint += r->i_inc; - memmove (r->buffer, r->buffer + r->sample_size, - r->buffer_len - r->sample_size); - - memcpy (r->buffer + r->buffer_len - r->sample_size, buffer->data, - r->sample_size); - audioresample_buffer_unref (buffer); - } - - switch (r->format) { - case RESAMPLE_FORMAT_S16: - for (i = 0; i < r->n_channels; i++) { - double acc = 0; - double offset; - double x; - - for (j = 0; j < r->filter_length; j++) { - offset = (r->i_start + j * r->i_inc) * r->o_inc; - x = *(int16_t *) (r->buffer + i * sizeof (int16_t) + - j * r->sample_size); - acc += functable_evaluate (r->ft, offset) * x; - //acc += resample_sinc_window (offset, r->filter_length * 0.5, r->sinc_scale) * x; - } - if (acc < -32768.0) - acc = -32768.0; - if (acc > 32767.0) - acc = 32767.0; - - *(int16_t *) (r->o_buf + i * sizeof (int16_t)) = rint (acc); - } - break; - case RESAMPLE_FORMAT_S32: - for (i = 0; i < r->n_channels; i++) { - double acc = 0; - double offset; - double x; - - for (j = 0; j < r->filter_length; j++) { - offset = (r->i_start + j * r->i_inc) * r->o_inc; - x = *(int32_t *) (r->buffer + i * sizeof (int32_t) + - j * r->sample_size); - acc += functable_evaluate (r->ft, offset) * x; - //acc += resample_sinc_window (offset, r->filter_length * 0.5, r->sinc_scale) * x; - } - if (acc < -2147483648.0) - acc = -2147483648.0; - if (acc > 2147483647.0) - acc = 2147483647.0; - - *(int32_t *) (r->o_buf + i * sizeof (int32_t)) = rint (acc); - } - break; - case RESAMPLE_FORMAT_F32: - for (i = 0; i < r->n_channels; i++) { - double acc = 0; - double offset; - double x; - - for (j = 0; j < r->filter_length; j++) { - offset = (r->i_start + j * r->i_inc) * r->o_inc; - x = *(float *) (r->buffer + i * sizeof (float) + - j * r->sample_size); - acc += functable_evaluate (r->ft, offset) * x; - //acc += resample_sinc_window (offset, r->filter_length * 0.5, r->sinc_scale) * x; - } - - *(float *) (r->o_buf + i * sizeof (float)) = acc; - } - break; - case RESAMPLE_FORMAT_F64: - for (i = 0; i < r->n_channels; i++) { - double acc = 0; - double offset; - double x; - - for (j = 0; j < r->filter_length; j++) { - offset = (r->i_start + j * r->i_inc) * r->o_inc; - x = *(double *) (r->buffer + i * sizeof (double) + - j * r->sample_size); - acc += functable_evaluate (r->ft, offset) * x; - //acc += resample_sinc_window (offset, r->filter_length * 0.5, r->sinc_scale) * x; - } - - *(double *) (r->o_buf + i * sizeof (double)) = acc; - } - break; - } - - r->i_start -= 1.0; - r->o_buf += r->sample_size; - r->o_size -= r->sample_size; - } - -} diff --git a/gst/legacyresample/resample_ref.c b/gst/legacyresample/resample_ref.c deleted file mode 100644 index 546e7cc9c..000000000 --- a/gst/legacyresample/resample_ref.c +++ /dev/null @@ -1,224 +0,0 @@ -/* Resampling library - * Copyright (C) <2001> David A. Schleef <ds@schleef.org> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - - -#include <string.h> -#include <math.h> -#include <stdio.h> -#include <stdlib.h> -#include <limits.h> - -#include <gst/math-compat.h> -#include "_stdint.h" - -#include "resample.h" -#include "buffer.h" -#include "debug.h" - -static double -resample_sinc_window (double x, double halfwidth, double scale) -{ - double y; - - if (x == 0) - return 1.0; - if (x < -halfwidth || x > halfwidth) - return 0.0; - - y = sin (x * M_PI * scale) / (x * M_PI * scale) * scale; - - x /= halfwidth; - y *= (1 - x * x) * (1 - x * x); - - return y; -} - -void -resample_scale_ref (ResampleState * r) -{ - if (r->need_reinit) { - RESAMPLE_DEBUG ("sample size %d", r->sample_size); - - if (r->buffer) - free (r->buffer); - r->buffer_len = r->sample_size * r->filter_length; - r->buffer = malloc (r->buffer_len); - memset (r->buffer, 0, r->buffer_len); - r->buffer_filled = 0; - - r->i_inc = r->o_rate / r->i_rate; - r->o_inc = r->i_rate / r->o_rate; - RESAMPLE_DEBUG ("i_inc %g o_inc %g", r->i_inc, r->o_inc); - - r->i_start = -r->i_inc * r->filter_length; - - r->need_reinit = 0; - -#if 0 - if (r->i_inc < 1.0) { - r->sinc_scale = r->i_inc; - if (r->sinc_scale == 0.5) { - /* strange things happen at integer multiples */ - r->sinc_scale = 1.0; - } - } else { - r->sinc_scale = 1.0; - } -#else - r->sinc_scale = 1.0; -#endif - } - - RESAMPLE_DEBUG ("asked to resample %d bytes", r->o_size); - RESAMPLE_DEBUG ("%d bytes in queue", - audioresample_buffer_queue_get_depth (r->queue)); - - while (r->o_size >= r->sample_size) { - double midpoint; - int i; - int j; - - midpoint = r->i_start + (r->filter_length - 1) * 0.5 * r->i_inc; - RESAMPLE_DEBUG - ("still need to output %d bytes, %d input left, i_start %g, midpoint %f", - r->o_size, audioresample_buffer_queue_get_depth (r->queue), r->i_start, - midpoint); - if (midpoint > 0.5 * r->i_inc) { - RESAMPLE_ERROR ("inconsistent state"); - } - while (midpoint < -0.5 * r->i_inc) { - AudioresampleBuffer *buffer; - - RESAMPLE_DEBUG ("midpoint %f < %f, r->i_inc %f", midpoint, - -0.5 * r->i_inc, r->i_inc); - buffer = audioresample_buffer_queue_pull (r->queue, r->sample_size); - if (buffer == NULL) { - /* FIXME: for the first buffer, this isn't necessarily an error, - * since because of the filter length we'll output less buffers. - * deal with that so we don't print to console */ - RESAMPLE_ERROR ("buffer_queue_pull returned NULL"); - return; - } - - r->i_start += r->i_inc; - RESAMPLE_DEBUG ("pulling (i_start = %g)", r->i_start); - - midpoint += r->i_inc; - memmove (r->buffer, r->buffer + r->sample_size, - r->buffer_len - r->sample_size); - - memcpy (r->buffer + r->buffer_len - r->sample_size, buffer->data, - r->sample_size); - r->buffer_filled = MIN (r->buffer_filled + r->sample_size, r->buffer_len); - - audioresample_buffer_unref (buffer); - } - - switch (r->format) { - case RESAMPLE_FORMAT_S16: - for (i = 0; i < r->n_channels; i++) { - double acc = 0; - double offset; - double x; - - for (j = 0; j < r->filter_length; j++) { - offset = (r->i_start + j * r->i_inc) * r->o_inc; - x = *(int16_t *) (r->buffer + i * sizeof (int16_t) + - j * r->sample_size); - acc += - resample_sinc_window (offset, r->filter_length * 0.5, - r->sinc_scale) * x; - } - if (acc < -32768.0) - acc = -32768.0; - if (acc > 32767.0) - acc = 32767.0; - - *(int16_t *) (r->o_buf + i * sizeof (int16_t)) = rint (acc); - } - break; - case RESAMPLE_FORMAT_S32: - for (i = 0; i < r->n_channels; i++) { - double acc = 0; - double offset; - double x; - - for (j = 0; j < r->filter_length; j++) { - offset = (r->i_start + j * r->i_inc) * r->o_inc; - x = *(int32_t *) (r->buffer + i * sizeof (int32_t) + - j * r->sample_size); - acc += - resample_sinc_window (offset, r->filter_length * 0.5, - r->sinc_scale) * x; - } - if (acc < -2147483648.0) - acc = -2147483648.0; - if (acc > 2147483647.0) - acc = 2147483647.0; - - *(int32_t *) (r->o_buf + i * sizeof (int32_t)) = rint (acc); - } - break; - case RESAMPLE_FORMAT_F32: - for (i = 0; i < r->n_channels; i++) { - double acc = 0; - double offset; - double x; - - for (j = 0; j < r->filter_length; j++) { - offset = (r->i_start + j * r->i_inc) * r->o_inc; - x = *(float *) (r->buffer + i * sizeof (float) + - j * r->sample_size); - acc += - resample_sinc_window (offset, r->filter_length * 0.5, - r->sinc_scale) * x; - } - - *(float *) (r->o_buf + i * sizeof (float)) = acc; - } - break; - case RESAMPLE_FORMAT_F64: - for (i = 0; i < r->n_channels; i++) { - double acc = 0; - double offset; - double x; - - for (j = 0; j < r->filter_length; j++) { - offset = (r->i_start + j * r->i_inc) * r->o_inc; - x = *(double *) (r->buffer + i * sizeof (double) + - j * r->sample_size); - acc += - resample_sinc_window (offset, r->filter_length * 0.5, - r->sinc_scale) * x; - } - - *(double *) (r->o_buf + i * sizeof (double)) = acc; - } - break; - } - - r->i_start -= 1.0; - r->o_buf += r->sample_size; - r->o_size -= r->sample_size; - } -} diff --git a/tests/check/Makefile.am b/tests/check/Makefile.am index e4e6aa9a6..2a093a024 100644 --- a/tests/check/Makefile.am +++ b/tests/check/Makefile.am @@ -193,7 +193,6 @@ check_PROGRAMS = \ elements/baseaudiovisualizer \ elements/camerabin \ elements/dataurisrc \ - elements/legacyresample \ $(check_jifmux) \ elements/jpegparse \ $(check_logoinsert) \ @@ -286,13 +285,6 @@ elements_faac_LDADD = \ $(GST_PLUGINS_BASE_LIBS) $(GST_BASE_LIBS) $(GST_LIBS) $(LDADD) \ -lgstaudio-@GST_API_VERSION@ -elements_legacyresample_CFLAGS = \ - $(GST_PLUGINS_BASE_CFLAGS) \ - $(GST_BASE_CFLAGS) $(GST_CFLAGS) $(AM_CFLAGS) -elements_legacyresample_LDADD = \ - $(GST_PLUGINS_BASE_LIBS) $(GST_BASE_LIBS) $(GST_LIBS) $(LDADD) \ - -lgstaudio-@GST_API_VERSION@ - elements_voaacenc_CFLAGS = \ $(GST_PLUGINS_BASE_CFLAGS) \ $(GST_BASE_CFLAGS) $(GST_CFLAGS) $(AM_CFLAGS) diff --git a/tests/check/elements/legacyresample.c b/tests/check/elements/legacyresample.c deleted file mode 100644 index 3c1bda3d7..000000000 --- a/tests/check/elements/legacyresample.c +++ /dev/null @@ -1,574 +0,0 @@ -/* GStreamer - * - * unit test for legacyresample - * - * Copyright (C) <2005> Thomas Vander Stichele <thomas at apestaart dot org> - * Copyright (C) <2006> Tim-Philipp Müller <tim at centricular net> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#include <unistd.h> - -#include <gst/check/gstcheck.h> -#include <gst/audio/audio.h> - -/* For ease of programming we use globals to keep refs for our floating - * src and sink pads we create; otherwise we always have to do get_pad, - * get_peer, and then remove references in every test function */ -static GstPad *mysrcpad, *mysinkpad; - - -#define RESAMPLE_CAPS_TEMPLATE_STRING \ - "audio/x-raw, " \ - "format = (string) " GST_AUDIO_NE (S16) ", " \ - "channels = (int) [ 1, MAX ], " \ - "rate = (int) [ 1, MAX ]" - -static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink", - GST_PAD_SINK, - GST_PAD_ALWAYS, - GST_STATIC_CAPS (RESAMPLE_CAPS_TEMPLATE_STRING) - ); -static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src", - GST_PAD_SRC, - GST_PAD_ALWAYS, - GST_STATIC_CAPS (RESAMPLE_CAPS_TEMPLATE_STRING) - ); - -static GstElement * -setup_legacyresample (int channels, int inrate, int outrate) -{ - GstElement *legacyresample; - GstCaps *caps; - GstStructure *structure; - - GST_DEBUG ("setup_legacyresample"); - legacyresample = gst_check_setup_element ("legacyresample"); - - caps = gst_caps_from_string (RESAMPLE_CAPS_TEMPLATE_STRING); - structure = gst_caps_get_structure (caps, 0); - gst_structure_set (structure, "channels", G_TYPE_INT, channels, - "rate", G_TYPE_INT, inrate, NULL); - fail_unless (gst_caps_is_fixed (caps)); - - fail_unless (gst_element_set_state (legacyresample, - GST_STATE_PAUSED) == GST_STATE_CHANGE_SUCCESS, - "could not set to paused"); - - mysrcpad = gst_check_setup_src_pad (legacyresample, &srctemplate); - gst_pad_set_active (mysrcpad, TRUE); - fail_unless (gst_pad_set_caps (mysrcpad, caps)); - gst_caps_unref (caps); - - caps = gst_caps_from_string (RESAMPLE_CAPS_TEMPLATE_STRING); - structure = gst_caps_get_structure (caps, 0); - gst_structure_set (structure, "channels", G_TYPE_INT, channels, - "rate", G_TYPE_INT, outrate, NULL); - fail_unless (gst_caps_is_fixed (caps)); - - mysinkpad = gst_check_setup_sink_pad (legacyresample, &sinktemplate); - gst_pad_set_active (mysinkpad, TRUE); - /* this installs a getcaps func that will always return the caps we set - * later */ - fail_unless (gst_pad_set_caps (mysinkpad, caps)); - gst_pad_use_fixed_caps (mysinkpad); - gst_caps_unref (caps); - - return legacyresample; -} - -static void -cleanup_legacyresample (GstElement * legacyresample) -{ - GST_DEBUG ("cleanup_legacyresample"); - - fail_unless (gst_element_set_state (legacyresample, - GST_STATE_NULL) == GST_STATE_CHANGE_SUCCESS, "could not set to NULL"); - - gst_pad_set_active (mysrcpad, FALSE); - gst_pad_set_active (mysinkpad, FALSE); - gst_check_teardown_src_pad (legacyresample); - gst_check_teardown_sink_pad (legacyresample); - gst_check_teardown_element (legacyresample); -} - -static void -fail_unless_perfect_stream (void) -{ - guint64 timestamp = 0L, duration = 0L; - guint64 offset = 0L, offset_end = 0L; - - GList *l; - GstBuffer *buffer; - - for (l = buffers; l; l = l->next) { - buffer = GST_BUFFER (l->data); - ASSERT_BUFFER_REFCOUNT (buffer, "buffer", 1); - GST_DEBUG ("buffer timestamp %" G_GUINT64_FORMAT ", duration %" - G_GUINT64_FORMAT " offset %" G_GUINT64_FORMAT " offset_end %" - G_GUINT64_FORMAT, - GST_BUFFER_TIMESTAMP (buffer), - GST_BUFFER_DURATION (buffer), - GST_BUFFER_OFFSET (buffer), GST_BUFFER_OFFSET_END (buffer)); - - fail_unless_equals_uint64 (timestamp, GST_BUFFER_TIMESTAMP (buffer)); - fail_unless_equals_uint64 (offset, GST_BUFFER_OFFSET (buffer)); - duration = GST_BUFFER_DURATION (buffer); - offset_end = GST_BUFFER_OFFSET_END (buffer); - - timestamp += duration; - offset = offset_end; - gst_buffer_unref (buffer); - } - g_list_free (buffers); - buffers = NULL; -} - -/* this tests that the output is a perfect stream if the input is */ -static void -test_perfect_stream_instance (int inrate, int outrate, int samples, - int numbuffers) -{ - GstElement *legacyresample; - GstBuffer *inbuffer, *outbuffer; - GstCaps *caps; - guint64 offset = 0; - - int i, j; - gint16 *p; - - legacyresample = setup_legacyresample (2, inrate, outrate); - caps = gst_pad_get_current_caps (mysrcpad); - fail_unless (gst_caps_is_fixed (caps)); - - fail_unless (gst_element_set_state (legacyresample, - GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS, - "could not set to playing"); - - for (j = 1; j <= numbuffers; ++j) { - GstMapInfo map; - - inbuffer = gst_buffer_new_and_alloc (samples * 4); - GST_BUFFER_DURATION (inbuffer) = samples * GST_SECOND / inrate; - GST_BUFFER_TIMESTAMP (inbuffer) = GST_BUFFER_DURATION (inbuffer) * (j - 1); - GST_BUFFER_OFFSET (inbuffer) = offset; - offset += samples; - GST_BUFFER_OFFSET_END (inbuffer) = offset; - - gst_buffer_map (inbuffer, &map, GST_MAP_WRITE); - p = (gint16 *) map.data; - - /* create a 16 bit signed ramp */ - for (i = 0; i < samples; ++i) { - *p = -32767 + i * (65535 / samples); - ++p; - *p = -32767 + i * (65535 / samples); - ++p; - } - gst_buffer_unmap (inbuffer, &map); - - /* pushing gives away my reference ... */ - fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK); - /* ... but it ends up being collected on the global buffer list */ - fail_unless_equals_int (g_list_length (buffers), j); - } - - /* FIXME: we should make legacyresample handle eos by flushing out the last - * samples, which will give us one more, small, buffer */ - fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL); - ASSERT_BUFFER_REFCOUNT (outbuffer, "outbuffer", 1); - - fail_unless_perfect_stream (); - - /* cleanup */ - gst_caps_unref (caps); - cleanup_legacyresample (legacyresample); -} - - -/* make sure that outgoing buffers are contiguous in timestamp/duration and - * offset/offsetend - */ -GST_START_TEST (test_perfect_stream) -{ - /* integral scalings */ - test_perfect_stream_instance (48000, 24000, 500, 20); - test_perfect_stream_instance (48000, 12000, 500, 20); - test_perfect_stream_instance (12000, 24000, 500, 20); - test_perfect_stream_instance (12000, 48000, 500, 20); - - /* non-integral scalings */ - test_perfect_stream_instance (44100, 8000, 500, 20); - test_perfect_stream_instance (8000, 44100, 500, 20); - - /* wacky scalings */ - test_perfect_stream_instance (12345, 54321, 500, 20); - test_perfect_stream_instance (101, 99, 500, 20); -} - -GST_END_TEST; - -/* this tests that the output is a correct discontinuous stream - * if the input is; ie input drops in time come out the same way */ -static void -test_discont_stream_instance (int inrate, int outrate, int samples, - int numbuffers) -{ - GstElement *legacyresample; - GstBuffer *inbuffer, *outbuffer; - GstCaps *caps; - GstClockTime ints; - - int i, j; - gint16 *p; - - GST_DEBUG ("inrate:%d outrate:%d samples:%d numbuffers:%d", - inrate, outrate, samples, numbuffers); - - legacyresample = setup_legacyresample (2, inrate, outrate); - caps = gst_pad_get_current_caps (mysrcpad); - fail_unless (gst_caps_is_fixed (caps)); - - fail_unless (gst_element_set_state (legacyresample, - GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS, - "could not set to playing"); - - for (j = 1; j <= numbuffers; ++j) { - GstMapInfo map; - - inbuffer = gst_buffer_new_and_alloc (samples * 4); - GST_BUFFER_DURATION (inbuffer) = samples * GST_SECOND / inrate; - /* "drop" half the buffers */ - ints = GST_BUFFER_DURATION (inbuffer) * 2 * (j - 1); - GST_BUFFER_TIMESTAMP (inbuffer) = ints; - GST_BUFFER_OFFSET (inbuffer) = (j - 1) * 2 * samples; - GST_BUFFER_OFFSET_END (inbuffer) = j * 2 * samples + samples; - - gst_buffer_map (inbuffer, &map, GST_MAP_WRITE); - p = (gint16 *) map.data; - - /* create a 16 bit signed ramp */ - for (i = 0; i < samples; ++i) { - *p = -32767 + i * (65535 / samples); - ++p; - *p = -32767 + i * (65535 / samples); - ++p; - } - gst_buffer_unmap (inbuffer, &map); - - GST_DEBUG ("Sending Buffer time:%" G_GUINT64_FORMAT " duration:%" - G_GINT64_FORMAT " discont:%d offset:%" G_GUINT64_FORMAT " offset_end:%" - G_GUINT64_FORMAT, GST_BUFFER_TIMESTAMP (inbuffer), - GST_BUFFER_DURATION (inbuffer), GST_BUFFER_IS_DISCONT (inbuffer), - GST_BUFFER_OFFSET (inbuffer), GST_BUFFER_OFFSET_END (inbuffer)); - /* pushing gives away my reference ... */ - fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK); - - /* check if the timestamp of the pushed buffer matches the incoming one */ - outbuffer = g_list_nth_data (buffers, g_list_length (buffers) - 1); - fail_if (outbuffer == NULL); - fail_unless_equals_uint64 (ints, GST_BUFFER_TIMESTAMP (outbuffer)); - GST_DEBUG ("Got Buffer time:%" G_GUINT64_FORMAT " duration:%" - G_GINT64_FORMAT " discont:%d offset:%" G_GUINT64_FORMAT " offset_end:%" - G_GUINT64_FORMAT, GST_BUFFER_TIMESTAMP (outbuffer), - GST_BUFFER_DURATION (outbuffer), GST_BUFFER_IS_DISCONT (outbuffer), - GST_BUFFER_OFFSET (outbuffer), GST_BUFFER_OFFSET_END (outbuffer)); - if (j > 1) { - fail_unless (GST_BUFFER_IS_DISCONT (outbuffer), - "expected discont for buffer #%d", j); - } - } - - /* cleanup */ - gst_caps_unref (caps); - cleanup_legacyresample (legacyresample); -} - -GST_START_TEST (test_discont_stream) -{ - /* integral scalings */ - test_discont_stream_instance (48000, 24000, 500, 20); - test_discont_stream_instance (48000, 12000, 500, 20); - test_discont_stream_instance (12000, 24000, 500, 20); - test_discont_stream_instance (12000, 48000, 500, 20); - - /* non-integral scalings */ - test_discont_stream_instance (44100, 8000, 500, 20); - test_discont_stream_instance (8000, 44100, 500, 20); - - /* wacky scalings */ - test_discont_stream_instance (12345, 54321, 500, 20); - test_discont_stream_instance (101, 99, 500, 20); -} - -GST_END_TEST; - - - -GST_START_TEST (test_reuse) -{ - GstElement *legacyresample; - GstEvent *newseg; - GstBuffer *inbuffer; - GstCaps *caps; - GstSegment seg; - - legacyresample = setup_legacyresample (1, 9343, 48000); - caps = gst_pad_get_current_caps (mysrcpad); - fail_unless (gst_caps_is_fixed (caps)); - - fail_unless (gst_element_set_state (legacyresample, - GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS, - "could not set to playing"); - - gst_segment_init (&seg, GST_FORMAT_TIME); - newseg = gst_event_new_segment (&seg); - fail_unless (gst_pad_push_event (mysrcpad, newseg) != FALSE); - - inbuffer = gst_buffer_new_and_alloc (9343 * 4); - gst_buffer_memset (inbuffer, 0, 0, -1); - GST_BUFFER_DURATION (inbuffer) = GST_SECOND; - GST_BUFFER_TIMESTAMP (inbuffer) = 0; - GST_BUFFER_OFFSET (inbuffer) = 0; - - /* pushing gives away my reference ... */ - fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK); - - /* ... but it ends up being collected on the global buffer list */ - fail_unless_equals_int (g_list_length (buffers), 1); - - /* now reset and try again ... */ - fail_unless (gst_element_set_state (legacyresample, - GST_STATE_NULL) == GST_STATE_CHANGE_SUCCESS, "could not set to NULL"); - - fail_unless (gst_element_set_state (legacyresample, - GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS, - "could not set to playing"); - - gst_segment_init (&seg, GST_FORMAT_TIME); - newseg = gst_event_new_segment (&seg); - fail_unless (gst_pad_push_event (mysrcpad, newseg) != FALSE); - - inbuffer = gst_buffer_new_and_alloc (9343 * 4); - gst_buffer_memset (inbuffer, 0, 0, -1); - GST_BUFFER_DURATION (inbuffer) = GST_SECOND; - GST_BUFFER_TIMESTAMP (inbuffer) = 0; - GST_BUFFER_OFFSET (inbuffer) = 0; - - fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK); - - /* ... it also ends up being collected on the global buffer list. If we - * now have more than 2 buffers, then legacyresample probably didn't clean - * up its internal buffer properly and tried to push the remaining samples - * when it got the second NEWSEGMENT event */ - fail_unless_equals_int (g_list_length (buffers), 2); - - cleanup_legacyresample (legacyresample); - gst_caps_unref (caps); -} - -GST_END_TEST; - -GST_START_TEST (test_shutdown) -{ - GstElement *pipeline, *src, *cf1, *ar, *cf2, *sink; - GstCaps *caps; - guint i; - - /* create pipeline, force legacyresample to actually resample */ - pipeline = gst_pipeline_new (NULL); - - src = gst_check_setup_element ("audiotestsrc"); - cf1 = gst_check_setup_element ("capsfilter"); - ar = gst_check_setup_element ("legacyresample"); - cf2 = gst_check_setup_element ("capsfilter"); - g_object_set (cf2, "name", "capsfilter2", NULL); - sink = gst_check_setup_element ("fakesink"); - - caps = - gst_caps_new_simple ("audio/x-raw-int", "rate", G_TYPE_INT, 11025, NULL); - g_object_set (cf1, "caps", caps, NULL); - gst_caps_unref (caps); - - caps = - gst_caps_new_simple ("audio/x-raw-int", "rate", G_TYPE_INT, 48000, NULL); - g_object_set (cf2, "caps", caps, NULL); - gst_caps_unref (caps); - - /* don't want to sync against the clock, the more throughput the better */ - g_object_set (src, "is-live", FALSE, NULL); - g_object_set (sink, "sync", FALSE, NULL); - - gst_bin_add_many (GST_BIN (pipeline), src, cf1, ar, cf2, sink, NULL); - fail_if (!gst_element_link_many (src, cf1, ar, cf2, sink, NULL)); - - /* now, wait until pipeline is running and then shut it down again; repeat */ - for (i = 0; i < 20; ++i) { - gst_element_set_state (pipeline, GST_STATE_PAUSED); - gst_element_get_state (pipeline, NULL, NULL, -1); - gst_element_set_state (pipeline, GST_STATE_PLAYING); - g_usleep (100); - gst_element_set_state (pipeline, GST_STATE_NULL); - } - - gst_object_unref (pipeline); -} - -GST_END_TEST; - -#if 0 -static GstFlowReturn -live_switch_alloc_only_48000 (GstPad * pad, guint64 offset, - guint size, GstCaps * caps, GstBuffer ** buf) -{ - GstStructure *structure; - gint rate; - gint channels; - GstCaps *desired; - - structure = gst_caps_get_structure (caps, 0); - fail_unless (gst_structure_get_int (structure, "rate", &rate)); - fail_unless (gst_structure_get_int (structure, "channels", &channels)); - - if (rate < 48000) - return GST_FLOW_NOT_NEGOTIATED; - - desired = gst_caps_copy (caps); - gst_caps_set_simple (desired, "rate", G_TYPE_INT, 48000, NULL); - - *buf = gst_buffer_new_and_alloc (channels * 48000); - gst_buffer_set_caps (*buf, desired); - gst_caps_unref (desired); - - return GST_FLOW_OK; -} - -static GstCaps * -live_switch_get_sink_caps (GstPad * pad) -{ - GstCaps *result; - - result = gst_caps_copy (GST_PAD_CAPS (pad)); - - gst_caps_set_simple (result, - "rate", GST_TYPE_INT_RANGE, 48000, G_MAXINT, NULL); - - return result; -} - -static void -live_switch_push (int rate, GstCaps * caps) -{ - GstBuffer *inbuffer; - GstCaps *desired; - GList *l; - - desired = gst_caps_copy (caps); - gst_caps_set_simple (desired, "rate", G_TYPE_INT, rate, NULL); - - fail_unless (gst_pad_alloc_buffer_and_set_caps (mysrcpad, - GST_BUFFER_OFFSET_NONE, rate * 4, desired, &inbuffer) == GST_FLOW_OK); - - /* When the basetransform hits the non-configured case it always - * returns a buffer with exactly the same caps as we requested so the actual - * renegotiation (if needed) will be done in the _chain*/ - fail_unless (inbuffer != NULL); - fail_unless (gst_caps_is_equal (desired, GST_BUFFER_CAPS (inbuffer))); - - gst_buffer_memset (inbuffer, 0, 0, -1); - GST_BUFFER_DURATION (inbuffer) = GST_SECOND; - GST_BUFFER_TIMESTAMP (inbuffer) = 0; - GST_BUFFER_OFFSET (inbuffer) = 0; - - /* pushing gives away my reference ... */ - fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK); - - /* ... but it ends up being collected on the global buffer list */ - fail_unless_equals_int (g_list_length (buffers), 1); - - for (l = buffers; l; l = l->next) { - GstBuffer *buffer = GST_BUFFER (l->data); - - gst_buffer_unref (buffer); - } - - g_list_free (buffers); - buffers = NULL; - - gst_caps_unref (desired); -} - -GST_START_TEST (test_live_switch) -{ - GstElement *legacyresample; - GstEvent *newseg; - GstCaps *caps; - - legacyresample = setup_legacyresample (4, 48000, 48000); - - /* Let the sinkpad act like something that can only handle things of - * rate 48000- and can only allocate buffers for that rate, but if someone - * tries to get a buffer with a rate higher then 48000 tries to renegotiate - * */ - gst_pad_set_bufferalloc_function (mysinkpad, live_switch_alloc_only_48000); - gst_pad_set_getcaps_function (mysinkpad, live_switch_get_sink_caps); - - caps = gst_pad_get_negotiated_caps (mysrcpad); - fail_unless (gst_caps_is_fixed (caps)); - - fail_unless (gst_element_set_state (legacyresample, - GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS, - "could not set to playing"); - - newseg = gst_event_new_new_segment (FALSE, 1.0, GST_FORMAT_TIME, 0, -1, 0); - fail_unless (gst_pad_push_event (mysrcpad, newseg) != FALSE); - - /* downstream can provide the requested rate, a buffer alloc will be passed - * on */ - live_switch_push (48000, caps); - - /* Downstream can never accept this rate, buffer alloc isn't passed on */ - live_switch_push (40000, caps); - - /* Downstream can provide the requested rate but will re-negotiate */ - live_switch_push (50000, caps); - - cleanup_legacyresample (legacyresample); - gst_caps_unref (caps); -} - -GST_END_TEST -#endif -static Suite * -legacyresample_suite (void) -{ - Suite *s = suite_create ("legacyresample"); - TCase *tc_chain = tcase_create ("general"); - - suite_add_tcase (s, tc_chain); - tcase_add_test (tc_chain, test_perfect_stream); - tcase_add_test (tc_chain, test_discont_stream); - tcase_add_test (tc_chain, test_reuse); - tcase_add_test (tc_chain, test_shutdown); -#if 0 - tcase_add_test (tc_chain, test_live_switch); -#endif - - return s; -} - -GST_CHECK_MAIN (legacyresample); |