summaryrefslogtreecommitdiffstats
path: root/chromecast/media/cma/backend/media_pipeline_backend_manager.h
blob: 890dfc8610ef4488efa800efe403391b97ba5ff0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROMECAST_MEDIA_CMA_BACKEND_MEDIA_PIPELINE_BACKEND_MANAGER_H_
#define CHROMECAST_MEDIA_CMA_BACKEND_MEDIA_PIPELINE_BACKEND_MANAGER_H_

#include <map>
#include <vector>

#include "base/macros.h"
#include "base/memory/scoped_ptr.h"
#include "chromecast/public/media/media_pipeline_backend.h"
#include "chromecast/public/media/media_pipeline_device_params.h"

namespace base {
template <typename T>
struct DefaultLazyInstanceTraits;
}  // namespace base

namespace chromecast {
namespace media {

// This class manages created media pipelines, and provides volume control by
// stream type.
// All functions in this class should be called on the media thread.
class MediaPipelineBackendManager {
 public:
  // Create media pipeline backend.
  static MediaPipelineBackend* CreateMediaPipelineBackend(
      const MediaPipelineDeviceParams& params);

  // Create media pipeline backend with a specific stream_type.
  static MediaPipelineBackend* CreateMediaPipelineBackend(
      const MediaPipelineDeviceParams& params,
      int stream_type);

  // Internal clean up when a new media pipeline backend is destroyed.
  static void OnMediaPipelineBackendDestroyed(
      const MediaPipelineBackend* backend);

  // Sets the relative volume for a specified stream type,
  // with range [0.0, 1.0] inclusive. If |multiplier| is outside the
  // range [0.0, 1.0], it is clamped to that range.
  // TODO(tianyuwang): change stream_type to use a enum.
  static void SetVolumeMultiplier(int stream_type, float volume);

 private:
  friend struct base::DefaultLazyInstanceTraits<MediaPipelineBackendManager>;

  // Returns a pointer to a singleton instance of the
  // MediaPipelineBackendManager.
  static MediaPipelineBackendManager* Get();

  MediaPipelineBackendManager();
  ~MediaPipelineBackendManager();

  float GetVolumeMultiplier(int stream_type);

  // A vector that stores all of the existing media_pipeline_backends_.
  std::vector<MediaPipelineBackend*> media_pipeline_backends_;

  // Volume multiplier for each type of audio streams.
  std::map<int, float> volume_by_stream_type_;

  DISALLOW_COPY_AND_ASSIGN(MediaPipelineBackendManager);
};

}  // namespace media
}  // namespace chromecast

#endif  // CHROMECAST_MEDIA_CMA_BACKEND_MEDIA_PIPELINE_BACKEND_MANAGER_H_