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

Side by Side Diff: chromecast/media/cma/backend/media_pipeline_backend_wrapper.cc

Issue 2173593002: [Chromecast] Limit number of concurrent audio and video decoders (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Increment/decrement API Created 4 years, 5 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 unified diff | Download patch
OLDNEW
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_wrapper.h" 5 #include "chromecast/media/cma/backend/media_pipeline_backend_wrapper.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "chromecast/media/cma/backend/media_pipeline_backend_manager.h" 8 #include "chromecast/media/cma/backend/media_pipeline_backend_manager.h"
9 9
10 namespace chromecast { 10 namespace chromecast {
11 namespace media { 11 namespace media {
12 12
13 MediaPipelineBackendWrapper::MediaPipelineBackendWrapper( 13 MediaPipelineBackendWrapper::MediaPipelineBackendWrapper(
14 std::unique_ptr<MediaPipelineBackend> backend, 14 std::unique_ptr<MediaPipelineBackend> backend,
15 int stream_type, 15 int stream_type,
16 float stream_type_volume, 16 float stream_type_volume,
17 MediaPipelineBackendManager* backend_manager) 17 MediaPipelineBackendManager* backend_manager)
18 : backend_(std::move(backend)), 18 : backend_(std::move(backend)),
19 stream_type_(stream_type), 19 stream_type_(stream_type),
20 audio_decoder_wrapper_(nullptr), 20 audio_decoder_wrapper_(nullptr),
21 stream_type_volume_(stream_type_volume), 21 stream_type_volume_(stream_type_volume),
22 is_initialized_(false), 22 is_initialized_(false),
23 have_video_decoder_(false),
23 backend_manager_(backend_manager) { 24 backend_manager_(backend_manager) {
24 DCHECK(backend_); 25 DCHECK(backend_);
25 } 26 }
26 27
27 MediaPipelineBackendWrapper::~MediaPipelineBackendWrapper() { 28 MediaPipelineBackendWrapper::~MediaPipelineBackendWrapper() {
28 backend_manager_->OnMediaPipelineBackendDestroyed(this); 29 backend_manager_->OnMediaPipelineBackendDestroyed(this);
30
31 if (audio_decoder_wrapper_)
32 backend_manager_->DecrementAudioDecoderCount();
33 if (have_video_decoder_)
34 backend_manager_->DecrementVideoDecoderCount();
kmackay 2016/07/22 16:50:07 Can't we have multiple video decoders (for DolbyVi
kmackay 2016/07/22 16:53:08 I think, since the API allows you to create multip
halliwell 2016/07/22 17:16:29 DV is handled by a single video decoder. You can
halliwell 2016/07/22 17:16:29 Although the API does, the implementation doesn't
29 } 35 }
30 36
31 MediaPipelineBackend::AudioDecoder* 37 MediaPipelineBackend::AudioDecoder*
32 MediaPipelineBackendWrapper::CreateAudioDecoder() { 38 MediaPipelineBackendWrapper::CreateAudioDecoder() {
33 DCHECK(!is_initialized_); 39 DCHECK(!is_initialized_);
34 if (audio_decoder_wrapper_) 40 if (audio_decoder_wrapper_)
35 return nullptr; 41 return nullptr;
36 42
43 if (!backend_manager_->IncrementAudioDecoderCount())
44 return nullptr;
45
37 audio_decoder_wrapper_.reset( 46 audio_decoder_wrapper_.reset(
38 new AudioDecoderWrapper(backend_->CreateAudioDecoder())); 47 new AudioDecoderWrapper(backend_->CreateAudioDecoder()));
39 return audio_decoder_wrapper_.get(); 48 return audio_decoder_wrapper_.get();
40 } 49 }
41 50
42 MediaPipelineBackend::VideoDecoder* 51 MediaPipelineBackend::VideoDecoder*
43 MediaPipelineBackendWrapper::CreateVideoDecoder() { 52 MediaPipelineBackendWrapper::CreateVideoDecoder() {
44 DCHECK(!is_initialized_); 53 DCHECK(!is_initialized_);
54 if (!backend_manager_->IncrementVideoDecoderCount())
55 return nullptr;
56 have_video_decoder_ = true;
57
45 return backend_->CreateVideoDecoder(); 58 return backend_->CreateVideoDecoder();
46 } 59 }
47 60
48 bool MediaPipelineBackendWrapper::Initialize() { 61 bool MediaPipelineBackendWrapper::Initialize() {
49 DCHECK(!is_initialized_); 62 DCHECK(!is_initialized_);
50 is_initialized_ = backend_->Initialize(); 63 is_initialized_ = backend_->Initialize();
51 if (is_initialized_ && audio_decoder_wrapper_) 64 if (is_initialized_ && audio_decoder_wrapper_)
52 audio_decoder_wrapper_->SetStreamTypeVolume(stream_type_volume_); 65 audio_decoder_wrapper_->SetStreamTypeVolume(stream_type_volume_);
53 66
54 return is_initialized_; 67 return is_initialized_;
(...skipping 29 matching lines...) Expand all
84 97
85 void MediaPipelineBackendWrapper::SetStreamTypeVolume( 98 void MediaPipelineBackendWrapper::SetStreamTypeVolume(
86 float stream_type_volume) { 99 float stream_type_volume) {
87 stream_type_volume_ = stream_type_volume; 100 stream_type_volume_ = stream_type_volume;
88 if (is_initialized_ && audio_decoder_wrapper_) 101 if (is_initialized_ && audio_decoder_wrapper_)
89 audio_decoder_wrapper_->SetStreamTypeVolume(stream_type_volume_); 102 audio_decoder_wrapper_->SetStreamTypeVolume(stream_type_volume_);
90 } 103 }
91 104
92 } // namespace media 105 } // namespace media
93 } // namespace chromecast 106 } // namespace chromecast
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698