| 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 "config.h" | 25 #include "config.h" |
| 26 | 26 |
| 27 #if ENABLE(WEB_AUDIO) | 27 #if ENABLE(WEB_AUDIO) |
| 28 | 28 |
| 29 #include "modules/webaudio/MediaElementAudioSourceNode.h" | 29 #include "modules/webaudio/MediaElementAudioSourceNode.h" |
| 30 | 30 |
| 31 #include "core/html/HTMLMediaElement.h" | 31 #include "core/html/HTMLMediaElement.h" |
| 32 #include "modules/webaudio/AudioContext.h" | 32 #include "modules/webaudio/AudioContext.h" |
| 33 #include "modules/webaudio/AudioNodeOutput.h" | 33 #include "modules/webaudio/AudioNodeOutput.h" |
| 34 #include "platform/Logging.h" | 34 #include "platform/Logging.h" |
| 35 #include "platform/audio/AudioUtilities.h" |
| 35 #include "platform/graphics/media/MediaPlayer.h" | 36 #include "platform/graphics/media/MediaPlayer.h" |
| 36 #include "wtf/Locker.h" | 37 #include "wtf/Locker.h" |
| 37 | 38 |
| 38 // These are somewhat arbitrary limits, but we need to do some kind of sanity-ch
ecking. | |
| 39 const unsigned minSampleRate = 8000; | |
| 40 const unsigned maxSampleRate = 192000; | |
| 41 | |
| 42 namespace blink { | 39 namespace blink { |
| 43 | 40 |
| 44 MediaElementAudioSourceNode* MediaElementAudioSourceNode::create(AudioContext* c
ontext, HTMLMediaElement* mediaElement) | 41 MediaElementAudioSourceNode* MediaElementAudioSourceNode::create(AudioContext* c
ontext, HTMLMediaElement* mediaElement) |
| 45 { | 42 { |
| 46 return adoptRefCountedGarbageCollectedWillBeNoop(new MediaElementAudioSource
Node(context, mediaElement)); | 43 return adoptRefCountedGarbageCollectedWillBeNoop(new MediaElementAudioSource
Node(context, mediaElement)); |
| 47 } | 44 } |
| 48 | 45 |
| 49 MediaElementAudioSourceNode::MediaElementAudioSourceNode(AudioContext* context,
HTMLMediaElement* mediaElement) | 46 MediaElementAudioSourceNode::MediaElementAudioSourceNode(AudioContext* context,
HTMLMediaElement* mediaElement) |
| 50 : AudioSourceNode(context, context->sampleRate()) | 47 : AudioSourceNode(context, context->sampleRate()) |
| 51 , m_mediaElement(mediaElement) | 48 , m_mediaElement(mediaElement) |
| (...skipping 17 matching lines...) Expand all Loading... |
| 69 void MediaElementAudioSourceNode::dispose() | 66 void MediaElementAudioSourceNode::dispose() |
| 70 { | 67 { |
| 71 m_mediaElement->setAudioSourceNode(0); | 68 m_mediaElement->setAudioSourceNode(0); |
| 72 uninitialize(); | 69 uninitialize(); |
| 73 AudioSourceNode::dispose(); | 70 AudioSourceNode::dispose(); |
| 74 } | 71 } |
| 75 | 72 |
| 76 void MediaElementAudioSourceNode::setFormat(size_t numberOfChannels, float sourc
eSampleRate) | 73 void MediaElementAudioSourceNode::setFormat(size_t numberOfChannels, float sourc
eSampleRate) |
| 77 { | 74 { |
| 78 if (numberOfChannels != m_sourceNumberOfChannels || sourceSampleRate != m_so
urceSampleRate) { | 75 if (numberOfChannels != m_sourceNumberOfChannels || sourceSampleRate != m_so
urceSampleRate) { |
| 79 if (!numberOfChannels || numberOfChannels > AudioContext::maxNumberOfCha
nnels() || sourceSampleRate < minSampleRate || sourceSampleRate > maxSampleRate)
{ | 76 if (!numberOfChannels || numberOfChannels > AudioContext::maxNumberOfCha
nnels() || !AudioUtilities::isValidAudioBufferSampleRate(sourceSampleRate)) { |
| 80 // process() will generate silence for these uninitialized values. | 77 // process() will generate silence for these uninitialized values. |
| 81 WTF_LOG(Media, "MediaElementAudioSourceNode::setFormat(%u, %f) - unh
andled format change", static_cast<unsigned>(numberOfChannels), sourceSampleRate
); | 78 WTF_LOG(Media, "MediaElementAudioSourceNode::setFormat(%u, %f) - unh
andled format change", static_cast<unsigned>(numberOfChannels), sourceSampleRate
); |
| 82 m_sourceNumberOfChannels = 0; | 79 m_sourceNumberOfChannels = 0; |
| 83 m_sourceSampleRate = 0; | 80 m_sourceSampleRate = 0; |
| 84 return; | 81 return; |
| 85 } | 82 } |
| 86 | 83 |
| 87 m_sourceNumberOfChannels = numberOfChannels; | 84 m_sourceNumberOfChannels = numberOfChannels; |
| 88 m_sourceSampleRate = sourceSampleRate; | 85 m_sourceSampleRate = sourceSampleRate; |
| 89 | 86 |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 void MediaElementAudioSourceNode::trace(Visitor* visitor) | 152 void MediaElementAudioSourceNode::trace(Visitor* visitor) |
| 156 { | 153 { |
| 157 visitor->trace(m_mediaElement); | 154 visitor->trace(m_mediaElement); |
| 158 AudioSourceNode::trace(visitor); | 155 AudioSourceNode::trace(visitor); |
| 159 AudioSourceProviderClient::trace(visitor); | 156 AudioSourceProviderClient::trace(visitor); |
| 160 } | 157 } |
| 161 | 158 |
| 162 } // namespace blink | 159 } // namespace blink |
| 163 | 160 |
| 164 #endif // ENABLE(WEB_AUDIO) | 161 #endif // ENABLE(WEB_AUDIO) |
| OLD | NEW |