diff --git a/aegisub/libmedia/audio/ffms_audio.cpp b/aegisub/libmedia/audio/ffms_audio.cpp index e0688b843..1ef123570 100644 --- a/aegisub/libmedia/audio/ffms_audio.cpp +++ b/aegisub/libmedia/audio/ffms_audio.cpp @@ -25,9 +25,10 @@ #endif #include "ffms_audio.h" -#include "libmedia/exception.h" +#include "libmedia/audio.h" -namespace agi { + +namespace media { namespace ffms { @@ -218,6 +219,5 @@ void Audio::GetAudio(void *Buf, int64_t Start, int64_t Count) const { throw AudioDecodeError(std::string("Failed to get audio samples: ") + ErrInfo.Buffer); } } - } // namespace ffms -} // namespace agi +} // namespace media diff --git a/aegisub/libmedia/audio/ffms_audio.h b/aegisub/libmedia/audio/ffms_audio.h index a9aea05e9..b971b2e97 100644 --- a/aegisub/libmedia/audio/ffms_audio.h +++ b/aegisub/libmedia/audio/ffms_audio.h @@ -19,7 +19,7 @@ /// @ingroup fmms audio #include "../../libffms/include/ffms.h" -#include +#include #ifndef AGI_PRE #ifdef WIN32 @@ -30,13 +30,12 @@ #endif #include "../common/ffms_common.h" - -namespace agi { +namespace media { namespace ffms { /// @class Audio /// Audio file support. -class Audio : public FFmpegSourceProvider { +class Audio : public AudioProvider, FFmpegSourceProvider { FFMS_AudioSource *AudioSource; ///< audio source object bool COMInited; ///< COM initialization state @@ -46,11 +45,6 @@ class Audio : public FFmpegSourceProvider { void Close(); void LoadAudio(std::string filename); - int channels; - int64_t num_samples; // for one channel, ie. number of PCM frames - int sample_rate; - int bytes_per_sample; - Audio(std::string filename); virtual ~Audio(); @@ -65,4 +59,4 @@ class Audio : public FFmpegSourceProvider { }; } // namespace ffms -} // namespace agi +} // namespace media diff --git a/aegisub/libmedia/common/ffms_common.cpp b/aegisub/libmedia/common/ffms_common.cpp index 92926c4ee..0e7955d70 100644 --- a/aegisub/libmedia/common/ffms_common.cpp +++ b/aegisub/libmedia/common/ffms_common.cpp @@ -57,7 +57,7 @@ //#include "md5.h" //#include "standard_paths.h" -namespace agi { +namespace media { namespace ffms { /// @brief Callback function that updates the indexing progress dialog @@ -389,4 +389,4 @@ wxThread::ExitCode FFmpegSourceCacheCleaner::Entry() { } // namespace ffms -} // namespace agi +} // namespace media diff --git a/aegisub/libmedia/common/ffms_common.h b/aegisub/libmedia/common/ffms_common.h index 7c6a7f530..9b20e0efe 100644 --- a/aegisub/libmedia/common/ffms_common.h +++ b/aegisub/libmedia/common/ffms_common.h @@ -45,7 +45,7 @@ #include "../../libffms/include/ffms.h" -namespace agi { +namespace media { namespace ffms { //#include "dialog_progress.h" @@ -111,4 +111,4 @@ public: #endif /* WITH_FFMPEGSOURCE */ } // namespace ffms -} // namespace agi +} // namespace media diff --git a/aegisub/libmedia/common/video_frame.cpp b/aegisub/libmedia/common/video_frame.cpp index c816b99b7..043dc9581 100644 --- a/aegisub/libmedia/common/video_frame.cpp +++ b/aegisub/libmedia/common/video_frame.cpp @@ -28,8 +28,7 @@ #include #endif -namespace agi { - namespace media { +namespace media { void AegiVideoFrame::Reset() { // Zero variables @@ -114,5 +113,4 @@ void AegiVideoFrame::SetTo(const unsigned char *source, unsigned int width, unsi this->pitch = pitch; } - } // namespace media -} // namespace agi +} // namespace media diff --git a/aegisub/libmedia/include/libmedia/audio.h b/aegisub/libmedia/include/libmedia/audio.h index ca1b07f05..9f6b53ed9 100644 --- a/aegisub/libmedia/include/libmedia/audio.h +++ b/aegisub/libmedia/include/libmedia/audio.h @@ -36,12 +36,10 @@ #pragma once -#ifndef AGI_PRE -#include -#endif - #include -#include "factory_manager.h" +#include + +namespace media { /// @class AudioProvider /// @brief DOCME @@ -72,13 +70,13 @@ protected: /// DOCME - wxString filename; + std::string filename; public: AudioProvider(); virtual ~AudioProvider(); - virtual wxString GetFilename() const { return filename; }; + virtual std::string GetFilename() const { return filename; }; virtual void GetAudio(void *buf, int64_t start, int64_t count) const = 0; void GetAudioWithVolume(void *buf, int64_t start, int64_t count, double volume) const; @@ -97,10 +95,10 @@ public: /// @brief DOCME /// /// DOCME -class AudioProviderFactory : public Factory1 { +class AudioProviderFactory : public Factory1 { public: static void RegisterProviders(); - static AudioProvider *GetProvider(wxString filename, int cache=-1); + static AudioProvider *GetProvider(std::string filename, int cache=-1); }; DEFINE_BASE_EXCEPTION_NOINNER(AudioProviderError, agi::Exception); @@ -108,3 +106,5 @@ DEFINE_SIMPLE_EXCEPTION_NOINNER(AudioOpenError, AudioProviderError, "audio/open/ /// Error of some sort occurred while decoding a frame DEFINE_SIMPLE_EXCEPTION_NOINNER(AudioDecodeError, AudioProviderError, "audio/error"); + +} // namespace media diff --git a/aegisub/libmedia/include/libmedia/factory_manager.h b/aegisub/libmedia/include/libmedia/factory_manager.h new file mode 100644 index 000000000..9fdccc628 --- /dev/null +++ b/aegisub/libmedia/include/libmedia/factory_manager.h @@ -0,0 +1,147 @@ +// Copyright (c) 2010, Thomas Goyne +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// * Neither the name of the Aegisub Group nor the names of its contributors +// may be used to endorse or promote products derived from this software +// without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. +// +// Aegisub Project http://www.aegisub.org/ +// +// $Id$ + +/// @file factory_manager.h +/// @brief Template/base-class for factory classes +/// @ingroup utility +/// + +#pragma once + +#ifndef MAGI_PRE +#include +#include +#include +#include +#endif + +namespace media { + +template +class FactoryBase { +protected: + typedef std::map > map; + typedef typename map::iterator iterator; + + static map *classes; + + static void DoRegister(func function, std::string name, bool hide, std::vector &subtypes) { + if (!classes) classes = new map; + + if (subtypes.empty()) { + classes->insert(std::make_pair(name, std::make_pair(hide, function))); + } + else { + for (size_t i = 0; i < subtypes.size(); i++) { + classes->insert(std::make_pair(name + '/' + subtypes[i], std::make_pair(hide, function))); + } + } + } + + static func Find(std::string name) { + if (!classes) return NULL; + + iterator factory = classes->find(name); + if (factory != classes->end()) return factory->second.second; + return NULL; + } + +public: + static void Clear() { + delete classes; + } + static std::vector GetClasses(std::string favourite="") { + std::vector list; + if (!classes) return list; + std::string cmp; + std::transform(favourite.begin(), favourite.end(), favourite.begin(), ::tolower); + for (iterator cur=classes->begin();cur!=classes->end();cur++) { + cmp.clear(); + std::transform(cur->first.begin(), cur->first.end(), std::back_inserter(cmp), ::tolower); + if (cmp == favourite) list.insert(list.begin(), cur->first); + else if (!cur->second.first) list.push_back(cur->first); + } + return list; + } + virtual ~FactoryBase() { + delete classes; + } +}; + +template +class Factory0 : public FactoryBase { + typedef Base *(*func)(); + template + static Base* create() { + return new T; + } +public: + static Base* Create(std::string name) { + func factory = FactoryBase::Find(name); + if (factory) { + return factory(); + } + else { + return NULL; + } + } + + template + static void Register(std::string name, bool hide = false, std::vector subTypes = std::vector()) { + DoRegister(&Factory0::template create, name, hide, subTypes); + } +}; + +template +class Factory1 : public FactoryBase { + typedef Base *(*func)(Arg1); + template + static Base* create(Arg1 a1) { + return new T(a1); + } +public: + static Base* Create(std::string name, Arg1 a1) { + func factory = FactoryBase::Find(name); + if (factory) { + return factory(a1); + } + else { + return NULL; + } + } + + template + static void Register(std::string name, bool hide = false, std::vector subTypes = std::vector()) { + DoRegister(&Factory1::template create, name, hide, subTypes); + } +}; + +} // namespace media diff --git a/aegisub/libmedia/include/libmedia/video.h b/aegisub/libmedia/include/libmedia/video.h index a658f5e32..6b1d5ca1b 100644 --- a/aegisub/libmedia/include/libmedia/video.h +++ b/aegisub/libmedia/include/libmedia/video.h @@ -36,10 +36,13 @@ #pragma once -#include "video_frame.h" +#include #include #include + +namespace media { + /// @class VideoProvider /// @brief DOCME /// @@ -61,10 +64,10 @@ public: /// @brief Use this to set any post-loading warnings, such as "being loaded with unreliable seeking" - virtual wxString GetWarning() const { return L""; } + virtual std::string GetWarning() const { return ""; } /// @brief Name of decoder, e.g. "Avisynth/FFMpegSource" - virtual wxString GetDecoderName() const = 0; + virtual std::string GetDecoderName() const = 0; /// @brief Does this provider want Aegisub to cache video frames? /// @return Returns true if caching is desired, false otherwise. @@ -79,3 +82,6 @@ DEFINE_SIMPLE_EXCEPTION_NOINNER(VideoOpenError, VideoProviderError, "video/open/ /// Error of some sort occurred while decoding a frame DEFINE_SIMPLE_EXCEPTION_NOINNER(VideoDecodeError, VideoProviderError, "video/error"); + +// namespace media + diff --git a/aegisub/libmedia/include/libmedia/video_frame.h b/aegisub/libmedia/include/libmedia/video_frame.h index 7ac1467e4..906dbe4a4 100644 --- a/aegisub/libmedia/include/libmedia/video_frame.h +++ b/aegisub/libmedia/include/libmedia/video_frame.h @@ -22,8 +22,7 @@ #ifndef LAGI_PRE #endif -namespace agi { - namespace media { +namespace media { /// DOCME /// @class AegiVideoFrame @@ -85,5 +84,4 @@ public: int GetBpp() const { return 4; }; }; - } // namespace media -} // namespace agi +} // namespace media