Skip to content

Commit

Permalink
Merge pull request #514 from smartdevicelink/feature/streaming_media_…
Browse files Browse the repository at this point in the history
…manager

Streaming Media Manager Updates
  • Loading branch information
joeljfischer authored Aug 17, 2017
2 parents ed1e03b + 65c1966 commit c860335
Show file tree
Hide file tree
Showing 48 changed files with 2,874 additions and 1,170 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 5.0.0 Release Notes (in-progress)
### Breaking Changes
* `SDLProxy streamingMediaManager` is now removed. If you wish to use a streaming media manager, you must use the `streamingMediaManager` on `SDLManager`.

# 4.6.1 Release Notes
### Bug Fixes
* Fixes a bug where an app would crash if connected while the app is foregrounded and the vehicle is already in motion.
Expand Down
415 changes: 208 additions & 207 deletions SmartDeviceLink-iOS.podspec

Large diffs are not rendered by default.

138 changes: 129 additions & 9 deletions SmartDeviceLink-iOS.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

415 changes: 208 additions & 207 deletions SmartDeviceLink.podspec

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions SmartDeviceLink/Assets/Base.lproj/SDLLockScreen.storyboard
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11762" systemVersion="16D32" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="sao-xX-Ugl">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="12121" systemVersion="16G29" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="sao-xX-Ugl">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment version="1808" identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11757"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="12089"/>
<capability name="Constraints to layout margins" minToolsVersion="6.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
Expand Down
23 changes: 23 additions & 0 deletions SmartDeviceLink/CVPixelBufferRef+SDLUtil.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//
// CVPixelBufferRef+SDLUtil.h
// SmartDeviceLink-iOS
//
// Created by Muller, Alexander (A.) on 3/16/17.
// Copyright © 2017 smartdevicelink. All rights reserved.
//

#import <UIKit/UIKit.h>
#import <CoreVideo/CVPixelBuffer.h>

NS_ASSUME_NONNULL_BEGIN

/**
Take a CVPixelBuffer frame and append some text onto it, attempting to fit it to the rect. This is used for a "blank" screen when streaming navigation is pushed to the background or otherwise disabled in progress.
@param pixelBuffer The pixel buffer to draw text over
@param text The text to draw
@return Whether or not it succeeded.
*/
Boolean CVPixelBufferAddText(CVPixelBufferRef CV_NONNULL pixelBuffer, NSString *text);

NS_ASSUME_NONNULL_END
103 changes: 103 additions & 0 deletions SmartDeviceLink/CVPixelBufferRef+SDLUtil.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
//
// CVPixelBufferRef+SDLUtil.m
// SmartDeviceLink-iOS
//
// Created by Muller, Alexander (A.) on 3/16/17.
// Copyright © 2017 smartdevicelink. All rights reserved.
//

#import "CVPixelBufferRef+SDLUtil.h"

NS_ASSUME_NONNULL_BEGIN

UIFont * _Nullable sdl_findFontSizeToFitText(CGSize size, NSString *text) {
CGFloat fontSize = 100;

do {
CGSize textSize = [text boundingRectWithSize:CGSizeMake(size.width, CGFLOAT_MAX)
options:NSStringDrawingUsesLineFragmentOrigin
attributes:@{NSFontAttributeName : [UIFont boldSystemFontOfSize:fontSize]}
context:nil].size;

if (textSize.height <= size.height) {
break;
}

fontSize -= 10.0;
} while (fontSize > 0.0);

return (fontSize > 0) ? [UIFont boldSystemFontOfSize:fontSize] : nil;
}

UIImage * _Nullable sdl_createTextImage(NSString *text, CGSize size) {
UIFont *font = sdl_findFontSizeToFitText(size, text);

if (!font) {
NSLog(@"Text cannot fit inside frame");
return nil;
}

CGRect frame = CGRectMake(0, 0, size.width, size.height);
UIGraphicsBeginImageContextWithOptions(frame.size, NO, 1.0);
CGContextRef context = UIGraphicsGetCurrentContext();

CGContextSetFillColorWithColor(context, [UIColor blackColor].CGColor);
CGContextFillRect(context, frame);
CGContextSaveGState(context);

NSMutableParagraphStyle* textStyle = NSMutableParagraphStyle.defaultParagraphStyle.mutableCopy;
textStyle.alignment = NSTextAlignmentCenter;

NSDictionary* textAttributes = @{
NSFontAttributeName: font,
NSForegroundColorAttributeName: [UIColor whiteColor],
NSParagraphStyleAttributeName: textStyle
};
CGRect textFrame = [text boundingRectWithSize:size
options:NSStringDrawingUsesLineFragmentOrigin
attributes:textAttributes
context:nil];

CGRect textInset = CGRectMake(0,
(frame.size.height - CGRectGetHeight(textFrame)) / 2.0,
frame.size.width,
frame.size.height);

[text drawInRect:textInset
withAttributes:textAttributes];

CGContextRestoreGState(context);
UIImage* image = UIGraphicsGetImageFromCurrentImageContext();

return image;
}

