class AudioBuffers;
class AudioAnalysis;
class Playlist;
+class AudioPoint;
/** @class AnalyseAudioJob
* @brief A job to analyse the audio of a film and make a note of its
std::string json_name () const;
void run ();
+ boost::shared_ptr<const Playlist> playlist () const {
+ return _playlist;
+ }
+
private:
void analyse (boost::shared_ptr<const AudioBuffers>);
_check_for_test_updates = false;
_maximum_j2k_bandwidth = 250000000;
_log_types = Log::TYPE_GENERAL | Log::TYPE_WARNING | Log::TYPE_ERROR;
+ _automatic_audio_analysis = false;
#ifdef DCPOMATIC_WINDOWS
_win32_console = false;
#endif
_allow_any_dcp_frame_rate = f.optional_bool_child ("AllowAnyDCPFrameRate");
_log_types = f.optional_number_child<int> ("LogTypes").get_value_or (Log::TYPE_GENERAL | Log::TYPE_WARNING | Log::TYPE_ERROR);
+ _automatic_audio_analysis = f.optional_bool_child ("AutomaticAudioAnalysis").get_value_or (false);
#ifdef DCPOMATIC_WINDOWS
_win32_console = f.optional_bool_child ("Win32Console").get_value_or (false);
#endif
root->add_child("MaximumJ2KBandwidth")->add_child_text (raw_convert<string> (_maximum_j2k_bandwidth));
root->add_child("AllowAnyDCPFrameRate")->add_child_text (_allow_any_dcp_frame_rate ? "1" : "0");
root->add_child("LogTypes")->add_child_text (raw_convert<string> (_log_types));
+ root->add_child("AutomaticAudioAnalysis")->add_child_text (_automatic_audio_analysis ? "1" : "0");
#ifdef DCPOMATIC_WINDOWS
root->add_child("Win32Console")->add_child_text (_win32_console ? "1" : "0");
#endif
return _log_types;
}
+ bool automatic_audio_analysis () const {
+ return _automatic_audio_analysis;
+ }
+
#ifdef DCPOMATIC_WINDOWS
bool win32_console () const {
return _win32_console;
maybe_set (_log_types, t);
}
+ void set_automatic_audio_analysis (bool a) {
+ maybe_set (_automatic_audio_analysis, a);
+ }
+
#ifdef DCPOMATIC_WINDOWS
void set_win32_console (bool c) {
maybe_set (_win32_console, c);
/** maximum allowed J2K bandwidth in bits per second */
int _maximum_j2k_bandwidth;
int _log_types;
+ bool _automatic_audio_analysis;
#ifdef DCPOMATIC_WINDOWS
bool _win32_console;
#endif
Film::~Film ()
{
- for (list<boost::signals2::connection>::const_iterator i = _job_connections.begin(); i != _job_connections.end(); ++i) {
- i->disconnect ();
+ BOOST_FOREACH (boost::signals2::connection& i, _job_connections) {
+ i.disconnect ();
+ }
+
+ BOOST_FOREACH (boost::signals2::connection& i, _audio_analysis_connections) {
+ i.disconnect ();
}
}
}
shared_ptr<Content> content = c.lock ();
- if (content) {
- add_content (content);
+ if (!content) {
+ return;
+ }
+
+ add_content (content);
+ if (Config::instance()->automatic_audio_analysis ()) {
+ shared_ptr<Playlist> playlist (new Playlist);
+ playlist->add (content);
+ boost::signals2::connection c;
+ JobManager::instance()->analyse_audio (
+ shared_from_this (), playlist, c, bind (&Film::audio_analysis_finished, this)
+ );
+ _audio_analysis_connections.push_back (c);
}
}
{
_playlist->remove (c);
}
+
+void
+Film::audio_analysis_finished ()
+{
+ /* XXX */
+}
void playlist_changed ();
void playlist_content_changed (boost::weak_ptr<Content>, int, bool frequent);
void maybe_add_content (boost::weak_ptr<Job>, boost::weak_ptr<Content>);
+ void audio_analysis_finished ();
/** Log to write to */
boost::shared_ptr<Log> _log;
boost::signals2::scoped_connection _playlist_changed_connection;
boost::signals2::scoped_connection _playlist_content_changed_connection;
std::list<boost::signals2::connection> _job_connections;
+ std::list<boost::signals2::connection> _audio_analysis_connections;
friend struct paths_test;
friend struct film_metadata_test;
using std::cout;
using boost::shared_ptr;
using boost::optional;
+using boost::function;
#define LOG_ERROR_NC(...) _film->log()->log (__VA_ARGS__, Log::TYPE_ERROR);
_pause_changed.notify_all ();
}
}
+
+void
+Job::when_finished (boost::signals2::connection& connection, function<void()> finished)
+{
+ boost::mutex::scoped_lock lm (_state_mutex);
+ if (_state == FINISHED_OK || _state == FINISHED_ERROR || _state == FINISHED_CANCELLED) {
+ finished ();
+ } else {
+ connection = Finished.connect (finished);
+ }
+}
+
return _film;
}
+ void when_finished (boost::signals2::connection& connection, boost::function<void()> finished);
+
boost::signals2::signal<void()> Progress;
/** Emitted from the UI thread when the job is finished */
boost::signals2::signal<void()> Finished;
/*
- Copyright (C) 2012 Carl Hetherington <cth@carlh.net>
+ Copyright (C) 2012-2015 Carl Hetherington <cth@carlh.net>
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
* @brief A simple scheduler for jobs.
*/
-#include <iostream>
-#include <boost/thread.hpp>
#include "job_manager.h"
#include "job.h"
#include "cross.h"
+#include "analyse_audio_job.h"
+#include "film.h"
+#include <boost/thread.hpp>
+#include <boost/foreach.hpp>
+#include <iostream>
using std::string;
using std::list;
using std::cout;
using boost::shared_ptr;
using boost::weak_ptr;
+using boost::function;
+using boost::dynamic_pointer_cast;
+using boost::optional;
JobManager* JobManager::_instance = 0;
JobManager::JobManager ()
: _terminate (false)
- , _last_active_jobs (false)
, _scheduler (0)
{
{
while (true) {
- bool active_jobs = false;
+ optional<string> active_job;
{
boost::mutex::scoped_lock lm (_mutex);
return;
}
- for (list<shared_ptr<Job> >::iterator i = _jobs.begin(); i != _jobs.end(); ++i) {
+ BOOST_FOREACH (shared_ptr<Job> i, _jobs) {
- if (!(*i)->finished ()) {
- active_jobs = true;
+ if (!i->finished ()) {
+ active_job = i->json_name ();
}
- if ((*i)->running ()) {
+ if (i->running ()) {
/* Something is already happening */
break;
}
- if ((*i)->is_new()) {
- (*i)->start ();
-
+ if (i->is_new()) {
+ i->start ();
/* Only start one job at once */
break;
}
}
}
- if (active_jobs != _last_active_jobs) {
- _last_active_jobs = active_jobs;
- emit (boost::bind (boost::ref (ActiveJobsChanged), active_jobs));
+ if (active_job != _last_active_job) {
+ _last_active_job = active_job;
+ emit (boost::bind (boost::ref (ActiveJobsChanged), active_job));
}
dcpomatic_sleep (1);
delete _instance;
_instance = 0;
}
+
+void
+JobManager::analyse_audio (
+ shared_ptr<const Film> film,
+ shared_ptr<const Playlist> playlist,
+ boost::signals2::connection& connection,
+ function<void()> ready
+ )
+{
+ shared_ptr<AnalyseAudioJob> job;
+
+ {
+ boost::mutex::scoped_lock lm (_mutex);
+
+ BOOST_FOREACH (shared_ptr<Job> i, _jobs) {
+ shared_ptr<AnalyseAudioJob> a = dynamic_pointer_cast<AnalyseAudioJob> (i);
+ if (a && film->audio_analysis_path (a->playlist ()) == film->audio_analysis_path (playlist)) {
+ i->when_finished (connection, ready);
+ return;
+ }
+ }
+
+ job.reset (new AnalyseAudioJob (film, playlist));
+ connection = job->Finished.connect (ready);
+ _jobs.push_back (job);
+ }
+
+ emit (boost::bind (boost::ref (JobAdded), weak_ptr<Job> (job)));
+}
/*
- Copyright (C) 2012 Carl Hetherington <cth@carlh.net>
+ Copyright (C) 2012-2015 Carl Hetherington <cth@carlh.net>
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
#include <list>
class Job;
+class Film;
+class Playlist;
+
extern void wait_for_jobs ();
/** @class JobManager
bool work_to_do () const;
bool errors () const;
+ void analyse_audio (
+ boost::shared_ptr<const Film> film,
+ boost::shared_ptr<const Playlist> playlist,
+ boost::signals2::connection& connection,
+ boost::function<void()> ready
+ );
+
boost::signals2::signal<void (boost::weak_ptr<Job>)> JobAdded;
- boost::signals2::signal<void (bool)> ActiveJobsChanged;
+ boost::signals2::signal<void (boost::optional<std::string>)> ActiveJobsChanged;
static JobManager* instance ();
static void drop ();
std::list<boost::shared_ptr<Job> > _jobs;
bool _terminate;
- bool _last_active_jobs;
+ boost::optional<std::string> _last_active_job;
boost::thread* _scheduler;
static JobManager* _instance;
#include "lib/signal_manager.h"
#include "lib/log.h"
#include "lib/job_manager.h"
-#include "lib/transcode_job.h"
#include "lib/exceptions.h"
#include "lib/cinema.h"
#include "lib/kdm.h"
{
list<shared_ptr<Job> > jobs = JobManager::instance()->get ();
list<shared_ptr<Job> >::iterator i = jobs.begin();
- while (i != jobs.end() && dynamic_pointer_cast<TranscodeJob> (*i) == 0) {
+ while (i != jobs.end() && (*i)->json_name() != "transcode") {
++i;
}
bool const dcp_creation = (i != jobs.end ()) && !(*i)->finished ();
shared_ptr<const Film> film = _film.lock ();
DCPOMATIC_ASSERT (film);
- boost::filesystem::path path = film->audio_analysis_path (_playlist);
-
+ boost::filesystem::path const path = film->audio_analysis_path (_playlist);
if (!boost::filesystem::exists (path)) {
_plot->set_analysis (shared_ptr<AudioAnalysis> ());
_analysis.reset ();
- shared_ptr<AnalyseAudioJob> job (new AnalyseAudioJob (film, _playlist));
- _analysis_finished_connection = job->Finished.connect (bind (&AudioDialog::analysis_finished, this));
- JobManager::instance()->add (job);
+ JobManager::instance()->analyse_audio (film, _playlist, _analysis_finished_connection, bind (&AudioDialog::analysis_finished, this));
return;
}
_analysis.reset (new AudioAnalysis (path));
} catch (xmlpp::exception& e) {
/* Probably an old-style analysis file: recreate it */
- shared_ptr<AnalyseAudioJob> job (new AnalyseAudioJob (film, _playlist));
- _analysis_finished_connection = job->Finished.connect (bind (&AudioDialog::analysis_finished, this));
- JobManager::instance()->add (job);
+ JobManager::instance()->analyse_audio (film, _playlist, _analysis_finished_connection, bind (&AudioDialog::analysis_finished, this));
return;
}
table->Add (_num_local_encoding_threads, wxGBPosition (r, 1));
++r;
+ _automatic_audio_analysis = new wxCheckBox (_panel, wxID_ANY, _("Automatically analyse content audio"));
+ table->Add (_automatic_audio_analysis, wxGBPosition (r, 0), wxGBSpan (1, 2));
+ ++r;
+
_check_for_updates = new wxCheckBox (_panel, wxID_ANY, _("Check for updates on startup"));
table->Add (_check_for_updates, wxGBPosition (r, 0), wxGBSpan (1, 2));
++r;
_num_local_encoding_threads->SetRange (1, 128);
_num_local_encoding_threads->Bind (wxEVT_COMMAND_SPINCTRL_UPDATED, boost::bind (&GeneralPage::num_local_encoding_threads_changed, this));
+ _automatic_audio_analysis->Bind (wxEVT_COMMAND_CHECKBOX_CLICKED, boost::bind (&GeneralPage::automatic_audio_analysis_changed, this));
_check_for_updates->Bind (wxEVT_COMMAND_CHECKBOX_CLICKED, boost::bind (&GeneralPage::check_for_updates_changed, this));
_check_for_test_updates->Bind (wxEVT_COMMAND_CHECKBOX_CLICKED, boost::bind (&GeneralPage::check_for_test_updates_changed, this));
setup_language_sensitivity ();
checked_set (_num_local_encoding_threads, config->num_local_encoding_threads ());
+ checked_set (_automatic_audio_analysis, config->automatic_audio_analysis ());
checked_set (_check_for_updates, config->check_for_updates ());
checked_set (_check_for_test_updates, config->check_for_test_updates ());
checked_set (_issuer, config->dcp_issuer ());
}
}
+ void automatic_audio_analysis_changed ()
+ {
+ Config::instance()->set_automatic_audio_analysis (_automatic_audio_analysis->GetValue ());
+ }
+
void check_for_updates_changed ()
{
Config::instance()->set_check_for_updates (_check_for_updates->GetValue ());
wxCheckBox* _set_language;
wxChoice* _language;
wxSpinCtrl* _num_local_encoding_threads;
+ wxCheckBox* _automatic_audio_analysis;
wxCheckBox* _check_for_updates;
wxCheckBox* _check_for_test_updates;
wxTextCtrl* _issuer;
#include <iostream>
using std::cout;
+using std::string;
using boost::shared_ptr;
+using boost::optional;
/** @param f Film to edit */
FilmEditor::FilmEditor (wxWindow* parent, FilmViewer* viewer)
}
void
-FilmEditor::active_jobs_changed (bool a)
+FilmEditor::active_jobs_changed (optional<string> j)
{
- set_general_sensitivity (!a);
+ set_general_sensitivity (!j || *j == "analyse_audio");
}
void film_content_changed (int);
void set_general_sensitivity (bool);
- void active_jobs_changed (bool);
+ void active_jobs_changed (boost::optional<std::string>);
wxNotebook* _main_notebook;
ContentPanel* _content_panel;
using boost::shared_ptr;
using boost::dynamic_pointer_cast;
using boost::weak_ptr;
+using boost::optional;
using dcp::Size;
FilmViewer::FilmViewer (wxWindow* p)
}
void
-FilmViewer::active_jobs_changed (bool a)
+FilmViewer::active_jobs_changed (optional<string> j)
{
- if (a) {
- list<shared_ptr<Job> > jobs = JobManager::instance()->get ();
- list<shared_ptr<Job> >::iterator i = jobs.begin ();
- while (i != jobs.end() && boost::dynamic_pointer_cast<ExamineContentJob> (*i) == 0) {
- ++i;
- }
-
- if (i == jobs.end() || (*i)->finished()) {
- /* no examine content job running, so we're ok to use the viewer */
- a = false;
- }
- }
-
- _slider->Enable (!a);
- _play_button->Enable (!a);
+ /* examine content is the only job which stops the viewer working */
+ bool const a = !j || *j != "examine_content";
+ _slider->Enable (a);
+ _play_button->Enable (a);
}
void
void timer ();
void calculate_sizes ();
void check_play_state ();
- void active_jobs_changed (bool);
+ void active_jobs_changed (boost::optional<std::string>);
void back_clicked ();
void forward_clicked ();
void player_changed (bool);