summaryrefslogtreecommitdiffstats
path: root/media/audio/mac/audio_manager_mac.cc
blob: ee5943a129967c6044685a05b430161456d8f2ff (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 (c) 2009 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.

#include <CoreAudio/AudioHardware.h>

#include "base/at_exit.h"
#include "media/audio/fake_audio_output_stream.h"
#include "media/audio/mac/audio_manager_mac.h"
#include "media/audio/mac/audio_output_mac.h"

bool AudioManagerMac::HasAudioDevices() {
  AudioDeviceID output_device_id = kAudioObjectUnknown;
  AudioObjectPropertyAddress property_address = {
    kAudioHardwarePropertyDefaultOutputDevice,  // mSelector
    kAudioObjectPropertyScopeGlobal,            // mScope
    kAudioObjectPropertyElementMaster           // mElement
  };
  size_t output_device_id_size = sizeof(output_device_id);
  OSStatus err = AudioObjectGetPropertyData(kAudioObjectSystemObject,
                                            &property_address,
                                            0,     // inQualifierDataSize
                                            NULL,  // inQualifierData
                                            &output_device_id_size,
                                            &output_device_id);
  return err == kAudioHardwareNoError &&
         output_device_id != kAudioObjectUnknown;
}

AudioOutputStream* AudioManagerMac::MakeAudioStream(Format format, int channels,
                                                    int sample_rate,
                                                    char bits_per_sample) {
  if (format == AUDIO_MOCK)
    return FakeAudioOutputStream::MakeFakeStream();
  else if (format != AUDIO_PCM_LINEAR)
    return NULL;
  return new PCMQueueOutAudioOutputStream(this, channels, sample_rate,
                                          bits_per_sample);
}

void AudioManagerMac::MuteAll() {
  // TODO(cpu): implement.
}

void AudioManagerMac::UnMuteAll() {
  // TODO(cpu): implement.
}

// Called by the stream when it has been released by calling Close().
void AudioManagerMac::ReleaseStream(PCMQueueOutAudioOutputStream* stream) {
  delete stream;
}

namespace {

AudioManagerMac* g_audio_manager = NULL;

}  // namespace.

void DestroyAudioManagerMac(void* param) {
  delete g_audio_manager;
  g_audio_manager = NULL;
}

// By convention, the AudioManager is not thread safe.
AudioManager* AudioManager::GetAudioManager() {
  if (!g_audio_manager) {
    g_audio_manager = new AudioManagerMac();
    base::AtExitManager::RegisterCallback(&DestroyAudioManagerMac, NULL);
  }
  return g_audio_manager;
}