Skip to content

Commit

Permalink
Merge branch 'release/2.5.4'
Browse files Browse the repository at this point in the history
  • Loading branch information
defagos committed Dec 4, 2018
2 parents 4844a4c + 72f2127 commit e0608cb
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 27 deletions.
44 changes: 24 additions & 20 deletions Framework/Sources/Controllers/SRGMediaPlayerController.m
Original file line number Diff line number Diff line change
Expand Up @@ -172,30 +172,34 @@ - (void)setPlayer:(AVPlayer *)player
}
};

// If a segment is targeted, add a small offset so that playback is guaranteed to start within the segment
SRGPosition *startPosition = self.startPosition;
if (self.targetSegment) {
startPosition = SRGMediaPlayerControllerOffset(startPosition, CMTimeMakeWithSeconds(SRGSegmentSeekOffsetInSeconds, NSEC_PER_SEC));
}

// Take into account tolerance at the end of the content being played. If near the end enough, start
// at the default position instead.
CMTimeRange timeRange = self.targetSegment ? self.targetSegment.srg_timeRange : self.timeRange;
CMTime tolerance = SRGMediaPlayerEffectiveEndTolerance(self.endTolerance, self.endToleranceRatio, CMTimeGetSeconds(timeRange.duration));
CMTime toleratedStartTime = CMTIME_COMPARE_INLINE(startPosition.time, >=, CMTimeSubtract(timeRange.duration, tolerance)) ? kCMTimeZero : startPosition.time;

// Positions in segments are relative. If not within a segment, they are absolute (relative positions
// are misleading for a DVR stream with a sliding window, and match the absolute position in other cases)
if (self.targetSegment) {
toleratedStartTime = CMTimeAdd(toleratedStartTime, timeRange.start);
}
SRGPosition *toleratedPosition = [SRGPosition positionWithTime:toleratedStartTime toleranceBefore:startPosition.toleranceBefore toleranceAfter:startPosition.toleranceAfter];

SRGPosition *seekPosition = SRGMediaPlayerControllerPositionInTimeRange(toleratedPosition, timeRange);
if (CMTIME_COMPARE_INLINE(seekPosition.time, ==, kCMTimeZero)) {
// Default position. Nothing to do.
if (CMTIME_COMPARE_INLINE(self.startPosition.time, ==, kCMTimeZero) && ! self.targetSegment) {
completionBlock(YES);
}
// Non-default start position. Calculate a valid position to seek to.
else {
// If a segment is targeted, add a small offset so that playback is guaranteed to start within the segment
if (self.targetSegment) {
startPosition = SRGMediaPlayerControllerOffset(startPosition, CMTimeMakeWithSeconds(SRGSegmentSeekOffsetInSeconds, NSEC_PER_SEC));
}

// Take into account tolerance at the end of the content being played. If near the end enough, start
// at the default position instead.
CMTimeRange timeRange = self.targetSegment ? self.targetSegment.srg_timeRange : self.timeRange;
CMTime tolerance = SRGMediaPlayerEffectiveEndTolerance(self.endTolerance, self.endToleranceRatio, CMTimeGetSeconds(timeRange.duration));
CMTime toleratedStartTime = CMTIME_COMPARE_INLINE(startPosition.time, >=, CMTimeSubtract(timeRange.duration, tolerance)) ? kCMTimeZero : startPosition.time;

// Positions in segments are relative. If not within a segment, they are absolute (relative positions
// are misleading for a DVR stream with a sliding window, and match the absolute position in other cases)
if (self.targetSegment) {
toleratedStartTime = CMTimeAdd(toleratedStartTime, timeRange.start);
}
SRGPosition *toleratedPosition = [SRGPosition positionWithTime:toleratedStartTime toleranceBefore:startPosition.toleranceBefore toleranceAfter:startPosition.toleranceAfter];

SRGPosition *seekPosition = SRGMediaPlayerControllerPositionInTimeRange(toleratedPosition, timeRange);

// Call system method to avoid unwanted seek state in this special case
[player seekToTime:seekPosition.time toleranceBefore:seekPosition.toleranceBefore toleranceAfter:seekPosition.toleranceAfter completionHandler:^(BOOL finished) {
completionBlock(finished);
Expand Down Expand Up @@ -1161,7 +1165,7 @@ - (id)addPeriodicTimeObserverForInterval:(CMTime)interval queue:(dispatch_queue_
return nil;
}

NSString *identifier = [[NSUUID UUID] UUIDString];
NSString *identifier = NSUUID.UUID.UUIDString;
SRGPeriodicTimeObserver *periodicTimeObserver = [self periodicTimeObserverForInterval:interval queue:queue];
[periodicTimeObserver setBlock:block forIdentifier:identifier];

Expand Down
20 changes: 17 additions & 3 deletions Framework/Sources/Controllers/SRGMediaPlayerViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,14 @@ - (BOOL)canSkipBackwardFromTime:(CMTime)time
return NO;
}

SRGMediaPlayerStreamType streamType = self.controller.streamType;
SRGMediaPlayerController *controller = self.controller;
SRGMediaPlayerPlaybackState playbackState = controller.playbackState;

if (playbackState == SRGMediaPlayerPlaybackStateIdle || playbackState == SRGMediaPlayerPlaybackStatePreparing) {
return NO;
}

SRGMediaPlayerStreamType streamType = controller.streamType;
return (streamType == SRGMediaPlayerStreamTypeOnDemand || streamType == SRGMediaPlayerStreamTypeDVR);
}

Expand All @@ -372,8 +379,15 @@ - (BOOL)canSkipForwardFromTime:(CMTime)time
}

SRGMediaPlayerController *controller = self.controller;
return (controller.streamType == SRGMediaPlayerStreamTypeOnDemand && CMTimeGetSeconds(time) + SRGMediaPlayerViewControllerForwardSkipInterval < CMTimeGetSeconds(controller.player.currentItem.duration))
|| (controller.streamType == SRGMediaPlayerStreamTypeDVR && ! controller.live);
SRGMediaPlayerPlaybackState playbackState = controller.playbackState;

if (playbackState == SRGMediaPlayerPlaybackStateIdle || playbackState == SRGMediaPlayerPlaybackStatePreparing) {
return NO;
}

SRGMediaPlayerStreamType streamType = controller.streamType;
return (streamType == SRGMediaPlayerStreamTypeOnDemand && CMTimeGetSeconds(time) + SRGMediaPlayerViewControllerForwardSkipInterval < CMTimeGetSeconds(controller.player.currentItem.duration))
|| (streamType == SRGMediaPlayerStreamTypeDVR && ! controller.live);
}

