mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-10-07 19:22:15 +00:00
validate:launcher: Cache GstValidateMediaDescriptor to avoid reparsing .media_info
Saving another second at startup
This commit is contained in:
parent
eda925a334
commit
e7b8ba2d68
1 changed files with 25 additions and 8 deletions
|
@ -2479,9 +2479,23 @@ class GstValidateMediaDescriptor(MediaDescriptor):
|
|||
PUSH_MEDIA_INFO_EXT = "media_info.push"
|
||||
STREAM_INFO_EXT = "stream_info"
|
||||
|
||||
__all_descriptors = {}
|
||||
|
||||
@classmethod
|
||||
def get(cls, xml_path):
|
||||
if xml_path in cls.__all_descriptors:
|
||||
return cls.__all_descriptors[xml_path]
|
||||
return GstValidateMediaDescriptor(xml_path)
|
||||
|
||||
def __init__(self, xml_path):
|
||||
super(GstValidateMediaDescriptor, self).__init__()
|
||||
|
||||
main_descriptor = self.__all_descriptors.get(xml_path)
|
||||
if main_descriptor:
|
||||
self._copy_data_from_main(main_descriptor)
|
||||
else:
|
||||
self.__all_descriptors[xml_path] = self
|
||||
|
||||
self._xml_path = xml_path
|
||||
try:
|
||||
media_xml = ET.parse(xml_path).getroot()
|
||||
|
@ -2489,7 +2503,6 @@ class GstValidateMediaDescriptor(MediaDescriptor):
|
|||
printc("Could not parse %s" % xml_path,
|
||||
Colors.FAIL)
|
||||
raise
|
||||
|
||||
self._extract_data(media_xml)
|
||||
|
||||
self.set_protocol(urllib.parse.urlparse(
|
||||
|
@ -2501,6 +2514,10 @@ class GstValidateMediaDescriptor(MediaDescriptor):
|
|||
def has_frames(self):
|
||||
return self._has_frames
|
||||
|
||||
def _copy_data_from_main(self, main_descriptor):
|
||||
for attr in main_descriptor.__dict__.keys():
|
||||
setattr(self, attr, getattr(main_descriptor, attr))
|
||||
|
||||
def _extract_data(self, media_xml):
|
||||
# Extract the information we need from the xml
|
||||
self._caps = media_xml.findall("streams")[0].attrib["caps"]
|
||||
|
|
Loading…
Reference in a new issue