Skip to content

Commit dc63fc9

Browse files
committed
Post code review changes.
1 parent fa37bba commit dc63fc9

File tree

2 files changed

+21
-14
lines changed

2 files changed

+21
-14
lines changed

libraries/dl-streamer/samples/gstreamer/python/open_close_valve/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ videoconvert ! autovideosink sync=true
119119

120120
#### Valve Stream (Controlled)
121121

122+
123+
122124
###### <u>Valve Control Element</u>
123125

124126
```
@@ -128,6 +130,8 @@ valve name=control_valve drop=false !
128130
- States:
129131
- ```drop=false``` Video flows through
130132
- ```drop=true``` Video blocked
133+
134+
You can learn more about the valve element and its properties in the [GStreamer documentation](https://gstreamer.freedesktop.org/documentation/coreelements/valve.html?gi-language=python).
131135
</br>
132136

133137
#### Processing Chain

libraries/dl-streamer/samples/gstreamer/python/open_close_valve/open_close_valve_sample.py

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@
33
#
44
# SPDX-License-Identifier: MIT
55
# ==============================================================================
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+
613
import sys
714
import time
815
#from contextlib import contextmanager
@@ -115,39 +122,35 @@ def create_pipeline(self):
115122
if not self.pipeline:
116123
print("Error: Could not create pipeline")
117124
return False
118-
else:
119-
print("Pipeline created")
125+
print("Pipeline created")
120126

121127
# Get valve element from pipeline
122128
self.valve = self.pipeline.get_by_name("control_valve")
123129
if not self.valve:
124130
print("Error: Could not find control_valve element")
125131
return False
126-
else:
127-
print("Found control_valve element")
132+
print("Found control_valve element")
128133

129134
# Get pre_view_classify element from pipeline
130135
# Below we add a probe to the sink pad of pre_view_classify to monitor detected objects
131136
self.pre_view_classify = self.pipeline.get_by_name("pre_view_classify")
132137
if not self.pre_view_classify:
133138
print("Error: Could not find pre_view_classify element")
134139
return False
135-
else:
136-
print("Found pre_view_classify element")
140+
print("Found pre_view_classify element")
137141

138142
# Get sink pad of pre_view_classify
139143
pre_view_classify_pad = self.pre_view_classify.get_static_pad("sink")
140144
if not pre_view_classify_pad:
141145
print("Unable to get sink pad of gvaclassify")
142146
return False
143-
else:
144-
print("Got sink pad of pre_view_classify")
147+
print("Got sink pad of pre_view_classify")
145148

146149
# and add probe/callback
147150
pre_view_classify_pad.add_probe(Gst.PadProbeType.BUFFER,
148151
self.object_detector_callback, 0)
149152
print("All elements found and pipeline created successfully")
150-
except Exception as e:
153+
except GLib.Error as e:
151154
print(f"Error creating pipeline: {e}")
152155
return False
153156
return True
@@ -234,7 +237,7 @@ def display_header():
234237
print("\n# ====================================== #")
235238
print("# Copyright (C) 2025 Intel Corporation #")
236239
print("# #")
237-
print("# SPDX-License-Identifier: MIT #")
240+
print("# SPDX-License-Identifier: MIT #")
238241
print("# ====================================== #")
239242
print("# DL Streamer Open/Close Valve Sample #")
240243
print("# ====================================== #\n")
@@ -271,21 +274,21 @@ def main():
271274
if msg:
272275
if msg.type == Gst.MessageType.ERROR:
273276
err, debug_info = msg.parse_error()
274-
# print(f"Error received from element {msg.src.get_name()}: {err.message}")
275277
print(f"Error received from element {msg.src.get_name()}")
276278
print(f"Debug info: {debug_info}")
277-
terminate = True
279+
terminate = True
278280
if msg.type == Gst.MessageType.EOS:
279-
print(f"Pipeline complete.")
281+
print("Pipeline complete.")
280282
terminate = True
281283
except KeyboardInterrupt as e:
282284
print(f"Interrupted by user. Stopping pipeline...[{e}]")
283285
terminate = True
284-
except Exception as e:
286+
except GLib.Error as e:
285287
print(f"Exception occurred: {e}")
286288

287289
# Stop pipeline
288290
controller.pipeline.set_state(Gst.State.NULL)
291+
return 0
289292

290293
if __name__ == "__main__":
291294
sys.exit(main())

0 commit comments

Comments
 (0)