Skip to content

Commit

Permalink
Merge pull request #1393 from t-yoshii/fix/reflect-bitrate
Browse files Browse the repository at this point in the history
reflect bitrate returned from HMI in video encoder settings
  • Loading branch information
NicoleYarroch authored Sep 23, 2019
2 parents 0e7d70b + 60d63e8 commit d139740
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 0 deletions.
8 changes: 8 additions & 0 deletions SmartDeviceLink/SDLStreamingMediaConfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,17 @@ typedef NS_ENUM(NSUInteger, SDLCarWindowRenderingType) {
* Properties to use for applications that utilize the video encoder for streaming. See VTCompressionProperties.h for more details. For example, you can set kVTCompressionPropertyKey_ExpectedFrameRate to set your framerate. Setting the framerate this way will also set the framerate if you use CarWindow automatic streaming.
*
* Other properties you may want to try adjusting include kVTCompressionPropertyKey_AverageBitRate and kVTCompressionPropertyKey_DataRateLimits.
@note Setting values can be overridden by StreamingMediaManager when `allowOverrideEncoderSettings` property is YES.
*/
@property (copy, nonatomic, nullable) NSDictionary<NSString *, id> *customVideoEncoderSettings;

/**
When YES, the StreamingMediaManager will override encoder settings by the capability values returned from HMI. If you wish not to allow overriding encoder settings, set it to NO. Defaults to YES.
*/
@property (assign, nonatomic) BOOL allowOverrideEncoderSettings;

/**
Usable to change run time video stream setup behavior. Only use this and modify the results if you *really* know what you're doing. The head unit defaults are generally good.
*/
Expand Down
2 changes: 2 additions & 0 deletions SmartDeviceLink/SDLStreamingMediaConfiguration.m
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ - (instancetype)initWithSecurityManagers:(nullable NSArray<Class<SDLSecurityType
_carWindowRenderingType = SDLCarWindowRenderingTypeLayer;
_enableForcedFramerateSync = YES;
_allowMultipleViewControllerOrientations = NO;
_allowOverrideEncoderSettings = YES;

return self;
}
Expand Down Expand Up @@ -68,6 +69,7 @@ - (id)copyWithZone:(nullable NSZone *)zone {
newConfig.carWindowRenderingType = self.carWindowRenderingType;
newConfig.enableForcedFramerateSync = self.enableForcedFramerateSync;
newConfig.allowMultipleViewControllerOrientations = self.allowMultipleViewControllerOrientations;
newConfig.allowOverrideEncoderSettings = self.allowOverrideEncoderSettings;

return newConfig;
}
Expand Down
6 changes: 6 additions & 0 deletions SmartDeviceLink/SDLStreamingVideoLifecycleManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,12 @@ NS_ASSUME_NONNULL_BEGIN
@property (assign, nonatomic) BOOL showVideoBackgroundDisplay;


/**
When YES, the StreamingMediaManager will override encoder settings by the capability values returned from HMI. Defaults to YES.
*/
@property (assign, nonatomic) BOOL allowOverrideEncoderSettings;


- (instancetype)init NS_UNAVAILABLE;

/**
Expand Down
9 changes: 9 additions & 0 deletions SmartDeviceLink/SDLStreamingVideoLifecycleManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ - (instancetype)initWithConnectionManager:(id<SDLConnectionManagerType>)connecti
_screenSize = SDLDefaultScreenSize;
_backgroundingPixelBuffer = NULL;
_showVideoBackgroundDisplay = YES;
_allowOverrideEncoderSettings = configuration.streamingMediaConfig.allowOverrideEncoderSettings;
_preferredFormatIndex = 0;
_preferredResolutionIndex = 0;

Expand Down Expand Up @@ -345,6 +346,14 @@ - (void)didEnterStateVideoStreamStarting {
weakSelf.preferredFormats = capability.supportedFormats;
weakSelf.preferredResolutions = @[capability.preferredResolution];

if (weakSelf.allowOverrideEncoderSettings && capability.maxBitrate != nil) {
NSNumber *bitrate = [[NSNumber alloc] initWithUnsignedLongLong:(capability.maxBitrate.unsignedLongLongValue * 1000)];
NSMutableDictionary *settings = [[NSMutableDictionary alloc] init];
[settings addEntriesFromDictionary: self.videoEncoderSettings];
[settings setObject:bitrate forKey:(__bridge NSString *)kVTCompressionPropertyKey_AverageBitRate];
weakSelf.videoEncoderSettings = settings;
}

if (weakSelf.dataSource != nil) {
SDLLogV(@"Calling data source for modified preferred formats");
weakSelf.preferredFormats = [weakSelf.dataSource preferredVideoFormatOrderFromHeadUnitPreferredOrder:weakSelf.preferredFormats];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ __block void (^sendNotificationForHMILevel)(SDLHMILevel hmiLevel, SDLVideoStream
expect(@(streamingLifecycleManager.pixelBufferPool == NULL)).to(equal(@YES));
expect(@(streamingLifecycleManager.requestedEncryptionType)).to(equal(@(SDLStreamingEncryptionFlagNone)));
expect(@(streamingLifecycleManager.showVideoBackgroundDisplay)).to(equal(@YES));
expect(@(streamingLifecycleManager.allowOverrideEncoderSettings)).to(equal(@YES));
expect(streamingLifecycleManager.currentAppState).to(equal(SDLAppStateActive));
expect(streamingLifecycleManager.currentVideoStreamState).to(equal(SDLVideoStreamManagerStateStopped));
expect(streamingLifecycleManager.videoFormat).to(beNil());
Expand Down

0 comments on commit d139740

Please sign in to comment.