gnash-commit
[Top][All Lists]
Advanced

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

[Gnash-commit] /srv/bzr/gnash/trunk r12317: Return of the ifdefs. Regist


From: Benjamin Wolsey
Subject: [Gnash-commit] /srv/bzr/gnash/trunk r12317: Return of the ifdefs. Register media handlers explicitly to avoid the
Date: Tue, 20 Jul 2010 13:59:11 +0200
User-agent: Bazaar (2.0.3)

------------------------------------------------------------
revno: 12317 [merge]
committer: Benjamin Wolsey <address@hidden>
branch nick: trunk
timestamp: Tue 2010-07-20 13:59:11 +0200
message:
  Return of the ifdefs. Register media handlers explicitly to avoid the
  problem with static initialization.
  
  Media handlers are still selectable at runtime, and all ifdefs are in one
  place.
  
  This unfortunately means more intervention into the libmedia and
  configure code when adding new handlers, but is unavoidable if we want
  portable code.
added:
  libmedia/ffmpeg/MediaHandlerFfmpeg.h
  libmedia/gst/MediaHandlerGst.h
  libmedia/haiku/MediaHandlerHaiku.h
modified:
  configure.ac
  libbase/GnashFactory.h
  libmedia/Makefile.am
  libmedia/MediaHandler.cpp
  libmedia/MediaHandler.h
  libmedia/ffmpeg/MediaHandlerFfmpeg.cpp
  libmedia/gst/MediaHandlerGst.cpp
  libmedia/haiku/MediaHandlerHaiku.cpp
=== modified file 'configure.ac'
--- a/configure.ac      2010-07-19 13:55:09 +0000
+++ b/configure.ac      2010-07-20 06:51:24 +0000
@@ -2279,6 +2279,18 @@
 dnl for now the Haiku media handler is experimental
 AM_CONDITIONAL(USE_HAIKU_ENGINE, test x"$build_media_haiku" = xyes)
 
+if test x"${build_media_ffmpeg}" = x"yes"; then
+  AC_DEFINE([ENABLE_FFMPEG_MEDIA],  [1], [Use FFmpeg for media decoding])
+fi
+
+if test x"${build_media_gst}" = x"yes"; then
+  AC_DEFINE([ENABLE_GST_MEDIA],  [1], [Use gstreamer for media decoding])
+fi
+
+if test x"${build_media_haiku}" = x"yes"; then
+  AC_DEFINE([ENABLE_HAIKU_MEDIA],  [1], [Use haiku for media decoding])
+fi
+
 if test x$build_sound_mkit = xyes; then
   if test x"${haiku}" != xyes; then
     AC_MSG_ERROR([Media Kit sound handling is supported only under Haiku]);

=== modified file 'libbase/GnashFactory.h'
--- a/libbase/GnashFactory.h    2010-07-19 13:57:06 +0000
+++ b/libbase/GnashFactory.h    2010-07-20 06:51:24 +0000
@@ -46,7 +46,13 @@
 //
 /// Note that this relies on static initialization, so do not call get()
 /// before or after main().
