diff --git a/SmartDeviceLink/SDLStreamingMediaConfiguration.h b/SmartDeviceLink/SDLStreamingMediaConfiguration.h index 3e4f91849..76ef5b3ff 100644 --- a/SmartDeviceLink/SDLStreamingMediaConfiguration.h +++ b/SmartDeviceLink/SDLStreamingMediaConfiguration.h @@ -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 *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. */ diff --git a/SmartDeviceLink/SDLStreamingMediaConfiguration.m b/SmartDeviceLink/SDLStreamingMediaConfiguration.m index 41c7df822..a3a06ed6f 100644 --- a/SmartDeviceLink/SDLStreamingMediaConfiguration.m +++ b/SmartDeviceLink/SDLStreamingMediaConfiguration.m @@ -37,6 +37,7 @@ - (instancetype)initWithSecurityManagers:(nullable NSArray)connecti _screenSize = SDLDefaultScreenSize; _backgroundingPixelBuffer = NULL; _showVideoBackgroundDisplay = YES; + _allowOverrideEncoderSettings = configuration.streamingMediaConfig.allowOverrideEncoderSettings; _preferredFormatIndex = 0; _preferredResolutionIndex = 0; @@ -344,6 +345,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]; diff --git a/SmartDeviceLinkTests/DevAPISpecs/SDLStreamingVideoLifecycleManagerSpec.m b/SmartDeviceLinkTests/DevAPISpecs/SDLStreamingVideoLifecycleManagerSpec.m index 31737c214..c8f169010 100644 --- a/SmartDeviceLinkTests/DevAPISpecs/SDLStreamingVideoLifecycleManagerSpec.m +++ b/SmartDeviceLinkTests/DevAPISpecs/SDLStreamingVideoLifecycleManagerSpec.m @@ -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());