Skip to content
This repository has been archived by the owner on Feb 2, 2023. It is now read-only.

[ASVideoPlayerNode] Fixes and improvements #3135

Merged
merged 3 commits into from
Mar 5, 2017
Merged

[ASVideoPlayerNode] Fixes and improvements #3135

merged 3 commits into from
Mar 5, 2017

Conversation

maicki
Copy link
Contributor

@maicki maicki commented Mar 4, 2017

This PR is building on top of the fabulous work of @nguyenhuy in #3093.

Some problems in ASVideoPlayerNode currently:

  • We have two sources of truth. One is the asset within the ASVideoPlayerNode and the other one is within the backing ASVideoNode. Ideally we only want to have only one final source of truth, therefore this PR will try to use the ASVideoNode as final truth of source.
  • _loadAssetWhenNodeBecomesVisible isn't turned on in the empty initializer. This causes an assertion in [ASVideoPlayerNode] Crash initialising videoplayer node  #3042 because it's not safe to set an asset on ASVideoNode off main.
  • The flag itself is troublesome. It's enabled by default, but even so, "visible" is a bit too late. The asset can be loaded as soon as the player enters preload state, which is what ASVideoNode is doing.
    This PR deprecates _loadAssetWhenNodeBecomesVisible and fixes [ASVideoPlayerNode] Crash initialising videoplayer node  #3042 by letting ASVideoPlayerNode handles its objects automatically.
  • The API does not align with UIKit components. Therefore a couple of initializer related to initialization with an URL are deprecated and replaced.

@MarvinNazari Would be great if you can comment and help me to test this PR. Thank you!

Copy link
Contributor

@nguyenhuy nguyenhuy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for pushing this, @maicki. A few cautious changes and we're good to go!


// Set asset based on interface state
if ((ASInterfaceStateIncludesPreload(self.interfaceState))) {
_videoNode.asset = asset;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 white space missing :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, it maybe a good idea to avoid holding the instance lock while calling the video node. Doing so might potentially cause deadlocks if videoNode (or a subclass) for some reasons walks up the node hierarchy.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lastly, please consider adding thread assertions since these setters are probably main-thread only?

if ([_pendingAsset isKindOfClass:AVURLAsset.class]) {
return ((AVURLAsset *)_pendingAsset).URL;
} else {
return _videoNode.assetURL;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, avoid holding instance lock while calling a subnode. Although in case of getters, the risk is very small.

return [_delegate videoPlayerNodeNeededDefaultControls:self];
// If we enter preload state we apply the pending asset to load to the video node so it can start and fetch the asset
if (_pendingAsset != nil && _videoNode.asset != _pendingAsset) {
_videoNode.asset = _pendingAsset;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, don't hold instance lock.

@maicki
Copy link
Contributor Author

maicki commented Mar 5, 2017

@nguyenhuy Comments addressed. Can you take another look over it. Thanks!

Copy link
Contributor

@nguyenhuy nguyenhuy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left one last comment. Feel free to merge after adressing it. Thanks!

{
if (!(self = [super init])) {
return nil;
__instanceLock__.lock();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably don't need this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for catching that ...

@nguyenhuy nguyenhuy merged commit 2df3922 into facebookarchive:master Mar 5, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[ASVideoPlayerNode] Crash initialising videoplayer node
3 participants