Add DCP size and length to player.
authorCarl Hetherington <cth@carlh.net>
Thu, 3 Aug 2017 16:03:22 +0000 (17:03 +0100)
committerCarl Hetherington <cth@carlh.net>
Mon, 14 Aug 2017 20:07:49 +0000 (21:07 +0100)
src/lib/util.cc
src/lib/util.h
src/tools/dcpomatic_player.cc
src/wx/film_viewer.h
src/wx/player_information.cc
src/wx/player_information.h
test/util_test.cc

index 4ffe3bd12bb8ed4f76092286f8aad08ce4fe0691..1f5b29101de78c7657a2341623590eed7b3ad92f 100644 (file)
@@ -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<int>(f));
+       return buffer;
+}
+
 /** @param s Number of seconds.
  *  @return String containing an approximate description of s (e.g. "about 2 hours")
  */
index b152b67b514cfb3ba2a9db90d094e8774d7bb190..d4616a7c9ea1bc4e0eadcb7e413a721314917602 100644 (file)
@@ -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 ();
index fb962d1bb135eb57359811342b300d64f3523fec..3a7c18f0241b51c3e8f4f93d864315dabf10f8a6 100644 (file)
@@ -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"
index b445528b1a93cc9fec16ccf7627ca18c462231cd..f8658be3834cb1a3f0866e269620bd1edbc0e9c7 100644 (file)
@@ -98,6 +98,7 @@ private:
        boost::shared_ptr<Player> _player;
 
        wxSizer* _v_sizer;
+       /** The area that we put our image in */
        wxPanel* _panel;
        wxCheckBox* _outline_content;
        wxRadioButton* _left_eye;
index e79e716227286ea6c5bcbde67cc83833e5d58971..baeae838cf0baaa53e85cfb7791c6144fbb41ad8 100644 (file)
 #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<DCPContent> dcp;
        if (_viewer->film()) {
                ContentList content = _viewer->film()->content();
                if (content.size() == 1) {
-                       shared_ptr<DCPContent> dcp = dynamic_pointer_cast<DCPContent>(content.front());
-                       if (dcp) {
-                               cpl_name = std_to_wx (dcp->name());
-                       }
+                       dcp = dynamic_pointer_cast<DCPContent>(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<double> 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)
+                       )
+               );
 }
index 7d784d7156351eb57e6538dc41e060a3ab8baf8e..af18cfb76dc8646dccae7f559fee48832d585591 100644 (file)
@@ -34,5 +34,6 @@ private:
        FilmViewer* _viewer;
        wxSizer* _sizer;
        wxStaticText* _cpl_name;
-       wxStaticText* _decoded_fps;
+       wxStaticText* _size;
+       wxStaticText* _length;
 };
index b071708b3043d55ad1a42c2e8fd257af82dc9808..a605c3548cc5ff3a8b2d6c49e860b3a3ab9276e3 100644 (file)
@@ -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");