Merge master and multifarious hackery.
[dcpomatic.git] / src / lib / player.cc
index 8a13efd0c7e7e3b5734027a5c5bab6abec5a173c..ff13f95dbd2197be7be681ff520b29ab1ef4422b 100644 (file)
@@ -62,7 +62,7 @@ Player::Player (shared_ptr<const Film> f, shared_ptr<const Playlist> p)
        , _subtitles (true)
        , _have_valid_pieces (false)
        , _position (0)
-       , _audio_buffers (MAX_AUDIO_CHANNELS, 0)
+       , _audio_buffers (f->dcp_audio_channels(), 0)
        , _next_audio (0)
 {
        _playlist->Changed.connect (bind (&Player::playlist_changed, this));
@@ -103,13 +103,18 @@ Player::pass ()
         shared_ptr<Piece> earliest;
 
        for (list<shared_ptr<Piece> >::iterator i = _pieces.begin(); i != _pieces.end(); ++i) {
-//             cout << "check " << (*i)->decoder->next() << " cf " << (*i)->content->end() << "\n";
+               cout << "check " << (*i)->content->file() << " start=" << (*i)->content->start() << ", next=" << (*i)->decoder->next() << ", end=" << (*i)->content->end() << "\n";
                if (((*i)->decoder->next() + (*i)->content->start()) >= (*i)->content->end()) {
                        continue;
                }
+
+               if (!_audio && dynamic_pointer_cast<SndfileContent> ((*i)->content)) {
+                       continue;
+               }
                
                Time const t = (*i)->content->start() + (*i)->decoder->next();
                if (t < earliest_t) {
+                       cout << "\t candidate; " << t << " " << (t / TIME_HZ) << ".\n";
                        earliest_t = t;
                        earliest = *i;
                }
@@ -120,7 +125,7 @@ Player::pass ()
        }
 
        cout << "PASS:\n";
-       cout << "\tpass ";
+       cout << "\tpass " << earliest->content->file() << " ";
        if (dynamic_pointer_cast<FFmpegContent> (earliest->content)) {
                cout << " FFmpeg.\n";
        } else if (dynamic_pointer_cast<ImageMagickContent> (earliest->content)) {
@@ -135,6 +140,7 @@ Player::pass ()
        
        earliest->decoder->pass ();
        _position = earliest->content->start() + earliest->decoder->next ();
+       cout << "\tpassed to " << _position << " " << (_position / TIME_HZ) << "\n";
 
         return false;
 }
@@ -142,6 +148,8 @@ Player::pass ()
 void
 Player::process_video (weak_ptr<Content> weak_content, shared_ptr<const Image> image, bool same, shared_ptr<Subtitle> sub, Time time)
 {
+       cout << "[V]\n";
+       
        shared_ptr<Content> content = weak_content.lock ();
        if (!content) {
                return;
@@ -160,8 +168,6 @@ Player::process_audio (weak_ptr<Content> weak_content, shared_ptr<const AudioBuf
                return;
        }
        
-        /* XXX: mapping */
-
         /* The time of this audio may indicate that some of our buffered audio is not going to
            be added to any more, so it can be emitted.
         */
@@ -170,7 +176,8 @@ Player::process_audio (weak_ptr<Content> weak_content, shared_ptr<const AudioBuf
 
         if (time > _next_audio) {
                 /* We can emit some audio from our buffers */
-                OutputAudioFrame const N = min (_film->time_to_audio_frames (time - _next_audio), static_cast<OutputAudioFrame> (_audio_buffers.frames()));
+               assert (_film->time_to_audio_frames (time - _next_audio) <= _audio_buffers.frames());
+                OutputAudioFrame const N = _film->time_to_audio_frames (time - _next_audio);
                 shared_ptr<AudioBuffers> emit (new AudioBuffers (_audio_buffers.channels(), N));
                 emit->copy_from (&_audio_buffers, N, 0, 0);
                 Audio (emit, _next_audio);
@@ -184,8 +191,8 @@ Player::process_audio (weak_ptr<Content> weak_content, shared_ptr<const AudioBuf
         }
 
         /* Now accumulate the new audio into our buffers */
-        _audio_buffers.ensure_size (time - _next_audio + audio->frames());
-        _audio_buffers.accumulate (audio.get(), 0, _film->time_to_audio_frames (time - _next_audio));
+        _audio_buffers.ensure_size (_audio_buffers.frames() + audio->frames());
+        _audio_buffers.accumulate_frames (audio.get(), 0, 0, audio->frames ());
 }
 
 /** @return true on error */
@@ -207,6 +214,7 @@ Player::seek (Time t)
                Time s = t - (*i)->content->start ();
                s = max (static_cast<Time> (0), s);
                s = min ((*i)->content->length(), s);
+               cout << "seek [" << (*i)->content->file() << "," << (*i)->content->start() << "," << (*i)->content->end() << "] to " << s << "\n";
                (*i)->decoder->seek (s);
        }
 
@@ -217,13 +225,13 @@ Player::seek (Time t)
 void
 Player::seek_back ()
 {
-       /* XXX */
+
 }
 
 void
 Player::seek_forward ()
 {
-       /* XXX */
+
 }
 
 struct ContentSorter