Bug 217552 - Clean up CAAudioStreamDescription
Summary: Clean up CAAudioStreamDescription
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Media (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Peng Liu
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2020-10-09 20:29 PDT by Peng Liu
Modified: 2020-10-26 11:24 PDT (History)
8 users (show)

See Also:


Attachments
Patch (7.52 KB, patch)
2020-10-09 20:44 PDT, Peng Liu
no flags Details | Formatted Diff | Diff
Fix crashes in layout tests (8.49 KB, patch)
2020-10-10 14:29 PDT, Peng Liu
no flags Details | Formatted Diff | Diff
Patch (1.34 KB, patch)
2020-10-23 16:28 PDT, Peng Liu
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Peng Liu 2020-10-09 20:29:44 PDT
Clean up CAAudioStreamDescription
Comment 1 Peng Liu 2020-10-09 20:44:14 PDT
Created attachment 411004 [details]
Patch
Comment 2 Peng Liu 2020-10-10 14:29:25 PDT
Created attachment 411020 [details]
Fix crashes in layout tests
Comment 3 youenn fablet 2020-10-12 03:06:17 PDT
Comment on attachment 411020 [details]
Fix crashes in layout tests

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

> Source/WebCore/ChangeLog:9
> +        constructor and assignment operator because of the updates on the two getters.

Can you describe the benefit of this change?

> Source/WebCore/platform/audio/cocoa/CAAudioStreamDescription.cpp:117
>      return m_platformDescription;

This is a potential change of behavior.
m_streamDescription could for instance be modified (for instance using streamDescription() non const getter).
This would make m_platformDescription out of sync.

> Source/WebCore/platform/audio/cocoa/CAAudioStreamDescription.cpp:122
> +    return m_format;

Why removing the lazy init of m_format?
Comment 4 Peng Liu 2020-10-12 09:45:30 PDT
Comment on attachment 411020 [details]
Fix crashes in layout tests

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

>> Source/WebCore/ChangeLog:9
>> +        constructor and assignment operator because of the updates on the two getters.
> 
> Can you describe the benefit of this change?

Sure.
I encountered some weirdness(linker errors) when I tried to move the WEBCORE_EXPORT from the class to methods, so I took a closer look and found this class looks strange. The class defines the function calculateFormat() but does not provide an implementation, and CAAudioStreamDescription::platformDescription() always needs to update m_platformDescription.

>> Source/WebCore/platform/audio/cocoa/CAAudioStreamDescription.cpp:117
>>      return m_platformDescription;
> 
> This is a potential change of behavior.
> m_streamDescription could for instance be modified (for instance using streamDescription() non const getter).
> This would make m_platformDescription out of sync.

Oops, sounds not a good encapsulation. Should we disable that possibility?

>> Source/WebCore/platform/audio/cocoa/CAAudioStreamDescription.cpp:122
>> +    return m_format;
> 
> Why removing the lazy init of m_format?

So it is just a lazy init? I thought we may need to do some unnecessary work whenever format() is called.
Comment 5 youenn fablet 2020-10-12 09:56:50 PDT
Comment on attachment 411020 [details]
Fix crashes in layout tests

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

>>> Source/WebCore/platform/audio/cocoa/CAAudioStreamDescription.cpp:117
>>>      return m_platformDescription;
>> 
>> This is a potential change of behavior.
>> m_streamDescription could for instance be modified (for instance using streamDescription() non const getter).
>> This would make m_platformDescription out of sync.
> 
> Oops, sounds not a good encapsulation. Should we disable that possibility?

Actually, I was wrong here since we pass m_streamDescription as a pointer and not by value.
If we can remove streamDescription() non const getter, we should probably do it in any case.

I am not sure platformDescription is called much, so a lazy init seems fine here.

>>> Source/WebCore/platform/audio/cocoa/CAAudioStreamDescription.cpp:122
>>> +    return m_format;
>> 
>> Why removing the lazy init of m_format?
> 
> So it is just a lazy init? I thought we may need to do some unnecessary work whenever format() is called.

It is a half lazy init. Agreed, it is a bit weird also since m_streamDescription could change but we would not change m_format accordingly if m_format is not None.
I guess that to make it clearer, we could use an Optional<Format>.
Comment 6 Radar WebKit Bug Importer 2020-10-16 20:30:31 PDT
<rdar://problem/70401637>
Comment 7 Peng Liu 2020-10-23 15:40:27 PDT
Comment on attachment 411020 [details]
Fix crashes in layout tests

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

>>>> Source/WebCore/platform/audio/cocoa/CAAudioStreamDescription.cpp:122
>>>> +    return m_format;
>>> 
>>> Why removing the lazy init of m_format?
>> 
>> So it is just a lazy init? I thought we may need to do some unnecessary work whenever format() is called.
> 
> It is a half lazy init. Agreed, it is a bit weird also since m_streamDescription could change but we would not change m_format accordingly if m_format is not None.
> I guess that to make it clearer, we could use an Optional<Format>.

Yeah, seems better to use an Optional<>. However, it won't solve the problem when m_streamDescription is changed by other objects.
Comment 8 Peng Liu 2020-10-23 16:28:34 PDT
Created attachment 412215 [details]
Patch
Comment 9 Peng Liu 2020-10-26 09:46:31 PDT
Looks like it is not a good idea to refactor the CAAudioStreamDescription class now. Let’s remove the unused private function and close this bug.
Comment 10 EWS 2020-10-26 11:24:15 PDT
Committed r268988: <https://trac.webkit.org/changeset/268988>

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