Bug 44890 - Add AudioContext files
Summary: Add AudioContext files
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: 528+ (Nightly build)
Hardware: Other OS X 10.5
: P2 Normal
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-08-30 12:56 PDT by Chris Rogers
Modified: 2010-11-17 15:43 PST (History)
12 users (show)

See Also:


Attachments
Patch (19.63 KB, patch)
2010-08-30 13:04 PDT, Chris Rogers
no flags Details | Formatted Diff | Diff
Patch (20.26 KB, patch)
2010-09-08 17:18 PDT, Chris Rogers
no flags Details | Formatted Diff | Diff
Patch (19.98 KB, patch)
2010-09-10 18:28 PDT, Chris Rogers
no flags Details | Formatted Diff | Diff
Patch (27.25 KB, patch)
2010-09-15 15:44 PDT, Chris Rogers
no flags Details | Formatted Diff | Diff
Patch (31.39 KB, patch)
2010-09-21 13:08 PDT, Chris Rogers
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Chris Rogers 2010-08-30 12:56:55 PDT
Add AudioContext files
Comment 1 Chris Rogers 2010-08-30 13:04:04 PDT
Created attachment 65948 [details]
Patch
Comment 2 Chris Rogers 2010-08-30 13:06:16 PDT
I just realized I need to add the vendor prefix "webkit" to the IDL.  But anybody interested please go ahead and review the patch (minus this one detail :)
Comment 3 Chris Rogers 2010-08-30 13:16:35 PDT
Sorry nevermind, Dimitri Glazkov just told me that it's DOMWindow.idl which will handle the "webkit" prefix, so that's not an issue with this patch.
Comment 4 Chris Rogers 2010-08-31 16:29:20 PDT
Implements AudioContext as described in the web audio specification:
http://chromium.googlecode.com/svn/trunk/samples/audio/specification/specification.html#AudioContext-section
Comment 5 James Robinson 2010-09-07 19:34:57 PDT
Comment on attachment 65948 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=65948&action=prettypatch

> WebCore/webaudio/AudioContext.h:31
> +
I think you want #if ENABLE(WEB_AUDIO) here as well, no?

> WebCore/webaudio/AudioContext.h:62
> +    static PassRefPtr<AudioContext> create(Document* document);
nit: no need to name this parameter

> WebCore/webaudio/AudioContext.h:75
> +    float currentTime() { return (float)m_destinationNode->currentTime(); }
> +    float sampleRate() { return (float)m_destinationNode->sampleRate(); }
I'm not sure why these have to cast, but please use C++ style static_cast<float>() instead of C-style casts.

> WebCore/webaudio/AudioContext.h:101
> +    void notifyNodeFinishedProcessing(AudioNode* node);
nit: no need to name this parameter in the header

> WebCore/webaudio/AudioContext.h:105
> +    void markForDeletion(AudioNode* node);
nit: no need to name this parameter in the header

> WebCore/webaudio/AudioContext.h:109
> +    // Gets called everytime an AudioNode is connected.
> +    void nodeConnected(AudioNode* /*source*/, AudioNode* /*destination*/, unsigned /*outputIndex*/, unsigned /*inputIndex*/)
This is a little odd.  Does this function need a FIXME?  It doesn't really seem to do what the signature suggests it might.

> WebCore/webaudio/AudioContext.h:125
> +    AudioContext(Document* document);
> +    void lazyInitialize();
> +    void uninitialize();
> +
> +    // The context itself keeps a reference to all source nodes.  The source nodes, then reference all nodes they're connected to, and so on...
> +    void refNode(AudioNode* node);
> +    void derefNode(AudioNode* node);
> +    void derefUnfinishedSourceNodes();
nit: no need to name these parameters in the header
Comment 6 Chris Rogers 2010-09-08 17:18:58 PDT
Created attachment 66969 [details]
Patch
Comment 7 Chris Rogers 2010-09-08 17:22:32 PDT
James, thanks for the initial review.  I've addressed all of your comments.  I didn't put a feature enable:


#if ENABLE(WEB_AUDIO)

in the header file because I was told to only put them in the .cpp files.
Comment 8 James Robinson 2010-09-08 17:44:02 PDT
Comment on attachment 66969 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=66969&action=prettypatch

Looking good overall.  You're right about #if ENABLE()s in a header file, not sure why I thought otherwise.

r- because of the RefPtr<Document> issue - I want to be sure we are handling that correctly since if it's subtly wrong it could be very hard to debug and fix down the road.

> WebCore/webaudio/AudioContext.cpp:51
> +#include "PlatformString.h"
Include <wtf/text/WTFString.h> to get the string class (it moved fairly recently).

