Commit dc6dc3ae authored by Becca Hughes's avatar Becca Hughes Committed by Commit Bot

[Audio Focus] Add common debug info to internals

Debug information that is common across all media
session types should be populated by media internals
instead of the sessions themselves. This removes
the need for duplicating logic across session types.

Test: MediaInternalsAudioFocusTest

BUG=875004

Change-Id: I0395e49423593d255973464658dbe41a3aa15b66
Reviewed-on: https://chromium-review.googlesource.com/c/1300103Reviewed-by: default avatarMounir Lamouri <mlamouri@chromium.org>
Commit-Queue: Becca Hughes <beccahughes@chromium.org>
Cr-Commit-Position: refs/heads/master@{#604640}
parent db8ef289
...@@ -27,6 +27,20 @@ const char kAudioFocusFunction[] = "media.onReceiveAudioFocusState"; ...@@ -27,6 +27,20 @@ const char kAudioFocusFunction[] = "media.onReceiveAudioFocusState";
const char kAudioFocusIdKey[] = "id"; const char kAudioFocusIdKey[] = "id";
const char kAudioFocusSessionsKey[] = "sessions"; const char kAudioFocusSessionsKey[] = "sessions";
const char kAudioFocusForceDuck[] = "ForceDuck";
const char kAudioFocusTypeGain[] = "Gain";
const char kAudioFocusTypeGainTransient[] = "GainTransient";
const char kAudioFocusTypeGainTransientMayDuck[] = "GainTransientMayDuck";
const char kMediaSessionStateActive[] = "Active";
const char kMediaSessionStateDucking[] = "Ducking";
const char kMediaSessionStateSuspended[] = "Suspended";
const char kMediaSessionStateInactive[] = "Inactive";
const char kMediaSessionPlaybackStatePaused[] = "Paused";
const char kMediaSessionPlaybackStatePlaying[] = "Playing";
} // namespace } // namespace
MediaInternalsAudioFocusHelper::MediaInternalsAudioFocusHelper() = default; MediaInternalsAudioFocusHelper::MediaInternalsAudioFocusHelper() = default;
...@@ -135,6 +149,7 @@ void MediaInternalsAudioFocusHelper::DidGetAudioFocusRequestList( ...@@ -135,6 +149,7 @@ void MediaInternalsAudioFocusHelper::DidGetAudioFocusRequestList(
return; return;
audio_focus_data_.Clear(); audio_focus_data_.Clear();
request_state_.clear();
// We should go backwards through the stack so the top of the stack is // We should go backwards through the stack so the top of the stack is
// always shown first in the list. // always shown first in the list.
...@@ -148,6 +163,8 @@ void MediaInternalsAudioFocusHelper::DidGetAudioFocusRequestList( ...@@ -148,6 +163,8 @@ void MediaInternalsAudioFocusHelper::DidGetAudioFocusRequestList(
media_session_data.SetKey(kAudioFocusIdKey, base::Value(id_string)); media_session_data.SetKey(kAudioFocusIdKey, base::Value(id_string));
stack_data.GetList().push_back(std::move(media_session_data)); stack_data.GetList().push_back(std::move(media_session_data));
request_state_.emplace(id_string, session.Clone());
audio_focus_debug_ptr_->GetDebugInfoForRequest( audio_focus_debug_ptr_->GetDebugInfoForRequest(
session->request_id.value(), session->request_id.value(),
base::BindOnce( base::BindOnce(
...@@ -180,9 +197,14 @@ void MediaInternalsAudioFocusHelper::DidGetAudioFocusDebugInfo( ...@@ -180,9 +197,14 @@ void MediaInternalsAudioFocusHelper::DidGetAudioFocusDebugInfo(
if (session.FindKey(kAudioFocusIdKey)->GetString() != id) if (session.FindKey(kAudioFocusIdKey)->GetString() != id)
continue; continue;
session.SetKey("name", base::Value(info->name)); auto state = request_state_.find(id);
DCHECK(state != request_state_.end());
session.SetKey("name",
base::Value(BuildNameString(state->second, info->name)));
session.SetKey("owner", base::Value(info->owner)); session.SetKey("owner", base::Value(info->owner));
session.SetKey("state", base::Value(info->state)); session.SetKey("state",
base::Value(BuildStateString(state->second, info->state)));
updated = true; updated = true;
} }
...@@ -205,4 +227,76 @@ void MediaInternalsAudioFocusHelper::SerializeAndSendUpdate( ...@@ -205,4 +227,76 @@ void MediaInternalsAudioFocusHelper::SerializeAndSendUpdate(
function, std::vector<const base::Value*>(1, value))); function, std::vector<const base::Value*>(1, value)));
} }
std::string MediaInternalsAudioFocusHelper::BuildNameString(
const media_session::mojom::AudioFocusRequestStatePtr& state,
const std::string& provided_name) const {
std::stringstream stream;
// Add the |source_name| (optional).
if (state->source_name.has_value()) {
stream << state->source_name.value();
stream << ":";
}
// Add the |request_id|.
stream << state->request_id.value().ToString();
if (!provided_name.empty())
stream << " " << provided_name;
return stream.str();
}
std::string MediaInternalsAudioFocusHelper::BuildStateString(
const media_session::mojom::AudioFocusRequestStatePtr& state,
const std::string& provided_state) const {
std::stringstream stream;
// Convert the AudioFocusType mojo enum to a string.
switch (state->audio_focus_type) {
case media_session::mojom::AudioFocusType::kGain:
stream << " " << kAudioFocusTypeGain;
break;
case media_session::mojom::AudioFocusType::kGainTransient:
stream << " " << kAudioFocusTypeGainTransient;
break;
case media_session::mojom::AudioFocusType::kGainTransientMayDuck:
stream << " " << kAudioFocusTypeGainTransientMayDuck;
break;
}
// Convert the MediaSessionInfo::SessionState mojo enum to a string.
switch (state->session_info->state) {
case media_session::mojom::MediaSessionInfo::SessionState::kActive:
stream << " " << kMediaSessionStateActive;
break;
case media_session::mojom::MediaSessionInfo::SessionState::kDucking:
stream << " " << kMediaSessionStateDucking;
break;
case media_session::mojom::MediaSessionInfo::SessionState::kSuspended:
stream << " " << kMediaSessionStateSuspended;
break;
case media_session::mojom::MediaSessionInfo::SessionState::kInactive:
stream << " " << kMediaSessionStateInactive;
break;
}
// Convert the MediaPlaybackState mojo enum to a string.
switch (state->session_info->playback_state) {
case media_session::mojom::MediaPlaybackState::kPaused:
stream << " " << kMediaSessionPlaybackStatePaused;
break;
case media_session::mojom::MediaPlaybackState::kPlaying:
stream << " " << kMediaSessionPlaybackStatePlaying;
break;
}
// Convert the |force_duck| boolean into a string.
if (state->session_info->force_duck)
stream << " " << kAudioFocusForceDuck;
if (!provided_state.empty())
stream << " " << provided_state;
return stream.str();
}
} // namespace content } // namespace content
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
#ifndef CONTENT_BROWSER_MEDIA_MEDIA_INTERNALS_AUDIO_FOCUS_HELPER_H_ #ifndef CONTENT_BROWSER_MEDIA_MEDIA_INTERNALS_AUDIO_FOCUS_HELPER_H_
#define CONTENT_BROWSER_MEDIA_MEDIA_INTERNALS_AUDIO_FOCUS_HELPER_H_ #define CONTENT_BROWSER_MEDIA_MEDIA_INTERNALS_AUDIO_FOCUS_HELPER_H_
#include <map>
#include "base/macros.h" #include "base/macros.h"
#include "mojo/public/cpp/bindings/binding.h" #include "mojo/public/cpp/bindings/binding.h"
#include "services/media_session/public/mojom/audio_focus.mojom.h" #include "services/media_session/public/mojom/audio_focus.mojom.h"
...@@ -49,12 +51,24 @@ class MediaInternalsAudioFocusHelper ...@@ -49,12 +51,24 @@ class MediaInternalsAudioFocusHelper
void SerializeAndSendUpdate(const std::string& function, void SerializeAndSendUpdate(const std::string& function,
const base::Value* value); const base::Value* value);
// Build the name of the request to display and inject values from |state|.
std::string BuildNameString(
const media_session::mojom::AudioFocusRequestStatePtr& state,
const std::string& provided_name) const;
// Inject |state| values to display in the state information.
std::string BuildStateString(
const media_session::mojom::AudioFocusRequestStatePtr& state,
const std::string& provided_state) const;
// Holds a pointer to the media session service and it's debug interface. // Holds a pointer to the media session service and it's debug interface.
media_session::mojom::AudioFocusManagerPtr audio_focus_ptr_; media_session::mojom::AudioFocusManagerPtr audio_focus_ptr_;
media_session::mojom::AudioFocusManagerDebugPtr audio_focus_debug_ptr_; media_session::mojom::AudioFocusManagerDebugPtr audio_focus_debug_ptr_;
// Must only be accessed on the UI thread. // Must only be accessed on the UI thread.
base::DictionaryValue audio_focus_data_; base::DictionaryValue audio_focus_data_;
std::map<std::string, media_session::mojom::AudioFocusRequestStatePtr>
request_state_;
bool enabled_ = false; bool enabled_ = false;
......
...@@ -37,10 +37,6 @@ const double kUnduckedVolumeMultiplier = 1.0; ...@@ -37,10 +37,6 @@ const double kUnduckedVolumeMultiplier = 1.0;
const double kDefaultDuckingVolumeMultiplier = 0.2; const double kDefaultDuckingVolumeMultiplier = 0.2;
const char kDebugInfoOwnerSeparator[] = " - "; const char kDebugInfoOwnerSeparator[] = " - ";
const char kDebugInfoDucked[] = "Ducked";
const char kDebugInfoActive[] = "Active";
const char kDebugInfoInactive[] = "Inactive";
const char kDebugInfoStateSeparator[] = " ";
using MapRenderFrameHostToDepth = std::map<RenderFrameHost*, size_t>; using MapRenderFrameHostToDepth = std::map<RenderFrameHost*, size_t>;
...@@ -660,11 +656,6 @@ void MediaSessionImpl::GetDebugInfo(GetDebugInfoCallback callback) { ...@@ -660,11 +656,6 @@ void MediaSessionImpl::GetDebugInfo(GetDebugInfoCallback callback) {
media_session::mojom::MediaSessionDebugInfoPtr info( media_session::mojom::MediaSessionDebugInfoPtr info(
media_session::mojom::MediaSessionDebugInfo::New()); media_session::mojom::MediaSessionDebugInfo::New());
// Convert the address of |this| to a string and use it as the name.
std::stringstream stream;
stream << this;
info->name = stream.str();
// Add the title and the url to the owner. // Add the title and the url to the owner.
std::vector<std::string> owner_parts; std::vector<std::string> owner_parts;
MaybePushBackString(owner_parts, MaybePushBackString(owner_parts,
...@@ -673,13 +664,6 @@ void MediaSessionImpl::GetDebugInfo(GetDebugInfoCallback callback) { ...@@ -673,13 +664,6 @@ void MediaSessionImpl::GetDebugInfo(GetDebugInfoCallback callback) {
web_contents()->GetLastCommittedURL().spec()); web_contents()->GetLastCommittedURL().spec());
info->owner = base::JoinString(owner_parts, kDebugInfoOwnerSeparator); info->owner = base::JoinString(owner_parts, kDebugInfoOwnerSeparator);
// Add the ducking state to state.
std::vector<std::string> state_parts;
MaybePushBackString(state_parts,
IsActive() ? kDebugInfoActive : kDebugInfoInactive);
MaybePushBackString(state_parts, is_ducking_ ? kDebugInfoDucked : "");
info->state = base::JoinString(state_parts, kDebugInfoStateSeparator);
std::move(callback).Run(std::move(info)); std::move(callback).Run(std::move(info));
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment