Bug 215591 - AudioContext.getOutputTimestamp() is missing
Summary: AudioContext.getOutputTimestamp() 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-17 16:05 PDT by Chris Dumez
Modified: 2020-08-18 09:32 PDT (History)
21 users (show)

See Also:


Attachments
Patch (37.63 KB, patch)
2020-08-17 16:10 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff
Patch (38.33 KB, patch)
2020-08-17 16:20 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff
Patch (39.73 KB, patch)
2020-08-17 17:49 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff
Patch (39.76 KB, patch)
2020-08-17 17:52 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff
Patch (39.78 KB, patch)
2020-08-17 18:06 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-17 16:05:50 PDT
AudioContext.getOutputTimestamp() is missing:
- https://www.w3.org/TR/webaudio/#dom-audiocontext-getoutputtimestamp
Comment 1 Chris Dumez 2020-08-17 16:10:57 PDT
Created attachment 406750 [details]
Patch
Comment 2 Chris Dumez 2020-08-17 16:20:49 PDT
Created attachment 406753 [details]
Patch
Comment 3 Darin Adler 2020-08-17 17:28:58 PDT
Comment on attachment 406753 [details]
Patch

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

> Source/WebCore/Modules/webaudio/AudioContext.cpp:105
> +        return AudioTimestamp { 0, 0 };

Should not need to write the class name here.

> Source/WebCore/Modules/webaudio/AudioContext.cpp:114
> +    if (position.position.seconds() > currentTime())
> +        position.position = Seconds { currentTime() };

We often write this kind of clamping using std::max instead of an if statement.

> Source/WebCore/Modules/webaudio/AudioContext.cpp:118
> +    if (performanceTime < 0.0)
> +        performanceTime = 0.0;

We often write this kind of clamping using std::max instead of an if statement.

> Source/WebCore/Modules/webaudio/AudioContext.cpp:120
> +    return AudioTimestamp { position.position.seconds(), performanceTime };

Should not need to write the class name here.

> Source/WebCore/Modules/webaudio/AudioContext.h:33
> +struct AudioTimestamp;

Typically the struct paragraph is separate and below the class paragraph.

> Source/WebCore/Modules/webaudio/BaseAudioContext.cpp:771
> +    AutoLocker locker(*this);
> +    return m_outputPosition;

The locking here doesn’t prevent races, but I suppose it prevents undefined behavior or getting mismatched structure values.

> Source/WebCore/platform/audio/AudioIOCallback.h:30
>  #ifndef AudioIOCallback_h
>  #define AudioIOCallback_h

#pragma once

> Source/WebCore/platform/audio/AudioIOCallback.h:53
> +    static WARN_UNUSED_RETURN bool decode(Decoder& decoder, AudioIOPosition& result)

I think we want the version that returns Optional rather than the version that returns bool.

> Source/WebCore/platform/audio/cocoa/AudioDestinationCocoa.cpp:161
> +static MonotonicTime machAbsoluteTimeToMonotonicTime(uint64_t machAbsoluteTime)
> +{
> +    // Based on listing #2 from Apple QA 1398, but modified to be thread-safe.
> +    static mach_timebase_info_data_t timebaseInfo;
> +    static std::once_flag initializeTimerOnceFlag;
> +    std::call_once(initializeTimerOnceFlag, [] {
> +        kern_return_t kr = mach_timebase_info(&timebaseInfo);
> +        ASSERT_UNUSED(kr, kr == KERN_SUCCESS);
> +        ASSERT(timebaseInfo.denom);
> +    });
> +
> +    return MonotonicTime::fromRawSeconds((machAbsoluteTime * timebaseInfo.numer) / (1.0e9 * timebaseInfo.denom));
> +}

This seems like a peculiar place for this function, which doesn’t seem to be specific to audio, just to Cocoa. Should we put this alongside the MonotonicTime class instead?

> Source/WebCore/platform/audio/cocoa/AudioDestinationCocoa.h:70
> +    OSStatus render(const AudioTimeStamp* timestamp, UInt32 numberOfFrames, AudioBufferList* ioData);

No need for the argument name "timestamp" here.
Comment 4 Chris Dumez 2020-08-17 17:49:26 PDT
Created attachment 406758 [details]
Patch
Comment 5 Chris Dumez 2020-08-17 17:52:12 PDT
Created attachment 406760 [details]
Patch
Comment 6 Chris Dumez 2020-08-17 18:06:46 PDT
Created attachment 406761 [details]
Patch
Comment 7 EWS 2020-08-17 19:16:18 PDT
Committed r265797: <https://trac.webkit.org/changeset/265797>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 406761 [details].
Comment 8 Radar WebKit Bug Importer 2020-08-17 19:17:15 PDT
<rdar://problem/67288515>
Comment 9 Chris Dumez 2020-08-18 09:32:20 PDT
Follow-up landed in <https://trac.webkit.org/changeset/265819> to address fast/mediastream/getUserMedia-webaudio.html test failure.