From e0c524cbc4f006a4319c3ce8aa7625f9d70d054a Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Thu, 3 Aug 2017 17:03:22 +0100 Subject: [PATCH] Add DCP size and length to player. --- src/lib/util.cc | 16 ++++++++++++++++ src/lib/util.h | 1 + src/tools/dcpomatic_player.cc | 1 + src/wx/film_viewer.h | 1 + src/wx/player_information.cc | 36 ++++++++++++++++++++++++++++------- src/wx/player_information.h | 3 ++- test/util_test.cc | 9 +++++++++ 7 files changed, 59 insertions(+), 8 deletions(-) diff --git a/src/lib/util.cc b/src/lib/util.cc index 4ffe3bd12..1f5b29101 100644 --- a/src/lib/util.cc +++ b/src/lib/util.cc @@ -127,6 +127,22 @@ seconds_to_hms (int s) return buffer; } +string +time_to_hmsf (DCPTime time, Frame rate) +{ + Frame f = time.frames_round (rate); + int s = f / rate; + f -= (s * rate); + int m = s / 60; + s -= m * 60; + int h = m / 60; + m -= h * 60; + + char buffer[64]; + snprintf (buffer, sizeof(buffer), "%d:%02d:%02d.%d", h, m, s, static_cast(f)); + return buffer; +} + /** @param s Number of seconds. * @return String containing an approximate description of s (e.g. "about 2 hours") */ diff --git a/src/lib/util.h b/src/lib/util.h index b152b67b5..d4616a7c9 100644 --- a/src/lib/util.h +++ b/src/lib/util.h @@ -60,6 +60,7 @@ struct AVSubtitle; class AudioBuffers; extern std::string seconds_to_hms (int); +extern std::string time_to_hmsf (DCPTime time, Frame rate); extern std::string seconds_to_approximate_hms (int); extern double seconds (struct timeval); extern void dcpomatic_setup (); diff --git a/src/tools/dcpomatic_player.cc b/src/tools/dcpomatic_player.cc index fb962d1bb..3a7c18f02 100644 --- a/src/tools/dcpomatic_player.cc +++ b/src/tools/dcpomatic_player.cc @@ -27,6 +27,7 @@ #include "lib/dcp_content.h" #include "lib/job_manager.h" #include "lib/job.h" +#include "lib/video_content.h" #include "wx/wx_signal_manager.h" #include "wx/wx_util.h" #include "wx/about_dialog.h" diff --git a/src/wx/film_viewer.h b/src/wx/film_viewer.h index b445528b1..f8658be38 100644 --- a/src/wx/film_viewer.h +++ b/src/wx/film_viewer.h @@ -98,6 +98,7 @@ private: boost::shared_ptr _player; wxSizer* _v_sizer; + /** The area that we put our image in */ wxPanel* _panel; wxCheckBox* _outline_content; wxRadioButton* _left_eye; diff --git a/src/wx/player_information.cc b/src/wx/player_information.cc index e79e71622..baeae838c 100644 --- a/src/wx/player_information.cc +++ b/src/wx/player_information.cc @@ -22,11 +22,13 @@ #include "wx_util.h" #include "film_viewer.h" #include "lib/playlist.h" +#include "lib/video_content.h" #include "lib/dcp_content.h" using std::cout; using boost::shared_ptr; using boost::dynamic_pointer_cast; +using boost::optional; PlayerInformation::PlayerInformation (wxWindow* parent, FilmViewer* viewer) : wxPanel (parent) @@ -40,13 +42,14 @@ PlayerInformation::PlayerInformation (wxWindow* parent, FilmViewer* viewer) wxSizer* s = new wxBoxSizer (wxVERTICAL); add_label_to_sizer(s, this, _("DCP"), false, 0)->SetFont(title_font); _cpl_name = add_label_to_sizer(s, this, wxT(""), false, 0); + _size = add_label_to_sizer(s, this, wxT(""), false, 0); + _length = add_label_to_sizer(s, this, wxT(""), false, 0); _sizer->Add (s, 1, wxEXPAND | wxALL, 6); } { wxSizer* s = new wxBoxSizer (wxVERTICAL); add_label_to_sizer(s, this, _("Performance"), false, 0)->SetFont(title_font); - _decoded_fps = add_label_to_sizer(s, this, wxT(""), false, 0); _sizer->Add (s, 1, wxEXPAND | wxALL, 6); } @@ -58,16 +61,35 @@ PlayerInformation::PlayerInformation (wxWindow* parent, FilmViewer* viewer) void PlayerInformation::update () { - wxString cpl_name; + shared_ptr dcp; if (_viewer->film()) { ContentList content = _viewer->film()->content(); if (content.size() == 1) { - shared_ptr dcp = dynamic_pointer_cast(content.front()); - if (dcp) { - cpl_name = std_to_wx (dcp->name()); - } + dcp = dynamic_pointer_cast(content.front()); } } - checked_set (_cpl_name, cpl_name); + if (!dcp) { + checked_set (_cpl_name, _("No DCP loaded.")); + checked_set (_size, wxT("")); + checked_set (_length, wxT("")); + return; + } + + DCPOMATIC_ASSERT (dcp->video); + + checked_set (_cpl_name, std_to_wx(dcp->name())); + checked_set (_size, wxString::Format(_("Size: %dx%d"), dcp->video->size().width, dcp->video->size().height)); + + optional vfr; + vfr = dcp->video_frame_rate (); + DCPOMATIC_ASSERT (vfr); + checked_set ( + _length, + wxString::Format( + _("Length: %s (%ld frames)"), + std_to_wx(time_to_hmsf(dcp->full_length(), lrint(*vfr))).data(), + dcp->full_length().frames_round(*vfr) + ) + ); } diff --git a/src/wx/player_information.h b/src/wx/player_information.h index 7d784d715..af18cfb76 100644 --- a/src/wx/player_information.h +++ b/src/wx/player_information.h @@ -34,5 +34,6 @@ private: FilmViewer* _viewer; wxSizer* _sizer; wxStaticText* _cpl_name; - wxStaticText* _decoded_fps; + wxStaticText* _size; + wxStaticText* _length; }; diff --git a/test/util_test.cc b/test/util_test.cc index b071708b3..a605c3548 100644 --- a/test/util_test.cc +++ b/test/util_test.cc @@ -105,6 +105,15 @@ BOOST_AUTO_TEST_CASE (seconds_to_approximate_hms_test) BOOST_CHECK_EQUAL (seconds_to_approximate_hms (13 * 3600 + 40 * 60), "14h"); } +BOOST_AUTO_TEST_CASE (time_to_hmsf_test) +{ + BOOST_CHECK_EQUAL (time_to_hmsf(DCPTime::from_frames(12, 24), 24), "0:00:00.12"); + BOOST_CHECK_EQUAL (time_to_hmsf(DCPTime::from_frames(24, 24), 24), "0:00:01.0"); + BOOST_CHECK_EQUAL (time_to_hmsf(DCPTime::from_frames(32, 24), 24), "0:00:01.8"); + BOOST_CHECK_EQUAL (time_to_hmsf(DCPTime::from_seconds(92), 24), "0:01:32.0"); + BOOST_CHECK_EQUAL (time_to_hmsf(DCPTime::from_seconds(2 * 60 * 60 + 92), 24), "2:01:32.0"); +} + BOOST_AUTO_TEST_CASE (tidy_for_filename_test) { BOOST_CHECK_EQUAL (tidy_for_filename ("fish\\chips"), "fish_chips"); -- 2.30.2