diff options
-rw-r--r-- | SmartDeviceLink/SDLStreamingMediaLifecycleManager.h | 5 | ||||
-rw-r--r-- | SmartDeviceLink/SDLStreamingMediaLifecycleManager.m | 51 | ||||
-rw-r--r-- | SmartDeviceLink/SDLStreamingMediaManager.h | 5 | ||||
-rw-r--r-- | SmartDeviceLink/SDLStreamingMediaManager.m | 4 |
4 files changed, 50 insertions, 15 deletions
diff --git a/SmartDeviceLink/SDLStreamingMediaLifecycleManager.h b/SmartDeviceLink/SDLStreamingMediaLifecycleManager.h index b1a9a5a39..94870097f 100644 --- a/SmartDeviceLink/SDLStreamingMediaLifecycleManager.h +++ b/SmartDeviceLink/SDLStreamingMediaLifecycleManager.h @@ -103,6 +103,11 @@ extern SDLAudioStreamState *const SDLAudioStreamStateShuttingDown; @property (strong, nonatomic, readonly, nullable) SDLVideoStreamingFormat *videoFormat; /** + A list of all supported video formats by this manager + */ +@property (strong, nonatomic, readonly) NSArray<SDLVideoStreamingFormat *> *supportedFormats; + +/** * The pixel buffer pool reference returned back from an active VTCompressionSessionRef encoder. * * @warning This will only return a valid pixel buffer pool after the encoder has been initialized (when the video session has started). diff --git a/SmartDeviceLink/SDLStreamingMediaLifecycleManager.m b/SmartDeviceLink/SDLStreamingMediaLifecycleManager.m index b76153b97..f208f7c7d 100644 --- a/SmartDeviceLink/SDLStreamingMediaLifecycleManager.m +++ b/SmartDeviceLink/SDLStreamingMediaLifecycleManager.m @@ -162,17 +162,15 @@ typedef void(^SDLVideoCapabilityResponse)(SDLVideoStreamingCapability *_Nullable SDLImageResolution *resolution = [[SDLImageResolution alloc] initWithWidth:weakSelf.screenSize.width height:weakSelf.screenSize.height]; weakSelf.preferredFormats = @[format]; weakSelf.preferredResolutions = @[resolution]; + } else { + // If we got a response, get our preferred formats and resolutions + weakSelf.preferredFormats = capability.supportedFormats; + weakSelf.preferredResolutions = @[capability.preferredResolution]; - BLOCK_RETURN; - } - - // If we got a response, get our preferred formats and resolutions - weakSelf.preferredFormats = capability.supportedFormats; - weakSelf.preferredResolutions = @[capability.preferredResolution]; - - if (weakSelf.dataSource != nil) { - weakSelf.preferredFormats = [weakSelf.dataSource preferredVideoFormatOrderFromHeadUnitPreferredOrder:weakSelf.preferredFormats]; - weakSelf.preferredResolutions = [weakSelf.dataSource resolutionFromHeadUnitPreferredResolution:weakSelf.preferredResolutions.firstObject]; + if (weakSelf.dataSource != nil) { + weakSelf.preferredFormats = [weakSelf.dataSource preferredVideoFormatOrderFromHeadUnitPreferredOrder:weakSelf.preferredFormats]; + weakSelf.preferredResolutions = [weakSelf.dataSource resolutionFromHeadUnitPreferredResolution:weakSelf.preferredResolutions.firstObject]; + } } }]; } @@ -329,7 +327,7 @@ typedef void(^SDLVideoCapabilityResponse)(SDLVideoStreamingCapability *_Nullable SDLLogD(@"Video stream starting"); self.restartVideoStream = NO; - [self sdl_sendVideoStartService]; // TODO: How to retry + [self sdl_sendVideoStartService]; } - (void)didEnterStateVideoStreamReady { @@ -477,16 +475,16 @@ typedef void(^SDLVideoCapabilityResponse)(SDLVideoStreamingCapability *_Nullable // If height and/or width was rejected, and we have another resolution to try, advance our counter to try another resolution if (([nakPayload.rejectedParams containsObject:[NSString stringWithUTF8String:SDLControlFrameHeightKey]] - || [nakPayload.rejectedParams containsObject:[NSString stringWithUTF8String:SDLControlFrameWidthKey]]) - && self.preferredResolutionIndex < self.preferredResolutions.count) { + || [nakPayload.rejectedParams containsObject:[NSString stringWithUTF8String:SDLControlFrameWidthKey]])) { self.preferredResolutionIndex++; } if (([nakPayload.rejectedParams containsObject:[NSString stringWithUTF8String:SDLControlFrameVideoCodecKey]] - || [nakPayload.rejectedParams containsObject:[NSString stringWithUTF8String:SDLControlFrameVideoProtocolKey]]) - && self.preferredFormatIndex < self.preferredFormats.count) { + || [nakPayload.rejectedParams containsObject:[NSString stringWithUTF8String:SDLControlFrameVideoProtocolKey]])) { self.preferredFormatIndex++; } + + [self sdl_sendVideoStartService]; } - (void)sdl_handleAudioStartServiceNak:(SDLProtocolMessage *)audioStartServiceNak { @@ -660,7 +658,23 @@ typedef void(^SDLVideoCapabilityResponse)(SDLVideoStreamingCapability *_Nullable }]; } +/** + Pull the current format / resolution out of our preferred resolutions and craft a start video service payload out of it, then send a start service. If the format isn't one that we support, we're going to try the next format. + */ - (void)sdl_sendVideoStartService { + while (self.preferredFormatIndex < self.preferredFormats.count) { + if (![self.supportedFormats containsObject:self.preferredFormats[self.preferredResolutionIndex]]) { + self.preferredFormatIndex++; + } + } + + // If this fails we have no known formats to use + if (self.preferredFormatIndex >= self.preferredFormats.count + || self.preferredResolutionIndex >= self.preferredResolutions.count) { + [self sdl_transitionToStoppedState:SDLServiceTypeVideo]; + return; + } + SDLVideoStreamingFormat *preferredFormat = self.preferredFormats[self.preferredFormatIndex]; SDLImageResolution *preferredResolution = self.preferredResolutions[self.preferredResolutionIndex]; @@ -692,6 +706,13 @@ typedef void(^SDLVideoCapabilityResponse)(SDLVideoStreamingCapability *_Nullable return [self.hmiLevel isEqualToEnum:SDLHMILevelLimited] || [self.hmiLevel isEqualToEnum:SDLHMILevelFull]; } +- (NSArray<SDLVideoStreamingFormat *> *)supportedFormats { + SDLVideoStreamingFormat *h264raw = [[SDLVideoStreamingFormat alloc] initWithCodec:SDLVideoStreamingCodecH264 protocol:SDLVideoStreamingProtocolRAW]; + SDLVideoStreamingFormat *h264rtp = [[SDLVideoStreamingFormat alloc] initWithCodec:SDLVideoStreamingCodecH264 protocol:SDLVideoStreamingProtocolRTP]; + + return @[h264raw, h264rtp]; +} + @end NS_ASSUME_NONNULL_END diff --git a/SmartDeviceLink/SDLStreamingMediaManager.h b/SmartDeviceLink/SDLStreamingMediaManager.h index 8434b1723..fedf5460c 100644 --- a/SmartDeviceLink/SDLStreamingMediaManager.h +++ b/SmartDeviceLink/SDLStreamingMediaManager.h @@ -71,6 +71,11 @@ NS_ASSUME_NONNULL_BEGIN @property (strong, nonatomic, readonly, nullable) SDLVideoStreamingFormat *videoFormat; /** + A list of all supported video formats by this manager + */ +@property (strong, nonatomic, readonly) NSArray<SDLVideoStreamingFormat *> *supportedFormats; + +/** * The pixel buffer pool reference returned back from an active VTCompressionSessionRef encoder. * * @warning This will only return a valid pixel buffer pool after the encoder has been initialized (when the video session has started). diff --git a/SmartDeviceLink/SDLStreamingMediaManager.m b/SmartDeviceLink/SDLStreamingMediaManager.m index e2c7731b6..e91b45b8f 100644 --- a/SmartDeviceLink/SDLStreamingMediaManager.m +++ b/SmartDeviceLink/SDLStreamingMediaManager.m @@ -105,6 +105,10 @@ NS_ASSUME_NONNULL_BEGIN return self.lifecycleManager.requestedEncryptionType; } +- (NSArray<SDLVideoStreamingFormat *> *)supportedFormats { + return self.lifecycleManager.supportedFormats; +} + #pragma mark - Setters - (void)setRequestedEncryptionType:(SDLStreamingEncryptionFlag)requestedEncryptionType { self.lifecycleManager.requestedEncryptionType = requestedEncryptionType; |