- if (fill_to) {
- /* XXX: this may not work for 3D */
- BOOST_FOREACH (DCPTimePeriod i, subtract(DCPTimePeriod (*fill_to, time), _no_video)) {
- for (DCPTime j = i.from; j < i.to; j += one_video_frame()) {
- LastVideoMap::const_iterator k = _last_video.find (wp);
- if (k != _last_video.end ()) {
- emit_video (k->second, j);
- } else {
- emit_video (black_player_video_frame(), j);
+ /* Fill gaps that we discover now that we have some video which needs to be emitted.
+ This is where we need to fill to.
+ */
+ DCPTime fill_to = min (time, piece->content->end(_film));
+
+ if (_next_video_time) {
+ DCPTime fill_from = max (*_next_video_time, piece->content->position());
+
+ /* Fill if we have more than half a frame to do */
+ if ((fill_to - fill_from) > one_video_frame() / 2) {
+ auto last = _last_video.find (wp);
+ if (_film->three_d()) {
+ auto fill_to_eyes = video.eyes;
+ if (fill_to_eyes == Eyes::BOTH) {
+ fill_to_eyes = Eyes::LEFT;
+ }
+ if (fill_to == piece->content->end(_film)) {
+ /* Don't fill after the end of the content */
+ fill_to_eyes = Eyes::LEFT;
+ }
+ auto j = fill_from;
+ auto eyes = _next_video_eyes.get_value_or(Eyes::LEFT);
+ if (eyes == Eyes::BOTH) {
+ eyes = Eyes::LEFT;
+ }
+ while (j < fill_to || eyes != fill_to_eyes) {
+ if (last != _last_video.end()) {
+ LOG_DEBUG_PLAYER("Fill using last video at %1 in 3D mode", to_string(j));
+ auto copy = last->second->shallow_copy();
+ copy->set_eyes (eyes);
+ emit_video (copy, j);
+ } else {
+ LOG_DEBUG_PLAYER("Fill using black at %1 in 3D mode", to_string(j));
+ emit_video (black_player_video_frame(eyes), j);
+ }
+ if (eyes == Eyes::RIGHT) {
+ j += one_video_frame();
+ }
+ eyes = increment_eyes (eyes);
+ }
+ } else {
+ for (DCPTime j = fill_from; j < fill_to; j += one_video_frame()) {
+ if (last != _last_video.end()) {
+ emit_video (last->second, j);
+ } else {
+ emit_video (black_player_video_frame(Eyes::BOTH), j);
+ }