/** CameraVideoView.h
 
 * View that handles displaying video frames
 * For now, this view displays video correctly only when created programmatically
 */

#import <UIKit/UIKit.h>
@import XPMobileSDK;

@protocol CameraVideoViewDelegate;


@interface CameraVideoView : UIView <XPSDKVideoConnectionDelegate> {
    
    XPSDKDownstreamVideoConnection * videoConnection;
    XPSDKVideoConnectionFrame * lastFrame;
    UIImage * lastImage;
    
    XPSDKVideoID videoID;
    
    CGRect originalRect;
    
    BOOL waitingFirstFrame;
    
    UIActivityIndicatorView * loadingIndicator;
    
    CGAffineTransform transformSourceCSToDrawCS;
    
    UILabel * errorMessageLabel;
    
    BOOL lostConnection;
}

@property (nonatomic) UIImage * lastImage;
@property (nonatomic) XPSDKVideoConnectionFrame * lastFrame;
@property (nonatomic, weak) id<CameraVideoViewDelegate> delegate;
@property (nonatomic, assign) BOOL waitingFirstFrame;

@property (weak, nonatomic, readonly) UIView * labelsContainer;

@property (nonatomic) CFTimeInterval timestamp;

@property (nonatomic, strong) XPSDKDownstreamVideoConnection * videoConnection;
@property (nonatomic, assign) CGRect displayRect;

- (void) setLoadingIndicatorVisible:(BOOL) visible;

@end

@protocol CameraVideoViewDelegate <NSObject>
@required
- (void) cameraVideoViewReceivedFirstFrame: (CameraVideoView *) cameraVideoView;
- (void) cameraVideoViewLostConnection: (CameraVideoView *) cameraVideoView;
- (void) cameraVideoViewRestoredConnection: (CameraVideoView *) cameraVideoView;
- (void) cameraVideoViewReceivedResolutionChange: (CameraVideoView *) cameraVideoView;

// Make sure you implement these methods if you use this view for live stream
@optional
- (void) cameraVideoView: (CameraVideoView *) cameraVideoView changedRecordingState: (BOOL) newRecordingState;
- (void) cameraVideoView: (CameraVideoView *) cameraVideoView changedMotionState: (BOOL) newMotionState;

@end
