Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update WebRTC media source stats #32538

Merged
merged 15 commits into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ browser-compat: api.RTCStatsReport.type_media-source.audioLevel

{{APIRef("WebRTC")}}{{SeeCompatTable}}

The {{domxref("RTCAudioSourceStats")}} dictionary's **`audioLevel`** property represents the audio level of the media source.
The **`audioLevel`** property of the {{domxref("RTCAudioSourceStats")}} dictionary represents the audio level of the media source.

The level is averaged over some small implementation-dependent interval.
Users can alternatively calculate the average audio level over some arbitrary duration using the algorithm described in the [`RTCAudioSourceStats` description](/en-US/docs/Web/API/RTCAudioSourceStats#description).
Expand Down
11 changes: 7 additions & 4 deletions files/en-us/web/api/rtcaudiosourcestats/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,28 @@ title: RTCAudioSourceStats
slug: Web/API/RTCAudioSourceStats
page-type: web-api-interface
browser-compat: api.RTCStatsReport.type_media-source
spec-urls: https://w3c.github.io/webrtc-stats/#dom-rtcaudiosourcestats
---

{{APIRef("WebRTC")}}

The [WebRTC API](/en-US/docs/Web/API/WebRTC_API)'s **`RTCAudioSourceStats`** dictionary provides 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")}}).
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't comment on the line, but the spec URL is wrong for this, it is https://w3c.github.io/webrtc-stats/#dom-rtcstatstype-media-source but should be something like https://w3c.github.io/webrtc-stats/#dom-rtcaudiosourcestats.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was because the media-source "type" is shared by both audio and video objects, and this is how the items are sorted in BCD. I added a spec-urls frontmatter for video and audio to fix this.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you also need that for the individual members? And this looks like a systemic issue, e.g. https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnectionStats#specifications

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wbamberg Whlle it is "systemic" I am fairly sure we don't need to panic about this.

Taking RTCPeerConnectionStats as an example, this links to https://w3c.github.io/webrtc-stats/#dom-rtcstatstype-peer-connection. This is the top level enum description for the type, which is used for searching. BUT, since all types except media-source map 1:1 with a stats object, the text usefully explains a particular stats object and links direct to the object itself.
I don't think that needs to be fixed. But if you do, we could fix in the same way (I'd prefer not to mess with BCD because I think it would be harder).

