gnash-commit
[Top][All Lists]
Advanced

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

[Gnash-commit] /srv/bzr/gnash/trunk r9825: Fix bug #24355.


From: Benjamin Wolsey
Subject: [Gnash-commit] /srv/bzr/gnash/trunk r9825: Fix bug #24355.
Date: Tue, 23 Sep 2008 19:57:14 +0200
User-agent: Bazaar (1.5)

------------------------------------------------------------
revno: 9825
committer: Benjamin Wolsey <address@hidden>
branch nick: trunk
timestamp: Tue 2008-09-23 19:57:14 +0200
message:
  Fix bug #24355.
modified:
  libcore/asobj/NetStreamFfmpeg.cpp
  libcore/asobj/SoundFfmpeg.cpp
  libmedia/AudioDecoder.h
  libmedia/AudioDecoderNellymoser.cpp
  libmedia/AudioDecoderNellymoser.h
  libmedia/AudioDecoderSimple.cpp
  libmedia/AudioDecoderSimple.h
  libmedia/MediaHandler.h
  libmedia/ffmpeg/AudioDecoderFfmpeg.cpp
  libmedia/ffmpeg/AudioDecoderFfmpeg.h
  libmedia/ffmpeg/MediaHandlerFfmpeg.cpp
  libmedia/ffmpeg/MediaHandlerFfmpeg.h
  libmedia/ffmpeg/sound_handler_sdl.cpp
  libmedia/gst/AudioDecoderGst.cpp
  libmedia/gst/AudioDecoderGst.h
  libmedia/gst/MediaHandlerGst.cpp
    ------------------------------------------------------------
    revno: 9822.1.1
    committer: Benjamin Wolsey <address@hidden>
    branch nick: work
    timestamp: Tue 2008-09-23 19:14:12 +0200
    message:
      Always return a valid Decoder or throw MediaException from 
MediaHandler::create{Audio,Video}Decoder().
      
      Modify all callers to catch and log the exception.
      
      Document MediaHandler interface correctly.
      
      Drop setup() from AudioDecoder interface and take AudioInfo& or SoundInfo&
      argument to constructor instead.
    modified:
      libcore/asobj/NetStreamFfmpeg.cpp
      libcore/asobj/SoundFfmpeg.cpp
      libmedia/AudioDecoder.h
      libmedia/AudioDecoderNellymoser.cpp
      libmedia/AudioDecoderNellymoser.h
      libmedia/AudioDecoderSimple.cpp
      libmedia/AudioDecoderSimple.h
      libmedia/MediaHandler.h
      libmedia/ffmpeg/AudioDecoderFfmpeg.cpp
      libmedia/ffmpeg/AudioDecoderFfmpeg.h
      libmedia/ffmpeg/MediaHandlerFfmpeg.cpp
      libmedia/ffmpeg/MediaHandlerFfmpeg.h
      libmedia/ffmpeg/sound_handler_sdl.cpp
      libmedia/gst/AudioDecoderGst.cpp
      libmedia/gst/AudioDecoderGst.h
      libmedia/gst/MediaHandlerGst.cpp
=== modified file 'libcore/asobj/NetStreamFfmpeg.cpp'
--- a/libcore/asobj/NetStreamFfmpeg.cpp 2008-09-17 07:16:12 +0000
+++ b/libcore/asobj/NetStreamFfmpeg.cpp 2008-09-23 17:14:12 +0000
@@ -215,7 +215,7 @@
            _videoDecoder = _mediaHandler->createVideoDecoder(*videoInfo);
        }
        catch (MediaException& e) {
-           log_error("Could not create Video decoder: %s", e.what());
+           log_error("NetStream: Could not create Video decoder: %s", 
e.what());
        }
 
 }
@@ -234,9 +234,13 @@
 
        assert ( _mediaHandler ); // caller should check this
 
-       _audioDecoder = _mediaHandler->createAudioDecoder(*audioInfo);
-       if ( ! _audioDecoder.get() )
-               log_error(_("Could not create audio decoder for codec %d"), 
audioInfo->codec);
+    try {
+           _audioDecoder = _mediaHandler->createAudioDecoder(*audioInfo);
+       }
+       catch (MediaException& e) {
+           log_error("Could not create Audio decoder: %s", e.what());
+       }
+
 }
 
 

=== modified file 'libcore/asobj/SoundFfmpeg.cpp'
--- a/libcore/asobj/SoundFfmpeg.cpp     2008-06-19 22:24:02 +0000
+++ b/libcore/asobj/SoundFfmpeg.cpp     2008-09-23 17:14:12 +0000
@@ -180,10 +180,12 @@
                return;
        }
 
