Author Message
prashant06
Joined: Aug 8, 2017
Messages: 32
Offline
I want to show remote video call stream in full screen without stretching video or maintaining a video aspect. I have tried to set content mode of remote video view to UIViewContentModeScaleAspectFit but doesn't work. Please help me to achieve this.
Pavel_K
Joined: Dec 20, 2016
Messages: 67
Offline
You can change video view as you want by changing width and heights. To save aspect ratio you need to update size of your view based on video size, that you can get from "layer" observer. Basically you should do next things:

1. Initialize layer with observer


[_remoteVideoView.layer addObserver:self
forKeyPath:@"videoFrameResolution"
options:(NSKeyValueObservingOptions)(NSKeyValueObservingOptionNew|NSKeyValueObservingOptionOld)
context:NULL];


2. Initialize surface with this layer


RemoteVideoSurface *surface1 = [[RemoteVideoSurface alloc] init];
surface1.name = @"remote surface 1";
surface1.renderer = (CSVideoRendererIOS *)self.remoteVideoView.layer;
surface1.view = _remoteVideoView;


3. Update size in handler


- (void)observeValueForKeyPath:(NSString *)keyPath
ofObject:(id)object
change:(NSDictionary *)change
context:(void *)context {
CGSize videoSize = [change[NSKeyValueChangeKey] CGSizeValue];
if (videoSize.height>0) {
CGFloat videoAspectRatio = videoSize.width / videoSize.height;
CGFloat frameWidth = self.remoteVideoView.frame.size.width;
CGFloat frameHeight = frameWidth / videoAspectRatio;
.....
}

prashant06
Joined: Aug 8, 2017
Messages: 32
Offline
I am using CSDK 3.2.0 in that from where I can get the RemoteVideoSurface class.
Pavel_K
Joined: Dec 20, 2016
Messages: 67
Offline
You can check how surface has been initialized in Sample app:

self.mediaManager.remoteVideoSink = (CSVideoRendererIOS *) self.remoteVideoView.layer;


You just need to add observer.
prashant06
Joined: Aug 8, 2017
Messages: 32
Offline
I sample app in ActiveCallViewController.m I have added code as you mentioned

[_remoteVideoView.layer addObserver:self
forKeyPath:@"videoFrameResolution"
options:(NSKeyValueObservingOptions)(NSKeyValueObservingOptionNew|NSKeyValueObservingOptionOld)
context:NULL];


- (void)observeValueForKeyPath:(NSString *)keyPath
ofObject:(id)object
change:(NSDictionary *)change
context:(void *)context
{
CGSize videoSize = [change[@"NSKeyValueChangeKey"] CGSizeValue];
if (videoSize.height>0)
{
CGFloat videoAspectRatio = videoSize.width / videoSize.height;
CGFloat frameWidth = self.remoteVideoView.frame.size.width;
CGFloat frameHeight = frameWidth / videoAspectRatio;
}
}

but i am always getting video size zero. Is am missing anything ?
prashant06
Joined: Aug 8, 2017
Messages: 32
Offline
Any update on this please ?
Pavel_K
Joined: Dec 20, 2016
Messages: 67
Offline
Try to get video size from videoFrameResolution.


- (void)observeValueForKeyPath:(NSString *)keyPath
ofObject:(id)object
change:(NSDictionary *)change
context:(void *)context
{
CGSize videoSize = self.remoteVideoView.videoFrameResolution;
if (videoSize.height>0)
{
CGFloat videoAspectRatio = videoSize.width / videoSize.height;
CGFloat frameWidth = self.remoteVideoView.frame.size.width;
CGFloat frameHeight = frameWidth / videoAspectRatio;
}
}
prashant06
Joined: Aug 8, 2017
Messages: 32
Offline
videoFrameResolution is deprecated
CGSize videoFrameResolution __deprecated

So what should i used instead of it ? Also I am not getting any updated video frame when is used below code

- (void)observeValueForKeyPath:(NSString *)keyPath
ofObject:(id)object
change:(NSDictionary *)change
context:(void *)context
{
CSVideoRendererIOS *layer = (CSVideoRendererIOS*)self.remoteVideoView.layer;
CGSize videoSize = layer.videoFrameSize; // Or CGSize videoSize = layer.videoFrameResolution
if (videoSize.height>0)
{
CGFloat videoAspectRatio = videoSize.width / videoSize.height;
CGFloat frameWidth = self.remoteVideoView.frame.size.width;
CGFloat frameHeight = frameWidth / videoAspectRatio;
}
}

I always get videoSize zero. Please help.
prashant06
Joined: Aug 8, 2017
Messages: 32
Offline
Please any update on this.
Pavel_K
Joined: Dec 20, 2016
Messages: 67
Offline
I have contacted with WebRTC team to found solution. I will inform you when get updates.
Pavel_K
Joined: Dec 20, 2016
Messages: 67
Offline
Extend UIView in this way:

@interface VideoView : UIView
@property (readonly, nonatomic) CSVideoRendererIOS* videoSink;
@end

@implementation VideoView

+ (Class) layerClass
{
return [CSVideoRendererIOS class];
}

- (CSVideoRendererIOS*) videoSink
{
return (CSVideoRendererIOS*) self.layer;
}

@end


Second, instantiate the VideoView, listen for frame size changes using a callback block, and register as a video sink:

VideoView* videoView = [[VideoView alloc] init];


videoView.videoSink.videoFrameSizeListener = ^(CGSize videoSize)
{
CGFloat videoAspectRatio = videoSize.width / videoSize.height;
// resize the view to match the new video aspect ratio
};


id<CSVideoSource> remoteVideoSource = [videoInterface getRemoteVideoSource: channelId];
[remoteVideoSource setVideoSink: videoView.videoSink];


Third, use a routine like this to calculate the frame size; given the maximum size available from the parent view, and the video aspect ratio:

if (maxSize.width / maxSize.height > videoAspectRatio)
{
// parent is wider than the video, plan for black bars left and right
maxSize.width = roundf(maxSize.height * videoAspectRatio);
}
else
{
// parent is taller than the video, plan for black bars top and bottom
maxSize.height = roundf(maxSize.width / videoAspectRatio);
}
prashant06
Joined: Aug 8, 2017
Messages: 32
Offline
Do you mean remote video always will be shown in window (i.e with some empty top and bottom space) not in full mobile screen like other video calls.
Pavel_K
Joined: Dec 20, 2016
Messages: 67
Offline
You can stretch view by height, but you will lose left and right content.
prashant06
Joined: Aug 8, 2017
Messages: 32
Offline
When I have done changes which you told then first time everything works fine but when I cut first call and connect other call that time my local video stream not getting at Avaya one-x communicator. Can you please look it into?
Pavel_K
Joined: Dec 20, 2016
Messages: 67
Offline
Yes, please open new thread and attach logs. I will check them.
Go to:   
Mobile view