13
0

[Summary] Added export cleanup

[Reviewed by] Andriy Mishyn
This commit is contained in:
GZharun 2015-01-15 13:47:06 +02:00 committed by Paul Davis
parent f9aeb659ee
commit ae8c494c02
3 changed files with 125 additions and 5 deletions

View File

@ -68,17 +68,20 @@ class LIBARDOUR_API ExportGraphBuilder
unsigned get_normalize_cycle_count() const;
void reset ();
void cleanup (bool remove_out_files = false);
void set_current_timespan (boost::shared_ptr<ExportTimespan> span);
void add_config (FileSpec const & config);
private:
void add_split_config (FileSpec const & config);
class Encoder {
public:
template <typename T> boost::shared_ptr<AudioGrapher::Sink<T> > init (FileSpec const & new_config);
void add_child (FileSpec const & new_config);
void remove_children ();
void destroy_writer (bool delete_out_file);
bool operator== (FileSpec const & other_config) const;
static int get_real_format (FileSpec const & config);
@ -95,6 +98,8 @@ class LIBARDOUR_API ExportGraphBuilder
std::list<ExportFilenamePtr> filenames;
PBD::ScopedConnection copy_files_connection;
std::string writer_filename;
// Only one of these should be available at a time
FloatWriterPtr float_writer;
IntWriterPtr int_writer;
@ -108,6 +113,7 @@ class LIBARDOUR_API ExportGraphBuilder
SFC (ExportGraphBuilder &, FileSpec const & new_config, framecnt_t max_frames);
FloatSinkPtr sink ();
void add_child (FileSpec const & new_config);
void remove_children (bool remove_out_files);
bool operator== (FileSpec const & other_config) const;
private:
@ -130,6 +136,7 @@ class LIBARDOUR_API ExportGraphBuilder
Normalizer (ExportGraphBuilder & parent, FileSpec const & new_config, framecnt_t max_frames);
FloatSinkPtr sink ();
void add_child (FileSpec const & new_config);
void remove_children (bool remove_out_files);
bool operator== (FileSpec const & other_config) const;
unsigned get_normalize_cycle_count() const;
@ -167,6 +174,8 @@ class LIBARDOUR_API ExportGraphBuilder
SRC (ExportGraphBuilder & parent, FileSpec const & new_config, framecnt_t max_frames);
FloatSinkPtr sink ();
void add_child (FileSpec const & new_config);
void remove_children (bool remove_out_files);
bool operator== (FileSpec const & other_config) const;
private:
@ -189,6 +198,7 @@ class LIBARDOUR_API ExportGraphBuilder
SilenceHandler (ExportGraphBuilder & parent, FileSpec const & new_config, framecnt_t max_frames);
FloatSinkPtr sink ();
void add_child (FileSpec const & new_config);
void remove_children (bool remove_out_files);
bool operator== (FileSpec const & other_config) const;
private:
@ -206,6 +216,7 @@ class LIBARDOUR_API ExportGraphBuilder
public:
ChannelConfig (ExportGraphBuilder & parent, FileSpec const & new_config, ChannelMap & channel_map);
void add_child (FileSpec const & new_config);
void remove_children (bool remove_out_files);
bool operator== (FileSpec const & other_config) const;
private:

View File

@ -112,6 +112,17 @@ ExportGraphBuilder::reset ()
normalizers.clear ();
}
void
ExportGraphBuilder::cleanup (bool remove_out_files/*=false*/)
{
ChannelConfigList::iterator iter = channel_configs.begin();
while (iter != channel_configs.end() ) {
iter->remove_children(remove_out_files);
iter = channel_configs.erase(iter);
}
}
void
ExportGraphBuilder::set_current_timespan (boost::shared_ptr<ExportTimespan> span)
{
@ -175,7 +186,7 @@ ExportGraphBuilder::add_split_config (FileSpec const & config)
// No duplicate channel config found, create new one
channel_configs.push_back (new ChannelConfig (*this, config, channels));
}
/* Encoder */
template <>
@ -210,6 +221,33 @@ ExportGraphBuilder::Encoder::add_child (FileSpec const & new_config)
{
filenames.push_back (new_config.filename);
}
void
ExportGraphBuilder::Encoder::destroy_writer (bool delete_out_file)
{
if (delete_out_file ) {
if (float_writer) {
float_writer->close ();
}
if (int_writer) {
int_writer->close ();
}
if (short_writer) {
short_writer->close ();
}
if (std::remove(writer_filename.c_str() ) != 0) {
std::cout << "Encoder::destroy_writer () : Error removing file: " << strerror(errno) << std::endl;
}
}
float_writer.reset ();
int_writer.reset ();
short_writer.reset ();
}
bool
ExportGraphBuilder::Encoder::operator== (FileSpec const & other_config) const
@ -231,9 +269,9 @@ ExportGraphBuilder::Encoder::init_writer (boost::shared_ptr<AudioGrapher::Sndfil
unsigned channels = config.channel_config->get_n_chans();
int format = get_real_format (config);
config.filename->set_channel_config(config.channel_config);
string filename = config.filename->get_path (config.format);
writer_filename = config.filename->get_path (config.format);
writer.reset (new AudioGrapher::SndfileWriter<T> (filename, format, channels, config.format->sample_rate(), config.broadcast_info));
writer.reset (new AudioGrapher::SndfileWriter<T> (writer_filename, format, channels, config.format->sample_rate(), config.broadcast_info));
writer->FileWritten.connect_same_thread (copy_files_connection, boost::bind (&ExportGraphBuilder::Encoder::copy_files, this, _1));
}
@ -306,6 +344,20 @@ ExportGraphBuilder::SFC::add_child (FileSpec const & new_config)
}
}
void
ExportGraphBuilder::SFC::remove_children (bool remove_out_files)
{
boost::ptr_list<Encoder>::iterator iter = children.begin ();
while (iter != children.end() ) {
if (remove_out_files) {
iter->destroy_writer(remove_out_files);
}
iter = children.erase (iter);
}
}
bool
ExportGraphBuilder::SFC::operator== (FileSpec const & other_config) const
{
@ -365,6 +417,17 @@ ExportGraphBuilder::Normalizer::add_child (FileSpec const & new_config)
threader->add_output (children.back().sink());
}
void
ExportGraphBuilder::Normalizer::remove_children (bool remove_out_files)
{
boost::ptr_list<SFC>::iterator iter = children.begin ();
while (iter != children.end() ) {
iter->remove_children (remove_out_files);
iter = children.erase (iter);
}
}
bool
ExportGraphBuilder::Normalizer::operator== (FileSpec const & other_config) const
{
@ -424,6 +487,27 @@ ExportGraphBuilder::SRC::add_child (FileSpec const & new_config)
add_child_to_list (new_config, children);
}
}
void
ExportGraphBuilder::SRC::remove_children (bool remove_out_files)
{
boost::ptr_list<SFC>::iterator sfc_iter = children.begin();
while (sfc_iter != children.end() ) {
converter->remove_output (sfc_iter->sink() );
sfc_iter->remove_children (remove_out_files);
sfc_iter = children.erase (sfc_iter);
}
boost::ptr_list<Normalizer>::iterator norm_iter = normalized_children.begin();
while (norm_iter != normalized_children.end() ) {
converter->remove_output (norm_iter->sink() );
norm_iter->remove_children (remove_out_files);
norm_iter = normalized_children.erase (norm_iter);
}
}
template<typename T>
void
@ -486,6 +570,18 @@ ExportGraphBuilder::SilenceHandler::add_child (FileSpec const & new_config)
children.push_back (new SRC (parent, new_config, max_frames_in));
silence_trimmer->add_output (children.back().sink());
}
void
ExportGraphBuilder::SilenceHandler::remove_children (bool remove_out_files)
{
boost::ptr_list<SRC>::iterator iter = children.begin();
while (iter != children.end() ) {
silence_trimmer->remove_output (iter->sink() );
iter->remove_children (remove_out_files);
iter = children.erase (iter);
}
}
bool
ExportGraphBuilder::SilenceHandler::operator== (FileSpec const & other_config) const
@ -551,6 +647,19 @@ ExportGraphBuilder::ChannelConfig::add_child (FileSpec const & new_config)
children.push_back (new SilenceHandler (parent, new_config, max_frames_out));
chunker->add_output (children.back().sink ());
}
void
ExportGraphBuilder::ChannelConfig::remove_children (bool remove_out_files)
{
boost::ptr_list<SilenceHandler>::iterator iter = children.begin();
while(iter != children.end() ) {
chunker->remove_output (iter->sink ());
iter->remove_children (remove_out_files);
iter = children.erase(iter);
}
}
bool
ExportGraphBuilder::ChannelConfig::operator== (FileSpec const & other_config) const

View File

@ -118,7 +118,7 @@ ExportHandler::ExportHandler (Session & session)
ExportHandler::~ExportHandler ()
{
// TODO remove files that were written but not finished
graph_builder->cleanup (export_status->aborted () );
}
/** Add an export to the `to-do' list */