gnash-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gnash-commit] /srv/bzr/gnash/trunk r10067: Initial implementation of Sp


From: Bastiaan Jacques
Subject: [Gnash-commit] /srv/bzr/gnash/trunk r10067: Initial implementation of Speex audio decoding in FLV. For now, it
Date: Thu, 23 Oct 2008 22:06:50 +0200
User-agent: Bazaar (1.5)

------------------------------------------------------------
revno: 10067
committer: Bastiaan Jacques <address@hidden>
branch nick: trunk
timestamp: Thu 2008-10-23 22:06:50 +0200
message:
  Initial implementation of Speex audio decoding in FLV. For now, it
  uses resampling from Util. 
added:
  libmedia/AudioDecoderSpeex.cpp
  libmedia/AudioDecoderSpeex.h
modified:
  configure.ac
  libmedia/Makefile.am
  libmedia/Util.h
  libmedia/gst/MediaHandlerGst.cpp
    ------------------------------------------------------------
    revno: 10053.1.1
    committer: Bastiaan Jacques <address@hidden>
    branch nick: speex
    timestamp: Thu 2008-10-23 20:13:50 +0200
    message:
      Make the docs to decode() useful.
    modified:
      libmedia/Util.h
    ------------------------------------------------------------
    revno: 10053.1.2
    committer: Bastiaan Jacques <address@hidden>
    branch nick: speex
    timestamp: Thu 2008-10-23 21:02:14 +0200
    message:
      Be a little more verbose in the docs.
    modified:
      libmedia/Util.h
    ------------------------------------------------------------
    revno: 10053.1.3
    committer: Bastiaan Jacques <address@hidden>
    branch nick: speex
    timestamp: Thu 2008-10-23 21:59:55 +0200
    message:
      libmedia/AudioDecoderSpeex.{cpp,h}: Initial implementation of Speex
        decoder.
      configure.ac: Look for libspeex.
      libmedia/Makefile.am: Build Speex decoder.
      libmedia/gst/MediaHandlerGst.cpp: Use the Speex decoder.
    added:
      libmedia/AudioDecoderSpeex.cpp
      libmedia/AudioDecoderSpeex.h
    modified:
      configure.ac
      libmedia/Makefile.am
      libmedia/gst/MediaHandlerGst.cpp
=== modified file 'configure.ac'
--- a/configure.ac      2008-10-21 17:42:41 +0000
+++ b/configure.ac      2008-10-23 19:59:55 +0000
@@ -1486,6 +1486,8 @@
 fi
 GNASH_PKG_INCLUDES([dejagnu], [dejagnu.h])
 
+GNASH_PKG_FIND(speex, [speex.h], [speex audio codec], speex_decode_int)
+
 dnl Find freetype and fontconfig
 dnl GNASH_PKG_FIND(freetype2, [freetype/freetype.h], [freetype2 font library], 
FT_Load_Char)
 dnl rob might be working on this or not ;)
@@ -2702,6 +2704,21 @@
   echo "                     or .rpm users: yum install curl-devel" >&4
 fi
 
+if test x"$SPEEX_LIBS" != x; then
+  if test x"$SPEEX_CFLAGS" != x; then
+    echo "        Speex flags are: $SPEEX_CFLAGS"
+  else
+    echo "        Speex flags are: default include path"
+  fi
+    echo "        Speex libs are: $SPEEX_LIBS"
+else
+  echo "        RECOMMENDED: If you install the Speex library, Gnash will be 
able to" >&4
+  echo "                     decoded Speex encoded audio in FLV files." >&4
+  echo "                     Install libspeex from http://speex.org"; >&4
+  echo "                     or .deb users: apt-get install libspeex-dev" >&4
+  echo "                     or .rpm users: yum install speex-devel" >&4
+fi
+
 if test x"$ext_dbus" = xyes; then
   if test x"$DBUS_LIBS" != x; then
     if test x"$DBUS_CFLAGS" != x; then

