Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8103)

Unified Diff: chromecast/media/cma/backend/media_pipeline_backend_manager.cc

Issue 2712883006: [Chromecast] Add new volume control API to CastMediaShlib (Closed)
Patch Set: rebase Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chromecast/media/cma/backend/media_pipeline_backend_manager.cc
diff --git a/chromecast/media/cma/backend/media_pipeline_backend_manager.cc b/chromecast/media/cma/backend/media_pipeline_backend_manager.cc
index df0b8895edc67e32640572d6d93148a00357eea2..216b1d5f8f50afb53a62bf8b31a4abefb9d91b81 100644
--- a/chromecast/media/cma/backend/media_pipeline_backend_manager.cc
+++ b/chromecast/media/cma/backend/media_pipeline_backend_manager.cc
@@ -7,10 +7,10 @@
#include <algorithm>
#include <limits>
+#include "base/location.h"
#include "base/memory/ptr_util.h"
#include "chromecast/chromecast_features.h"
#include "chromecast/media/cma/backend/media_pipeline_backend_wrapper.h"
-#include "chromecast/public/cast_media_shlib.h"
namespace chromecast {
namespace media {
@@ -18,16 +18,19 @@ namespace {
#if BUILDFLAG(IS_CAST_AUDIO_ONLY)
constexpr int kAudioDecoderLimit = std::numeric_limits<int>::max();
#else
-constexpr int kAudioDecoderLimit = 2;
+constexpr int kAudioDecoderLimit = 1;
#endif
} // namespace
MediaPipelineBackendManager::MediaPipelineBackendManager(
scoped_refptr<base::SingleThreadTaskRunner> media_task_runner)
- : media_task_runner_(std::move(media_task_runner)) {
- DCHECK_EQ(2, NUM_DECODER_TYPES);
- decoder_count_[AUDIO_DECODER] = 0;
- decoder_count_[VIDEO_DECODER] = 0;
+ : media_task_runner_(std::move(media_task_runner)),
+ playing_noneffects_audio_streams_count_(0),
+ allow_volume_feedback_observers_(
+ new base::ObserverListThreadSafe<AllowVolumeFeedbackObserver>()) {
+ for (int i = 0; i < NUM_DECODER_TYPES; ++i) {
+ decoder_count_[i] = 0;
+ }
}
MediaPipelineBackendManager::~MediaPipelineBackendManager() {
@@ -37,22 +40,7 @@ std::unique_ptr<MediaPipelineBackend>
MediaPipelineBackendManager::CreateMediaPipelineBackend(
const media::MediaPipelineDeviceParams& params) {
DCHECK(media_task_runner_->BelongsToCurrentThread());
- return CreateMediaPipelineBackend(params, 0);
-}
-
-std::unique_ptr<MediaPipelineBackend>
-MediaPipelineBackendManager::CreateMediaPipelineBackend(
- const media::MediaPipelineDeviceParams& params,
- int stream_type) {
- DCHECK(media_task_runner_->BelongsToCurrentThread());
- LOG(INFO) << "Creating a " << params.device_id << " stream.";
- std::unique_ptr<MediaPipelineBackend> backend_ptr(
- new MediaPipelineBackendWrapper(
- base::WrapUnique(
- media::CastMediaShlib::CreateMediaPipelineBackend(params)),
- stream_type, GetVolumeMultiplier(stream_type), this));
- media_pipeline_backends_.push_back(backend_ptr.get());
- return backend_ptr;
+ return base::MakeUnique<MediaPipelineBackendWrapper>(params, this);
}
bool MediaPipelineBackendManager::IncrementDecoderCount(DecoderType type) {
@@ -72,42 +60,35 @@ void MediaPipelineBackendManager::DecrementDecoderCount(DecoderType type) {
DCHECK(media_task_runner_->BelongsToCurrentThread());
DCHECK(type < NUM_DECODER_TYPES);
DCHECK(decoder_count_[type] > 0);
+
decoder_count_[type]--;
}
-void MediaPipelineBackendManager::OnMediaPipelineBackendDestroyed(
- const MediaPipelineBackend* backend) {
- DCHECK(media_task_runner_->BelongsToCurrentThread());
- media_pipeline_backends_.erase(
- std::remove(media_pipeline_backends_.begin(),
- media_pipeline_backends_.end(), backend),
- media_pipeline_backends_.end());
-}
+void MediaPipelineBackendManager::UpdatePlayingAudioCount(int change) {
+ DCHECK(change == -1 || change == 1) << "bad count change: " << change;
-void MediaPipelineBackendManager::SetVolumeMultiplier(int stream_type,
- float volume) {
- DCHECK(media_task_runner_->BelongsToCurrentThread());
- volume = std::max(0.0f, std::min(volume, 1.0f));
- volume_by_stream_type_[stream_type] = volume;
-
- // Set volume for each open media pipeline backends.
- for (auto it = media_pipeline_backends_.begin();
- it != media_pipeline_backends_.end(); it++) {
- MediaPipelineBackendWrapper* wrapper =
- static_cast<MediaPipelineBackendWrapper*>(*it);
- if (wrapper->GetStreamType() == stream_type)
- wrapper->SetStreamTypeVolume(volume);
+ // Volume feedback sounds are only allowed when there are no non-effects
+ // audio streams playing.
+ bool prev_allow_feedback = (playing_noneffects_audio_streams_count_ == 0);
+ playing_noneffects_audio_streams_count_ += change;
+ DCHECK_GE(playing_noneffects_audio_streams_count_, 0);
+ bool new_allow_feedback = (playing_noneffects_audio_streams_count_ == 0);
+
+ if (new_allow_feedback != prev_allow_feedback) {
+ allow_volume_feedback_observers_->Notify(
+ FROM_HERE, &AllowVolumeFeedbackObserver::AllowVolumeFeedbackSounds,
+ new_allow_feedback);
}
}
-float MediaPipelineBackendManager::GetVolumeMultiplier(int stream_type) {
- DCHECK(media_task_runner_->BelongsToCurrentThread());
- auto it = volume_by_stream_type_.find(stream_type);
- if (it == volume_by_stream_type_.end()) {
- return 1.0;
- } else {
- return it->second;
- }
+void MediaPipelineBackendManager::AddAllowVolumeFeedbackObserver(
+ AllowVolumeFeedbackObserver* observer) {
+ allow_volume_feedback_observers_->AddObserver(observer);
+}
+
+void MediaPipelineBackendManager::RemoveAllowVolumeFeedbackObserver(
+ AllowVolumeFeedbackObserver* observer) {
+ allow_volume_feedback_observers_->RemoveObserver(observer);
}
} // namespace media

Powered by Google App Engine
This is Rietveld 408576698