Chromium Code Reviews| 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 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 144 AudioContext::~AudioContext() | 144 AudioContext::~AudioContext() |
| 145 { | 145 { |
| 146 #if DEBUG_AUDIONODE_REFERENCES | 146 #if DEBUG_AUDIONODE_REFERENCES |
| 147 fprintf(stderr, "%p: AudioContext::~AudioContext(): %u\n", this, m_contextId ); | 147 fprintf(stderr, "%p: AudioContext::~AudioContext(): %u\n", this, m_contextId ); |
| 148 #endif | 148 #endif |
| 149 deferredTaskHandler().contextWillBeDestroyed(); | 149 deferredTaskHandler().contextWillBeDestroyed(); |
| 150 // 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. | 150 // 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. |
| 151 ASSERT(!m_isInitialized); | 151 ASSERT(!m_isInitialized); |
| 152 ASSERT(!m_activeSourceNodes.size()); | 152 ASSERT(!m_activeSourceNodes.size()); |
| 153 ASSERT(!m_finishedSourceHandlers.size()); | 153 ASSERT(!m_finishedSourceHandlers.size()); |
| 154 ASSERT(!m_suspendResolvers.size()); | |
| 155 ASSERT(!m_isResolvingResumePromises); | 154 ASSERT(!m_isResolvingResumePromises); |
| 156 ASSERT(!m_resumeResolvers.size()); | 155 ASSERT(!m_resumeResolvers.size()); |
| 157 } | 156 } |
| 158 | 157 |
| 159 void AudioContext::initialize() | 158 void AudioContext::initialize() |
| 160 { | 159 { |
| 161 if (isInitialized()) | 160 if (isInitialized()) |
| 162 return; | 161 return; |
| 163 | 162 |
| 164 FFTFrame::initialize(); | 163 FFTFrame::initialize(); |
| (...skipping 586 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 751 return ScriptPromise::rejectWithDOMException( | 750 return ScriptPromise::rejectWithDOMException( |
| 752 scriptState, | 751 scriptState, |
| 753 DOMException::create( | 752 DOMException::create( |
| 754 InvalidAccessError, | 753 InvalidAccessError, |
| 755 "cannot suspend an OfflineAudioContext")); | 754 "cannot suspend an OfflineAudioContext")); |
| 756 } | 755 } |
| 757 | 756 |
| 758 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver:: create(scriptState); | 757 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver:: create(scriptState); |
| 759 ScriptPromise promise = resolver->promise(); | 758 ScriptPromise promise = resolver->promise(); |
| 760 | 759 |
| 761 // Save the resolver. If the context is running, it will get resolved at th e end of a rendering | 760 if (m_contextState == Closed) { |
| 762 // quantum. Otherwise, resolve it now. | 761 resolver->reject( |
| 763 m_suspendResolvers.append(resolver); | 762 DOMException::create(InvalidStateError, "Cannot suspend a context th at has been closed")); |
| 763 } else { | |
| 764 // Stop rendering now. | |
| 765 if (m_destinationNode) | |
| 766 stopRendering(); | |
| 764 | 767 |
| 765 if (m_contextState != Running) { | 768 // Since we don't have any way of knowing when the hardware actually sto ps, we'll just |
| 766 // Context is not running so we can't wait for a rendering quantum to re solve the | 769 // resolve the promise now. |
| 767 // promise. Just resolve it now (along with any other pending suspend pr omises). | 770 resolver->resolve(); |
| 768 resolvePromisesForSuspendOnMainThread(); | |
|
haraken
2015/05/18 14:47:59
Actually I was wondering why we need to call resol
Raymond Toy
2015/05/18 18:25:08
Yeah, I have no recollection of why I did it this
| |
| 769 } | 771 } |
| 770 | 772 |
| 771 return promise; | 773 return promise; |
| 772 } | 774 } |
| 773 | 775 |
| 774 ScriptPromise AudioContext::resumeContext(ScriptState* scriptState) | 776 ScriptPromise AudioContext::resumeContext(ScriptState* scriptState) |
| 775 { | 777 { |
| 776 ASSERT(isMainThread()); | 778 ASSERT(isMainThread()); |
| 777 AutoLocker locker(this); | 779 AutoLocker locker(this); |
| 778 | 780 |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 891 if (tryLock()) { | 893 if (tryLock()) { |
| 892 // Take care of AudioNode tasks where the tryLock() failed previously. | 894 // Take care of AudioNode tasks where the tryLock() failed previously. |
| 893 deferredTaskHandler().breakConnections(); | 895 deferredTaskHandler().breakConnections(); |
| 894 | 896 |
| 895 // Dynamically clean up nodes which are no longer needed. | 897 // Dynamically clean up nodes which are no longer needed. |
| 896 releaseFinishedSourceNodes(); | 898 releaseFinishedSourceNodes(); |
| 897 | 899 |
| 898 deferredTaskHandler().handleDeferredTasks(); | 900 deferredTaskHandler().handleDeferredTasks(); |
| 899 deferredTaskHandler().requestToDeleteHandlersOnMainThread(); | 901 deferredTaskHandler().requestToDeleteHandlersOnMainThread(); |
| 900 | 902 |
| 901 resolvePromisesForSuspend(); | |
| 902 | |
| 903 unlock(); | 903 unlock(); |
| 904 } | 904 } |
| 905 } | 905 } |
| 906 | 906 |
| 907 void AudioContext::resolvePromisesForResumeOnMainThread() | 907 void AudioContext::resolvePromisesForResumeOnMainThread() |
| 908 { | 908 { |
| 909 ASSERT(isMainThread()); | 909 ASSERT(isMainThread()); |
| 910 AutoLocker locker(this); | 910 AutoLocker locker(this); |
| 911 | 911 |
| 912 for (auto& resolver : m_resumeResolvers) { | 912 for (auto& resolver : m_resumeResolvers) { |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 930 | 930 |
| 931 // Resolve any pending promises created by resume(). Only do this if we have n't already started | 931 // Resolve any pending promises created by resume(). Only do this if we have n't already started |
| 932 // resolving these promises. This gets called very often and it takes some t ime to resolve the | 932 // resolving these promises. This gets called very often and it takes some t ime to resolve the |
| 933 // promises in the main thread. | 933 // promises in the main thread. |
| 934 if (!m_isResolvingResumePromises && m_resumeResolvers.size() > 0) { | 934 if (!m_isResolvingResumePromises && m_resumeResolvers.size() > 0) { |
| 935 m_isResolvingResumePromises = true; | 935 m_isResolvingResumePromises = true; |
| 936 Platform::current()->mainThread()->postTask(FROM_HERE, threadSafeBind(&A udioContext::resolvePromisesForResumeOnMainThread, this)); | 936 Platform::current()->mainThread()->postTask(FROM_HERE, threadSafeBind(&A udioContext::resolvePromisesForResumeOnMainThread, this)); |
| 937 } | 937 } |
| 938 } | 938 } |
| 939 | 939 |
| 940 void AudioContext::resolvePromisesForSuspendOnMainThread() | |
| 941 { | |
| 942 ASSERT(isMainThread()); | |
| 943 AutoLocker locker(this); | |
| 944 | |
| 945 // We can stop rendering now. | |
| 946 if (m_destinationNode) | |
| 947 stopRendering(); | |
| 948 | |
| 949 for (auto& resolver : m_suspendResolvers) { | |
| 950 if (m_contextState == Closed) { | |
| 951 resolver->reject( | |
| 952 DOMException::create(InvalidStateError, "Cannot suspend a contex t that has been closed")); | |
| 953 } else { | |
| 954 resolver->resolve(); | |
| 955 } | |
| 956 } | |
| 957 | |
| 958 m_suspendResolvers.clear(); | |
| 959 } | |
| 960 | |
| 961 void AudioContext::resolvePromisesForSuspend() | |
| 962 { | |
| 963 // This runs inside the AudioContext's lock when handling pre-render tasks. | |
| 964 ASSERT(isAudioThread()); | |
| 965 ASSERT(isGraphOwner()); | |
| 966 | |
| 967 // Resolve any pending promises created by suspend() | |
| 968 if (m_suspendResolvers.size() > 0) | |
| 969 Platform::current()->mainThread()->postTask(FROM_HERE, threadSafeBind(&A udioContext::resolvePromisesForSuspendOnMainThread, this)); | |
| 970 } | |
| 971 | |
| 972 void AudioContext::rejectPendingResolvers() | 940 void AudioContext::rejectPendingResolvers() |
| 973 { | 941 { |
| 974 ASSERT(isMainThread()); | 942 ASSERT(isMainThread()); |
| 975 | 943 |
| 976 // Audio context is closing down so reject any suspend or resume promises th at are still | 944 // Audio context is closing down so reject any resume promises that are stil l pending. |
| 977 // pending. | |
| 978 | |
| 979 for (auto& resolver : m_suspendResolvers) { | |
| 980 resolver->reject(DOMException::create(InvalidStateError, "Audio context is going away")); | |
| 981 } | |
| 982 m_suspendResolvers.clear(); | |
| 983 | 945 |
| 984 for (auto& resolver : m_resumeResolvers) { | 946 for (auto& resolver : m_resumeResolvers) { |
| 985 resolver->reject(DOMException::create(InvalidStateError, "Audio context is going away")); | 947 resolver->reject(DOMException::create(InvalidStateError, "Audio context is going away")); |
| 986 } | 948 } |
| 987 m_resumeResolvers.clear(); | 949 m_resumeResolvers.clear(); |
| 988 m_isResolvingResumePromises = false; | 950 m_isResolvingResumePromises = false; |
| 989 } | 951 } |
| 990 | 952 |
| 991 const AtomicString& AudioContext::interfaceName() const | 953 const AtomicString& AudioContext::interfaceName() const |
| 992 { | 954 { |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1056 visitor->trace(m_listener); | 1018 visitor->trace(m_listener); |
| 1057 // trace() can be called in AudioContext constructor, and | 1019 // trace() can be called in AudioContext constructor, and |
| 1058 // m_contextGraphMutex might be unavailable. | 1020 // m_contextGraphMutex might be unavailable. |
| 1059 if (m_didInitializeContextGraphMutex) { | 1021 if (m_didInitializeContextGraphMutex) { |
| 1060 AutoLocker lock(this); | 1022 AutoLocker lock(this); |
| 1061 visitor->trace(m_activeSourceNodes); | 1023 visitor->trace(m_activeSourceNodes); |
| 1062 } else { | 1024 } else { |
| 1063 visitor->trace(m_activeSourceNodes); | 1025 visitor->trace(m_activeSourceNodes); |
| 1064 } | 1026 } |
| 1065 visitor->trace(m_resumeResolvers); | 1027 visitor->trace(m_resumeResolvers); |
| 1028 #if 0 | |
|
haraken
2015/05/18 14:47:59
You can remove this.
Raymond Toy
2015/05/18 18:25:08
Oops. Done
| |
| 1066 visitor->trace(m_suspendResolvers); | 1029 visitor->trace(m_suspendResolvers); |
| 1030 #endif | |
| 1067 RefCountedGarbageCollectedEventTargetWithInlineData<AudioContext>::trace(vis itor); | 1031 RefCountedGarbageCollectedEventTargetWithInlineData<AudioContext>::trace(vis itor); |
| 1068 ActiveDOMObject::trace(visitor); | 1032 ActiveDOMObject::trace(visitor); |
| 1069 } | 1033 } |
| 1070 | 1034 |
| 1071 SecurityOrigin* AudioContext::securityOrigin() const | 1035 SecurityOrigin* AudioContext::securityOrigin() const |
| 1072 { | 1036 { |
| 1073 if (executionContext()) | 1037 if (executionContext()) |
| 1074 return executionContext()->securityOrigin(); | 1038 return executionContext()->securityOrigin(); |
| 1075 | 1039 |
| 1076 return nullptr; | 1040 return nullptr; |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 1101 // the destination node can GCed if JS has no references. stop() will also r esolve the Promise | 1065 // the destination node can GCed if JS has no references. stop() will also r esolve the Promise |
| 1102 // created here. | 1066 // created here. |
| 1103 stop(); | 1067 stop(); |
| 1104 | 1068 |
| 1105 return promise; | 1069 return promise; |
| 1106 } | 1070 } |
| 1107 | 1071 |
| 1108 } // namespace blink | 1072 } // namespace blink |
| 1109 | 1073 |
| 1110 #endif // ENABLE(WEB_AUDIO) | 1074 #endif // ENABLE(WEB_AUDIO) |
| OLD | NEW |