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/observer_list_threadsafe.h" | |
14 #include "base/single_thread_task_runner.h" | 15 #include "base/single_thread_task_runner.h" |
15 #include "chromecast/public/media/media_pipeline_backend.h" | 16 #include "chromecast/public/media/media_pipeline_backend.h" |
16 #include "chromecast/public/media/media_pipeline_device_params.h" | 17 #include "chromecast/public/media/media_pipeline_device_params.h" |
17 | 18 |
18 namespace chromecast { | 19 namespace chromecast { |
19 namespace media { | 20 namespace media { |
20 | 21 |
21 // This class manages created media pipelines, and provides volume control by | 22 // This class tracks all created media backends, tracking whether or not volume |
22 // stream type. | 23 // feedback sounds should be enabled based on the currently active backends. |
23 // All functions in this class should be called on the media thread. | 24 // Volume feedback sounds are only enabled when there are no active audio |
25 // streams (apart from sound-effects streams). | |
24 class MediaPipelineBackendManager { | 26 class MediaPipelineBackendManager { |
25 public: | 27 public: |
26 enum DecoderType { AUDIO_DECODER, VIDEO_DECODER, NUM_DECODER_TYPES }; | 28 class AllowVolumeFeedbackObserver { |
29 public: | |
30 virtual void AllowVolumeFeedbackSounds(bool allow) = 0; | |
31 | |
32 protected: | |
33 virtual ~AllowVolumeFeedbackObserver() = default; | |
34 }; | |
35 | |
36 enum DecoderType { | |
37 AUDIO_DECODER, | |
38 VIDEO_DECODER, | |
39 SFX_DECODER, | |
40 NUM_DECODER_TYPES | |
41 }; | |
27 | 42 |
28 explicit MediaPipelineBackendManager( | 43 explicit MediaPipelineBackendManager( |
29 scoped_refptr<base::SingleThreadTaskRunner> media_task_runner); | 44 scoped_refptr<base::SingleThreadTaskRunner> media_task_runner); |
30 ~MediaPipelineBackendManager(); | 45 ~MediaPipelineBackendManager(); |
31 | 46 |
32 // Create media pipeline backend. | 47 // Creates a media pipeline backend. Must be called on the same thread as |
48 // |media_task_runner_|. | |
33 std::unique_ptr<MediaPipelineBackend> CreateMediaPipelineBackend( | 49 std::unique_ptr<MediaPipelineBackend> CreateMediaPipelineBackend( |
34 const MediaPipelineDeviceParams& params); | 50 const MediaPipelineDeviceParams& params); |
35 | 51 |
36 // Create media pipeline backend with a specific stream_type. | |
37 std::unique_ptr<MediaPipelineBackend> CreateMediaPipelineBackend( | |
38 const MediaPipelineDeviceParams& params, | |
39 int stream_type); | |
40 | |
41 // Sets the relative volume for a specified stream type, | |
42 // with range [0.0, 1.0] inclusive. If |multiplier| is outside the | |
43 // range [0.0, 1.0], it is clamped to that range. | |
44 // TODO(tianyuwang): change stream_type to use a enum. | |
45 void SetVolumeMultiplier(int stream_type, float volume); | |
46 | |
47 base::SingleThreadTaskRunner* task_runner() const { | 52 base::SingleThreadTaskRunner* task_runner() const { |
48 return media_task_runner_.get(); | 53 return media_task_runner_.get(); |
49 } | 54 } |
50 | 55 |
56 // Adds/removes an observer for when folume feedback sounds are allowed. | |
halliwell
2017/02/24 21:37:21
"folume"
kmackay
2017/02/24 23:53:29
Done.
| |
57 // An observer must be removed on the same thread that added it. | |
58 void AddAllowVolumeFeedbackObserver(AllowVolumeFeedbackObserver* observer); | |
59 void RemoveAllowVolumeFeedbackObserver(AllowVolumeFeedbackObserver* observer); | |
60 | |
51 private: | 61 private: |
52 friend class MediaPipelineBackendWrapper; | 62 friend class MediaPipelineBackendWrapper; |
53 | 63 |
54 // Backend wrapper instances must use these APIs when allocating and releasing | 64 // Backend wrapper instances must use these APIs when allocating and releasing |
55 // decoder objects, so we can enforce global limit on #concurrent decoders. | 65 // decoder objects, so we can enforce global limit on #concurrent decoders. |
56 bool IncrementDecoderCount(DecoderType type); | 66 bool IncrementDecoderCount(DecoderType type); |
57 void DecrementDecoderCount(DecoderType type); | 67 void DecrementDecoderCount(DecoderType type); |
58 | 68 |
59 // Internal clean up when a new media pipeline backend is destroyed. | 69 // Update the count of playing non-effects audio streams. |
60 void OnMediaPipelineBackendDestroyed(const MediaPipelineBackend* backend); | 70 void UpdatePlayingAudioCount(int change); |
61 | |
62 float GetVolumeMultiplier(int stream_type); | |
63 | 71 |
64 const scoped_refptr<base::SingleThreadTaskRunner> media_task_runner_; | 72 const scoped_refptr<base::SingleThreadTaskRunner> media_task_runner_; |
65 | 73 |
66 // A vector that stores all of the existing media_pipeline_backends_. | |
67 std::vector<MediaPipelineBackend*> media_pipeline_backends_; | |
68 | |
69 // Total count of decoders created | 74 // Total count of decoders created |
70 int decoder_count_[NUM_DECODER_TYPES]; | 75 int decoder_count_[NUM_DECODER_TYPES]; |
71 | 76 |
72 // Volume multiplier for each type of audio streams. | 77 // Total number of playing non-effects streams. |
73 std::map<int, float> volume_by_stream_type_; | 78 int playing_noneffects_audio_streams_count_; |
79 | |
80 scoped_refptr<base::ObserverListThreadSafe<AllowVolumeFeedbackObserver>> | |
81 allow_volume_feedback_observers_; | |
74 | 82 |
75 DISALLOW_COPY_AND_ASSIGN(MediaPipelineBackendManager); | 83 DISALLOW_COPY_AND_ASSIGN(MediaPipelineBackendManager); |
76 }; | 84 }; |
77 | 85 |
78 } // namespace media | 86 } // namespace media |
79 } // namespace chromecast | 87 } // namespace chromecast |
80 | 88 |
81 #endif // CHROMECAST_MEDIA_CMA_BACKEND_MEDIA_PIPELINE_BACKEND_MANAGER_H_ | 89 #endif // CHROMECAST_MEDIA_CMA_BACKEND_MEDIA_PIPELINE_BACKEND_MANAGER_H_ |
OLD | NEW |