Start a new topic

Advanced Android Thread Performance

Hi,
We are trying to solve issue with overheating and battery consumption of the Argo device during videocall.


please tell me, how to use Advanced Android Thread Performance with webRtc Unity Plugin?
We are trying something like this, but there is no video (only audio works).

        public IObservable<Tuple<RoomToken, CallSession>> StartCall(CreateCallRequest createCallRequest)

        {

            CurrentCallState.Value = CallState.Connecting;

            _invitedUsersCount = createCallRequest.InvitedUsers.Count;

            Observable.Timer(TimeSpan.FromSeconds(1))

                .SelectMany(_ =>

                    Observable.Start(() =>

                    {

                        SpacesThreadUtility.SetThreadHint(SpacesThreadType.SPACES_THREAD_TYPE_RENDERER_WORKER);

                        while (true)

                        {

                            WebRTC.Update();

                            Task.Delay(33).Wait();

                        }

                    }).SubscribeOn(Scheduler.ThreadPool)

                ).Subscribe();

            InitTracks();

            return new CreateCall(createCallRequest).Execute()

                .SelectMany(call =>

                {

                    return new GetIceServers().Execute()

                        .Select(iceServers => new Tuple<IceServers, CallSession>(iceServers, call));

                })

                .SelectMany(iceServersAndCallSessionData =>

                {

                    SaveIceServers(iceServersAndCallSessionData.Item1);

                    return new GetRoomToken(iceServersAndCallSessionData.Item2.Id).Execute()

                        .Select(roomToken =>

                            new Tuple<RoomToken, CallSession>(roomToken, iceServersAndCallSessionData.Item2));

                });

        }

 

 

 

 

 

1 Comment

Hi Tomasz,


there are several scenarios to consider here:

  • As stated in the documentation " Identifying non-rendering threads as SPACES_THREAD_TYPE_RENDERER_WORKER could adversely affect the XR experience by taking priority away from rendering threads and can cause decreased FPS, increased latency, reduced stability etc. "
  • You need to make sure that your thread sleeps regularly. Just yielding is not sufficient because a thread with highest priority will yield, then automatically resume, thereby block all other threads. 
  • You are assigning the RenderWorker hint to the main thread
    • You can check if you are assinging the main thread the hint by checking your log:
      • Info Unity Configuring thread (tid: XXXXX) as SPACES_THREAD_TYPE_APPLICATION_MAIN. <-- Automatically logged for the main thread
      • Info Unity Configuring thread (tid: XXXXX) as SPACES_THREAD_TYPE_RENDERER_WORKER <-- Logged when assigining a thread hint
      • Compare the tid of those threads to check if you are assigining 
    • I'm not quite sure what sort of threading System.Observable is using or if you are doing something in the background. The thread hint must be assigned in the tread running it. Try creating threads manually, assinging those threads the RenderWorker hint.
Login to post a comment