2 Copyright (C) 2012-2021 Carl Hetherington <cth@carlh.net>
4 This file is part of DCP-o-matic.
6 DCP-o-matic is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 DCP-o-matic is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>.
22 #include "analyse_audio_job.h"
23 #include "audio_analysis.h"
24 #include "compose.hpp"
25 #include "dcpomatic_log.h"
37 using std::dynamic_pointer_cast;
38 using std::make_shared;
41 using std::shared_ptr;
44 using namespace dcpomatic;
45 #if BOOST_VERSION >= 106100
46 using namespace boost::placeholders;
50 /** @param whole_film true to analyse the whole film' audio (i.e. start from time 0 and use processors), false
51 * to analyse just the single piece of content in the playlist (i.e. start from Playlist::start() and do not
54 AnalyseAudioJob::AnalyseAudioJob (shared_ptr<const Film> film, shared_ptr<const Playlist> playlist, bool whole_film)
56 , _analyser(film, playlist, whole_film, boost::bind(&Job::set_progress, this, _1, false))
57 , _playlist (playlist)
58 , _path (film->audio_analysis_path(playlist))
59 , _whole_film(whole_film)
61 LOG_DEBUG_AUDIO_ANALYSIS_NC("AnalyseAudioJob::AnalyseAudioJob");
65 AnalyseAudioJob::~AnalyseAudioJob ()
72 AnalyseAudioJob::name () const
74 return _("Analysing audio");
79 AnalyseAudioJob::json_name () const
81 return N_("analyse_audio");
86 AnalyseAudioJob::run ()
88 LOG_DEBUG_AUDIO_ANALYSIS_NC("AnalyseAudioJob::run");
90 auto player = make_shared<Player>(_film, _playlist);
91 player->set_ignore_video ();
92 player->set_ignore_text ();
94 player->set_play_referenced ();
95 player->Audio.connect (bind(&AudioAnalyser::analyse, &_analyser, _1, _2));
97 player->set_disable_audio_processor();
100 bool has_any_audio = false;
101 for (auto c: _playlist->content()) {
103 has_any_audio = true;
108 player->seek (_analyser.start(), true);
109 while (!player->pass ()) {}
112 LOG_DEBUG_AUDIO_ANALYSIS_NC("Loop complete");
115 auto analysis = _analyser.get();
116 analysis.write (_path);
118 LOG_DEBUG_AUDIO_ANALYSIS_NC("Job finished");
120 set_state (FINISHED_OK);