-template<typename T, typename Key = std::string>
+//
+/// @tparam T       The base type to be produced by the factory
+/// @tparam Init    An object whose constructor ensures that the elements
+///                 are registered. This helps avoid problems with
+///                 unpredictable static initialization.
+/// @tparam Key     The type to be used as a key.
+template<typename T, typename Init = void, typename Key = std::string>
 class DSOEXPORT GnashFactory
 {
 public:
@@ -70,6 +76,8 @@
     typedef std::map<std::string, CreateHandler> Handlers;
 
     /// Get the GnashFactory singleton.
+    //
+    /// This also initializes the factory if an Init argument was provided.
     static GnashFactory& instance() {
         static GnashFactory m;
         return m;
@@ -82,6 +90,7 @@
     void listKeys(Iterator i, typename boost::enable_if<boost::is_same<
               typename std::iterator_traits<Iterator>::iterator_category,
               std::output_iterator_tag> >::type* dummy = 0) {
+        Init();
         static_cast<void>(dummy);
         std::transform(_handlers.begin(), _handlers.end(), i,
                 FirstElement<typename Handlers::value_type>());
@@ -95,6 +104,7 @@
     ///                 string is not empty and no match is found, a null
     ///                 pointer will be returned.
     T* get(const Key& name) {
+        Init();
         if (name.empty()) {
             return _handlers.empty() ? 0 : _handlers.begin()->second();
         }
@@ -116,6 +126,8 @@
 
 private:
 
+    GnashFactory() {}
+
     Handlers _handlers;
 
 };

=== modified file 'libmedia/Makefile.am'
--- a/libmedia/Makefile.am      2010-07-14 12:19:53 +0000
+++ b/libmedia/Makefile.am      2010-07-20 06:51:24 +0000
@@ -101,6 +101,7 @@
        $(NULL)
 
    noinst_HEADERS += \
+       gst/MediaHandlerGst.h \
        gst/AudioDecoderGst.h \
        gst/VideoDecoderGst.h \
        gst/MediaParserGst.h \
@@ -142,6 +143,7 @@
        $(NULL)
 
    noinst_HEADERS += \
+       ffmpeg/MediaHandlerFfmpeg.h \
        ffmpeg/MediaParserFfmpeg.h \
        ffmpeg/AudioDecoderFfmpeg.h \
        ffmpeg/VideoDecoderFfmpeg.h \

=== modified file 'libmedia/MediaHandler.cpp'
--- a/libmedia/MediaHandler.cpp 2010-07-14 13:12:36 +0000
+++ b/libmedia/MediaHandler.cpp 2010-07-20 06:51:24 +0000
@@ -111,7 +111,38 @@
     }
 }
 
-
-} // end of gnash::media namespace
-} // end of gnash namespace
-
+} // namespace media 
+} // namespace gnash
+
+/// Here follows handler registration code.
+
+#ifdef ENABLE_FFMPEG_MEDIA
+#include "ffmpeg/MediaHandlerFfmpeg.h"
+#endif
+#ifdef ENABLE_GST_MEDIA
+#include "gst/MediaHandlerGst.h"
+#endif
+#ifdef ENABLE_HAIKU_MEDIA
+#include "haiku/MediaHandlerHaiku.h"
+#endif
+
+namespace gnash {
+namespace media {
+
+RegisterAllHandlers::RegisterAllHandlers()
+{
+#ifdef ENABLE_FFMPEG_MEDIA
+    static const MediaFactory::RegisterHandler<ffmpeg::MediaHandlerFfmpeg>
+        ffmpeg("ffmpeg");
+#endif
+#ifdef ENABLE_GST_MEDIA
+    static const MediaFactory::RegisterHandler<gst::MediaHandlerGst> 
gst("gst");
+#endif
+#ifdef ENABLE_HAIKU_MEDIA
+    static const MediaFactory::RegisterHandler<haiku::MediaHandlerHaiku>
+        haiku("haiku");
+#endif
+}
+
+} // namespace media
+} // namespace gnash

