Bug 168027 - Configure MockRealtimeAudioSourceMac to generate stereo audio
Summary: Configure MockRealtimeAudioSourceMac to generate stereo audio
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Jer Noble
URL:
Keywords: InRadar
Depends on:
Blocks: 168051
  Show dependency treegraph
 
Reported: 2017-02-08 16:40 PST by Jer Noble
Modified: 2022-10-26 03:44 PDT (History)
5 users (show)

See Also:


Attachments
Patch (50.04 KB, patch)
2017-02-08 17:54 PST, Jer Noble
eric.carlson: review+
Details | Formatted Diff | Diff
Patch for landing (50.20 KB, patch)
2017-02-08 21:36 PST, Jer Noble
no flags Details | Formatted Diff | Diff
Patch for landing (50.41 KB, patch)
2017-02-08 21:38 PST, Jer Noble
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Jer Noble 2017-02-08 16:40:23 PST
Configure MockRealtimeAudioSourceMac to generate stereo audio
Comment 1 Jer Noble 2017-02-08 17:54:02 PST
Created attachment 300992 [details]
Patch
Comment 2 Jer Noble 2017-02-08 17:56:15 PST
rdar://problem/30401723
Comment 3 Eric Carlson 2017-02-08 18:25:42 PST
Comment on attachment 300992 [details]
Patch

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

> Source/WebCore/platform/audio/mac/AudioSampleBufferList.cpp:53
> +    m_bufferList = std::make_unique<WebAudioBufferList>(format, m_maxBufferSizePerChannel);

This is unnecessary, te call to reset() below will do it.

> Source/WebCore/platform/mediastream/mac/AVAudioCaptureSource.mm:207
> +    OSStatus err = CMSampleBufferGetAudioBufferListWithRetainedBlockBuffer(sampleBuffer, nullptr, m_list->list(), m_listBufferSize, kCFAllocatorSystemDefault, kCFAllocatorSystemDefault, kCMSampleBufferFlag_AudioBufferList_Assure16ByteAlignment, &buffer);

Isn't this already done by the call to WebAudioBufferList:: WebAudioBufferList(const CAAudioStreamDescription&, CMSampleBufferRef)?
Comment 4 Jer Noble 2017-02-08 21:27:39 PST
Comment on attachment 300992 [details]
Patch

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

>> Source/WebCore/platform/audio/mac/AudioSampleBufferList.cpp:53
>> +    m_bufferList = std::make_unique<WebAudioBufferList>(format, m_maxBufferSizePerChannel);
> 
> This is unnecessary, te call to reset() below will do it.

Indeed!

>> Source/WebCore/platform/mediastream/mac/AVAudioCaptureSource.mm:207
>> +    OSStatus err = CMSampleBufferGetAudioBufferListWithRetainedBlockBuffer(sampleBuffer, nullptr, m_list->list(), m_listBufferSize, kCFAllocatorSystemDefault, kCFAllocatorSystemDefault, kCMSampleBufferFlag_AudioBufferList_Assure16ByteAlignment, &buffer);
> 
> Isn't this already done by the call to WebAudioBufferList:: WebAudioBufferList(const CAAudioStreamDescription&, CMSampleBufferRef)?

You're right!

> Source/WebCore/platform/mediastream/mac/MockRealtimeAudioSourceMac.mm:143
>      m_streamFormat.mSampleRate = m_sampleRate;
>      m_streamFormat.mFormatID = kAudioFormatLinearPCM;
> -    m_streamFormat.mFormatFlags = kAudioFormatFlagsNativeFloatPacked;
> -    m_streamFormat.mBytesPerPacket = bytesPerFloat * channelCount;
> +    m_streamFormat.mFormatFlags = kAudioFormatFlagsNativeFloatPacked | kAudioFormatFlagIsNonInterleaved;
> +    m_streamFormat.mBytesPerPacket = bytesPerFloat;
>      m_streamFormat.mFramesPerPacket = 1;
> -    m_streamFormat.mBytesPerFrame = bytesPerFloat * channelCount;
> +    m_streamFormat.mBytesPerFrame = bytesPerFloat;
>      m_streamFormat.mChannelsPerFrame = channelCount;
>      m_streamFormat.mBitsPerChannel = bitsPerByte * bytesPerFloat;

It also looks like this can all be replaced by a call to FillOutASBDForLPCM(). Will change before landing.
Comment 5 Jer Noble 2017-02-08 21:36:06 PST
Created attachment 301014 [details]
Patch for landing
Comment 6 Jer Noble 2017-02-08 21:38:40 PST
Created attachment 301016 [details]
Patch for landing
Comment 7 youenn fablet 2017-02-09 07:59:25 PST
Comment on attachment 301016 [details]
Patch for landing

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

> Source/WebCore/platform/mediastream/RealtimeMediaSource.h:113
> +    void audioSamplesAvailable(const MediaTime&, PlatformAudioData&, const AudioStreamDescription&, size_t);

It is not very clear to me why this takes a PlatformAudioData&.
I would expect either a const PlatformAudioData& or a PlatformAudioData&& as parameter.

Also, is the numberOfFrames a parameter on its own, or should it be part of PlatformAudioData?
Comment 8 WebKit Commit Bot 2017-02-09 08:34:39 PST
Comment on attachment 301016 [details]
Patch for landing

Clearing flags on attachment: 301016

Committed r211959: <http://trac.webkit.org/changeset/211959>
Comment 9 Jer Noble 2017-02-09 08:39:04 PST
(In reply to comment #7)
> Comment on attachment 301016 [details]
> Patch for landing
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=301016&action=review
> 
> > Source/WebCore/platform/mediastream/RealtimeMediaSource.h:113
> > +    void audioSamplesAvailable(const MediaTime&, PlatformAudioData&, const AudioStreamDescription&, size_t);
> 
> It is not very clear to me why this takes a PlatformAudioData&.
> I would expect either a const PlatformAudioData& or a PlatformAudioData&& as
> parameter.

It's not a && because the calling class retains ownership of the object. It's not const because we'd have to cast away the constness when accessing the wrapped ABL.

> Also, is the numberOfFrames a parameter on its own, or should it be part of
> PlatformAudioData?

The PlatformAudioData has a capacity, but not a numberOfFrames.  I don't think we want to tie together the concept of "please copy this number of frames out of this audio data" with the audio data structure itself.
Comment 10 Jer Noble 2017-02-09 08:49:50 PST
(In reply to comment #9)
> It's not const because we'd have to cast away the constness when accessing
> the wrapped ABL.

So it looks like you can make this entire path const-correct, but it's a significant code change, deserving of its own patch.
Comment 11 Jer Noble 2017-02-09 09:05:12 PST
(In reply to comment #10)
> (In reply to comment #9)
> > It's not const because we'd have to cast away the constness when accessing
> > the wrapped ABL.
> 
> So it looks like you can make this entire path const-correct, but it's a
> significant code change, deserving of its own patch.

See <https://bugs.webkit.org/show_bug.cgi?id=168051>
Comment 12 Ahmad Saleem 2022-10-26 03:44:33 PDT
It seems this landed:

https://github.com/WebKit/WebKit/commit/c71329a506449e928ab40cc4a0496260f6881336

and didn't backed out and follow-up bug also corrected the other bits.

Marking this as "RESOLVED FIXED".