Skip to content

Commit

Permalink
Merge branch 'release/3.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
defagos committed Dec 12, 2017
2 parents 0a5b293 + 92d2f62 commit 11f8c0c
Show file tree
Hide file tree
Showing 8 changed files with 417 additions and 28 deletions.
4 changes: 2 additions & 2 deletions Cartfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
github "SRGSSR/SRGMediaPlayer-iOS" "2.1"
github "SRGSSR/srgdataprovider-ios" "5.5.1"
github "SRGSSR/SRGMediaPlayer-iOS" "2.2"
github "SRGSSR/srgdataprovider-ios" "5.5.2"
github "SRGSSR/tagcommander-ios" "4.1.3_4.1.1"
github "comScore/ComScore-iOS-SDK" "92f34897cd7659d56bb5a3e9e85b808cf3758bda"
4 changes: 2 additions & 2 deletions Cartfile.resolved
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
github "Mantle/Mantle" "2.1.0"
github "SRGSSR/MAKVONotificationCenter" "d5af67218b3b7b49660a43edef5e6eb9c437d670"
github "SRGSSR/SRGMediaPlayer-iOS" "2.1"
github "SRGSSR/SRGMediaPlayer-iOS" "2.2"
github "SRGSSR/libextobjc" "46f179fbba8dde2a3eb3da284919789b78aac441"
github "SRGSSR/srgdataprovider-ios" "5.5.1"
github "SRGSSR/srgdataprovider-ios" "5.5.2"
github "SRGSSR/srglogger-ios" "1.0"
github "SRGSSR/tagcommander-ios" "4.1.3_4.1.1"
github "comScore/ComScore-iOS-SDK" "92f34897cd7659d56bb5a3e9e85b808cf3758bda"
Expand Down
2 changes: 1 addition & 1 deletion Documentation/Getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ Our services directly supply the custom analytics labels which need to be sent w
This framework adds a category `SRGMediaPlayerController (SRGAnalytics_DataProvider)`, which adds playback methods for media compositions to `SRGMediaPlayerController`. To play a media composition retrieved from an `SRGDataProvider` and have all measurement information automatically associated with the playback, simply call:

```objective-c
SRGRequest *request = [mediaPlayerController playMediaComposition:mediaComposition withPreferredStreamingMethod:SRGStreamingMethodHLS quality:SRGQualityHD startBitRate:0 userInfo:nil resume:YES completionHandler:^(NSError * _Nonnull error) {
SRGRequest *request = [mediaPlayerController playMediaComposition:mediaComposition withPreferredStreamingMethod:SRGStreamingMethodHLS streamtype:SRGStreamTypeNone quality:SRGQualityHD startBitRate:0 userInfo:nil resume:YES completionHandler:^(NSError * _Nonnull error) {
// Deal with errors, or play the URL with a media player
}];
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ NS_ASSUME_NONNULL_BEGIN
* @param mediaComposition The media composition to prepare.
* @param streamingMethod The streaming method to use. If `SRGStreamingMethodNone` or if the method is not
* found, a recommended method will be used instead.
* @param streamType The stream type to use. If `SRGStreamTypeNone` or not found, the optimal available stream
* type is used.
* @param quality The quality to use. If `SRGQualityNone` or not found, the best available quality
* is used.
* @param startBitRate The bit rate the media should start playing with, in kbps. This parameter is a
Expand All @@ -42,9 +44,12 @@ NS_ASSUME_NONNULL_BEGIN
*
* @return The playback request. If successful, the player will be paused on the chapter / segment specified by
* the media composition. The method might return `nil` if no protocol / quality combination is found.
* Resource lookup is performed so that a matching streaming method is found first, then a matching
* stream type, and finally a quality.
*/
- (nullable SRGRequest *)prepareToPlayMediaComposition:(SRGMediaComposition *)mediaComposition
withPreferredStreamingMethod:(SRGStreamingMethod)streamingMethod
streamType:(SRGStreamType)streamType
quality:(SRGQuality)quality
startBitRate:(NSInteger)startBitRate
userInfo:(nullable NSDictionary *)userInfo
Expand All @@ -61,6 +66,7 @@ NS_ASSUME_NONNULL_BEGIN
*/
- (nullable SRGRequest *)playMediaComposition:(SRGMediaComposition *)mediaComposition
withPreferredStreamingMethod:(SRGStreamingMethod)streamingMethod
streamType:(SRGStreamType)streamType
quality:(SRGQuality)quality
startBitRate:(NSInteger)startBitRate
userInfo:(nullable NSDictionary *)userInfo
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ + (SRGAnalyticsStreamLabels *)analyticsLabelsForMediaComposition:(SRGMediaCompos

- (SRGRequest *)loadMediaComposition:(SRGMediaComposition *)mediaComposition
withPreferredStreamingMethod:(SRGStreamingMethod)streamingMethod
streamType:(SRGStreamType)streamType
quality:(SRGQuality)quality
startBitRate:(NSInteger)startBitRate
resume:(BOOL)resume
Expand All @@ -71,13 +72,20 @@ - (SRGRequest *)loadMediaComposition:(SRGMediaComposition *)mediaComposition
streamingMethod = chapter.recommendedStreamingMethod;
}

// Find the best resource subset matching the streaming method and quality. Prefer DVR streams to live streams.
NSArray<SRGResource *> *resources = [chapter resourcesForStreamingMethod:streamingMethod];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"%K == %@", @keypath(SRGResource.new, quality), @(quality)];
NSSortDescriptor *sortDescriptor = [NSSortDescriptor sortDescriptorWithKey:@keypath(SRGResource.new, streamType) ascending:YES comparator:^(NSNumber * _Nonnull streamType1, NSNumber * _Nonnull streamType2) {
// Don't simply compare enum values as integers, since their order might change.
NSArray<NSNumber *> *orderedStreamTypes = @[ @(SRGStreamTypeDVR), @(SRGStreamTypeLive), @(SRGStreamTypeOnDemand) ];

if (resources.count == 0) {
resources = [chapter resourcesForStreamingMethod:chapter.recommendedStreamingMethod];
}

// Determine the stream type order to use (start with a default setup, overridden if a preferred type has been set),
// from the lowest to the highest priority.
NSArray<NSNumber *> *orderedStreamTypes = @[@(SRGStreamTypeOnDemand), @(SRGStreamTypeLive), @(SRGStreamTypeDVR)];
if (streamType != SRGStreamTypeNone) {
orderedStreamTypes = [[orderedStreamTypes mtl_arrayByRemovingObject:@(streamType)] arrayByAddingObject:@(streamType)];
}

NSSortDescriptor *sortDescriptor = [NSSortDescriptor sortDescriptorWithKey:@keypath(SRGResource.new, streamType) ascending:NO comparator:^(NSNumber * _Nonnull streamType1, NSNumber * _Nonnull streamType2) {
// Don't simply compare enum values as integers since their order might change.
NSUInteger index1 = [orderedStreamTypes indexOfObject:streamType1];
NSUInteger index2 = [orderedStreamTypes indexOfObject:streamType2];
if (index1 == index2) {
Expand All @@ -90,12 +98,27 @@ - (SRGRequest *)loadMediaComposition:(SRGMediaComposition *)mediaComposition
return NSOrderedDescending;
}
}];
SRGResource *resource = [[resources filteredArrayUsingPredicate:predicate] sortedArrayUsingDescriptors:@[sortDescriptor]].firstObject ?: [resources sortedArrayUsingDescriptors:@[sortDescriptor]].firstObject;
resources = [resources sortedArrayUsingDescriptors:@[sortDescriptor]];

// Resources are initially ordered by quality (see `-resourcesForStreamingMethod:` documentation), and this order
// is kept stable by the stream type sort descriptor above. We therefore attempt to find a proper match for the specified
// quality, otherwise we just use the first resource available.
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"%K == %@", @keypath(SRGResource.new, quality), @(quality)];
SRGResource *resource = [resources filteredArrayUsingPredicate:predicate].firstObject ?: resources.firstObject;
if (! resource) {
SRGAnalyticsMediaPlayerLogError(@"mediaplayer", @"No valid resource could be retrieved");
return nil;
}

if (resource.presentation == SRGPresentation360) {
if (self.view.viewMode != SRGMediaPlayerViewModeMonoscopic && self.view.viewMode != SRGMediaPlayerViewModeStereoscopic) {
self.view.viewMode = SRGMediaPlayerViewModeMonoscopic;
}
}
else {
self.view.viewMode = SRGMediaPlayerViewModeFlat;
}

// Use the preferrred start bit rate is set. Currrently only supported by Akamai via a __b__ parameter (the actual
// bitrate will be rounded to the nearest available quality)
NSURL *URL = resource.URL;
Expand Down Expand Up @@ -129,13 +152,14 @@ - (SRGRequest *)loadMediaComposition:(SRGMediaComposition *)mediaComposition

- (SRGRequest *)prepareToPlayMediaComposition:(SRGMediaComposition *)mediaComposition
withPreferredStreamingMethod:(SRGStreamingMethod)streamingMethod
streamType:(SRGStreamType)streamType
quality:(SRGQuality)quality
startBitRate:(NSInteger)startBitRate
userInfo:(NSDictionary *)userInfo
resume:(BOOL)resume
completionHandler:(void (^)(NSError * _Nullable))completionHandler
{
return [self loadMediaComposition:mediaComposition withPreferredStreamingMethod:streamingMethod quality:quality startBitRate:startBitRate resume:resume completionBlock:^(NSURL * _Nullable URL, SRGResource *resource, NSInteger index, NSArray<id<SRGSegment>> *segments, SRGAnalyticsStreamLabels * _Nullable analyticsLabels, NSError * _Nullable error) {
return [self loadMediaComposition:mediaComposition withPreferredStreamingMethod:streamingMethod streamType:streamType quality:quality startBitRate:startBitRate resume:resume completionBlock:^(NSURL * _Nullable URL, SRGResource *resource, NSInteger index, NSArray<id<SRGSegment>> *segments, SRGAnalyticsStreamLabels * _Nullable analyticsLabels, NSError * _Nullable error) {
if (error) {
completionHandler ? completionHandler(error) : nil;
return;
Expand All @@ -157,6 +181,7 @@ - (SRGRequest *)prepareToPlayMediaComposition:(SRGMediaComposition *)mediaCompos

- (SRGRequest *)playMediaComposition:(SRGMediaComposition *)mediaComposition
withPreferredStreamingMethod:(SRGStreamingMethod)streamingMethod
streamType:(SRGStreamType)streamType
quality:(SRGQuality)quality
startBitRate:(NSInteger)startBitRate
userInfo:(NSDictionary *)userInfo
Expand All @@ -172,6 +197,7 @@ - (SRGRequest *)playMediaComposition:(SRGMediaComposition *)mediaComposition

return [self prepareToPlayMediaComposition:mediaComposition
withPreferredStreamingMethod:streamingMethod
streamType:streamType
quality:quality
startBitRate:startBitRate
userInfo:userInfo
Expand Down
4 changes: 2 additions & 2 deletions SRGAnalytics.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1205,7 +1205,7 @@
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
MARKETING_VERSION = 3.1.2;
MARKETING_VERSION = 3.2;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
};
Expand Down Expand Up @@ -1252,7 +1252,7 @@
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
MARKETING_VERSION = 3.1.2;
MARKETING_VERSION = 3.2;
SDKROOT = iphoneos;
VALIDATE_PRODUCT = YES;
};
Expand Down
6 changes: 3 additions & 3 deletions Tests/Sources/ComScoreDataProviderTestCase.m
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ - (void)testPrepareToPlayMediaComposition
[[dataProvider videoMediaCompositionWithUid:@"42297626" chaptersOnly:NO completionBlock:^(SRGMediaComposition * _Nullable mediaComposition, NSError * _Nullable error) {
XCTAssertNotNil(mediaComposition);

[self.mediaPlayerController prepareToPlayMediaComposition:mediaComposition withPreferredStreamingMethod:SRGStreamingMethodNone quality:SRGQualityHD startBitRate:0 userInfo:nil resume:YES completionHandler:^(NSError * _Nonnull error) {
[self.mediaPlayerController prepareToPlayMediaComposition:mediaComposition withPreferredStreamingMethod:SRGStreamingMethodNone streamType:SRGStreamTypeNone quality:SRGQualityHD startBitRate:0 userInfo:nil resume:YES completionHandler:^(NSError * _Nonnull error) {
XCTAssertNil(error);
XCTAssertEqual(self.mediaPlayerController.mediaComposition, mediaComposition);
[expectation fulfill];
Expand Down Expand Up @@ -77,7 +77,7 @@ - (void)testPlayMediaComposition
[[dataProvider videoMediaCompositionWithUid:@"42297626" chaptersOnly:NO completionBlock:^(SRGMediaComposition * _Nullable mediaComposition, NSError * _Nullable error) {
XCTAssertNotNil(mediaComposition);

[self.mediaPlayerController playMediaComposition:mediaComposition withPreferredStreamingMethod:SRGStreamingMethodNone quality:SRGQualityHD startBitRate:0 userInfo:nil resume:YES completionHandler:^(NSError * _Nonnull error) {
[self.mediaPlayerController playMediaComposition:mediaComposition withPreferredStreamingMethod:SRGStreamingMethodNone streamType:SRGStreamTypeNone quality:SRGQualityHD startBitRate:0 userInfo:nil resume:YES completionHandler:^(NSError * _Nonnull error) {
XCTAssertNil(error);
XCTAssertEqual(self.mediaPlayerController.mediaComposition, mediaComposition);
[expectation fulfill];
Expand All @@ -103,7 +103,7 @@ - (void)testPlaySegmentInMediaComposition
[[dataProvider videoMediaCompositionWithUid:@"27af89ad-2408-40e5-8318-96e25d3e003b" chaptersOnly:NO completionBlock:^(SRGMediaComposition * _Nullable mediaComposition, NSError * _Nullable error) {
XCTAssertNotNil(mediaComposition);

[self.mediaPlayerController playMediaComposition:mediaComposition withPreferredStreamingMethod:SRGStreamingMethodNone quality:SRGQualityHD startBitRate:0 userInfo:nil resume:YES completionHandler:^(NSError * _Nonnull error) {
[self.mediaPlayerController playMediaComposition:mediaComposition withPreferredStreamingMethod:SRGStreamingMethodNone streamType:SRGStreamTypeNone quality:SRGQualityHD startBitRate:0 userInfo:nil resume:YES completionHandler:^(NSError * _Nonnull error) {
XCTAssertNil(error);
XCTAssertEqual(self.mediaPlayerController.mediaComposition, mediaComposition);
}];
Expand Down
Loading

0 comments on commit 11f8c0c

Please sign in to comment.