=== modified file 'libmedia/MediaHandler.h'
--- a/libmedia/MediaHandler.h   2010-07-15 06:33:18 +0000
+++ b/libmedia/MediaHandler.h   2010-07-20 06:51:24 +0000
@@ -57,7 +57,12 @@
 /// @todo fix http://wiki.gnashdev.org/wiki/index.php/Libmedia, is obsoleted
 namespace media {
 
-typedef GnashFactory<MediaHandler> MediaFactory;
+struct RegisterAllHandlers
+{
+    RegisterAllHandlers();
+};
+
+typedef GnashFactory<MediaHandler, RegisterAllHandlers> MediaFactory;
 
 /// The MediaHandler class acts as a factory to provide parser and decoders
 class DSOEXPORT MediaHandler

=== modified file 'libmedia/ffmpeg/MediaHandlerFfmpeg.cpp'
--- a/libmedia/ffmpeg/MediaHandlerFfmpeg.cpp    2010-07-15 06:33:18 +0000
+++ b/libmedia/ffmpeg/MediaHandlerFfmpeg.cpp    2010-07-20 06:51:24 +0000
@@ -18,7 +18,7 @@
 //
 
 
-#include "MediaHandler.h"
+#include "MediaHandlerFfmpeg.h"
 
 #include <sstream>
 
@@ -36,43 +36,17 @@
 namespace gnash { 
 namespace media {
 namespace ffmpeg {
-
-/// FFMPEG based MediaHandler
-class MediaHandlerFfmpeg : public MediaHandler
+    
+std::string
+MediaHandlerFfmpeg::description() const
 {
-public:
-
-    virtual std::string description() const {
-        std::ostringstream ss;
-        const boost::uint32_t ver = avcodec_version();
-        ss << "FFmpeg (avcodec version: " << (ver >> 16) << "."
-                                          << (ver & 0xff00 >> 8)  << "."
-                                          << (ver & 0xff) << ")";
-        return ss.str();
-    }
-
-       virtual std::auto_ptr<MediaParser>
-        createMediaParser(std::auto_ptr<IOChannel> stream);
-
-       virtual std::auto_ptr<VideoDecoder>
-        createVideoDecoder(const VideoInfo& info);
-       
-       virtual std::auto_ptr<VideoConverter>
-               createVideoConverter(ImgBuf::Type4CC srcFormat,
-                ImgBuf::Type4CC dstFormat);
-
-       virtual std::auto_ptr<AudioDecoder>
-        createAudioDecoder(const AudioInfo& info);
-
-    virtual size_t getInputPaddingSize() const;
-    
-    virtual VideoInput* getVideoInput(size_t index);
-    
-    virtual AudioInput* getAudioInput(size_t index);
-
-    virtual void cameraNames(std::vector<std::string>& names) const;
-
-};
+    std::ostringstream ss;
+    const boost::uint32_t ver = avcodec_version();
+    ss << "FFmpeg (avcodec version: " << (ver >> 16) << "."
+                      << (ver & 0xff00 >> 8)  << "."
+                      << (ver & 0xff) << ")";
+    return ss.str();
+}
 
 std::auto_ptr<MediaParser>
 MediaHandlerFfmpeg::createMediaParser(std::auto_ptr<IOChannel> stream)
@@ -181,12 +155,6 @@
     return FF_INPUT_BUFFER_PADDING_SIZE;
 }
 
-#ifdef REGISTER_MEDIA_HANDLERS
-namespace {
-    MediaFactory::RegisterHandler<MediaHandlerFfmpeg> reg("ffmpeg");
-}
-#endif
-
 } // gnash.media.ffmpeg namespace 
 } // gnash.media namespace 
 } // gnash namespace

=== added file 'libmedia/ffmpeg/MediaHandlerFfmpeg.h'
--- a/libmedia/ffmpeg/MediaHandlerFfmpeg.h      1970-01-01 00:00:00 +0000
+++ b/libmedia/ffmpeg/MediaHandlerFfmpeg.h      2010-07-20 06:51:24 +0000
@@ -0,0 +1,77 @@
+// MediaHandlerFfmpeg.h: FFMPEG media handler, for Gnash
+// 
+//   Copyright (C) 2007, 2008, 2009, 2010 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
+
+#ifndef GNASH_MEDIAHANDLERFFMPEG_H
+#define GNASH_MEDIAHANDLERFFMPEG_H
+
+#include "MediaHandler.h" // for inheritance
+
+#include <vector>
+#include <memory>
+
+namespace gnash {
+namespace media {
+
+/// FFMPEG-based media handler module
+//
+/// The module implements the MediaHandler factory as required
+/// by Gnash core for a loadable media handler module.
+///
+/// It uses libavformat and libavcodec:
+/// http://www.irisa.fr/texmex/people/dufouil/ffmpegdoxy/index.html
+///
+/// Starting point is MediaHandlerFfmpeg.
+/// 
+namespace ffmpeg {
+
+/// FFMPEG based MediaHandler
+class MediaHandlerFfmpeg : public MediaHandler
+{
+public:
+
+    std::string description() const;
+
+       virtual std::auto_ptr<MediaParser>
+        createMediaParser(std::auto_ptr<IOChannel> stream);
+
+       virtual std::auto_ptr<VideoDecoder>
+        createVideoDecoder(const VideoInfo& info);
+       
+       virtual std::auto_ptr<VideoConverter>
+               createVideoConverter(ImgBuf::Type4CC srcFormat,
+                ImgBuf::Type4CC dstFormat);
+
+       virtual std::auto_ptr<AudioDecoder>
+        createAudioDecoder(const AudioInfo& info);
+
+    virtual size_t getInputPaddingSize() const;
+    
+    virtual VideoInput* getVideoInput(size_t index);
+    
+    virtual AudioInput* getAudioInput(size_t index);
+
+    virtual void cameraNames(std::vector<std::string>& names) const;
+
+};
+
+
+} // gnash.media.ffmpeg namespace 
+} // gnash.media namespace 
+} // namespace gnash
+
+#endif 

