| 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 <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/memory/ref_counted.h" |
| 12 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/single_thread_task_runner.h" |
| 13 #include "chromecast/public/media/media_pipeline_backend.h" | 15 #include "chromecast/public/media/media_pipeline_backend.h" |
| 14 #include "chromecast/public/media/media_pipeline_device_params.h" | 16 #include "chromecast/public/media/media_pipeline_device_params.h" |
| 15 | 17 |
| 16 namespace base { | |
| 17 template <typename T> | |
| 18 struct DefaultLazyInstanceTraits; | |
| 19 } // namespace base | |
| 20 | |
| 21 namespace chromecast { | 18 namespace chromecast { |
| 22 namespace media { | 19 namespace media { |
| 23 | 20 |
| 24 // This class manages created media pipelines, and provides volume control by | 21 // This class manages created media pipelines, and provides volume control by |
| 25 // stream type. | 22 // stream type. |
| 26 // 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. |
| 27 class MediaPipelineBackendManager { | 24 class MediaPipelineBackendManager { |
| 28 public: | 25 public: |
| 26 explicit MediaPipelineBackendManager( |
| 27 scoped_refptr<base::SingleThreadTaskRunner> media_task_runner); |
| 28 ~MediaPipelineBackendManager(); |
| 29 |
| 29 // Create media pipeline backend. | 30 // Create media pipeline backend. |
| 30 static MediaPipelineBackend* CreateMediaPipelineBackend( | 31 scoped_ptr<MediaPipelineBackend> CreateMediaPipelineBackend( |
| 31 const MediaPipelineDeviceParams& params); | 32 const MediaPipelineDeviceParams& params); |
| 32 | 33 |
| 33 // Create media pipeline backend with a specific stream_type. | 34 // Create media pipeline backend with a specific stream_type. |
| 34 static MediaPipelineBackend* CreateMediaPipelineBackend( | 35 scoped_ptr<MediaPipelineBackend> CreateMediaPipelineBackend( |
| 35 const MediaPipelineDeviceParams& params, | 36 const MediaPipelineDeviceParams& params, |
| 36 int stream_type); | 37 int stream_type); |
| 37 | 38 |
| 38 // Internal clean up when a new media pipeline backend is destroyed. | |
| 39 static void OnMediaPipelineBackendDestroyed( | |
| 40 const MediaPipelineBackend* backend); | |
| 41 | |
| 42 // Sets the relative volume for a specified stream type, | 39 // Sets the relative volume for a specified stream type, |
| 43 // with range [0.0, 1.0] inclusive. If |multiplier| is outside the | 40 // with range [0.0, 1.0] inclusive. If |multiplier| is outside the |
| 44 // range [0.0, 1.0], it is clamped to that range. | 41 // range [0.0, 1.0], it is clamped to that range. |
| 45 // TODO(tianyuwang): change stream_type to use a enum. | 42 // TODO(tianyuwang): change stream_type to use a enum. |
| 46 static void SetVolumeMultiplier(int stream_type, float volume); | 43 void SetVolumeMultiplier(int stream_type, float volume); |
| 44 |
| 45 base::SingleThreadTaskRunner* task_runner() const { |
| 46 return media_task_runner_.get(); |
| 47 } |
| 47 | 48 |
| 48 private: | 49 private: |
| 49 friend struct base::DefaultLazyInstanceTraits<MediaPipelineBackendManager>; | 50 friend class MediaPipelineBackendWrapper; |
| 50 | 51 |
| 51 // Returns a pointer to a singleton instance of the | 52 // Internal clean up when a new media pipeline backend is destroyed. |
| 52 // MediaPipelineBackendManager. | 53 void OnMediaPipelineBackendDestroyed(const MediaPipelineBackend* backend); |
| 53 static MediaPipelineBackendManager* Get(); | |
| 54 | |
| 55 MediaPipelineBackendManager(); | |
| 56 ~MediaPipelineBackendManager(); | |
| 57 | 54 |
| 58 float GetVolumeMultiplier(int stream_type); | 55 float GetVolumeMultiplier(int stream_type); |
| 59 | 56 |
| 57 const scoped_refptr<base::SingleThreadTaskRunner> media_task_runner_; |
| 58 |
| 60 // A vector that stores all of the existing media_pipeline_backends_. | 59 // A vector that stores all of the existing media_pipeline_backends_. |
| 61 std::vector<MediaPipelineBackend*> media_pipeline_backends_; | 60 std::vector<MediaPipelineBackend*> media_pipeline_backends_; |
| 62 | 61 |
| 63 // Volume multiplier for each type of audio streams. | 62 // Volume multiplier for each type of audio streams. |
| 64 std::map<int, float> volume_by_stream_type_; | 63 std::map<int, float> volume_by_stream_type_; |
| 65 | 64 |
| 66 DISALLOW_COPY_AND_ASSIGN(MediaPipelineBackendManager); | 65 DISALLOW_COPY_AND_ASSIGN(MediaPipelineBackendManager); |
| 67 }; | 66 }; |
| 68 | 67 |
| 69 } // namespace media | 68 } // namespace media |
| 70 } // namespace chromecast | 69 } // namespace chromecast |
| 71 | 70 |
| 72 #endif // CHROMECAST_MEDIA_CMA_BACKEND_MEDIA_PIPELINE_BACKEND_MANAGER_H_ | 71 #endif // CHROMECAST_MEDIA_CMA_BACKEND_MEDIA_PIPELINE_BACKEND_MANAGER_H_ |
| OLD | NEW |