diff --git a/files/en-us/web/api/rtcaudiosourcestats/index.md b/files/en-us/web/api/rtcaudiosourcestats/index.md index 83a211999c58e73..9e893e27a5c76a8 100644 --- a/files/en-us/web/api/rtcaudiosourcestats/index.md +++ b/files/en-us/web/api/rtcaudiosourcestats/index.md @@ -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`. @@ -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")}}: - {{domxref("RTCAudioSourceStats.trackIdentifier", "trackIdentifier")}} diff --git a/files/en-us/web/api/rtcvideosourcestats/frames/index.md b/files/en-us/web/api/rtcvideosourcestats/frames/index.md new file mode 100644 index 000000000000000..2f037226649812e --- /dev/null +++ b/files/en-us/web/api/rtcvideosourcestats/frames/index.md @@ -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}} diff --git a/files/en-us/web/api/rtcvideosourcestats/height/index.md b/files/en-us/web/api/rtcvideosourcestats/height/index.md new file mode 100644 index 000000000000000..86469752ec31f80 --- /dev/null +++ b/files/en-us/web/api/rtcvideosourcestats/height/index.md @@ -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}} diff --git a/files/en-us/web/api/rtcvideosourcestats/index.md b/files/en-us/web/api/rtcvideosourcestats/index.md index 844c0325f4e7088..0bb20c2fb0dc341 100644 --- a/files/en-us/web/api/rtcvideosourcestats/index.md +++ b/files/en-us/web/api/rtcvideosourcestats/index.md @@ -7,7 +7,7 @@ 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`. @@ -15,21 +15,24 @@ These statistics can be obtained by iterating the {{domxref("RTCStatsReport")}} ## 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")}}: - {{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`. @@ -46,12 +49,12 @@ The following properties are common to all statistics objects. ## 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 @@ -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 diff --git a/files/en-us/web/api/rtcvideosourcestats/width/index.md b/files/en-us/web/api/rtcvideosourcestats/width/index.md new file mode 100644 index 000000000000000..f647e4f74cd2f4f --- /dev/null +++ b/files/en-us/web/api/rtcvideosourcestats/width/index.md @@ -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}}