From 04bd447fd8960625bda5081cbac235b848d7631f Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Wed, 13 May 2015 22:28:50 +0100 Subject: Rename UISignaller -> SignalManager. --- src/lib/content.cc | 1 - src/lib/job.cc | 1 - src/lib/job_manager.cc | 1 - src/lib/server_finder.cc | 1 - src/lib/signal_manager.cc | 23 ++++++++++++ src/lib/signal_manager.h | 90 +++++++++++++++++++++++++++++++++++++++++++++++ src/lib/signaller.h | 6 ++-- src/lib/ui_signaller.cc | 24 ------------- src/lib/ui_signaller.h | 90 ----------------------------------------------- src/lib/update.cc | 1 - src/lib/wscript | 2 +- 11 files changed, 117 insertions(+), 123 deletions(-) create mode 100644 src/lib/signal_manager.cc create mode 100644 src/lib/signal_manager.h delete mode 100644 src/lib/ui_signaller.cc delete mode 100644 src/lib/ui_signaller.h (limited to 'src/lib') diff --git a/src/lib/content.cc b/src/lib/content.cc index b00ea3e57..b9e8367e1 100644 --- a/src/lib/content.cc +++ b/src/lib/content.cc @@ -24,7 +24,6 @@ #include "content.h" #include "util.h" #include "content_factory.h" -#include "ui_signaller.h" #include "exceptions.h" #include "film.h" #include "safe_stringstream.h" diff --git a/src/lib/job.cc b/src/lib/job.cc index f28146632..c4d93ddc1 100644 --- a/src/lib/job.cc +++ b/src/lib/job.cc @@ -27,7 +27,6 @@ #include "job.h" #include "util.h" #include "cross.h" -#include "ui_signaller.h" #include "exceptions.h" #include "film.h" #include "log.h" diff --git a/src/lib/job_manager.cc b/src/lib/job_manager.cc index 63db662d0..b5b64a77e 100644 --- a/src/lib/job_manager.cc +++ b/src/lib/job_manager.cc @@ -26,7 +26,6 @@ #include "job_manager.h" #include "job.h" #include "cross.h" -#include "ui_signaller.h" using std::string; using std::list; diff --git a/src/lib/server_finder.cc b/src/lib/server_finder.cc index 72a9a4ef5..b4b400b52 100644 --- a/src/lib/server_finder.cc +++ b/src/lib/server_finder.cc @@ -22,7 +22,6 @@ #include "util.h" #include "config.h" #include "cross.h" -#include "ui_signaller.h" #include "dcpomatic_socket.h" #include "raw_convert.h" #include diff --git a/src/lib/signal_manager.cc b/src/lib/signal_manager.cc new file mode 100644 index 000000000..7c2b3e11a --- /dev/null +++ b/src/lib/signal_manager.cc @@ -0,0 +1,23 @@ +/* + Copyright (C) 2012-2015 Carl Hetherington + + 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 + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + +#include "signal_manager.h" + +/** Global SignalManager instance */ +SignalManager* signal_manager = 0; diff --git a/src/lib/signal_manager.h b/src/lib/signal_manager.h new file mode 100644 index 000000000..ae4306e30 --- /dev/null +++ b/src/lib/signal_manager.h @@ -0,0 +1,90 @@ +/* + Copyright (C) 2012-2015 Carl Hetherington + + 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 + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + +#ifndef DCPOMATIC_SIGNAL_MANAGER_H +#define DCPOMATIC_SIGNAL_MANAGER_H + +#include +#include +#include + +class Signaller; + +/** A class to allow signals to be emitted from non-UI threads and handled + * by a UI thread. + */ +class SignalManager : public boost::noncopyable +{ +public: + /** Create a SignalManager. Must be called from the UI thread */ + SignalManager () + : _work (_service) + { + _ui_thread = boost::this_thread::get_id (); + } + + /* Do something next time the UI is idle */ + template + void when_idle (T f) { + _service.post (f); + } + + /** Call this in the UI when it is idle */ + size_t ui_idle () { + /* This executes any functors that have been post()ed to _service */ + return _service.poll (); + } + + /** This should wake the UI and make it call ui_idle() */ + virtual void wake_ui () { + /* This is only a sensible implementation when there is no GUI */ + ui_idle (); + } + +private: + /** Emit a signal from any thread whose handlers will be called in the UI + * thread. Use something like: + * + * ui_signaller->emit (boost::bind (boost::ref (SomeSignal), parameter)); + */ + template + void emit (T f) { + if (boost::this_thread::get_id() == _ui_thread) { + /* already in the UI thread */ + f (); + } else { + /* non-UI thread; post to the service and wake up the UI */ + _service.post (f); + wake_ui (); + } + } + + friend class Signaller; + + /** A io_service which is used as the conduit for messages */ + boost::asio::io_service _service; + /** Object required to keep io_service from stopping when it has nothing to do */ + boost::asio::io_service::work _work; + /** The UI thread's ID */ + boost::thread::id _ui_thread; +}; + +extern SignalManager* signal_manager; + +#endif diff --git a/src/lib/signaller.h b/src/lib/signaller.h index 408cfcf5b..4ef9b38b3 100644 --- a/src/lib/signaller.h +++ b/src/lib/signaller.h @@ -20,7 +20,7 @@ #ifndef DCPOMATIC_SIGNALLER_H #define DCPOMATIC_SIGNALLER_H -#include "ui_signaller.h" +#include "signal_manager.h" #include #include @@ -100,8 +100,8 @@ public: void emit (T signal) { Wrapper* w = new Wrapper (signal); - if (ui_signaller) { - ui_signaller->emit (boost::bind (&Wrapper::signal, w)); + if (signal_manager) { + signal_manager->emit (boost::bind (&Wrapper::signal, w)); } boost::mutex::scoped_lock lm (_mutex); diff --git a/src/lib/ui_signaller.cc b/src/lib/ui_signaller.cc deleted file mode 100644 index 4cb34da51..000000000 --- a/src/lib/ui_signaller.cc +++ /dev/null @@ -1,24 +0,0 @@ -/* - Copyright (C) 2012 Carl Hetherington - - 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 - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - -*/ - -#include "ui_signaller.h" - -/** Global UISignaller instance */ -UISignaller* ui_signaller = 0; - diff --git a/src/lib/ui_signaller.h b/src/lib/ui_signaller.h deleted file mode 100644 index 9d4495cd1..000000000 --- a/src/lib/ui_signaller.h +++ /dev/null @@ -1,90 +0,0 @@ -/* - Copyright (C) 2012 Carl Hetherington - - 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 - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - -*/ - -#ifndef DCPOMATIC_UI_SIGNALLER_H -#define DCPOMATIC_UI_SIGNALLER_H - -#include -#include -#include - -class Signaller; - -/** A class to allow signals to be emitted from non-UI threads and handled - * by a UI thread. - */ -class UISignaller : public boost::noncopyable -{ -public: - /** Create a UISignaller. Must be called from the UI thread */ - UISignaller () - : _work (_service) - { - _ui_thread = boost::this_thread::get_id (); - } - - /* Do something next time the UI is idle */ - template - void when_idle (T f) { - _service.post (f); - } - - /** Call this in the UI when it is idle */ - size_t ui_idle () { - /* This executes any functors that have been post()ed to _service */ - return _service.poll (); - } - - /** This should wake the UI and make it call ui_idle() */ - virtual void wake_ui () { - /* This is only a sensible implementation when there is no GUI... */ - ui_idle (); - } - -private: - /** Emit a signal from any thread whose handlers will be called in the UI - * thread. Use something like: - * - * ui_signaller->emit (boost::bind (boost::ref (SomeSignal), parameter)); - */ - template - void emit (T f) { - if (boost::this_thread::get_id() == _ui_thread) { - /* already in the UI thread */ - f (); - } else { - /* non-UI thread; post to the service and wake up the UI */ - _service.post (f); - wake_ui (); - } - } - - friend class Signaller; - - /** A io_service which is used as the conduit for messages */ - boost::asio::io_service _service; - /** Object required to keep io_service from stopping when it has nothing to do */ - boost::asio::io_service::work _work; - /** The UI thread's ID */ - boost::thread::id _ui_thread; -}; - -extern UISignaller* ui_signaller; - -#endif diff --git a/src/lib/update.cc b/src/lib/update.cc index 26944ecc3..f433ff991 100644 --- a/src/lib/update.cc +++ b/src/lib/update.cc @@ -19,7 +19,6 @@ #include "update.h" #include "version.h" -#include "ui_signaller.h" #include "safe_stringstream.h" #include "config.h" #include "util.h" diff --git a/src/lib/wscript b/src/lib/wscript index 68897a4c4..5956c73d6 100644 --- a/src/lib/wscript +++ b/src/lib/wscript @@ -109,7 +109,7 @@ sources = """ transcode_job.cc transcoder.cc types.cc - ui_signaller.cc + signal_manager.cc update.cc upmixer_a.cc util.cc -- cgit v1.2.3 From 1504f8460d6c438525489ee22eb9a4b437cb449e Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Wed, 13 May 2015 22:59:47 +0100 Subject: Port XML audio analysis code from master. --- src/lib/audio_analysis.cc | 96 ++++++++++++++++------------------------------- src/lib/audio_analysis.h | 25 +++--------- src/wx/audio_dialog.cc | 9 ++++- 3 files changed, 46 insertions(+), 84 deletions(-) (limited to 'src/lib') diff --git a/src/lib/audio_analysis.cc b/src/lib/audio_analysis.cc index ee34b0d80..73422a9be 100644 --- a/src/lib/audio_analysis.cc +++ b/src/lib/audio_analysis.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2012 Carl Hetherington + Copyright (C) 2012-2015 Carl Hetherington 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 @@ -18,15 +18,17 @@ */ #include "audio_analysis.h" -#include "dcpomatic_assert.h" #include "cross.h" +#include "util.h" +#include "raw_convert.h" +#include #include +#include #include -#include #include -#include #include #include +#include using std::ostream; using std::istream; @@ -35,6 +37,7 @@ using std::vector; using std::cout; using std::max; using std::list; +using boost::shared_ptr; AudioPoint::AudioPoint () { @@ -43,14 +46,10 @@ AudioPoint::AudioPoint () } } -AudioPoint::AudioPoint (FILE* f) +AudioPoint::AudioPoint (cxml::ConstNodePtr node) { - for (int i = 0; i < COUNT; ++i) { - int n = fscanf (f, "%f", &_data[i]); - if (n != 1) { - _data[i] = 0; - } - } + _data[PEAK] = node->number_child ("Peak"); + _data[RMS] = node->number_child ("RMS"); } AudioPoint::AudioPoint (AudioPoint const & other) @@ -75,14 +74,12 @@ AudioPoint::operator= (AudioPoint const & other) } void -AudioPoint::write (FILE* f) const +AudioPoint::as_xml (xmlpp::Element* parent) const { - for (int i = 0; i < COUNT; ++i) { - fprintf (f, "%f\n", _data[i]); - } + parent->add_child ("Peak")->add_child_text (raw_convert (_data[PEAK])); + parent->add_child ("RMS")->add_child_text (raw_convert (_data[RMS])); } - AudioAnalysis::AudioAnalysis (int channels) { _data.resize (channels); @@ -90,44 +87,21 @@ AudioAnalysis::AudioAnalysis (int channels) AudioAnalysis::AudioAnalysis (boost::filesystem::path filename) { - FILE* f = fopen_boost (filename, "r"); - if (!f) { - throw OpenFileError (filename); - } + cxml::Document f ("AudioAnalysis"); + f.read_file (filename); - int channels = 0; - fscanf (f, "%d", &channels); - _data.resize (channels); + BOOST_FOREACH (cxml::NodePtr i, f.node_children ("Channel")) { + vector channel; - for (int i = 0; i < channels; ++i) { - int points; - fscanf (f, "%d", &points); - if (feof (f)) { - fclose (f); - return; - } - - for (int j = 0; j < points; ++j) { - _data[i].push_back (AudioPoint (f)); - if (feof (f)) { - fclose (f); - return; - } + BOOST_FOREACH (cxml::NodePtr j, i->node_children ("Point")) { + channel.push_back (AudioPoint (j)); } - } - /* These may not exist in old analysis files, so be careful - about reading them. - */ - - float peak; - DCPTime::Type peak_time; - if (fscanf (f, "%f%" SCNd64, &peak, &peak_time) == 2) { - _peak = peak; - _peak_time = DCPTime (peak_time); + _data.push_back (channel); } - - fclose (f); + + _peak = f.number_child ("Peak"); + _peak_time = DCPTime (f.number_child ("PeakTime")); } void @@ -160,26 +134,20 @@ AudioAnalysis::points (int c) const void AudioAnalysis::write (boost::filesystem::path filename) { - boost::filesystem::path tmp = filename; - tmp.replace_extension (".tmp"); - - FILE* f = fopen_boost (tmp, "w"); - if (!f) { - throw OpenFileError (tmp); - } + shared_ptr doc (new xmlpp::Document); + xmlpp::Element* root = doc->create_root_node ("AudioAnalysis"); - fprintf (f, "%ld\n", _data.size ()); - for (vector >::iterator i = _data.begin(); i != _data.end(); ++i) { - fprintf (f, "%ld\n", i->size ()); - for (vector::iterator j = i->begin(); j != i->end(); ++j) { - j->write (f); + BOOST_FOREACH (vector& i, _data) { + xmlpp::Element* channel = root->add_child ("Channel"); + BOOST_FOREACH (AudioPoint& j, i) { + j.as_xml (channel->add_child ("Point")); } } if (_peak) { - fprintf (f, "%f%" PRId64, _peak.get (), _peak_time.get().get ()); + root->add_child("Peak")->add_child_text (raw_convert (_peak.get ())); + root->add_child("PeakTime")->add_child_text (raw_convert (_peak_time.get().get ())); } - fclose (f); - boost::filesystem::rename (tmp, filename); + doc->write_to_file_formatted (filename.string ()); } diff --git a/src/lib/audio_analysis.h b/src/lib/audio_analysis.h index 1872c57ad..9387ec896 100644 --- a/src/lib/audio_analysis.h +++ b/src/lib/audio_analysis.h @@ -17,21 +17,16 @@ */ -/** @file src/lib/audio_analysis.h - * @brief AudioAnalysis and AudioPoint classes. - */ - #ifndef DCPOMATIC_AUDIO_ANALYSIS_H #define DCPOMATIC_AUDIO_ANALYSIS_H -#include "types.h" +#include +#include #include #include -#include +#include +#include "types.h" -/** @class AudioPoint - * @brief A single point of an audio analysis for one portion of one channel. - */ class AudioPoint { public: @@ -42,11 +37,11 @@ public: }; AudioPoint (); - AudioPoint (FILE *); + AudioPoint (cxml::ConstNodePtr node); AudioPoint (AudioPoint const &); AudioPoint& operator= (AudioPoint const &); - void write (FILE *) const; + void as_xml (xmlpp::Element *) const; float& operator[] (int t) { return _data[t]; @@ -56,14 +51,6 @@ private: float _data[COUNT]; }; -/** @class AudioAnalysis - * @brief An analysis of the audio data in a piece of AudioContent. - * - * This is a set of AudioPoints for each channel. The AudioPoints - * each represent some measurement of the audio over a portion of the - * content. For example each AudioPoint may give the RMS level of - * a 1-minute portion of the audio. - */ class AudioAnalysis : public boost::noncopyable { public: diff --git a/src/wx/audio_dialog.cc b/src/wx/audio_dialog.cc index 286e7f49d..fcae9c30f 100644 --- a/src/wx/audio_dialog.cc +++ b/src/wx/audio_dialog.cc @@ -124,8 +124,15 @@ AudioDialog::try_to_load_analysis () _analysis_finished_connection = _content->analyse_audio (bind (&AudioDialog::analysis_finished, this)); return; } + + try { + _analysis.reset (new AudioAnalysis (_content->audio_analysis_path ())); + } catch (xmlpp::exception& e) { + /* Probably an old-style analysis file: recreate it */ + _analysis_finished_connection = _content->analyse_audio (bind (&AudioDialog::analysis_finished, this)); + return; + } - _analysis.reset (new AudioAnalysis (_content->audio_analysis_path ())); _plot->set_analysis (_analysis); setup_peak_time (); -- cgit v1.2.3 From 419c025709132e21ce948c4a6051a323f06ee61d Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Wed, 13 May 2015 23:38:49 +0100 Subject: Token effort toward non-bitmap subtitles from FFmpegDecoder. --- src/lib/ffmpeg_decoder.cc | 53 ++++++++++++++++++++++++++++++----------------- src/lib/ffmpeg_decoder.h | 2 ++ 2 files changed, 36 insertions(+), 19 deletions(-) (limited to 'src/lib') diff --git a/src/lib/ffmpeg_decoder.cc b/src/lib/ffmpeg_decoder.cc index 6122a547e..35e15a331 100644 --- a/src/lib/ffmpeg_decoder.cc +++ b/src/lib/ffmpeg_decoder.cc @@ -453,15 +453,43 @@ FFmpegDecoder::decode_subtitle_packet () AVSubtitleRect const * rect = sub.rects[0]; - if (rect->type != SUBTITLE_BITMAP) { - throw DecodeError (_("non-bitmap subtitles not yet supported")); + switch (rect->type) { + case SUBTITLE_NONE: + break; + case SUBTITLE_BITMAP: + decode_bitmap_subtitle (rect, period); + break; + case SUBTITLE_TEXT: + cout << "XXX: SUBTITLE_TEXT " << rect->text << "\n"; + break; + case SUBTITLE_ASS: + cout << "XXX: SUBTITLE_ASS " << rect->ass << "\n"; + break; } + + avsubtitle_free (&sub); +} + +list +FFmpegDecoder::image_subtitles_during (ContentTimePeriod p, bool starting) const +{ + return _ffmpeg_content->subtitles_during (p, starting); +} +list +FFmpegDecoder::text_subtitles_during (ContentTimePeriod, bool) const +{ + return list (); +} + +void +FFmpegDecoder::decode_bitmap_subtitle (AVSubtitleRect const * rect, ContentTimePeriod period) +{ /* Note RGBA is expressed little-endian, so the first byte in the word is R, second G, third B, fourth A. */ shared_ptr image (new Image (PIX_FMT_RGBA, dcp::Size (rect->w, rect->h), true)); - + /* Start of the first line in the subtitle */ uint8_t* sub_p = rect->pict.data[0]; /* sub_p looks up into a BGRA palette which is here @@ -470,7 +498,7 @@ FFmpegDecoder::decode_subtitle_packet () uint32_t const * palette = (uint32_t *) rect->pict.data[1]; /* Start of the output data */ uint32_t* out_p = (uint32_t *) image->data()[0]; - + for (int y = 0; y < rect->h; ++y) { uint8_t* sub_line_p = sub_p; uint32_t* out_line_p = out_p; @@ -481,7 +509,7 @@ FFmpegDecoder::decode_subtitle_packet () sub_p += rect->pict.linesize[0]; out_p += image->stride()[0] / sizeof (uint32_t); } - + dcp::Size const vs = _ffmpeg_content->video_size (); dcpomatic::Rect const scaled_rect ( static_cast (rect->x) / vs.width, @@ -489,20 +517,7 @@ FFmpegDecoder::decode_subtitle_packet () static_cast (rect->w) / vs.width, static_cast (rect->h) / vs.height ); - - image_subtitle (ContentTimePeriod (period.from, period.to), image, scaled_rect); - avsubtitle_free (&sub); -} - -list -FFmpegDecoder::image_subtitles_during (ContentTimePeriod p, bool starting) const -{ - return _ffmpeg_content->subtitles_during (p, starting); + image_subtitle (period, image, scaled_rect); } -list -FFmpegDecoder::text_subtitles_during (ContentTimePeriod, bool) const -{ - return list (); -} diff --git a/src/lib/ffmpeg_decoder.h b/src/lib/ffmpeg_decoder.h index 616fa88dd..6f027ce1c 100644 --- a/src/lib/ffmpeg_decoder.h +++ b/src/lib/ffmpeg_decoder.h @@ -64,6 +64,8 @@ private: void decode_audio_packet (); void decode_subtitle_packet (); + void decode_bitmap_subtitle (AVSubtitleRect const * rect, ContentTimePeriod period); + void maybe_add_subtitle (); boost::shared_ptr deinterleave_audio (uint8_t** data, int size); -- cgit v1.2.3