mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-07-28 09:15:08 +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
|
@ -2479,18 +2479,31 @@ class GstValidateMediaDescriptor(MediaDescriptor):
|
||||||
PUSH_MEDIA_INFO_EXT = "media_info.push"
|
PUSH_MEDIA_INFO_EXT = "media_info.push"
|
||||||
STREAM_INFO_EXT = "stream_info"
|
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):
|
def __init__(self, xml_path):
|
||||||
super(GstValidateMediaDescriptor, self).__init__()
|
super(GstValidateMediaDescriptor, self).__init__()
|
||||||
|
|
||||||
self._xml_path = xml_path
|
main_descriptor = self.__all_descriptors.get(xml_path)
|
||||||
try:
|
if main_descriptor:
|
||||||
media_xml = ET.parse(xml_path).getroot()
|
self._copy_data_from_main(main_descriptor)
|
||||||
except xml.etree.ElementTree.ParseError:
|
else:
|
||||||
printc("Could not parse %s" % xml_path,
|
self.__all_descriptors[xml_path] = self
|
||||||
Colors.FAIL)
|
|
||||||
raise
|
|
||||||
|
|
||||||
self._extract_data(media_xml)
|
self._xml_path = xml_path
|
||||||
|
try:
|
||||||
|
media_xml = ET.parse(xml_path).getroot()
|
||||||
|
except xml.etree.ElementTree.ParseError:
|
||||||
|
printc("Could not parse %s" % xml_path,
|
||||||
|
Colors.FAIL)
|
||||||
|
raise
|
||||||
|
self._extract_data(media_xml)
|
||||||
|
|
||||||
self.set_protocol(urllib.parse.urlparse(
|
self.set_protocol(urllib.parse.urlparse(
|
||||||
urllib.parse.urlparse(self.get_uri()).scheme).scheme)
|
urllib.parse.urlparse(self.get_uri()).scheme).scheme)
|
||||||
|
@ -2501,6 +2514,10 @@ class GstValidateMediaDescriptor(MediaDescriptor):
|
||||||
def has_frames(self):
|
def has_frames(self):
|
||||||
return self._has_frames
|
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):
|
def _extract_data(self, media_xml):
|
||||||
# Extract the information we need from the xml
|
# Extract the information we need from the xml
|
||||||
self._caps = media_xml.findall("streams")[0].attrib["caps"]
|
self._caps = media_xml.findall("streams")[0].attrib["caps"]
|
||||||
|
|
Loading…
Reference in a new issue