Bug 204979 - The value of [AVPlayerViewController isPictureInPicturePossible] is NO in the first attempt to enter PiP
Summary: The value of [AVPlayerViewController isPictureInPicturePossible] is NO in the...
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: Peng Liu
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2019-12-07 00:03 PST by Peng Liu
Modified: 2020-04-05 21:02 PDT (History)
12 users (show)

See Also:


Attachments
Patch (6.62 KB, patch)
2019-12-07 00:37 PST, Peng Liu
no flags Details | Formatted Diff | Diff
Patch (Updated to fix build failures) (7.24 KB, patch)
2019-12-09 09:44 PST, Peng Liu
no flags Details | Formatted Diff | Diff
Patch (7.50 KB, patch)
2020-03-17 20:54 PDT, Peng Liu
jer.noble: review+
Details | Formatted Diff | Diff
Patch for landing (7.34 KB, patch)
2020-03-18 10:02 PDT, Peng Liu
no flags Details | Formatted Diff | Diff
Patch to fix a watch OS build failure (6.04 KB, patch)
2020-03-18 16:06 PDT, Peng Liu
no flags Details | Formatted Diff | Diff
patch to fix build failures (8.17 KB, patch)
2020-03-18 18:06 PDT, Peng Liu
no flags Details | Formatted Diff | Diff
patch to fix build failures (8.18 KB, patch)
2020-03-18 18:08 PDT, Peng Liu
no flags Details | Formatted Diff | Diff
A follow-up patch to fix mistakes on #if HAVE(HAVE_AVOBSERVATIONCONTROLLER) (5.28 KB, patch)
2020-04-05 14:47 PDT, Peng Liu
darin: review+
Details | Formatted Diff | Diff
Fix iOS build failures by adding NS_ASSUME_NONNULL_BEGIN/NS_ASSUME_NONNULL_END (5.60 KB, patch)
2020-04-05 17:53 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 2019-12-07 00:03:55 PST
The value of [AVPlayerViewControl isPictureInPicturePossible] is NO in the first attempt to enter PiP
Comment 1 Peng Liu 2019-12-07 00:04:39 PST
<rdar://problem/57671139>
Comment 2 Peng Liu 2019-12-07 00:37:17 PST
Created attachment 385086 [details]
Patch
Comment 3 Peng Liu 2019-12-09 09:44:56 PST
Created attachment 385160 [details]
Patch (Updated to fix build failures)
Comment 4 Peng Liu 2020-03-17 20:54:28 PDT
Created attachment 393821 [details]
Patch
Comment 5 Jer Noble 2020-03-18 08:34:11 PDT
Comment on attachment 393821 [details]
Patch

r=me. Is there a radar on the weird PiP behavior here? If so, it would be great to have a "FIXME: remove this once XXX is fixed" comment in this area.
Comment 6 Eric Carlson 2020-03-18 08:48:32 PDT
Comment on attachment 393821 [details]
Patch

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

> Source/WebCore/platform/ios/VideoFullscreenInterfaceAVKit.mm:1380
> +        [m_playerViewController tryToStartPictureInPicture];

Won't this fail to enter PiP if @pictureInPicturePossible is already true and so doesn't change?

Maybe something like this would be better?

         if ([m_playerViewController isPictureInPicturePossible])
             [m_playerViewController startPictureInPicture];
         else
             [m_playerViewController tryToStartPictureInPicture];
