Bug 215947 - AudioParam.cancelAndHoldAtTime() is missing
Summary: AudioParam.cancelAndHoldAtTime() is missing
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Web Audio (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Chris Dumez
URL: https://www.w3.org/TR/webaudio/#dom-a...
Keywords: InRadar
Depends on:
Blocks: 212611
  Show dependency treegraph
 
Reported: 2020-08-28 13:09 PDT by Chris Dumez
Modified: 2020-09-07 18:35 PDT (History)
12 users (show)

See Also:


Attachments
WIP Patch (89.47 KB, patch)
2020-09-06 19:34 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff
WIP Patch (87.58 KB, patch)
2020-09-06 19:53 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff
Patch (109.43 KB, patch)
2020-09-07 11:36 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff
Patch (116.28 KB, patch)
2020-09-07 14:41 PDT, Chris Dumez
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 Dumez 2020-08-28 13:09:46 PDT
AudioParam.cancelAndHoldAtTime() is missing:
- https://www.w3.org/TR/webaudio/#dom-audioparam-cancelandholdattime
Comment 1 Radar WebKit Bug Importer 2020-09-04 13:10:12 PDT
<rdar://problem/68362061>
Comment 2 Chris Dumez 2020-09-06 17:44:26 PDT
Corresponding Blink patch: https://codereview.chromium.org/1533103002
Comment 3 Chris Dumez 2020-09-06 19:34:36 PDT
Created attachment 408161 [details]
WIP Patch
Comment 4 Chris Dumez 2020-09-06 19:53:34 PDT
Created attachment 408162 [details]
WIP Patch
Comment 5 Chris Dumez 2020-09-07 11:36:17 PDT
Created attachment 408189 [details]
Patch
Comment 6 Darin Adler 2020-09-07 11:57:26 PDT
Comment on attachment 408189 [details]
Patch

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

r=me assuming tests pass

> Source/WebCore/Modules/webaudio/AudioParamTimeline.cpp:196
> +    size_t i;
> +    // Find the first event at or just past cancelTime.
> +    for (i = 0; i < m_events.size(); ++i) {
> +        if (m_events[i]->time() > cancelTime)
> +            break;
> +    }

Vector::findMatching does this kind of thing, although it returns notFound instead of size() when not found.

> Source/WebCore/Modules/webaudio/AudioParamTimeline.cpp:217
> +    Optional<UniqueRef<ParamEvent>> newEvent;
> +    Optional<UniqueRef<ParamEvent>> newSetValueEvent;

Normally we’d use unique_ptr instead of Optional<UniqueRef>.

> Source/WebCore/Modules/webaudio/AudioParamTimeline.cpp:376
> +        ParamEvent& event = m_events[i].get();
> +        ParamEvent* nextEvent = i < n - 1 ? &m_events[i + 1].get() : nullptr;

auto&, auto or auto*

> Source/WebCore/Modules/webaudio/AudioParamTimeline.cpp:382
> +        ParamEvent::Type nextEventType = nextEvent ? static_cast<ParamEvent::Type>(nextEvent->type()) : ParamEvent::LastType /* unknown */;

auto

> Source/WebCore/Modules/webaudio/AudioParamTimeline.cpp:451
> +                {

This is brace style from another project, I think. But not just the new code.

> Source/WebCore/Modules/webaudio/AudioParamTimeline.cpp:605
> +inline float AudioParamTimeline::linearRampAtTime(Seconds t, float value1, Seconds time1, float value2, Seconds time2)

Seems unlikely we have to write "inline" to get inlining here.

> Source/WebCore/Modules/webaudio/AudioParamTimeline.cpp:610
> +inline float AudioParamTimeline::exponentialRampAtTime(Seconds t, float value1, Seconds time1, float value2, Seconds time2)

Ditto.

> Source/WebCore/Modules/webaudio/AudioParamTimeline.h:84
> +        static UniqueRef<ParamEvent> createSetValueEvent(float value, Seconds time)
> +        {
> +            return makeUniqueRef<ParamEvent>(ParamEvent::SetValue, value, time, 0, Seconds { }, Vector<float> { }, 0, 0, nullptr);
> +        }

Can we put most of the function bodies into the .cpp file instead of the header?
Comment 7 Chris Dumez 2020-09-07 12:32:06 PDT
Comment on attachment 408189 [details]
Patch

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

>> Source/WebCore/Modules/webaudio/AudioParamTimeline.cpp:217
>> +    Optional<UniqueRef<ParamEvent>> newSetValueEvent;
> 
> Normally we’d use unique_ptr instead of Optional<UniqueRef>.

Yes, I wanted that. I could not find a nice way to convert a unique_ptr to a UniqueRef though. How do we do that? Or should I add a function to UniqueRef to construct from a unique_ptr?
Comment 8 Chris Dumez 2020-09-07 12:53:15 PDT
(In reply to Chris Dumez from comment #7)
> Comment on attachment 408189 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=408189&action=review
> 
> >> Source/WebCore/Modules/webaudio/AudioParamTimeline.cpp:217
> >> +    Optional<UniqueRef<ParamEvent>> newSetValueEvent;
> > 
> > Normally we’d use unique_ptr instead of Optional<UniqueRef>.
> 
> Yes, I wanted that. I could not find a nice way to convert a unique_ptr to a
> UniqueRef though. How do we do that? Or should I add a function to UniqueRef
> to construct from a unique_ptr?

I might be missing something but it seems we can easily go from a UniqueRef to unique_ptr but not the other way around. Seems like a potential hole in our current API?

My proposal would be to add a new static function to UniqueRef<>, e.g.

static UniqueRef fromUniquePtr(unique_ptr p);
With an assertion in there to make sure p is non-null.
Comment 9 Chris Dumez 2020-09-07 14:19:29 PDT
(In reply to Chris Dumez from comment #8)
> (In reply to Chris Dumez from comment #7)
> > Comment on attachment 408189 [details]
> > Patch
> > 
> > View in context:
> > https://bugs.webkit.org/attachment.cgi?id=408189&action=review
> > 
> > >> Source/WebCore/Modules/webaudio/AudioParamTimeline.cpp:217
> > >> +    Optional<UniqueRef<ParamEvent>> newSetValueEvent;
> > > 
> > > Normally we’d use unique_ptr instead of Optional<UniqueRef>.
> > 
> > Yes, I wanted that. I could not find a nice way to convert a unique_ptr to a
> > UniqueRef though. How do we do that? Or should I add a function to UniqueRef
> > to construct from a unique_ptr?
> 
> I might be missing something but it seems we can easily go from a UniqueRef
> to unique_ptr but not the other way around. Seems like a potential hole in
> our current API?
> 
> My proposal would be to add a new static function to UniqueRef<>, e.g.
> 
> static UniqueRef fromUniquePtr(unique_ptr p);
> With an assertion in there to make sure p is non-null.

template<typename T>
UniqueRef<T> makeUniqueRefFromNonNullUniquePtr(std::unique_ptr<T> ptr)
{
    static_assert(std::is_same<typename T::webkitFastMalloced, int>::value, "T is FastMalloced");
    return UniqueRef<T>(*ptr.release());
}

Thoughts?

Although the Optional<UniqueRef<T>> solution in my patch was kind of nice because I did not need moveToUniquePtr() or makeUniqueRefFromNonNullUniquePtr().
Comment 10 Chris Dumez 2020-09-07 14:41:56 PDT
Created attachment 408197 [details]
Patch
Comment 11 EWS 2020-09-07 18:35:18 PDT
Committed r266712: <https://trac.webkit.org/changeset/266712>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 408197 [details].