| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2010, Google Inc. All rights reserved. | 2 * Copyright (C) 2010, 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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 { | 75 { |
| 76 return AudioContext::create(document, exceptionState); | 76 return AudioContext::create(document, exceptionState); |
| 77 } | 77 } |
| 78 | 78 |
| 79 // FIXME(dominicc): Devolve these constructors to AudioContext | 79 // FIXME(dominicc): Devolve these constructors to AudioContext |
| 80 // and OfflineAudioContext respectively. | 80 // and OfflineAudioContext respectively. |
| 81 | 81 |
| 82 // Constructor for rendering to the audio hardware. | 82 // Constructor for rendering to the audio hardware. |
| 83 AbstractAudioContext::AbstractAudioContext(Document* document) | 83 AbstractAudioContext::AbstractAudioContext(Document* document) |
| 84 : ActiveDOMObject(document) | 84 : ActiveDOMObject(document) |
| 85 , m_destinationNode(nullptr) |
| 85 , m_isCleared(false) | 86 , m_isCleared(false) |
| 86 , m_destinationNode(nullptr) | |
| 87 , m_isResolvingResumePromises(false) | 87 , m_isResolvingResumePromises(false) |
| 88 , m_connectionCount(0) | 88 , m_connectionCount(0) |
| 89 , m_didInitializeContextGraphMutex(false) | 89 , m_didInitializeContextGraphMutex(false) |
| 90 , m_deferredTaskHandler(DeferredTaskHandler::create()) | 90 , m_deferredTaskHandler(DeferredTaskHandler::create()) |
| 91 , m_contextState(Suspended) | 91 , m_contextState(Suspended) |
| 92 { | 92 { |
| 93 m_didInitializeContextGraphMutex = true; | 93 m_didInitializeContextGraphMutex = true; |
| 94 m_destinationNode = DefaultAudioDestinationNode::create(this); | 94 m_destinationNode = DefaultAudioDestinationNode::create(this); |
| 95 | 95 |
| 96 initialize(); | 96 initialize(); |
| 97 } | 97 } |
| 98 | 98 |
| 99 // Constructor for offline (non-realtime) rendering. | 99 // Constructor for offline (non-realtime) rendering. |
| 100 AbstractAudioContext::AbstractAudioContext(Document* document, unsigned numberOf
Channels, size_t numberOfFrames, float sampleRate) | 100 AbstractAudioContext::AbstractAudioContext(Document* document, unsigned numberOf
Channels, size_t numberOfFrames, float sampleRate) |
| 101 : ActiveDOMObject(document) | 101 : ActiveDOMObject(document) |
| 102 , m_destinationNode(nullptr) |
| 102 , m_isCleared(false) | 103 , m_isCleared(false) |
| 103 , m_destinationNode(nullptr) | |
| 104 , m_isResolvingResumePromises(false) | 104 , m_isResolvingResumePromises(false) |
| 105 , m_connectionCount(0) | 105 , m_connectionCount(0) |
| 106 , m_didInitializeContextGraphMutex(false) | 106 , m_didInitializeContextGraphMutex(false) |
| 107 , m_deferredTaskHandler(DeferredTaskHandler::create()) | 107 , m_deferredTaskHandler(DeferredTaskHandler::create()) |
| 108 , m_contextState(Suspended) | 108 , m_contextState(Suspended) |
| 109 { | 109 { |
| 110 m_didInitializeContextGraphMutex = true; | 110 m_didInitializeContextGraphMutex = true; |
| 111 // Create a new destination for offline rendering. | |
| 112 m_renderTarget = AudioBuffer::create(numberOfChannels, numberOfFrames, sampl
eRate); | |
| 113 if (m_renderTarget.get()) | |
| 114 m_destinationNode = OfflineAudioDestinationNode::create(this, m_renderTa
rget.get()); | |
| 115 | |
| 116 initialize(); | |
| 117 } | 111 } |
| 118 | 112 |
| 119 AbstractAudioContext::~AbstractAudioContext() | 113 AbstractAudioContext::~AbstractAudioContext() |
| 120 { | 114 { |
| 121 deferredTaskHandler().contextWillBeDestroyed(); | 115 deferredTaskHandler().contextWillBeDestroyed(); |
| 122 // AudioNodes keep a reference to their context, so there should be no way t
o be in the destructor if there are still AudioNodes around. | 116 // AudioNodes keep a reference to their context, so there should be no way t
o be in the destructor if there are still AudioNodes around. |
| 123 ASSERT(!isDestinationInitialized()); | 117 ASSERT(!isDestinationInitialized()); |
| 124 ASSERT(!m_activeSourceNodes.size()); | 118 ASSERT(!m_activeSourceNodes.size()); |
| 125 ASSERT(!m_finishedSourceHandlers.size()); | 119 ASSERT(!m_finishedSourceHandlers.size()); |
| 126 ASSERT(!m_isResolvingResumePromises); | 120 ASSERT(!m_isResolvingResumePromises); |
| (...skipping 670 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 797 // This is called for both online and offline contexts. | 791 // This is called for both online and offline contexts. |
| 798 ASSERT(isMainThread()); | 792 ASSERT(isMainThread()); |
| 799 ASSERT(m_destinationNode); | 793 ASSERT(m_destinationNode); |
| 800 | 794 |
| 801 if (m_contextState == Suspended) { | 795 if (m_contextState == Suspended) { |
| 802 destination()->audioDestinationHandler().startRendering(); | 796 destination()->audioDestinationHandler().startRendering(); |
| 803 setContextState(Running); | 797 setContextState(Running); |
| 804 } | 798 } |
| 805 } | 799 } |
| 806 | 800 |
| 807 void AbstractAudioContext::fireCompletionEvent() | |
| 808 { | |
| 809 ASSERT(isMainThread()); | |
| 810 if (!isMainThread()) | |
| 811 return; | |
| 812 | |
| 813 AudioBuffer* renderedBuffer = m_renderTarget.get(); | |
| 814 | |
| 815 // For an offline context, we set the state to closed here so that the oncom
plete handler sees | |
| 816 // that the context has been closed. | |
| 817 setContextState(Closed); | |
| 818 | |
| 819 ASSERT(renderedBuffer); | |
| 820 if (!renderedBuffer) | |
| 821 return; | |
| 822 | |
| 823 // Avoid firing the event if the document has already gone away. | |
| 824 if (executionContext()) { | |
| 825 // Call the offline rendering completion event listener and resolve the
promise too. | |
| 826 dispatchEvent(OfflineAudioCompletionEvent::create(renderedBuffer)); | |
| 827 m_offlineResolver->resolve(renderedBuffer); | |
| 828 } | |
| 829 } | |
| 830 | |
| 831 DEFINE_TRACE(AbstractAudioContext) | 801 DEFINE_TRACE(AbstractAudioContext) |
| 832 { | 802 { |
| 833 visitor->trace(m_offlineResolver); | |
| 834 visitor->trace(m_renderTarget); | |
| 835 visitor->trace(m_destinationNode); | 803 visitor->trace(m_destinationNode); |
| 836 visitor->trace(m_listener); | 804 visitor->trace(m_listener); |
| 837 // trace() can be called in AbstractAudioContext constructor, and | 805 // trace() can be called in AbstractAudioContext constructor, and |
| 838 // m_contextGraphMutex might be unavailable. | 806 // m_contextGraphMutex might be unavailable. |
| 839 if (m_didInitializeContextGraphMutex) { | 807 if (m_didInitializeContextGraphMutex) { |
| 840 AutoLocker lock(this); | 808 AutoLocker lock(this); |
| 841 visitor->trace(m_activeSourceNodes); | 809 visitor->trace(m_activeSourceNodes); |
| 842 } else { | 810 } else { |
| 843 visitor->trace(m_activeSourceNodes); | 811 visitor->trace(m_activeSourceNodes); |
| 844 } | 812 } |
| 845 visitor->trace(m_resumeResolvers); | 813 visitor->trace(m_resumeResolvers); |
| 846 RefCountedGarbageCollectedEventTargetWithInlineData<AbstractAudioContext>::t
race(visitor); | 814 RefCountedGarbageCollectedEventTargetWithInlineData<AbstractAudioContext>::t
race(visitor); |
| 847 ActiveDOMObject::trace(visitor); | 815 ActiveDOMObject::trace(visitor); |
| 848 } | 816 } |
| 849 | 817 |
| 850 SecurityOrigin* AbstractAudioContext::securityOrigin() const | 818 SecurityOrigin* AbstractAudioContext::securityOrigin() const |
| 851 { | 819 { |
| 852 if (executionContext()) | 820 if (executionContext()) |
| 853 return executionContext()->securityOrigin(); | 821 return executionContext()->securityOrigin(); |
| 854 | 822 |
| 855 return nullptr; | 823 return nullptr; |
| 856 } | 824 } |
| 857 | 825 |
| 858 } // namespace blink | 826 } // namespace blink |
| 859 | 827 |
| 860 #endif // ENABLE(WEB_AUDIO) | 828 #endif // ENABLE(WEB_AUDIO) |
| OLD | NEW |