audio_device_listener_mac.h revision 868fa2fe829687343ffae624259930155e16dbd8
1// Copyright (c) 2012 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#ifndef MEDIA_AUDIO_MAC_AUDIO_DEVICE_LISTENER_MAC_H_
6#define MEDIA_AUDIO_MAC_AUDIO_DEVICE_LISTENER_MAC_H_
7
8#include <CoreAudio/AudioHardware.h>
9
10#include "base/basictypes.h"
11#include "base/callback.h"
12#include "base/threading/thread_checker.h"
13#include "media/base/media_export.h"
14
15namespace media {
16
17// AudioDeviceListenerMac facilitates execution of device listener callbacks
18// issued via CoreAudio.
19class MEDIA_EXPORT AudioDeviceListenerMac {
20 public:
21  // |listener_cb| will be called when a device change occurs; it's a permanent
22  // callback and must outlive AudioDeviceListenerMac.
23  explicit AudioDeviceListenerMac(const base::Closure& listener_cb);
24  ~AudioDeviceListenerMac();
25
26 private:
27  friend class AudioDeviceListenerMacTest;
28  static const AudioObjectPropertyAddress kDeviceChangePropertyAddress;
29
30  static OSStatus OnDefaultDeviceChanged(
31      AudioObjectID object, UInt32 num_addresses,
32      const AudioObjectPropertyAddress addresses[], void* context);
33
34  base::Closure listener_cb_;
35
36  // AudioDeviceListenerMac must be constructed and destructed on the same
37  // thread.
38  base::ThreadChecker thread_checker_;
39
40  DISALLOW_COPY_AND_ASSIGN(AudioDeviceListenerMac);
41};
42
43}  // namespace media
44
45#endif  // MEDIA_AUDIO_MAC_AUDIO_DEVICE_LISTENER_MAC_H_
46