summaryrefslogtreecommitdiff
path: root/SmartDeviceLink/SDLStreamingMediaLifecycleManager.h
blob: 1dcbcd09fb71948e20b5755326482b5fd56e6f97 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
//
//  SDLStreamingMediaLifecycleManager.h
//  SmartDeviceLink-iOS
//
//  Created by Muller, Alexander (A.) on 2/16/17.
//  Copyright © 2017 smartdevicelink. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <VideoToolbox/VideoToolbox.h>

#import "SDLHMILevel.h"
#import "SDLProtocolListener.h"
#import "SDLStreamingMediaManagerConstants.h"

@class SDLAbstractProtocol;
@class SDLStateMachine;
@class SDLTouchManager;

NS_ASSUME_NONNULL_BEGIN

typedef NSString SDLAppState;
extern SDLAppState *const SDLAppStateInactive;
extern SDLAppState *const SDLAppStateActive;

typedef NSString SDLVideoStreamState;
extern SDLVideoStreamState *const SDLVideoStreamStateStopped;
extern SDLVideoStreamState *const SDLVideoStreamStateStarting;
extern SDLVideoStreamState *const SDLVideoStreamStateReady;
extern SDLVideoStreamState *const SDLVideoStreamStateShuttingDown;

typedef NSString SDLAudioStreamState;
extern SDLAudioStreamState *const SDLAudioStreamStateStopped;
extern SDLAudioStreamState *const SDLAudioStreamStateStarting;
extern SDLAudioStreamState *const SDLAudioStreamStateReady;
extern SDLAudioStreamState *const SDLAudioStreamStateShuttingDown;


#pragma mark - Interface

@interface SDLStreamingMediaLifecycleManager : NSObject <SDLProtocolListener>

@property (strong, nonatomic, readonly) SDLStateMachine *appStateMachine;
@property (strong, nonatomic, readonly) SDLStateMachine *videoStreamStateMachine;
@property (strong, nonatomic, readonly) SDLStateMachine *audioStreamStateMachine;

@property (strong, nonatomic, readonly) SDLAppState *currentAppState;
@property (strong, nonatomic, readonly) SDLAudioStreamState *currentAudioStreamState;
@property (strong, nonatomic, readonly) SDLVideoStreamState *currentVideoStreamState;

@property (copy, nonatomic, nullable) SDLHMILevel hmiLevel;

@property (assign, nonatomic, readonly, getter=shouldRestartVideoStream) BOOL restartVideoStream;

/**
 *  Touch Manager responsible for providing touch event notifications.
 */
@property (nonatomic, strong, readonly) SDLTouchManager *touchManager;

/**
 *  Whether or not video streaming is supported
 *
 *  @see SDLRegisterAppInterface SDLDisplayCapabilities
 */
@property (assign, nonatomic, readonly, getter=isVideoStreamingSupported) BOOL videoStreamingSupported;

/**
 *  Whether or not audio streaming is supported. Currently this is the same as videoStreamingSupported.
 */
@property (assign, nonatomic, readonly, getter=isAudioStreamingSupported) BOOL audioStreamingSupported;

/**
 *  Whether or not the video session is connected.
 */
@property (assign, nonatomic, readonly, getter=isVideoConnected) BOOL videoConnected;

/**
 *  Whether or not the video session is encrypted. This may be different than the requestedEncryptionType.
 */
@property (assign, nonatomic, readonly, getter=isVideoEncrypted) BOOL videoEncrypted;

/**
 *  Whether or not the audio session is connected.
 */
@property (assign, nonatomic, readonly, getter=isAudioConnected) BOOL audioConnected;

/**
 *  Whether or not the audio session is encrypted. This may be different than the requestedEncryptionType.
 */
@property (assign, nonatomic, readonly, getter=isAudioEncrypted) BOOL audioEncrypted;

/**
 *  Whether or not the video stream is paused due to either the application being backgrounded, the HMI state being either NONE or BACKGROUND, or the video stream not being ready.
 */
@property (assign, nonatomic, readonly, getter=isVideoStreamingPaused) BOOL videoStreamingPaused;

/**
 *  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;

/**
 *  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).
 *  @discussion Clients may call this once and retain the resulting pool, this call is cheap enough that it's OK to call it once per frame.
 */
@property (assign, nonatomic, readonly, nullable) CVPixelBufferPoolRef pixelBufferPool;

/**
 *  The requested encryption type when a session attempts to connect. This setting applies to both video and audio sessions.
 *
 *  DEFAULT: SDLStreamingEncryptionFlagAuthenticateAndEncrypt
 */
@property (assign, nonatomic) SDLStreamingEncryptionFlag requestedEncryptionType;

/**
 *  Creates a streaming manager with a specified encryption type.
 *
 *  @param encryption               The encryption type requested when starting to stream.
 *  @param videoEncoderSettings     The video encoder settings to use with SDLVideoEncoder.
 *
 *  @return An instance of SDLStreamingMediaManager
 */
- (instancetype)initWithEncryption:(SDLStreamingEncryptionFlag)encryption videoEncoderSettings:(nullable NSDictionary<NSString *, id> *)videoEncoderSettings NS_DESIGNATED_INITIALIZER;

/**
 *  Start the manager with a completion block that will be called when startup completes. This is used internally. To use an SDLStreamingMediaManager, you should use the manager found on `SDLManager`.
 *
 *  @param completionHandler    The block to be called when the manager's setup is complete.
 */
- (void)startWithProtocol:(SDLAbstractProtocol*)protocol completionHandler:(void (^)(BOOL success, NSError *__nullable error))completionHandler;

/**
 *  Stop the manager. This method is used internally.
 */
- (void)stop;

/**
 *  This method receives raw image data and will run iOS8+'s hardware video encoder to turn the data into a video stream, which will then be passed to the connected head unit.
 *
 *  @param imageBuffer  A CVImageBufferRef to be encoded by Video Toolbox
 *
 *  @return Whether or not the data was successfully encoded and sent.
 */
- (BOOL)sendVideoData:(CVImageBufferRef)imageBuffer;

/**
 *  This method receives raw image data and will run iOS8+'s hardware video encoder to turn the data into a video stream, which will then be passed to the connected head unit.
 *
 *  @param imageBuffer  A CVImageBufferRef to be encoded by Video Toolbox
 *  @param presentationTimestamp A presentation timestamp for the frame, or kCMTimeInvalid if timestamp is unknown. If it's valid, it must be greater than the previous one.
 *
 *  @return Whether or not the data was successfully encoded and sent.
 */
- (BOOL)sendVideoData:(CVImageBufferRef)imageBuffer presentationTimestamp:(CMTime)presentationTimestamp;

/**
 *  This method receives PCM audio data and will attempt to send that data across to the head unit for immediate playback
 *
 *  @param audioData    The data in PCM audio format, to be played
 *
 *  @return Whether or not the data was successfully sent.
 */
- (BOOL)sendAudioData:(NSData *)audioData;


@end

NS_ASSUME_NONNULL_END