|
3 | 3 | # |
4 | 4 | # SPDX-License-Identifier: MIT |
5 | 5 | # ============================================================================== |
| 6 | +""" |
| 7 | +DL Streamer Open/Close Valve Sample. |
| 8 | +
|
| 9 | +This module demonstrates dual GStreamer pipeline control with a valve element |
| 10 | +to dynamically route video streams based on object detection results. |
| 11 | +""" |
| 12 | + |
6 | 13 | import sys |
7 | 14 | import time |
8 | 15 | #from contextlib import contextmanager |
@@ -115,39 +122,35 @@ def create_pipeline(self): |
115 | 122 | if not self.pipeline: |
116 | 123 | print("Error: Could not create pipeline") |
117 | 124 | return False |
118 | | - else: |
119 | | - print("Pipeline created") |
| 125 | + print("Pipeline created") |
120 | 126 |
|
121 | 127 | # Get valve element from pipeline |
122 | 128 | self.valve = self.pipeline.get_by_name("control_valve") |
123 | 129 | if not self.valve: |
124 | 130 | print("Error: Could not find control_valve element") |
125 | 131 | return False |
126 | | - else: |
127 | | - print("Found control_valve element") |
| 132 | + print("Found control_valve element") |
128 | 133 |
|
129 | 134 | # Get pre_view_classify element from pipeline |
130 | 135 | # Below we add a probe to the sink pad of pre_view_classify to monitor detected objects |
131 | 136 | self.pre_view_classify = self.pipeline.get_by_name("pre_view_classify") |
132 | 137 | if not self.pre_view_classify: |
133 | 138 | print("Error: Could not find pre_view_classify element") |
134 | 139 | return False |
135 | | - else: |
136 | | - print("Found pre_view_classify element") |
| 140 | + print("Found pre_view_classify element") |
137 | 141 |
|
138 | 142 | # Get sink pad of pre_view_classify |
139 | 143 | pre_view_classify_pad = self.pre_view_classify.get_static_pad("sink") |
140 | 144 | if not pre_view_classify_pad: |
141 | 145 | print("Unable to get sink pad of gvaclassify") |
142 | 146 | return False |
143 | | - else: |
144 | | - print("Got sink pad of pre_view_classify") |
| 147 | + print("Got sink pad of pre_view_classify") |
145 | 148 |
|
146 | 149 | # and add probe/callback |
147 | 150 | pre_view_classify_pad.add_probe(Gst.PadProbeType.BUFFER, |
148 | 151 | self.object_detector_callback, 0) |
149 | 152 | print("All elements found and pipeline created successfully") |
150 | | - except Exception as e: |
| 153 | + except GLib.Error as e: |
151 | 154 | print(f"Error creating pipeline: {e}") |
152 | 155 | return False |
153 | 156 | return True |
@@ -234,7 +237,7 @@ def display_header(): |
234 | 237 | print("\n# ====================================== #") |
235 | 238 | print("# Copyright (C) 2025 Intel Corporation #") |
236 | 239 | print("# #") |
237 | | - print("# SPDX-License-Identifier: MIT #") |
| 240 | + print("# SPDX-License-Identifier: MIT #") |
238 | 241 | print("# ====================================== #") |
239 | 242 | print("# DL Streamer Open/Close Valve Sample #") |
240 | 243 | print("# ====================================== #\n") |
@@ -271,21 +274,21 @@ def main(): |
271 | 274 | if msg: |
272 | 275 | if msg.type == Gst.MessageType.ERROR: |
273 | 276 | err, debug_info = msg.parse_error() |
274 | | - # print(f"Error received from element {msg.src.get_name()}: {err.message}") |
275 | 277 | print(f"Error received from element {msg.src.get_name()}") |
276 | 278 | print(f"Debug info: {debug_info}") |
277 | | - terminate = True |
| 279 | + terminate = True |
278 | 280 | if msg.type == Gst.MessageType.EOS: |
279 | | - print(f"Pipeline complete.") |
| 281 | + print("Pipeline complete.") |
280 | 282 | terminate = True |
281 | 283 | except KeyboardInterrupt as e: |
282 | 284 | print(f"Interrupted by user. Stopping pipeline...[{e}]") |
283 | 285 | terminate = True |
284 | | - except Exception as e: |
| 286 | + except GLib.Error as e: |
285 | 287 | print(f"Exception occurred: {e}") |
286 | 288 |
|
287 | 289 | # Stop pipeline |
288 | 290 | controller.pipeline.set_state(Gst.State.NULL) |
| 291 | + return 0 |
289 | 292 |
|
290 | 293 | if __name__ == "__main__": |
291 | 294 | sys.exit(main()) |
0 commit comments