Skip to content

Commit

Permalink
fix: always use an upper limit for caps resolver
Browse files Browse the repository at this point in the history
  • Loading branch information
tomli380576 committed Jan 2, 2025
1 parent a6e94ed commit 543cd32
Showing 1 changed file with 15 additions and 16 deletions.
31 changes: 15 additions & 16 deletions checkbox-support/checkbox_support/camera_pipelines.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,19 +122,11 @@ def remap_range_to_list(

return out

@T.overload
def get_all_fixated_caps(
self, caps: Gst.Caps, resolve_method: T.Literal["remap"]
): ...
@T.overload
def get_all_fixated_caps(
self, caps: Gst.Caps, resolve_method: T.Literal["limit"], limit: int
): ...
def get_all_fixated_caps(
self,
caps: Gst.Caps,
resolve_method: RangeResolveMethod,
limit: T.Optional[int] = None,
limit: int = 10_000,
) -> T.List[Gst.Caps]:
"""Gets all the fixated(1 value per property) caps from a Gst.Caps obj
Expand All @@ -145,7 +137,7 @@ def get_all_fixated_caps(
- "limit" => Use the caps.is_fixed while loop until we reaches limit
:param limit: the limit to use for the "limit" resolver
- ignored if resolve_method != "limit"
- if resolve method is remap, this is still in effect
:return: a list of fixed caps
"""
if caps.is_fixed():
Expand Down Expand Up @@ -193,7 +185,13 @@ def get_all_fixated_caps(
finite_list = temp.get_list(prop)[1]

if finite_list is not None:
assert finite_list.n_values != 0
if finite_list.n_values == 0:
print(
"Resolve method is remap,"
"but original caps doesn't have any",
"of the common values.",
"Skipping.",
)
s_i.set_list(
prop,
finite_list,
Expand All @@ -202,11 +200,12 @@ def get_all_fixated_caps(
caps_i = Gst.Caps.from_string(s_i.to_string())

while not caps_i.is_fixed() and not caps_i.is_empty():
if resolve_method == "limit":
assert limit
if len(fixed_caps) >= limit:
break
if len(fixed_caps) >= limit:
break
fixed_cap = caps_i.fixate() # type: Gst.Caps
if len(fixed_caps) != 0 and fixed_cap.is_equal(fixed_caps[-1]):
# if the caps is already seen
break
fixed_caps.append(fixed_cap)
caps_i = caps_i.subtract(fixed_cap)

Expand Down Expand Up @@ -488,7 +487,7 @@ def record_video(
'capsfilter name=source-caps caps="{}"', # 0
"decodebin", # 1
"videoconvert name=converter", # 2
"jpegenc", # 3, avoid massiave uncompressed videos
"jpegenc", # 3, avoid massive uncompressed videos
"matroskamux", # 4
"filesink location={}".format(file_path), # 5
]
Expand Down

0 comments on commit 543cd32

Please sign in to comment.