From 5d7ef8a3403bdd77945a680b9285e4b4274ee430 Mon Sep 17 00:00:00 2001 From: "Muller, Alexander (A.)" Date: Tue, 17 May 2016 14:55:43 -0700 Subject: [PATCH 1/2] Added support for contained video encoder to use the properties of the screen size returned from a successful Register App Interface. --- SmartDeviceLink-iOS/SmartDeviceLink/SDLProxy.m | 12 +++++++++++- .../SmartDeviceLink/SDLStreamingMediaManager.h | 9 +++++++-- .../SmartDeviceLink/SDLStreamingMediaManager.m | 17 +++++++++++------ 3 files changed, 29 insertions(+), 9 deletions(-) diff --git a/SmartDeviceLink-iOS/SmartDeviceLink/SDLProxy.m b/SmartDeviceLink-iOS/SmartDeviceLink/SDLProxy.m index 0fe44f31e..ffdf52551 100644 --- a/SmartDeviceLink-iOS/SmartDeviceLink/SDLProxy.m +++ b/SmartDeviceLink-iOS/SmartDeviceLink/SDLProxy.m @@ -29,6 +29,7 @@ #import "SDLProtocolMessage.h" #import "SDLProtocolMessage.h" #import "SDLPutFile.h" +#import "SDLRegisterAppInterfaceResponse.h" #import "SDLRPCPayload.h" #import "SDLRPCPayload.h" #import "SDLRPCRequestFactory.h" @@ -57,6 +58,7 @@ @interface SDLProxy () { @property (strong, nonatomic) NSMutableSet *mutableProxyListeners; @property (nonatomic, strong, readwrite) SDLStreamingMediaManager *streamingMediaManager; +@property (nonatomic, strong) SDLDisplayCapabilities* displayCapabilities; @end @@ -101,6 +103,7 @@ - (void)destructObjects { _transport = nil; _protocol = nil; _mutableProxyListeners = nil; + _streamingMediaManager = nil; } } @@ -166,7 +169,10 @@ - (NSString *)proxyVersion { - (SDLStreamingMediaManager *)streamingMediaManager { if (_streamingMediaManager == nil) { - _streamingMediaManager = [[SDLStreamingMediaManager alloc] initWithProtocol:self.protocol]; + if (self.displayCapabilities == nil) { + @throw [NSException exceptionWithName:NSInvalidArgumentException reason:@"SDLStreamingMediaManager must be accessed only after a successful RegisterAppInterfaceResponse" userInfo:nil]; + } + _streamingMediaManager = [[SDLStreamingMediaManager alloc] initWithProtocol:self.protocol displayCapabilities:self.displayCapabilities]; [self.protocol.protocolDelegateTable addObject:_streamingMediaManager]; } @@ -328,6 +334,10 @@ - (void)handleRegisterAppInterfaceResponse:(SDLRPCResponse *)response { [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(sendMobileHMIState) name:UIApplicationDidBecomeActiveNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(sendMobileHMIState) name:UIApplicationDidEnterBackgroundNotification object:nil]; } + + // Extract the display capabilties to successfully build SDLStreamingMediaManager's video encoder. + SDLRegisterAppInterfaceResponse* registerResponse = (SDLRegisterAppInterfaceResponse*)response; + self.displayCapabilities = registerResponse.displayCapabilities; } - (void)handleSyncPData:(SDLRPCMessage *)message { diff --git a/SmartDeviceLink-iOS/SmartDeviceLink/SDLStreamingMediaManager.h b/SmartDeviceLink-iOS/SmartDeviceLink/SDLStreamingMediaManager.h index 05a855e13..6a7f0318a 100644 --- a/SmartDeviceLink-iOS/SmartDeviceLink/SDLStreamingMediaManager.h +++ b/SmartDeviceLink-iOS/SmartDeviceLink/SDLStreamingMediaManager.h @@ -12,7 +12,7 @@ #import "SDLProtocolListener.h" @class SDLAbstractProtocol; - +@class SDLDisplayCapabilities; NS_ASSUME_NONNULL_BEGIN @@ -36,7 +36,7 @@ typedef void (^SDLStreamingStartBlock)(BOOL success, NSError *__nullable error); @interface SDLStreamingMediaManager : NSObject -- (instancetype)initWithProtocol:(SDLAbstractProtocol *)protocol; +- (instancetype)initWithProtocol:(SDLAbstractProtocol *)protocol displayCapabilities:(SDLDisplayCapabilities*)displayCapabilities; /** * This method will attempt to start a streaming video session. It will set up iOS's video encoder, and call out to the head unit asking if it will start a video session. @@ -85,6 +85,11 @@ typedef void (^SDLStreamingStartBlock)(BOOL success, NSError *__nullable error); @property (assign, nonatomic, readonly) BOOL videoSessionConnected; @property (assign, nonatomic, readonly) BOOL audioSessionConnected; +/* + * This is the current screen size of a connected display. This will be the size the video encoder uses to encode the raw image data. + */ +@property (assign, nonatomic, readonly) CGSize screenSize; + @end diff --git a/SmartDeviceLink-iOS/SmartDeviceLink/SDLStreamingMediaManager.m b/SmartDeviceLink-iOS/SmartDeviceLink/SDLStreamingMediaManager.m index 62682c9dc..bfb4e4965 100644 --- a/SmartDeviceLink-iOS/SmartDeviceLink/SDLStreamingMediaManager.m +++ b/SmartDeviceLink-iOS/SmartDeviceLink/SDLStreamingMediaManager.m @@ -11,8 +11,10 @@ @import UIKit; #import "SDLAbstractProtocol.h" +#import "SDLDisplayCapabilities.h" #import "SDLGlobals.h" - +#import "SDLImageResolution.h" +#import "SDLScreenParams.h" NSString *const SDLErrorDomainStreamingMediaVideo = @"com.sdl.streamingmediamanager.video"; NSString *const SDLErrorDomainStreamingMediaAudio = @"com.sdl.streamingmediamanager.audio"; @@ -41,7 +43,7 @@ @implementation SDLStreamingMediaManager #pragma mark - Class Lifecycle -- (instancetype)initWithProtocol:(SDLAbstractProtocol *)protocol { +- (instancetype)initWithProtocol:(SDLAbstractProtocol *)protocol displayCapabilities:(SDLDisplayCapabilities *)displayCapabilities { self = [super init]; if (!self) { return nil; @@ -56,11 +58,15 @@ - (instancetype)initWithProtocol:(SDLAbstractProtocol *)protocol { _videoStartBlock = nil; _audioStartBlock = nil; - + + SDLImageResolution* resolution = displayCapabilities.screenParams.resolution; + if (resolution != nil) { + _screenSize = CGSizeMake(resolution.resolutionWidth.floatValue, resolution.resolutionHeight.floatValue); + } + return self; } - #pragma mark - Streaming media lifecycle - (void)startVideoSessionWithStartBlock:(SDLStreamingStartBlock)startBlock { @@ -224,8 +230,7 @@ - (BOOL)sdl_configureVideoEncoderWithError:(NSError *__autoreleasing *)error { OSStatus status; // Create a compression session - // TODO (Joel F.)[2015-08-18]: Dimensions should be from the Head Unit - status = VTCompressionSessionCreate(NULL, 640, 480, kCMVideoCodecType_H264, NULL, NULL, NULL, &sdl_videoEncoderOutputCallback, (__bridge void *)self, &_compressionSession); + status = VTCompressionSessionCreate(NULL, self.screenSize.width, self.screenSize.height, kCMVideoCodecType_H264, NULL, NULL, NULL, &sdl_videoEncoderOutputCallback, (__bridge void *)self, &_compressionSession); if (status != noErr) { // TODO: Log the error From a67d2fa7141a71abf3f9dd124b86f59f5875d304 Mon Sep 17 00:00:00 2001 From: "Muller, Alexander (A.)" Date: Thu, 19 May 2016 12:53:09 -0700 Subject: [PATCH 2/2] added nullable properties to SDLStreamingManager & SDLDisplayCapability properties. Also added nil when proxy is disposed for local display capabilities. --- SmartDeviceLink-iOS/SmartDeviceLink/SDLProxy.m | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/SmartDeviceLink-iOS/SmartDeviceLink/SDLProxy.m b/SmartDeviceLink-iOS/SmartDeviceLink/SDLProxy.m index ffdf52551..9a037ec72 100644 --- a/SmartDeviceLink-iOS/SmartDeviceLink/SDLProxy.m +++ b/SmartDeviceLink-iOS/SmartDeviceLink/SDLProxy.m @@ -57,8 +57,8 @@ @interface SDLProxy () { } @property (strong, nonatomic) NSMutableSet *mutableProxyListeners; -@property (nonatomic, strong, readwrite) SDLStreamingMediaManager *streamingMediaManager; -@property (nonatomic, strong) SDLDisplayCapabilities* displayCapabilities; +@property (nonatomic, strong, readwrite, nullable) SDLStreamingMediaManager *streamingMediaManager; +@property (nonatomic, strong, nullable) SDLDisplayCapabilities* displayCapabilities; @end @@ -104,6 +104,7 @@ - (void)destructObjects { _protocol = nil; _mutableProxyListeners = nil; _streamingMediaManager = nil; + _displayCapabilities = nil; } }