-       _audioDecoder.reset( 
_mediaHandler->createAudioDecoder(*audioInfo).release() );
-       if ( ! _audioDecoder.get() )
-       {
-               log_error(_("Could not create audio decoder for codec %d"), 
audioInfo->codec);
+    try {
+           
_audioDecoder.reset(_mediaHandler->createAudioDecoder(*audioInfo).release());
+       }
+       catch (MediaException& e) {
+        assert(!_audioDecoder.get());
+               log_error(_("Could not create audio decoder: %s"), e.what());
        }
 
        // start playing ASAP, a call to ::start will just change _startTime

=== modified file 'libmedia/AudioDecoder.h'
--- a/libmedia/AudioDecoder.h   2008-06-20 07:18:01 +0000
+++ b/libmedia/AudioDecoder.h   2008-09-23 17:14:12 +0000
@@ -37,33 +37,12 @@
 class AudioDecoder {
        
 public:
+
        AudioDecoder() {}
 
        // virtual classes need a virtual destructor !
        virtual ~AudioDecoder() {}
 
-       /// Sets up the decoder.
-       //
-       /// @param info
-       ///     AudioInfo class with all the info needed to decode
-       ///     the sound correctly.
-       ///
-       /// @return true if succesfull else false
-       ///
-       /// TODO: take AudioInfo by ref, not pointer
-       ///
-       virtual bool setup(AudioInfo* /*info*/) { return false; }
-
-       /// Sets up the decoder.
-       //
-       /// @param info
-       ///     SoundInfo class with all the info needed to decode
-       ///     the audio correctly.
-       ///
-       /// @return true if succesfull else false
-       ///
-       virtual bool setup(SoundInfo* /*info*/) { return false; }
-
        /// Decodes a frame and returns a pointer to the data
        //
        /// @param input

=== modified file 'libmedia/AudioDecoderNellymoser.cpp'
--- a/libmedia/AudioDecoderNellymoser.cpp       2008-03-29 02:07:07 +0000
+++ b/libmedia/AudioDecoderNellymoser.cpp       2008-09-23 17:14:12 +0000
@@ -52,11 +52,6 @@
 #include <cmath>
 #include "VM.h"
 
-#ifdef _WIN32
-#define random rand
-#define srandom srand
-#endif
-
 namespace gnash {
 namespace media {
 
@@ -744,40 +739,66 @@
 {
        delete nh;
 }
+
+
+AudioDecoderNellymoser::AudioDecoderNellymoser()
+       :
+       _sampleRate(0),
+       _stereo(false)
+{
+       _nh = nelly_get_handle();
+}
+
        
-AudioDecoderNellymoser::AudioDecoderNellymoser ()
-       :
-       _sampleRate(0),
-       _stereo(false)
-{
-       _nh = nelly_get_handle();
-}
+AudioDecoderNellymoser::AudioDecoderNellymoser(AudioInfo& info)
+       :
+       _sampleRate(0),
+       _stereo(false)
+{
+    setup(info);
+       _nh = nelly_get_handle();
+}
+
+
+AudioDecoderNellymoser::AudioDecoderNellymoser(SoundInfo& info)
+       :
+       _sampleRate(0),
+       _stereo(false)
+{
+    setup(info);
+       _nh = nelly_get_handle();
+}
+
 
 AudioDecoderNellymoser::~AudioDecoderNellymoser()
 {
        nelly_free_handle(_nh);
 }
 
-bool AudioDecoderNellymoser::setup(SoundInfo* info)
+void AudioDecoderNellymoser::setup(SoundInfo& info)
 {
-       if (info->getFormat() == AUDIO_CODEC_NELLYMOSER || info->getFormat() == 
AUDIO_CODEC_NELLYMOSER_8HZ_MONO) {
-               _sampleRate = info->getSampleRate();
-               _stereo = info->isStereo();
-               return true;
-       } else {
-               return false;
-       }
+
+       if (info.getFormat() == AUDIO_CODEC_NELLYMOSER ||
+           info.getFormat() == AUDIO_CODEC_NELLYMOSER_8HZ_MONO) {
+               _sampleRate = info.getSampleRate();
+               _stereo = info.isStereo();
+               return;
+       } 
+       throw MediaException("AudioDecoderNellymoser: attempt to use with "
+                               "non-nellymoser codec");
 }
 
-bool AudioDecoderNellymoser::setup(AudioInfo* info)
+void AudioDecoderNellymoser::setup(AudioInfo& info)
 {
-       if (info->type == FLASH && (info->codec == AUDIO_CODEC_NELLYMOSER || 
info->codec == AUDIO_CODEC_NELLYMOSER_8HZ_MONO)) {
-               _sampleRate = info->sampleRate;
-               _stereo = info->stereo;
-               return true;
-       } else {
-               return false;
+       if (info.type == FLASH && (info.codec == AUDIO_CODEC_NELLYMOSER ||
+               info.codec == AUDIO_CODEC_NELLYMOSER_8HZ_MONO)) {
+               _sampleRate = info.sampleRate;
+               _stereo = info.stereo;
+               return;
        }
+
+       throw MediaException("AudioDecoderNellymoser: attempt to use with "
+                               "non-nellymoser codec");
 }
 
 float* AudioDecoderNellymoser::decode(boost::uint8_t* in_buf, boost::uint32_t 
inputSize, boost::uint32_t* outputSize)

=== modified file 'libmedia/AudioDecoderNellymoser.h'
--- a/libmedia/AudioDecoderNellymoser.h 2008-06-03 11:39:51 +0000
+++ b/libmedia/AudioDecoderNellymoser.h 2008-09-23 17:14:12 +0000
@@ -44,8 +44,8 @@
  * DEALINGS IN THE SOFTWARE.
  */
 
-#ifndef __AUDIODECODERNELLYMOSER_H__
-#define __AUDIODECODERNELLYMOSER_H__
+#ifndef GNASH_AUDIODECODERNELLYMOSER_H
+#define GNASH_AUDIODECODERNELLYMOSER_H
 
 #include "log.h"
 #include "AudioDecoder.h"
@@ -75,14 +75,29 @@
 namespace media {
 
 /// Audio decoding using internal Nellymoser decoder.
+/// TODO: as ffmpeg now has Nellymoser support (maintained
+/// by people who know what they're doing, I hope), do
+/// we need this?
 class AudioDecoderNellymoser : public AudioDecoder {
 
 public:
-       AudioDecoderNellymoser();
-       ~AudioDecoderNellymoser();
-
-       bool setup(AudioInfo* info);
-       bool setup(SoundInfo* info);
+
+    /// This is needed by gstreamer still. TODO: drop.
+    AudioDecoderNellymoser();
+
+       /// @param info
+       ///     AudioInfo class with all the info needed to decode
+       ///     the sound correctly. Throws a MediaException on fatal
+       ///     error.
+       AudioDecoderNellymoser(AudioInfo& info);
+
+       /// @param info
+       ///     SoundInfo class with all the info needed to decode
+       ///     the sound correctly. Throws a MediaException on fatal
+       ///      error.
+       AudioDecoderNellymoser(SoundInfo& info);
+
+    ~AudioDecoderNellymoser();
 
        boost::uint8_t* decode(boost::uint8_t* input, boost::uint32_t 
inputSize, boost::uint32_t& outputSize, boost::uint32_t& decodedBytes, bool 
parse);
        
@@ -91,6 +106,9 @@
 
 private:
 
+       void setup(AudioInfo& info);
+       void setup(SoundInfo& info);
+
        // The handle used by the decoder
        nelly_handle* _nh;
 

=== modified file 'libmedia/AudioDecoderSimple.cpp'
--- a/libmedia/AudioDecoderSimple.cpp   2008-05-19 12:03:52 +0000
+++ b/libmedia/AudioDecoderSimple.cpp   2008-09-23 17:14:12 +0000
@@ -276,40 +276,51 @@
 }
 
 
-AudioDecoderSimple::AudioDecoderSimple ()
-       :
-       _sampleRate(0),
-       _sampleCount(0),
-       _stereo(false),
-       _is16bit(true)
-{
-}
+AudioDecoderSimple::AudioDecoderSimple(AudioInfo& info)
+       :
+       _sampleRate(0),
+       _sampleCount(0),
+       _stereo(false),
+       _is16bit(true)
+{
+    if (!setup(info)) throw MediaException("Failed to setup decoder");
+}
+
+AudioDecoderSimple::AudioDecoderSimple(SoundInfo& info)
+       :
+       _sampleRate(0),
+       _sampleCount(0),
+       _stereo(false),
+       _is16bit(true)
+{
+    if (!setup(info)) throw MediaException("Failed to setup decoder");
+}
+
 
 AudioDecoderSimple::~AudioDecoderSimple()
 {
-
 }
 
-bool AudioDecoderSimple::setup(SoundInfo* info)
+bool AudioDecoderSimple::setup(SoundInfo& info)
 {
 
-       if (info->getFormat() == AUDIO_CODEC_ADPCM || info->getFormat() == 
AUDIO_CODEC_RAW || info->getFormat() == AUDIO_CODEC_UNCOMPRESSED) {
-               _codec = info->getFormat();
-               _sampleRate = info->getSampleRate();
-               _sampleCount = info->getSampleCount();
-               _stereo = info->isStereo();
-               _is16bit = info->is16bit();
+       if (info.getFormat() == AUDIO_CODEC_ADPCM || info.getFormat() == 
AUDIO_CODEC_RAW || info.getFormat() == AUDIO_CODEC_UNCOMPRESSED) {
+               _codec = info.getFormat();
+               _sampleRate = info.getSampleRate();
+               _sampleCount = info.getSampleCount();
+               _stereo = info.isStereo();
+               _is16bit = info.is16bit();
                return true;
        }
        return false;
 }
 
-bool AudioDecoderSimple::setup(AudioInfo* info)
+bool AudioDecoderSimple::setup(AudioInfo& info)
 {
-       if (info->type == FLASH && (info->codec == AUDIO_CODEC_ADPCM || 
info->codec == AUDIO_CODEC_RAW || info->codec == AUDIO_CODEC_UNCOMPRESSED)) {
-               _codec = static_cast<audioCodecType>(info->codec);
-               _sampleRate = info->sampleRate;
-               _stereo = info->stereo;
+       if (info.type == FLASH && (info.codec == AUDIO_CODEC_ADPCM || 
info.codec == AUDIO_CODEC_RAW || info.codec == AUDIO_CODEC_UNCOMPRESSED)) {
+               _codec = static_cast<audioCodecType>(info.codec);
+               _sampleRate = info.sampleRate;
+               _stereo = info.stereo;
                _is16bit = true; // Fix this?
                return true;
        } else {

=== modified file 'libmedia/AudioDecoderSimple.h'
--- a/libmedia/AudioDecoderSimple.h     2008-03-05 03:55:48 +0000
+++ b/libmedia/AudioDecoderSimple.h     2008-09-23 17:14:12 +0000
@@ -17,8 +17,8 @@
 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
 
-#ifndef __AUDIODECODERSIMPLE_H__
-#define __AUDIODECODERSIMPLE_H__
+#ifndef GNASH_AUDIODECODERSIMPLE_H
+#define GNASH_AUDIODECODERSIMPLE_H
 
 #include "log.h"
 #include "AudioDecoder.h"
@@ -34,17 +34,29 @@
 class AudioDecoderSimple : public AudioDecoder {
 
 public:
-       AudioDecoderSimple();
+
+       /// @param info
+       ///     AudioInfo class with all the info needed to decode
+       ///     the sound correctly. Throws a MediaException on fatal
+       ///     error.
+       AudioDecoderSimple(AudioInfo& info);
+       
+       /// @param info
+       ///     SoundInfo class with all the info needed to decode
+       ///     the sound correctly. Throws a MediaException on fatal
+       ///     error.  
+       AudioDecoderSimple(SoundInfo& info);
+
        ~AudioDecoderSimple();
 
-       bool setup(AudioInfo* info);
-
-       bool setup(SoundInfo* info);
-
        boost::uint8_t* decode(boost::uint8_t* input, boost::uint32_t 
inputSize, boost::uint32_t& outputSize, boost::uint32_t& decodedBytes, bool 
parse);
 
 private:
 
+       bool setup(AudioInfo& info);
+
+       bool setup(SoundInfo& info);
+
        // codec
        audioCodecType _codec;
 

=== modified file 'libmedia/MediaHandler.h'
--- a/libmedia/MediaHandler.h   2008-06-09 13:31:51 +0000
+++ b/libmedia/MediaHandler.h   2008-09-23 17:14:12 +0000
@@ -74,27 +74,20 @@
        ///
        virtual std::auto_ptr<MediaParser> 
createMediaParser(std::auto_ptr<IOChannel> stream);
 
-       /// Create a VideoDecoder for the specified codec_type
+       /// Create a VideoDecoder for decoding what's specified in the VideoInfo
        //
-       /// @param format
-       ///     Video encoding.
-       ///
-       /// @param width
-       ///     Video frame width
-       ///
-       /// @param height
-       ///     Video frame height
-       ///
-       /// @return 0 if no decoder could be created for the specified encoding
-       ///
+       /// @param info VideoInfo class with all the info needed to decode
+       ///             the sound correctly.
+    /// @return     Will always return a valid VideoDecoder or throw a
+    ///             gnash::MediaException if a fatal error occurs.
        virtual std::auto_ptr<VideoDecoder> createVideoDecoder(VideoInfo& 
info)=0;
 
        /// Create an AudioDecoder for decoding what's specified in the 
AudioInfo
        //
-       /// @param info
-       ///     AudioInfo class with all the info needed to decode
-       ///     the sound correctly.
-       ///
+       /// @param info AudioInfo class with all the info needed to decode
+       ///             the sound correctly.
+    /// @return     Will always return a valid AudioDecoder or throw a
+    ///             gnash::MediaException if a fatal error occurs.
        virtual std::auto_ptr<AudioDecoder> createAudioDecoder(AudioInfo& 
info)=0;
 
 protected:

=== modified file 'libmedia/ffmpeg/AudioDecoderFfmpeg.cpp'
--- a/libmedia/ffmpeg/AudioDecoderFfmpeg.cpp    2008-06-25 21:34:19 +0000
+++ b/libmedia/ffmpeg/AudioDecoderFfmpeg.cpp    2008-09-23 17:14:12 +0000
@@ -35,12 +35,23 @@
 namespace gnash {
 namespace media {
        
-AudioDecoderFfmpeg::AudioDecoderFfmpeg ()
-       :
-       _audioCodec(NULL),
-       _audioCodecCtx(NULL),
-       _parser(NULL)
-{}
+AudioDecoderFfmpeg::AudioDecoderFfmpeg(AudioInfo& info)
+       :
+       _audioCodec(NULL),
+       _audioCodecCtx(NULL),
+       _parser(NULL)
+{
+    setup(info);
+}
+
+AudioDecoderFfmpeg::AudioDecoderFfmpeg(SoundInfo& info)
+       :
+       _audioCodec(NULL),
+       _audioCodecCtx(NULL),
+       _parser(NULL)
+{
+    setup(info);
+}
 
 AudioDecoderFfmpeg::~AudioDecoderFfmpeg()
 {
@@ -52,7 +63,7 @@
        if (_parser) av_parser_close(_parser);
 }
 
-bool AudioDecoderFfmpeg::setup(SoundInfo* info)
+void AudioDecoderFfmpeg::setup(SoundInfo& info)
 {
        // Init the avdecoder-decoder
        avcodec_init();
@@ -60,7 +71,7 @@
 
        enum CodecID codec_id;
 
-       switch(info->getFormat()) {
+       switch(info.getFormat()) {
                case AUDIO_CODEC_RAW:
                        codec_id = CODEC_ID_PCM_U16LE;
                        break;
@@ -73,46 +84,47 @@
                        _parser = av_parser_init(codec_id);
 
                        if (!_parser) { 
-                               log_error(_("libavcodec can't parse the current 
audio format"));
-                               return false;
+                               throw MediaException(_("libavcodec can't parse "
+                                                      "the current audio 
format"));
                        }
                        break;
                default:
-                       log_error(_("Unsupported audio codec %d"), 
static_cast<int>(info->getFormat()));
-                       return false;
+                   boost::format err = boost::format(
+                       _("Unsupported audio codec %d")) %
+                       static_cast<int>(info.getFormat());
+                       throw MediaException(err.str());
        }
        _audioCodec = avcodec_find_decoder(codec_id);
 
        if (!_audioCodec) {
-               log_error(_("libavcodec can't decode the current audio 
format"));
-               return false;
+               throw MediaException(_("libavcodec can't decode the current 
audio format"));
        }
 
        _audioCodecCtx = avcodec_alloc_context();
+
        if (!_audioCodecCtx) {
-               log_error(_("libavcodec couldn't allocate context"));
-               return false;
+               throw MediaException(_("libavcodec couldn't allocate context"));
        }
 
        int ret = avcodec_open(_audioCodecCtx, _audioCodec);
        if (ret < 0) {
-               //avcodec_close(_audioCodecCtx);
                av_free(_audioCodecCtx);
                _audioCodecCtx=0;
-               log_error(_("AudioDecoderFfmpeg::setup: avcodec_open: failed to 
initialize FFMPEG codec %d"), (int)codec_id);
-               return false;
+        boost::format err = boost::format(
+            _("AudioDecoderFfmpeg: avcodec_open failed to initialize "
+            "FFMPEG codec %s (%d)")) % _audioCodec->name % (int)codec_id;
+       throw MediaException(err.str());
        }
 
        if (_audioCodecCtx->codec->id != CODEC_ID_MP3) {
-               _audioCodecCtx->channels = (info->isStereo() ? 2 : 1);
-               _audioCodecCtx->sample_rate = info->getSampleRate();
+               _audioCodecCtx->channels = (info.isStereo() ? 2 : 1);
+               _audioCodecCtx->sample_rate = info.getSampleRate();
                _audioCodecCtx->sample_fmt = SAMPLE_FMT_S16;
        }
 
-       return true;
 }
 
-bool AudioDecoderFfmpeg::setup(AudioInfo* info)
+void AudioDecoderFfmpeg::setup(AudioInfo& info)
 {
        // Init the avdecoder-decoder
        avcodec_init();
@@ -120,14 +132,14 @@
 
        enum CodecID codec_id = CODEC_ID_NONE;
 
-       if (info->type == FFMPEG)
+       if (info.type == FFMPEG)
        {
-               codec_id = static_cast<CodecID>(info->codec);
+               codec_id = static_cast<CodecID>(info.codec);
        }
-       else if (info->type == FLASH)
+       else if (info.type == FLASH)
        {
 
-               switch(info->codec)
+               switch(info.codec)
                {
                        case AUDIO_CODEC_RAW:
                                codec_id = CODEC_ID_PCM_U16LE;
@@ -138,38 +150,49 @@
                        case AUDIO_CODEC_MP3:
                                codec_id = CODEC_ID_MP3;
                                break;
+#if 0
+            // Enable this to use ffmpeg for nellymoser
+            // decoding (fails in decodeFrame, but probably not Ffmpeg's
+            // fault.
+                   case AUDIO_CODEC_NELLYMOSER:
+                       codec_id = CODEC_ID_NELLYMOSER;
+                       break;
+#endif
                        default:
-                               log_error(_("Unsupported audio codec %d"), 
static_cast<int>(info->codec));
-                               return false;
+                           boost::format err = boost::format(
+                               _("Unsupported audio codec %d")) %
+                               static_cast<int>(info.codec);
+                               throw MediaException(err.str());
                }
        }
        else
        {
-               log_error("AudioDecoderFfmpeg::setup: unknown codec type %d ( 
should never happen )", info->type);
-               return false;
+        boost::format err = boost::format(
+            _("AudioDecoderFfmpeg: unknown codec type %d "
+            "(should never happen)")) % info.type;
+        throw MediaException(err.str());
        }
 
        _audioCodec = avcodec_find_decoder(codec_id);
        if (!_audioCodec)
        {
-               log_error(_("libavcodec can't decode the current audio 
format"));
-               return false;
+               throw MediaException(_("libavcodec can't decode this "
+                               "audio format"));
        }
 
        // Init the parser
-       _parser = av_parser_init(static_cast<CodecID>(info->codec));
+       _parser = av_parser_init(static_cast<CodecID>(info.codec));
 
        // Create an audioCodecCtx from the ffmpeg parser if exists/possible
        _audioCodecCtx = avcodec_alloc_context();
        if (!_audioCodecCtx) {
-               log_error(_("libavcodec couldn't allocate context"));
-               return false;
+               throw MediaException(_("libavcodec couldn't allocate context"));
        }
 
-       if ( info->extra.get() )
+       if ( info.extra.get() )
        {
-               assert(dynamic_cast<ExtraAudioInfoFfmpeg*>(info->extra.get()));
-               const ExtraAudioInfoFfmpeg& ei = 
static_cast<ExtraAudioInfoFfmpeg&>(*info->extra);
+               assert(dynamic_cast<ExtraAudioInfoFfmpeg*>(info.extra.get()));
+               const ExtraAudioInfoFfmpeg& ei = 
static_cast<ExtraAudioInfoFfmpeg&>(*info.extra);
                _audioCodecCtx->extradata = ei.data;
                _audioCodecCtx->extradata_size = ei.dataSize;
        }
@@ -179,21 +202,21 @@
                //avcodec_close(_audioCodecCtx);
                av_free(_audioCodecCtx);
                _audioCodecCtx = 0;
-               log_error(_("AudioDecoderFfmpeg::setup: avcodec_open: failed to 
initialize FFMPEG codec %s (%d)"),
-                       _audioCodec->name, (int)codec_id);
-               return false;
+
+        boost::format err = boost::format(
+            _("AudioDecoderFfmpeg: avcodec_open failed to initialize "
+            "FFMPEG codec %s (%d)")) % _audioCodec->name % (int)codec_id;
+       throw MediaException(err.str());
        }
 
        if (_audioCodecCtx->codec->id != CODEC_ID_MP3) {
-               _audioCodecCtx->channels = (info->stereo ? 2 : 1);
-               _audioCodecCtx->sample_rate = info->sampleRate;
+               _audioCodecCtx->channels = (info.stereo ? 2 : 1);
+               _audioCodecCtx->sample_rate = info.sampleRate;
                _audioCodecCtx->sample_fmt = SAMPLE_FMT_S16; // was commented 
out, why ?
        }
 
-       log_debug(_("AudioDecoderFfmpeg::setup: initialized FFMPEG codec %s 
(%d)"),
+       log_debug(_("AudioDecoderFfmpeg: initialized FFMPEG codec %s (%d)"),
                _audioCodec->name, (int)codec_id);
-
-       return true;
 }
 
 boost::uint8_t*
@@ -403,7 +426,8 @@
                        log_debug(" output channels (assuming): %d", 2);
                        log_debug(" output samples: %d", samples);
 
-                       abort(); // the call to resample() likely corrupted 
memory...
+            /// Memory errors...
+                       abort();
                }
 
                // we let the consistency check run before we override outSize

=== modified file 'libmedia/ffmpeg/AudioDecoderFfmpeg.h'
--- a/libmedia/ffmpeg/AudioDecoderFfmpeg.h      2008-09-22 16:56:45 +0000
+++ b/libmedia/ffmpeg/AudioDecoderFfmpeg.h      2008-09-23 17:14:12 +0000
@@ -17,8 +17,8 @@
 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
 
-#ifndef __AUDIODECODERFFMPEG_H__
-#define __AUDIODECODERFFMPEG_H__
+#ifndef GNASH_AUDIODECODERFFMPEG_H
+#define GNASH_AUDIODECODERFFMPEG_H
 
 // TODO: What's this for ?
 #ifndef __STDC_CONSTANT_MACROS
@@ -36,18 +36,28 @@
 class AudioDecoderFfmpeg : public AudioDecoder {
        
 public:
-       AudioDecoderFfmpeg();
+       /// @param info
+       ///     AudioInfo class with all the info needed to decode
+       ///     the sound correctly. Throws a MediaException on fatal
+       ///     error.
+       AudioDecoderFfmpeg(AudioInfo& info);
+
+       /// @param info
+       ///     SoundInfo class with all the info needed to decode
+       ///     the sound correctly. Throws a MediaException on fatal
+       ///     error.
+       AudioDecoderFfmpeg(SoundInfo& info);
        ~AudioDecoderFfmpeg();
 
-       bool setup(AudioInfo* info);
-       bool setup(SoundInfo* info);
-
        boost::uint8_t* decode(boost::uint8_t* input, boost::uint32_t 
inputSize, boost::uint32_t& outputSize, boost::uint32_t& decodedBytes, bool 
parse);
 
        boost::uint8_t* decode(const EncodedAudioFrame& af, boost::uint32_t& 
outputSize);
 
 private:
 
+       void setup(AudioInfo& info);
+       void setup(SoundInfo& info);
+
        boost::uint8_t* decodeFrame(boost::uint8_t* input, boost::uint32_t 
inputSize, boost::uint32_t& outputSize);
 
        AVCodec* _audioCodec;

=== modified file 'libmedia/ffmpeg/MediaHandlerFfmpeg.cpp'
--- a/libmedia/ffmpeg/MediaHandlerFfmpeg.cpp    2008-06-09 13:31:51 +0000
+++ b/libmedia/ffmpeg/MediaHandlerFfmpeg.cpp    2008-09-23 17:14:12 +0000
@@ -48,7 +48,8 @@
                }
                catch (GnashException& ex)
                {
-                       log_error("Could not create FFMPEG based media parser 
for input stream: %s", ex.what());
+                       log_error("Could not create FFMPEG based media parser 
for "
+                    "input stream: %s", ex.what());
                        assert(!parser.get());
                }
        }
@@ -59,15 +60,14 @@
 std::auto_ptr<VideoDecoder>
 MediaHandlerFfmpeg::createVideoDecoder(VideoInfo& info)
 {
-       std::auto_ptr<VideoDecoder> ret( new VideoDecoderFfmpeg(info) );
+       std::auto_ptr<VideoDecoder> ret(new VideoDecoderFfmpeg(info));
        return ret;
 }
 
 std::auto_ptr<AudioDecoder>
 MediaHandlerFfmpeg::createAudioDecoder(AudioInfo& info)
 {
-       std::auto_ptr<AudioDecoder> ret( new AudioDecoderFfmpeg() );
-       ret->setup(&info);
+       std::auto_ptr<AudioDecoder> ret(new AudioDecoderFfmpeg(info));
        return ret;
 }
 

=== modified file 'libmedia/ffmpeg/MediaHandlerFfmpeg.h'
--- a/libmedia/ffmpeg/MediaHandlerFfmpeg.h      2008-06-09 13:31:51 +0000
+++ b/libmedia/ffmpeg/MediaHandlerFfmpeg.h      2008-09-23 17:14:12 +0000
@@ -17,8 +17,8 @@
 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
 
-#ifndef __MEDIAHANDLERFFMPEG_H__
-#define __MEDIAHANDLERFFMPEG_H__
+#ifndef GNASH_MEDIAHANDLERFFMPEG_H
+#define GNASH_MEDIAHANDLERFFMPEG_H
 
 #ifdef HAVE_CONFIG_H
 #include "gnashconfig.h"
@@ -46,4 +46,4 @@
 } // gnash.media namespace 
 } // namespace gnash
 
-#endif // __MEDIAHANDLERFFMPEG_H__
+#endif 

=== modified file 'libmedia/ffmpeg/sound_handler_sdl.cpp'
--- a/libmedia/ffmpeg/sound_handler_sdl.cpp     2008-09-23 14:49:55 +0000
+++ b/libmedia/ffmpeg/sound_handler_sdl.cpp     2008-09-23 17:14:12 +0000
@@ -274,43 +274,29 @@
 
        sound->decoder = NULL;
 
-       switch (sounddata->soundinfo->getFormat()) {
-       case AUDIO_CODEC_NELLYMOSER:
-       case AUDIO_CODEC_NELLYMOSER_8HZ_MONO:
-               sound->decoder = new AudioDecoderNellymoser();
-
-               if (!sound->decoder->setup(sounddata->soundinfo.get())) {
-                       log_error("The audio decoder can't decode the audio");
-                       delete sound->decoder;
-                       sound->decoder = NULL;
-               }
-
-               break;
-       case AUDIO_CODEC_MP3:
+    try {
+
+           switch (sounddata->soundinfo->getFormat()) {
+               case AUDIO_CODEC_NELLYMOSER:
+               case AUDIO_CODEC_NELLYMOSER_8HZ_MONO:
+                       sound->decoder = new 
AudioDecoderNellymoser(*(sounddata->soundinfo));
+                       break;
+               case AUDIO_CODEC_MP3:
 #ifdef USE_FFMPEG
-               sound->decoder = new AudioDecoderFfmpeg();
-
-               if (!sound->decoder->setup(sounddata->soundinfo.get())) {
-                       log_error("The audio decoder can't decode the audio");
-                       delete sound->decoder;
-                       sound->decoder = NULL;
-               }
-
-               break;
+                       sound->decoder = new 
AudioDecoderFfmpeg(*(sounddata->soundinfo));
+                       break;
 #endif
-       case AUDIO_CODEC_ADPCM:
-       default:
-
-               sound->decoder = new AudioDecoderSimple();
-
-               if (!sound->decoder->setup(sounddata->soundinfo.get())) {
-                       log_error("The audio decoder can't decode the audio");
-                       delete sound->decoder;
-                       sound->decoder = NULL;
-               }
-
-       }
-               
+               case AUDIO_CODEC_ADPCM:
+               default:
+                sound->decoder = new 
AudioDecoderSimple(*(sounddata->soundinfo));
+                break;
+           }
+       }
+       catch (MediaException& e)
+       {
+           log_error("AudioDecoder initialization failed");
+       }
+
        if (!soundOpened) {
                if (SDL_OpenAudio(&audioSpec, NULL) < 0 ) {
                        log_error(_("Unable to start SDL sound: %s"), 
SDL_GetError());

=== modified file 'libmedia/gst/AudioDecoderGst.cpp'
--- a/libmedia/gst/AudioDecoderGst.cpp  2008-03-05 03:55:48 +0000
+++ b/libmedia/gst/AudioDecoderGst.cpp  2008-09-23 17:14:12 +0000
@@ -28,7 +28,7 @@
 namespace gnash {
 namespace media {
 
-AudioDecoderGst::AudioDecoderGst() :
+AudioDecoderGst::AudioDecoderGst(AudioInfo& info) :
        _pipeline(NULL),
        _input(NULL),
        _inputcaps(NULL),
@@ -43,6 +43,7 @@
        _decodedDataSize(0),
        _decodedData(0)
 {
+    setup(info);
 }
 
 AudioDecoderGst::~AudioDecoderGst()
@@ -56,9 +57,12 @@
        }
 }
 
-bool AudioDecoderGst::setup(AudioInfo* info)
+void AudioDecoderGst::setup(AudioInfo& info)
 {
-       if (info->type != FLASH || info->codec != AUDIO_CODEC_MP3) return false;
+       if (info.type != FLASH || info.codec != AUDIO_CODEC_MP3)
+       {
+           throw MediaException("AudioDecoderGst: cannot handle this codec!");
+       }
 
        // init GStreamer
        gst_init (NULL, NULL);
@@ -91,8 +95,9 @@
        }
        // Check if the element was correctly created
        if (!_decoder) {
-               log_error(_("A gstreamer mp3-decoder element could not be 
created.  You probably need to install a mp3-decoder plugin like 
gstreamer0.10-mad or gstreamer0.10-fluendo-mp3."));
-               return false;
+               throw MediaException (_("A gstreamer mp3-decoder element could 
not "
+                               "be created. You probably need to install a 
mp3-decoder plugin"
+                               " like gstreamer0.10-mad or 
gstreamer0.10-fluendo-mp3."));
        }
 
        GstCaps *caps = NULL;
@@ -140,8 +145,6 @@
        // Start "playing"
        gst_element_set_state (GST_ELEMENT (_pipeline), GST_STATE_PLAYING);
 
-       return true;
-
 }
 
 boost::uint8_t* AudioDecoderGst::decode(boost::uint8_t* input, boost::uint32_t 
inputSize, boost::uint32_t& outputSize, boost::uint32_t& decodedData, bool 
/*parse*/)

=== modified file 'libmedia/gst/AudioDecoderGst.h'
--- a/libmedia/gst/AudioDecoderGst.h    2008-03-05 03:55:48 +0000
+++ b/libmedia/gst/AudioDecoderGst.h    2008-09-23 17:14:12 +0000
@@ -17,8 +17,8 @@
 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
 
-#ifndef __AUDIODECODERGST_H__
-#define __AUDIODECODERGST_H__
+#ifndef GNASH_AUDIODECODERGST_H
+#define GNASH_AUDIODECODERGST_H
 
 #ifdef HAVE_CONFIG_H
 #include "gnashconfig.h"
@@ -40,17 +40,18 @@
 class AudioDecoderGst : public AudioDecoder {
        
 public:
-       AudioDecoderGst();
+       AudioDecoderGst(AudioInfo& info);
+
        ~AudioDecoderGst();
 
-       bool setup(AudioInfo* info);
-
        boost::uint8_t* decode(boost::uint8_t* /*input*/, boost::uint32_t 
/*inputSize*/, boost::uint32_t& /*outputSize*/, boost::uint32_t& 
/*decodedData*/, bool /*parse*/);
 
        static void callback_handoff (GstElement * /*c*/, GstBuffer *buffer, 
GstPad* /*pad*/, gpointer user_data);
        static void callback_output (GstElement * /*c*/, GstBuffer *buffer, 
GstPad* /*pad*/, gpointer user_data);
 private:
 
+       void setup(AudioInfo& info);
+
        // gstreamer pipeline objects
 
        /// the main bin containing the elements

=== modified file 'libmedia/gst/MediaHandlerGst.cpp'
--- a/libmedia/gst/MediaHandlerGst.cpp  2008-06-09 13:31:51 +0000
+++ b/libmedia/gst/MediaHandlerGst.cpp  2008-09-23 17:14:12 +0000
@@ -54,8 +54,7 @@
 std::auto_ptr<AudioDecoder>
 MediaHandlerGst::createAudioDecoder(AudioInfo& info)
 {
-       std::auto_ptr<AudioDecoder> ret( new AudioDecoderGst() );
-       ret->setup(&info);
+       std::auto_ptr<AudioDecoder> ret( new AudioDecoderGst(info) );
        return ret;
 }
 


reply via email to

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