Skip to content

Commit f897869

Browse files
Updating video send constriants doc
1 parent 713cd26 commit f897869

File tree

1 file changed

+78
-21
lines changed

1 file changed

+78
-21
lines changed

articles/communication-services/quickstarts/voice-video-calling/includes/video-constraints/video-constraints-javascript.md

Lines changed: 78 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,32 @@ ms.service: azure-communication-services
1111
ms.subservice: calling
1212
---
1313

14-
The Video Constraints API enables developers to control the video quality from within their video calls. In this quickstart guide, we'll illustrate how to use the API to set the constraints.
14+
You can set video constraints in your calls to control the video quality based on resolution or frameRate or bitrate in your video calls. In this quickstart guide, we'll illustrate how to set video constraints at the start of a call and how to use our `setConstraints` method on the call object to set video constraints dynamically during the call.
1515

1616

1717
[!INCLUDE [Public Preview](../../../../includes/public-preview-include-document.md)]
1818

19-
## Using video constraints
20-
The video constraints setting is implemented on the `Call` interface. To use the Video Constraints, you can specify the constraints from within CallOptions when you make a call, accept a call, or join a call. You will also have to specify `localVideoStreams` in `videoOptions`. Do note that constraints don't work if you join a call with audio only option and turn on the camera later.
19+
> [!NOTE]
20+
> Currently, we only support setting video send constraints. You cannot set video constraints on incoming videos at this point of time.
21+
22+
## Setting video constraints at the start of a call
23+
The video constraints setting is implemented on the `Call` interface. To use the Video Constraints, you can specify the constraints from within `CallOptions` when you make a call, accept a call, or join a call. You will also have to specify `localVideoStreams` in `videoOptions`. <br/>
24+
Do note that constraints don't work if you join a call with audio only option and turn on the camera later. In this case, you can set video constraints dynamically using the `setConstraints` method on the `Call` interface (guide below).
2125

2226
```javascript
2327
const callOptions = {
2428
videoOptions: {
2529
localVideoStreams: [...],
2630
constraints: {
2731
send: {
28-
height: {
32+
bitrate: {
33+
max: 575000
34+
},
35+
frameHeight: {
2936
max: 240
37+
},
38+
frameRate: {
39+
max: 20
3040
}
3141
}
3242
}
@@ -50,42 +60,89 @@ export declare interface VideoOptions {
5060
//video constraint when call starts
5161
constraints?: VideoConstraints;
5262
};
63+
5364
export declare type VideoConstraints = {
5465
send?: VideoSendConstraints;
5566
};
56-
export declare type VideoSendConstraints = {
57-
height?: MediaConstraintRange;
67+
68+
export type VideoSendConstraints = {
69+
/**
70+
* Resolution constraint
71+
*/
72+
frameHeight?: MediaConstraintRange;
73+
74+
/**
75+
* FrameRate constraint
76+
*/
77+
frameRate?: MediaConstraintRange;
78+
79+
/**
80+
* Bitrate constriant
81+
*/
82+
bitrate?: MediaConstraintRange;
5883
};
84+
5985
export declare type MediaConstraintRange = {
6086
max?: number;
6187
};
6288
```
6389

64-
### Sender max video resolution constraint
90+
When setting video constraints, the SDK will choose the nearest value that falls within the constraint set (to prevent the values for resolution, frameRate and bitrate to not exceed the maximum constraint values set). Also, when the resolution constraint value is too small, the SDK will choose the smallest available resolution. In this case, the height of chosen resolution can be larger than the constraint value.
6591

66-
With sender max video resolution constraint, you can limit the max video resolution of the sending stream. The value you have to provide for this constraint is `height`.
92+
> [!NOTE]
93+
> For all `bitrate`, `frameHeight` and `frameRate`, the constraint value is a `max` constraint, which means the actual value in the call can be the specified value or smaller.
94+
> There is no gurantee that the sent video resolution will remain at the specified resolution.
95+
96+
The `frameHeight` in `VideoSendConstraints` has a different meaning when a mobile device is in portrait mode. In portrait mode, this value indicates the shorter side of the device. For example, specifying `frameHeight.max` value with 240 on a 1080(W) x 1920(H) device in portrait mode, the constraint height is on the 1080(W) side. When the same device is in landscape mode (1920(W) x 1080(H)), the constraint is on the 1080(H) side.
97+
98+
If you use MediaStats API to track the sent video resolution, you may find out that the sent resolution can change during the call. It can go up and down, but should be equal or smaller than the constraint value you provide. This resolution change is an expected behavior. The browser also has some degradation rule to adjust sent resolution based on cpu or network conditions.
6799

100+
## Setting video constraints during the call
101+
You can set video constraints during the call by using the `setConstraints` method on the `Call` object.
68102
```javascript
69-
{
70-
localVideoStreams: [...],
71-
constraints: {
103+
// For eg, when you've started a call,
104+
const currentCall = this.callAgent.startCall(identitiesToCall, callOptions);
105+
106+
// To set constraints during the call,
107+
await currentCall.setConstraints({
108+
video: {
72109
send: {
73-
height: {
74-
max: 240
110+
frameHeight: {
111+
max: 360
112+
},
113+
frameRate: {
114+
max: 15
75115
}
76116
}
77117
}
78-
}
79-
```
80-
When setting the maximum resolution video constraints, the SDK will choose the nearest resolution that falls within the constraint set (to prevent the resolution height doesn't exceed the maximum constraint value allowed). Also, when the resolution constraint value is too small, the SDK will choose the smallest available resolution. In this case, the height of chosen resolution can be larger than the constraint value.
118+
});
81119

82-
> [!NOTE]
83-
> The resolution constraint is a `max` constraint, which means the possible resolutions can be the specified resolution or smaller.
84-
> There is no gurantee that the sent video resolution will remain at the specified resolution.
120+
// To set only a particular constraint (the others will stay as what they were set before, if they were set)
121+
await currentCall.setConstraints({
122+
video: {
123+
send: {
124+
bitrate: {
125+
max: 400000
126+
}
127+
}
128+
}
129+
});
85130

86-
The `height` in `VideoSendConstraints` has a different meaning when a mobile device is in portrait mode. In portrait mode, this value indicates the shorter side of the device. For example, specifying `constraints.send.height.max` value with 240 on a 1080(W) x 1920(H) device in portrait mode, the constraint height is on the 1080(W) side. When the same device is in landscape mode (1920(W) x 1080(H)), the constraint is on the 1080(H) side.
131+
// To unset any constraint,
132+
await currentCall.setConstraints({
133+
video: {
134+
send: {
135+
frameHeight: {
136+
max: 0
137+
}
138+
}
139+
}
140+
});
141+
```
142+
> [!NOTE]
143+
> Setting constraint value as `0` will unset any previously set constraints. You can use this way to reset or remove constraints.
87144
88-
If you use MediaStats API to track the sent video resolution, you may find out that the sent resolution can change during the call. It can go up and down, but should be equal or smaller than the constraint value you provide. This resolution change is an expected behavior. The browser also has some degradation rule to adjust sent resolution based on cpu or network conditions.
145+
<br/>
89146

90147
### Media stats
91148
To evaluate and compare the video quality after applying the video constraints, you can access [MediaStats API](../../../../concepts/voice-video-calling/media-quality-sdk.md) to get video resolution and bitrate information of the sending stream. The media stats also include other granular stats related to the streams, such as jitter, packet loss, round trip time, etc.

0 commit comments

Comments
 (0)