/* Emit any audio that is ready */
- optional<DCPTime> earliest_audio;
- BOOST_FOREACH (shared_ptr<Piece> i, _pieces) {
- if (i->decoder->audio) {
- DCPTime t = i->content->position()
- + DCPTime (i->decoder->audio->position(), i->frc)
- + DCPTime::from_seconds (i->content->audio->delay() / 1000.0);
-
- if (t < DCPTime()) {
- t = DCPTime();
- }
-
- if (!earliest_audio || t < *earliest_audio) {
- earliest_audio = t;
- }
+ DCPTime pull_from = _playlist->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_from) {
+ pull_from = i->second.last_push_end;
}
}
- pair<shared_ptr<AudioBuffers>, DCPTime> audio = _audio_merger.pull (earliest_audio.get_value_or(DCPTime()));
+ pair<shared_ptr<AudioBuffers>, DCPTime> audio = _audio_merger.pull (pull_from);
if (audio.first->frames() > 0) {
DCPOMATIC_ASSERT (audio.second >= _last_audio_time);
DCPTime t = _last_audio_time;
}
_audio_merger.push (content_audio.audio, time);
+
+ if (_stream_states.find (stream) == _stream_states.end ()) {
+ _stream_states[stream] = StreamState (piece, time);
+ } else {
+ _stream_states[stream].last_push_end = time + DCPTime::from_frames (content_audio.audio->frames(), _film->audio_frame_rate());
+ }
}
void
AudioMerger _audio_merger;
DCPTime _last_audio_time;
+ class StreamState {
+ public:
+ StreamState () {}
+
+ StreamState (boost::shared_ptr<Piece> p, DCPTime l)
+ : piece(p)
+ , last_push_end(l)
+ {}
+
+ boost::shared_ptr<Piece> piece;
+ DCPTime last_push_end;
+ };
+ std::map<AudioStreamPtr, StreamState> _stream_states;
+
std::list<std::pair<PlayerSubtitles, DCPTimePeriod> > _subtitles;
boost::shared_ptr<AudioProcessor> _audio_processor;
_empty_condition.notify_all ();
}
-/** Write one video frame's worth of audio frames to the DCP.
+/** Write some audio frames to the DCP.
* @param audio Audio data or 0 if there is no audio to be written here (i.e. it is referenced).
* This method is not thread safe.
*/
_audio_reel->write (audio);
- /* written is in video frames, not audio frames */
- if (_audio_reel->total_written_audio_frames() >= _audio_reel->period().duration().frames_floor (_film->video_frame_rate())) {
+ if (_audio_reel->total_written_audio_frames() >= _audio_reel->period().duration().frames_floor (_film->audio_frame_rate())) {
++_audio_reel;
}
}