=== added file 'libmedia/AudioDecoderSpeex.cpp'
--- a/libmedia/AudioDecoderSpeex.cpp    1970-01-01 00:00:00 +0000
+++ b/libmedia/AudioDecoderSpeex.cpp    2008-10-23 19:59:55 +0000
@@ -0,0 +1,116 @@
+//   Copyright (C) 2008 Free Software Foundation, Inc.
+// 
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 3 of the License, or
+// (at your option) any later version.
+// 
+// This program 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 General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+
+#include "AudioDecoderSpeex.h"
+#include "log.h"
+
+#include <boost/bind.hpp>
+#include <boost/checked_delete.hpp>
+
+namespace gnash {
+namespace media {
+
+AudioDecoderSpeex::AudioDecoderSpeex()
+    : _speex_dec_state(speex_decoder_init(&speex_wb_mode)) 
+{
+    if (!_speex_dec_state) {
+        throw MediaException(_("AudioDecoderSpeex: initialization failed."));
+    }
+
+    speex_bits_init(&_speex_bits);
+
+    speex_decoder_ctl(_speex_dec_state, SPEEX_GET_FRAME_SIZE, 
&_speex_framesize);
+}
+AudioDecoderSpeex::~AudioDecoderSpeex()
+{
+    speex_bits_destroy(&_speex_bits);
+
+    speex_decoder_destroy(_speex_dec_state);
+}
+
+struct DecodedFrame : boost::noncopyable
+{
+    DecodedFrame(boost::int16_t* newdata, size_t datasize)
+    : data(newdata),
+      size(datasize)
+    {}
+
+    boost::scoped_array<boost::int16_t> data;
+    size_t size;
+};
+
+boost::uint8_t*
+AudioDecoderSpeex::decode(const EncodedAudioFrame& input,
+    boost::uint32_t& outputSize)
+{
+    speex_bits_read_from(&_speex_bits, 
reinterpret_cast<char*>(input.data.get()),
+                         input.dataSize);
+
+    std::vector<DecodedFrame*> decoded_frames;
+
+    boost::uint32_t total_size = 0;
+
+    while (speex_bits_remaining(&_speex_bits)) {
+
+        boost::scoped_array<short> output( new short[_speex_framesize] );
+
+        int rv = speex_decode_int(_speex_dec_state, &_speex_bits, 
output.get());
+        if (rv != 0) {
+            if (rv != -1) {
+                log_error(_("Corrupt Speex stream!"));
+            }
+
+            break;
+        }
+
+        int conv_size = 0;
+        boost::int16_t* conv_data = 0;
+
+        Util::convert_raw_data(&conv_data, &conv_size, output.get(), 
+            _speex_framesize /* sample count*/, 2 /* sample size */,
+            16000, false /* stereo */, 44100 /* new rate */,
+            true /* convert to stereo */);
+
+        total_size += conv_size;
+
+        decoded_frames.push_back(new DecodedFrame(conv_data, conv_size));
+    }
+
+    outputSize = total_size;
+
+    // We have to jump through hoops because decode() requires as much
+    // data to be returned as possible.
+    boost::uint8_t* rv = new boost::uint8_t[total_size];
+    boost::uint8_t* ptr = rv;
+
+    for (std::vector<DecodedFrame*>::iterator it = decoded_frames.begin(),
+         end = decoded_frames.end(); it != end; ++it) {
+        DecodedFrame* frame = *it;
+
+        memcpy(ptr, frame->data.get(), frame->size);
+
+        ptr += frame->size;
+
+        delete frame;
+    }
+
+    outputSize = total_size;
+
+    return rv;
+}
+
+} // gnash.media namespace 
+} // gnash namespace

=== added file 'libmedia/AudioDecoderSpeex.h'
--- a/libmedia/AudioDecoderSpeex.h      1970-01-01 00:00:00 +0000
+++ b/libmedia/AudioDecoderSpeex.h      2008-10-23 19:59:55 +0000
@@ -0,0 +1,46 @@
+//   Copyright (C) 2008 Free Software Foundation, Inc.
+// 
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 3 of the License, or
+// (at your option) any later version.
+// 
+// This program 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 General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+
+#include "AudioDecoder.h"
+
+#include <speex/speex.h> 
+
+#ifndef GNASH_MEDIA_DECODER_SPEEX
+#define GNASH_MEDIA_DECODER_SPEEX
+
+namespace gnash {
+namespace media {
+
+class AudioDecoderSpeex : public AudioDecoder
+{
+public:
+    AudioDecoderSpeex();
+    ~AudioDecoderSpeex();
+
+    boost::uint8_t* decode(const EncodedAudioFrame& input,
+        boost::uint32_t& outputSize);
+
+private:
+
+    SpeexBits _speex_bits;
+    void* _speex_dec_state;
+    int _speex_framesize;
+};
+
+} // namespace media
+} // namespace gnash
+
+#endif // GNASH_MEDIA_DECODER_SPEEX

