Skip to content

Commit

Permalink
Add remainder of Video source updates
Browse files Browse the repository at this point in the history
  • Loading branch information
hamishwillee committed Mar 5, 2024
1 parent aedc312 commit c15eee3
Show file tree
Hide file tree
Showing 5 changed files with 157 additions and 16 deletions.
4 changes: 3 additions & 1 deletion files/en-us/web/api/rtcaudiosourcestats/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ browser-compat: api.RTCStatsReport.type_media-source

{{APIRef("WebRTC")}}

The **`RTCAudioSourceStats`** dictionary of the [WebRTC API](/en-US/docs/Web/API/WebRTC_API) provides statistics information about an audio track that is attached to one or more senders.
The **`RTCAudioSourceStats`** dictionary of the [WebRTC API](/en-US/docs/Web/API/WebRTC_API) provides statistics information about an audio track ({{domxref("MediaStreamTrack")}}) that is attached to one or more senders ({{domxref("RTCRtpSender")}}).

These statistics can be obtained by iterating the {{domxref("RTCStatsReport")}} returned by {{domxref("RTCRtpSender.getStats()")}} or {{domxref("RTCPeerConnection.getStats()")}} until you find a report with the [`type`](#type) of `media-source` and a [`kind`](#kind) of `audio`.

Expand All @@ -22,6 +22,8 @@ These statistics can be obtained by iterating the {{domxref("RTCStatsReport")}}
- {{domxref("RTCAudioSourceStats.totalSamplesDuration", "totalSamplesDuration")}} {{Experimental_Inline}}{{optional_inline}}
- : A number that represents the total duration of all samples produced by the media source over the lifetime of the stats object.

### Common media-source properties

The following properties are present in both `RTCAudioSourceStats` and {{domxref("RTCVideoSourceStats")}}: <!-- RTCMediaSourceStats -->

- {{domxref("RTCAudioSourceStats.trackIdentifier", "trackIdentifier")}}
Expand Down
42 changes: 42 additions & 0 deletions files/en-us/web/api/rtcvideosourcestats/frames/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---
title: "RTCVideoSourceStats: frames property"
short-title: frames
slug: Web/API/RTCVideoSourceStats/frames
page-type: web-api-instance-property
browser-compat: api.RTCStatsReport.type_media-source.frames
---

{{APIRef("WebRTC")}}

The **`frames`** property of the {{domxref("RTCVideoSourceStats")}} dictionary indicates the total number of frames sent from this video source over its lifetime.

## Value

A number indicating the total number of frames from this source.

## Examples

This example shows how you might iterate the stats object returned from `RTCRtpSender.getStats()` to get the video source stats, and then extract the `frames`.

```js
// where sender is an RTCRtpSender
const stats = await sender.getStats();
let videoSourceStats = null;

stats.forEach((report) => {
if (report.type === "media-source" && report.kind==="video") {
videoSourceStats = report;
break;
}
});

const frames = videoSourceStats.frames;
```

## Specifications

{{Specifications}}

## Browser compatibility

{{Compat}}
46 changes: 46 additions & 0 deletions files/en-us/web/api/rtcvideosourcestats/height/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
---
title: "RTCVideoSourceStats: height property"
short-title: height
slug: Web/API/RTCVideoSourceStats/height
page-type: web-api-instance-property
browser-compat: api.RTCStatsReport.type_media-source.height
---

{{APIRef("WebRTC")}}

The **`height`** property of the {{domxref("RTCVideoSourceStats")}} dictionary indicates the height, in pixels, of the last frame originating from this source.

This property is not defined on the stats object until after the first frame has been produced.

## Value

A positive number indicating the height, in pixels.

## Examples

This example shows how you might iterate the stats object returned from `RTCRtpSender.getStats()` to get the video source stats, and then extract the `height`.

```js
// where sender is an RTCRtpSender
const stats = await sender.getStats();
let videoSourceStats = null;

stats.forEach((report) => {
if (report.type === "media-source" && report.kind==="video") {
videoSourceStats = report;
break;
}
});

// Note, test is conditional because the property
// 'height' does not exist until frames are being produced.
const height = videoSourceStats?.height;
```
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
35 changes: 20 additions & 15 deletions files/en-us/web/api/rtcvideosourcestats/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,32 @@ browser-compat: api.RTCStatsReport.type_media-source

{{APIRef("WebRTC")}}

The **`RTCVideoSourceStats`** dictionary of the [WebRTC API](/en-US/docs/Web/API/WebRTC_API) provides statistics information about a video track that is attached to one or more senders.
The **`RTCVideoSourceStats`** dictionary of the [WebRTC API](/en-US/docs/Web/API/WebRTC_API) provides statistics information about a video track ({{domxref("MediaStreamTrack")}}) that is attached to one or more senders ({{domxref("RTCRtpSender")}}).

These statistics can be obtained by iterating the {{domxref("RTCStatsReport")}} returned by {{domxref("RTCRtpSender.getStats()")}} or {{domxref("RTCPeerConnection.getStats()")}} until you find a report with the [`type`](#type) of `media-source` and a [`kind`](#kind) of `video`.

> **Note:** For video information about remotely sourced tracks (that are being received), see {{domxref("RTCInboundRtpStreamStats")}}.
## Instance properties

- {{domxref("RTCVideoSourceStats.frames", "frames")}}
- : A positive number that indicates the total number of frames from this video source.
- {{domxref("RTCVideoSourceStats.framesPerSecond", "framesPerSecond")}}
- : A number that represents the number of frames from this video source in the last second.
- {{domxref("RTCVideoSourceStats.height", "height")}}
- {{domxref("RTCVideoSourceStats.frames", "frames")}} {{optional_inline}}
- : A positive number that indicates the total number of frames sent from this video source.
- {{domxref("RTCVideoSourceStats.framesPerSecond", "framesPerSecond")}} {{optional_inline}}
- : A number that represents the number of frames sent from this video source in the last second.
This property is not defined on this stats object for the first second of its existence.
- {{domxref("RTCVideoSourceStats.height", "height")}} {{optional_inline}}
- : A positive number that represents the height, in pixels, of the last frame originating from this source.
This property is not defined on the stats option until after the first frame has been produced.
- {{domxref("RTCVideoSourceStats.width", "width")}}
This property is not defined on this stats object until after the first frame has been produced.
- {{domxref("RTCVideoSourceStats.width", "width")}} {{optional_inline}}
- : A number that represents thewidth, in pixels, of the last frame originating from this source.
This property is not defined on the stats option until after the first frame has been produced.
This property is not defined on this stats object until after the first frame has been produced.

### Common media-source properties

The following properties are present in both `RTCVideoSourceStats` and {{domxref("RTCAudioSourceStats")}}: <!-- RTCMediaSourceStats -->

- {{domxref("RTCVideoSourceStats.trackIdentifier", "trackIdentifier")}}
- : A string that contains the [`id`](/en-US/docs/Web/API/MediaStreamTrack/id) value of the [`MediaStreamTrack`](/en-US/docs/Web/API/MediaStreamTrack) associated with the audio source.
- : A string that contains the [`id`](/en-US/docs/Web/API/MediaStreamTrack/id) value of the [`MediaStreamTrack`](/en-US/docs/Web/API/MediaStreamTrack) associated with the video source.
- {{domxref("RTCVideoSourceStats.kind", "kind")}}
- : A string indicating the kind of media source. For an `RTCVideoSourceStats` this will always be `video`.

Expand All @@ -46,12 +49,12 @@ The following properties are common to all statistics objects. <!-- RTCStats -->

## Description

The interface provides statistics about an audio media source attached to one or more senders.
The information includes Xxxxx.
The interface provides statistics about a video media source attached to one or more senders.
The information includes a identifier for the associated `MediaStreamTrack`, along with the height and width of the last frame sent from the source, the number of frames sent from the source, and the frame rate.

## Examples

This example shows how you might iterate the stats object returned from `RTCRtpSender.getStats()` to get the video source stats, and then extract the `framesPerSecond`.
This example shows how you might iterate the stats object returned from `RTCRtpSender.getStats()` to get the video-specific media-source stats.

```js
// where sender is an RTCRtpSender
Expand All @@ -65,9 +68,11 @@ stats.forEach((report) => {
}
});

// Note, test is conditional.
// framesPerSecond does not exist in the first second
// framesPerSecond, width, height, may initially be defined on the stats object
const frames = videoSourceStats.frames;
const fps = videoSourceStats?.framesPerSecond;
const width = videoSourceStats?.width;
const height = videoSourceStats?.height;
```
## Specifications
Expand Down
46 changes: 46 additions & 0 deletions files/en-us/web/api/rtcvideosourcestats/width/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
---
title: "RTCVideoSourceStats: width property"
short-title: width
slug: Web/API/RTCVideoSourceStats/width
page-type: web-api-instance-property
browser-compat: api.RTCStatsReport.type_media-source.width
---

{{APIRef("WebRTC")}}

The **`width`** property of the {{domxref("RTCVideoSourceStats")}} dictionary indicates the width, in pixels, of the last frame originating from this source.

This property is not defined on the stats object until after the first frame has been produced.

## Value

A positive number indicating the width, in pixels.

## Examples

This example shows how you might iterate the stats object returned from `RTCRtpSender.getStats()` to get the video source stats, and then extract the `width`.

```js
// where sender is an RTCRtpSender
const stats = await sender.getStats();
let videoSourceStats = null;

stats.forEach((report) => {
if (report.type === "media-source" && report.kind==="video") {
videoSourceStats = report;
break;
}
});

// Note, test is conditional because the property
// 'width' does not exist until frames are being produced.
const height = videoSourceStats?.width;
```
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}

0 comments on commit c15eee3

Please sign in to comment.