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 #ifndef CHROMECAST_MEDIA_CMA_BACKEND_MEDIA_PIPELINE_BACKEND_MANAGER_H_ | 5 #ifndef CHROMECAST_MEDIA_CMA_BACKEND_MEDIA_PIPELINE_BACKEND_MANAGER_H_ |
6 #define CHROMECAST_MEDIA_CMA_BACKEND_MEDIA_PIPELINE_BACKEND_MANAGER_H_ | 6 #define CHROMECAST_MEDIA_CMA_BACKEND_MEDIA_PIPELINE_BACKEND_MANAGER_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <memory> | 9 #include <memory> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
14 #include "base/single_thread_task_runner.h" | 14 #include "base/single_thread_task_runner.h" |
15 #include "chromecast/public/media/media_pipeline_backend.h" | 15 #include "chromecast/public/media/media_pipeline_backend.h" |
16 #include "chromecast/public/media/media_pipeline_device_params.h" | 16 #include "chromecast/public/media/media_pipeline_device_params.h" |
17 | 17 |
18 namespace chromecast { | 18 namespace chromecast { |
19 namespace media { | 19 namespace media { |
20 | 20 |
21 // This class manages created media pipelines, and provides volume control by | 21 // This class manages created media pipelines, and provides volume control by |
22 // stream type. | 22 // stream type. |
23 // All functions in this class should be called on the media thread. | 23 // All functions in this class should be called on the media thread. |
24 class MediaPipelineBackendManager { | 24 class MediaPipelineBackendManager { |
25 public: | 25 public: |
| 26 enum DecoderType { AUDIO_DECODER, VIDEO_DECODER, NUM_DECODER_TYPES }; |
| 27 |
26 explicit MediaPipelineBackendManager( | 28 explicit MediaPipelineBackendManager( |
27 scoped_refptr<base::SingleThreadTaskRunner> media_task_runner); | 29 scoped_refptr<base::SingleThreadTaskRunner> media_task_runner); |
28 ~MediaPipelineBackendManager(); | 30 ~MediaPipelineBackendManager(); |
29 | 31 |
30 // Create media pipeline backend. | 32 // Create media pipeline backend. |
31 std::unique_ptr<MediaPipelineBackend> CreateMediaPipelineBackend( | 33 std::unique_ptr<MediaPipelineBackend> CreateMediaPipelineBackend( |
32 const MediaPipelineDeviceParams& params); | 34 const MediaPipelineDeviceParams& params); |
33 | 35 |
34 // Create media pipeline backend with a specific stream_type. | 36 // Create media pipeline backend with a specific stream_type. |
35 std::unique_ptr<MediaPipelineBackend> CreateMediaPipelineBackend( | 37 std::unique_ptr<MediaPipelineBackend> CreateMediaPipelineBackend( |
36 const MediaPipelineDeviceParams& params, | 38 const MediaPipelineDeviceParams& params, |
37 int stream_type); | 39 int stream_type); |
38 | 40 |
39 // Sets the relative volume for a specified stream type, | 41 // Sets the relative volume for a specified stream type, |
40 // with range [0.0, 1.0] inclusive. If |multiplier| is outside the | 42 // with range [0.0, 1.0] inclusive. If |multiplier| is outside the |
41 // range [0.0, 1.0], it is clamped to that range. | 43 // range [0.0, 1.0], it is clamped to that range. |
42 // TODO(tianyuwang): change stream_type to use a enum. | 44 // TODO(tianyuwang): change stream_type to use a enum. |
43 void SetVolumeMultiplier(int stream_type, float volume); | 45 void SetVolumeMultiplier(int stream_type, float volume); |
44 | 46 |
45 base::SingleThreadTaskRunner* task_runner() const { | 47 base::SingleThreadTaskRunner* task_runner() const { |
46 return media_task_runner_.get(); | 48 return media_task_runner_.get(); |
47 } | 49 } |
48 | 50 |
49 private: | 51 private: |
50 friend class MediaPipelineBackendWrapper; | 52 friend class MediaPipelineBackendWrapper; |
51 | 53 |
| 54 // Backend wrapper instances must use these APIs when allocating and releasing |
| 55 // decoder objects, so we can enforce global limit on #concurrent decoders. |
| 56 bool IncrementDecoderCount(DecoderType type); |
| 57 void DecrementDecoderCount(DecoderType type); |
| 58 |
52 // Internal clean up when a new media pipeline backend is destroyed. | 59 // Internal clean up when a new media pipeline backend is destroyed. |
53 void OnMediaPipelineBackendDestroyed(const MediaPipelineBackend* backend); | 60 void OnMediaPipelineBackendDestroyed(const MediaPipelineBackend* backend); |
54 | 61 |
55 float GetVolumeMultiplier(int stream_type); | 62 float GetVolumeMultiplier(int stream_type); |
56 | 63 |
57 const scoped_refptr<base::SingleThreadTaskRunner> media_task_runner_; | 64 const scoped_refptr<base::SingleThreadTaskRunner> media_task_runner_; |
58 | 65 |
59 // A vector that stores all of the existing media_pipeline_backends_. | 66 // A vector that stores all of the existing media_pipeline_backends_. |
60 std::vector<MediaPipelineBackend*> media_pipeline_backends_; | 67 std::vector<MediaPipelineBackend*> media_pipeline_backends_; |
61 | 68 |
| 69 // Total count of decoders created |
| 70 int decoder_count_[NUM_DECODER_TYPES]; |
| 71 |
62 // Volume multiplier for each type of audio streams. | 72 // Volume multiplier for each type of audio streams. |
63 std::map<int, float> volume_by_stream_type_; | 73 std::map<int, float> volume_by_stream_type_; |
64 | 74 |
65 DISALLOW_COPY_AND_ASSIGN(MediaPipelineBackendManager); | 75 DISALLOW_COPY_AND_ASSIGN(MediaPipelineBackendManager); |
66 }; | 76 }; |
67 | 77 |
68 } // namespace media | 78 } // namespace media |
69 } // namespace chromecast | 79 } // namespace chromecast |
70 | 80 |
71 #endif // CHROMECAST_MEDIA_CMA_BACKEND_MEDIA_PIPELINE_BACKEND_MANAGER_H_ | 81 #endif // CHROMECAST_MEDIA_CMA_BACKEND_MEDIA_PIPELINE_BACKEND_MANAGER_H_ |
OLD | NEW |