Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chromecast/media/cma/backend/media_pipeline_backend_manager.h" | 5 #include "chromecast/media/cma/backend/media_pipeline_backend_manager.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "chromecast/media/cma/backend/media_pipeline_backend_wrapper.h" | 10 #include "chromecast/media/cma/backend/media_pipeline_backend_wrapper.h" |
| 11 #include "chromecast/public/cast_media_shlib.h" | 11 #include "chromecast/public/cast_media_shlib.h" |
| 12 | 12 |
| 13 namespace chromecast { | 13 namespace chromecast { |
| 14 namespace media { | 14 namespace media { |
| 15 | 15 |
| 16 MediaPipelineBackendManager::MediaPipelineBackendManager( | 16 MediaPipelineBackendManager::MediaPipelineBackendManager( |
| 17 scoped_refptr<base::SingleThreadTaskRunner> media_task_runner) | 17 scoped_refptr<base::SingleThreadTaskRunner> media_task_runner) |
| 18 : media_task_runner_(std::move(media_task_runner)) { | 18 : media_task_runner_(std::move(media_task_runner)), |
| 19 } | 19 audio_decoder_count_(0), |
| 20 video_decoder_count_(0) {} | |
| 20 | 21 |
| 21 MediaPipelineBackendManager::~MediaPipelineBackendManager() { | 22 MediaPipelineBackendManager::~MediaPipelineBackendManager() { |
| 22 } | 23 } |
| 23 | 24 |
| 24 std::unique_ptr<MediaPipelineBackend> | 25 std::unique_ptr<MediaPipelineBackend> |
| 25 MediaPipelineBackendManager::CreateMediaPipelineBackend( | 26 MediaPipelineBackendManager::CreateMediaPipelineBackend( |
| 26 const media::MediaPipelineDeviceParams& params) { | 27 const media::MediaPipelineDeviceParams& params) { |
| 27 DCHECK(media_task_runner_->BelongsToCurrentThread()); | 28 DCHECK(media_task_runner_->BelongsToCurrentThread()); |
| 28 return CreateMediaPipelineBackend(params, 0); | 29 return CreateMediaPipelineBackend(params, 0); |
| 29 } | 30 } |
| 30 | 31 |
| 31 std::unique_ptr<MediaPipelineBackend> | 32 std::unique_ptr<MediaPipelineBackend> |
| 32 MediaPipelineBackendManager::CreateMediaPipelineBackend( | 33 MediaPipelineBackendManager::CreateMediaPipelineBackend( |
| 33 const media::MediaPipelineDeviceParams& params, | 34 const media::MediaPipelineDeviceParams& params, |
| 34 int stream_type) { | 35 int stream_type) { |
| 35 DCHECK(media_task_runner_->BelongsToCurrentThread()); | 36 DCHECK(media_task_runner_->BelongsToCurrentThread()); |
| 36 std::unique_ptr<MediaPipelineBackend> backend_ptr( | 37 std::unique_ptr<MediaPipelineBackend> backend_ptr( |
| 37 new MediaPipelineBackendWrapper( | 38 new MediaPipelineBackendWrapper( |
| 38 base::WrapUnique( | 39 base::WrapUnique( |
| 39 media::CastMediaShlib::CreateMediaPipelineBackend(params)), | 40 media::CastMediaShlib::CreateMediaPipelineBackend(params)), |
| 40 stream_type, GetVolumeMultiplier(stream_type), this)); | 41 stream_type, GetVolumeMultiplier(stream_type), this)); |
| 41 media_pipeline_backends_.push_back(backend_ptr.get()); | 42 media_pipeline_backends_[backend_ptr.get()] = BackendInfo(); |
| 42 return backend_ptr; | 43 return backend_ptr; |
| 43 } | 44 } |
| 44 | 45 |
| 46 bool MediaPipelineBackendManager::CanCreateAudioDecoder( | |
|
alokp
2016/07/22 04:59:46
The function name is a bit weird. In addition to r
halliwell
2016/07/22 16:34:50
Agreed :) I moved the count into the wrapper (act
| |
| 47 MediaPipelineBackend* backend) { | |
| 48 DCHECK(media_task_runner_->BelongsToCurrentThread()); | |
| 49 | |
| 50 if (audio_decoder_count_ >= 2) { | |
| 51 LOG(WARNING) << "Unable to create AudioDecoder: global limit exceeded"; | |
| 52 return false; | |
| 53 } | |
| 54 | |
| 55 auto itr = media_pipeline_backends_.find(backend); | |
| 56 DCHECK(itr != media_pipeline_backends_.end()); | |
| 57 itr->second.audio_decoder_count_++; | |
| 58 audio_decoder_count_++; | |
| 59 | |
| 60 return true; | |
| 61 } | |
| 62 | |
| 63 bool MediaPipelineBackendManager::CanCreateVideoDecoder( | |
| 64 MediaPipelineBackend* backend) { | |
| 65 DCHECK(media_task_runner_->BelongsToCurrentThread()); | |
| 66 | |
| 67 if (video_decoder_count_ >= 1) { | |
| 68 LOG(WARNING) << "Unable to create VideoDecoder: global limit exceeded"; | |
| 69 return false; | |
| 70 } | |
| 71 | |
| 72 auto itr = media_pipeline_backends_.find(backend); | |
| 73 DCHECK(itr != media_pipeline_backends_.end()); | |
| 74 itr->second.video_decoder_count_++; | |
| 75 video_decoder_count_++; | |
| 76 | |
| 77 return true; | |
| 78 } | |
| 79 | |
| 45 void MediaPipelineBackendManager::OnMediaPipelineBackendDestroyed( | 80 void MediaPipelineBackendManager::OnMediaPipelineBackendDestroyed( |
| 46 const MediaPipelineBackend* backend) { | 81 MediaPipelineBackend* backend) { |
| 47 DCHECK(media_task_runner_->BelongsToCurrentThread()); | 82 DCHECK(media_task_runner_->BelongsToCurrentThread()); |
| 48 media_pipeline_backends_.erase( | 83 |
| 49 std::remove(media_pipeline_backends_.begin(), | 84 auto itr = media_pipeline_backends_.find(backend); |
| 50 media_pipeline_backends_.end(), backend), | 85 DCHECK(itr != media_pipeline_backends_.end()); |
| 51 media_pipeline_backends_.end()); | 86 |
| 87 audio_decoder_count_ -= itr->second.audio_decoder_count_; | |
| 88 video_decoder_count_ -= itr->second.video_decoder_count_; | |
| 89 | |
| 90 media_pipeline_backends_.erase(itr); | |
| 52 } | 91 } |
| 53 | 92 |
| 54 void MediaPipelineBackendManager::SetVolumeMultiplier(int stream_type, | 93 void MediaPipelineBackendManager::SetVolumeMultiplier(int stream_type, |
| 55 float volume) { | 94 float volume) { |
| 56 DCHECK(media_task_runner_->BelongsToCurrentThread()); | 95 DCHECK(media_task_runner_->BelongsToCurrentThread()); |
| 57 volume = std::max(0.0f, std::min(volume, 1.0f)); | 96 volume = std::max(0.0f, std::min(volume, 1.0f)); |
| 58 volume_by_stream_type_[stream_type] = volume; | 97 volume_by_stream_type_[stream_type] = volume; |
| 59 | 98 |
| 60 // Set volume for each open media pipeline backends. | 99 // Set volume for each open media pipeline backends. |
| 61 for (auto it = media_pipeline_backends_.begin(); | 100 for (auto it = media_pipeline_backends_.begin(); |
| 62 it != media_pipeline_backends_.end(); it++) { | 101 it != media_pipeline_backends_.end(); it++) { |
| 63 MediaPipelineBackendWrapper* wrapper = | 102 MediaPipelineBackendWrapper* wrapper = |
| 64 static_cast<MediaPipelineBackendWrapper*>(*it); | 103 static_cast<MediaPipelineBackendWrapper*>(it->first); |
| 65 if (wrapper->GetStreamType() == stream_type) | 104 if (wrapper->GetStreamType() == stream_type) |
| 66 wrapper->SetStreamTypeVolume(volume); | 105 wrapper->SetStreamTypeVolume(volume); |
| 67 } | 106 } |
| 68 } | 107 } |
| 69 | 108 |
| 70 float MediaPipelineBackendManager::GetVolumeMultiplier(int stream_type) { | 109 float MediaPipelineBackendManager::GetVolumeMultiplier(int stream_type) { |
| 71 DCHECK(media_task_runner_->BelongsToCurrentThread()); | 110 DCHECK(media_task_runner_->BelongsToCurrentThread()); |
| 72 auto it = volume_by_stream_type_.find(stream_type); | 111 auto it = volume_by_stream_type_.find(stream_type); |
| 73 if (it == volume_by_stream_type_.end()) { | 112 if (it == volume_by_stream_type_.end()) { |
| 74 return 1.0; | 113 return 1.0; |
| 75 } else { | 114 } else { |
| 76 return it->second; | 115 return it->second; |
| 77 } | 116 } |
| 78 } | 117 } |
| 79 | 118 |
| 80 } // namespace media | 119 } // namespace media |
| 81 } // namespace chromecast | 120 } // namespace chromecast |
| OLD | NEW |