Skip to content

Commit

Permalink
Improve locking situation in ASVideoPlayerNode (#1042)
Browse files Browse the repository at this point in the history
* Improve locking in ASVideoPlayerNode

* Address comments
  • Loading branch information
maicki committed Jul 20, 2018
1 parent 5fef6a1 commit d9d5b12
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 27 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
- Split MapKit, Photos, and AssetsLibrary dependent code into separate subspecs to improve binary size and start time when they're not needed. The default subspec includes all three for backwards compatibility, but this **will change in 3.0**. When using non-Cocoapods build environments, define `AS_USE_PHOTOS, AS_USE_MAPKIT, AS_USE_ASSETS_LIBRARY` to 1 respectively to signal their use. [Adlai Holler](https://github.com/Adlai-Holler)
- Optimization: Removed an NSMutableArray in flattened layouts. [Adlai Holler](https://github.com/Adlai-Holler)
- Reduced binary size by disabling exception support (which we don't use.) [Adlai Holler](https://github.com/Adlai-Holler)
- Create and set delegate for clip corner layers within ASDisplayNode [Michael Schneider](https://github.com/maicki) [#1024](https://github.com/TextureGroup/Texture/pull/1029)
- Create and set delegate for clip corner layers within ASDisplayNode [Michael Schneider](https://github.com/maicki) [#1029](https://github.com/TextureGroup/Texture/pull/1029)
- Improve locking situation in ASVideoPlayerNode [Michael Schneider](https://github.com/maicki) [#1042](https://github.com/TextureGroup/Texture/pull/1042)


## 2.7
- Fix pager node for interface coalescing. [Max Wang](https://github.com/wsdwsd0829) [#877](https://github.com/TextureGroup/Texture/pull/877)
Expand Down
86 changes: 60 additions & 26 deletions Source/ASVideoPlayerNode.mm
Original file line number Diff line number Diff line change
Expand Up @@ -209,10 +209,8 @@ - (AVAsset *)asset
- (void)didLoad
{
[super didLoad];
{
ASLockScopeSelf();
[self createControls];
}

[self createControls];
}

- (void)didEnterPreloadState
Expand Down Expand Up @@ -284,15 +282,23 @@ - (void)createControls

if (_delegateFlags.delegateCustomControls && _delegateFlags.delegateLayoutSpecForControls) {
NSDictionary *customControls = [_delegate videoPlayerNodeCustomControls:self];
std::vector<ASDisplayNode *> subnodes;
for (id key in customControls) {
id node = customControls[key];
if (![node isKindOfClass:[ASDisplayNode class]]) {
continue;
}

[self addSubnode:node];
subnodes.push_back(node);
[_cachedControls setObject:node forKey:key];
}

{
ASUnlockScope(self);
for (var subnode : subnodes) {
[self addSubnode:subnode];
}
}
}
}

Expand All @@ -315,14 +321,21 @@ - (NSArray *)createDefaultControlElementArray

- (void)removeControls
{
for (ASDisplayNode *node in [_cachedControls objectEnumerator]) {
[node removeFromSupernode];
NSMutableDictionary *cachedControls = nil;
{
ASLockScope(self);

// Grab the cached controls for removing it
cachedControls = [_cachedControls copy];
[self _locked_cleanCachedControls];
}

[self cleanCachedControls];
for (ASDisplayNode *node in [cachedControls objectEnumerator]) {
[node removeFromSupernode];
}
}

- (void)cleanCachedControls
- (void)_locked_cleanCachedControls
{
[_cachedControls removeAllObjects];

Expand Down Expand Up @@ -355,7 +368,10 @@ - (void)_locked_createPlaybackButton
[_cachedControls setObject:_playbackButtonNode forKey:@(ASVideoPlayerNodeControlTypePlaybackButton)];
}

[self addSubnode:_playbackButtonNode];
{
ASUnlockScope(self);
[self addSubnode:_playbackButtonNode];
}
}

- (void)_locked_createFullScreenButton
Expand All @@ -374,7 +390,10 @@ - (void)_locked_createFullScreenButton
[_cachedControls setObject:_fullScreenButtonNode forKey:@(ASVideoPlayerNodeControlTypeFullScreenButton)];
}

[self addSubnode:_fullScreenButtonNode];
{
ASUnlockScope(self);
[self addSubnode:_fullScreenButtonNode];
}
}

- (void)_locked_createElapsedTextField
Expand All @@ -389,7 +408,10 @@ - (void)_locked_createElapsedTextField

[_cachedControls setObject:_elapsedTextNode forKey:@(ASVideoPlayerNodeControlTypeElapsedText)];
}
[self addSubnode:_elapsedTextNode];
{
ASUnlockScope(self);
[self addSubnode:_elapsedTextNode];
}
}

- (void)_locked_createDurationTextField
Expand All @@ -405,7 +427,10 @@ - (void)_locked_createDurationTextField
[_cachedControls setObject:_durationTextNode forKey:@(ASVideoPlayerNodeControlTypeDurationText)];
}
[self updateDurationTimeLabel];
[self addSubnode:_durationTextNode];
{
ASUnlockScope(self);
[self addSubnode:_durationTextNode];
}
}

- (void)_locked_createScrubber
Expand Down Expand Up @@ -450,8 +475,10 @@ - (void)_locked_createScrubber

[_cachedControls setObject:_scrubberNode forKey:@(ASVideoPlayerNodeControlTypeScrubber)];
}

[self addSubnode:_scrubberNode];
{
ASUnlockScope(self);
[self addSubnode:_scrubberNode];
}
}

- (void)_locked_createControlFlexGrowSpacer
Expand Down Expand Up @@ -623,7 +650,6 @@ - (void)showSpinner
ASLockScopeSelf();

if (!_spinnerNode) {

__weak __typeof__(self) weakSelf = self;
_spinnerNode = [[ASDisplayNode alloc] initWithViewBlock:^UIView *{
__typeof__(self) strongSelf = weakSelf;
Expand All @@ -642,24 +668,32 @@ - (void)showSpinner

return spinnnerView;
}];

_spinnerNode.style.preferredSize = CGSizeMake(44.0, 44.0);

[self addSubnode:_spinnerNode];
[self setNeedsLayout];

let spinnerNode = _spinnerNode;
{
ASUnlockScope(self);
[self addSubnode:spinnerNode];
[self setNeedsLayout];
}
}
[(UIActivityIndicatorView *)_spinnerNode.view startAnimating];
}

- (void)removeSpinner
{
ASLockScopeSelf();

if (!_spinnerNode) {
return;
ASDisplayNode *spinnerNode = nil;
{
ASLockScopeSelf();
if (!_spinnerNode) {
return;
}

spinnerNode = _spinnerNode;
_spinnerNode = nil;
}
[_spinnerNode removeFromSupernode];
_spinnerNode = nil;

[spinnerNode removeFromSupernode];
}

- (void)didTapPlaybackButton:(ASControlNode*)node
Expand Down

0 comments on commit d9d5b12

Please sign in to comment.