Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion External/UnityLogcatServer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,9 @@ Stream header, once, 20 bytes:
u32 flags bit 0: the server can inject input
u32 serverPid this process on the device, so the Editor can name it

Frame, repeated, 28 byte header + payload:
Frame, repeated, 40 byte header + payload:
u64 ptsUs microseconds since the first frame
u64 realtimeUs wall clock at capture, microseconds since the epoch
u32 width pixels of the streamed image
u32 height pixels of the streamed image
u32 displayWidth pixels of the display it was captured from
Expand Down
2 changes: 1 addition & 1 deletion External/UnityLogcatServer/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Version of the wire protocol spoken between the Editor and the on-device server.
# The Editor refuses to talk to a server whose protocol version it does not know,
# so bump this whenever the packet layout in Protocol.java changes.
serverProtocolVersion=2
serverProtocolVersion=3

# Android platform the server is compiled against (android.jar is taken from
# $SDK/platforms/android-<androidPlatform>/android.jar).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@
* u32 flags FLAG_CONTROL_SUPPORTED if touch can be injected
* u32 serverPid this process on the device, so the Editor can name it
*
* Frame, repeated, 32 byte header + payload:
* Frame, repeated, 40 byte header + payload:
* u64 ptsUs microseconds since the first frame
* u64 realtimeUs wall clock at capture, microseconds since the epoch
* u32 width pixels of the streamed image
* u32 height pixels of the streamed image
* u32 displayWidth pixels of the display it was captured from
Expand Down Expand Up @@ -70,6 +71,9 @@ public void writeFrame(long captureNs, int width, int height, int displayWidth,
firstFrameNs = captureNs;
}
out.writeLong((captureNs - firstFrameNs) / 1000L);
// The clock logcat stamps messages with, so the Editor can place them among
// the frames. Taken back by the frame's age, as it was captured a moment ago.
out.writeLong(System.currentTimeMillis() * 1000L - (System.nanoTime() - captureNs) / 1000L);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1

At 1 FPS, a log emitted during the throttle wait can be attached to an image captured before that log. ScreenStreamer.onImageAvailable acquires the image before sleeping, then passes a fresh System.nanoTime() as captureNs after sleeping. writeFrame therefore stamps the image with the end of the wait rather than its capture time. PlaceLogs can assign messages emitted during that wait to the earlier image. Derive both frame timestamps from the image's capture time. Keep throttling timestamps separate.

🤖 Helpful? 👍/👎

out.writeInt(width);
out.writeInt(height);
out.writeInt(displayWidth);
Expand Down
77 changes: 73 additions & 4 deletions TestProjects/SampleProject1/Assets/DebugMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,90 @@

public class DebugMethods : MonoBehaviour
{
const int kMaxTypedLength = 200;

// What was typed, as Input.inputString reports it: backspace removes the last
// character and Enter starts a new line.
string m_Typed = string.Empty;
GUIStyle m_TypedStyle;
// Updated every frame, so the screen shows the time whatever the tick is doing.
float m_Time;

// Start is called before the first frame update
void Start()
{
StartCoroutine("runner");
TestDebug();
StartCoroutine(Tick());
}

IEnumerator runner()
// A steady message to line up against a recording's frames.
IEnumerator Tick()
{
var wait = new WaitForSeconds(3);
while (true)
{
TestDebug();
yield return new WaitForSeconds(2);
Debug.LogFormat(LogType.Log, LogOption.NoStacktrace, null, "Tick: {0:0.00}", Time.time);
yield return wait;
}
}

void Update()
{
m_Time = Time.time;

var input = Input.inputString;
if (string.IsNullOrEmpty(input))
return;

foreach (var c in input)
{
if (c == '\b')
{
if (m_Typed.Length > 0)
m_Typed = m_Typed.Substring(0, m_Typed.Length - 1);
}
else if (c == '\n' || c == '\r')
{
m_Typed += '\n';
}
else
{
m_Typed += c;
}
}

if (m_Typed.Length > kMaxTypedLength)
m_Typed = m_Typed.Substring(m_Typed.Length - kMaxTypedLength);

// Logged too, so typing shows up in logcat.
Debug.LogFormat(LogType.Log, LogOption.NoStacktrace, null, "Typed: '{0}'", Escape(input));
}

void OnGUI()
{
if (m_TypedStyle == null)
{
m_TypedStyle = new GUIStyle(GUI.skin.label)
{
fontSize = Mathf.Max(24, Screen.height / 30),
wordWrap = true
};
m_TypedStyle.normal.textColor = Color.white;
}

var margin = Screen.width * 0.05f;
var rect = new Rect(margin, margin, Screen.width - 2 * margin, Screen.height - 2 * margin);
// The time running, to compare against the logcat panel.
var text = $"Time: {m_Time:0.00}\nTyped: {m_Typed}_";
GUI.Label(rect, text, m_TypedStyle);
}

static string Escape(string input)
{
return input.Replace("\b", "\\b").Replace("\n", "\\n").Replace("\r", "\\r");
}


public void TestDebug()
{
Debug.Log("This is a simple LOG message");
Expand Down
Loading