|
1 | 1 | using System; |
2 | | -using System.Collections.Concurrent; |
3 | 2 | using System.ComponentModel; |
4 | | -using System.Runtime.InteropServices; |
5 | 3 | using UnityEngine; |
6 | | -using UnityEngine.Experimental.Rendering; |
7 | 4 |
|
8 | 5 | namespace Unity.WebRTC |
9 | 6 | { |
| 7 | + /// <summary> |
| 8 | + /// Provides extension methods for <see cref="Camera"/> objects to facilitate video streaming functionalities. |
| 9 | + /// </summary> |
10 | 10 | public static class CameraExtension |
11 | 11 | { |
12 | 12 | /// <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. |
14 | 14 | /// </summary> |
15 | 15 | /// <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. |
18 | 18 | /// </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> |
24 | 44 | public static VideoStreamTrack CaptureStreamTrack(this Camera cam, int width, int height, |
25 | 45 | RenderTextureDepth depth = RenderTextureDepth.Depth24, CopyTexture textureCopy = null) |
26 | 46 | { |
@@ -48,15 +68,29 @@ public static VideoStreamTrack CaptureStreamTrack(this Camera cam, int width, in |
48 | 68 | } |
49 | 69 |
|
50 | 70 | /// <summary> |
51 | | - /// |
| 71 | + /// Creates an instance of <see cref="MediaStream"/> capturing video from a <see cref="Camera"/> object. |
52 | 72 | /// </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) |
60 | 94 | { |
61 | 95 | var stream = new MediaStream(); |
62 | 96 | var track = cam.CaptureStreamTrack(width, height, depth); |
|
0 commit comments