summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Fischer <joeljfischer@gmail.com>2017-08-08 17:35:04 -0400
committerJoel Fischer <joeljfischer@gmail.com>2017-08-08 17:35:04 -0400
commit08e0cd39fb1ca53f183fa760b9ed1b21580ea41c (patch)
tree921eb0d3b5710ea009ae364ad4858d87e1846faa
parent7fcb08c82260a3b9fcded68c71634a78ad134bae (diff)
downloadsdl_ios-08e0cd39fb1ca53f183fa760b9ed1b21580ea41c.tar.gz
Update Streaming Media Manager with video control payloads
-rw-r--r--SmartDeviceLink/SDLStreamingMediaManager.h29
-rw-r--r--SmartDeviceLink/SDLStreamingMediaManager.m64
2 files changed, 63 insertions, 30 deletions
diff --git a/SmartDeviceLink/SDLStreamingMediaManager.h b/SmartDeviceLink/SDLStreamingMediaManager.h
index 027b39304..8bbde367a 100644
--- a/SmartDeviceLink/SDLStreamingMediaManager.h
+++ b/SmartDeviceLink/SDLStreamingMediaManager.h
@@ -14,6 +14,8 @@
@class SDLAbstractProtocol;
@class SDLDisplayCapabilities;
@class SDLTouchManager;
+@class SDLVideoStreamingCodec;
+@class SDLVideoStreamingProtocol;
NS_ASSUME_NONNULL_BEGIN
@@ -99,7 +101,7 @@ typedef void (^SDLStreamingEncryptionStartBlock)(BOOL success, BOOL encryption,
- (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. This will not use encryption.
+ * 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. This will not use encryption.
*
* @warning If this method is called on an 8.0 device, it will assert (in debug), or return a failure immediately to your block (in release).
*
@@ -108,6 +110,19 @@ typedef void (^SDLStreamingEncryptionStartBlock)(BOOL success, BOOL encryption,
- (void)startVideoSessionWithStartBlock:(SDLStreamingStartBlock)startBlock;
/**
+ 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. This will not use encryption. To get proper values for height, width, protocol, and codec, call GetSystemCapabilities. If the remote system does not support GetSystemCapabilities, then call `startVideoSessionWithStartBlock:` instead.
+
+ @warning If this method is called on an 8.0 device, it will assert (in debug), or return a failure immediately to your block (in release).
+
+ @param height The height requested to be used
+ @param width The width requested to be used
+ @param protocol The protocol requested to be used
+ @param codec The codec requested to be used
+ @param startBlock A block that will be called with the result of attempting to start a video session
+ */
+- (void)startVideoSessionWithHeight:(int32_t)height width:(int32_t)width protocol:(nullable SDLVideoStreamingProtocol *)protocol codec:(nullable SDLVideoStreamingCodec *)codec startBlock:(SDLStreamingStartBlock)startBlock;
+
+/**
* Start a video session either with with no encryption (the default), with authentication but no encryption (this will attempt a TLS authentication with the other side, but will not physically encrypt the data after that), or authentication and encryption, which will encrypt all video data being sent.
*
* @param encryptionFlag Whether and how much security to apply to the video session.
@@ -116,6 +131,18 @@ typedef void (^SDLStreamingEncryptionStartBlock)(BOOL success, BOOL encryption,
- (void)startVideoSessionWithTLS:(SDLEncryptionFlag)encryptionFlag startBlock:(SDLStreamingEncryptionStartBlock)startBlock;
/**
+ Start a video session either with with no encryption (the default), with authentication but no encryption (this will attempt a TLS authentication with the other side, but will not physically encrypt the data after that), or authentication and encryption, which will encrypt all video data being sent. To get proper values for height, width, protocol, and codec, call GetSystemCapabilities. If the remote system does not support GetSystemCapabilities, then call `startVideoSessionWithStartBlock:` instead.
+
+ @param encryptionFlag Whether and how much security to apply to the video session.
+ @param height The height requested to be used
+ @param width The width requested to be used
+ @param protocol The protocol requested to be used
+ @param codec The codec requested to be used
+ @param startBlock A block that will be called with the result of attempting to start a video session
+ */
+- (void)startVideoSessionWithTLS:(SDLEncryptionFlag)encryptionFlag height:(int32_t)height width:(int32_t)width protocol:(nullable SDLVideoStreamingProtocol *)protocol codec:(nullable SDLVideoStreamingCodec *)codec startBlock:(SDLStreamingEncryptionStartBlock)startBlock;
+
+/**
* This method will stop a running video session if there is one running.
*/
- (void)stopVideoSession;
diff --git a/SmartDeviceLink/SDLStreamingMediaManager.m b/SmartDeviceLink/SDLStreamingMediaManager.m
index 57df1dcbf..3831b036d 100644
--- a/SmartDeviceLink/SDLStreamingMediaManager.m
+++ b/SmartDeviceLink/SDLStreamingMediaManager.m
@@ -13,6 +13,7 @@
#import "SDLAbstractProtocol.h"
#import "SDLControlFramePayloadConstants.h"
#import "SDLControlFramePayloadAudioStartServiceAck.h"
+#import "SDLControlFramePayloadVideoStartService.h"
#import "SDLControlFramePayloadVideoStartServiceAck.h"
#import "SDLDebugTool.h"
#import "SDLDisplayCapabilities.h"
@@ -105,15 +106,8 @@ NS_ASSUME_NONNULL_BEGIN
_videoEncoderSettings = self.defaultVideoEncoderSettings;
_touchManager = [[SDLTouchManager alloc] init];
- [[NSNotificationCenter defaultCenter] addObserver:self
- selector:@selector(sdl_applicationDidEnterBackground:)
- name:UIApplicationDidEnterBackgroundNotification
- object:nil];
-
- [[NSNotificationCenter defaultCenter] addObserver:self
- selector:@selector(sdl_applicationDidResignActive:)
- name:UIApplicationWillResignActiveNotification
- object:nil];
+ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(sdl_applicationDidEnterBackground:) name:UIApplicationDidEnterBackgroundNotification object:nil];
+ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(sdl_applicationDidResignActive:) name:UIApplicationWillResignActiveNotification object:nil];
return self;
}
@@ -125,13 +119,20 @@ NS_ASSUME_NONNULL_BEGIN
#pragma mark - Streaming media lifecycle
- (void)startVideoSessionWithStartBlock:(SDLStreamingStartBlock)startBlock {
- [self startVideoSessionWithTLS:SDLEncryptionFlagNone
- startBlock:^(BOOL success, BOOL encryption, NSError *_Nullable error) {
- startBlock(success, error);
- }];
+ [self startVideoSessionWithHeight:SDLControlFrameInt32NotFound width:SDLControlFrameInt32NotFound protocol:nil codec:nil startBlock:startBlock];
+}
+
+- (void)startVideoSessionWithHeight:(int32_t)height width:(int32_t)width protocol:(nullable SDLVideoStreamingProtocol *)protocol codec:(nullable SDLVideoStreamingCodec *)codec startBlock:(SDLStreamingStartBlock)startBlock {
+ [self startVideoSessionWithTLS:SDLEncryptionFlagNone height:height width:width protocol:protocol codec:codec startBlock:^(BOOL success, BOOL encryption, NSError *_Nullable error) {
+ startBlock(success, error);
+ }];
}
- (void)startVideoSessionWithTLS:(SDLEncryptionFlag)encryptionFlag startBlock:(SDLStreamingEncryptionStartBlock)startBlock {
+ [self startVideoSessionWithTLS:encryptionFlag height:SDLControlFrameInt32NotFound width:SDLControlFrameInt32NotFound protocol:nil codec:nil startBlock:startBlock];
+}
+
+- (void)startVideoSessionWithTLS:(SDLEncryptionFlag)encryptionFlag height:(int32_t)height width:(int32_t)width protocol:(nullable SDLVideoStreamingProtocol *)protocol codec:(nullable SDLVideoStreamingCodec *)codec startBlock:(SDLStreamingEncryptionStartBlock)startBlock {
if (SDL_SYSTEM_VERSION_LESS_THAN(@"8.0")) {
NSAssert(NO, @"SDL Video Sessions can only be run on iOS 8+ devices");
startBlock(NO, NO, [NSError errorWithDomain:SDLErrorDomainStreamingMediaVideo code:SDLStreamingVideoErrorInvalidOperatingSystemVersion userInfo:nil]);
@@ -142,23 +143,23 @@ NS_ASSUME_NONNULL_BEGIN
self.videoStartBlock = [startBlock copy];
self.videoSessionEncrypted = (encryptionFlag == SDLEncryptionFlagAuthenticateAndEncrypt ? YES : NO);
+ SDLControlFramePayloadVideoStartService *payload = [[SDLControlFramePayloadVideoStartService alloc] initWithVideoHeight:height width:width protocol:protocol codec:codec];
if (encryptionFlag != SDLEncryptionFlagNone) {
__weak typeof(self) weakSelf = self;
- [self.protocol startSecureServiceWithType:SDLServiceType_Video
- completionHandler:^(BOOL success, NSError *error) {
- typeof(weakSelf) strongSelf = weakSelf;
- // If success, we will get an ACK or NACK, so those methods will handle calling the video block
- if (!success) {
- if (strongSelf.videoStartBlock == nil) {
- return;
- }
-
- strongSelf.videoStartBlock(NO, NO, error);
- strongSelf.videoStartBlock = nil;
- }
- }];
+ [self.protocol startSecureServiceWithType:SDLServiceType_Video payload:payload.data completionHandler:^(BOOL success, NSError *error) {
+ typeof(weakSelf) strongSelf = weakSelf;
+ // If success, we will get an ACK or NACK, so those methods will handle calling the video block
+ if (!success) {
+ if (strongSelf.videoStartBlock == nil) {
+ return;
+ }
+
+ strongSelf.videoStartBlock(NO, NO, error);
+ strongSelf.videoStartBlock = nil;
+ }
+ }];
} else {
- [self.protocol startServiceWithType:SDLServiceType_Video];
+ [self.protocol startServiceWithType:SDLServiceType_Video payload:payload.data];
}
}
@@ -183,7 +184,7 @@ NS_ASSUME_NONNULL_BEGIN
if (encryptionFlag != SDLEncryptionFlagNone) {
__weak typeof(self) weakSelf = self;
- [self.protocol startSecureServiceWithType:SDLServiceType_Audio
+ [self.protocol startSecureServiceWithType:SDLServiceType_Audio payload:nil
completionHandler:^(BOOL success, NSError *error) {
typeof(weakSelf) strongSelf = weakSelf;
// If this passes, we will get an ACK or NACK, so those methods will handle calling the audio block
@@ -197,7 +198,7 @@ NS_ASSUME_NONNULL_BEGIN
}
}];
} else {
- [self.protocol startServiceWithType:SDLServiceType_Audio];
+ [self.protocol startServiceWithType:SDLServiceType_Audio payload:nil];
}
}
@@ -323,6 +324,10 @@ NS_ASSUME_NONNULL_BEGIN
[[SDLGlobals globals] setDynamicMTUSize:videoAckPayload.mtu forServiceType:SDLServiceType_Video];
}
+ if (videoAckPayload.height != SDLControlFrameInt32NotFound && videoAckPayload.width != SDLControlFrameInt32NotFound) {
+ _screenSize = CGSizeMake(videoAckPayload.height, videoAckPayload.width);
+ }
+
NSError *error = nil;
BOOL success = [self sdl_configureVideoEncoderWithError:&error];
@@ -608,6 +613,7 @@ void sdl_videoEncoderOutputCallback(void *CM_NULLABLE outputCallbackRefCon, void
}
#pragma mark - Private Functions
+
- (void)sdl_applicationDidEnterBackground:(NSNotification *)notification {
[self.touchManager cancelPendingTouches];
}