Bug 205645

Summary: Apply rotation at source level if WebRTC sink ask so
Product: WebKit Reporter: youenn fablet <youennf>
Component: WebRTCAssignee: youenn fablet <youennf>
Status: RESOLVED FIXED    
Severity: Normal CC: commit-queue, eric.carlson, ews-watchlist, glenn, hta, jer.noble, philipj, sergio, tommyw, webkit-bug-importer, youennf
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
Patch
none
Patch
none
Patch
none
Patch
none
Patch
none
Patch
none
Potential build fix
none
Potential build fix none

Description youenn fablet 2019-12-30 06:41:15 PST
Apply rotation at source level if WebRTC sink ask so.
This allows to do rotation in UIProcess/GPUProcess if needed.
Comment 1 youenn fablet 2019-12-30 06:48:55 PST
Created attachment 386530 [details]
Patch
Comment 2 youenn fablet 2019-12-30 09:08:45 PST
Created attachment 386538 [details]
Patch
Comment 3 Eric Carlson 2019-12-30 09:27:06 PST
Comment on attachment 386538 [details]
Patch

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

> Source/WebCore/platform/graphics/cv/ImageRotationSessionVT.mm:123
> +    IntSize size { (int)CVPixelBufferGetWidth(pixelBuffer) , (int)CVPixelBufferGetHeight(pixelBuffer) };

s/(pixelBuffer) , (int)/(pixelBuffer), (int)/

> Source/WebCore/platform/mediastream/RealtimeOutgoingVideoSource.cpp:94
> +    if (!shouldApplyRotation || shouldApplyRotation == m_areSinksAskingToApplyRotation)
> +        return;
> +
> +    m_areSinksAskingToApplyRotation = true;
> +    if (!m_videoSource->source().setShouldApplyRotation(true))
> +        m_shouldApplyRotation = true;

Don't you want to clear m_areSinksAskingToApplyRotation and unapply rotation to the source if passed shouldApplyRotation==false?
Comment 4 youenn fablet 2019-12-30 09:36:05 PST
Created attachment 386540 [details]
Patch
Comment 5 youenn fablet 2019-12-30 09:37:26 PST
> > +    m_areSinksAskingToApplyRotation = true;
> > +    if (!m_videoSource->source().setShouldApplyRotation(true))
> > +        m_shouldApplyRotation = true;
> 
> Don't you want to clear m_areSinksAskingToApplyRotation and unapply rotation
> to the source if passed shouldApplyRotation==false?

