Closed Bug 836599 Opened 11 years ago Closed 11 years ago

Implement OfflineAudioContext

Categories

(Core :: Web Audio, defect)

x86
macOS
defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla24

People

(Reporter: ehsan.akhgari, Assigned: ehsan.akhgari)

References

Details

(Keywords: dev-doc-complete)

Attachments

(15 files, 5 obsolete files)

4.59 KB, patch
roc
: review+
Details | Diff | Splinter Review
3.41 KB, patch
roc
: review+
Details | Diff | Splinter Review
2.81 KB, patch
roc
: review+
Details | Diff | Splinter Review
2.26 KB, patch
roc
: review+
Details | Diff | Splinter Review
1.84 KB, patch
roc
: review+
Details | Diff | Splinter Review
1.21 KB, patch
roc
: review+
Details | Diff | Splinter Review
12.79 KB, patch
roc
: review+
ehsan.akhgari
: checkin+
Details | Diff | Splinter Review
2.89 KB, patch
roc
: review+
Details | Diff | Splinter Review
6.76 KB, patch
roc
: review+
Details | Diff | Splinter Review
5.18 KB, patch
Details | Diff | Splinter Review
8.44 KB, patch
Details | Diff | Splinter Review
9.84 KB, patch
roc
: review+
Details | Diff | Splinter Review
16.96 KB, patch
roc
: review+
Details | Diff | Splinter Review
8.96 KB, patch
Details | Diff | Splinter Review
8.35 KB, patch
roc
: review+
Details | Diff | Splinter Review
roc, do you know what underlying assumptions MediaStreamsGraphImpl makes about the underlying hardware, such as the number of channels, sample rate, etc.?

