Made Export format compatibility checking a bit more robust

git-svn-id: svn://localhost/ardour2/branches/3.0@3829 d708f5d6-7413-0410-9779-e7cbd77b26cf
This commit is contained in:
Sakari Bergen 2008-09-29 10:02:35 +00:00
parent 400f8bb03d
commit 474f8bc376
3 changed files with 29 additions and 31 deletions

View file

@ -26,11 +26,15 @@
#include <list>
#include <boost/weak_ptr.hpp>
#include <pbd/failed_constructor.h>
namespace ARDOUR
{
class HasSampleFormat;
class ExportFormatIncompatible : public failed_constructor {
public:
virtual const char *what() const throw() { return "Export format constructor failed: Format incompatible with system"; }
};
/// Base class for formats
class ExportFormat : public ExportFormatBase, public ExportFormatBase::SelectableCompatible {
@ -170,8 +174,6 @@ class ExportFormatOggVorbis : public ExportFormat {
ExportFormatOggVorbis ();
~ExportFormatOggVorbis () {};
static bool check_system_compatibility ();
bool set_compatibility_state (ExportFormatCompatibility const & compatibility);
Type get_type () const { return T_Sndfile; }
SampleFormat get_explicit_sample_format () const { return SF_Vorbis; }
@ -183,8 +185,6 @@ class ExportFormatFLAC : public ExportFormat, public HasSampleFormat {
ExportFormatFLAC ();
~ExportFormatFLAC () {};
static bool check_system_compatibility ();
bool set_compatibility_state (ExportFormatCompatibility const & compatibility);
Type get_type () const { return T_Sndfile; }

View file

@ -185,15 +185,15 @@ ExportFormatManager::init_formats ()
fl_ptr->set_extension ("raw");
add_format (f_ptr);
if (ExportFormatOggVorbis::check_system_compatibility()) {
try {
f_ptr.reset (new ExportFormatOggVorbis ());
add_format (f_ptr);
}
} catch (ExportFormatIncompatible & e) {}
if (ExportFormatFLAC::check_system_compatibility()) {
try {
f_ptr.reset (new ExportFormatFLAC ());
add_format (f_ptr);
}
} catch (ExportFormatIncompatible & e) {}
}
void

View file

@ -234,6 +234,16 @@ ExportFormatLinear::set_compatibility_state (ExportFormatCompatibility const & c
ExportFormatOggVorbis::ExportFormatOggVorbis ()
{
/* Check system compatibility */
SF_INFO sf_info;
sf_info.channels = 2;
sf_info.samplerate = SR_44_1;
sf_info.format = F_Ogg | SF_Vorbis;
if (sf_format_check (&sf_info) != SF_TRUE) {
throw ExportFormatIncompatible();
}
set_name ("Ogg Vorbis");
set_format_id (F_Ogg);
sample_formats.insert (SF_Vorbis);
@ -251,17 +261,6 @@ ExportFormatOggVorbis::ExportFormatOggVorbis ()
set_quality (Q_LossyCompression);
}
bool
ExportFormatOggVorbis::check_system_compatibility ()
{
SF_INFO sf_info;
sf_info.channels = 2;
sf_info.samplerate = SR_44_1;
sf_info.format = F_Ogg | SF_Vorbis;
return (sf_format_check (&sf_info) == SF_TRUE ? true : false);
}
bool
ExportFormatOggVorbis::set_compatibility_state (ExportFormatCompatibility const & compatibility)
{
@ -275,6 +274,16 @@ ExportFormatOggVorbis::set_compatibility_state (ExportFormatCompatibility const
ExportFormatFLAC::ExportFormatFLAC () :
HasSampleFormat (sample_formats)
{
/* Check system compatibility */
SF_INFO sf_info;
sf_info.channels = 2;
sf_info.samplerate = SR_44_1;
sf_info.format = F_FLAC | SF_16;
if (sf_format_check (&sf_info) != SF_TRUE) {
throw ExportFormatIncompatible();
}
set_name ("FLAC");
set_format_id (F_FLAC);
@ -295,17 +304,6 @@ ExportFormatFLAC::ExportFormatFLAC () :
set_quality (Q_LosslessCompression);
}
bool
ExportFormatFLAC::check_system_compatibility ()
{
SF_INFO sf_info;
sf_info.channels = 2;
sf_info.samplerate = SR_44_1;
sf_info.format = F_FLAC | SF_16;
return (sf_format_check (&sf_info) == SF_TRUE ? true : false);
}
bool
ExportFormatFLAC::set_compatibility_state (ExportFormatCompatibility const & compatibility)
{