Boolean CVPixelBufferAddText(CVPixelBufferRef CV_NONNULL pixelBuffer, NSString *text) {
size_t width = CVPixelBufferGetWidth(pixelBuffer);
size_t height = CVPixelBufferGetHeight(pixelBuffer);

UIImage *image = sdl_createTextImage(text, CGSizeMake(width, height));
if (!image) {
NSLog(@"Could not create text image.");
return false;
}

CVPixelBufferLockBaseAddress(pixelBuffer, 0);
void *data = CVPixelBufferGetBaseAddress(pixelBuffer);

CGColorSpaceRef rgbColorSpace = CGColorSpaceCreateDeviceRGB();
CGContextRef context = CGBitmapContextCreate(data, width, height,
8, CVPixelBufferGetBytesPerRow(pixelBuffer), rgbColorSpace,
kCGBitmapByteOrder32Little |
kCGImageAlphaPremultipliedFirst);
CGContextDrawImage(context, CGRectMake(0, 0, width, height), image.CGImage);
CGColorSpaceRelease(rgbColorSpace);

CGContextRelease(context);

CVPixelBufferUnlockBaseAddress(pixelBuffer, 0);

return true;
}

NS_ASSUME_NONNULL_END
2 changes: 1 addition & 1 deletion SmartDeviceLink/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>4.6.1</string>
<string>5.0.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
Expand Down
57 changes: 42 additions & 15 deletions SmartDeviceLink/SDLConfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
@class SDLLifecycleConfiguration;
@class SDLLockScreenConfiguration;
@class SDLLogConfiguration;
@class SDLStreamingMediaConfiguration;

NS_ASSUME_NONNULL_BEGIN

Expand All @@ -26,19 +27,41 @@ NS_ASSUME_NONNULL_BEGIN
*/
@property (copy, nonatomic, readonly) SDLLockScreenConfiguration *lockScreenConfig;


/**
The log configuration.
*/
@property (copy, nonatomic, readonly) SDLLogConfiguration *loggingConfig;

/**
The configuration
*/
@property (copy, nonatomic, readonly) SDLStreamingMediaConfiguration *streamingMediaConfig;

/**
Create a new configuration to be passed into SDLManager with a custom lifecycle, lock screen, and a default logging configuration.
@param lifecycleConfiguration The lifecycle configuration to be used.
@return The configuration
*/
- (instancetype)initWithLifecycle:(SDLLifecycleConfiguration *)lifecycleConfiguration __deprecated_msg(("Use initWithLifecycle:lockScreen:logging: instead"));

/**
Create a new configuration to be passed into SDLManager with a custom lifecycle, lock screen, and a default logging configuration.
@param lifecycleConfiguration The lifecycle configuration to be used.
@return The configuration
*/
- (instancetype)initWithLifecycle:(SDLLifecycleConfiguration *)lifecycleConfiguration;
+ (instancetype)configurationWithLifecycle:(SDLLifecycleConfiguration *)lifecycleConfiguration __deprecated_msg(("Use configurationWithLifecycle:lockScreen:logging: instead"));

/**
* Create a new configuration to be passed into SDLManager with a custom lifecycle, lock screen, and a default logging configuration.
*
* @param lifecycleConfig The lifecycle configuration to be used.
* @param lockScreenConfig The lockscreen configuration to be used, or `enabledConfiguration` if nil.
*
* @return The configuration
*/
- (instancetype)initWithLifecycle:(SDLLifecycleConfiguration *)lifecycleConfig lockScreen:(nullable SDLLockScreenConfiguration *)lockScreenConfig __deprecated_msg(("Use initWithLifecycle:lockScreen:logging: instead"));