> WebCore/webaudio/AudioContext.cpp:60
> +PassRefPtr<CachedAudio> AudioContext::createAudioRequest(const String &url, bool mixToMono)
Do we have to use strings for URLs?  I think this will make the security folks sad pandas.

As a general note, prefer enums to bools for parameters.  It's very difficult to tell what the 'false' in createAudioContext(..., false) means.  Something like createAudioContext(..., MixToMono/MixToStereo) or whatever the appropriate two values would be is easier to understand.

> WebCore/webaudio/AudioContext.h:119
> +    AudioContext(Document* document);
nit: don't name this parameter

> WebCore/webaudio/AudioContext.h:123
> +    // The context itself keeps a reference to all source nodes.  The source nodes, then reference all nodes they're connected to, and so on...
This comment sort of trails off.  I'm not sure what it's trying to say.

> WebCore/webaudio/AudioContext.h:149
> +    // FIXME: check if we really need to hold on to document - we may need to, so be careful!
> +    RefPtr<Document> m_document;
This makes me a little bit nervous.  What's the plan to resolve this FIXME?
Comment 9 Chris Rogers 2010-09-10 18:28:31 PDT
Created attachment 67279 [details]
Patch
Comment 10 Chris Rogers 2010-09-10 18:32:53 PDT
James, I've removed the createAudioRequest() method since this is just a temporary hack to access audio file binary data in an XHR-like way.  I'll be looking to replace it with XHR with binary data capabilities.

I think I've addressed all your other comments.  I got rid of the RefPtr on Document, since I was able to locate why this was necessary and check that the document is still there by adding a hasDocument() method (I clear m_document when stop() is called).
Comment 11 Chris Rogers 2010-09-15 15:44:08 PDT
Created attachment 67734 [details]
Patch
Comment 12 Chris Rogers 2010-09-15 15:46:11 PDT
I've added a locking mechanism with lock(), tryLock(), and unlock() methods.
Comment 13 Chris Rogers 2010-09-21 13:08:05 PDT
Created attachment 68279 [details]
Patch
Comment 14 Chris Rogers 2010-09-21 13:11:44 PDT
This patch addresses some more work which was done in AudioNode.  I've added extensive asserts about threads and locks being held the important methods.  I've tested this in both multicore and simulated single-core modes (by turning off all but one thread using hwprefs) under stress tests, repeatedly re-loading the page etc. and it works well.
Comment 15 Kenneth Russell 2010-09-22 17:51:06 PDT
Comment on attachment 68279 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=68279&action=review

We've gone through the locking semantics of this class as well as AudioNode at length offline, and at this point I think this looks great. Marking r+; a couple of minor issues that aren't really necessary before commit, so leave them up to you.

> WebCore/webaudio/AudioContext.cpp:60
> +const int UndefinedThreadIdentifier = 0xffffffff;

From looking at ThreadingPthreads.cpp and ThreadingWin.cpp, I think that 0 is the correct value to use here. Regardless it would be good to define that explicitly in WTF.

> WebCore/webaudio/AudioContext.cpp:114
> +    printf("%p: AudioContext::~AudioContext()\n", this);

Should use LOG_ERROR or similar.

> WebCore/webaudio/AudioContext.cpp:352
> +    m_graphOwnerThread = thisThread;

This could be placed in the "else" clause to avoid mutating this member over and over; not a big deal.

> WebCore/webaudio/AudioContext.cpp:437
> +    ASSERT(isAudioThread());

Could use an ASSERT(isGraphOwner()) too.
Comment 16 Kenneth Russell 2010-09-22 17:53:39 PDT
Comment on attachment 68279 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=68279&action=review

> WebCore/webaudio/AudioContext.idl:60
> +        RealtimeAnalyserNode createAnalyser();

One more minor comment: I don't see this method in the Web Audio spec.
Comment 17 WebKit Commit Bot 2010-09-23 10:50:12 PDT
Comment on attachment 68279 [details]
Patch

Clearing flags on attachment: 68279

Committed r68163: <http://trac.webkit.org/changeset/68163>
Comment 18 WebKit Commit Bot 2010-09-23 10:50:20 PDT
All reviewed patches have been landed.  Closing bug.
Comment 20 Olli Pettay (:smaug) 2010-11-17 11:23:09 PST
So the main interface is non-prefixed?
It certainly should be prefixed with webkit, because there
is no specification for Audio yet, just proposals.
Comment 21 Chris Rogers 2010-11-17 11:52:01 PST
The webkit prefix will be in the patch for adding the AudioContext constructor in DOMWindow.idl.  So an AudioContext will be constructed as follows:

var context = new webkitAudioContext();
Comment 22 Olli Pettay (:smaug) 2010-11-17 15:43:23 PST
Ok, great.