OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2011, Google Inc. All rights reserved. | 2 * Copyright (C) 2011, Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 14 matching lines...) Expand all Loading... |
25 #include "modules/webaudio/DefaultAudioDestinationNode.h" | 25 #include "modules/webaudio/DefaultAudioDestinationNode.h" |
26 #include "bindings/core/v8/ExceptionMessages.h" | 26 #include "bindings/core/v8/ExceptionMessages.h" |
27 #include "bindings/core/v8/ExceptionState.h" | 27 #include "bindings/core/v8/ExceptionState.h" |
28 #include "core/dom/ExceptionCode.h" | 28 #include "core/dom/ExceptionCode.h" |
29 #include "modules/webaudio/AbstractAudioContext.h" | 29 #include "modules/webaudio/AbstractAudioContext.h" |
30 #include "platform/Logging.h" | 30 #include "platform/Logging.h" |
31 | 31 |
32 namespace blink { | 32 namespace blink { |
33 | 33 |
34 DefaultAudioDestinationHandler::DefaultAudioDestinationHandler(AudioNode& node) | 34 DefaultAudioDestinationHandler::DefaultAudioDestinationHandler(AudioNode& node) |
35 : AudioDestinationHandler(node, AudioDestination::hardwareSampleRate()) | 35 : AudioDestinationHandler(node, AudioRenderSink::audioHardwareSampleRate()) |
36 , m_numberOfInputChannels(0) | 36 , m_numberOfInputChannels(0) |
37 { | 37 { |
38 // Node-specific default mixing rules. | 38 // Node-specific default mixing rules. |
39 m_channelCount = 2; | 39 m_channelCount = 2; |
40 m_channelCountMode = Explicit; | 40 m_channelCountMode = Explicit; |
41 m_channelInterpretation = AudioBus::Speakers; | 41 m_channelInterpretation = AudioBus::Speakers; |
42 } | 42 } |
43 | 43 |
44 PassRefPtr<DefaultAudioDestinationHandler> DefaultAudioDestinationHandler::creat
e(AudioNode& node) | 44 PassRefPtr<DefaultAudioDestinationHandler> DefaultAudioDestinationHandler::creat
e(AudioNode& node) |
45 { | 45 { |
(...skipping 10 matching lines...) Expand all Loading... |
56 uninitialize(); | 56 uninitialize(); |
57 AudioDestinationHandler::dispose(); | 57 AudioDestinationHandler::dispose(); |
58 } | 58 } |
59 | 59 |
60 void DefaultAudioDestinationHandler::initialize() | 60 void DefaultAudioDestinationHandler::initialize() |
61 { | 61 { |
62 ASSERT(isMainThread()); | 62 ASSERT(isMainThread()); |
63 if (isInitialized()) | 63 if (isInitialized()) |
64 return; | 64 return; |
65 | 65 |
66 createDestination(); | 66 createRenderSink(); |
67 AudioHandler::initialize(); | 67 AudioHandler::initialize(); |
68 } | 68 } |
69 | 69 |
70 void DefaultAudioDestinationHandler::uninitialize() | 70 void DefaultAudioDestinationHandler::uninitialize() |
71 { | 71 { |
72 ASSERT(isMainThread()); | 72 ASSERT(isMainThread()); |
73 if (!isInitialized()) | 73 if (!isInitialized()) |
74 return; | 74 return; |
75 | 75 |
76 m_destination->stop(); | 76 m_audioRenderSink->stop(); |
77 m_numberOfInputChannels = 0; | 77 m_numberOfInputChannels = 0; |
78 | 78 |
79 AudioHandler::uninitialize(); | 79 AudioHandler::uninitialize(); |
80 } | 80 } |
81 | 81 |
82 void DefaultAudioDestinationHandler::createDestination() | 82 void DefaultAudioDestinationHandler::createRenderSink() |
83 { | 83 { |
84 float hardwareSampleRate = AudioDestination::hardwareSampleRate(); | 84 float audioHardwareSampleRate = AudioRenderSink::audioHardwareSampleRate(); |
85 VLOG(1) << ">>>> hardwareSampleRate = " << hardwareSampleRate; | 85 VLOG(1) << ">>>> hardwareSampleRate = " << audioHardwareSampleRate; |
86 | 86 |
87 m_destination = AudioDestination::create(*this, m_inputDeviceId, m_numberOfI
nputChannels, channelCount(), hardwareSampleRate, context()->getSecurityOrigin()
); | 87 m_audioRenderSink = AudioRenderSink::create(*this, |
| 88 m_inputDeviceId, m_numberOfInputChannels, channelCount(), |
| 89 audioHardwareSampleRate, context()->getSecurityOrigin()); |
88 } | 90 } |
89 | 91 |
90 void DefaultAudioDestinationHandler::startRendering() | 92 void DefaultAudioDestinationHandler::startRendering() |
91 { | 93 { |
92 ASSERT(isInitialized()); | 94 ASSERT(isInitialized()); |
93 if (isInitialized()) { | 95 if (isInitialized()) |
94 ASSERT(!m_destination->isPlaying()); | 96 m_audioRenderSink->start(); |
95 m_destination->start(); | |
96 } | |
97 } | 97 } |
98 | 98 |
99 void DefaultAudioDestinationHandler::stopRendering() | 99 void DefaultAudioDestinationHandler::stopRendering() |
100 { | 100 { |
101 ASSERT(isInitialized()); | 101 ASSERT(isInitialized()); |
102 if (isInitialized()) { | 102 if (isInitialized()) |
103 ASSERT(m_destination->isPlaying()); | 103 m_audioRenderSink->stop(); |
104 m_destination->stop(); | |
105 } | |
106 } | 104 } |
107 | 105 |
108 unsigned long DefaultAudioDestinationHandler::maxChannelCount() const | 106 unsigned long DefaultAudioDestinationHandler::maxChannelCount() const |
109 { | 107 { |
110 return AudioDestination::maxChannelCount(); | 108 return AudioRenderSink::audioHardwareChannelCount(); |
111 } | 109 } |
112 | 110 |
113 void DefaultAudioDestinationHandler::setChannelCount(unsigned long channelCount,
ExceptionState& exceptionState) | 111 void DefaultAudioDestinationHandler::setChannelCount(unsigned long newChannelCou
nt, ExceptionState& exceptionState) |
114 { | 112 { |
115 // The channelCount for the input to this node controls the actual number of
channels we | 113 // The channelCount for the input to this node controls the actual number of |
116 // send to the audio hardware. It can only be set depending on the maximum n
umber of | 114 // channels we send to the audio hardware. It can only be set depending on |
117 // channels supported by the hardware. | 115 // the maximum number of channels supported by the hardware. |
| 116 ASSERT(isMainThread()); |
| 117 ASSERT(isInitialized()); |
| 118 if (!isInitialized()) |
| 119 return; |
118 | 120 |
119 ASSERT(isMainThread()); | 121 if (!maxChannelCount() || newChannelCount > maxChannelCount()) { |
120 | |
121 if (!maxChannelCount() || channelCount > maxChannelCount()) { | |
122 exceptionState.throwDOMException( | 122 exceptionState.throwDOMException( |
123 IndexSizeError, | 123 IndexSizeError, |
124 ExceptionMessages::indexOutsideRange<unsigned>("channel count", chan
nelCount, 1, ExceptionMessages::InclusiveBound, maxChannelCount(), ExceptionMess
ages::InclusiveBound)); | 124 ExceptionMessages::indexOutsideRange<unsigned>("channel count", newC
hannelCount, 1, ExceptionMessages::InclusiveBound, maxChannelCount(), ExceptionM
essages::InclusiveBound)); |
125 return; | 125 return; |
126 } | 126 } |
127 | 127 |
128 unsigned long oldChannelCount = this->channelCount(); | 128 unsigned long oldChannelCount = channelCount(); |
129 AudioHandler::setChannelCount(channelCount, exceptionState); | 129 AudioHandler::setChannelCount(newChannelCount, exceptionState); |
130 | 130 |
131 if (!exceptionState.hadException() && this->channelCount() != oldChannelCoun
t && isInitialized()) { | 131 // Restart render sink to apply the channel count change. |
132 // Re-create destination. | 132 if (!exceptionState.hadException() && channelCount() != oldChannelCount) { |
133 m_destination->stop(); | 133 m_audioRenderSink->stop(); |
134 createDestination(); | 134 createRenderSink(); |
135 m_destination->start(); | 135 m_audioRenderSink->start(); |
136 } | 136 } |
137 } | 137 } |
138 | 138 |
139 // ---------------------------------------------------------------- | 139 // ---------------------------------------------------------------- |
140 | 140 |
141 DefaultAudioDestinationNode::DefaultAudioDestinationNode(AbstractAudioContext& c
ontext) | 141 DefaultAudioDestinationNode::DefaultAudioDestinationNode(AbstractAudioContext& c
ontext) |
142 : AudioDestinationNode(context) | 142 : AudioDestinationNode(context) |
143 { | 143 { |
144 setHandler(DefaultAudioDestinationHandler::create(*this)); | 144 setHandler(DefaultAudioDestinationHandler::create(*this)); |
145 } | 145 } |
146 | 146 |
147 DefaultAudioDestinationNode* DefaultAudioDestinationNode::create(AbstractAudioCo
ntext* context) | 147 DefaultAudioDestinationNode* DefaultAudioDestinationNode::create(AbstractAudioCo
ntext* context) |
148 { | 148 { |
149 return new DefaultAudioDestinationNode(*context); | 149 return new DefaultAudioDestinationNode(*context); |
150 } | 150 } |
151 | 151 |
152 } // namespace blink | 152 } // namespace blink |
153 | 153 |
OLD | NEW |