mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-29 21:21:12 +00:00
Remove mpg123 plugin, moved to -good
https://bugzilla.gnome.org/show_bug.cgi?id=774252
This commit is contained in:
parent
53160e8fa1
commit
83ff57c849
17 changed files with 3 additions and 1359 deletions
|
@ -40,10 +40,12 @@ CRUFT_FILES = \
|
||||||
$(top_builddir)/gst-plugins-ugly.spec \
|
$(top_builddir)/gst-plugins-ugly.spec \
|
||||||
$(top_builddir)/common/shave \
|
$(top_builddir)/common/shave \
|
||||||
$(top_builddir)/common/shave-libtool \
|
$(top_builddir)/common/shave-libtool \
|
||||||
|
$(top_builddir)/ext/mpg123/.libs/libgstmpg123.so \
|
||||||
$(top_builddir)/gst/realmedia/.libs/libgstrmdemux.so
|
$(top_builddir)/gst/realmedia/.libs/libgstrmdemux.so
|
||||||
|
|
||||||
CRUFT_DIRS = \
|
CRUFT_DIRS = \
|
||||||
$(top_srcdir)/docs/plugins/tmpl \
|
$(top_srcdir)/docs/plugins/tmpl \
|
||||||
|
$(top_srcdir)/ext/mpg123/ \
|
||||||
$(top_builddir)/win32 \
|
$(top_builddir)/win32 \
|
||||||
$(top_srcdir)/win32
|
$(top_srcdir)/win32
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,7 @@ Required tools:
|
||||||
===============
|
===============
|
||||||
|
|
||||||
An extra set of tools is required if you wish to build GStreamer out of
|
An extra set of tools is required if you wish to build GStreamer out of
|
||||||
CVS (using autogen.sh):
|
git (using autogen.sh):
|
||||||
|
|
||||||
autoconf 2.52 or better
|
autoconf 2.52 or better
|
||||||
automake 1.5
|
automake 1.5
|
||||||
|
@ -34,8 +34,6 @@ a52dec (for the a52dec AC-3 decoder)
|
||||||
http://liba52.sourceforge.net/
|
http://liba52.sourceforge.net/
|
||||||
opencore-amr (for the AMR-NB decoder and encoder and the AMR-WB decoder)
|
opencore-amr (for the AMR-NB decoder and encoder and the AMR-WB decoder)
|
||||||
http://sourceforge.net/projects/opencore-amr/
|
http://sourceforge.net/projects/opencore-amr/
|
||||||
libmpg123 (for the mpg123 mp3 decoder plugin)
|
|
||||||
https://www.mpg123.de/api/
|
|
||||||
liblame (for lame mp3 encoder)
|
liblame (for lame mp3 encoder)
|
||||||
http://www.mp3dev.org/mp3/
|
http://www.mp3dev.org/mp3/
|
||||||
libdvdread (for the dvdreadsrc)
|
libdvdread (for the dvdreadsrc)
|
||||||
|
|
10
configure.ac
10
configure.ac
|
@ -303,14 +303,6 @@ AG_GST_CHECK_FEATURE(MPEG2DEC, [mpeg2dec], mpeg2dec, [
|
||||||
AG_GST_PKG_CHECK_MODULES(MPEG2DEC, libmpeg2 >= 0.5.1)
|
AG_GST_PKG_CHECK_MODULES(MPEG2DEC, libmpeg2 >= 0.5.1)
|
||||||
])
|
])
|
||||||
|
|
||||||
dnl *** mpg123 ***
|
|
||||||
translit(dnm, m, l) AM_CONDITIONAL(USE_MPG123, true)
|
|
||||||
AG_GST_CHECK_FEATURE(MPG123, [mpg123 audio decoder], mpg123, [
|
|
||||||
PKG_CHECK_MODULES(MPG123, libmpg123 >= 1.13, HAVE_MPG123="yes", HAVE_MPG123="no")
|
|
||||||
AC_SUBST(MPG123_CFLAGS)
|
|
||||||
AC_SUBST(MPG123_LIBS)
|
|
||||||
])
|
|
||||||
|
|
||||||
dnl *** sidplay : works with libsidplay 1.36.x (not 2.x.x) ***
|
dnl *** sidplay : works with libsidplay 1.36.x (not 2.x.x) ***
|
||||||
translit(dnm, m, l) AM_CONDITIONAL(USE_SIDPLAY, true)
|
translit(dnm, m, l) AM_CONDITIONAL(USE_SIDPLAY, true)
|
||||||
AG_GST_CHECK_FEATURE(SIDPLAY, [libsidplay], sid, [
|
AG_GST_CHECK_FEATURE(SIDPLAY, [libsidplay], sid, [
|
||||||
|
@ -357,7 +349,6 @@ AM_CONDITIONAL(USE_CDIO, false)
|
||||||
AM_CONDITIONAL(USE_DVDREAD, false)
|
AM_CONDITIONAL(USE_DVDREAD, false)
|
||||||
AM_CONDITIONAL(USE_LAME, false)
|
AM_CONDITIONAL(USE_LAME, false)
|
||||||
AM_CONDITIONAL(USE_MPEG2DEC, false)
|
AM_CONDITIONAL(USE_MPEG2DEC, false)
|
||||||
AM_CONDITIONAL(USE_MPG123, false)
|
|
||||||
AM_CONDITIONAL(USE_SIDPLAY, false)
|
AM_CONDITIONAL(USE_SIDPLAY, false)
|
||||||
AM_CONDITIONAL(USE_TWOLAME, false)
|
AM_CONDITIONAL(USE_TWOLAME, false)
|
||||||
AM_CONDITIONAL(USE_X264, false)
|
AM_CONDITIONAL(USE_X264, false)
|
||||||
|
@ -441,7 +432,6 @@ ext/cdio/Makefile
|
||||||
ext/dvdread/Makefile
|
ext/dvdread/Makefile
|
||||||
ext/lame/Makefile
|
ext/lame/Makefile
|
||||||
ext/mpeg2dec/Makefile
|
ext/mpeg2dec/Makefile
|
||||||
ext/mpg123/Makefile
|
|
||||||
ext/sidplay/Makefile
|
ext/sidplay/Makefile
|
||||||
ext/twolame/Makefile
|
ext/twolame/Makefile
|
||||||
ext/x264/Makefile
|
ext/x264/Makefile
|
||||||
|
|
|
@ -23,7 +23,6 @@
|
||||||
<xi:include href="xml/element-amrwbdec.xml" />
|
<xi:include href="xml/element-amrwbdec.xml" />
|
||||||
<xi:include href="xml/element-cdiocddasrc.xml" />
|
<xi:include href="xml/element-cdiocddasrc.xml" />
|
||||||
<xi:include href="xml/element-lamemp3enc.xml" />
|
<xi:include href="xml/element-lamemp3enc.xml" />
|
||||||
<xi:include href="xml/element-mpg123audiodec.xml" />
|
|
||||||
<xi:include href="xml/element-rademux.xml" />
|
<xi:include href="xml/element-rademux.xml" />
|
||||||
<xi:include href="xml/element-rmdemux.xml" />
|
<xi:include href="xml/element-rmdemux.xml" />
|
||||||
<xi:include href="xml/element-rdtmanager.xml" />
|
<xi:include href="xml/element-rdtmanager.xml" />
|
||||||
|
@ -47,7 +46,6 @@
|
||||||
<xi:include href="xml/plugin-dvdsub.xml" />
|
<xi:include href="xml/plugin-dvdsub.xml" />
|
||||||
<xi:include href="xml/plugin-lame.xml" />
|
<xi:include href="xml/plugin-lame.xml" />
|
||||||
<xi:include href="xml/plugin-mpeg2dec.xml" />
|
<xi:include href="xml/plugin-mpeg2dec.xml" />
|
||||||
<xi:include href="xml/plugin-mpg123.xml" />
|
|
||||||
<xi:include href="xml/plugin-realmedia.xml" />
|
<xi:include href="xml/plugin-realmedia.xml" />
|
||||||
<xi:include href="xml/plugin-siddec.xml" />
|
<xi:include href="xml/plugin-siddec.xml" />
|
||||||
<xi:include href="xml/plugin-twolame.xml" />
|
<xi:include href="xml/plugin-twolame.xml" />
|
||||||
|
|
|
@ -92,20 +92,6 @@ gst_lamemp3enc_get_type
|
||||||
gst_lamemp3enc_register
|
gst_lamemp3enc_register
|
||||||
</SECTION>
|
</SECTION>
|
||||||
|
|
||||||
<SECTION>
|
|
||||||
<FILE>element-mpg123audiodec</FILE>
|
|
||||||
<TITLE>mpg123audiodec</TITLE>
|
|
||||||
GstMpg123AudioDec
|
|
||||||
<SUBSECTION Standard>
|
|
||||||
GstMpg123AudioDecClass
|
|
||||||
GST_MPG123_AUDIO_DEC
|
|
||||||
GST_MPG123_AUDIO_DEC_CLASS
|
|
||||||
GST_IS_MPG123_AUDIO_DEC
|
|
||||||
GST_IS_MPG123_AUDIO_DEC_CLASS
|
|
||||||
GST_TYPE_MPG123_AUDIO_DEC
|
|
||||||
gst_mpg123_audio_dec_get_type
|
|
||||||
</SECTION>
|
|
||||||
|
|
||||||
<SECTION>
|
<SECTION>
|
||||||
<FILE>element-rademux</FILE>
|
<FILE>element-rademux</FILE>
|
||||||
<TITLE>rademux</TITLE>
|
<TITLE>rademux</TITLE>
|
||||||
|
|
|
@ -14,7 +14,6 @@ GObject
|
||||||
GstAmrnbDec
|
GstAmrnbDec
|
||||||
GstAmrwbDec
|
GstAmrwbDec
|
||||||
GstDvdLpcmDec
|
GstDvdLpcmDec
|
||||||
GstMpg123AudioDec
|
|
||||||
GstAudioEncoder
|
GstAudioEncoder
|
||||||
GstAmrnbEnc
|
GstAmrnbEnc
|
||||||
GstLameMP3Enc
|
GstLameMP3Enc
|
||||||
|
|
|
@ -1,34 +0,0 @@
|
||||||
<plugin>
|
|
||||||
<name>mpg123</name>
|
|
||||||
<description>mp3 decoding based on the mpg123 library</description>
|
|
||||||
<filename>../../ext/mpg123/.libs/libgstmpg123.so</filename>
|
|
||||||
<basename>libgstmpg123.so</basename>
|
|
||||||
<version>1.12.0</version>
|
|
||||||
<license>LGPL</license>
|
|
||||||
<source>gst-plugins-ugly</source>
|
|
||||||
<package>GStreamer Ugly Plug-ins source release</package>
|
|
||||||
<origin>Unknown package origin</origin>
|
|
||||||
<elements>
|
|
||||||
<element>
|
|
||||||
<name>mpg123audiodec</name>
|
|
||||||
<longname>mpg123 mp3 decoder</longname>
|
|
||||||
<class>Codec/Decoder/Audio</class>
|
|
||||||
<description>Decodes mp3 streams using the mpg123 library</description>
|
|
||||||
<author>Carlos Rafael Giani <dv@pseudoterminal.org></author>
|
|
||||||
<pads>
|
|
||||||
<caps>
|
|
||||||
<name>sink</name>
|
|
||||||
<direction>sink</direction>
|
|
||||||
<presence>always</presence>
|
|
||||||
<details>audio/mpeg, mpegversion=(int)1, layer=(int)[ 1, 3 ], rate=(int){ 8000, 11025, 12000, 16000, 22050, 24000, 32000, 44100, 48000 }, channels=(int)[ 1, 2 ], parsed=(boolean)true</details>
|
|
||||||
</caps>
|
|
||||||
<caps>
|
|
||||||
<name>src</name>
|
|
||||||
<direction>source</direction>
|
|
||||||
<presence>always</presence>
|
|
||||||
<details>audio/x-raw, format=(string){ S16LE, U16LE, S32LE, U32LE, S24LE, U24LE, F32LE }, rate=(int){ 8000, 11025, 12000, 16000, 22050, 24000, 32000, 44100, 48000 }, channels=(int)[ 1, 2 ], layout=(string)interleaved</details>
|
|
||||||
</caps>
|
|
||||||
</pads>
|
|
||||||
</element>
|
|
||||||
</elements>
|
|
||||||
</plugin>
|
|
|
@ -40,12 +40,6 @@ else
|
||||||
MPEG2DEC_DIR =
|
MPEG2DEC_DIR =
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if USE_MPG123
|
|
||||||
MPG123_DIR=mpg123
|
|
||||||
else
|
|
||||||
MPG123_DIR=
|
|
||||||
endif
|
|
||||||
|
|
||||||
if USE_SIDPLAY
|
if USE_SIDPLAY
|
||||||
SIDPLAY_DIR = sidplay
|
SIDPLAY_DIR = sidplay
|
||||||
else
|
else
|
||||||
|
@ -72,7 +66,6 @@ SUBDIRS = \
|
||||||
$(DVDREAD_DIR) \
|
$(DVDREAD_DIR) \
|
||||||
$(LAME_DIR) \
|
$(LAME_DIR) \
|
||||||
$(MPEG2DEC_DIR) \
|
$(MPEG2DEC_DIR) \
|
||||||
$(MPG123_DIR) \
|
|
||||||
$(SIDPLAY_DIR) \
|
$(SIDPLAY_DIR) \
|
||||||
$(TWOLAME_DIR) \
|
$(TWOLAME_DIR) \
|
||||||
$(X264_DIR)
|
$(X264_DIR)
|
||||||
|
@ -85,7 +78,6 @@ DIST_SUBDIRS = \
|
||||||
dvdread \
|
dvdread \
|
||||||
lame \
|
lame \
|
||||||
mpeg2dec \
|
mpeg2dec \
|
||||||
mpg123 \
|
|
||||||
sidplay \
|
sidplay \
|
||||||
twolame \
|
twolame \
|
||||||
x264
|
x264
|
||||||
|
|
|
@ -5,7 +5,6 @@ subdir('cdio')
|
||||||
subdir('dvdread')
|
subdir('dvdread')
|
||||||
subdir('lame')
|
subdir('lame')
|
||||||
subdir('mpeg2dec')
|
subdir('mpeg2dec')
|
||||||
subdir('mpg123')
|
|
||||||
subdir('sidplay')
|
subdir('sidplay')
|
||||||
subdir('twolame')
|
subdir('twolame')
|
||||||
subdir('x264')
|
subdir('x264')
|
||||||
|
|
|
@ -1,11 +0,0 @@
|
||||||
plugin_LTLIBRARIES = libgstmpg123.la
|
|
||||||
|
|
||||||
libgstmpg123_la_SOURCES = gstmpg123audiodec.c
|
|
||||||
libgstmpg123_la_CFLAGS = -DGST_USE_UNSTABLE_API \
|
|
||||||
$(GST_PLUGINS_BASE_CFLAGS) \
|
|
||||||
$(GST_BASE_CFLAGS) $(GST_CFLAGS) $(MPG123_CFLAGS)
|
|
||||||
libgstmpg123_la_LIBADD = $(GST_PLUGINS_BASE_LIBS) -lgstaudio-@GST_API_VERSION@ \
|
|
||||||
$(GST_BASE_LIBS) $(GST_LIBS) $(MPG123_LIBS)
|
|
||||||
libgstmpg123_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS)
|
|
||||||
|
|
||||||
noinst_HEADERS = gstmpg123audiodec.h
|
|
|
@ -1,634 +0,0 @@
|
||||||
/* MP3 decoding plugin for GStreamer using the mpg123 library
|
|
||||||
* Copyright (C) 2012 Carlos Rafael Giani
|
|
||||||
*
|
|
||||||
* This library is free software; you can redistribute it and/or
|
|
||||||
* modify it under the terms of the GNU Lesser General Public
|
|
||||||
* License as published by the Free Software Foundation; either
|
|
||||||
* version 2.1 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
|
|
||||||
* Lesser General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Lesser General Public
|
|
||||||
* License along with this library; if not, write to the Free Software
|
|
||||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* SECTION: element-mpg123audiodec
|
|
||||||
* @see_also: lamemp3enc, mad
|
|
||||||
*
|
|
||||||
* Audio decoder for MPEG-1 layer 1/2/3 audio data.
|
|
||||||
*
|
|
||||||
* <refsect2>
|
|
||||||
* <title>Example pipelines</title>
|
|
||||||
* |[
|
|
||||||
* gst-launch-1.0 filesrc location=music.mp3 ! mpegaudioparse ! mpg123audiodec ! audioconvert ! audioresample ! autoaudiosink
|
|
||||||
* ]| Decode and play the mp3 file
|
|
||||||
* </refsect2>
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifdef HAVE_CONFIG_H
|
|
||||||
#include <config.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "gstmpg123audiodec.h"
|
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
GST_DEBUG_CATEGORY_STATIC (mpg123_debug);
|
|
||||||
#define GST_CAT_DEFAULT mpg123_debug
|
|
||||||
|
|
||||||
/* Omitted sample formats that mpg123 supports (or at least can support):
|
|
||||||
* - 8bit integer signed
|
|
||||||
* - 8bit integer unsigned
|
|
||||||
* - a-law
|
|
||||||
* - mu-law
|
|
||||||
* - 64bit float
|
|
||||||
*
|
|
||||||
* The first four formats are not supported by the GstAudioDecoder base class.
|
|
||||||
* (The internal gst_audio_format_from_caps_structure() call fails.)
|
|
||||||
*
|
|
||||||
* The 64bit float issue is tricky. mpg123 actually decodes to "real",
|
|
||||||
* not necessarily to "float".
|
|
||||||
*
|
|
||||||
* "real" can be fixed point, 32bit float, 64bit float. There seems to be
|
|
||||||
* no way how to find out which one of them is actually used.
|
|
||||||
*
|
|
||||||
* However, in all known installations, "real" equals 32bit float, so that's
|
|
||||||
* what is used. */
|
|
||||||
|
|
||||||
static GstStaticPadTemplate static_sink_template =
|
|
||||||
GST_STATIC_PAD_TEMPLATE ("sink",
|
|
||||||
GST_PAD_SINK,
|
|
||||||
GST_PAD_ALWAYS,
|
|
||||||
GST_STATIC_CAPS ("audio/mpeg, "
|
|
||||||
"mpegversion = (int) 1, "
|
|
||||||
"layer = (int) [ 1, 3 ], "
|
|
||||||
"rate = (int) { 8000, 11025, 12000, 16000, 22050, 24000, 32000, 44100, 48000 }, "
|
|
||||||
"channels = (int) [ 1, 2 ], " "parsed = (boolean) true ")
|
|
||||||
);
|
|
||||||
|
|
||||||
static gboolean gst_mpg123_audio_dec_start (GstAudioDecoder * dec);
|
|
||||||
static gboolean gst_mpg123_audio_dec_stop (GstAudioDecoder * dec);
|
|
||||||
static GstFlowReturn gst_mpg123_audio_dec_push_decoded_bytes (GstMpg123AudioDec
|
|
||||||
* mpg123_decoder, unsigned char const *decoded_bytes,
|
|
||||||
size_t const num_decoded_bytes);
|
|
||||||
static GstFlowReturn gst_mpg123_audio_dec_handle_frame (GstAudioDecoder * dec,
|
|
||||||
GstBuffer * input_buffer);
|
|
||||||
static gboolean gst_mpg123_audio_dec_set_format (GstAudioDecoder * dec,
|
|
||||||
GstCaps * input_caps);
|
|
||||||
static void gst_mpg123_audio_dec_flush (GstAudioDecoder * dec, gboolean hard);
|
|
||||||
|
|
||||||
G_DEFINE_TYPE (GstMpg123AudioDec, gst_mpg123_audio_dec, GST_TYPE_AUDIO_DECODER);
|
|
||||||
|
|
||||||
static void
|
|
||||||
gst_mpg123_audio_dec_class_init (GstMpg123AudioDecClass * klass)
|
|
||||||
{
|
|
||||||
GstAudioDecoderClass *base_class;
|
|
||||||
GstElementClass *element_class;
|
|
||||||
GstPadTemplate *src_template, *sink_template;
|
|
||||||
int error;
|
|
||||||
|
|
||||||
GST_DEBUG_CATEGORY_INIT (mpg123_debug, "mpg123", 0, "mpg123 mp3 decoder");
|
|
||||||
|
|
||||||
base_class = GST_AUDIO_DECODER_CLASS (klass);
|
|
||||||
element_class = GST_ELEMENT_CLASS (klass);
|
|
||||||
|
|
||||||
gst_element_class_set_static_metadata (element_class,
|
|
||||||
"mpg123 mp3 decoder",
|
|
||||||
"Codec/Decoder/Audio",
|
|
||||||
"Decodes mp3 streams using the mpg123 library",
|
|
||||||
"Carlos Rafael Giani <dv@pseudoterminal.org>");
|
|
||||||
|
|
||||||
/* Not using static pad template for srccaps, since the comma-separated list
|
|
||||||
* of formats needs to be created depending on whatever mpg123 supports */
|
|
||||||
{
|
|
||||||
const int *format_list;
|
|
||||||
const long *rates_list;
|
|
||||||
size_t num, i;
|
|
||||||
GString *s;
|
|
||||||
GstCaps *src_template_caps;
|
|
||||||
|
|
||||||
s = g_string_new ("audio/x-raw, ");
|
|
||||||
|
|
||||||
mpg123_encodings (&format_list, &num);
|
|
||||||
g_string_append (s, "format = { ");
|
|
||||||
for (i = 0; i < num; ++i) {
|
|
||||||
switch (format_list[i]) {
|
|
||||||
case MPG123_ENC_SIGNED_16:
|
|
||||||
g_string_append (s, (i > 0) ? ", " : "");
|
|
||||||
g_string_append (s, GST_AUDIO_NE (S16));
|
|
||||||
break;
|
|
||||||
case MPG123_ENC_UNSIGNED_16:
|
|
||||||
g_string_append (s, (i > 0) ? ", " : "");
|
|
||||||
g_string_append (s, GST_AUDIO_NE (U16));
|
|
||||||
break;
|
|
||||||
case MPG123_ENC_SIGNED_24:
|
|
||||||
g_string_append (s, (i > 0) ? ", " : "");
|
|
||||||
g_string_append (s, GST_AUDIO_NE (S24));
|
|
||||||
break;
|
|
||||||
case MPG123_ENC_UNSIGNED_24:
|
|
||||||
g_string_append (s, (i > 0) ? ", " : "");
|
|
||||||
g_string_append (s, GST_AUDIO_NE (U24));
|
|
||||||
break;
|
|
||||||
case MPG123_ENC_SIGNED_32:
|
|
||||||
g_string_append (s, (i > 0) ? ", " : "");
|
|
||||||
g_string_append (s, GST_AUDIO_NE (S32));
|
|
||||||
break;
|
|
||||||
case MPG123_ENC_UNSIGNED_32:
|
|
||||||
g_string_append (s, (i > 0) ? ", " : "");
|
|
||||||
g_string_append (s, GST_AUDIO_NE (U32));
|
|
||||||
break;
|
|
||||||
case MPG123_ENC_FLOAT_32:
|
|
||||||
g_string_append (s, (i > 0) ? ", " : "");
|
|
||||||
g_string_append (s, GST_AUDIO_NE (F32));
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
GST_DEBUG ("Ignoring mpg123 format %d", format_list[i]);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
g_string_append (s, " }, ");
|
|
||||||
|
|
||||||
mpg123_rates (&rates_list, &num);
|
|
||||||
g_string_append (s, "rate = (int) { ");
|
|
||||||
for (i = 0; i < num; ++i) {
|
|
||||||
g_string_append_printf (s, "%s%lu", (i > 0) ? ", " : "", rates_list[i]);
|
|
||||||
}
|
|
||||||
g_string_append (s, "}, ");
|
|
||||||
|
|
||||||
g_string_append (s, "channels = (int) [ 1, 2 ], ");
|
|
||||||
g_string_append (s, "layout = (string) interleaved");
|
|
||||||
|
|
||||||
src_template_caps = gst_caps_from_string (s->str);
|
|
||||||
src_template = gst_pad_template_new ("src", GST_PAD_SRC, GST_PAD_ALWAYS,
|
|
||||||
src_template_caps);
|
|
||||||
gst_caps_unref (src_template_caps);
|
|
||||||
|
|
||||||
g_string_free (s, TRUE);
|
|
||||||
}
|
|
||||||
|
|
||||||
sink_template = gst_static_pad_template_get (&static_sink_template);
|
|
||||||
|
|
||||||
gst_element_class_add_pad_template (element_class, sink_template);
|
|
||||||
gst_element_class_add_pad_template (element_class, src_template);
|
|
||||||
|
|
||||||
base_class->start = GST_DEBUG_FUNCPTR (gst_mpg123_audio_dec_start);
|
|
||||||
base_class->stop = GST_DEBUG_FUNCPTR (gst_mpg123_audio_dec_stop);
|
|
||||||
base_class->handle_frame =
|
|
||||||
GST_DEBUG_FUNCPTR (gst_mpg123_audio_dec_handle_frame);
|
|
||||||
base_class->set_format = GST_DEBUG_FUNCPTR (gst_mpg123_audio_dec_set_format);
|
|
||||||
base_class->flush = GST_DEBUG_FUNCPTR (gst_mpg123_audio_dec_flush);
|
|
||||||
|
|
||||||
error = mpg123_init ();
|
|
||||||
if (G_UNLIKELY (error != MPG123_OK))
|
|
||||||
GST_ERROR ("Could not initialize mpg123 library: %s",
|
|
||||||
mpg123_plain_strerror (error));
|
|
||||||
else
|
|
||||||
GST_INFO ("mpg123 library initialized");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
gst_mpg123_audio_dec_init (GstMpg123AudioDec * mpg123_decoder)
|
|
||||||
{
|
|
||||||
mpg123_decoder->handle = NULL;
|
|
||||||
gst_audio_decoder_set_needs_format (GST_AUDIO_DECODER (mpg123_decoder), TRUE);
|
|
||||||
gst_audio_decoder_set_use_default_pad_acceptcaps (GST_AUDIO_DECODER_CAST
|
|
||||||
(mpg123_decoder), TRUE);
|
|
||||||
GST_PAD_SET_ACCEPT_TEMPLATE (GST_AUDIO_DECODER_SINK_PAD (mpg123_decoder));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static gboolean
|
|
||||||
gst_mpg123_audio_dec_start (GstAudioDecoder * dec)
|
|
||||||
{
|
|
||||||
GstMpg123AudioDec *mpg123_decoder;
|
|
||||||
int error;
|
|
||||||
|
|
||||||
mpg123_decoder = GST_MPG123_AUDIO_DEC (dec);
|
|
||||||
error = 0;
|
|
||||||
|
|
||||||
mpg123_decoder->handle = mpg123_new (NULL, &error);
|
|
||||||
mpg123_decoder->has_next_audioinfo = FALSE;
|
|
||||||
mpg123_decoder->frame_offset = 0;
|
|
||||||
|
|
||||||
/* Initially, the mpg123 handle comes with a set of default formats
|
|
||||||
* supported. This clears this set. This is necessary, since only one
|
|
||||||
* format shall be supported (see set_format for more). */
|
|
||||||
mpg123_format_none (mpg123_decoder->handle);
|
|
||||||
|
|
||||||
/* Built-in mpg123 support for gapless decoding is disabled for now,
|
|
||||||
* since it does not work well with seeking */
|
|
||||||
mpg123_param (mpg123_decoder->handle, MPG123_REMOVE_FLAGS, MPG123_GAPLESS, 0);
|
|
||||||
/* Tells mpg123 to use a small read-ahead buffer for better MPEG sync;
|
|
||||||
* essential for MP3 radio streams */
|
|
||||||
mpg123_param (mpg123_decoder->handle, MPG123_ADD_FLAGS, MPG123_SEEKBUFFER, 0);
|
|
||||||
/* Sets the resync limit to the end of the stream (otherwise mpg123 may give
|
|
||||||
* up on decoding prematurely, especially with mp3 web radios) */
|
|
||||||
mpg123_param (mpg123_decoder->handle, MPG123_RESYNC_LIMIT, -1, 0);
|
|
||||||
#if MPG123_API_VERSION >= 36
|
|
||||||
/* The precise API version where MPG123_AUTO_RESAMPLE appeared is
|
|
||||||
* somewhere between 29 and 36 */
|
|
||||||
/* Don't let mpg123 resample output */
|
|
||||||
mpg123_param (mpg123_decoder->handle, MPG123_REMOVE_FLAGS,
|
|
||||||
MPG123_AUTO_RESAMPLE, 0);
|
|
||||||
#endif
|
|
||||||
/* Don't let mpg123 print messages to stdout/stderr */
|
|
||||||
mpg123_param (mpg123_decoder->handle, MPG123_ADD_FLAGS, MPG123_QUIET, 0);
|
|
||||||
|
|
||||||
/* Open in feed mode (= encoded data is fed manually into the handle). */
|
|
||||||
error = mpg123_open_feed (mpg123_decoder->handle);
|
|
||||||
|
|
||||||
if (G_UNLIKELY (error != MPG123_OK)) {
|
|
||||||
GST_ELEMENT_ERROR (dec, LIBRARY, INIT, (NULL),
|
|
||||||
("%s", mpg123_strerror (mpg123_decoder->handle)));
|
|
||||||
mpg123_close (mpg123_decoder->handle);
|
|
||||||
mpg123_delete (mpg123_decoder->handle);
|
|
||||||
mpg123_decoder->handle = NULL;
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
GST_INFO_OBJECT (dec, "mpg123 decoder started");
|
|
||||||
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static gboolean
|
|
||||||
gst_mpg123_audio_dec_stop (GstAudioDecoder * dec)
|
|
||||||
{
|
|
||||||
GstMpg123AudioDec *mpg123_decoder = GST_MPG123_AUDIO_DEC (dec);
|
|
||||||
|
|
||||||
if (G_LIKELY (mpg123_decoder->handle != NULL)) {
|
|
||||||
mpg123_close (mpg123_decoder->handle);
|
|
||||||
mpg123_delete (mpg123_decoder->handle);
|
|
||||||
mpg123_decoder->handle = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
GST_INFO_OBJECT (dec, "mpg123 decoder stopped");
|
|
||||||
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static GstFlowReturn
|
|
||||||
gst_mpg123_audio_dec_push_decoded_bytes (GstMpg123AudioDec * mpg123_decoder,
|
|
||||||
unsigned char const *decoded_bytes, size_t const num_decoded_bytes)
|
|
||||||
{
|
|
||||||
GstBuffer *output_buffer;
|
|
||||||
GstAudioDecoder *dec;
|
|
||||||
|
|
||||||
output_buffer = NULL;
|
|
||||||
dec = GST_AUDIO_DECODER (mpg123_decoder);
|
|
||||||
|
|
||||||
if ((num_decoded_bytes == 0) || (decoded_bytes == NULL)) {
|
|
||||||
/* This occurs in the first few frames, which do not carry data; once
|
|
||||||
* MPG123_AUDIO_DEC_NEW_FORMAT is received, the empty frames stop occurring */
|
|
||||||
GST_DEBUG_OBJECT (mpg123_decoder,
|
|
||||||
"cannot decode yet, need more data -> no output buffer to push");
|
|
||||||
return GST_FLOW_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
output_buffer = gst_buffer_new_allocate (NULL, num_decoded_bytes, NULL);
|
|
||||||
|
|
||||||
if (output_buffer == NULL) {
|
|
||||||
/* This is necessary to advance playback in time,
|
|
||||||
* even when nothing was decoded. */
|
|
||||||
return gst_audio_decoder_finish_frame (dec, NULL, 1);
|
|
||||||
} else {
|
|
||||||
GstMapInfo info;
|
|
||||||
|
|
||||||
if (gst_buffer_map (output_buffer, &info, GST_MAP_WRITE)) {
|
|
||||||
memcpy (info.data, decoded_bytes, num_decoded_bytes);
|
|
||||||
gst_buffer_unmap (output_buffer, &info);
|
|
||||||
} else {
|
|
||||||
GST_ERROR_OBJECT (mpg123_decoder, "gst_buffer_map() returned NULL");
|
|
||||||
gst_buffer_unref (output_buffer);
|
|
||||||
output_buffer = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
return gst_audio_decoder_finish_frame (dec, output_buffer, 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static GstFlowReturn
|
|
||||||
gst_mpg123_audio_dec_handle_frame (GstAudioDecoder * dec,
|
|
||||||
GstBuffer * input_buffer)
|
|
||||||
{
|
|
||||||
GstMpg123AudioDec *mpg123_decoder;
|
|
||||||
int decode_error;
|
|
||||||
unsigned char *decoded_bytes;
|
|
||||||
size_t num_decoded_bytes;
|
|
||||||
GstFlowReturn retval;
|
|
||||||
|
|
||||||
mpg123_decoder = GST_MPG123_AUDIO_DEC (dec);
|
|
||||||
|
|
||||||
g_assert (mpg123_decoder->handle != NULL);
|
|
||||||
|
|
||||||
/* The actual decoding */
|
|
||||||
{
|
|
||||||
/* feed input data (if there is any) */
|
|
||||||
if (G_LIKELY (input_buffer != NULL)) {
|
|
||||||
GstMapInfo info;
|
|
||||||
|
|
||||||
if (gst_buffer_map (input_buffer, &info, GST_MAP_READ)) {
|
|
||||||
mpg123_feed (mpg123_decoder->handle, info.data, info.size);
|
|
||||||
gst_buffer_unmap (input_buffer, &info);
|
|
||||||
} else {
|
|
||||||
GST_AUDIO_DECODER_ERROR (mpg123_decoder, 1, RESOURCE, READ, (NULL),
|
|
||||||
("gst_memory_map() failed"), retval);
|
|
||||||
return retval;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Try to decode a frame */
|
|
||||||
decoded_bytes = NULL;
|
|
||||||
num_decoded_bytes = 0;
|
|
||||||
decode_error = mpg123_decode_frame (mpg123_decoder->handle,
|
|
||||||
&mpg123_decoder->frame_offset, &decoded_bytes, &num_decoded_bytes);
|
|
||||||
}
|
|
||||||
|
|
||||||
retval = GST_FLOW_OK;
|
|
||||||
|
|
||||||
switch (decode_error) {
|
|
||||||
case MPG123_NEW_FORMAT:
|
|
||||||
/* As mentioned in gst_mpg123_audio_dec_set_format(), the next audioinfo
|
|
||||||
* is not set immediately; instead, the code waits for mpg123 to take
|
|
||||||
* note of the new format, and then sets the audioinfo. This fixes glitches
|
|
||||||
* with mp3s containing several format headers (for example, first half
|
|
||||||
* using 44.1kHz, second half 32 kHz) */
|
|
||||||
|
|
||||||
GST_LOG_OBJECT (dec,
|
|
||||||
"mpg123 reported a new format -> setting next srccaps");
|
|
||||||
|
|
||||||
gst_mpg123_audio_dec_push_decoded_bytes (mpg123_decoder, decoded_bytes,
|
|
||||||
num_decoded_bytes);
|
|
||||||
|
|
||||||
/* If there is a next audioinfo, use it, then set has_next_audioinfo to
|
|
||||||
* FALSE, to make sure gst_audio_decoder_set_output_format() isn't called
|
|
||||||
* again until set_format is called by the base class */
|
|
||||||
if (mpg123_decoder->has_next_audioinfo) {
|
|
||||||
if (!gst_audio_decoder_set_output_format (dec,
|
|
||||||
&(mpg123_decoder->next_audioinfo))) {
|
|
||||||
GST_WARNING_OBJECT (dec, "Unable to set output format");
|
|
||||||
retval = GST_FLOW_NOT_NEGOTIATED;
|
|
||||||
}
|
|
||||||
mpg123_decoder->has_next_audioinfo = FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
|
|
||||||
case MPG123_NEED_MORE:
|
|
||||||
case MPG123_OK:
|
|
||||||
retval = gst_mpg123_audio_dec_push_decoded_bytes (mpg123_decoder,
|
|
||||||
decoded_bytes, num_decoded_bytes);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case MPG123_DONE:
|
|
||||||
/* If this happens, then the upstream parser somehow missed the ending
|
|
||||||
* of the bitstream */
|
|
||||||
GST_LOG_OBJECT (dec, "mpg123 is done decoding");
|
|
||||||
gst_mpg123_audio_dec_push_decoded_bytes (mpg123_decoder, decoded_bytes,
|
|
||||||
num_decoded_bytes);
|
|
||||||
retval = GST_FLOW_EOS;
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
{
|
|
||||||
/* Anything else is considered an error */
|
|
||||||
int errcode;
|
|
||||||
retval = GST_FLOW_ERROR; /* use error by default */
|
|
||||||
switch (decode_error) {
|
|
||||||
case MPG123_ERR:
|
|
||||||
errcode = mpg123_errcode (mpg123_decoder->handle);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
errcode = decode_error;
|
|
||||||
}
|
|
||||||
switch (errcode) {
|
|
||||||
case MPG123_BAD_OUTFORMAT:{
|
|
||||||
GstCaps *input_caps =
|
|
||||||
gst_pad_get_current_caps (GST_AUDIO_DECODER_SINK_PAD (dec));
|
|
||||||
GST_ELEMENT_ERROR (dec, STREAM, FORMAT, (NULL),
|
|
||||||
("Output sample format could not be used when trying to decode frame. "
|
|
||||||
"This is typically caused when the input caps (often the sample "
|
|
||||||
"rate) do not match the actual format of the audio data. "
|
|
||||||
"Input caps: %" GST_PTR_FORMAT, input_caps)
|
|
||||||
);
|
|
||||||
gst_caps_unref (input_caps);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default:{
|
|
||||||
char const *errmsg = mpg123_plain_strerror (errcode);
|
|
||||||
/* GST_AUDIO_DECODER_ERROR sets a new return value according to
|
|
||||||
* its estimations */
|
|
||||||
GST_AUDIO_DECODER_ERROR (mpg123_decoder, 1, STREAM, DECODE, (NULL),
|
|
||||||
("mpg123 decoding error: %s", errmsg), retval);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return retval;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static gboolean
|
|
||||||
gst_mpg123_audio_dec_set_format (GstAudioDecoder * dec, GstCaps * input_caps)
|
|
||||||
{
|
|
||||||
/* "encoding" is the sample format specifier for mpg123 */
|
|
||||||
int encoding;
|
|
||||||
int sample_rate, num_channels;
|
|
||||||
GstAudioFormat format;
|
|
||||||
GstMpg123AudioDec *mpg123_decoder;
|
|
||||||
gboolean retval = FALSE;
|
|
||||||
|
|
||||||
mpg123_decoder = GST_MPG123_AUDIO_DEC (dec);
|
|
||||||
|
|
||||||
g_assert (mpg123_decoder->handle != NULL);
|
|
||||||
|
|
||||||
mpg123_decoder->has_next_audioinfo = FALSE;
|
|
||||||
|
|
||||||
/* Get sample rate and number of channels from input_caps */
|
|
||||||
{
|
|
||||||
GstStructure *structure;
|
|
||||||
gboolean err = FALSE;
|
|
||||||
|
|
||||||
/* Only the first structure is used (multiple
|
|
||||||
* input caps structures don't make sense */
|
|
||||||
structure = gst_caps_get_structure (input_caps, 0);
|
|
||||||
|
|
||||||
if (!gst_structure_get_int (structure, "rate", &sample_rate)) {
|
|
||||||
err = TRUE;
|
|
||||||
GST_ERROR_OBJECT (dec, "Input caps do not have a rate value");
|
|
||||||
}
|
|
||||||
if (!gst_structure_get_int (structure, "channels", &num_channels)) {
|
|
||||||
err = TRUE;
|
|
||||||
GST_ERROR_OBJECT (dec, "Input caps do not have a channel value");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (G_UNLIKELY (err))
|
|
||||||
goto done;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Get sample format from the allowed src caps */
|
|
||||||
{
|
|
||||||
GstCaps *allowed_srccaps =
|
|
||||||
gst_pad_get_allowed_caps (GST_AUDIO_DECODER_SRC_PAD (dec));
|
|
||||||
|
|
||||||
if (allowed_srccaps == NULL) {
|
|
||||||
/* srcpad is not linked (yet), so no peer information is available;
|
|
||||||
* just use the default sample format (16 bit signed integer) */
|
|
||||||
GST_DEBUG_OBJECT (mpg123_decoder,
|
|
||||||
"srcpad is not linked (yet) -> using S16 sample format");
|
|
||||||
format = GST_AUDIO_FORMAT_S16;
|
|
||||||
encoding = MPG123_ENC_SIGNED_16;
|
|
||||||
} else if (gst_caps_is_empty (allowed_srccaps)) {
|
|
||||||
gst_caps_unref (allowed_srccaps);
|
|
||||||
goto done;
|
|
||||||
} else {
|
|
||||||
gchar const *format_str;
|
|
||||||
GValue const *format_value;
|
|
||||||
|
|
||||||
/* Look at the sample format values from the first structure */
|
|
||||||
GstStructure *structure = gst_caps_get_structure (allowed_srccaps, 0);
|
|
||||||
format_value = gst_structure_get_value (structure, "format");
|
|
||||||
|
|
||||||
if (format_value == NULL) {
|
|
||||||
gst_caps_unref (allowed_srccaps);
|
|
||||||
goto done;
|
|
||||||
} else if (GST_VALUE_HOLDS_LIST (format_value)) {
|
|
||||||
/* if value is a format list, pick the first entry */
|
|
||||||
GValue const *fmt_list_value =
|
|
||||||
gst_value_list_get_value (format_value, 0);
|
|
||||||
format_str = g_value_get_string (fmt_list_value);
|
|
||||||
} else if (G_VALUE_HOLDS_STRING (format_value)) {
|
|
||||||
/* if value is a string, use it directly */
|
|
||||||
format_str = g_value_get_string (format_value);
|
|
||||||
} else {
|
|
||||||
GST_ERROR_OBJECT (mpg123_decoder, "unexpected type for 'format' field "
|
|
||||||
"in caps structure %" GST_PTR_FORMAT, structure);
|
|
||||||
gst_caps_unref (allowed_srccaps);
|
|
||||||
goto done;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* get the format value from the string */
|
|
||||||
format = gst_audio_format_from_string (format_str);
|
|
||||||
gst_caps_unref (allowed_srccaps);
|
|
||||||
|
|
||||||
g_assert (format != GST_AUDIO_FORMAT_UNKNOWN);
|
|
||||||
|
|
||||||
/* convert format to mpg123 encoding */
|
|
||||||
switch (format) {
|
|
||||||
case GST_AUDIO_FORMAT_S16:
|
|
||||||
encoding = MPG123_ENC_SIGNED_16;
|
|
||||||
break;
|
|
||||||
case GST_AUDIO_FORMAT_S24:
|
|
||||||
encoding = MPG123_ENC_SIGNED_24;
|
|
||||||
break;
|
|
||||||
case GST_AUDIO_FORMAT_S32:
|
|
||||||
encoding = MPG123_ENC_SIGNED_32;
|
|
||||||
break;
|
|
||||||
case GST_AUDIO_FORMAT_U16:
|
|
||||||
encoding = MPG123_ENC_UNSIGNED_16;
|
|
||||||
break;
|
|
||||||
case GST_AUDIO_FORMAT_U24:
|
|
||||||
encoding = MPG123_ENC_UNSIGNED_24;
|
|
||||||
break;
|
|
||||||
case GST_AUDIO_FORMAT_U32:
|
|
||||||
encoding = MPG123_ENC_UNSIGNED_32;
|
|
||||||
break;
|
|
||||||
case GST_AUDIO_FORMAT_F32:
|
|
||||||
encoding = MPG123_ENC_FLOAT_32;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
g_assert_not_reached ();
|
|
||||||
goto done;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Sample rate, number of channels, and sample format are known at this point.
|
|
||||||
* Set the audioinfo structure's values and the mpg123 format. */
|
|
||||||
{
|
|
||||||
int err;
|
|
||||||
|
|
||||||
/* clear all existing format settings from the mpg123 instance */
|
|
||||||
mpg123_format_none (mpg123_decoder->handle);
|
|
||||||
/* set the chosen format */
|
|
||||||
err =
|
|
||||||
mpg123_format (mpg123_decoder->handle, sample_rate, num_channels,
|
|
||||||
encoding);
|
|
||||||
|
|
||||||
if (err != MPG123_OK) {
|
|
||||||
GST_WARNING_OBJECT (dec,
|
|
||||||
"mpg123_format() failed: %s",
|
|
||||||
mpg123_strerror (mpg123_decoder->handle));
|
|
||||||
} else {
|
|
||||||
gst_audio_info_init (&(mpg123_decoder->next_audioinfo));
|
|
||||||
gst_audio_info_set_format (&(mpg123_decoder->next_audioinfo), format,
|
|
||||||
sample_rate, num_channels, NULL);
|
|
||||||
GST_LOG_OBJECT (dec, "The next audio format is: %s, %u Hz, %u channels",
|
|
||||||
gst_audio_format_to_string (format), sample_rate, num_channels);
|
|
||||||
mpg123_decoder->has_next_audioinfo = TRUE;
|
|
||||||
|
|
||||||
retval = TRUE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
done:
|
|
||||||
return retval;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static void
|
|
||||||
gst_mpg123_audio_dec_flush (GstAudioDecoder * dec, gboolean hard)
|
|
||||||
{
|
|
||||||
int error;
|
|
||||||
GstMpg123AudioDec *mpg123_decoder;
|
|
||||||
|
|
||||||
GST_LOG_OBJECT (dec, "Flushing decoder");
|
|
||||||
|
|
||||||
mpg123_decoder = GST_MPG123_AUDIO_DEC (dec);
|
|
||||||
|
|
||||||
g_assert (mpg123_decoder->handle != NULL);
|
|
||||||
|
|
||||||
/* Flush by reopening the feed */
|
|
||||||
mpg123_close (mpg123_decoder->handle);
|
|
||||||
error = mpg123_open_feed (mpg123_decoder->handle);
|
|
||||||
|
|
||||||
if (G_UNLIKELY (error != MPG123_OK)) {
|
|
||||||
GST_ELEMENT_ERROR (dec, LIBRARY, INIT, (NULL),
|
|
||||||
("Error while reopening mpg123 feed: %s",
|
|
||||||
mpg123_plain_strerror (error)));
|
|
||||||
mpg123_close (mpg123_decoder->handle);
|
|
||||||
mpg123_delete (mpg123_decoder->handle);
|
|
||||||
mpg123_decoder->handle = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (hard)
|
|
||||||
mpg123_decoder->has_next_audioinfo = FALSE;
|
|
||||||
|
|
||||||
/* opening/closing feeds do not affect the format defined by the
|
|
||||||
* mpg123_format() call that was made in gst_mpg123_audio_dec_set_format(),
|
|
||||||
* and since the up/downstream caps are not expected to change here, no
|
|
||||||
* mpg123_format() calls are done */
|
|
||||||
}
|
|
||||||
|
|
||||||
static gboolean
|
|
||||||
plugin_init (GstPlugin * plugin)
|
|
||||||
{
|
|
||||||
return gst_element_register (plugin, "mpg123audiodec",
|
|
||||||
GST_RANK_MARGINAL, gst_mpg123_audio_dec_get_type ());
|
|
||||||
}
|
|
||||||
|
|
||||||
GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
|
|
||||||
GST_VERSION_MINOR,
|
|
||||||
mpg123, "mp3 decoding based on the mpg123 library",
|
|
||||||
plugin_init, VERSION, "LGPL", GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN)
|
|
|
@ -1,74 +0,0 @@
|
||||||
/* MP3 decoding plugin for GStreamer using the mpg123 library
|
|
||||||
* Copyright (C) 2012 Carlos Rafael Giani
|
|
||||||
*
|
|
||||||
* This library is free software; you can redistribute it and/or
|
|
||||||
* modify it under the terms of the GNU Lesser General Public
|
|
||||||
* License as published by the Free Software Foundation; either
|
|
||||||
* version 2.1 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
|
|
||||||
* Lesser General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Lesser General Public
|
|
||||||
* License along with this library; if not, write to the Free Software
|
|
||||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef __GST_MPG123_AUDIO_DEC_H__
|
|
||||||
#define __GST_MPG123_AUDIO_DEC_H__
|
|
||||||
|
|
||||||
/* This is what the visual studio build in mpg123 does before including the
|
|
||||||
* original header file. Without this we get syntax errors in the
|
|
||||||
* replace_reader function declarations because it doesn't know ssize_t etc.
|
|
||||||
* It doesn't realy matter for us if the ssize_t typedef here is correct. */
|
|
||||||
#ifdef _MSC_VER
|
|
||||||
#include <tchar.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <sys/types.h>
|
|
||||||
typedef long ssize_t;
|
|
||||||
#include <stdint.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <gst/gst.h>
|
|
||||||
#include <gst/audio/gstaudiodecoder.h>
|
|
||||||
#include <mpg123.h>
|
|
||||||
|
|
||||||
|
|
||||||
G_BEGIN_DECLS
|
|
||||||
|
|
||||||
|
|
||||||
typedef struct _GstMpg123AudioDec GstMpg123AudioDec;
|
|
||||||
typedef struct _GstMpg123AudioDecClass GstMpg123AudioDecClass;
|
|
||||||
|
|
||||||
|
|
||||||
#define GST_TYPE_MPG123_AUDIO_DEC (gst_mpg123_audio_dec_get_type())
|
|
||||||
#define GST_MPG123_AUDIO_DEC(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), GST_TYPE_MPG123_AUDIO_DEC,GstMpg123AudioDec))
|
|
||||||
#define GST_MPG123_AUDIO_DEC_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), GST_TYPE_MPG123_AUDIO_DEC,GstMpg123AudioDecClass))
|
|
||||||
#define GST_IS_MPG123_AUDIO_DEC(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), GST_TYPE_MPG123_AUDIO_DEC))
|
|
||||||
#define GST_IS_MPG123_AUDIO_DEC_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), GST_TYPE_MPG123_AUDIO_DEC))
|
|
||||||
|
|
||||||
struct _GstMpg123AudioDec
|
|
||||||
{
|
|
||||||
GstAudioDecoder parent;
|
|
||||||
|
|
||||||
mpg123_handle *handle;
|
|
||||||
|
|
||||||
GstAudioInfo next_audioinfo;
|
|
||||||
gboolean has_next_audioinfo;
|
|
||||||
|
|
||||||
off_t frame_offset;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
struct _GstMpg123AudioDecClass
|
|
||||||
{
|
|
||||||
GstAudioDecoderClass parent_class;
|
|
||||||
};
|
|
||||||
|
|
||||||
G_GNUC_INTERNAL GType gst_mpg123_audio_dec_get_type (void);
|
|
||||||
|
|
||||||
G_END_DECLS
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -1,16 +0,0 @@
|
||||||
mpg123_sources = [
|
|
||||||
'gstmpg123audiodec.c',
|
|
||||||
]
|
|
||||||
|
|
||||||
mpg123_dep = dependency('libmpg123', version : '>= 1.3', required : false)
|
|
||||||
|
|
||||||
if mpg123_dep.found()
|
|
||||||
gstmpg123 = library('gstmpg123',
|
|
||||||
mpg123_sources,
|
|
||||||
c_args : ugly_args,
|
|
||||||
include_directories : [configinc],
|
|
||||||
dependencies : [gstaudio_dep, mpg123_dep],
|
|
||||||
install : true,
|
|
||||||
install_dir : plugins_install_dir,
|
|
||||||
)
|
|
||||||
endif
|
|
|
@ -38,12 +38,6 @@ else
|
||||||
MPEG2DEC =
|
MPEG2DEC =
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if USE_MPG123
|
|
||||||
check_mpg123 = elements/mpg123audiodec
|
|
||||||
else
|
|
||||||
check_mpg123 =
|
|
||||||
endif
|
|
||||||
|
|
||||||
if USE_X264
|
if USE_X264
|
||||||
check_x264enc=elements/x264enc
|
check_x264enc=elements/x264enc
|
||||||
else
|
else
|
||||||
|
@ -62,7 +56,6 @@ check_PROGRAMS = \
|
||||||
$(AMRNB) \
|
$(AMRNB) \
|
||||||
$(LAME) \
|
$(LAME) \
|
||||||
$(MPEG2DEC) \
|
$(MPEG2DEC) \
|
||||||
$(check_mpg123) \
|
|
||||||
$(check_x264enc) \
|
$(check_x264enc) \
|
||||||
$(check_xingmux)
|
$(check_xingmux)
|
||||||
|
|
||||||
|
@ -86,14 +79,6 @@ SUPPRESSIONS = $(top_srcdir)/common/gst.supp $(srcdir)/gst-plugins-ugly.supp
|
||||||
elements_amrnbenc_CFLAGS = $(GST_PLUGINS_BASE_CFLAGS) $(AM_CFLAGS)
|
elements_amrnbenc_CFLAGS = $(GST_PLUGINS_BASE_CFLAGS) $(AM_CFLAGS)
|
||||||
elements_amrnbenc_LDADD = $(GST_PLUGINS_BASE_LIBS) -lgstaudio-$(GST_API_VERSION) $(LDADD)
|
elements_amrnbenc_LDADD = $(GST_PLUGINS_BASE_LIBS) -lgstaudio-$(GST_API_VERSION) $(LDADD)
|
||||||
|
|
||||||
elements_cmmldec_CFLAGS = $(GST_PLUGINS_BASE_CFLAGS) $(AM_CFLAGS)
|
|
||||||
elements_cmmlenc_CFLAGS = $(GST_PLUGINS_BASE_CFLAGS) $(AM_CFLAGS)
|
|
||||||
|
|
||||||
elements_mpg123audiodec_CFLAGS = $(GST_PLUGINS_BASE_CFLAGS) $(GST_BASE_CFLAGS) $(AM_CFLAGS)
|
|
||||||
elements_mpg123audiodec_LDADD = \
|
|
||||||
$(GST_PLUGINS_BASE_LIBS) $(GST_BASE_LIBS) $(GST_LIBS) $(LDADD) \
|
|
||||||
-lgstaudio-@GST_API_VERSION@ -lgstfft-@GST_API_VERSION@ -lgstapp-@GST_API_VERSION@
|
|
||||||
|
|
||||||
elements_mpeg2dec_CFLAGS = $(GST_PLUGINS_BASE_CFLAGS) $(GST_BASE_CFLAGS) $(AM_CFLAGS)
|
elements_mpeg2dec_CFLAGS = $(GST_PLUGINS_BASE_CFLAGS) $(GST_BASE_CFLAGS) $(AM_CFLAGS)
|
||||||
elements_mpeg2dec_LDADD = $(GST_PLUGINS_BASE_LIBS) $(GST_BASE_LIBS) $(GST_LIBS) $(LDADD) \
|
elements_mpeg2dec_LDADD = $(GST_PLUGINS_BASE_LIBS) $(GST_BASE_LIBS) $(GST_LIBS) $(LDADD) \
|
||||||
-lgstvideo-@GST_API_VERSION@
|
-lgstvideo-@GST_API_VERSION@
|
||||||
|
|
1
tests/check/elements/.gitignore
vendored
1
tests/check/elements/.gitignore
vendored
|
@ -1,6 +1,5 @@
|
||||||
amrnbenc
|
amrnbenc
|
||||||
mpeg2dec
|
mpeg2dec
|
||||||
mpg123audiodec
|
|
||||||
x264enc
|
x264enc
|
||||||
xingmux
|
xingmux
|
||||||
.dirstamp
|
.dirstamp
|
||||||
|
|
|
@ -1,534 +0,0 @@
|
||||||
/* GStreamer
|
|
||||||
*
|
|
||||||
* unit test for mpg123audiodec
|
|
||||||
*
|
|
||||||
* Copyright (c) 2012 Carlos Rafael Giani <dv@pseudoterminal.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., 51 Franklin St, Fifth Floor,
|
|
||||||
* Boston, MA 02110-1301, USA.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
#include <gst/check/gstcheck.h>
|
|
||||||
#include <gst/audio/audio.h>
|
|
||||||
|
|
||||||
#include <gst/fft/gstfft.h>
|
|
||||||
#include <gst/fft/gstffts16.h>
|
|
||||||
#include <gst/fft/gstffts32.h>
|
|
||||||
#include <gst/fft/gstfftf32.h>
|
|
||||||
#include <gst/fft/gstfftf64.h>
|
|
||||||
|
|
||||||
#include <gst/app/gstappsink.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 MP2_STREAM_FILENAME "stream.mp2"
|
|
||||||
#define MP3_CBR_STREAM_FILENAME "cbr_stream.mp3"
|
|
||||||
#define MP3_VBR_STREAM_FILENAME "vbr_stream.mp3"
|
|
||||||
|
|
||||||
|
|
||||||
/* mpeg 1 layer 2 stream created with:
|
|
||||||
* gst-launch-1.0 -v audiotestsrc wave=sine freq=440 volume=1 num-buffers=32 ! \
|
|
||||||
* "audio/x-raw, format=(string)S16LE, layout=(string)interleaved, rate=(int)44100, channels=(int)1" ! \
|
|
||||||
* avenc_mp2 bitrate=32000 ! tee name=t \
|
|
||||||
* t. ! queue ! fakesink silent=false \
|
|
||||||
* t. ! queue ! filesink location=test.mp2
|
|
||||||
*
|
|
||||||
* mpeg 1 layer 3 CBR stream created with:
|
|
||||||
* gst-launch-1.0 -v audiotestsrc wave=sine freq=440 volume=1 num-buffers=32 ! \
|
|
||||||
* "audio/x-raw, format=(string)S16LE, layout=(string)interleaved, rate=(int)44100, channels=(int)1" ! \
|
|
||||||
* lamemp3enc encoding-engine-quality=high cbr=true target=bitrate bitrate=32 ! \
|
|
||||||
* "audio/mpeg, rate=(int)44100, channels=(int)1" ! tee name=t \
|
|
||||||
* t. ! queue ! fakesink silent=false \
|
|
||||||
* t. ! queue ! filesink location=test.mp3
|
|
||||||
*
|
|
||||||
* mpeg 1 layer 3 VBR stream created with:
|
|
||||||
* gst-launch-1.0 -v audiotestsrc wave=sine freq=440 volume=1 num-buffers=32 ! \
|
|
||||||
* "audio/x-raw, format=(string)S16LE, layout=(string)interleaved, rate=(int)44100, channels=(int)1" ! \
|
|
||||||
* lamemp3enc encoding-engine-quality=high cbr=false target=quality quality=7 ! \
|
|
||||||
* "audio/mpeg, rate=(int)44100, channels=(int)1" ! tee name=t \
|
|
||||||
* t. ! queue ! fakesink silent=false \
|
|
||||||
* t. ! queue ! filesink location=test.mp3
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
/* FFT test helpers taken from gst-plugins-base tests/check/audioresample.c */
|
|
||||||
|
|
||||||
#define FFT_HELPERS(type,ffttag,ffttag2,scale) \
|
|
||||||
static gdouble magnitude##ffttag (const GstFFT##ffttag##Complex *c) \
|
|
||||||
{ \
|
|
||||||
gdouble mag = (gdouble) c->r * (gdouble) c->r; \
|
|
||||||
mag += (gdouble) c->i * (gdouble) c->i; \
|
|
||||||
mag /= scale * scale; \
|
|
||||||
mag = 10.0 * log10 (mag); \
|
|
||||||
return mag; \
|
|
||||||
} \
|
|
||||||
static gdouble find_main_frequency_spot_##ffttag ( \
|
|
||||||
const GstFFT##ffttag##Complex *v, int elements) \
|
|
||||||
{ \
|
|
||||||
int i; \
|
|
||||||
gdouble maxmag = -9999; \
|
|
||||||
int maxidx = 0; \
|
|
||||||
for (i=0; i<elements; ++i) { \
|
|
||||||
gdouble mag = magnitude##ffttag (v+i); \
|
|
||||||
if (mag > maxmag) { \
|
|
||||||
maxmag = mag; \
|
|
||||||
maxidx = i; \
|
|
||||||
} \
|
|
||||||
} \
|
|
||||||
return maxidx / (gdouble) elements; \
|
|
||||||
} \
|
|
||||||
static gboolean is_zero_except_##ffttag (const GstFFT##ffttag##Complex *v, \
|
|
||||||
int elements, gdouble spot) \
|
|
||||||
{ \
|
|
||||||
int i; \
|
|
||||||
for (i=0; i<elements; ++i) { \
|
|
||||||
gdouble pos = i / (gdouble) elements; \
|
|
||||||
gdouble mag = magnitude##ffttag (v+i); \
|
|
||||||
if (fabs (pos - spot) > 0.01) { \
|
|
||||||
if (mag > -35.0) { \
|
|
||||||
GST_LOG("Found magnitude at %f : %f (peak at %f)\n", pos, mag, spot); \
|
|
||||||
return FALSE; \
|
|
||||||
} \
|
|
||||||
} \
|
|
||||||
} \
|
|
||||||
return TRUE; \
|
|
||||||
} \
|
|
||||||
static void check_main_frequency_spot_##ffttag (GstBuffer *buffer, gdouble \
|
|
||||||
expected_spot) \
|
|
||||||
{ \
|
|
||||||
GstMapInfo map; \
|
|
||||||
int num_samples; \
|
|
||||||
gdouble actual_spot; \
|
|
||||||
GstFFT##ffttag *ctx; \
|
|
||||||
GstFFT##ffttag##Complex *fftdata; \
|
|
||||||
\
|
|
||||||
gst_buffer_map (buffer, &map, GST_MAP_READ); \
|
|
||||||
\
|
|
||||||
num_samples = map.size / sizeof(type) & ~1; \
|
|
||||||
ctx = gst_fft_##ffttag2##_new (num_samples, FALSE); \
|
|
||||||
fftdata = g_new (GstFFT##ffttag##Complex, num_samples / 2 + 1); \
|
|
||||||
\
|
|
||||||
gst_fft_##ffttag2##_window (ctx, (type*)map.data, \
|
|
||||||
GST_FFT_WINDOW_HAMMING); \
|
|
||||||
gst_fft_##ffttag2##_fft (ctx, (type*)map.data, fftdata); \
|
|
||||||
\
|
|
||||||
actual_spot = find_main_frequency_spot_##ffttag (fftdata, \
|
|
||||||
num_samples / 2 + 1); \
|
|
||||||
GST_LOG ("Expected spot: %.3f actual: %.3f %f", expected_spot, actual_spot, \
|
|
||||||
fabs (expected_spot - actual_spot)); \
|
|
||||||
fail_unless (fabs (expected_spot - actual_spot) < 0.05, \
|
|
||||||
"Actual main frequency spot is too far away from expected one"); \
|
|
||||||
fail_unless (is_zero_except_##ffttag (fftdata, num_samples / 2 + 1, \
|
|
||||||
actual_spot), "One secondary peak in spectrum exceeds threshold"); \
|
|
||||||
\
|
|
||||||
gst_buffer_unmap (buffer, &map); \
|
|
||||||
\
|
|
||||||
gst_fft_##ffttag2##_free (ctx); \
|
|
||||||
g_free (fftdata); \
|
|
||||||
}
|
|
||||||
FFT_HELPERS (gint32, S32, s32, 2147483647.0);
|
|
||||||
|
|
||||||
|
|
||||||
static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink",
|
|
||||||
GST_PAD_SINK,
|
|
||||||
GST_PAD_ALWAYS,
|
|
||||||
GST_STATIC_CAPS ("audio/x-raw, format = (string) " GST_AUDIO_NE (S32))
|
|
||||||
);
|
|
||||||
static GstStaticPadTemplate layer2_srctemplate = GST_STATIC_PAD_TEMPLATE ("src",
|
|
||||||
GST_PAD_SRC,
|
|
||||||
GST_PAD_ALWAYS,
|
|
||||||
GST_STATIC_CAPS_ANY);
|
|
||||||
static GstStaticPadTemplate layer3_srctemplate = GST_STATIC_PAD_TEMPLATE ("src",
|
|
||||||
GST_PAD_SRC,
|
|
||||||
GST_PAD_ALWAYS,
|
|
||||||
GST_STATIC_CAPS_ANY);
|
|
||||||
|
|
||||||
|
|
||||||
static void
|
|
||||||
setup_input_pipeline (gchar const *stream_filename, GstElement ** pipeline,
|
|
||||||
GstElement ** appsink)
|
|
||||||
{
|
|
||||||
GstElement *source, *parser;
|
|
||||||
|
|
||||||
*pipeline = gst_pipeline_new (NULL);
|
|
||||||
source = gst_element_factory_make ("filesrc", NULL);
|
|
||||||
parser = gst_element_factory_make ("mpegaudioparse", NULL);
|
|
||||||
*appsink = gst_element_factory_make ("appsink", NULL);
|
|
||||||
|
|
||||||
gst_bin_add_many (GST_BIN (*pipeline), source, parser, *appsink, NULL);
|
|
||||||
gst_element_link_many (source, parser, *appsink, NULL);
|
|
||||||
|
|
||||||
{
|
|
||||||
char *full_filename =
|
|
||||||
g_build_filename (GST_TEST_FILES_PATH, stream_filename, NULL);
|
|
||||||
g_object_set (G_OBJECT (source), "location", full_filename, NULL);
|
|
||||||
g_free (full_filename);
|
|
||||||
}
|
|
||||||
|
|
||||||
gst_element_set_state (*pipeline, GST_STATE_PLAYING);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
cleanup_input_pipeline (GstElement * pipeline)
|
|
||||||
{
|
|
||||||
gst_element_set_state (pipeline, GST_STATE_NULL);
|
|
||||||
gst_object_unref (pipeline);
|
|
||||||
}
|
|
||||||
|
|
||||||
static GstElement *
|
|
||||||
setup_mpeg1layer2dec (void)
|
|
||||||
{
|
|
||||||
GstElement *mpg123audiodec;
|
|
||||||
GstCaps *caps;
|
|
||||||
|
|
||||||
GST_DEBUG ("setup_mpeg1layer2dec");
|
|
||||||
mpg123audiodec = gst_check_setup_element ("mpg123audiodec");
|
|
||||||
mysrcpad = gst_check_setup_src_pad (mpg123audiodec, &layer2_srctemplate);
|
|
||||||
mysinkpad = gst_check_setup_sink_pad (mpg123audiodec, &sinktemplate);
|
|
||||||
gst_pad_set_active (mysrcpad, TRUE);
|
|
||||||
gst_pad_set_active (mysinkpad, TRUE);
|
|
||||||
|
|
||||||
/* This is necessary to trigger a set_format call in the decoder;
|
|
||||||
* fixed caps don't trigger it */
|
|
||||||
caps = gst_caps_new_simple ("audio/mpeg",
|
|
||||||
"mpegversion", G_TYPE_INT, 1,
|
|
||||||
"layer", G_TYPE_INT, 2,
|
|
||||||
"rate", G_TYPE_INT, 44100,
|
|
||||||
"channels", G_TYPE_INT, 1, "parsed", G_TYPE_BOOLEAN, TRUE, NULL);
|
|
||||||
gst_check_setup_events (mysrcpad, mpg123audiodec, caps, GST_FORMAT_TIME);
|
|
||||||
gst_caps_unref (caps);
|
|
||||||
|
|
||||||
return mpg123audiodec;
|
|
||||||
}
|
|
||||||
|
|
||||||
static GstElement *
|
|
||||||
setup_mpeg1layer3dec (void)
|
|
||||||
{
|
|
||||||
GstElement *mpg123audiodec;
|
|
||||||
GstCaps *caps;
|
|
||||||
|
|
||||||
GST_DEBUG ("setup_mpeg1layer3dec");
|
|
||||||
mpg123audiodec = gst_check_setup_element ("mpg123audiodec");
|
|
||||||
mysrcpad = gst_check_setup_src_pad (mpg123audiodec, &layer3_srctemplate);
|
|
||||||
mysinkpad = gst_check_setup_sink_pad (mpg123audiodec, &sinktemplate);
|
|
||||||
gst_pad_set_active (mysrcpad, TRUE);
|
|
||||||
gst_pad_set_active (mysinkpad, TRUE);
|
|
||||||
|
|
||||||
/* This is necessary to trigger a set_format call in the decoder;
|
|
||||||
* fixed caps don't trigger it */
|
|
||||||
caps = gst_caps_new_simple ("audio/mpeg",
|
|
||||||
"mpegversion", G_TYPE_INT, 1,
|
|
||||||
"layer", G_TYPE_INT, 3,
|
|
||||||
"rate", G_TYPE_INT, 44100,
|
|
||||||
"channels", G_TYPE_INT, 1, "parsed", G_TYPE_BOOLEAN, TRUE, NULL);
|
|
||||||
gst_check_setup_events (mysrcpad, mpg123audiodec, caps, GST_FORMAT_TIME);
|
|
||||||
gst_caps_unref (caps);
|
|
||||||
|
|
||||||
return mpg123audiodec;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
cleanup_mpg123audiodec (GstElement * mpg123audiodec)
|
|
||||||
{
|
|
||||||
GST_DEBUG ("cleanup_mpeg1layer2dec");
|
|
||||||
gst_element_set_state (mpg123audiodec, GST_STATE_NULL);
|
|
||||||
|
|
||||||
gst_pad_set_active (mysrcpad, FALSE);
|
|
||||||
gst_pad_set_active (mysinkpad, FALSE);
|
|
||||||
gst_check_teardown_src_pad (mpg123audiodec);
|
|
||||||
gst_check_teardown_sink_pad (mpg123audiodec);
|
|
||||||
gst_check_teardown_element (mpg123audiodec);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
run_decoding_test (GstElement * mpg123audiodec, gchar const *filename)
|
|
||||||
{
|
|
||||||
GstBus *bus;
|
|
||||||
unsigned int num_input_buffers, num_decoded_buffers;
|
|
||||||
gint expected_size;
|
|
||||||
GstCaps *out_caps, *caps;
|
|
||||||
GstAudioInfo audioinfo;
|
|
||||||
GstElement *input_pipeline, *input_appsink;
|
|
||||||
int i;
|
|
||||||
GstBuffer *outbuffer;
|
|
||||||
|
|
||||||
/* 440 Hz = frequency of sine wave in audio data
|
|
||||||
* 44100 Hz = sample rate
|
|
||||||
* (44100 / 2) Hz = Nyquist frequency */
|
|
||||||
static double const expected_frequency_spot = 440.0 / (44100.0 / 2.0);
|
|
||||||
|
|
||||||
fail_unless (gst_element_set_state (mpg123audiodec,
|
|
||||||
GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
|
|
||||||
"could not set to playing");
|
|
||||||
bus = gst_bus_new ();
|
|
||||||
|
|
||||||
gst_element_set_bus (mpg123audiodec, bus);
|
|
||||||
|
|
||||||
setup_input_pipeline (filename, &input_pipeline, &input_appsink);
|
|
||||||
|
|
||||||
num_input_buffers = 0;
|
|
||||||
while (TRUE) {
|
|
||||||
GstSample *sample;
|
|
||||||
GstBuffer *input_buffer;
|
|
||||||
|
|
||||||
sample = gst_app_sink_pull_sample (GST_APP_SINK (input_appsink));
|
|
||||||
if (sample == NULL)
|
|
||||||
break;
|
|
||||||
|
|
||||||
fail_unless (GST_IS_SAMPLE (sample));
|
|
||||||
|
|
||||||
input_buffer = gst_sample_get_buffer (sample);
|
|
||||||
fail_if (input_buffer == NULL);
|
|
||||||
|
|
||||||
/* This is done to be on the safe side - docs say lifetime of the input buffer
|
|
||||||
* depends *solely* on the sample */
|
|
||||||
input_buffer = gst_buffer_copy (input_buffer);
|
|
||||||
|
|
||||||
fail_unless_equals_int (gst_pad_push (mysrcpad, input_buffer), GST_FLOW_OK);
|
|
||||||
|
|
||||||
++num_input_buffers;
|
|
||||||
|
|
||||||
gst_sample_unref (sample);
|
|
||||||
}
|
|
||||||
|
|
||||||
num_decoded_buffers = g_list_length (buffers);
|
|
||||||
|
|
||||||
/* check number of decoded buffers */
|
|
||||||
fail_unless_equals_int (num_decoded_buffers, num_input_buffers - 2);
|
|
||||||
|
|
||||||
caps = gst_pad_get_current_caps (mysinkpad);
|
|
||||||
GST_LOG ("output caps %" GST_PTR_FORMAT, caps);
|
|
||||||
fail_unless (gst_audio_info_from_caps (&audioinfo, caps),
|
|
||||||
"Getting audio info from caps failed");
|
|
||||||
|
|
||||||
/* check caps */
|
|
||||||
out_caps = gst_caps_new_simple ("audio/x-raw",
|
|
||||||
"format", G_TYPE_STRING, GST_AUDIO_NE (S32),
|
|
||||||
"layout", G_TYPE_STRING, "interleaved",
|
|
||||||
"rate", G_TYPE_INT, 44100, "channels", G_TYPE_INT, 1, NULL);
|
|
||||||
|
|
||||||
fail_unless (gst_caps_is_equal_fixed (caps, out_caps), "Incorrect out caps");
|
|
||||||
|
|
||||||
gst_caps_unref (out_caps);
|
|
||||||
gst_caps_unref (caps);
|
|
||||||
|
|
||||||
/* here, test if decoded data is a sine tone, and if the sine frequency is at the
|
|
||||||
* right spot in the spectrum */
|
|
||||||
for (i = 0; i < num_decoded_buffers; ++i) {
|
|
||||||
outbuffer = GST_BUFFER (buffers->data);
|
|
||||||
fail_if (outbuffer == NULL, "Invalid buffer retrieved");
|
|
||||||
|
|
||||||
/* MPEG 1 layer 2 uses 1152 samples per frame */
|
|
||||||
expected_size = 1152 * GST_AUDIO_INFO_BPF (&audioinfo);
|
|
||||||
fail_unless_equals_int (gst_buffer_get_size (outbuffer), expected_size);
|
|
||||||
|
|
||||||
check_main_frequency_spot_S32 (outbuffer, expected_frequency_spot);
|
|
||||||
|
|
||||||
buffers = g_list_remove (buffers, outbuffer);
|
|
||||||
gst_buffer_unref (outbuffer);
|
|
||||||
outbuffer = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
g_list_free (buffers);
|
|
||||||
buffers = NULL;
|
|
||||||
|
|
||||||
cleanup_input_pipeline (input_pipeline);
|
|
||||||
gst_bus_set_flushing (bus, TRUE);
|
|
||||||
gst_element_set_bus (mpg123audiodec, NULL);
|
|
||||||
gst_object_unref (GST_OBJECT (bus));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
GST_START_TEST (test_decode_mpeg1layer2)
|
|
||||||
{
|
|
||||||
GstElement *mpg123audiodec;
|
|
||||||
mpg123audiodec = setup_mpeg1layer2dec ();
|
|
||||||
run_decoding_test (mpg123audiodec, MP2_STREAM_FILENAME);
|
|
||||||
cleanup_mpg123audiodec (mpg123audiodec);
|
|
||||||
mpg123audiodec = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
GST_END_TEST;
|
|
||||||
|
|
||||||
|
|
||||||
GST_START_TEST (test_decode_mpeg1layer3_cbr)
|
|
||||||
{
|
|
||||||
GstElement *mpg123audiodec;
|
|
||||||
mpg123audiodec = setup_mpeg1layer3dec ();
|
|
||||||
run_decoding_test (mpg123audiodec, MP3_CBR_STREAM_FILENAME);
|
|
||||||
cleanup_mpg123audiodec (mpg123audiodec);
|
|
||||||
}
|
|
||||||
|
|
||||||
GST_END_TEST;
|
|
||||||
|
|
||||||
|
|
||||||
GST_START_TEST (test_decode_mpeg1layer3_vbr)
|
|
||||||
{
|
|
||||||
GstElement *mpg123audiodec;
|
|
||||||
mpg123audiodec = setup_mpeg1layer3dec ();
|
|
||||||
run_decoding_test (mpg123audiodec, MP3_VBR_STREAM_FILENAME);
|
|
||||||
cleanup_mpg123audiodec (mpg123audiodec);
|
|
||||||
}
|
|
||||||
|
|
||||||
GST_END_TEST;
|
|
||||||
|
|
||||||
|
|
||||||
GST_START_TEST (test_decode_garbage_mpeg1layer2)
|
|
||||||
{
|
|
||||||
GstElement *mpg123audiodec;
|
|
||||||
GstBuffer *inbuffer;
|
|
||||||
GstBus *bus;
|
|
||||||
int i, num_buffers;
|
|
||||||
guint32 *tmpbuf;
|
|
||||||
|
|
||||||
mpg123audiodec = setup_mpeg1layer2dec ();
|
|
||||||
|
|
||||||
fail_unless (gst_element_set_state (mpg123audiodec,
|
|
||||||
GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
|
|
||||||
"could not set to playing");
|
|
||||||
bus = gst_bus_new ();
|
|
||||||
|
|
||||||
/* initialize the buffer with something that is no mpeg2 */
|
|
||||||
tmpbuf = g_new (guint32, 4096);
|
|
||||||
for (i = 0; i < 4096; i++) {
|
|
||||||
tmpbuf[i] = i;
|
|
||||||
}
|
|
||||||
inbuffer = gst_buffer_new_wrapped (tmpbuf, 4096 * sizeof (guint32));
|
|
||||||
|
|
||||||
ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
|
|
||||||
|
|
||||||
gst_element_set_bus (mpg123audiodec, bus);
|
|
||||||
|
|
||||||
/* should be possible to push without problems but nothing gets decoded */
|
|
||||||
fail_unless_equals_int (gst_pad_push (mysrcpad, inbuffer), GST_FLOW_OK);
|
|
||||||
|
|
||||||
num_buffers = g_list_length (buffers);
|
|
||||||
|
|
||||||
/* should be 0 buffers as decoding should've been impossible */
|
|
||||||
fail_unless_equals_int (num_buffers, 0);
|
|
||||||
|
|
||||||
g_list_free (buffers);
|
|
||||||
buffers = NULL;
|
|
||||||
|
|
||||||
gst_bus_set_flushing (bus, TRUE);
|
|
||||||
gst_element_set_bus (mpg123audiodec, NULL);
|
|
||||||
gst_object_unref (GST_OBJECT (bus));
|
|
||||||
cleanup_mpg123audiodec (mpg123audiodec);
|
|
||||||
mpg123audiodec = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
GST_END_TEST;
|
|
||||||
|
|
||||||
|
|
||||||
GST_START_TEST (test_decode_garbage_mpeg1layer3)
|
|
||||||
{
|
|
||||||
GstElement *mpg123audiodec;
|
|
||||||
GstBuffer *inbuffer;
|
|
||||||
GstBus *bus;
|
|
||||||
int i, num_buffers;
|
|
||||||
guint32 *tmpbuf;
|
|
||||||
|
|
||||||
mpg123audiodec = setup_mpeg1layer3dec ();
|
|
||||||
|
|
||||||
fail_unless (gst_element_set_state (mpg123audiodec,
|
|
||||||
GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
|
|
||||||
"could not set to playing");
|
|
||||||
bus = gst_bus_new ();
|
|
||||||
|
|
||||||
/* initialize the buffer with something that is no mpeg2 */
|
|
||||||
tmpbuf = g_new (guint32, 4096);
|
|
||||||
for (i = 0; i < 4096; i++) {
|
|
||||||
tmpbuf[i] = i;
|
|
||||||
}
|
|
||||||
inbuffer = gst_buffer_new_wrapped (tmpbuf, 4096 * sizeof (guint32));
|
|
||||||
|
|
||||||
ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
|
|
||||||
|
|
||||||
gst_element_set_bus (mpg123audiodec, bus);
|
|
||||||
|
|
||||||
/* should be possible to push without problems but nothing gets decoded */
|
|
||||||
fail_unless_equals_int (gst_pad_push (mysrcpad, inbuffer), GST_FLOW_OK);
|
|
||||||
|
|
||||||
num_buffers = g_list_length (buffers);
|
|
||||||
|
|
||||||
/* should be 0 buffers as decoding should've been impossible */
|
|
||||||
fail_unless_equals_int (num_buffers, 0);
|
|
||||||
|
|
||||||
g_list_free (buffers);
|
|
||||||
buffers = NULL;
|
|
||||||
|
|
||||||
gst_bus_set_flushing (bus, TRUE);
|
|
||||||
gst_element_set_bus (mpg123audiodec, NULL);
|
|
||||||
gst_object_unref (GST_OBJECT (bus));
|
|
||||||
cleanup_mpg123audiodec (mpg123audiodec);
|
|
||||||
mpg123audiodec = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
GST_END_TEST;
|
|
||||||
|
|
||||||
|
|
||||||
static gboolean
|
|
||||||
is_test_file_available (gchar const *filename)
|
|
||||||
{
|
|
||||||
gboolean ret;
|
|
||||||
gchar *full_filename;
|
|
||||||
gchar *cwd;
|
|
||||||
|
|
||||||
cwd = g_get_current_dir ();
|
|
||||||
full_filename = g_build_filename (cwd, GST_TEST_FILES_PATH, filename, NULL);
|
|
||||||
ret =
|
|
||||||
g_file_test (full_filename, G_FILE_TEST_IS_REGULAR | G_FILE_TEST_EXISTS);
|
|
||||||
g_free (full_filename);
|
|
||||||
g_free (cwd);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
static Suite *
|
|
||||||
mpg123audiodec_suite (void)
|
|
||||||
{
|
|
||||||
GstRegistry *registry;
|
|
||||||
Suite *s = suite_create ("mpg123audiodec");
|
|
||||||
TCase *tc_chain = tcase_create ("general");
|
|
||||||
|
|
||||||
registry = gst_registry_get ();
|
|
||||||
|
|
||||||
suite_add_tcase (s, tc_chain);
|
|
||||||
if (gst_registry_check_feature_version (registry, "filesrc",
|
|
||||||
GST_VERSION_MAJOR, GST_VERSION_MINOR, 0) &&
|
|
||||||
gst_registry_check_feature_version (registry, "mpegaudioparse",
|
|
||||||
GST_VERSION_MAJOR, GST_VERSION_MINOR, 0) &&
|
|
||||||
gst_registry_check_feature_version (registry, "appsrc",
|
|
||||||
GST_VERSION_MAJOR, GST_VERSION_MINOR, 0)) {
|
|
||||||
if (is_test_file_available (MP2_STREAM_FILENAME))
|
|
||||||
tcase_add_test (tc_chain, test_decode_mpeg1layer2);
|
|
||||||
if (is_test_file_available (MP3_CBR_STREAM_FILENAME))
|
|
||||||
tcase_add_test (tc_chain, test_decode_mpeg1layer3_cbr);
|
|
||||||
if (is_test_file_available (MP3_VBR_STREAM_FILENAME))
|
|
||||||
tcase_add_test (tc_chain, test_decode_mpeg1layer3_vbr);
|
|
||||||
}
|
|
||||||
tcase_add_test (tc_chain, test_decode_garbage_mpeg1layer2);
|
|
||||||
tcase_add_test (tc_chain, test_decode_garbage_mpeg1layer3);
|
|
||||||
|
|
||||||
return s;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
GST_CHECK_MAIN (mpg123audiodec)
|
|
|
@ -2,7 +2,6 @@
|
||||||
ugly_tests = [
|
ugly_tests = [
|
||||||
[ 'elements/amrnbenc', not amrnb_dep.found() ],
|
[ 'elements/amrnbenc', not amrnb_dep.found() ],
|
||||||
[ 'elements/mpeg2dec', not mpeg2_dep.found(), [ gstvideo_dep ] ],
|
[ 'elements/mpeg2dec', not mpeg2_dep.found(), [ gstvideo_dep ] ],
|
||||||
[ 'elements/mpg123audiodec', not mpg123_dep.found() ],
|
|
||||||
[ 'elements/x264enc', not x264_dep.found() ],
|
[ 'elements/x264enc', not x264_dep.found() ],
|
||||||
[ 'elements/xingmux' ],
|
[ 'elements/xingmux' ],
|
||||||
[ 'generic/states' ],
|
[ 'generic/states' ],
|
||||||
|
|
Loading…
Reference in a new issue