/**
* Create a new configuration to be passed into SDLManager with a custom lifecycle, lock screen, and a default logging configuration.
Expand All @@ -48,7 +71,7 @@ NS_ASSUME_NONNULL_BEGIN
*
* @return The configuration
*/
- (instancetype)initWithLifecycle:(SDLLifecycleConfiguration *)lifecycleConfig lockScreen:(nullable SDLLockScreenConfiguration *)lockScreenConfig;
+ (instancetype)configurationWithLifecycle:(SDLLifecycleConfiguration *)lifecycleConfig lockScreen:(nullable SDLLockScreenConfiguration *)lockScreenConfig __deprecated_msg(("Use configurationWithLifecycle:lockScreen:logging: instead"));

/**
Create a new configuration to be passed into SDLManager with a custom lifecycle, lock screen, and logging configuration.
Expand All @@ -61,32 +84,36 @@ NS_ASSUME_NONNULL_BEGIN
- (instancetype)initWithLifecycle:(SDLLifecycleConfiguration *)lifecycleConfig lockScreen:(nullable SDLLockScreenConfiguration *)lockScreenConfig logging:(nullable SDLLogConfiguration *)logConfig;

/**
Create a new configuration to be passed into SDLManager with a custom lifecycle, lock screen, and a default logging configuration.
Create a new configuration to be passed into SDLManager with a custom lifecycle, lock screen, and logging configuration.
@param lifecycleConfiguration The lifecycle configuration to be used.
@param lifecycleConfig The lifecycle configuration to be used.
@param lockScreenConfig The lockscreen configuration to be used, or `enabledConfiguration` if nil.
@param logConfig The logging configuration to be used, or `defaultConfiguration` if nil.
@return The configuration
*/
+ (instancetype)configurationWithLifecycle:(SDLLifecycleConfiguration *)lifecycleConfiguration;
+ (instancetype)configurationWithLifecycle:(SDLLifecycleConfiguration *)lifecycleConfig lockScreen:(nullable SDLLockScreenConfiguration *)lockScreenConfig logging:(nullable SDLLogConfiguration *)logConfig;

/**
* Create a new configuration to be passed into SDLManager with a custom lifecycle, lock screen, and a default logging configuration.
*
* @param lifecycleConfig The lifecycle configuration to be used.
* @param lockScreenConfig The lockscreen configuration to be used, or `enabledConfiguration` if nil.
*
* @return The configuration
Create a new configuration to be passed into SDLManager with a custom lifecycle, lock screen, logging, and streaming media configuration.
@param lifecycleConfig The lifecycle configuration to be used.
@param lockScreenConfig The lockscreen configuration to be used, or `enabledConfiguration` if nil.
@param logConfig The logging configuration to be used, or `defaultConfiguration` if nil.
@param streamingMediaConfig The streaming media configuration to be used, or nil because it is not needed.
@return The configuration
*/
+ (instancetype)configurationWithLifecycle:(SDLLifecycleConfiguration *)lifecycleConfig lockScreen:(nullable SDLLockScreenConfiguration *)lockScreenConfig;
- (instancetype)initWithLifecycle:(SDLLifecycleConfiguration *)lifecycleConfig lockScreen:(nullable SDLLockScreenConfiguration *)lockScreenConfig logging:(nullable SDLLogConfiguration *)logConfig streamingMedia:(nullable SDLStreamingMediaConfiguration *)streamingMediaConfig;

/**
Create a new configuration to be passed into SDLManager with a custom lifecycle, lock screen, and logging configuration.
Create a new configuration to be passed into SDLManager with a custom lifecycle, lock screen, logging, and streaming media configuration.
@param lifecycleConfig The lifecycle configuration to be used.
@param lockScreenConfig The lockscreen configuration to be used, or `enabledConfiguration` if nil.
@param logConfig The logging configuration to be used, or `defaultConfiguration` if nil.
@param streamingMediaConfig The streaming media configuration to be used, or nil because it is not needed.
@return The configuration
*/
+ (instancetype)configurationWithLifecycle:(SDLLifecycleConfiguration *)lifecycleConfig lockScreen:(nullable SDLLockScreenConfiguration *)lockScreenConfig logging:(nullable SDLLogConfiguration *)logConfig;
+ (instancetype)configurationWithLifecycle:(SDLLifecycleConfiguration *)lifecycleConfig lockScreen:(nullable SDLLockScreenConfiguration *)lockScreenConfig logging:(nullable SDLLogConfiguration *)logConfig streamingMedia:(nullable SDLStreamingMediaConfiguration *)streamingMediaConfig;

@end

Expand Down
24 changes: 24 additions & 0 deletions SmartDeviceLink/SDLConfiguration.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#import "SDLLifecycleConfiguration.h"
#import "SDLLockScreenConfiguration.h"
#import "SDLLogConfiguration.h"
#import "SDLStreamingMediaConfiguration.h"

