blob: bf1dfc3a6e5dff0aab3ab63289fd78c389c2418b (
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
73
74
75
76
77
|
// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef MEDIA_AUDIO_MAC_AUDIO_DEVICE_LISTENER_MAC_H_
#define MEDIA_AUDIO_MAC_AUDIO_DEVICE_LISTENER_MAC_H_
#include <CoreAudio/AudioHardware.h>
#include <map>
#include <memory>
#include <utility>
#include "base/callback.h"
#include "base/containers/flat_map.h"
#include "base/memory/weak_ptr.h"
#include "base/threading/thread_checker.h"
#include "media/base/media_export.h"
namespace media {
// AudioDeviceListenerMac facilitates execution of device listener callbacks
// issued via CoreAudio.
class MEDIA_EXPORT AudioDeviceListenerMac {
public:
// |listener_cb| will be called when a device change occurs; it's a permanent
// callback and must outlive AudioDeviceListenerMac. Note that |listener_cb|
// might not be executed on the same thread as construction.
AudioDeviceListenerMac(base::RepeatingClosure listener_cb,
bool monitor_default_input = false,
bool monitor_addition_removal = false,
bool monitor_sources = false);
AudioDeviceListenerMac(const AudioDeviceListenerMac&) = delete;
AudioDeviceListenerMac& operator=(const AudioDeviceListenerMac&) = delete;
~AudioDeviceListenerMac();
private:
friend class AudioDeviceListenerMacTest;
class PropertyListener;
static const AudioObjectPropertyAddress
kDefaultOutputDeviceChangePropertyAddress;
static const AudioObjectPropertyAddress
kDefaultInputDeviceChangePropertyAddress;
static const AudioObjectPropertyAddress kDevicesPropertyAddress;
static OSStatus OnEvent(AudioObjectID object,
UInt32 num_addresses,
const AudioObjectPropertyAddress addresses[],
void* context);
bool AddPropertyListener(PropertyListener* property_listener);
void RemovePropertyListener(PropertyListener* property_listener);
void OnDevicesAddedOrRemoved();
void UpdateSourceListeners();
base::RepeatingClosure listener_cb_;
std::unique_ptr<PropertyListener> default_output_listener_;
std::unique_ptr<PropertyListener> default_input_listener_;
std::unique_ptr<PropertyListener> addition_removal_listener_;
using SourceListenerKey = std::pair<AudioObjectID, bool>;
using SourceListenerMap =
base::flat_map<SourceListenerKey, std::unique_ptr<PropertyListener>>;
SourceListenerMap source_listeners_;
// AudioDeviceListenerMac must be constructed and destructed on the same
// thread.
THREAD_CHECKER(thread_checker_);
base::WeakPtrFactory<AudioDeviceListenerMac> weak_factory_;
};
} // namespace media
#endif // MEDIA_AUDIO_MAC_AUDIO_DEVICE_LISTENER_MAC_H_
|