Files

49 lines
1.6 KiB
Python

import urllib.request
import json
import time
def call_mcp(method, params={}):
url = "http://192.168.68.128/api/mcp"
payload = {
"jsonrpc": "2.0",
"id": 1,
"method": method,
"params": params
}
req = urllib.request.Request(
url,
data=json.dumps(payload).encode("utf-8"),
headers={"Content-Type": "application/json"},
method="POST"
)
try:
with urllib.request.urlopen(req, timeout=5.0) as resp:
return json.loads(resp.read().decode("utf-8"))
except Exception as e:
return {"error": str(e)}
# 1. Fetch start stats
print("Fetching start stats...")
res_start = call_mcp("tools/call", {"name": "get_stream_stats", "arguments": {}})
print(json.dumps(res_start, indent=2))
# 2. Wait 3 seconds
print("Waiting 3 seconds...")
time.sleep(3.0)
# 3. Fetch end stats
print("Fetching end stats...")
res_end = call_mcp("tools/call", {"name": "get_stream_stats", "arguments": {}})
print(json.dumps(res_end, indent=2))
# Calculate FPS
try:
start_stats = json.loads(res_start["result"]["content"][0]["text"])
end_stats = json.loads(res_end["result"]["content"][0]["text"])
frames_diff = end_stats["frames_drawn"] - start_stats["frames_drawn"]
packets_diff = end_stats["udp_packets_received"] - start_stats["udp_packets_received"]
print(f"\nResult: Drew {frames_diff} frames in 3.0 seconds ({frames_diff / 3.0:.1f} FPS)")
print(f"Packets received: {packets_diff} in 3.0 seconds ({packets_diff / 3.0:.1f} pps)")
except Exception as e:
print("Failed to calculate FPS:", e)