Put two video views inside FilmViewer, one for main and one for sign language.
[dcpomatic.git] / src / wx / film_viewer.cc
1 /*
2     Copyright (C) 2012-2021 Carl Hetherington <cth@carlh.net>
3
4     This file is part of DCP-o-matic.
5
6     DCP-o-matic is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10
11     DCP-o-matic is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with DCP-o-matic.  If not, see <http://www.gnu.org/licenses/>.
18
19 */
20
21
22 /** @file  src/film_viewer.cc
23  *  @brief A wx widget to view a preview of a Film.
24  */
25
26
27 #include "closed_captions_dialog.h"
28 #include "film_viewer.h"
29 #include "gl_video_view.h"
30 #include "nag_dialog.h"
31 #include "playhead_to_frame_dialog.h"
32 #include "playhead_to_timecode_dialog.h"
33 #include "sign_language_dialog.h"
34 #include "simple_video_view.h"
35 #include "wx_util.h"
36 #include "lib/butler.h"
37 #include "lib/compose.hpp"
38 #include "lib/config.h"
39 #include "lib/dcpomatic_log.h"
40 #include "lib/examine_content_job.h"
41 #include "lib/exceptions.h"
42 #include "lib/film.h"
43 #include "lib/filter.h"
44 #include "lib/image.h"
45 #include "lib/job_manager.h"
46 #include "lib/log.h"
47 #include "lib/player.h"
48 #include "lib/player_video.h"
49 #include "lib/ratio.h"
50 #include "lib/text_content.h"
51 #include "lib/timer.h"
52 #include "lib/util.h"
53 #include "lib/video_content.h"
54 #include "lib/video_decoder.h"
55 #include <dcp/exceptions.h>
56 #include <dcp/warnings.h>
57 extern "C" {
58 #include <libavutil/pixfmt.h>
59 }
60 LIBDCP_DISABLE_WARNINGS
61 #include <wx/tglbtn.h>
62 LIBDCP_ENABLE_WARNINGS
63 #include <iomanip>
64
65
66 using std::bad_alloc;
67 using std::dynamic_pointer_cast;
68 using std::make_shared;
69 using std::max;
70 using std::shared_ptr;
71 using std::string;
72 using std::vector;
73 using boost::optional;
74 #if BOOST_VERSION >= 106100
75 using namespace boost::placeholders;
76 #endif
77 using dcp::Size;
78 using namespace dcpomatic;
79
80
81 static
82 int
83 rtaudio_callback (void* out, void *, unsigned int frames, double, RtAudioStreamStatus, void* data)
84 {
85         return reinterpret_cast<FilmViewer*>(data)->audio_callback (out, frames);
86 }
87
88
89 FilmViewer::FilmViewer (wxWindow* p)
90         : _audio (DCPOMATIC_RTAUDIO_API)
91         , _closed_captions_dialog (new ClosedCaptionsDialog(p, this))
92         , _sign_language_dialog(new SignLanguageDialog(p))
93 {
94 #if wxCHECK_VERSION(3, 1, 0)
95         switch (Config::instance()->video_view_type()) {
96         case Config::VIDEO_VIEW_OPENGL:
97                 _video_view[VideoType::MAIN] = std::make_shared<GLVideoView>(this, VideoType::MAIN, p);
98                 _video_view[VideoType::SIGN_LANGUAGE] = std::make_shared<GLVideoView>(this, VideoType::SIGN_LANGUAGE, _sign_language_dialog);
99                 break;
100         case Config::VIDEO_VIEW_SIMPLE:
101                 _video_view[VideoType::MAIN] = std::make_shared<SimpleVideoView>(this, VideoType::MAIN, p);
102                 _video_view[VideoType::SIGN_LANGUAGE] = std::make_shared<SimpleVideoView>(this, VideoType::SIGN_LANGUAGE, _sign_language_dialog);
103                 break;
104         }
105 #else
106         _video_view = std::make_shared<SimpleVideoView>(this, p);
107 #endif
108
109         _video_view[VideoType::MAIN]->Sized.connect(boost::bind(&FilmViewer::video_view_sized, this, VideoType::MAIN));
110         _video_view[VideoType::SIGN_LANGUAGE]->Sized.connect(boost::bind(&FilmViewer::video_view_sized, this, VideoType::SIGN_LANGUAGE));
111         _video_view[VideoType::MAIN]->TooManyDropped.connect(boost::bind(boost::ref(TooManyDropped)));
112
113         set_film (shared_ptr<Film>());
114
115         _config_changed_connection = Config::instance()->Changed.connect(bind(&FilmViewer::config_changed, this, _1));
116         config_changed (Config::SOUND_OUTPUT);
117 }
118
119
120 FilmViewer::~FilmViewer ()
121 {
122         stop ();
123 }
124
125
126 /** Ask for ::idle_handler() to be called next time we are idle */
127 void
128 FilmViewer::request_idle_display_next_frame ()
129 {
130         if (_idle_get) {
131                 return;
132         }
133
134         _idle_get = true;
135         DCPOMATIC_ASSERT (signal_manager);
136         signal_manager->when_idle (boost::bind(&FilmViewer::idle_handler, this));
137 }
138
139
140 void
141 FilmViewer::idle_handler ()
142 {
143         if (!_idle_get) {
144                 return;
145         }
146
147         if (_video_view[VideoType::MAIN]->display_next_frame(true) == VideoView::AGAIN) {
148                 /* get() could not complete quickly so we'll try again later */
149                 signal_manager->when_idle (boost::bind(&FilmViewer::idle_handler, this));
150         } else {
151                 _idle_get = false;
152         }
153 }
154
155
156 void
157 FilmViewer::set_film (shared_ptr<Film> film)
158 {
159         if (_film == film) {
160                 return;
161         }
162
163         _film = film;
164
165         _video_view[VideoType::MAIN]->clear();
166         _video_view[VideoType::SIGN_LANGUAGE]->clear();
167         _closed_captions_dialog->clear ();
168
169         destroy_butler();
170
171         if (!_film) {
172                 _player = boost::none;
173                 resume();
174                 _video_view[VideoType::MAIN]->update();
175                 _video_view[VideoType::SIGN_LANGUAGE]->update();
176                 return;
177         }
178
179         try {
180                 _player.emplace(_film, _optimise_for_j2k ? Image::Alignment::COMPACT : Image::Alignment::PADDED);
181                 _player->set_fast ();
182                 if (_dcp_decode_reduction) {
183                         _player->set_dcp_decode_reduction (_dcp_decode_reduction);
184                 }
185         } catch (bad_alloc &) {
186                 error_dialog(_video_view[VideoType::MAIN]->get(), _("There is not enough free memory to do that."));
187                 _film.reset ();
188                 resume();
189                 return;
190         }
191
192         _player->set_always_burn_open_subtitles ();
193         _player->set_play_referenced ();
194
195         _film->Change.connect (boost::bind (&FilmViewer::film_change, this, _1, _2));
196         _film->LengthChange.connect (boost::bind(&FilmViewer::film_length_change, this));
197         _player->Change.connect (boost::bind (&FilmViewer::player_change, this, _1, _2, _3));
198
199         film_change (ChangeType::DONE, Film::Property::VIDEO_FRAME_RATE);
200         film_change (ChangeType::DONE, Film::Property::THREE_D);
201         film_length_change ();
202
203         /* Keep about 1 second's worth of history samples */
204         _latency_history_count = _film->audio_frame_rate() / _audio_block_size;
205
206         _closed_captions_dialog->update_tracks (_film);
207
208         create_butler();
209
210         calculate_sizes ();
211         slow_refresh ();
212 }
213
214
215 void
216 FilmViewer::destroy_butler()
217 {
218         suspend ();
219         _butler.reset ();
220 }
221
222
223 void
224 FilmViewer::destroy_and_maybe_create_butler()
225 {
226         destroy_butler();
227
228         if (!_film) {
229                 resume ();
230                 return;
231         }
232
233         create_butler();
234 }
235
236
237 void
238 FilmViewer::create_butler()
239 {
240 #if wxCHECK_VERSION(3, 1, 0)
241         auto const j2k_gl_optimised = dynamic_pointer_cast<GLVideoView>(_video_view[VideoType::MAIN]) && _optimise_for_j2k;
242 #else
243         auto const j2k_gl_optimised = false;
244 #endif
245
246         DCPOMATIC_ASSERT(_player);
247
248         _butler = std::make_shared<Butler>(
249                 _film,
250                 *_player,
251                 Config::instance()->audio_mapping(_audio_channels),
252                 _audio_channels,
253                 boost::bind(&PlayerVideo::force, AV_PIX_FMT_RGB24),
254                 VideoRange::FULL,
255                 j2k_gl_optimised ? Image::Alignment::COMPACT : Image::Alignment::PADDED,
256                 true,
257                 j2k_gl_optimised,
258                 (Config::instance()->sound() && _audio.isStreamOpen()) ? Butler::Audio::ENABLED : Butler::Audio::DISABLED
259                 );
260
261         _closed_captions_dialog->set_butler (_butler);
262
263         resume ();
264 }
265
266
267 void
268 FilmViewer::set_outline_content (bool o)
269 {
270         _outline_content = o;
271         _video_view[VideoType::MAIN]->update();
272 }
273
274
275 void
276 FilmViewer::set_outline_subtitles (optional<dcpomatic::Rect<double>> rect)
277 {
278         _outline_subtitles = rect;
279         _video_view[VideoType::MAIN]->update();
280 }
281
282
283 void
284 FilmViewer::set_eyes (Eyes e)
285 {
286         _video_view[VideoType::MAIN]->set_eyes(e);
287         slow_refresh ();
288 }
289
290
291 void
292 FilmViewer::video_view_sized(VideoType)
293 {
294         calculate_sizes ();
295         if (!quick_refresh()) {
296                 slow_refresh ();
297         }
298 }
299
300
301 void
302 FilmViewer::calculate_sizes ()
303 {
304         if (!_film || !_player) {
305                 return;
306         }
307
308         auto set_sizes = [this](VideoType type, float ratio) {
309                 auto const scale = dpi_scale_factor(_video_view[type]->get());
310                 int const video_view_width = std::round(_video_view[type]->get()->GetSize().x * scale);
311                 int const video_view_height = std::round(_video_view[type]->get()->GetSize().y * scale);
312
313                 auto const view_ratio = float(video_view_width) / video_view_height;
314
315                 dcp::Size out_size;
316                 if (view_ratio < ratio) {
317                         /* panel is less widescreen than the film; clamp width */
318                         out_size.width = video_view_width;
319                         out_size.height = lrintf(out_size.width / ratio);
320                 } else {
321                         /* panel is more widescreen than the film; clamp height */
322                         out_size.height = video_view_height;
323                         out_size.width = lrintf(out_size.height * ratio);
324                 }
325
326                 /* Catch silly values */
327                 out_size.width = max (64, out_size.width);
328                 out_size.height = max (64, out_size.height);
329
330                 /* Make sure the video container sizes are always a multiple of 2 so that
331                  * we don't get gaps with subsampled sources (e.g. YUV420)
332                  */
333                 if (out_size.width % 2) {
334                         out_size.width++;
335                 }
336                 if (out_size.height % 2) {
337                         out_size.height++;
338                 }
339
340                 _player->set_video_container_size(type, out_size);
341         };
342
343         set_sizes(VideoType::MAIN, _film->container() ? _film->container()->ratio() : 1.78);
344         set_sizes(VideoType::SIGN_LANGUAGE, 480.0 / 640.0);
345 }
346
347
348 void
349 FilmViewer::suspend ()
350 {
351         ++_suspended;
352         if (_audio.isStreamRunning()) {
353                 _audio.abortStream();
354         }
355 }
356
357
358 void
359 FilmViewer::start_audio_stream_if_open ()
360 {
361         if (_audio.isStreamOpen()) {
362                 _audio.setStreamTime(_video_view[VideoType::MAIN]->position().seconds());
363                 try {
364                         _audio.startStream ();
365                 } catch (RtAudioError& e) {
366                         _audio_channels = 0;
367                         error_dialog (
368                                 _video_view[VideoType::MAIN]->get(),
369                                 _("There was a problem starting audio playback.  Please try another audio output device in Preferences."), std_to_wx(e.what())
370                                 );
371                 }
372         }
373 }
374
375
376 void
377 FilmViewer::resume ()
378 {
379         DCPOMATIC_ASSERT (_suspended > 0);
380         --_suspended;
381         if (_playing && !_suspended) {
382                 start_audio_stream_if_open ();
383                 _video_view[VideoType::MAIN]->start();
384                 _video_view[VideoType::SIGN_LANGUAGE]->start();
385         }
386 }
387
388
389 void
390 FilmViewer::start ()
391 {
392         if (!_film) {
393                 return;
394         }
395
396         auto v = PlaybackPermitted ();
397         if (v && !*v) {
398                 /* Computer says no */
399                 return;
400         }
401
402         /* We are about to set up the audio stream from the position of the video view.
403            If there is `lazy' seek in progress we need to wait for it to go through so that
404            _video_view->position() gives us a sensible answer.
405          */
406         while (_idle_get) {
407                 idle_handler ();
408         }
409
410         /* Take the video view's idea of position as our `playhead' and start the
411            audio stream (which is the timing reference) there.
412          */
413         start_audio_stream_if_open ();
414
415         _playing = true;
416         /* Calling start() below may directly result in Stopped being emitted, and if that
417          * happens we want it to come after the Started signal, so do that first.
418          */
419         Started ();
420         _video_view[VideoType::MAIN]->start();
421         _video_view[VideoType::SIGN_LANGUAGE]->start();
422 }
423
424
425 bool
426 FilmViewer::stop ()
427 {
428         if (_audio.isStreamRunning()) {
429                 /* stop stream and discard any remaining queued samples */
430                 _audio.abortStream ();
431         }
432
433         if (!_playing) {
434                 return false;
435         }
436
437         _playing = false;
438         _video_view[VideoType::MAIN]->stop();
439         _video_view[VideoType::SIGN_LANGUAGE]->stop();
440         Stopped ();
441
442         _video_view[VideoType::MAIN]->rethrow();
443         _video_view[VideoType::SIGN_LANGUAGE]->rethrow();
444         return true;
445 }
446
447
448 void
449 FilmViewer::player_change (ChangeType type, int property, bool frequent)
450 {
451         if (type != ChangeType::DONE || frequent) {
452                 return;
453         }
454
455         if (_coalesce_player_changes) {
456                 _pending_player_changes.push_back (property);
457                 return;
458         }
459
460         player_change ({property});
461 }
462
463
464 void
465 FilmViewer::player_change (vector<int> properties)
466 {
467         calculate_sizes ();
468
469         bool try_quick_refresh = false;
470         bool update_ccap_tracks = false;
471
472         for (auto i: properties) {
473                 if (
474                         i == VideoContentProperty::CROP ||
475                         i == VideoContentProperty::CUSTOM_RATIO ||
476                         i == VideoContentProperty::CUSTOM_SIZE ||
477                         i == VideoContentProperty::FADE_IN ||
478                         i == VideoContentProperty::FADE_OUT ||
479                         i == VideoContentProperty::COLOUR_CONVERSION ||
480                         i == PlayerProperty::VIDEO_CONTAINER_SIZE ||
481                         i == PlayerProperty::FILM_CONTAINER
482                    ) {
483                         try_quick_refresh = true;
484                 }
485
486                 if (i == TextContentProperty::USE || i == TextContentProperty::TYPE || i == TextContentProperty::DCP_TRACK) {
487                         update_ccap_tracks = true;
488                 }
489         }
490
491         if (!try_quick_refresh || !quick_refresh()) {
492                 slow_refresh ();
493         }
494
495         if (update_ccap_tracks) {
496                 _closed_captions_dialog->update_tracks (_film);
497         }
498 }
499
500
501 void
502 FilmViewer::film_change (ChangeType type, Film::Property p)
503 {
504         if (type != ChangeType::DONE) {
505                 return;
506         }
507
508         if (p == Film::Property::AUDIO_CHANNELS) {
509                 destroy_and_maybe_create_butler();
510         } else if (p == Film::Property::VIDEO_FRAME_RATE) {
511                 _video_view[VideoType::MAIN]->set_video_frame_rate(_film->video_frame_rate());
512                 _video_view[VideoType::SIGN_LANGUAGE]->set_video_frame_rate(_film->video_frame_rate());
513         } else if (p == Film::Property::THREE_D) {
514                 _video_view[VideoType::MAIN]->set_three_d(_film->three_d());
515         } else if (p == Film::Property::CONTENT) {
516                 _closed_captions_dialog->update_tracks (_film);
517         }
518 }
519
520
521 void
522 FilmViewer::film_length_change ()
523 {
524         _video_view[VideoType::MAIN]->set_length(_film->length());
525         _video_view[VideoType::SIGN_LANGUAGE]->set_length(_film->length());
526 }
527
528
529 /** Re-get the current frame slowly by seeking */
530 void
531 FilmViewer::slow_refresh ()
532 {
533         seek(_video_view[VideoType::MAIN]->position(), true);
534 }
535
536
537 /** Try to re-get the current frame quickly by resetting the metadata
538  *  in the PlayerVideo that we used last time.
539  *  @return true if this was possible, false if not.
540  */
541 bool
542 FilmViewer::quick_refresh ()
543 {
544         if (!_video_view[VideoType::MAIN] || !_film || !_player) {
545                 return true;
546         }
547         return _video_view[VideoType::MAIN]->reset_metadata(_film, _player->video_container_size(VideoType::MAIN));
548 }
549
550
551 void
552 FilmViewer::seek (shared_ptr<Content> content, ContentTime t, bool accurate)
553 {
554         DCPOMATIC_ASSERT(_player);
555         auto dt = _player->content_time_to_dcp (content, t);
556         if (dt) {
557                 seek (*dt, accurate);
558         }
559 }
560
561
562 void
563 FilmViewer::set_coalesce_player_changes (bool c)
564 {
565         _coalesce_player_changes = c;
566
567         if (!c) {
568                 player_change (_pending_player_changes);
569                 _pending_player_changes.clear ();
570         }
571 }
572
573
574 void
575 FilmViewer::seek (DCPTime t, bool accurate)
576 {
577         if (!_butler) {
578                 return;
579         }
580
581         if (t < DCPTime()) {
582                 t = DCPTime ();
583         }
584
585         if (t >= _film->length()) {
586                 t = _film->length() - one_video_frame();
587         }
588
589         suspend ();
590
591         _closed_captions_dialog->clear ();
592         _butler->seek (t, accurate);
593
594         if (!_playing) {
595                 /* We're not playing, so let the GUI thread get on and
596                    come back later to get the next frame after the seek.
597                 */
598                 request_idle_display_next_frame ();
599         } else {
600                 /* We're going to start playing again straight away
601                    so wait for the seek to finish.
602                 */
603                 while (_video_view[VideoType::MAIN]->display_next_frame(false) == VideoView::AGAIN) {}
604         }
605
606         resume ();
607 }
608
609
610 void
611 FilmViewer::config_changed (Config::Property p)
612 {
613         if (p == Config::AUDIO_MAPPING) {
614                 destroy_and_maybe_create_butler();
615                 return;
616         }
617
618         if (p != Config::SOUND && p != Config::SOUND_OUTPUT) {
619                 return;
620         }
621
622         if (_audio.isStreamOpen ()) {
623                 _audio.closeStream ();
624         }
625
626         if (Config::instance()->sound() && _audio.getDeviceCount() > 0) {
627                 unsigned int st = 0;
628                 if (Config::instance()->sound_output()) {
629                         while (st < _audio.getDeviceCount()) {
630                                 try {
631                                         if (_audio.getDeviceInfo(st).name == Config::instance()->sound_output().get()) {
632                                                 break;
633                                         }
634                                 } catch (RtAudioError&) {
635                                         /* Something went wrong with that device so we don't want to use it anyway */
636                                 }
637                                 ++st;
638                         }
639                         if (st == _audio.getDeviceCount()) {
640                                 st = _audio.getDefaultOutputDevice();
641                         }
642                 } else {
643                         st = _audio.getDefaultOutputDevice();
644                 }
645
646                 try {
647                         _audio_channels = _audio.getDeviceInfo(st).outputChannels;
648                         RtAudio::StreamParameters sp;
649                         sp.deviceId = st;
650                         sp.nChannels = _audio_channels;
651                         sp.firstChannel = 0;
652                         _audio.openStream (&sp, 0, RTAUDIO_FLOAT32, 48000, &_audio_block_size, &rtaudio_callback, this);
653                 } catch (RtAudioError& e) {
654                         _audio_channels = 0;
655                         error_dialog (
656                                 _video_view[VideoType::MAIN]->get(),
657                                 _("Could not set up audio output.  There will be no audio during the preview."), std_to_wx(e.what())
658                                 );
659                 }
660                 destroy_and_maybe_create_butler();
661
662         } else {
663                 _audio_channels = 0;
664                 destroy_and_maybe_create_butler();
665         }
666 }
667
668
669 DCPTime
670 FilmViewer::uncorrected_time () const
671 {
672         if (_audio.isStreamRunning()) {
673                 return DCPTime::from_seconds (const_cast<RtAudio*>(&_audio)->getStreamTime());
674         }
675
676         return _video_view[VideoType::MAIN]->position();
677 }
678
679
680 optional<DCPTime>
681 FilmViewer::audio_time () const
682 {
683         if (!_audio.isStreamRunning()) {
684                 return {};
685         }
686
687         return DCPTime::from_seconds (const_cast<RtAudio*>(&_audio)->getStreamTime ()) -
688                 DCPTime::from_frames (average_latency(), _film->audio_frame_rate());
689 }
690
691
692 DCPTime
693 FilmViewer::time () const
694 {
695         return audio_time().get_value_or(_video_view[VideoType::MAIN]->position());
696 }
697
698
699 int
700 FilmViewer::audio_callback (void* out_p, unsigned int frames)
701 {
702         while (true) {
703                 auto t = _butler->get_audio (Butler::Behaviour::NON_BLOCKING, reinterpret_cast<float*> (out_p), frames);
704                 if (!t || DCPTime(uncorrected_time() - *t) < one_video_frame()) {
705                         /* There was an underrun or this audio is on time; carry on */
706                         break;
707                 }
708                 /* The audio we just got was (very) late; drop it and get some more. */
709         }
710
711         boost::mutex::scoped_lock lm (_latency_history_mutex, boost::try_to_lock);
712         if (lm) {
713                 _latency_history.push_back (_audio.getStreamLatency ());
714                 if (_latency_history.size() > static_cast<size_t> (_latency_history_count)) {
715                         _latency_history.pop_front ();
716                 }
717         }
718
719         return 0;
720 }
721
722
723 Frame
724 FilmViewer::average_latency () const
725 {
726         boost::mutex::scoped_lock lm (_latency_history_mutex);
727         if (_latency_history.empty()) {
728                 return 0;
729         }
730
731         Frame total = 0;
732         for (auto i: _latency_history) {
733                 total += i;
734         }
735
736         return total / _latency_history.size();
737 }
738
739
740 void
741 FilmViewer::set_dcp_decode_reduction (optional<int> reduction)
742 {
743         _dcp_decode_reduction = reduction;
744         if (_player) {
745                 _player->set_dcp_decode_reduction (reduction);
746         }
747 }
748
749
750 optional<int>
751 FilmViewer::dcp_decode_reduction () const
752 {
753         return _dcp_decode_reduction;
754 }
755
756
757 optional<ContentTime>
758 FilmViewer::position_in_content (shared_ptr<const Content> content) const
759 {
760         DCPOMATIC_ASSERT(_player);
761         return _player->dcp_to_content_time (content, position());
762 }
763
764
765 DCPTime
766 FilmViewer::one_video_frame () const
767 {
768         return DCPTime::from_frames (1, _film ? _film->video_frame_rate() : 24);
769 }
770
771
772 /** Open a dialog box showing our film's closed captions */
773 void
774 FilmViewer::show_closed_captions ()
775 {
776         _closed_captions_dialog->Show();
777 }
778
779
780 void
781 FilmViewer::show_sign_language()
782 {
783         _sign_language_dialog->Show();
784 }
785
786
787 void
788 FilmViewer::seek_by (DCPTime by, bool accurate)
789 {
790         seek(_video_view[VideoType::MAIN]->position() + by, accurate);
791 }
792
793
794 void
795 FilmViewer::set_pad_black (bool p)
796 {
797         _pad_black = p;
798 }
799
800
801 /** Called when a player has finished the current film.
802  *  May be called from a non-UI thread.
803  */
804 void
805 FilmViewer::finished ()
806 {
807         emit (boost::bind(&FilmViewer::ui_finished, this));
808 }
809
810
811 /** Called by finished() in the UI thread */
812 void
813 FilmViewer::ui_finished ()
814 {
815         stop ();
816         Finished ();
817 }
818
819
820 int
821 FilmViewer::dropped () const
822 {
823         return _video_view[VideoType::MAIN]->dropped();
824 }
825
826
827 int
828 FilmViewer::errored () const
829 {
830         return _video_view[VideoType::MAIN]->errored();
831 }
832
833
834 int
835 FilmViewer::gets () const
836 {
837         return _video_view[VideoType::MAIN]->gets();
838 }
839
840
841 void
842 FilmViewer::image_changed (shared_ptr<PlayerVideo> pv)
843 {
844         emit (boost::bind(boost::ref(ImageChanged), pv));
845 }
846
847
848 void
849 FilmViewer::set_optimise_for_j2k (bool o)
850 {
851         _optimise_for_j2k = o;
852         _video_view[VideoType::MAIN]->set_optimise_for_j2k(o);
853 }
854
855
856 void
857 FilmViewer::set_crop_guess (dcpomatic::Rect<float> crop)
858 {
859         if (crop != _crop_guess) {
860                 _crop_guess = crop;
861                 _video_view[VideoType::MAIN]->update();
862         }
863 }
864
865
866 void
867 FilmViewer::unset_crop_guess ()
868 {
869         _crop_guess = boost::none;
870         _video_view[VideoType::MAIN]->update();
871 }
872
873
874 optional<dcpomatic::Rect<float>>
875 FilmViewer::crop_guess(VideoType type) const
876 {
877         if (type != VideoType::MAIN) {
878                 return {};
879         }
880
881         return _crop_guess;
882 }
883
884
885 optional<dcpomatic::Rect<double>>
886 FilmViewer::outline_subtitles(VideoType type) const
887 {
888         if (type != VideoType::MAIN) {
889                 return {};
890         }
891
892         return _outline_subtitles;
893 }
894