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 from_zero true to analyse audio from time 0 in the playlist, otherwise begin at Playlist::start */
51 AnalyseAudioJob::AnalyseAudioJob (shared_ptr<const Film> film, shared_ptr<const Playlist> playlist, bool from_zero)
53 , _analyser (film, playlist, from_zero, boost::bind(&Job::set_progress, this, _1, false))
54 , _playlist (playlist)
55 , _path (film->audio_analysis_path(playlist))
57 LOG_DEBUG_AUDIO_ANALYSIS_NC("AnalyseAudioJob::AnalyseAudioJob");
61 AnalyseAudioJob::~AnalyseAudioJob ()
68 AnalyseAudioJob::name () const
70 return _("Analysing audio");
75 AnalyseAudioJob::json_name () const
77 return N_("analyse_audio");
82 AnalyseAudioJob::run ()
84 LOG_DEBUG_AUDIO_ANALYSIS_NC("AnalyseAudioJob::run");
86 auto player = make_shared<Player>(_film, _playlist);
87 player->set_ignore_video ();
88 player->set_ignore_text ();
90 player->set_play_referenced ();
91 player->Audio.connect (bind(&AudioAnalyser::analyse, &_analyser, _1, _2));
93 bool has_any_audio = false;
94 for (auto c: _playlist->content()) {
101 player->seek (_analyser.start(), true);
102 while (!player->pass ()) {}
105 LOG_DEBUG_AUDIO_ANALYSIS_NC("Loop complete");
108 auto analysis = _analyser.get();
109 analysis.write (_path);
111 LOG_DEBUG_AUDIO_ANALYSIS_NC("Job finished");
113 set_state (FINISHED_OK);