diff options
| author | Carl Hetherington <cth@carlh.net> | 2020-03-16 00:44:31 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2020-03-16 00:46:34 +0100 |
| commit | 19760ad4cf6d348416444e515b5e709be565f81e (patch) | |
| tree | 55c889deb559ce325fd436bdfb8b97170a15e14c /src/wx | |
| parent | 3e3e8433842820ce6380e8f5c1917ae1a28e2e57 (diff) | |
Move stress testing code into a separate class and always build it.
Fix stress script generation to always reload a DCP rather than
expecting it to be available after it has finished playback.
Diffstat (limited to 'src/wx')
| -rw-r--r-- | src/wx/controls.cc | 2 | ||||
| -rw-r--r-- | src/wx/controls.h | 4 | ||||
| -rw-r--r-- | src/wx/player_stress_tester.cc | 161 | ||||
| -rw-r--r-- | src/wx/player_stress_tester.h | 72 | ||||
| -rw-r--r-- | src/wx/playlist_controls.cc | 3 | ||||
| -rw-r--r-- | src/wx/playlist_controls.h | 4 | ||||
| -rw-r--r-- | src/wx/standard_controls.cc | 2 | ||||
| -rw-r--r-- | src/wx/standard_controls.h | 2 | ||||
| -rw-r--r-- | src/wx/wscript | 1 |
9 files changed, 236 insertions, 15 deletions
diff --git a/src/wx/controls.cc b/src/wx/controls.cc index 27139f1f5..92103637c 100644 --- a/src/wx/controls.cc +++ b/src/wx/controls.cc @@ -407,7 +407,6 @@ Controls::film_change (ChangeType type, Film::Property p) } } -#ifdef DCPOMATIC_PLAYER_STRESS_TEST void Controls::seek (int slider) { @@ -415,4 +414,3 @@ Controls::seek (int slider) slider_moved (false); slider_released (); } -#endif diff --git a/src/wx/controls.h b/src/wx/controls.h index c11d6e8e3..b9c4604b6 100644 --- a/src/wx/controls.h +++ b/src/wx/controls.h @@ -52,11 +52,11 @@ public: virtual void log (wxString) {} virtual void set_film (boost::shared_ptr<Film> film); -#ifdef DCPOMATIC_PLAYER_STRESS_TEST + virtual void play () {}; virtual void stop () {}; void seek (int slider); -#endif + boost::shared_ptr<Film> film () const; void back_frame (); void forward_frame (); diff --git a/src/wx/player_stress_tester.cc b/src/wx/player_stress_tester.cc new file mode 100644 index 000000000..c0e6e8443 --- /dev/null +++ b/src/wx/player_stress_tester.cc @@ -0,0 +1,161 @@ +/* + Copyright (C) 2017-2020 Carl Hetherington <cth@carlh.net> + + This file is part of DCP-o-matic. + + DCP-o-matic 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. + + DCP-o-matic 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 DCP-o-matic. If not, see <http://www.gnu.org/licenses/>. + +*/ + +#include "player_stress_tester.h" +#include "controls.h" +#include <dcp/raw_convert.h> +#include <dcp/util.h> +#include <wx/wx.h> +#include <boost/algorithm/string.hpp> +#include <boost/foreach.hpp> +#include <boost/bind.hpp> +#include <string> +#include <vector> +#include <iostream> + +using std::string; +using std::vector; +using std::cout; +using dcp::raw_convert; +using boost::optional; + +/* Interval to check for things to do with the stress script (in milliseconds) */ +#define CHECK_INTERVAL 20 + +Command::Command (string line) + : type (NONE) + , int_param (0) +{ + vector<string> bits; + boost::split (bits, line, boost::is_any_of(" ")); + if (bits[0] == "O") { + if (bits.size() != 2) { + return; + } + type = OPEN; + string_param = bits[1]; + } else if (bits[0] == "P") { + type = PLAY; + } else if (bits[0] == "W") { + if (bits.size() != 2) { + return; + } + type = WAIT; + int_param = raw_convert<int>(bits[1]); + } else if (bits[0] == "S") { + type = STOP; + } else if (bits[0] == "K") { + if (bits.size() != 2) { + return; + } + type = SEEK; + int_param = raw_convert<int>(bits[1]); + } +} + +PlayerStressTester::PlayerStressTester () + : _parent (0) + , _controls (0) + , _suspended (false) +{ + +} + + +void +PlayerStressTester::setup (wxWindow* parent, Controls* controls) +{ + _parent = parent; + _controls = controls; +} + + +void +PlayerStressTester::load_script (boost::filesystem::path file) +{ + DCPOMATIC_ASSERT (_parent); + + _timer.Bind (wxEVT_TIMER, boost::bind(&PlayerStressTester::check_commands, this)); + _timer.Start (CHECK_INTERVAL); + vector<string> lines; + string const script = dcp::file_to_string(file); + boost::split (lines, script, boost::is_any_of("\n")); + BOOST_FOREACH (string i, lines) { + _commands.push_back (Command(i)); + } + _current_command = _commands.begin(); +} + +void +PlayerStressTester::check_commands () +{ + DCPOMATIC_ASSERT (_controls); + + if (_suspended) { + return; + } + + if (_current_command == _commands.end()) { + _timer.Stop (); + cout << "ST: finished.\n"; + return; + } + + switch (_current_command->type) { + case Command::OPEN: + LoadDCP(_current_command->string_param); + ++_current_command; + break; + case Command::PLAY: + cout << "ST: play\n"; + _controls->play (); + ++_current_command; + break; + case Command::WAIT: + /* int_param here is the number of milliseconds to wait */ + if (_wait_remaining) { + _wait_remaining = *_wait_remaining - CHECK_INTERVAL; + if (_wait_remaining < 0) { + cout << "ST: wait done.\n"; + _wait_remaining = optional<int>(); + ++_current_command; + } + } else { + _wait_remaining = _current_command->int_param; + cout << "ST: waiting for " << *_wait_remaining << ".\n"; + } + break; + case Command::STOP: + cout << "ST: stop\n"; + _controls->stop (); + ++_current_command; + break; + case Command::NONE: + ++_current_command; + break; + case Command::SEEK: + /* int_param here is a number between 0 and 4095, corresponding to the possible slider positions */ + cout << "ST: seek to " << _current_command->int_param << "\n"; + _controls->seek (_current_command->int_param); + ++_current_command; + break; + } +} + diff --git a/src/wx/player_stress_tester.h b/src/wx/player_stress_tester.h new file mode 100644 index 000000000..40686bc24 --- /dev/null +++ b/src/wx/player_stress_tester.h @@ -0,0 +1,72 @@ +/* + Copyright (C) 2017-2020 Carl Hetherington <cth@carlh.net> + + This file is part of DCP-o-matic. + + DCP-o-matic 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. + + DCP-o-matic 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 DCP-o-matic. If not, see <http://www.gnu.org/licenses/>. + +*/ + +#include <wx/wx.h> +#include <boost/signals2.hpp> +#include <boost/filesystem.hpp> + +class wxWindow; +class Controls; + +class Command +{ +public: + enum Type { + NONE, + OPEN, + PLAY, + WAIT, + STOP, + SEEK, + }; + + Command(std::string line); + + Type type; + std::string string_param; + int int_param; +}; + +class PlayerStressTester +{ +public: + PlayerStressTester (); + + void setup (wxWindow* parent, Controls* controls); + void load_script (boost::filesystem::path file); + void set_suspended (bool s) { + _suspended = s; + } + + boost::signals2::signal<void (boost::filesystem::path)> LoadDCP; + +private: + void check_commands (); + + wxWindow* _parent; + Controls* _controls; + wxTimer _timer; + bool _suspended; + std::list<Command> _commands; + std::list<Command>::const_iterator _current_command; + /** Remaining time that the script must wait, in milliseconds */ + boost::optional<int> _wait_remaining; +}; + diff --git a/src/wx/playlist_controls.cc b/src/wx/playlist_controls.cc index edc4485e6..72ec7ad1f 100644 --- a/src/wx/playlist_controls.cc +++ b/src/wx/playlist_controls.cc @@ -52,7 +52,6 @@ PlaylistControls::PlaylistControls (wxWindow* parent, shared_ptr<FilmViewer> vie , _stop_button (new Button(this, _("Stop"))) , _next_button (new Button(this, "Next")) , _previous_button (new Button(this, "Previous")) - , _timer (this) { _button_sizer->Add (_previous_button, 0, wxEXPAND); _button_sizer->Add (_play_button, 0, wxEXPAND); @@ -455,7 +454,6 @@ PlaylistControls::viewer_finished () } } -#ifdef DCPOMATIC_PLAYER_STRESS_TEST void PlaylistControls::play () { @@ -467,4 +465,3 @@ PlaylistControls::stop () { stop_clicked (); } -#endif diff --git a/src/wx/playlist_controls.h b/src/wx/playlist_controls.h index 460924217..4f144834a 100644 --- a/src/wx/playlist_controls.h +++ b/src/wx/playlist_controls.h @@ -37,10 +37,8 @@ public: */ boost::signals2::signal<void (boost::weak_ptr<Film>)> ResetFilm; -#ifdef DCPOMATIC_PLAYER_STRESS_TEST void play (); void stop (); -#endif private: void play_clicked (); @@ -81,6 +79,4 @@ private: std::vector<SPL> _playlists; boost::optional<int> _selected_playlist; int _selected_playlist_position; - - wxTimer _timer; }; diff --git a/src/wx/standard_controls.cc b/src/wx/standard_controls.cc index e9a31c86b..5df89f8fe 100644 --- a/src/wx/standard_controls.cc +++ b/src/wx/standard_controls.cc @@ -75,7 +75,6 @@ StandardControls::setup_sensitivity () _play_button->Enable (_film && !_film->content().empty() && !active_job); } -#ifdef DCPOMATIC_PLAYER_STRESS_TEST void StandardControls::play () { @@ -89,4 +88,3 @@ StandardControls::stop () _play_button->SetValue (false); play_clicked (); } -#endif diff --git a/src/wx/standard_controls.h b/src/wx/standard_controls.h index f79e4a178..143624126 100644 --- a/src/wx/standard_controls.h +++ b/src/wx/standard_controls.h @@ -25,10 +25,8 @@ class StandardControls : public Controls public: StandardControls (wxWindow* parent, boost::shared_ptr<FilmViewer> viewer, bool editor_controls); -#ifdef DCPOMATIC_PLAYER_STRESS_TEST void play (); void stop (); -#endif private: void check_play_state (); diff --git a/src/wx/wscript b/src/wx/wscript index 2685ba8b4..66c88f8d0 100644 --- a/src/wx/wscript +++ b/src/wx/wscript @@ -100,6 +100,7 @@ sources = """ password_entry.cc player_config_dialog.cc player_information.cc + player_stress_tester.cc playhead_to_timecode_dialog.cc playhead_to_frame_dialog.cc playlist_controls.cc |
