Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / content / browser / renderer_host / media / audio_output_device_enumerator.h
blob05e51cf40384ba73ff47b7171a4c5ccf38eab7f9
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.
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.
11 #ifndef CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_OUTPUT_DEVICE_ENUMERATOR_H_
12 #define CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_OUTPUT_DEVICE_ENUMERATOR_H_
14 #include <stdint.h>
15 #include <list>
16 #include <string>
17 #include <vector>
19 #include "base/callback.h"
20 #include "base/macros.h"
21 #include "base/memory/scoped_ptr.h"
22 #include "base/memory/weak_ptr.h"
23 #include "base/threading/thread_checker.h"
24 #include "content/common/content_export.h"
25 #include "media/audio/audio_parameters.h"
27 namespace base {
28 class SingleThreadTaskRunner;
31 namespace media {
32 class AudioManager;
35 namespace content {
37 // AudioOutputDeviceInfo describes information about an audio output device.
38 // The enumerations returned by AudioOutputDeviceEnumerator::Enumerate() contain
39 // elements of this type. It is used only in the browser side.
40 struct AudioOutputDeviceInfo {
41 std::string unique_id;
42 std::string device_name;
43 media::AudioParameters output_params;
46 typedef std::vector<AudioOutputDeviceInfo> AudioOutputDeviceEnumeration;
47 typedef base::Callback<void(const AudioOutputDeviceEnumeration&)>
48 AudioOutputDeviceEnumerationCB;
50 class CONTENT_EXPORT AudioOutputDeviceEnumerator {
51 public:
52 enum CachePolicy {
53 CACHE_POLICY_NO_CACHING,
54 CACHE_POLICY_MANUAL_INVALIDATION
56 AudioOutputDeviceEnumerator(media::AudioManager* audio_manager,
57 CachePolicy cache_policy);
58 ~AudioOutputDeviceEnumerator();
60 // Must be called on the IO thread. |callback| is also invoked
61 // on the IO thread.
62 void Enumerate(const AudioOutputDeviceEnumerationCB& callback);
64 // Invalidates the current cache. Must be called on the IO thread.
65 void InvalidateCache();
67 // Sets the cache policy. Must be called on the IO thread.
68 void SetCachePolicy(CachePolicy cache_policy);
70 private:
71 void InitializeOnIOThread();
72 void DoEnumerateDevices();
73 AudioOutputDeviceEnumeration DoEnumerateDevicesOnDeviceThread();
74 void DevicesEnumerated(const AudioOutputDeviceEnumeration& snapshot);
75 int64_t NewEventSequence();
76 bool IsLastEnumerationValid() const;
78 media::AudioManager* const audio_manager_;
79 CachePolicy cache_policy_;
80 AudioOutputDeviceEnumeration cache_;
81 std::list<AudioOutputDeviceEnumerationCB> pending_callbacks_;
83 // sequential number that serves as logical clock
84 int64_t current_event_sequence_;
86 int64_t seq_last_enumeration_;
87 int64_t seq_last_invalidation_;
88 bool is_enumeration_ongoing_;
90 base::ThreadChecker thread_checker_;
91 base::WeakPtrFactory<AudioOutputDeviceEnumerator> weak_factory_;
93 DISALLOW_COPY_AND_ASSIGN(AudioOutputDeviceEnumerator);
96 } // namespace content
98 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_OUTPUT_DEVICE_ENUMERATOR_H_