The individual members should be fine.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I agree that setting spec-url is easier. I think it is wrong to link to the enum type but don't care much, since we don't AFAIK have particularly precise policies for what to link to in spec URLs.


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`.

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

## Instance properties

- {{domxref("RTCAudioSourceStats.audioLevel", "audioLevel")}} {{Experimental_Inline}}
- {{domxref("RTCAudioSourceStats.audioLevel", "audioLevel")}} {{Experimental_Inline}}{{optional_inline}}
Copy link
Collaborator Author

@hamishwillee hamishwillee Mar 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ones that are not marked required in the IDL have been marked as optional.

- : A number that represents the audio level of the media source.
- {{domxref("RTCAudioSourceStats.totalAudioEnergy", "totalAudioEnergy")}} {{Experimental_Inline}}
- {{domxref("RTCAudioSourceStats.totalAudioEnergy", "totalAudioEnergy")}} {{Experimental_Inline}}{{optional_inline}}
- : A number that represents the total audio energy of the media source over the lifetime of the stats object.
- {{domxref("RTCAudioSourceStats.totalSamplesDuration", "totalSamplesDuration")}} {{Experimental_Inline}}
- {{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
4 changes: 2 additions & 2 deletions files/en-us/web/api/rtcaudiosourcestats/kind/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ browser-compat: api.RTCStatsReport.type_media-source.kind

{{APIRef("WebRTC")}}

The {{domxref("RTCAudioSourceStats")}} dictionary's **`kind`** property is a string value that is used to differentiate `audio` and `video` media sources.
The **`kind`** property of the {{domxref("RTCAudioSourceStats")}} dictionary is a string with the value `audio`.

Along with the {{domxref("RTCAudioSourceStats.type", "type")}}, this identifies the object as an {{domxref("RTCAudioSourceStats")}} object when iterating the {{domxref("RTCStatsReport")}} returned by {{domxref("RTCRtpSender.getStats()")}} or {{domxref("RTCPeerConnection.getStats()")}}.
The `kind` is used to differentiate between audio and video media sources when iterating an {{domxref("RTCStatsReport")}}, which both have a {{domxref("RTCAudioSourceStats.type", "type")}} of `media-source` (a `kind` of `video` indicates an {{domxref("RTCVideoSourceStats")}} object).

## Value

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ browser-compat: api.RTCStatsReport.type_media-source.totalAudioEnergy

{{APIRef("WebRTC")}}{{SeeCompatTable}}

The {{domxref("RTCAudioSourceStats")}} dictionary's **`totalAudioEnergy`** property represents the total audio energy of the media source over the lifetime of this stats object.
The **`totalAudioEnergy`** property of the {{domxref("RTCAudioSourceStats")}} dictionary represents the total audio energy of the media source over the lifetime of this stats object.

The total energy across a particular duration can be determined by subtracting the value of this property returned by two different `getStats()` calls.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ browser-compat: api.RTCStatsReport.type_media-source.totalSamplesDuration

{{APIRef("WebRTC")}}{{SeeCompatTable}}

The {{domxref("RTCAudioSourceStats")}} dictionary's **`totalSamplesDuration`** property represents the combined duration of all samples produced by the media source over the lifetime of this stats object, in seconds.
The **`totalSamplesDuration`** property of the {{domxref("RTCAudioSourceStats")}} dictionary represents the combined duration of all samples produced by the media source over the lifetime of this stats object, in seconds.
It does not include samples dropped before reaching this media source. <!-- Dropped samples in `droppedSamplesDuration`; not implemented -->

This can be used with {{domxref("RTCAudioSourceStats.totalAudioEnergy", "totalAudioEnergy")}} to compute an [average audio level over different intervals](/en-US/docs/Web/API/RTCAudioSourceStats#description).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ browser-compat: api.RTCStatsReport.type_media-source.trackIdentifier

{{APIRef("WebRTC")}}

The {{domxref("RTCAudioSourceStats")}} dictionary's property **`trackIdentifier`** contains the `id` attribute of the associated [`MediaStreamTrack`](/en-US/docs/Web/API/MediaStreamTrack).
The **`trackIdentifier`** property of the {{domxref("RTCAudioSourceStats")}} dictionary contains the `id` attribute of the associated [`MediaStreamTrack`](/en-US/docs/Web/API/MediaStreamTrack).

## Value

Expand Down
2 changes: 1 addition & 1 deletion files/en-us/web/api/rtcaudiosourcestats/type/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ browser-compat: api.RTCStatsReport.type_media-source.type

{{APIRef("WebRTC")}}

The {{domxref("RTCAudioSourceStats")}} dictionary's property **`type`** is a string with value `media-source`.
The **`type`** property of the {{domxref("RTCAudioSourceStats")}} dictionary is a string with value `media-source`.

The type of `media-source` identifies the type of statistics as either {{domxref("RTCAudioSourceStats")}} or {{domxref("RTCVideoSourceStats")}} when iterating the {{domxref("RTCStatsReport")}} returned by {{domxref("RTCRtpSender.getStats()")}} or {{domxref("RTCPeerConnection.getStats()")}}.
The type of stats can further be differentiated using the {{domxref("RTCAudioSourceStats.kind", "kind")}}, which will be `audio` for `RTCAudioSourceStats`.
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 originating from this video source over its lifetime.

## Value

A number indicating the total number of frames originating 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}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
---
title: "RTCVideoSourceStats: framesPerSecond property"
short-title: framesPerSecond
slug: Web/API/RTCVideoSourceStats/framesPerSecond
page-type: web-api-instance-property
browser-compat: api.RTCStatsReport.type_media-source.framesPerSecond
---

{{APIRef("WebRTC")}}

The **`framesPerSecond`** property of the {{domxref("RTCVideoSourceStats")}} dictionary indicates the number of frames originating from this video source in the last second.

The property is not defined on the stats object for the first second of its lifetime.

## Value

A number indicating the frames originating from this source in the last second.

## 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`.

```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 in case the stats object
// does not include video source stats
const fps = videoSourceStats?.framesPerSecond;
```

