+/** @return Time just after the last thing that was emitted from a given stream */
+ContentTime
+AudioDecoder::stream_position (AudioStreamPtr stream) const
+{
+ PositionMap::const_iterator i = _positions.find (stream);
+ DCPOMATIC_ASSERT (i != _positions.end ());
+ return ContentTime::from_frames (i->second, _content->resampled_frame_rate());
+}
+
+ContentTime
+AudioDecoder::position () const
+{
+ optional<ContentTime> p;
+ for (PositionMap::const_iterator i = _positions.begin(); i != _positions.end(); ++i) {
+ ContentTime const ct = stream_position (i->first);
+ if (!p || ct < *p) {
+ p = ct;
+ }
+ }
+
+ return p.get_value_or(ContentTime());
+}
+
+void
+AudioDecoder::seek ()
+{
+ for (ResamplerMap::iterator i = _resamplers.begin(); i != _resamplers.end(); ++i) {
+ i->second->flush ();
+ i->second->reset ();
+ }
+
+ for (PositionMap::iterator i = _positions.begin(); i != _positions.end(); ++i) {
+ i->second = 0;
+ }
+}
+
+void
+AudioDecoder::flush ()
+{
+ for (ResamplerMap::iterator i = _resamplers.begin(); i != _resamplers.end(); ++i) {
+ shared_ptr<const AudioBuffers> ro = i->second->flush ();
+ if (ro->frames() > 0) {
+ Data (i->first, ContentAudio (ro, _positions[i->first]));
+ _positions[i->first] += ro->frames();