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

Side by Side Diff: content/browser/renderer_host/media/audio_output_device_enumerator.h

Issue 2368213002: Remove AudioOutputDeviceEnumerator. Replace usage with MediaDevicesManager. (Closed)
Patch Set: Remove BoolDeviceTypes std::array literals Created 4 years, 2 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
(Empty)
1 // Copyright (c) 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 // AudioOutputDeviceEnumerator is used to enumerate audio output devices.
6 // It can return cached results of previous enumerations in order to boost
7 // performance.
8 // All its public methods must be called on the thread where the object is
9 // created.
10
11 #ifndef CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_OUTPUT_DEVICE_ENUMERATOR_H_
12 #define CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_OUTPUT_DEVICE_ENUMERATOR_H_
13
14 #include <stdint.h>
15
16 #include <list>
17 #include <memory>
18 #include <string>
19 #include <vector>
20
21 #include "base/callback.h"
22 #include "base/macros.h"
23 #include "base/memory/weak_ptr.h"
24 #include "base/threading/thread_checker.h"
25 #include "content/common/content_export.h"
26 #include "media/base/audio_parameters.h"
27
28 namespace base {
29 class SingleThreadTaskRunner;
30 }
31
32 namespace media {
33 class AudioManager;
34 }
35
36 namespace content {
37
38 // AudioOutputDeviceInfo describes information about an audio output device.
39 // The enumerations returned by AudioOutputDeviceEnumerator::Enumerate() contain
40 // elements of this type. It is used only in the browser side.
41 struct AudioOutputDeviceInfo {
42 AudioOutputDeviceInfo();
43 AudioOutputDeviceInfo(const AudioOutputDeviceInfo& audio_output_device_info);
44 AudioOutputDeviceInfo(AudioOutputDeviceInfo&& audio_output_device_info);
45 AudioOutputDeviceInfo& operator=(
46 const AudioOutputDeviceInfo& audio_output_device_info);
47 AudioOutputDeviceInfo(const std::string& unique_id,
48 const std::string& device_name,
49 const std::string& group_id,
50 media::AudioParameters output_params);
51 ~AudioOutputDeviceInfo();
52 std::string unique_id;
53 std::string device_name;
54 std::string group_id;
55 media::AudioParameters output_params;
56 };
57
58 // The result of an enumeration. It is used only in the browser side.
59 struct AudioOutputDeviceEnumeration {
60 public:
61 AudioOutputDeviceEnumeration(
62 const std::vector<AudioOutputDeviceInfo>& devices,
63 bool has_actual_devices);
64 AudioOutputDeviceEnumeration();
65 AudioOutputDeviceEnumeration(const AudioOutputDeviceEnumeration& other);
66 ~AudioOutputDeviceEnumeration();
67
68 std::vector<AudioOutputDeviceInfo> devices;
69 bool has_actual_devices;
70 };
71
72 typedef base::Callback<void(const AudioOutputDeviceEnumeration&)>
73 AudioOutputDeviceEnumerationCB;
74
75 class CONTENT_EXPORT AudioOutputDeviceEnumerator {
76 public:
77 enum CachePolicy {
78 CACHE_POLICY_NO_CACHING,
79 CACHE_POLICY_MANUAL_INVALIDATION
80 };
81 AudioOutputDeviceEnumerator(media::AudioManager* audio_manager,
82 CachePolicy cache_policy);
83 ~AudioOutputDeviceEnumerator();
84
85 // Does an enumeration and provides the results to the callback.
86 // If there are no physical devices, the result contains a single entry with
87 // the default parameters provided by the underlying audio manager and with
88 // the |has_actual_devices| field set to false.
89 // The behavior with no physical devices is there to ease the transition
90 // from the use of RenderThreadImpl::GetAudioHardwareConfig(), which always
91 // provides default parameters, even if there are no devices.
92 // See https://crbug.com/549125.
93 // Some audio managers always report a single device, regardless of the
94 // physical devices in the system. In this case the |has_actual_devices| field
95 // is set to true to differentiate from the case of no physical devices.
96 void Enumerate(const AudioOutputDeviceEnumerationCB& callback);
97
98 // Invalidates the current cache.
99 void InvalidateCache();
100
101 // Sets the cache policy.
102 void SetCachePolicy(CachePolicy cache_policy);
103
104 // Returns true if the caching policy is different from
105 // CACHE_POLICY_NO_CACHING, false otherwise.
106 bool IsCacheEnabled();
107
108 private:
109 void InitializeOnIOThread();
110 void DoEnumerateDevices();
111 AudioOutputDeviceEnumeration DoEnumerateDevicesOnDeviceThread();
112 void DevicesEnumerated(const AudioOutputDeviceEnumeration& snapshot);
113 int64_t NewEventSequence();
114 bool IsLastEnumerationValid() const;
115
116 media::AudioManager* const audio_manager_;
117 CachePolicy cache_policy_;
118 AudioOutputDeviceEnumeration cache_;
119 std::list<AudioOutputDeviceEnumerationCB> pending_callbacks_;
120
121 // sequential number that serves as logical clock
122 int64_t current_event_sequence_;
123
124 int64_t seq_last_enumeration_;
125 int64_t seq_last_invalidation_;
126 bool is_enumeration_ongoing_;
127
128 base::ThreadChecker thread_checker_;
129 base::WeakPtrFactory<AudioOutputDeviceEnumerator> weak_factory_;
130
131 DISALLOW_COPY_AND_ASSIGN(AudioOutputDeviceEnumerator);
132 };
133
134 } // namespace content
135
136 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_OUTPUT_DEVICE_ENUMERATOR_H_
OLDNEW
« no previous file with comments | « content/browser/BUILD.gn ('k') | content/browser/renderer_host/media/audio_output_device_enumerator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698