Thanks!
Assignee: nobody → ehsan
Status: NEW → ASSIGNED
Attachment #709855 - Flags: review?(roc)
I haven't finished the rest of the patches in this series yet so I won't attach them to the bug just now, but we should be able to land the first 6 parts now.
Note that bug 836850 is now fixed, so we can just use a single class here if desired.
(In reply to Boris Zbarsky (:bz) from comment #10)
> Note that bug 836850 is now fixed, so we can just use a single class here if
> desired.

Yes, thanks!
Depends on: 836850
Whiteboard: [leave open]
Depends on: 859600
This currently passes try.  I'd like to land this part sooner.  I'm working on the rest.
Attachment #746745 - Flags: review?(roc)
Comment on attachment 746745 [details] [diff] [review]
Part 7: Implement a non-realtime API in MediaStreamGraph

Review of attachment 746745 [details] [diff] [review]:
-----------------------------------------------------------------

Nice!
Attachment #746745 - Flags: review?(roc) → review+
Whiteboard: [leave open]
Comment on attachment 746745 [details] [diff] [review]
Part 7: Implement a non-realtime API in MediaStreamGraph

https://hg.mozilla.org/integration/mozilla-inbound/rev/c97a67b4ec08
Attachment #746745 - Flags: checkin+
Depends on: 871226
Depends on: 872635
Whiteboard: [leave open]
Attachment #749984 - Flags: review?(roc)
Attachment #749987 - Flags: review?(roc)
Blocks: 872394
Try is happy with this stuff: https://tbpl.mozilla.org/?tree=Try&rev=b4da97aa2e0f
Comment on attachment 749983 [details] [diff] [review]
Part 8: Add a non-realtime media graph API to produce a given number of ticks

Review of attachment 749983 [details] [diff] [review]:
-----------------------------------------------------------------

::: content/media/MediaStreamGraphImpl.h
@@ +531,5 @@
>     */
>    bool mRealtime;
> +  /**
> +   * True when a non-realtime MediaStreamGraph has started to process input.  This
> +   * value is always set to true on the main thread.

"only accessed on the main thread"
Attachment #749983 - Flags: review?(roc) → review+
Comment on attachment 749987 [details] [diff] [review]
Part 11: Implement the processing of OfflineAudioContext

Review of attachment 749987 [details] [diff] [review]:
-----------------------------------------------------------------

I actually think we should run the entire graph at the OfflineAudioContext's rate. Sorry, I know that's a big change and maybe difficult, but it seems like the right thing to do.

If you want to take a shortcut and only support OfflineAudioContext with the IdealAudioRate, we can do that for now to get tests working better.
Comment on attachment 749988 [details] [diff] [review]
Part 12: Fix the lifetime management of the Web Audio graph in presence of OfflineAudioContexts

Review of attachment 749988 [details] [diff] [review]:
-----------------------------------------------------------------

::: content/media/webaudio/AudioDestinationNode.cpp
@@ +253,5 @@
>    mStream = graph->CreateAudioNodeStream(engine, MediaStreamGraph::EXTERNAL_STREAM);
>  }
>  
> +void
> +AudioDestinationNode::DestroyGraphIfNeeded()

This seems like a poor name, since you unconditionally destroy the graph.
(In reply to Robert O'Callahan (:roc) (Mozilla Corporation) from comment #26)
> Comment on attachment 749987 [details] [diff] [review]
> Part 11: Implement the processing of OfflineAudioContext
> 
> Review of attachment 749987 [details] [diff] [review]:
> -----------------------------------------------------------------
> 
> I actually think we should run the entire graph at the OfflineAudioContext's
> rate. Sorry, I know that's a big change and maybe difficult, but it seems
> like the right thing to do.

Hmm, why do you think that we should do that?  That pretty much breaks everything that depends on the current assumption that the graph runs at 48KHz...

> If you want to take a shortcut and only support OfflineAudioContext with the
> IdealAudioRate, we can do that for now to get tests working better.

No matter what we decide to do eventually, I definitely don't want to make that big of a change here, since we need this sooner rather than later...  We can always do that later, and it should be transparent as far as content is concerned.
(In reply to :Ehsan Akhgari (needinfo? me!) from comment #28)
> (In reply to Robert O'Callahan (:roc) (Mozilla Corporation) from comment #26)
> > Comment on attachment 749987 [details] [diff] [review]
> > Part 11: Implement the processing of OfflineAudioContext
> > 
> > Review of attachment 749987 [details] [diff] [review]:
> > -----------------------------------------------------------------
> > 
> > I actually think we should run the entire graph at the OfflineAudioContext's
> > rate. Sorry, I know that's a big change and maybe difficult, but it seems
> > like the right thing to do.
> 
> Hmm, why do you think that we should do that?  That pretty much breaks
> everything that depends on the current assumption that the graph runs at
> 48KHz...

Why? Using OfflineAudioContext you can specify that the rate is 48KHz, which is actually *more* reliable than assuming AudioContext's rate is 48KHz!

That's one reason I think we should do that; if someone wants processing to happen at a certain rate, we can and should support that in OfflineAudioContext.

> > If you want to take a shortcut and only support OfflineAudioContext with the
> > IdealAudioRate, we can do that for now to get tests working better.
> 
> No matter what we decide to do eventually, I definitely don't want to make
> that big of a change here, since we need this sooner rather than later... 
> We can always do that later, and it should be transparent as far as content
> is concerned.

OK.
(In reply to Robert O'Callahan (:roc) (Mozilla Corporation) from comment #29)
> (In reply to :Ehsan Akhgari (needinfo? me!) from comment #28)
> > (In reply to Robert O'Callahan (:roc) (Mozilla Corporation) from comment #26)
> > > Comment on attachment 749987 [details] [diff] [review]
> > > Part 11: Implement the processing of OfflineAudioContext
> > > 
> > > Review of attachment 749987 [details] [diff] [review]:
> > > -----------------------------------------------------------------
> > > 
> > > I actually think we should run the entire graph at the OfflineAudioContext's
> > > rate. Sorry, I know that's a big change and maybe difficult, but it seems
> > > like the right thing to do.
> > 
> > Hmm, why do you think that we should do that?  That pretty much breaks
> > everything that depends on the current assumption that the graph runs at
> > 48KHz...
> 
> Why? Using OfflineAudioContext you can specify that the rate is 48KHz, which
> is actually *more* reliable than assuming AudioContext's rate is 48KHz!

Well, we make assumptions about IdealAudioRate() all around the code base.  If we want to change that, all of the existing code must be audited to make sure we don't break things.  (At least we should change all callers of IdealAudioRate.)

> That's one reason I think we should do that; if someone wants processing to
> happen at a certain rate, we can and should support that in
> OfflineAudioContext.

Hmm, I guess there's actually a content visible difference for a-rate AudioParams...  I was not paying attention to that. :(

> > > If you want to take a shortcut and only support OfflineAudioContext with the
> > > IdealAudioRate, we can do that for now to get tests working better.
> > 
> > No matter what we decide to do eventually, I definitely don't want to make
> > that big of a change here, since we need this sooner rather than later... 
> > We can always do that later, and it should be transparent as far as content
> > is concerned.
> 
> OK.

To confirm my understanding, do you mean throwing when you try to create an OfflineAudioContext with a different rate for now, or leave the patch as is?  (I slightly prefer to leave it as is)
(with the nit addressed)
Attachment #749983 - Attachment is obsolete: true
(In reply to :Ehsan Akhgari (needinfo? me!) from comment #30)
> To confirm my understanding, do you mean throwing when you try to create an
> OfflineAudioContext with a different rate for now, or leave the patch as is?
> (I slightly prefer to leave it as is)

Throw, I think.
(In reply to comment #33)
> (In reply to :Ehsan Akhgari (needinfo? me!) from comment #30)
> > To confirm my understanding, do you mean throwing when you try to create an
> > OfflineAudioContext with a different rate for now, or leave the patch as is?
> > (I slightly prefer to leave it as is)
> 
> Throw, I think.

OK, I'll do that tomorrow though.  Not feeling well right now...
Attachment #749984 - Attachment is obsolete: true
Attachment #750399 - Flags: review?(roc)
Attachment #749987 - Attachment is obsolete: true
Attachment #749987 - Flags: review?(roc)
Attachment #750401 - Flags: review?(roc)
Comment on attachment 750401 [details] [diff] [review]
Part 11: Implement the processing of OfflineAudioContext

Review of attachment 750401 [details] [diff] [review]:
-----------------------------------------------------------------

::: content/media/webaudio/AudioDestinationNode.cpp
@@ +31,5 @@
> +    // These allocations might fail if content provides a huge number of
> +    // channels or size, but it's OK since we'll deal with the failure
> +    // gracefully.
> +    if (mInputChannels.SetLength(aNumberOfChannels)) {
> +      static const fallible_t fallible = fallible_t();

Factoring this out seems pointless. Just use new (fallible_t()).

@@ +108,5 @@
> +      {
> +        // If it's not safe to run scripts right now, schedule this to run later
> +        if (!nsContentUtils::IsSafeToRunScript()) {
> +          nsContentUtils::AddScriptRunner(this);
> +          return NS_OK;

Unnecessary. It's always safe to run script in an nsRunnable dispatched to the main thread.

@@ +165,1 @@
>    uint32_t mLength;

Please document the meaning of mWriteIndex and mLength. And mInputChannels.
Attachment #750401 - Flags: review?(roc) → review+
(In reply to comment #38)
> @@ +108,5 @@
> > +      {
> > +        // If it's not safe to run scripts right now, schedule this to run later
> > +        if (!nsContentUtils::IsSafeToRunScript()) {
> > +          nsContentUtils::AddScriptRunner(this);
> > +          return NS_OK;
> 
> Unnecessary. It's always safe to run script in an nsRunnable dispatched to the
> main thread.

See bug 865233 comment 8.  :-)
Gah. We should have NS_DispatchToMainThreadWhenSafeToRunScript or something like that. OK.
(In reply to Robert O'Callahan (:roc) (Mozilla Corporation) from comment #38)
> Comment on attachment 750401 [details] [diff] [review]
> Part 11: Implement the processing of OfflineAudioContext
> 
> Review of attachment 750401 [details] [diff] [review]:
> -----------------------------------------------------------------
> 
> ::: content/media/webaudio/AudioDestinationNode.cpp
> @@ +31,5 @@
> > +    // These allocations might fail if content provides a huge number of
> > +    // channels or size, but it's OK since we'll deal with the failure
> > +    // gracefully.
> > +    if (mInputChannels.SetLength(aNumberOfChannels)) {
> > +      static const fallible_t fallible = fallible_t();
> 
> Factoring this out seems pointless. Just use new (fallible_t()).

That seems to confuse the compiler, since it doesn't know whether we mean to allocate a fallible_t or not. :(
(In reply to Robert O'Callahan (:roc) (Mozilla Corporation) from comment #40)
> Gah. We should have NS_DispatchToMainThreadWhenSafeToRunScript or something
> like that. OK.

Agreed! Filed bug 873292.
Depends on: 873553
Mass moving Web Audio bugs to the Web Audio component.  Filter on duckityduck.
Component: Video/Audio → Web Audio
Depends on: 910171
Depends on: 1388591
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: