MediaSourceGraphView.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. using UnityEngine.UIElements;
  2. namespace Unity.WebRTC.Editor
  3. {
  4. internal class MediaSourceGraphView
  5. {
  6. //Video
  7. private GraphView widthGraph = new GraphView("width");
  8. private GraphView heightGraph = new GraphView("height");
  9. private GraphView framesGraph = new GraphView("frames");
  10. private GraphView framesPerSecondGraph = new GraphView("framesPerSecond");
  11. //Audio
  12. private GraphView audioLevelGraph = new GraphView("audioLevel");
  13. private GraphView totalAudioEnergyGraph = new GraphView("totalAudioEnergy");
  14. private GraphView totalSamplesDurationGraph = new GraphView("totalSamplesDuration");
  15. public void AddInput(RTCVideoSourceStats input)
  16. {
  17. var timestamp = input.UtcTimeStamp;
  18. widthGraph.AddInput(timestamp, input.width);
  19. heightGraph.AddInput(timestamp, input.height);
  20. framesGraph.AddInput(timestamp, input.frames);
  21. framesPerSecondGraph.AddInput(timestamp, (float)input.framesPerSecond);
  22. }
  23. public void AddInput(RTCAudioSourceStats input)
  24. {
  25. var timestamp = input.UtcTimeStamp;
  26. audioLevelGraph.AddInput(timestamp, (float)input.audioLevel);
  27. totalAudioEnergyGraph.AddInput(timestamp, (float)input.totalAudioEnergy);
  28. totalSamplesDurationGraph.AddInput(timestamp, (float)input.totalSamplesDuration);
  29. }
  30. public VisualElement Create()
  31. {
  32. var container = new VisualElement {style = {flexDirection = FlexDirection.Row, flexWrap = Wrap.Wrap}};
  33. container.Add(widthGraph.Create());
  34. container.Add(heightGraph.Create());
  35. container.Add(framesGraph.Create());
  36. container.Add(framesPerSecondGraph.Create());
  37. container.Add(audioLevelGraph.Create());
  38. container.Add(totalAudioEnergyGraph.Create());
  39. container.Add(totalSamplesDurationGraph.Create());
  40. return container;
  41. }
  42. }
  43. }