=== modified file 'libmedia/gst/MediaHandlerGst.cpp'
--- a/libmedia/gst/MediaHandlerGst.cpp  2010-07-15 06:33:18 +0000
+++ b/libmedia/gst/MediaHandlerGst.cpp  2010-07-20 06:51:24 +0000
@@ -16,7 +16,7 @@
 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 //
 
-#include "MediaHandler.h"
+#include "MediaHandlerGst.h"
 
 #include <sstream>
 
@@ -42,46 +42,15 @@
 namespace media {
 namespace gst {
 
-/// GST based MediaHandler
-//
-/// The module implements the MediaHandler factory as required
-/// by Gnash core for a loadable media handler module.
-///
-/// It uses gstreamer: http://gstreamer.freedesktop.org/
-///
-/// Starting point is MediaHandlerGst.
-class MediaHandlerGst : public MediaHandler
+std::string
+MediaHandlerGst::description() const
 {
-public:
-
-    virtual std::string description() const {
-        guint major, minor, micro, nano;
-        gst_version(&major, &minor, &micro, &nano);
-        std::ostringstream s;
-        s << _("Gstreamer ") <<  major << "." << minor << "." << micro;
-        return s.str();
-    }
-
-       virtual std::auto_ptr<MediaParser>
-        createMediaParser(std::auto_ptr<IOChannel> stream);
-
-       virtual std::auto_ptr<VideoDecoder>
-        createVideoDecoder(const VideoInfo& info);
-
-       virtual std::auto_ptr<AudioDecoder>
-        createAudioDecoder(const AudioInfo& info);
-       
-       virtual std::auto_ptr<VideoConverter>
-        createVideoConverter(ImgBuf::Type4CC srcFormat,
-                ImgBuf::Type4CC dstFormat);
-    
-    virtual VideoInput* getVideoInput(size_t index);
-
-    virtual AudioInput* getAudioInput(size_t index);
-
-    virtual void cameraNames(std::vector<std::string>& names) const;
-};
-
+    guint major, minor, micro, nano;
+    gst_version(&major, &minor, &micro, &nano);
+    std::ostringstream s;
+    s << "Gstreamer " <<  major << "." << minor << "." << micro;
+    return s.str();
+}
 
 std::auto_ptr<MediaParser>
 MediaHandlerGst::createMediaParser(std::auto_ptr<IOChannel> stream)

=== added file 'libmedia/gst/MediaHandlerGst.h'
--- a/libmedia/gst/MediaHandlerGst.h    1970-01-01 00:00:00 +0000
+++ b/libmedia/gst/MediaHandlerGst.h    2010-07-20 06:51:24 +0000
@@ -0,0 +1,73 @@
+// MediaHandlerGst.h: GST media handler, for Gnash
+// 
+//   Copyright (C) 2007, 2008, 2009, 2010 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
+
+#ifndef GNASH_MEDIAHANDLERGST_H
+#define GNASH_MEDIAHANDLERGST_H
+
+#include "MediaHandler.h"
+
+#include <vector>
+#include <memory>
+
+namespace gnash {
+namespace media {
+
+/// Gstreamer-based media handler module
+namespace gst {
+
+/// GST based MediaHandler
+//
+/// The module implements the MediaHandler factory as required
+/// by Gnash core for a loadable media handler module.
+///
+/// It uses gstreamer: http://gstreamer.freedesktop.org/
+///
+/// Starting point is MediaHandlerGst.
+class MediaHandlerGst : public MediaHandler
+{
+public:
+
+    virtual std::string description() const;
+
+       virtual std::auto_ptr<MediaParser>
+        createMediaParser(std::auto_ptr<IOChannel> stream);
+
+       virtual std::auto_ptr<VideoDecoder>
+        createVideoDecoder(const VideoInfo& info);
+
+       virtual std::auto_ptr<AudioDecoder>
+        createAudioDecoder(const AudioInfo& info);
+       
+       virtual std::auto_ptr<VideoConverter>
+        createVideoConverter(ImgBuf::Type4CC srcFormat,
+                ImgBuf::Type4CC dstFormat);
+    
+    virtual VideoInput* getVideoInput(size_t index);
+
+    virtual AudioInput* getAudioInput(size_t index);
+
+    virtual void cameraNames(std::vector<std::string>& names) const;
+};
+
+
+
+} // gnash.media.gst namespace
+} // gnash.media namespace 
+} // namespace gnash
+
+#endif 

=== modified file 'libmedia/haiku/MediaHandlerHaiku.cpp'
--- a/libmedia/haiku/MediaHandlerHaiku.cpp      2010-07-19 13:55:09 +0000
+++ b/libmedia/haiku/MediaHandlerHaiku.cpp      2010-07-20 06:51:24 +0000
@@ -17,7 +17,7 @@
 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 //
 
-#include "MediaHandler.h"
+#include "MediaHandlerHaiku.h"
 #include "MediaParser.h"
 
 #include "log.h"
@@ -38,37 +38,6 @@
 namespace media {
 namespace haiku {
 
-/// Haiku based MediaHandler
-class MediaHandlerHaiku : public MediaHandler
-{
-public:
-
-    virtual std::string description() const {
-        return "Haiku Media Handler";
-    }
-
-       virtual std::auto_ptr<MediaParser>
-        createMediaParser(std::auto_ptr<IOChannel> stream);
-
-       virtual std::auto_ptr<VideoDecoder>
-        createVideoDecoder(const VideoInfo& info);
-       
-       virtual std::auto_ptr<VideoConverter>
-               createVideoConverter(ImgBuf::Type4CC srcFormat,
-                ImgBuf::Type4CC dstFormat);
-
-       virtual std::auto_ptr<AudioDecoder>
-        createAudioDecoder(const AudioInfo& info);
-
-//    virtual size_t getInputPaddingSize() const;
-    
-    virtual VideoInput* getVideoInput(size_t index);
-    
-    virtual AudioInput* getAudioInput(size_t index);
-
-    virtual void cameraNames(std::vector<std::string>& names) const;
-
-};
 
 std::auto_ptr<MediaParser>
 MediaHandlerHaiku::createMediaParser(std::auto_ptr<IOChannel> stream)

=== added file 'libmedia/haiku/MediaHandlerHaiku.h'
--- a/libmedia/haiku/MediaHandlerHaiku.h        1970-01-01 00:00:00 +0000
+++ b/libmedia/haiku/MediaHandlerHaiku.h        2010-07-20 06:51:24 +0000
@@ -0,0 +1,78 @@
+// MediaHandlerHaiku.h: Haiku media kit media handler, for Gnash
+// 
+//   Copyright (C) 2007, 2008, 2009, 2010 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
+
+#ifndef GNASH_MEDIAHANDLERHAIKU_H
+#define GNASH_MEDIAHANDLERHAIKU_H
+
+#include "MediaHandler.h" // for inheritance
+
+#include <vector>
+#include <memory>
+
+namespace gnash {
+namespace media {
+
+/// Haiku media kit based media handler module
+//
+/// The module implements the MediaHandler factory as required
+/// by Gnash core for a loadable media handler module.
+///
+/// It uses the Haiku media kit
+///
+/// Starting point is MediaHandlerHaiku.
+/// 
+namespace haiku {
+
+/// Haiku based MediaHandler
+class MediaHandlerHaiku : public MediaHandler
+{
+public:
+
+    virtual std::string description() const {
+        return "Haiku Media Handler";
+    }
+
+       virtual std::auto_ptr<MediaParser>
+        createMediaParser(std::auto_ptr<IOChannel> stream);
+
+       virtual std::auto_ptr<VideoDecoder>
+        createVideoDecoder(const VideoInfo& info);
+       
+       virtual std::auto_ptr<VideoConverter>
+               createVideoConverter(ImgBuf::Type4CC srcFormat,
+                ImgBuf::Type4CC dstFormat);
+
+       virtual std::auto_ptr<AudioDecoder>
+        createAudioDecoder(const AudioInfo& info);
+
+//    virtual size_t getInputPaddingSize() const;
+    
+    virtual VideoInput* getVideoInput(size_t index);
+    
+    virtual AudioInput* getAudioInput(size_t index);
+
+    virtual void cameraNames(std::vector<std::string>& names) const;
+
+};
+
+
+} // gnash.media.haiku namespace 
+} // gnash.media namespace 
+} // namespace gnash
+
+#endif 


reply via email to

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