Comment 7 Peng Liu 2020-03-18 09:43:09 PDT
(In reply to Jer Noble from comment #5)
> Comment on attachment 393821 [details]
> Patch
> 
> r=me. Is there a radar on the weird PiP behavior here? If so, it would be
> great to have a "FIXME: remove this once XXX is fixed" comment in this area.

Thanks for the review.
Yes, there is a radar for it, but not for this patch. This patch is a protection after AVKit fixed their issue. We won’t remove it.
Comment 8 Peng Liu 2020-03-18 09:50:55 PDT
Comment on attachment 393821 [details]
Patch

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

>> Source/WebCore/platform/ios/VideoFullscreenInterfaceAVKit.mm:1380
>> +        [m_playerViewController tryToStartPictureInPicture];
> 
> Won't this fail to enter PiP if @pictureInPicturePossible is already true and so doesn't change?
> 
> Maybe something like this would be better?
> 
>          if ([m_playerViewController isPictureInPicturePossible])
>              [m_playerViewController startPictureInPicture];
>          else
>              [m_playerViewController tryToStartPictureInPicture];

No it won't fail because of “includeInitialValue:YES”. The initial value is treated as a change for _avPlayerViewControllerObservationController as well.

However, I think your suggestion is a great idea to simplify the logic for most cases. So I will update the patch. Thanks!
Comment 9 Peng Liu 2020-03-18 10:02:21 PDT
Created attachment 393874 [details]
Patch for landing
Comment 10 EWS 2020-03-18 12:18:43 PDT
Committed r258655: <https://trac.webkit.org/changeset/258655>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 393874 [details].
Comment 11 Darin Adler 2020-03-18 12:20:37 PDT
Comment on attachment 393874 [details]
Patch for landing

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

> Source/WebCore/platform/ios/VideoFullscreenInterfaceAVKit.mm:577
> +    _fullscreenInterface = nullptr;

What does this line of code accomplish?
Comment 12 Peng Liu 2020-03-18 13:23:24 PDT
Comment on attachment 393874 [details]
Patch for landing

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

>> Source/WebCore/platform/ios/VideoFullscreenInterfaceAVKit.mm:577
>> +    _fullscreenInterface = nullptr;
> 
> What does this line of code accomplish?

Oops, it does nothing useful. Will remove it in another patch.
Probably we need a refactoring to replace it with a smart pointer.
Comment 13 Peng Liu 2020-03-18 15:57:33 PDT
Reopen this bug to fix a watch os build failure.
Comment 14 Peng Liu 2020-03-18 16:06:13 PDT
Created attachment 393912 [details]
Patch to fix a watch OS build failure
Comment 15 David Kilzer (:ddkilzer) 2020-03-18 17:51:59 PDT
Comment on attachment 393912 [details]
Patch to fix a watch OS build failure

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

> Source/WebCore/PAL/pal/spi/cocoa/AVKitSPI.h:32
> +#if !PLATFORM(WATCHOS)
>  #import <AVKit/AVObservationController.h>
> +#endif

This header is also not present on macOS Mojave (build 18G103, for example).  I just hit a build failure on that build of macOS:

In file included from OpenSource/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlaybackTargetPickerMac.mm:36:
PAL/pal/spi/cocoa/AVKitSPI.h:30:9: fatal error: 'AVKit/AVObservationController.h' file not found
#import <AVKit/AVObservationController.h>
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
Comment 16 David Kilzer (:ddkilzer) 2020-03-18 17:55:14 PDT
Comment on attachment 393912 [details]
Patch to fix a watch OS build failure

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

>> Source/WebCore/PAL/pal/spi/cocoa/AVKitSPI.h:32
>> +#endif
> 
> This header is also not present on macOS Mojave (build 18G103, for example).  I just hit a build failure on that build of macOS:
> 
> In file included from OpenSource/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlaybackTargetPickerMac.mm:36:
> PAL/pal/spi/cocoa/AVKitSPI.h:30:9: fatal error: 'AVKit/AVObservationController.h' file not found
> #import <AVKit/AVObservationController.h>
>         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> 1 error generated.

Note that the AVObservationController class is available; the header just isn't there:

$ nm /System/Library/Frameworks/AVKit.framework/AVKit | grep AVObservationController | grep OBJC_CLASS
0000000000144bd0 S _OBJC_CLASS_$_AVObservationController

So maybe you can conditionally include the header here, and then just declare the classes/methods for Mojave in the USE(APPLE_INTERNAL_SDK) section?

+@class AVKeyValueChange;
+
+@interface AVObservationController<Owner> : NSObject
+- (instancetype)initWithOwner:(Owner)owner NS_DESIGNATED_INITIALIZER;
+- (id)startObserving:(id)object keyPath:(NSString *)keyPath includeInitialValue:(BOOL)shouldIncludeInitialValue observationHandler:(void (^)(Owner owner, id observed, AVKeyValueChange *change))observationHandler;
+- (void)stopAllObservation;
+@end
Comment 17 Peng Liu 2020-03-18 18:06:41 PDT
Created attachment 393927 [details]
patch to fix build failures
Comment 18 Peng Liu 2020-03-18 18:08:47 PDT
Created attachment 393928 [details]
patch to fix build failures
Comment 19 Peng Liu 2020-03-18 18:37:45 PDT
Comment on attachment 393912 [details]
Patch to fix a watch OS build failure

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

>>> Source/WebCore/PAL/pal/spi/cocoa/AVKitSPI.h:32
>>> +#endif
>> 
>> This header is also not present on macOS Mojave (build 18G103, for example).  I just hit a build failure on that build of macOS:
>> 
>> In file included from OpenSource/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlaybackTargetPickerMac.mm:36:
>> PAL/pal/spi/cocoa/AVKitSPI.h:30:9: fatal error: 'AVKit/AVObservationController.h' file not found
>> #import <AVKit/AVObservationController.h>
>>         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>> 1 error generated.
> 
> Note that the AVObservationController class is available; the header just isn't there:
> 
> $ nm /System/Library/Frameworks/AVKit.framework/AVKit | grep AVObservationController | grep OBJC_CLASS
> 0000000000144bd0 S _OBJC_CLASS_$_AVObservationController
> 
> So maybe you can conditionally include the header here, and then just declare the classes/methods for Mojave in the USE(APPLE_INTERNAL_SDK) section?
> 
> +@class AVKeyValueChange;
> +
> +@interface AVObservationController<Owner> : NSObject
> +- (instancetype)initWithOwner:(Owner)owner NS_DESIGNATED_INITIALIZER;
> +- (id)startObserving:(id)object keyPath:(NSString *)keyPath includeInitialValue:(BOOL)shouldIncludeInitialValue observationHandler:(void (^)(Owner owner, id observed, AVKeyValueChange *change))observationHandler;
> +- (void)stopAllObservation;
> +@end

Sorry for the trouble and thanks for the investigation! I updated the patch to only use AVObservationController in iOS for now.
Comment 20 EWS 2020-03-18 22:23:19 PDT
Committed r258682: <https://trac.webkit.org/changeset/258682>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 393928 [details].
Comment 21 Darin Adler 2020-04-05 11:08:29 PDT
Comment on attachment 393928 [details]
patch to fix build failures

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

> Source/WebCore/PAL/pal/spi/cocoa/AVKitSPI.h:57
> +#if HAVE(HAVE_AVOBSERVATIONCONTROLLER)

This change turns off the code entirely, because it says HAVE(HAVE_xxx).

To turn the code back on, we need to change it all to HAVE(AVOBSERVATIONCONTROLLER).

This also shows we have no tests covering this, because they would all fail!
Comment 22 Peng Liu 2020-04-05 13:33:53 PDT
Comment on attachment 393928 [details]
patch to fix build failures

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

>> Source/WebCore/PAL/pal/spi/cocoa/AVKitSPI.h:57
>> +#if HAVE(HAVE_AVOBSERVATIONCONTROLLER)
> 
> This change turns off the code entirely, because it says HAVE(HAVE_xxx).
> 
> To turn the code back on, we need to change it all to HAVE(AVOBSERVATIONCONTROLLER).
> 
> This also shows we have no tests covering this, because they would all fail!

Sorry for the stupid mistake. :-(
Will upload a patch to fix it.

The patch is to provide extra protection suggested by AVKit after they fixed the bug in AVPlayerViewController. With the current behavior of AVKit, WebKit works fine without this patch.
Comment 23 Peng Liu 2020-04-05 14:41:17 PDT
Reopen this bug to fix mistakes on the macro name.
Comment 24 Peng Liu 2020-04-05 14:47:24 PDT
Created attachment 395529 [details]
A follow-up patch to fix mistakes on #if HAVE(HAVE_AVOBSERVATIONCONTROLLER)
Comment 25 Darin Adler 2020-04-05 15:00:24 PDT
Comment on attachment 395529 [details]
A follow-up patch to fix mistakes on #if HAVE(HAVE_AVOBSERVATIONCONTROLLER)

Any way to add a test for this? I caught it by code inspection, but that’s not a reliable way to check these things.
Comment 26 Darin Adler 2020-04-05 15:01:01 PDT
(In reply to Darin Adler from comment #25)
> Any way to add a test for this? I caught it by code inspection, but that’s
> not a reliable way to check these things.

Oh, I see your comment now. No simple way to test for now.
Comment 27 Peng Liu 2020-04-05 17:53:01 PDT
Created attachment 395539 [details]
Fix iOS build failures by adding NS_ASSUME_NONNULL_BEGIN/NS_ASSUME_NONNULL_END
Comment 28 EWS 2020-04-05 21:02:49 PDT
Committed r259561: <https://trac.webkit.org/changeset/259561>

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