com.unity.webrtc
com.unity.webrtc copied to clipboard
[REQUEST]: Add a public function to update the frame rendering under application control
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
It'd be a great feature! Right now I have to hack into plugin source to be able to control the frame rate of the outgoing stream.
memo: WRS-411