diff options
| author | Carl Hetherington <cth@carlh.net> | 2013-12-20 17:36:31 +0000 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2013-12-20 17:36:31 +0000 |
| commit | 9b21d77dccc88d9b77085e05845e0b8e2d606b3b (patch) | |
| tree | 03d962ff6ebda619a9e749cc3d235d9b687a0de7 /src | |
| parent | 570d4c4489b49c3915674085ee24414f738cb914 (diff) | |
Some small optimisations to player.
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib/encoder.cc | 2 | ||||
| -rw-r--r-- | src/lib/image.cc | 7 | ||||
| -rw-r--r-- | src/lib/player.cc | 21 | ||||
| -rw-r--r-- | src/lib/player.h | 4 | ||||
| -rw-r--r-- | src/tools/server_test.cc | 9 | ||||
| -rw-r--r-- | src/wx/film_viewer.cc | 10 |
6 files changed, 40 insertions, 13 deletions
diff --git a/src/lib/encoder.cc b/src/lib/encoder.cc index f8a597191..046a3248e 100644 --- a/src/lib/encoder.cc +++ b/src/lib/encoder.cc @@ -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() ) )); diff --git a/src/lib/image.cc b/src/lib/image.cc index 95bf2b04d..18ddbc98d 100644 --- a/src/lib/image.cc +++ b/src/lib/image.cc @@ -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()]; diff --git a/src/lib/player.cc b/src/lib/player.cc index d1098be24..daefd6db0 100644 --- a/src/lib/player.cc +++ b/src/lib/player.cc @@ -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; } + diff --git a/src/lib/player.h b/src/lib/player.h index 35ffdcca9..b4454b859 100644 --- a/src/lib/player.h +++ b/src/lib/player.h @@ -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; diff --git a/src/tools/server_test.cc b/src/tools/server_test.cc index 3c40139b8..cc500eeb0 100644 --- a/src/tools/server_test.cc +++ b/src/tools/server_test.cc @@ -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 (); diff --git a/src/wx/film_viewer.cc b/src/wx/film_viewer.cc index cc2f67b15..e6b8bf8dd 100644 --- a/src/wx/film_viewer.cc +++ b/src/wx/film_viewer.cc @@ -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); |