NS_ASSUME_NONNULL_BEGIN

Expand Down Expand Up @@ -49,6 +50,29 @@ + (instancetype)configurationWithLifecycle:(SDLLifecycleConfiguration *)lifecycl
return [[self alloc] initWithLifecycle:lifecycleConfig lockScreen:lockScreenConfig logging:logConfig];
}

- (instancetype)initWithLifecycle:(SDLLifecycleConfiguration *)lifecycleConfig lockScreen:(nullable SDLLockScreenConfiguration *)lockScreenConfig logging:(nullable SDLLogConfiguration *)logConfig streamingMedia:(nullable SDLStreamingMediaConfiguration *)streamingMediaConfig {
self = [super init];
if (!self) {
return nil;
}

_lifecycleConfig = lifecycleConfig;
_lockScreenConfig = lockScreenConfig ?: [SDLLockScreenConfiguration enabledConfiguration];
_loggingConfig = logConfig ?: [SDLLogConfiguration defaultConfiguration];

if (_streamingMediaConfig != nil) {
NSAssert(!([_lifecycleConfig.appType isEqualToEnum:SDLAppHMITypeNavigation] || [_lifecycleConfig.appType isEqualToEnum:SDLAppHMITypeProjection]), @"You should only set a streaming media configuration if your app is a NAVIGATION or PROJECTION HMI type");
_streamingMediaConfig = streamingMediaConfig;
} else {
NSAssert(([_lifecycleConfig.appType isEqualToEnum:SDLAppHMITypeNavigation] || [_lifecycleConfig.appType isEqualToEnum:SDLAppHMITypeProjection]), @"If your app is a NAVIGATION or PROJECTION HMI type, you must set a streaming media configuration on SDLConfiguration");
}

return self;
}

+ (instancetype)configurationWithLifecycle:(SDLLifecycleConfiguration *)lifecycleConfig lockScreen:(nullable SDLLockScreenConfiguration *)lockScreenConfig logging:(nullable SDLLogConfiguration *)logConfig streamingMedia:(nullable SDLStreamingMediaConfiguration *)streamingMediaConfig {
return [[self alloc] initWithLifecycle:lifecycleConfig lockScreen:lockScreenConfig logging:logConfig streamingMedia:streamingMediaConfig];
}

#pragma mark - NSCopying

Expand Down
9 changes: 1 addition & 8 deletions SmartDeviceLink/SDLLifecycleConfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,14 @@
// Copyright © 2015 smartdevicelink. All rights reserved.
//

#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>

#import "SDLAppHMIType.h"
#import "SDLLanguage.h"

@class SDLFile;
@class SDLTTSChunk;

@protocol SDLSecurityType;


NS_ASSUME_NONNULL_BEGIN

Expand Down Expand Up @@ -118,11 +116,6 @@ NS_ASSUME_NONNULL_BEGIN
*/
@property (copy, nonatomic, nullable) NSArray<NSString *> *voiceRecognitionCommandNames;

/**
* Set security managers which could be used. This is primarily used with video streaming applications to authenticate and perhaps encrypt traffic data.
*/
@property (copy, nonatomic, nullable) NSArray<Class<SDLSecurityType>> *securityManagers;

@end

NS_ASSUME_NONNULL_END
1 change: 1 addition & 0 deletions SmartDeviceLink/SDLLifecycleConfiguration.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#import "SDLLifecycleConfiguration.h"

#import "SDLFile.h"
#import "SDLVideoEncoder.h"

static NSString *const DefaultTCPIPAddress = @"192.168.0.1";
static UInt16 const DefaultTCPIPPort = 12345;
Expand Down
2 changes: 1 addition & 1 deletion SmartDeviceLink/SDLLifecycleManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ typedef void (^SDLManagerReadyBlock)(BOOL success, NSError *_Nullable error);

@property (strong, nonatomic) SDLFileManager *fileManager;
@property (strong, nonatomic) SDLPermissionManager *permissionManager;
@property (strong, nonatomic, readonly, nullable) SDLStreamingMediaManager *streamManager;
@property (strong, nonatomic, nullable) SDLStreamingMediaManager *streamManager;
@property (strong, nonatomic) SDLLockScreenManager *lockScreenManager;

@property (strong, nonatomic, readonly) SDLNotificationDispatcher *notificationDispatcher;
Expand Down
Loading

0 comments on commit c860335

Please sign in to comment.