#ifndef DCPOMATIC_PIECE_H
#define DCPOMATIC_PIECE_H
-#include "types.h"
+#include "audio_stream.h"
+#include "dcpomatic_time.h"
#include "frame_rate_change.h"
+#include "types.h"
class Content;
class Decoder;
public:
Piece (boost::shared_ptr<Content> c, boost::shared_ptr<Decoder> d, FrameRateChange f);
+ void update_pull_to (dcpomatic::DCPTime& pull_to) const;
+ void set_last_push_end (AudioStreamPtr stream, DCPTime last_push_end);
+
private:
std::vector<boost::shared_ptr<Content> > _content;
std::vector<boost::shared_ptr<Decoder> > _decoder;
FrameRateChange _frc;
bool _done;
+
+ std::map<AudioStreamPtr, dcpomatic::DCPTime> _stream_last_push_end;
};
#endif
}
}
- _stream_states.clear ();
- BOOST_FOREACH (shared_ptr<Piece> i, _pieces) {
- if (i->content->audio) {
- BOOST_FOREACH (AudioStreamPtr j, i->content->audio->streams()) {
- _stream_states[j] = StreamState (i, i->content->position ());
- }
- }
- }
-
_black = Empty (_film, playlist(), bind(&have_video, _1), _playback_length);
_silent = Empty (_film, playlist(), bind(&have_audio, _1), _playback_length);
of our streams, or the position of the _silent.
*/
DCPTime pull_to = _playback_length;
- for (map<AudioStreamPtr, StreamState>::const_iterator i = _stream_states.begin(); i != _stream_states.end(); ++i) {
- if (!i->second.piece->done && i->second.last_push_end < pull_to) {
- pull_to = i->second.last_push_end;
- }
+ BOOST_FOREACH (shared_ptr<Piece> i, _pieces) {
+ i->update_pull_to (pull_to);
}
if (!_silent.done() && _silent.position() < pull_to) {
pull_to = _silent.position();
/* Push */
_audio_merger.push (content_audio.audio, time);
- DCPOMATIC_ASSERT (_stream_states.find (stream) != _stream_states.end ());
- _stream_states[stream].last_push_end = time + DCPTime::from_frames (content_audio.audio->frames(), _film->audio_frame_rate());
+ /* XXX: this almost certainly needs to be more efficient; perhaps pieces fill a map to find
+ * the piece from the stream, then we can call the right piece with no loop.
+ */
+ BOOST_FOREACH (shared_ptr<Piece> i, _pieces) {
+ i->set_last_push_end (stream, time + DCPTime::from_frames(content_audio.audio->frames(), _film->audio_frame_rate()));
+ }
}
void
Shuffler* _shuffler;
std::list<std::pair<boost::shared_ptr<PlayerVideo>, dcpomatic::DCPTime> > _delay;
- class StreamState
- {
- public:
- StreamState () {}
-
- StreamState (boost::shared_ptr<Piece> p, dcpomatic::DCPTime l)
- : piece(p)
- , last_push_end(l)
- {}
-
- boost::shared_ptr<Piece> piece;
- dcpomatic::DCPTime last_push_end;
- };
- std::map<AudioStreamPtr, StreamState> _stream_states;
-
Empty _black;
Empty _silent;