Bug 1572627 implement currentFrame, currentTime, and sampleRate members on AudioWorkletGlobalScope r=padenot
authorKarl Tomlinson <karlt+@karlt.net>
Thu, 21 Nov 2019 13:42:49 +0000
changeset 503385 29ecee49005452f5b675b8a2a6eccd2ffa9239a2
parent 503384 75a9f4f8b4908f53e2b315f1475acfa15f48575e
child 503386 eb874118621070fa4ef69cb951b2dd7a51f93d66
push id36833
push userbtara@mozilla.com
push dateFri, 22 Nov 2019 21:40:53 +0000
treeherdermozilla-central@2c912e46295e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspadenot
bugs1572627
milestone72.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1572627 implement currentFrame, currentTime, and sampleRate members on AudioWorkletGlobalScope r=padenot Depends on D54084 Differential Revision: https://phabricator.services.mozilla.com/D54085
dom/media/webaudio/AudioWorkletGlobalScope.cpp
dom/media/webaudio/AudioWorkletGlobalScope.h
dom/media/webaudio/AudioWorkletImpl.h
testing/web-platform/meta/webaudio/the-audio-api/the-audioworklet-interface/audioworkletglobalscope-sample-rate.https.html.ini
--- a/dom/media/webaudio/AudioWorkletGlobalScope.cpp
+++ b/dom/media/webaudio/AudioWorkletGlobalScope.cpp
@@ -26,17 +26,17 @@ NS_IMPL_CYCLE_COLLECTION_INHERITED(Audio
 
 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(AudioWorkletGlobalScope)
 NS_INTERFACE_MAP_END_INHERITING(WorkletGlobalScope)
 
 NS_IMPL_ADDREF_INHERITED(AudioWorkletGlobalScope, WorkletGlobalScope)
 NS_IMPL_RELEASE_INHERITED(AudioWorkletGlobalScope, WorkletGlobalScope)
 
 AudioWorkletGlobalScope::AudioWorkletGlobalScope(AudioWorkletImpl* aImpl)
-    : mImpl(aImpl), mCurrentFrame(0), mCurrentTime(0), mSampleRate(0.0) {}
+    : mImpl(aImpl) {}
 
 bool AudioWorkletGlobalScope::WrapGlobalObject(
     JSContext* aCx, JS::MutableHandle<JSObject*> aReflector) {
   JS::RealmOptions options;
   JS::AutoHoldPrincipals principals(aCx, new WorkletPrincipals(mImpl));
   return AudioWorkletGlobalScope_Binding::Wrap(
       aCx, this, this, options, principals.get(), true, aReflector);
 }
@@ -197,21 +197,29 @@ void AudioWorkletGlobalScope::RegisterPr
           return;
         }
         destinationNode->Context()->SetParamMapForWorkletName(name, &map);
       }));
 }
 
 WorkletImpl* AudioWorkletGlobalScope::Impl() const { return mImpl; }
 
-uint64_t AudioWorkletGlobalScope::CurrentFrame() const { return mCurrentFrame; }
+uint64_t AudioWorkletGlobalScope::CurrentFrame() const {
+  AudioNodeTrack* destinationTrack = mImpl->DestinationTrack();
+  GraphTime processedTime = destinationTrack->Graph()->ProcessedTime();
+  return destinationTrack->GraphTimeToTrackTime(processedTime);
+}
 
-double AudioWorkletGlobalScope::CurrentTime() const { return mCurrentTime; }
+double AudioWorkletGlobalScope::CurrentTime() const {
+  return static_cast<double>(CurrentFrame()) * SampleRate();
+}
 
-float AudioWorkletGlobalScope::SampleRate() const { return mSampleRate; }
+float AudioWorkletGlobalScope::SampleRate() const {
+  return static_cast<float>(mImpl->DestinationTrack()->mSampleRate);
+}
 
 AudioParamDescriptorMap AudioWorkletGlobalScope::DescriptorsFromJS(
     JSContext* aCx, const JS::Rooted<JS::Value>& aDescriptors,
     ErrorResult& aRv) {
   // We already checked if aDescriptors is an array or undefined in step 8 of
   // registerProcessor, so we should be confident aDescriptors if valid here
   if (aDescriptors.isUndefined()) {
     return AudioParamDescriptorMap();
--- a/dom/media/webaudio/AudioWorkletGlobalScope.h
+++ b/dom/media/webaudio/AudioWorkletGlobalScope.h
@@ -58,20 +58,16 @@ class AudioWorkletGlobalScope final : pu
   // objects, extracted from JS. Returns an empty map in case of error and set
   // aRv accordingly.
   AudioParamDescriptorMap DescriptorsFromJS(
       JSContext* aCx, const JS::Rooted<JS::Value>& aDescriptors,
       ErrorResult& aRv);
 
   const RefPtr<AudioWorkletImpl> mImpl;
 
-  uint64_t mCurrentFrame;
-  double mCurrentTime;
-  float mSampleRate;
-
   typedef nsRefPtrHashtable<nsStringHashKey, AudioWorkletProcessorConstructor>
       NodeNameToProcessorDefinitionMap;
   NodeNameToProcessorDefinitionMap mNameToProcessorMap;
 };
 
 }  // namespace dom
 }  // namespace mozilla
 
--- a/dom/media/webaudio/AudioWorkletImpl.h
+++ b/dom/media/webaudio/AudioWorkletImpl.h
@@ -32,17 +32,17 @@ class AudioWorkletImpl final : public Wo
 
   // Execution thread only.
   dom::AudioWorkletGlobalScope* GetGlobalScope() {
     return static_cast<dom::AudioWorkletGlobalScope*>(
         WorkletImpl::GetGlobalScope());
   }
 
   // Any thread:
-  AudioNodeTrack* DestinationTrack() { return mDestinationTrack; }
+  AudioNodeTrack* DestinationTrack() const { return mDestinationTrack; }
 
  protected:
   // Execution thread only.
   already_AddRefed<dom::WorkletGlobalScope> ConstructGlobalScope() override;
 
  private:
   AudioWorkletImpl(nsPIDOMWindowInner* aWindow, nsIPrincipal* aPrincipal,
                    AudioNodeTrack* aDestinationTrack);
--- a/testing/web-platform/meta/webaudio/the-audio-api/the-audioworklet-interface/audioworkletglobalscope-sample-rate.https.html.ini
+++ b/testing/web-platform/meta/webaudio/the-audio-api/the-audioworklet-interface/audioworkletglobalscope-sample-rate.https.html.ini
@@ -1,8 +1,8 @@
 [audioworkletglobalscope-sample-rate.https.html]
   bug: AudioWorklet not enabled on release_or_beta
   expected:
     if release_or_beta: ERROR
   [Executing "Query |sampleRate| upon AudioWorkletGlobalScope construction"]
-    bug: https://bugzilla.mozilla.org/show_bug.cgi?id=1572627
+    bug: AudioWorkletNode.parameters https://bugzilla.mozilla.org/show_bug.cgi?id=1598114
     expected: FAIL