MCPcopy Create free account
hub / github.com/ARM-software/AVH / _setFilename

Method _setFilename

interface/vstream/python/vsi_video_server.py:161–228  ·  view source on GitHub ↗

Set the filename for input or output file. Checks file extension to determine if file format is supported. For input: verifies file exists and is supported. For output: removes existing file if present. Args: base_dir: The base directory for the

(self, base_dir, filename)

Source from the content-addressed store, hash-verified

159 return self.device
160
161 def _setFilename(self, base_dir, filename):
162 """
163 Set the filename for input or output file.
164
165 Checks file extension to determine if file format is supported.
166 For input: verifies file exists and is supported.
167 For output: removes existing file if present.
168 Args:
169 base_dir: The base directory for the file.
170 filename: The name of the file (with extension).
171 Returns:
172 filename_valid: True if the filename is valid and set, False otherwise.
173 """
174 logger.debug(f"_setFilename: base_dir={base_dir}, filename={filename}")
175
176 filename_valid = False
177
178 self.filename = None
179
180 if filename == "":
181 # Empty filename is valid (use microphone/speakers)
182 return True
183
184 work_dir = Path(base_dir)
185 file_name = Path(filename)
186 file_path = Path("")
187
188 # Check if file extension is supported
189 ext = file_name.suffix.lstrip('.').lower()
190 if ext not in video_file_extensions + image_file_extensions:
191 logger.error(f"_setFilename: unsupported file extension={ext}")
192 return filename_valid
193
194 # Check if filename is absolute path
195 if file_name.is_absolute():
196 # Absolute path provided
197 file_path = file_name
198 logger.debug(f"_setFilename: absolute path provided, file path={file_path}")
199 else:
200 # Relative path provided, create full path
201 file_path = work_dir / file_name
202 logger.debug(f"_setFilename: relative path provided, file path={file_path}")
203
204 # Normalize the file path
205 file_path = file_path.resolve()
206
207 if self.mode == MODE_VIDEO_INPUT:
208 # Check if the file exists
209 if Path(file_path).exists():
210 # File exists
211 filename_valid = True
212 else:
213 logger.error(f"_setFilename: file does not exist: {file_path}")
214
215 if self.mode == MODE_VIDEO_OUTPUT:
216 # Check if the file exists
217 if Path(file_path).exists():
218 # Remove existing file

Callers 1

runMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected