Skip to content

Commit c0fc556

Browse files
committed
uodates
1 parent b5ff11c commit c0fc556

File tree

9 files changed

+385
-38
lines changed

9 files changed

+385
-38
lines changed

helper/camera_5004.sdp

Lines changed: 0 additions & 9 deletions
This file was deleted.

helper/cameras_page.py

Lines changed: 79 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def __init__(self, parent, controller):
1111

1212
# Initialize RTP stream handler
1313
self.rtp_handler = RTPStreamHandler()
14-
self.stream_ip = "127.0.0.1" # Default IP for RTP streams
14+
self.stream_ip = "10.0.0.23" # Default IP for RTP streams
1515

1616
# Main frame for camera controls
1717
main_frame = ttk.Frame(self, padding=10)
@@ -28,22 +28,32 @@ def __init__(self, parent, controller):
2828
self.cameras_frame = ttk.LabelFrame(main_frame, text="Available Cameras", padding=10)
2929
self.cameras_frame.pack(fill=tk.BOTH, expand=True, pady=10)
3030

31-
# Add camera buttons
31+
# Add camera buttons - now with both snapshot and preview
3232
for port in self.rtp_handler.stream_ports:
33-
camera_btn = ttk.Button(
34-
self.cameras_frame,
35-
text=f"Take Photo: Camera on Port {port}",
33+
port_frame = ttk.Frame(self.cameras_frame)
34+
port_frame.pack(fill=tk.X, pady=5)
35+
36+
ttk.Label(port_frame, text=f"Camera on Port {port}:", width=20).pack(side=tk.LEFT, padx=5)
37+
38+
ttk.Button(
39+
port_frame,
40+
text="Take Photo",
3641
command=lambda p=port: self.take_photo(p)
37-
)
38-
camera_btn.pack(fill=tk.X, pady=5)
42+
).pack(side=tk.LEFT, padx=5)
43+
44+
ttk.Button(
45+
port_frame,
46+
text="Preview Stream",
47+
command=lambda p=port: self.preview_stream(p)
48+
).pack(side=tk.LEFT, padx=5)
3949

4050
# Group action buttons
4151
group_frame = ttk.LabelFrame(main_frame, text="Group Actions", padding=10)
4252
group_frame.pack(fill=tk.X, pady=10)
4353

4454
ttk.Button(
4555
group_frame,
46-
text="Take Photos from Cameras 0 and 1 Simultaneously",
56+
text="Take Photos from Cameras 5001 and 5002 Simultaneously",
4757
command=self.take_photo_0_1
4858
).pack(fill=tk.X, pady=5)
4959

@@ -53,16 +63,49 @@ def __init__(self, parent, controller):
5363
command=self.take_photo_all
5464
).pack(fill=tk.X, pady=5)
5565

66+
# Status variable and label
67+
self.status_var = tk.StringVar(value="Ready")
68+
ttk.Label(main_frame, textvariable=self.status_var, foreground="green").pack(pady=5)
69+
5670
def take_photo(self, port):
5771
"""Take a photo from a specific RTP stream."""
5872
try:
73+
self.status_var.set(f"Taking photo from port {port}...")
5974
file_path = self.rtp_handler.take_snapshot(port)
6075
messagebox.showinfo("Success", f"Snapshot saved to {file_path}")
76+
self.status_var.set("Ready")
6177
except Exception as e:
62-
messagebox.showerror("Error", f"Failed to take snapshot: {str(e)}")
78+
error_msg = str(e)
79+
print(f"Error taking snapshot: {error_msg}")
80+
81+
# Create an informative error message with debugging help
82+
detail_msg = (
83+
f"Failed to take snapshot from port {port}.\n\n"
84+
f"Error: {error_msg}\n\n"
85+
f"Debugging steps:\n"
86+
f"1. Verify camera is streaming to {self.stream_ip}:{port}\n"
87+
f"2. Try using the 'Preview Stream' button first\n"
88+
f"3. Check network connectivity\n"
89+
f"4. Ensure no firewall is blocking UDP on port {port}"
90+
)
91+
92+
messagebox.showerror("Snapshot Error", detail_msg)
93+
self.status_var.set("Error taking snapshot")
94+
95+
def preview_stream(self, port):
96+
"""Preview the RTP stream using ffplay."""
97+
try:
98+
self.status_var.set(f"Starting preview for port {port}...")
99+
self.rtp_handler.preview_stream(port)
100+
self.status_var.set("Preview started. Close ffplay window when done.")
101+
except Exception as e:
102+
error_msg = str(e)
103+
print(f"Error starting preview: {error_msg}")
104+
messagebox.showerror("Preview Error", f"Failed to start preview: {error_msg}")
105+
self.status_var.set("Error starting preview")
63106

64107
def take_photo_0_1(self):
65-
self._take_photos_simultaneous([5000, 5001])
108+
self._take_photos_simultaneous([5001, 5002])
66109

67110
def take_photo_all(self):
68111
self._take_photos_simultaneous(self.rtp_handler.stream_ports)
@@ -72,13 +115,16 @@ def _take_photos_simultaneous(self, ports):
72115
results = {}
73116
errors = {}
74117
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
118+
self.status_var.set(f"Taking photos from ports {ports}...")
75119

76120
def capture(port):
77121
try:
78122
file_path = self.rtp_handler.take_snapshot(port, timestamp=timestamp)
79123
results[port] = file_path
80124
except Exception as e:
81-
errors[port] = str(e)
125+
error_msg = str(e)
126+
print(f"Thread error taking snapshot from port {port}: {error_msg}")
127+
errors[port] = error_msg
82128

83129
threads = []
84130
for port in ports:
@@ -88,9 +134,29 @@ def capture(port):
88134
for t in threads:
89135
t.join()
90136

137+
# Update status based on results
138+
if results and not errors:
139+
self.status_var.set("All snapshots successful")
140+
elif results and errors:
141+
self.status_var.set(f"Some snapshots failed ({len(errors)} errors)")
142+
else:
143+
self.status_var.set("All snapshots failed")
144+
91145
if results:
92146
msg = "Snapshots saved:\n" + "\n".join([f"Camera {p}: {f}" for p, f in results.items()])
93147
messagebox.showinfo("Success", msg)
94148
if errors:
95-
msg = "Errors:\n" + "\n".join([f"Camera {p}: {e}" for p, e in errors.items()])
96-
messagebox.showerror("Error", msg)
149+
# Create a detailed error report
150+
error_report = "Errors occurred while taking snapshots:\n\n"
151+
for port, error in errors.items():
152+
error_report += f"Port {port}: {error}\n\n"
153+
154+
error_report += (
155+
"Possible solutions:\n"
156+
"1. Verify all cameras are streaming correctly\n"
157+
"2. Check if GStreamer is installed and configured\n"
158+
"3. Make sure ports are not blocked by firewall\n"
159+
"4. Try restarting the application or the camera streams"
160+
)
161+
162+
messagebox.showerror("Snapshot Errors", error_report)

0 commit comments

Comments
 (0)