[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Gnash-commit] /srv/bzr/gnash/trunk r10084: Make building against Speex
From: |
Bastiaan Jacques |
Subject: |
[Gnash-commit] /srv/bzr/gnash/trunk r10084: Make building against Speex optional. Use Speex's resampling module |
Date: |
Fri, 24 Oct 2008 19:14:48 +0200 |
User-agent: |
Bazaar (1.5) |
------------------------------------------------------------
revno: 10084
committer: Bastiaan Jacques <address@hidden>
branch nick: trunk
timestamp: Fri 2008-10-24 19:14:48 +0200
message:
Make building against Speex optional. Use Speex's resampling module
in AudioDecoderSpeex, if available.
modified:
Makefile.am
configure.ac
libmedia/AudioDecoderSpeex.cpp
libmedia/AudioDecoderSpeex.h
libmedia/Makefile.am
libmedia/gst/MediaHandlerGst.cpp
------------------------------------------------------------
revno: 10068.1.2
committer: Bastiaan Jacques <address@hidden>
branch nick: speex
timestamp: Fri 2008-10-24 16:30:10 +0200
message:
Add support for Speex's resampling library. Build system work to follow.
modified:
libmedia/AudioDecoderSpeex.cpp
libmedia/AudioDecoderSpeex.h
------------------------------------------------------------
revno: 10068.1.3
committer: Bastiaan Jacques <address@hidden>
branch nick: speex
timestamp: Fri 2008-10-24 19:11:59 +0200
message:
Make Speex optional.
modified:
Makefile.am
configure.ac
libmedia/AudioDecoderSpeex.cpp
libmedia/AudioDecoderSpeex.h
libmedia/Makefile.am
libmedia/gst/MediaHandlerGst.cpp
=== modified file 'Makefile.am'
--- a/Makefile.am 2008-10-24 15:18:26 +0000
+++ b/Makefile.am 2008-10-24 17:14:48 +0000
@@ -163,6 +163,12 @@
@echo " OGG_CFLAGS is $(OGG_CFLAGS)"
@echo " OGG_LIBS is $(OGG_LIBS)"
endif
+if HAVE_SPEEX
+ @echo " SPEEX_CFLAGS is $(SPEEX_CFLAGS)"
+ @echo " SPEEXDSP_CFLAGS is $(SPEEXDSP_CFLAGS)"
+ @echo " SPEEX_LIBS is $(SPEEX_LIBS)"
+ @echo " SPEEXDSP_LIBS is $(SPEEXDSP_LIBS)"
+endif
@echo "GUI Toolkit decoding support..."
@echo " SDL_CFLAGS is $(SDL_CFLAGS)"
@echo " SDL_LIBS is $(SDL_LIBS)"
=== modified file 'configure.ac'
--- a/configure.ac 2008-10-24 16:53:53 +0000
+++ b/configure.ac 2008-10-24 17:14:48 +0000
@@ -1487,6 +1487,15 @@
GNASH_PKG_INCLUDES([dejagnu], [dejagnu.h])
GNASH_PKG_FIND(speex, [speex.h], [speex audio codec], speex_decode_int)
+AM_CONDITIONAL(HAVE_SPEEX, [ test x$has_speex = xyes ])
+if test x$has_speex = xyes ; then
+ AC_DEFINE([DECODING_SPEEX], [1], [Speex codec available])
+fi
+
+GNASH_PKG_FIND(speexdsp, [speex_resampler.h], [speex DSP utilities],
speex_resampler_process_int)
+if test x$has_speexdsp = xyes ; then
+ AC_DEFINE([RESAMPLING_SPEEX], [1], [Speex resampler available])
+fi
dnl Find freetype and fontconfig
dnl GNASH_PKG_FIND(freetype2, [freetype/freetype.h], [freetype2 font library],
FT_Load_Char)
=== modified file 'libmedia/AudioDecoderSpeex.cpp'
--- a/libmedia/AudioDecoderSpeex.cpp 2008-10-23 19:59:55 +0000
+++ b/libmedia/AudioDecoderSpeex.cpp 2008-10-24 17:11:59 +0000
@@ -20,6 +20,11 @@
#include <boost/bind.hpp>
#include <boost/checked_delete.hpp>
+#ifdef RESAMPLING_SPEEX
+# include <boost/rational.hpp>
+#endif
+
+
namespace gnash {
namespace media {
@@ -27,18 +32,42 @@
: _speex_dec_state(speex_decoder_init(&speex_wb_mode))
{
if (!_speex_dec_state) {
- throw MediaException(_("AudioDecoderSpeex: initialization failed."));
+ throw MediaException(_("AudioDecoderSpeex: state initialization
failed."));
}
speex_bits_init(&_speex_bits);
speex_decoder_ctl(_speex_dec_state, SPEEX_GET_FRAME_SIZE,
&_speex_framesize);
+
+#ifdef RESAMPLING_SPEEX
+ int err = 0;
+ _resampler = speex_resampler_init(1, 16000, 44100,
+ SPEEX_RESAMPLER_QUALITY_DEFAULT, &err);
+
+ if (err != RESAMPLER_ERR_SUCCESS) {
+ throw MediaException(_("AudioDecoderSpeex: initialization failed."));
+ }
+
+ boost::uint32_t num = 0, den = 0;
+
+ speex_resampler_get_ratio (_resampler, &num, &den);
+ assert(num && den);
+
+ boost::rational<boost::uint32_t> numsamples(den, num);
+
+ numsamples *= _speex_framesize * 2 /* convert to stereo */;
+
+ _target_frame_size = boost::rational_cast<boost::uint32_t>(numsamples);
+#endif
}
AudioDecoderSpeex::~AudioDecoderSpeex()
{
speex_bits_destroy(&_speex_bits);
speex_decoder_destroy(_speex_dec_state);
+
+
+ speex_resampler_destroy(_resampler);
}
struct DecodedFrame : boost::noncopyable
@@ -76,14 +105,46 @@
break;
}
- int conv_size = 0;
+ boost::uint32_t conv_size = 0;
boost::int16_t* conv_data = 0;
- Util::convert_raw_data(&conv_data, &conv_size, output.get(),
+#ifdef RESAMPLING_SPEEX
+ conv_data = new boost::int16_t[_target_frame_size];
+ memset(conv_data, 0, _target_frame_size * 2);
+
+ boost::uint32_t in_size = _speex_framesize;
+
+ // Our input format is mono and we want to expand to stereo. Speex
+ // won't do this for us, but we can ask it to skip a sample after
+ // writing one, so all we have to do is duplicate the samples.
+ speex_resampler_set_output_stride(_resampler, 2);
+ conv_size = _target_frame_size; // Assuming this hould be samples.
+
+ int err = speex_resampler_process_int(_resampler, 0 /* mono */,
output.get(), &in_size, conv_data, &conv_size);
+ if (err != RESAMPLER_ERR_SUCCESS) {
+ log_error(_("Failed to resample Speex frame."));
+ delete [] conv_data;
+ continue;
+ }
+
+ // The returned size is the number of *mono* samples returned.
+ conv_size *= 2;
+
+ // Now, duplicate all the samples so we get a stereo sound.
+ for (boost::uint32_t i = 0; i < conv_size; i += 2) {
+ conv_data[i+1] = conv_data[i];
+ }
+
+ // Our interface requires returning the audio size in bytes.
+ conv_size *= sizeof(boost::int16_t);
+#else
+ int outsize = 0;
+ Util::convert_raw_data(&conv_data, &outsize, output.get(),
_speex_framesize /* sample count*/, 2 /* sample size */,
16000, false /* stereo */, 44100 /* new rate */,
true /* convert to stereo */);
-
+ conv_size = outsize;
+#endif
total_size += conv_size;
decoded_frames.push_back(new DecodedFrame(conv_data, conv_size));
=== modified file 'libmedia/AudioDecoderSpeex.h'
--- a/libmedia/AudioDecoderSpeex.h 2008-10-23 19:59:55 +0000
+++ b/libmedia/AudioDecoderSpeex.h 2008-10-24 17:11:59 +0000
@@ -18,6 +18,10 @@
#include <speex/speex.h>
+#ifdef RESAMPLING_SPEEX
+# include <speex/speex_resampler.h>
+#endif
+
#ifndef GNASH_MEDIA_DECODER_SPEEX
#define GNASH_MEDIA_DECODER_SPEEX
@@ -38,6 +42,12 @@
SpeexBits _speex_bits;
void* _speex_dec_state;
int _speex_framesize;
+
+#ifdef RESAMPLING_SPEEX
+ SpeexResamplerState* _resampler;
+ /// Number of samples in a resampled 44kHz stereo frame.
+ boost::uint32_t _target_frame_size;
+#endif
};
} // namespace media
=== modified file 'libmedia/Makefile.am'
--- a/libmedia/Makefile.am 2008-10-23 22:42:02 +0000
+++ b/libmedia/Makefile.am 2008-10-24 17:11:59 +0000
@@ -49,7 +49,6 @@
$(GIF_CFLAGS) \
$(BOOST_CFLAGS) \
$(INCLTDL) \
- $(SPEEX_CFLAGS) \
$(NULL)
# These headers get installed
@@ -71,14 +70,12 @@
$(LIBLTDLHEAD) \
$(BOOST_LIBS) \
$(PTHREAD_LIBS) \
- $(SPEEX_LIBS) \
$(NULL)
libgnashmedia_la_SOURCES = \
MediaHandler.cpp \
AudioDecoderNellymoser.cpp \
AudioDecoderSimple.cpp \
- AudioDecoderSpeex.cpp \
MediaParser.cpp \
FLVParser.cpp \
Util.cpp \
@@ -93,7 +90,6 @@
FLVParser.h \
AudioDecoderNellymoser.h \
AudioDecoderSimple.h \
- AudioDecoderSpeex.h \
sound_handler.h \
NullSoundHandler.h \
SoundInfo.h \
@@ -159,6 +155,19 @@
$(SDL_CFLAGS)
endif
+if HAVE_SPEEX
+ libgnashmedia_la_LIBADD += \
+ $(SPEEX_LIBS) \
+ $(SPEEXDSP_LIBS) \
+ $(NULL)
+ libgnashmedia_la_CPPFLAGS += \
+ $(SPEEX_CFLAGS) \
+ $(SPEEXDSP_CFLAGS) \
+ $(NULL)
+ libgnashmedia_la_SOURCES += AudioDecoderSpeex.cpp
+ noinst_HEADERS += AudioDecoderSpeex.h
+endif
+
libgnashmedia_la_LDFLAGS = -release $(VERSION)
if WIN32
=== modified file 'libmedia/gst/MediaHandlerGst.cpp'
--- a/libmedia/gst/MediaHandlerGst.cpp 2008-10-23 20:06:50 +0000
+++ b/libmedia/gst/MediaHandlerGst.cpp 2008-10-24 17:11:59 +0000
@@ -23,7 +23,10 @@
#include "AudioDecoderGst.h"
#include "MediaParserGst.h"
#include "FLVParser.h"
+
+#ifdef DECODING_SPEEX
#include "AudioDecoderSpeex.h"
+#endif
#include "IOChannel.h" // for visibility of destructor
#include "MediaParser.h" // for visibility of destructor
@@ -92,16 +95,18 @@
std::auto_ptr<AudioDecoder>
MediaHandlerGst::createAudioDecoder(const AudioInfo& info)
{
- std::auto_ptr<AudioDecoder> ret;
-
+ AudioDecoder* decoder = 0;
+#ifdef DECODING_SPEEX
if (info.codec == AUDIO_CODEC_SPEEX) {
assert(info.type == FLASH);
- ret.reset(new AudioDecoderSpeex);
- } else {
- ret.reset( new AudioDecoderGst(info) );
+ decoder = new AudioDecoderSpeex;
+ } else
+#endif
+ {
+ decoder = new AudioDecoderGst(info);
}
- return ret;
+ return std::auto_ptr<AudioDecoder>(decoder);
}
} // gnash.media namespace
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Gnash-commit] /srv/bzr/gnash/trunk r10084: Make building against Speex optional. Use Speex's resampling module,
Bastiaan Jacques <=