Bug 167961 - [WebRTC] Implement Incoming libwebrtc audio source support.
Summary: [WebRTC] Implement Incoming libwebrtc audio source support.
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebCore Misc. (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: youenn fablet
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-02-07 15:28 PST by youenn fablet
Modified: 2017-02-21 15:17 PST (History)
4 users (show)

See Also:


Attachments
Patch (23.22 KB, patch)
2017-02-07 15:30 PST, youenn fablet
no flags Details | Formatted Diff | Diff
Patch (27.81 KB, patch)
2017-02-09 18:15 PST, youenn fablet
no flags Details | Formatted Diff | Diff
Patch (5.80 KB, patch)
2017-02-20 16:53 PST, youenn fablet
no flags Details | Formatted Diff | Diff
Copying data (5.86 KB, patch)
2017-02-21 11:09 PST, youenn fablet
no flags Details | Formatted Diff | Diff
Patch for landing (5.97 KB, patch)
2017-02-21 14:31 PST, 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 2017-02-07 15:28:02 PST
[WebRTC] Implement Incoming libwebrtc audio source support.
Comment 1 youenn fablet 2017-02-07 15:30:25 PST
Created attachment 300855 [details]
Patch
Comment 2 youenn fablet 2017-02-07 15:32:25 PST
Patch is not working in my branch.
startProducingData is not called.
The timer in an audio element consuming this track gets updated to "ty aN:aN", so something is probably not correct in the set-up of the audio source.

If somebody has an idea, please let me know.
Otherwise, I'll debug this tomorrow.
Comment 3 youenn fablet 2017-02-09 18:15:45 PST
Created attachment 301116 [details]
Patch
Comment 4 Eric Carlson 2017-02-10 08:45:38 PST
Comment on attachment 301116 [details]
Patch

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

> Source/WebCore/platform/audio/mac/AudioSampleDataSource.cpp:299
> +    if (!m_ringBuffer || m_muted)

Nit: won't get this far if there isn't a ring buffer.

> Source/WebCore/platform/mediastream/mac/RealtimeIncomingAudioSource.cpp:116
> +    size_t dataSize = numberOfFrames * numberOfChannels * sizeof(uint16_t);
> +    CMBlockBufferRef dataBuffer;
> +    OSStatus error = CMBlockBufferCreateWithMemoryBlock(nullptr, nullptr, dataSize, nullptr, nullptr, 0, dataSize, 0, &dataBuffer);
> +    ASSERT_UNUSED(error, !error);
> +
> +    error = CMBlockBufferReplaceDataBytes(data, dataBuffer, 0 , dataSize);
> +    ASSERT(!error);
> +
> +    CMSampleBufferRef sampleBuffer;
> +    OSStatus result = CMAudioSampleBufferCreateWithPacketDescriptions(nullptr, nullptr, true, nullptr, nullptr, m_formatDescription.get(), numberOfFrames, startTime, nullptr, &sampleBuffer);
> +    ASSERT(sampleBuffer);
> +    ASSERT_UNUSED(result, !result);
> +    if (!sampleBuffer)
> +        return;
> +
> +    result = CMSampleBufferSetDataReady(sampleBuffer);
> +    ASSERT(!result);
> +

Nit: none of this is necessary if m_audioSourceObservers is empty. We should change the web audio audio observer callback to take a buffer list instead of a sample buffer.
Comment 5 youenn fablet 2017-02-20 16:53:29 PST
Created attachment 302205 [details]
Patch
Comment 6 youenn fablet 2017-02-21 11:09:50 PST
Created attachment 302287 [details]
Copying data
Comment 7 Eric Carlson 2017-02-21 14:26:49 PST
Comment on attachment 302287 [details]
Copying data

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

> Source/WebCore/ChangeLog:8
> +        Hooking libwebrtc incoming audio source into WebCore audio rendering path.

Nit: "Hooking" -> "Hook"

> Source/WebCore/platform/mediastream/mac/RealtimeIncomingAudioSource.cpp:98
> +    WebAudioBufferList audioBufferList { CAAudioStreamDescription(m_streamFormat), WTF::safeCast<uint32_t>(numberOfFrames) };
> +    audioBufferList.buffer(0)->mDataByteSize = numberOfChannels * numberOfFrames * bitsPerSample / 8;
> +    audioBufferList.buffer(0)->mNumberChannels = numberOfChannels;
> +    memcpy(audioBufferList.buffer(0)->mData, audioData, audioBufferList.buffer(0)->mDataByteSize);
> +
> +    audioSamplesAvailable(mediaTime, audioBufferList, CAAudioStreamDescription(m_streamFormat), numberOfFrames);

Nit: please add a FIXME here, we should not have to copy this data because it will be copied into the data source on the other end of this call.
Comment 8 youenn fablet 2017-02-21 14:31:47 PST
Created attachment 302308 [details]
Patch for landing
Comment 9 youenn fablet 2017-02-21 14:32:10 PST
Thanks for the review.

(In reply to comment #7)
> Comment on attachment 302287 [details]
> Copying data
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=302287&action=review
> 
> > Source/WebCore/ChangeLog:8
> > +        Hooking libwebrtc incoming audio source into WebCore audio rendering path.
> 
> Nit: "Hooking" -> "Hook"

Done

> > Source/WebCore/platform/mediastream/mac/RealtimeIncomingAudioSource.cpp:98
> > +    WebAudioBufferList audioBufferList { CAAudioStreamDescription(m_streamFormat), WTF::safeCast<uint32_t>(numberOfFrames) };
> > +    audioBufferList.buffer(0)->mDataByteSize = numberOfChannels * numberOfFrames * bitsPerSample / 8;
> > +    audioBufferList.buffer(0)->mNumberChannels = numberOfChannels;
> > +    memcpy(audioBufferList.buffer(0)->mData, audioData, audioBufferList.buffer(0)->mDataByteSize);
> > +
> > +    audioSamplesAvailable(mediaTime, audioBufferList, CAAudioStreamDescription(m_streamFormat), numberOfFrames);
> 
> Nit: please add a FIXME here, we should not have to copy this data because
> it will be copied into the data source on the other end of this call.

Done
Comment 10 WebKit Commit Bot 2017-02-21 15:17:48 PST
Comment on attachment 302308 [details]
Patch for landing

Clearing flags on attachment: 302308

Committed r212769: <http://trac.webkit.org/changeset/212769>
Comment 11 WebKit Commit Bot 2017-02-21 15:17:54 PST
All reviewed patches have been landed.  Closing bug.