## 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 in case the stats object
// does not include video source stats
const height = videoSourceStats?.height;
```

## Specifications

{{Specifications}}

## Browser compatibility

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

{{APIRef("WebRTC")}}

The **`id`** property of the {{domxref("RTCVideoSourceStats")}} dictionary is a string which uniquely identifies the object for which this object provides statistics.

Using the `id`, you can correlate this statistics object with others, in order to monitor statistics over time for a given WebRTC object, such as an {{domxref("RTCPeerConnection")}}, or an {{domxref("RTCDataChannel")}}.

## Value

A string that uniquely identifies the object for which this `RTCVideoSourceStats` object provides statistics.

The format of the ID string is not defined by the specification, so you cannot reliably make any assumptions about the contents of the string, or assume that the format of the string will remain unchanged for a given object type.

## Specifications

{{Specifications}}

## Browser compatibility

{{Compat}}
85 changes: 85 additions & 0 deletions files/en-us/web/api/rtcvideosourcestats/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
---
title: RTCVideoSourceStats
slug: Web/API/RTCVideoSourceStats
page-type: web-api-interface
browser-compat: api.RTCStatsReport.type_media-source
spec-urls: https://w3c.github.io/webrtc-stats/#dom-rtcvideosourcestats
---

{{APIRef("WebRTC")}}

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")}} {{optional_inline}}
- : A positive number that indicates the total number of frames originating from this video source.
- {{domxref("RTCVideoSourceStats.framesPerSecond", "framesPerSecond")}} {{optional_inline}}
- : A positive number that represents the number of frames originating 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 number that represents the height, in pixels, of the last frame originating from this source.
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 the width, in pixels, of the most recent frame originating from this source.
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 video source.
- {{domxref("RTCVideoSourceStats.kind", "kind")}}
- : A string indicating whether this object represents stats for a video source or a media source. For an `RTCVideoSourceStats` this will always be `video`.

### Common instance properties

The following properties are common to all statistics objects. <!-- RTCStats -->

- {{domxref("RTCVideoSourceStats.id", "id")}}
- : A string that uniquely identifies the object that is being monitored to produce this set of statistics.
- {{domxref("RTCVideoSourceStats.timestamp", "timestamp")}}
- : A {{domxref("DOMHighResTimeStamp")}} object indicating the time at which the sample was taken for this statistics object.
- {{domxref("RTCVideoSourceStats.type", "type")}}
- : A string with the value `"media-source"`, indicating that the object is an instance of either {{domxref("RTCVideoSourceStats")}} or {{domxref("RTCVideoSourceStats")}}.

## Description

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-specific media-source stats.

```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;
}
});

// 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;
hamishwillee marked this conversation as resolved.
Show resolved Hide resolved
```

## Specifications

{{Specifications}}

## Browser compatibility

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

{{APIRef("WebRTC")}}

The **`kind`** property of the {{domxref("RTCVideoSourceStats")}} dictionary is a string with the value `video`.

The `kind` is used to differentiate between audio and video media sources when iterating an {{domxref("RTCStatsReport")}}, which both have a {{domxref("RTCVideoSourceStats.type", "type")}} of `media-source` (a `kind` of `audio` indicates an {{domxref("RTCAudioSourceStats")}} object).

## Value

A string with the value `video`.

## Specifications

{{Specifications}}

## Browser compatibility

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

{{APIRef("WebRTC")}}

The **`timestamp`** property of the {{domxref("RTCVideoSourceStats")}} dictionary is a {{domxref("DOMHighResTimeStamp")}} object specifying the time at which the data in the object was sampled.

The time is given in milliseconds elapsed since the first moment of January 1, 1970, UTC (also known as [Unix time](/en-US/docs/Glossary/Unix_time)).

## Value

A {{domxref("DOMHighResTimeStamp")}} value indicating the time at which the activity described by the statistics in this object was recorded, in milliseconds elapsed since the beginning of January 1, 1970, UTC.

The value should be accurate to within a few milliseconds but may not be entirely precise, either because of hardware or operating system limitations or because of [fingerprinting](/en-US/docs/Glossary/Fingerprinting) protection in the form of reduced clock precision or accuracy.

## Specifications

{{Specifications}}

## Browser compatibility

{{Compat}}
Loading
Loading