Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Video Encoder Support for Dynamic Screen Sizes #400

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 13 additions & 2 deletions SmartDeviceLink/SDLProxy.m
Expand Up @@ -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"
Expand Down Expand Up @@ -56,7 +57,8 @@ @interface SDLProxy () {
}

@property (strong, nonatomic) NSMutableSet *mutableProxyListeners;
@property (nonatomic, strong, readwrite) SDLStreamingMediaManager *streamingMediaManager;
@property (nonatomic, strong, readwrite, nullable) SDLStreamingMediaManager *streamingMediaManager;
@property (nonatomic, strong, nullable) SDLDisplayCapabilities* displayCapabilities;

@end

Expand Down Expand Up @@ -101,6 +103,8 @@ - (void)destructObjects {
_transport = nil;
_protocol = nil;
_mutableProxyListeners = nil;
_streamingMediaManager = nil;
_displayCapabilities = nil;
}
}

Expand Down Expand Up @@ -166,7 +170,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];
}

Expand Down Expand Up @@ -328,6 +335,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 {
Expand Down
9 changes: 7 additions & 2 deletions SmartDeviceLink/SDLStreamingMediaManager.h
Expand Up @@ -12,7 +12,7 @@
#import "SDLProtocolListener.h"

@class SDLAbstractProtocol;

@class SDLDisplayCapabilities;

NS_ASSUME_NONNULL_BEGIN

Expand All @@ -36,7 +36,7 @@ typedef void (^SDLStreamingStartBlock)(BOOL success, NSError *__nullable error);

@interface SDLStreamingMediaManager : NSObject <SDLProtocolListener>

- (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.
Expand Down Expand Up @@ -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

Expand Down
17 changes: 11 additions & 6 deletions SmartDeviceLink/SDLStreamingMediaManager.m
Expand Up @@ -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";
Expand Down Expand Up @@ -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;
Expand All @@ -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 {
Expand Down Expand Up @@ -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
Expand Down