Not really, for instance if the same track is given to two peer connections one with CVO enabled and the other with CVO disabled.
It is simpler to enable rotation at source level and never disable it.
In practice, this should happen rarely.
Comment 6 Eric Carlson 2019-12-30 09:48:49 PST
(In reply to youenn fablet from comment #5)
> > > +    m_areSinksAskingToApplyRotation = true;
> > > +    if (!m_videoSource->source().setShouldApplyRotation(true))
> > > +        m_shouldApplyRotation = true;
> > 
> > Don't you want to clear m_areSinksAskingToApplyRotation and unapply rotation
> > to the source if passed shouldApplyRotation==false?
> 
> Not really, for instance if the same track is given to two peer connections
> one with CVO enabled and the other with CVO disabled.
> It is simpler to enable rotation at source level and never disable it.
> In practice, this should happen rarely.

Then why have the 'shouldApplyRotation' parameter at all?
Comment 7 youenn fablet 2019-12-31 01:53:36 PST
Created attachment 386551 [details]
Patch
Comment 8 youenn fablet 2019-12-31 02:16:55 PST
(In reply to Eric Carlson from comment #6)
> (In reply to youenn fablet from comment #5)
> > > > +    m_areSinksAskingToApplyRotation = true;
> > > > +    if (!m_videoSource->source().setShouldApplyRotation(true))
> > > > +        m_shouldApplyRotation = true;
> > > 
> > > Don't you want to clear m_areSinksAskingToApplyRotation and unapply rotation
> > > to the source if passed shouldApplyRotation==false?
> > 
> > Not really, for instance if the same track is given to two peer connections
> > one with CVO enabled and the other with CVO disabled.
> > It is simpler to enable rotation at source level and never disable it.
> > In practice, this should happen rarely.
> 
> Then why have the 'shouldApplyRotation' parameter at all?

True, I removed it from RealtimeOutgoingVideoSource.
Comment 9 youenn fablet 2020-03-10 06:34:54 PDT
Created attachment 393143 [details]
Patch
Comment 10 Eric Carlson 2020-03-11 09:35:11 PDT
Comment on attachment 393143 [details]
Patch

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

> Source/WebCore/ChangeLog:9
> +        By default, the method does nothing and RealtimeOyutgoingVideoSource will continue to do the rotation itself.

s/RealtimeOyutgoingVideoSource/RealtimeOutgoingVideoSource/

> Source/WebCore/platform/graphics/cv/ImageRotationSessionVT.h:58
> +    ImageRotationSessionVT(const RotationProperties&, FloatSize, OSType pixelFormat, IsCGImageCompatible);

Nit: "pixelFormat" doesn't seem necessary.

> Source/WebCore/platform/graphics/cv/ImageRotationSessionVT.h:72
> +    void initialize(const RotationProperties&, FloatSize, OSType pixelFormat, IsCGImageCompatible);

Ditto.

> Source/WebCore/platform/graphics/cv/ImageRotationSessionVT.mm:101
>      CVPixelBufferPoolRef rawPool = nullptr;
>      if (auto err = CVPixelBufferPoolCreate(kCFAllocatorDefault, nullptr, (__bridge CFDictionaryRef)pixelAttributes, &rawPool); err != noErr)

I now this isn't new, but it seems like a bad idea to use a NULL buffer pool if this fails.

> Source/WebCore/platform/mediastream/RealtimeMediaSource.h:200
> +    virtual bool setShouldApplyRotation(bool /* shouldApplyRotation */) { return false; }

Nit: the method name is quite descriptive so the commented out parameter name doesn't seem necessary.

> Source/WebKit/UIProcess/Cocoa/UserMediaCaptureManagerProxy.cpp:195
> +    bool m_shouldApplyRotation { false };

It doesn't look like this is used.

> Source/WebKit/WebProcess/cocoa/UserMediaCaptureManager.cpp:226
> +    bool setShouldApplyRotation(bool /* shouldApplyRotation */) final;

Same comment as above.
Comment 11 youenn fablet 2020-03-13 00:56:07 PDT
Created attachment 393464 [details]
Patch
Comment 12 WebKit Commit Bot 2020-03-13 03:13:18 PDT
Comment on attachment 393464 [details]
Patch

Clearing flags on attachment: 393464

Committed r258391: <https://trac.webkit.org/changeset/258391>
Comment 13 WebKit Commit Bot 2020-03-13 03:13:20 PDT
All reviewed patches have been landed.  Closing bug.
Comment 14 Radar WebKit Bug Importer 2020-03-13 03:14:17 PDT
<rdar://problem/60411815>
Comment 15 Ryan Haddad 2020-03-13 13:22:59 PDT
Reverted in https://trac.webkit.org/changeset/258424/webkit because it broke internal builds. Build logs in radar.
Comment 16 youenn fablet 2020-03-16 03:51:54 PDT
Created attachment 393644 [details]
Potential build fix
Comment 17 youenn fablet 2020-03-16 05:34:45 PDT
Created attachment 393649 [details]
Potential build fix
Comment 18 WebKit Commit Bot 2020-03-16 09:41:19 PDT
Comment on attachment 393649 [details]
Potential build fix

Clearing flags on attachment: 393649

Committed r258504: <https://trac.webkit.org/changeset/258504>
Comment 19 WebKit Commit Bot 2020-03-16 09:41:21 PDT
All reviewed patches have been landed.  Closing bug.