summaryrefslogtreecommitdiffstats
path: root/dom/media/mediacontrol/MediaPlaybackStatus.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'dom/media/mediacontrol/MediaPlaybackStatus.cpp')
-rw-r--r--dom/media/mediacontrol/MediaPlaybackStatus.cpp64
1 files changed, 64 insertions, 0 deletions
diff --git a/dom/media/mediacontrol/MediaPlaybackStatus.cpp b/dom/media/mediacontrol/MediaPlaybackStatus.cpp
index 80dedf8599..434d6dbd7e 100644
--- a/dom/media/mediacontrol/MediaPlaybackStatus.cpp
+++ b/dom/media/mediacontrol/MediaPlaybackStatus.cpp
@@ -71,6 +71,23 @@ void MediaPlaybackStatus::UpdateMediaAudibleState(uint64_t aContextId,
}
}
+void MediaPlaybackStatus::UpdateGuessedPositionState(
+ uint64_t aContextId, const nsID& aElementId,
+ const Maybe<PositionState>& aState) {
+ MOZ_ASSERT(NS_IsMainThread());
+ if (aState) {
+ LOG("Update guessed position state for context %" PRIu64
+ " element %s (duration=%f, playbackRate=%f, position=%f)",
+ aContextId, aElementId.ToString().get(), aState->mDuration,
+ aState->mPlaybackRate, aState->mLastReportedPlaybackPosition);
+ } else {
+ LOG("Clear guessed position state for context %" PRIu64 " element %s",
+ aContextId, aElementId.ToString().get());
+ }
+ ContextMediaInfo& info = GetNotNullContextInfo(aContextId);
+ info.UpdateGuessedPositionState(aElementId, aState);
+}
+
bool MediaPlaybackStatus::IsPlaying() const {
MOZ_ASSERT(NS_IsMainThread());
return std::any_of(mContextInfoMap.Values().cbegin(),
@@ -92,6 +109,35 @@ bool MediaPlaybackStatus::IsAnyMediaBeingControlled() const {
[](const auto& info) { return info->IsAnyMediaBeingControlled(); });
}
+Maybe<PositionState> MediaPlaybackStatus::GuessedMediaPositionState(
+ Maybe<uint64_t> aPreferredContextId) const {
+ auto contextId = aPreferredContextId;
+ if (!contextId) {
+ contextId = mOwningAudioFocusContextId;
+ }
+
+ // either the preferred or focused context
+ if (contextId) {
+ auto entry = mContextInfoMap.Lookup(*contextId);
+ if (!entry) {
+ return Nothing();
+ }
+ LOG("Using guessed position state from preferred/focused BC %" PRId64,
+ *contextId);
+ return entry.Data()->GuessedPositionState();
+ }
+
+ // look for the first position state
+ for (const auto& context : mContextInfoMap.Values()) {
+ auto state = context->GuessedPositionState();
+ if (state) {
+ LOG("Using guessed position state from BC %" PRId64, context->Id());
+ return state;
+ }
+ }
+ return Nothing();
+}
+
MediaPlaybackStatus::ContextMediaInfo&
MediaPlaybackStatus::GetNotNullContextInfo(uint64_t aContextId) {
MOZ_ASSERT(NS_IsMainThread());
@@ -139,4 +185,22 @@ bool MediaPlaybackStatus::IsContextOwningAudioFocus(uint64_t aContextId) const {
: false;
}
+Maybe<PositionState>
+MediaPlaybackStatus::ContextMediaInfo::GuessedPositionState() const {
+ if (mGuessedPositionStateMap.Count() != 1) {
+ LOG("Count is %d", mGuessedPositionStateMap.Count());
+ return Nothing();
+ }
+ return Some(mGuessedPositionStateMap.begin()->GetData());
+}
+
+void MediaPlaybackStatus::ContextMediaInfo::UpdateGuessedPositionState(
+ const nsID& aElementId, const Maybe<PositionState>& aState) {
+ if (aState) {
+ mGuessedPositionStateMap.InsertOrUpdate(aElementId, *aState);
+ } else {
+ mGuessedPositionStateMap.Remove(aElementId);
+ }
+}
+
} // namespace mozilla::dom