- shared_ptr<AudioBuffers> trimmed (new AudioBuffers (audio->data->channels(), audio->data->frames() - frames));
- trimmed->copy_from (audio->data.get(), audio->data->frames() - frames, frames, 0);
-
- audio->data = trimmed;
- audio->dcp_time = 0;
- }
-
- _audio_merger.push (audio->data, audio->dcp_time);
-}
-
-void
-Player::flush ()
-{
- TimedAudioBuffers<DCPTime> tb = _audio_merger.flush ();
- if (tb.audio) {
- Audio (tb.audio, tb.time);
- _audio_position += _film->audio_frames_to_time (tb.audio->frames ());
- }
-
- while (_video_position < _audio_position) {
- emit_black ();
- }
-
- while (_audio_position < _video_position) {
- emit_silence (_video_position - _audio_position);
- }
-
-}
-
-/** Seek so that the next pass() will yield (approximately) the requested frame.
- * Pass accurate = true to try harder to get close to the request.
- * @return true on error
- */
-void
-Player::seek (DCPTime t, bool accurate)
-{
- if (!_have_valid_pieces) {
- setup_pieces ();
- }
-
- if (_pieces.empty ()) {
- return;
- }
-
- for (list<shared_ptr<Piece> >::iterator i = _pieces.begin(); i != _pieces.end(); ++i) {
- /* s is the offset of t from the start position of this content */
- DCPTime s = t - (*i)->content->position ();
- s = max (static_cast<DCPTime> (0), s);
- s = min ((*i)->content->length_after_trim(), s);
-
- /* Convert this to the content time */
- ContentTime ct = (s * (*i)->frc.speed_up) + (*i)->content->trim_start ();
-
- /* And seek the decoder */
- (*i)->decoder->seek (ct, accurate);
- }
-
- _video_position = time_round_up (t, TIME_HZ / _film->video_frame_rate());
- _audio_position = time_round_up (t, TIME_HZ / _film->audio_frame_rate());
-
- _audio_merger.clear (_audio_position);
-
- if (!accurate) {
- /* We just did an inaccurate seek, so it's likely that the next thing seen
- out of pass() will be a fair distance from _{video,audio}_position. Setting
- this flag stops pass() from trying to fix that: we assume that if it
- was an inaccurate seek then the caller does not care too much about
- inserting black/silence to keep the time tidy.
- */
- _just_did_inaccurate_seek = true;
- }
-}
-
-void
-Player::setup_pieces ()
-{
- list<shared_ptr<Piece> > old_pieces = _pieces;
- _pieces.clear ();
-
- ContentList content = _playlist->content ();
-
- for (ContentList::iterator i = content.begin(); i != content.end(); ++i) {
-
- shared_ptr<Decoder> decoder;
- optional<FrameRateChange> frc;
-