Skip to content

Commit

Permalink
Make AudioContentType/VolumeChangeSource easier to print
Browse files Browse the repository at this point in the history
No need to add XXXToString helper function in each file.

Bug: None
Change-Id: Ie717defac4f4444aeab207de472ae190f935ac1e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2220359
Commit-Queue: Linkun Chen <lkchen@chromium.org>
Reviewed-by: Sergey Volk <servolk@chromium.org>
Cr-Commit-Position: refs/heads/master@{#778526}
  • Loading branch information
Linkun Chen authored and Commit Bot committed Jun 15, 2020
1 parent 7c83aef commit 5ea1bc1
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 2 deletions.
9 changes: 9 additions & 0 deletions chromecast/common/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ cast_source_set("resource_delegate") {
]
}

cast_source_set("volume_control_enum_printer") {
sources = [ "volume_control_enum_printer.cc" ]

deps = [
"//base",
"//chromecast/public",
]
}

cast_source_set("activity_url_filter") {
sources = [
"activity_filtering_url_loader_throttle.cc",
Expand Down
41 changes: 41 additions & 0 deletions chromecast/common/volume_control_enum_printer.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chromecast/public/volume_control.h"

#include "base/notreached.h"

namespace chromecast {
namespace media {

std::ostream& operator<<(std::ostream& os, AudioContentType audio_type) {
switch (audio_type) {
case AudioContentType::kMedia:
return os << "MEDIA";
case AudioContentType::kAlarm:
return os << "ALARM";
case AudioContentType::kCommunication:
return os << "COMMUNICATION";
case AudioContentType::kOther:
return os << "OTHER";
default:
NOTREACHED()
<< "Add a new entry above, otherwise kNumTypes is not a valid type.";
return os << "UNKNOWN";
}
}

std::ostream& operator<<(std::ostream& os,
VolumeChangeSource vol_change_source) {
switch (vol_change_source) {
case VolumeChangeSource::kUser:
return os << "USER";
case VolumeChangeSource::kAutomatic:
return os << "AUTOMATIC";
case VolumeChangeSource::kAutoWithFeedback:
return os << "AUTO_WITH_FEEDBACK";
}
}

} // namespace media
} // namespace chromecast
1 change: 1 addition & 0 deletions chromecast/media/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ test("cast_media_unittests") {
"//chromecast:chromecast_buildflags",
"//chromecast/base",
"//chromecast/base/metrics:test_support",
"//chromecast/common:volume_control_enum_printer",
"//chromecast/common/mojom",
"//chromecast/media/api:test_support",
"//chromecast/media/audio:unittests",
Expand Down
1 change: 1 addition & 0 deletions chromecast/media/cma/backend/mixer/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ cast_source_set("mixer") {
"//chromecast/base",
"//chromecast/base:chromecast_switches",
"//chromecast/base:thread_health_checker",
"//chromecast/common:volume_control_enum_printer",
"//chromecast/media/audio:audio_io_thread",
"//chromecast/media/audio:interleaved_channel_mixer",
"//chromecast/media/audio:libcast_external_audio_pipeline_1.0",
Expand Down
3 changes: 1 addition & 2 deletions chromecast/media/cma/backend/mixer/stream_mixer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -908,8 +908,7 @@ void StreamMixer::SetOutputLimit(AudioContentType type, float limit) {
MAKE_SURE_MIXER_THREAD(SetOutputLimit, type, limit);
DCHECK(type != AudioContentType::kOther);

LOG(INFO) << "Set volume limit for " << static_cast<int>(type) << " to "
<< limit;
LOG(INFO) << "Set volume limit for " << type << " to " << limit;
volume_info_[type].limit = limit;
int fade_ms = kUseDefaultFade;
if (type == AudioContentType::kMedia) {
Expand Down
10 changes: 10 additions & 0 deletions chromecast/public/volume_control.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#ifndef CHROMECAST_PUBLIC_VOLUME_CONTROL_H_
#define CHROMECAST_PUBLIC_VOLUME_CONTROL_H_

#include <ostream>
#include <string>
#include <vector>

Expand All @@ -24,6 +25,10 @@ enum class AudioContentType {
kNumTypes, // Not a valid type; should always be last in the enum.
};

// In case of link issue, implement it by your own or depend on
// c/common/volume_control_enum_printer
std::ostream& operator<<(std::ostream& os, AudioContentType audio_type);

// Different sources of volume changes. Used to change behaviour (eg feedback
// sounds) based on the source.
enum class VolumeChangeSource {
Expand All @@ -33,6 +38,11 @@ enum class VolumeChangeSource {
// volume feedback UX.
};

// In case of link issue, implement it by your own or depend on
// c/common/volume_control_enum_printer
std::ostream& operator<<(std::ostream& os,
VolumeChangeSource vol_change_source);

// Observer for volume/mute state changes. This is useful to detect volume
// changes that occur outside of cast_shell. Add/RemoveVolumeObserver() must not
// be called synchronously from OnVolumeChange() or OnMuteChange(). Note that
Expand Down

0 comments on commit 5ea1bc1

Please sign in to comment.