small optimizations and cleanups by Moritz Venn
[vuplus_dvbapp] / lib / python / Components / Converter / Streaming.py
1 from Converter import Converter
2 from Components.Element import cached
3
4 # the protocol works as the following:
5
6 # lines starting with '-' are fatal errors (no recovery possible),
7 # lines starting with '=' are progress notices,
8 # lines starting with '+' are PIDs to record:
9 #       "+d:[p:t[,p:t...]]" with d=demux nr, p: pid, t: type
10
11 class Streaming(Converter):
12         @cached
13         def getText(self):
14                 service = self.source.service
15                 if service is None:
16                         return "-NO SERVICE\n"
17
18                 streaming = service.stream()
19                 s = streaming and streaming.getStreamingData()
20
21                 if s is None:
22                         err = service.getError()
23                         if err:
24                                 return "-SERVICE ERROR:%d\n" % err
25                         else:
26                                 return "=NO STREAM\n"
27
28                 demux = s["demux"]
29                 pids = ','.join(["%x:%s" % (x[0], x[1]) for x in s["pids"]])
30
31                 return "+%d:%s\n" % (demux, pids)
32
33         text = property(getText)