- (void)skipBackwardFromTime:(CMTime)time withCompletionHandler:(void (^)(BOOL finished))completionHandler
Expand Down
30 changes: 26 additions & 4 deletions SRGMediaPlayer.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -929,6 +929,7 @@
E69A1E641D61BEFC0064E6C1 /* Frameworks */,
E69A1E651D61BEFC0064E6C1 /* Resources */,
E69A1FC31D61C0180064E6C1 /* Embed Frameworks */,
0805608821A75209000FA74E /* Copy Frameworks (Carthage) */,
);
buildRules = (
);
Expand Down Expand Up @@ -1077,6 +1078,27 @@
/* End PBXResourcesBuildPhase section */

/* Begin PBXShellScriptBuildPhase section */
0805608821A75209000FA74E /* Copy Frameworks (Carthage) */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputFileListPaths = (
);
inputPaths = (
"$(SRCROOT)/Carthage/Build/iOS/libextobjc.framework",
"$(SRCROOT)/Carthage/Build/iOS/MAKVONotificationCenter.framework",
"$(SRCROOT)/Carthage/Build/iOS/SRGLogger.framework",
);
name = "Copy Frameworks (Carthage)";
outputFileListPaths = (
);
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "/usr/local/bin/carthage copy-frameworks\n";
};
6F44486B210F24CD009FDB70 /* Copy Framework Dependencies for Xcode View Rendering */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
Expand Down Expand Up @@ -1289,7 +1311,7 @@
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
MARKETING_VERSION = 2.5.3;
MARKETING_VERSION = 2.5.4;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
TARGETED_DEVICE_FAMILY = "1,2";
Expand Down Expand Up @@ -1426,7 +1448,7 @@
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
MARKETING_VERSION = 2.5.3;
MARKETING_VERSION = 2.5.4;
SDKROOT = iphoneos;
TARGETED_DEVICE_FAMILY = "1,2";
VALIDATE_PRODUCT = YES;
Expand Down Expand Up @@ -1652,7 +1674,7 @@
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
MARKETING_VERSION = 2.5.3;
MARKETING_VERSION = 2.5.4;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
TARGETED_DEVICE_FAMILY = "1,2";
Expand Down Expand Up @@ -1703,7 +1725,7 @@
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
MARKETING_VERSION = 2.5.3;
MARKETING_VERSION = 2.5.4;
SDKROOT = iphoneos;
TARGETED_DEVICE_FAMILY = "1,2";
VALIDATE_PRODUCT = YES;
Expand Down

0 comments on commit e0608cb

Please sign in to comment.