Some small optimisations to player.
authorCarl Hetherington <cth@carlh.net>
Fri, 20 Dec 2013 17:36:31 +0000 (17:36 +0000)
committerCarl Hetherington <cth@carlh.net>
Fri, 20 Dec 2013 17:36:31 +0000 (17:36 +0000)
src/lib/encoder.cc
src/lib/image.cc
src/lib/player.cc
src/lib/player.h
src/tools/server_test.cc
src/wx/film_viewer.cc
test/play_test.cc

index f8a5971911278b96eb5332691c23f52de7aca2f3..046a3248ef13fe0d3586cb6d6e41d3997a3913fb 100644 (file)
@@ -216,7 +216,7 @@ Encoder::process_video (shared_ptr<PlayerImage> image, Eyes eyes, ColourConversi
                TIMING ("adding to queue of %1", _queue.size ());
                _queue.push_back (shared_ptr<DCPVideoFrame> (
                                          new DCPVideoFrame (
-                                                 image->image(), _video_frames_out, eyes, conversion, _film->video_frame_rate(),
+                                                 image->image(PIX_FMT_RGB24, false), _video_frames_out, eyes, conversion, _film->video_frame_rate(),
                                                  _film->j2k_bandwidth(), _film->log()
                                                  )
                                          ));
index 95bf2b04d171085615e786418600d23d858f2909..18ddbc98dc7bdbffa64a9f9f55185e1a5ab948a8 100644 (file)
@@ -31,6 +31,7 @@ extern "C" {
 #include "image.h"
 #include "exceptions.h"
 #include "scaler.h"
+#include "timer.h"
 
 using std::string;
 using std::min;
@@ -94,9 +95,9 @@ Image::crop_scale_window (Crop crop, libdcp::Size inter_size, libdcp::Size out_s
        libdcp::Size cropped_size = crop.apply (size ());
 
        struct SwsContext* scale_context = sws_getContext (
-               cropped_size.width, cropped_size.height, pixel_format(),
-               inter_size.width, inter_size.height, out_format,
-               scaler->ffmpeg_id (), 0, 0, 0
+                       cropped_size.width, cropped_size.height, pixel_format(),
+                       inter_size.width, inter_size.height, out_format,
+                       scaler->ffmpeg_id (), 0, 0, 0
                );
 
        uint8_t* scale_in_data[components()];
index d1098be24d8f4d3ac0e918a756c920d54277d75f..daefd6db09a70d2f41d7c31138a384aece085352 100644 (file)
@@ -71,6 +71,7 @@ Player::Player (shared_ptr<const Film> f, shared_ptr<const Playlist> p)
        , _audio_merger (f->audio_channels(), bind (&Film::time_to_audio_frames, f.get(), _1), bind (&Film::audio_frames_to_time, f.get(), _1))
        , _last_emit_was_black (false)
        , _just_did_inaccurate_seek (false)
+       , _approximate_size (false)
 {
        _playlist_changed_connection = _playlist->Changed.connect (bind (&Player::playlist_changed, this));
        _playlist_content_changed_connection = _playlist->ContentChanged.connect (bind (&Player::content_changed, this, _1, _2, _3));
@@ -207,7 +208,11 @@ Player::emit_video (weak_ptr<Piece> weak_piece, shared_ptr<DecodedVideo> video)
        }
 
        float const ratio = content->ratio() ? content->ratio()->ratio() : content->video_size_after_crop().ratio();
-       libdcp::Size const image_size = fit_ratio_within (ratio, _video_container_size);
+       libdcp::Size image_size = fit_ratio_within (ratio, _video_container_size);
+       if (_approximate_size) {
+               image_size.width &= ~3;
+               image_size.height &= ~3;
+       }
 
        shared_ptr<PlayerImage> pi (
                new PlayerImage (
@@ -600,6 +605,13 @@ Player::repeat_last_video ()
        return true;
 }
 
+void
+Player::set_approximate_size ()
+{
+       _approximate_size = true;
+}
+                             
+
 PlayerImage::PlayerImage (
        shared_ptr<const Image> in,
        Crop crop,
@@ -624,10 +636,10 @@ PlayerImage::set_subtitle (shared_ptr<const Image> image, Position<int> pos)
 }
 
 shared_ptr<Image>
-PlayerImage::image ()
+PlayerImage::image (AVPixelFormat format, bool aligned)
 {
-       shared_ptr<Image> out = _in->crop_scale_window (_crop, _inter_size, _out_size, _scaler, PIX_FMT_RGB24, false);
-
+       shared_ptr<Image> out = _in->crop_scale_window (_crop, _inter_size, _out_size, _scaler, format, aligned);
+       
        Position<int> const container_offset ((_out_size.width - _inter_size.width) / 2, (_out_size.height - _inter_size.width) / 2);
 
        if (_subtitle_image) {
@@ -636,3 +648,4 @@ PlayerImage::image ()
 
        return out;
 }
+
index 35ffdcca9b7813c0bc6e03d79e61a577eb4f67c5..b4454b859d858e6d3736052c899c6c2f8f4114a0 100644 (file)
@@ -49,7 +49,7 @@ public:
 
        void set_subtitle (boost::shared_ptr<const Image>, Position<int>);
        
-       boost::shared_ptr<Image> image ();
+       boost::shared_ptr<Image> image (AVPixelFormat, bool);
 
 private:
        boost::shared_ptr<const Image> _in;
@@ -81,6 +81,7 @@ public:
        }
 
        void set_video_container_size (libdcp::Size);
+       void set_approximate_size ();
 
        bool repeat_last_video ();
 
@@ -162,6 +163,7 @@ private:
        } _last_incoming_video;
 
        bool _just_did_inaccurate_seek;
+       bool _approximate_size;
 
        boost::signals2::scoped_connection _playlist_changed_connection;
        boost::signals2::scoped_connection _playlist_content_changed_connection;
index 3c40139b80560d85ec948d5ca5b5fbf7dd6eb8e4..cc500eeb00438c1a004cae2b81136e05a4a1c236 100644 (file)
@@ -49,8 +49,13 @@ static int frame = 0;
 void
 process_video (shared_ptr<PlayerImage> image, Eyes eyes, ColourConversion conversion, DCPTime)
 {
-       shared_ptr<DCPVideoFrame> local  (new DCPVideoFrame (image->image(), frame, eyes, conversion, film->video_frame_rate(), 250000000, log_));
-       shared_ptr<DCPVideoFrame> remote (new DCPVideoFrame (image->image(), frame, eyes, conversion, film->video_frame_rate(), 250000000, log_));
+       shared_ptr<DCPVideoFrame> local  (
+               new DCPVideoFrame (image->image (PIX_FMT_RGB24, false), frame, eyes, conversion, film->video_frame_rate(), 250000000, log_)
+               );
+       
+       shared_ptr<DCPVideoFrame> remote (
+               new DCPVideoFrame (image->image (PIX_FMT_RGB24, false), frame, eyes, conversion, film->video_frame_rate(), 250000000, log_)
+               );
 
        cout << "Frame " << frame << ": ";
        cout.flush ();
index cc2f67b15c06216584b9ce82fff0b47d7d8ff2d6..e6b8bf8dd06cd37b6d4e67fd41a3f3cec2c3381d 100644 (file)
@@ -36,6 +36,7 @@
 #include "lib/player.h"
 #include "lib/video_content.h"
 #include "lib/video_decoder.h"
+#include "lib/timer.h"
 #include "film_viewer.h"
 #include "wx_util.h"
 
@@ -128,6 +129,7 @@ FilmViewer::set_film (shared_ptr<Film> f)
 
        _player = f->make_player ();
        _player->disable_audio ();
+       _player->set_approximate_size ();
        _player->Video.connect (boost::bind (&FilmViewer::process_video, this, _1, _2, _5));
        _player->Changed.connect (boost::bind (&FilmViewer::player_changed, this, _1));
 
@@ -280,8 +282,12 @@ FilmViewer::process_video (shared_ptr<PlayerImage> image, Eyes eyes, DCPTime t)
        if (eyes == EYES_RIGHT) {
                return;
        }
-       
-       _frame = image->image ();
+
+       /* Going via BGRA here makes the scaler faster then using RGB24 directly (about
+          twice on x86 Linux).
+       */
+       shared_ptr<Image> im = image->image (PIX_FMT_BGRA, true);
+       _frame = im->scale (im->size(), Scaler::from_id ("fastbilinear"), PIX_FMT_RGB24, false);
        _got_frame = true;
 
        set_position_text (t);
index 7beee6f43df86453e316e052a8fc3e83bb32a7c5..54fe2699f7fd47b19ad9ac666a70857e309d4567 100644 (file)
@@ -50,7 +50,7 @@ public:
        {
                Video v;
                v.content = _player->_last_video;
-               v.image = i->image ();
+               v.image = i->image (PIX_FMT_RGB24, false);
                v.time = t;
                _queue.push_front (v);
        }