Bug 187627 - Support connecting a MediaStreamAudioDestinationNode to RTCPeerConnection
Summary: Support connecting a MediaStreamAudioDestinationNode to RTCPeerConnection
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebRTC (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: youenn fablet
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2018-07-12 16:34 PDT by youenn fablet
Modified: 2018-07-13 17:04 PDT (History)
4 users (show)

See Also:


Attachments
Patch (19.09 KB, patch)
2018-07-12 16:41 PDT, youenn fablet
no flags Details | Formatted Diff | Diff
Patch (22.52 KB, patch)
2018-07-12 17:09 PDT, youenn fablet
no flags Details | Formatted Diff | Diff
Patch (22.62 KB, patch)
2018-07-12 17:47 PDT, youenn fablet
no flags Details | Formatted Diff | Diff
Patch (22.33 KB, patch)
2018-07-13 12:18 PDT, youenn fablet
no flags Details | Formatted Diff | Diff
Patch for landing (30.02 KB, patch)
2018-07-13 16:20 PDT, youenn fablet
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description youenn fablet 2018-07-12 16:34:16 PDT
We basically need to implement MediaStreamAudioSource
Comment 1 youenn fablet 2018-07-12 16:41:19 PDT
Created attachment 344901 [details]
Patch
Comment 2 youenn fablet 2018-07-12 16:41:43 PDT
<rdar://problem/35334400>
Comment 3 youenn fablet 2018-07-12 17:09:02 PDT
Created attachment 344905 [details]
Patch
Comment 4 youenn fablet 2018-07-12 17:47:30 PDT
Created attachment 344906 [details]
Patch
Comment 5 Eric Carlson 2018-07-12 18:43:18 PDT
Comment on attachment 344906 [details]
Patch

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

> Source/WebCore/Modules/webaudio/MediaStreamAudioSourceCocoa.cpp:58
> +    if (bus.numberOfChannels() != 1 && bus.numberOfChannels() != 2)
> +        return;

It is probably worth adding a release error log here.

> Source/WebCore/Modules/webaudio/MediaStreamAudioSourceCocoa.cpp:93
> +        auto* buffer = audioBufferList.buffer(0);
> +        buffer->mDataByteSize = numberOfFrames * sizeof(float);
> +        buffer->mNumberChannels = 1;
> +        if (!muted())
> +            memcpy(buffer->mData, bus.channel(0)->data(), buffer->mDataByteSize);
> +        else
> +            memset(buffer->mData, 0, buffer->mDataByteSize);
> +    } else {
> +        auto* buffer = audioBufferList.buffer(0);
> +        buffer->mDataByteSize = numberOfFrames * sizeof(float);
> +        buffer->mNumberChannels = 1;
> +        if (!muted())
> +            memcpy(buffer->mData, bus.channel(0)->data(), buffer->mDataByteSize);
> +        else
> +            memset(buffer->mData, 0, buffer->mDataByteSize);
> +
> +        buffer = audioBufferList.buffer(1);
> +        buffer->mDataByteSize = numberOfFrames * sizeof(float);
> +        buffer->mNumberChannels = 1;
> +        if (!muted())
> +            memcpy(buffer->mData, bus.channel(1)->data(), buffer->mDataByteSize);
> +        else
> +            memset(buffer->mData, 0, buffer->mDataByteSize);
> +

A helper function would simplify this, something like:

static void setupBuffer(WebAudioBufferList audioBufferList, int channel, size_t numberOfFrames)
{
    auto* buffer = audioBufferList.buffer(channel);
    buffer->mDataByteSize = numberOfFrames * sizeof(float);
    buffer->mNumberChannels = 1;
    if (!muted())
        memcpy(buffer->mData, bus.channel(channel)->data(), buffer->mDataByteSize);
    else
        memset(buffer->mData, 0, buffer->mDataByteSize);
}
Comment 6 youenn fablet 2018-07-13 12:18:17 PDT
Created attachment 344965 [details]
Patch
Comment 7 Jer Noble 2018-07-13 15:57:16 PDT
Comment on attachment 344965 [details]
Patch

r=me, with nits.

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

> Source/WebCore/Modules/webaudio/MediaStreamAudioDestinationNode.cpp:48
> +static inline Ref<MediaStream> createMediaStream(ScriptExecutionContext& context, Ref<RealtimeMediaSource>&& source)
> +{
> +    auto mediaStreamPrivate = MediaStreamPrivate::create(Vector<Ref<RealtimeMediaSource>>::from(WTFMove(source)), { });
> +    return MediaStream::create(context, WTFMove(mediaStreamPrivate));
> +}
> +

This seems really awkward. Why isn't this a static create() method on MediaStream, taking a context and source?

> Source/WebCore/Modules/webaudio/MediaStreamAudioSource.h:-58
> -    void setAudioFormat(size_t numberOfChannels, float sampleRate);
> -    void consumeAudio(AudioBus*, size_t numberOfFrames);
> -
> -    void addAudioConsumer(AudioDestinationConsumer*);
> -    bool removeAudioConsumer(AudioDestinationConsumer*);
> -    const Vector<RefPtr<AudioDestinationConsumer>>& audioConsumers() const { return m_audioConsumers; }

It looks like this was the only use of AudioDestinationConsumer, so you might as well just remove AudioDestinationConsumer.h entirely.
Comment 8 youenn fablet 2018-07-13 16:20:16 PDT
Created attachment 345000 [details]
Patch for landing
Comment 9 youenn fablet 2018-07-13 16:21:22 PDT
Thanks for the review.


> A helper function would simplify this, something like:
> 
> static void setupBuffer(WebAudioBufferList audioBufferList, int channel,
> size_t numberOfFrames)

Added a helper routine.

> > +static inline Ref<MediaStream> createMediaStream(ScriptExecutionContext& context, Ref<RealtimeMediaSource>&& source)
> > +{
> > +    auto mediaStreamPrivate = MediaStreamPrivate::create(Vector<Ref<RealtimeMediaSource>>::from(WTFMove(source)), { });
> > +    return MediaStream::create(context, WTFMove(mediaStreamPrivate));
> > +}
> > +
> 
> This seems really awkward. Why isn't this a static create() method on
> MediaStream, taking a context and source?

OK, added a create to MediaStreamPrivate.

> > Source/WebCore/Modules/webaudio/MediaStreamAudioSource.h:-58
> > -    void setAudioFormat(size_t numberOfChannels, float sampleRate);
> > -    void consumeAudio(AudioBus*, size_t numberOfFrames);
> > -
> > -    void addAudioConsumer(AudioDestinationConsumer*);
> > -    bool removeAudioConsumer(AudioDestinationConsumer*);
> > -    const Vector<RefPtr<AudioDestinationConsumer>>& audioConsumers() const { return m_audioConsumers; }
> 
> It looks like this was the only use of AudioDestinationConsumer, so you
> might as well just remove AudioDestinationConsumer.h entirely.

OK
Comment 10 WebKit Commit Bot 2018-07-13 17:04:38 PDT
Comment on attachment 345000 [details]
Patch for landing

Clearing flags on attachment: 345000

Committed r233829: <https://trac.webkit.org/changeset/233829>
Comment 11 WebKit Commit Bot 2018-07-13 17:04:39 PDT
All reviewed patches have been landed.  Closing bug.