Unity-Technologies / Unity-Technologies/com.unity.webrtc

[REQUEST]: Add a public function to update the frame rendering under application control

Open
#1,018 2 comments 0 reactions 1 assignee View on GitHub

@karasusan is already working on this.

Since Feb 2, 2024.

enhancement issued
Dominant language
Assembly
Stars
852
Forks
238
PR merge metrics
No merged PRs in 30d

Description

Is your feature request related to a problem?

Actually the WebRTC.Update() function is a coroutine that is execute at each EndOfFrame. With this implementation the rate isn't under application control and depends by the application rate.
It will be useful to have the possibility to control the rate in the application itself.

Describe the solution you'd like

To add this function in WebRTC.cs file

   /// <summary>
   ///
   /// </summary>
   /// <returns></returns>
   public static IEnumerator UpdateNow()
   {
       var instruction = new WaitForEndOfFrame();

           // Wait until all frame rendering is done
           yield return instruction;
           {
               var tempTextureActive = RenderTexture.active;
               RenderTexture.active = null;

               var batch = Context.batch;
               batch.ResizeCapacity(VideoStreamTrack.s_tracks.Count);

               int trackIndex = 0;
               foreach (var reference in VideoStreamTrack.s_tracks.Values)
               {
                   if (!reference.TryGetTarget(out var track))
                       continue;

                   track.UpdateTexture();
                   if (track.DataPtr != IntPtr.Zero)
                   {
                       batch.data.tracks[trackIndex] = track.DataPtr;
                       trackIndex++;
                   }
               }

               batch.data.tracksCount = trackIndex;
               if (trackIndex > 0)
                   batch.Submit();

               RenderTexture.active = tempTextureActive;
           }
   }
Describe alternatives you've considered

As an alternative, it can be added a parameter ,to the current Update function, that indicates the frame per second required and of course change a little bit the code.

Additional context

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.