=== modified file 'libmedia/Makefile.am'
--- a/libmedia/Makefile.am      2008-10-15 02:51:58 +0000
+++ b/libmedia/Makefile.am      2008-10-23 19:59:55 +0000
@@ -76,6 +76,7 @@
        MediaHandler.cpp \
        AudioDecoderNellymoser.cpp \
        AudioDecoderSimple.cpp \
+       AudioDecoderSpeex.cpp \
        MediaParser.cpp \
        FLVParser.cpp \
        Util.cpp \
@@ -90,6 +91,7 @@
        FLVParser.h \
        AudioDecoderNellymoser.h \
        AudioDecoderSimple.h \
+       AudioDecoderSpeex.h \
        sound_handler.h \
        NullSoundHandler.h \
        SoundInfo.h \

=== modified file 'libmedia/Util.h'
--- a/libmedia/Util.h   2008-03-06 05:22:49 +0000
+++ b/libmedia/Util.h   2008-10-23 19:02:14 +0000
@@ -31,32 +31,34 @@
 /// output format.
 //
 /// @param adjusted_data
-/// Where the converted data is placed.
+/// Where the converted data is placed (output). WARNING: even though
+/// the type of the output data is int16, the adjusted_size output
+/// parameter is in bytes.
 ///
 /// @param adjusted_size
-/// The size of the converted data.
+/// The size of the converted data (output) in bytes.
 ///
 /// @param data
-/// Data that needs to be converted.
+/// Data that needs to be converted (input).
 ///
 /// @param sample_count
-/// The datas current sample count.
+/// The datas current sample count (input).
 /// 
 /// @param sample_size
-/// The datas current sample size.
+/// The datas current sample size (input) in bytes.
 ///
 /// @param sample_rate
-/// The datas current sample rate.
+/// The datas current sample rate (input).
 ///
 /// @param stereo
-/// Whether the current data is in stereo
+/// Whether the current data is in stereo (input).
 ///
 /// @param m_sample_rate
-/// The samplerate we which to convert to.
+/// The samplerate we which to convert to (output).
 ///
 /// @param m_stereo
-/// Do we want the output data to be in stereo?
-///
+/// Do we want the output data to be in stereo (output)?
+
        static void convert_raw_data(boost::int16_t** adjusted_data,
                  int* adjusted_size, void* data, int sample_count,
                  int sample_size, int sample_rate, bool stereo,

=== modified file 'libmedia/gst/MediaHandlerGst.cpp'
--- a/libmedia/gst/MediaHandlerGst.cpp  2008-10-23 15:33:28 +0000
+++ b/libmedia/gst/MediaHandlerGst.cpp  2008-10-23 20:06:50 +0000
@@ -23,6 +23,7 @@
 #include "AudioDecoderGst.h"
 #include "MediaParserGst.h"
 #include "FLVParser.h"
+#include "AudioDecoderSpeex.h"
 
 #include "IOChannel.h" // for visibility of destructor
 #include "MediaParser.h" // for visibility of destructor
@@ -91,7 +92,15 @@
 std::auto_ptr<AudioDecoder>
 MediaHandlerGst::createAudioDecoder(const AudioInfo& info)
 {
-       std::auto_ptr<AudioDecoder> ret( new AudioDecoderGst(info) );
+       std::auto_ptr<AudioDecoder> ret;
+
+       if (info.codec == AUDIO_CODEC_SPEEX) {
+               assert(info.type == FLASH);
+               ret.reset(new AudioDecoderSpeex);
+       } else {
+               ret.reset( new AudioDecoderGst(info) );
+       }
+
        return ret;
 }
 


reply via email to

[Prev in Thread] Current Thread [Next in Thread]