bool
have_audio (shared_ptr<const Content> content)
{
- return static_cast<bool>(content->audio) && content->can_be_played();
+ return content->has_mapped_audio() && content->can_be_played();
}
_stream_states.clear ();
for (auto i: _pieces) {
- if (i->content->audio) {
+ if (i->content->has_mapped_audio()) {
for (auto j: i->content->audio->streams()) {
_stream_states[j] = StreamState(i);
}
}
+pair<shared_ptr<Piece>, optional<DCPTime>>
+Player::earliest_piece_and_time() const
+{
+ auto film = _film.lock();
+ DCPOMATIC_ASSERT(film);
+
+ shared_ptr<Piece> earliest_content;
+ optional<DCPTime> earliest_time;
+
+ for (auto const& piece: _pieces) {
+ if (piece->done) {
+ continue;
+ }
+
+ auto const t = content_time_to_dcp(piece, max(piece->decoder->position(), piece->content->trim_start()));
+ if (t > piece->content->end(film)) {
+ piece->done = true;
+ } else {
+
+ /* Given two choices at the same time, pick the one with texts so we see it before
+ the video.
+ */
+ if (!earliest_time || t < *earliest_time || (t == *earliest_time && !piece->decoder->text.empty())) {
+ earliest_time = t;
+ earliest_content = piece;
+ }
+ }
+ }
+
+ return { earliest_content, earliest_time };
+}
+
+
bool
Player::pass ()
{
shared_ptr<Piece> earliest_content;
optional<DCPTime> earliest_time;
-
- for (auto i: _pieces) {
- if (i->done) {
- continue;
- }
-
- auto const t = content_time_to_dcp (i, max(i->decoder->position(), i->content->trim_start()));
- if (t > i->content->end(film)) {
- i->done = true;
- } else {
-
- /* Given two choices at the same time, pick the one with texts so we see it before
- the video.
- */
- if (!earliest_time || t < *earliest_time || (t == *earliest_time && !i->decoder->text.empty())) {
- earliest_time = t;
- earliest_content = i;
- }
- }
- }
+ std::tie(earliest_content, earliest_time) = earliest_piece_and_time();
bool done = false;
_disable_audio_processor = true;
}
+
+Frame
+Player::frames_done() const
+{
+ auto film = _film.lock();
+ DCPOMATIC_ASSERT(film);
+
+ shared_ptr<Piece> earliest_content;
+ optional<DCPTime> earliest_time;
+ std::tie(earliest_content, earliest_time) = earliest_piece_and_time();
+
+ return earliest_time.get_value_or({}).frames_round(film->video_frame_rate());
+}
+
+
+float
+Player::progress() const
+{
+ auto film = _film.lock();
+ DCPOMATIC_ASSERT(film);
+
+ shared_ptr<Piece> earliest_content;
+ optional<DCPTime> earliest_time;
+ std::tie(earliest_content, earliest_time) = earliest_piece_and_time();
+
+ return static_cast<float>(earliest_time.get_value_or({}).get()) / film->length().get();
+}