Skip to content

Commit d0059ad

Browse files
doc: improve the API doc of CameraExtension (#1073)
* add documentation * add class summary * simplify code * update example
1 parent 789f720 commit d0059ad

File tree

1 file changed

+53
-19
lines changed

1 file changed

+53
-19
lines changed

Runtime/Scripts/CameraExtension.cs

Lines changed: 53 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,46 @@
11
using System;
2-
using System.Collections.Concurrent;
32
using System.ComponentModel;
4-
using System.Runtime.InteropServices;
53
using UnityEngine;
6-
using UnityEngine.Experimental.Rendering;
74

85
namespace Unity.WebRTC
96
{
7+
/// <summary>
8+
/// Provides extension methods for <see cref="Camera"/> objects to facilitate video streaming functionalities.
9+
/// </summary>
1010
public static class CameraExtension
1111
{
1212
/// <summary>
13-
/// Create an instance of <see cref="VideoStreamTrack"/> to stream a camera.
13+
/// Creates an instance of <see cref="VideoStreamTrack"/> for streaming video from a <see cref="Camera"/> object.
1414
/// </summary>
1515
/// <remarks>
16-
/// You should keep a reference of <see cref="VideoStreamTrack"/>, created by this method.
17-
/// This instance is collected by GC automatically if you don't own a reference.
16+
/// It is recommended to maintain a reference to the <see cref="VideoStreamTrack"/> instance created by this method.
17+
/// Without a reference, the instance may be collected by the garbage collector automatically.
1818
/// </remarks>
19-
/// <param name="cam"></param>
20-
/// <param name="width"></param>
21-
/// <param name="height"></param>
22-
/// <param name="depth"></param>
23-
/// <returns></returns>
19+
/// <param name="cam">The camera from which to capture video frames</param>
20+
/// <param name="width">The desired width of the video stream, in pixels. Must be greater than zero</param>
21+
/// <param name="height">The desired height of the video stream, in pixels. Must be greater than zero</param>
22+
/// <param name="depth">The depth buffer format for the render texture. Default is <see cref="RenderTextureDepth.Depth24"/></param>
23+
/// <param name="textureCopy">An optional <see cref="CopyTexture"/> to facilitate texture copying. Default is null</param>
24+
/// <returns>A <see cref="VideoStreamTrack"/> instance that can be used to stream video.</returns>
25+
/// <example>
26+
/// Creates a GameObject with a Camera component and a VideoStreamTrack capturing video from the camera.
27+
/// <code lang="cs"><![CDATA[
28+
/// private void AddVideoObject()
29+
/// {
30+
/// Camera newCam = new GameObject("Camera").AddComponent<Camera>();
31+
/// RawImage newSource = new GameObject("SourceImage").AddComponent<RawImage>();
32+
/// try
33+
/// {
34+
/// videoStreamTrackList.Add(newCam.CaptureStreamTrack(WebRTCSettings.StreamSize.x, WebRTCSettings.StreamSize.y));
35+
/// newSource.texture = newCam.targetTexture;
36+
/// }
37+
/// catch (Exception e)
38+
/// {
39+
/// Debug.LogError(e.Message);
40+
/// }
41+
/// }
42+
/// ]]></code>
43+
/// </example>
2444
public static VideoStreamTrack CaptureStreamTrack(this Camera cam, int width, int height,
2545
RenderTextureDepth depth = RenderTextureDepth.Depth24, CopyTexture textureCopy = null)
2646
{
@@ -48,15 +68,29 @@ public static VideoStreamTrack CaptureStreamTrack(this Camera cam, int width, in
4868
}
4969

5070
/// <summary>
51-
///
71+
/// Creates an instance of <see cref="MediaStream"/> capturing video from a <see cref="Camera"/> object.
5272
/// </summary>
53-
/// <param name="cam"></param>
54-
/// <param name="width"></param>
55-
/// <param name="height"></param>
56-
/// <param name="depth"></param>
57-
/// <returns></returns>
58-
public static MediaStream CaptureStream(this Camera cam, int width, int height,
59-
RenderTextureDepth depth = RenderTextureDepth.Depth24)
73+
/// <remarks>
74+
/// It is recommended to maintain a reference to the <see cref="MediaStream"/> instance created by this method.
75+
/// Without a reference, the instance may be collected by the garbage collector automatically.
76+
/// </remarks>
77+
/// <param name="cam">The camera from which to capture video frames</param>
78+
/// <param name="width">The desired width of the video stream, in pixels. Must be greater than zero</param>
79+
/// <param name="height">The desired height of the video stream, in pixels. Must be greater than zero</param>
80+
/// <param name="depth">The depth buffer format for the render texture. Default is <see cref="RenderTextureDepth.Depth24"/></param>
81+
/// <returns>A <see cref="MediaStream"/> containing the video track captured from the camera.</returns>
82+
/// <example>
83+
/// Creates a MediaStream with a VideoStreamTrack capturing video from the camera.
84+
/// <code lang="cs"><![CDATA[
85+
/// private static MediaStream CreateMediaStream()
86+
/// {
87+
/// MediaStream videoStream = Camera.main.CaptureStream(1280, 720);
88+
/// return videoStream;
89+
/// }
90+
/// ]]></code>
91+
/// </example>
92+
93+
public static MediaStream CaptureStream(this Camera cam, int width, int height, RenderTextureDepth depth = RenderTextureDepth.Depth24)
6094
{
6195
var stream = new MediaStream();
6296
var track = cam.CaptureStreamTrack(width, height, depth);

0 commit comments

Comments
 (0)