follow enigma2 pvr channel allocation api change
[enigma2-plugins.git] / bitrateviewer / src / plugin.py
1 #
2 #  BitrateViewer E2
3 #
4 #  $Id$
5 #
6 #  Coded by Dr.Best (c) 2010
7 #  Support: www.dreambox-tools.info
8 #
9 #  This plugin is licensed under the Creative Commons 
10 #  Attribution-NonCommercial-ShareAlike 3.0 Unported 
11 #  License. To view a copy of this license, visit
12 #  http://creativecommons.org/licenses/by-nc-sa/3.0/ or send a letter to Creative
13 #  Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
14 #
15 #  Alternatively, this plugin may be distributed and executed on hardware which
16 #  is licensed by Dream Multimedia GmbH.
17
18 #  This plugin is NOT free software. It is open source, you are allowed to
19 #  modify it (if you keep the license), but it may not be commercially 
20 #  distributed other than under the conditions noted above.
21 #
22
23 from Plugins.Plugin import PluginDescriptor
24 from Screens.Screen import Screen
25 from Components.Sources.StaticText import StaticText
26 from Components.ActionMap import ActionMap
27 from enigma import iServiceInformation, getDesktop
28 from bitratecalc import eBitrateCalculator
29
30 class BitrateCalculator(Screen):
31         sz_w = getDesktop(0).size().width()
32         if sz_w == 1280:
33                 left = 1030
34         elif sz_w == 1024:
35                 left = 774
36         else:
37                 left = 470
38         skin = """
39                 <screen position="%d,40" size="205,68" flags="wfNoBorder" title="BitrateViewer">
40                         <widget render="Label" source="video_caption" position="10,10" zPosition="1" size="70,23" font="Regular;22" transparent="1"/>
41                         <widget render="Label" source="audio_caption" position="10,35" zPosition="1" size="70,23" font="Regular;22" transparent="1"/>
42                         <widget render="Label" source="video" position="75,10" zPosition="1" size="120,23" font="Regular;22" halign="right" transparent="1"/>
43                         <widget render="Label" source="audio" position="75,35" zPosition="1" size="120,23" font="Regular;22" halign="right" transparent="1"/>
44                 </screen>""" % left
45
46         def __init__(self, session, args = None):
47                 Screen.__init__(self, session)
48                 self["video_caption"] = StaticText("Video:")
49                 self["audio_caption"] = StaticText("Audio:")
50                 self["video"] = StaticText()
51                 self["audio"] = StaticText()
52                 self["actions"] = ActionMap(["WizardActions"],
53                 {
54                         "back": self.close,
55                         "ok": self.close,
56                         "right": self.close,
57                         "left": self.close,
58                         "down": self.close,
59                         "up": self.close,
60
61                 }, -1)
62                 ref = session.nav.getCurrentlyPlayingServiceReference()
63                 vpid = apid = -1
64                 service = session.nav.getCurrentService()
65                 if service:
66                         serviceInfo = service.info()
67                         vpid = serviceInfo.getInfo(iServiceInformation.sVideoPID)
68                         apid = serviceInfo.getInfo(iServiceInformation.sAudioPID)
69                         if vpid:
70                                 self.videoBitrate = eBitrateCalculator(vpid, ref.toString(), 1000, 1024*1024) # pid, dvbnamespace, tsid, onid, refresh intervall, buffer size
71                                 self.videoBitrate.callback.append(self.getVideoBitrateData)
72                         if apid:
73                                 self.audioBitrate = eBitrateCalculator(apid, ref.toString(), 1000, 64*1024)
74                                 self.audioBitrate.callback.append(self.getAudioBitrateData)
75
76         def getVideoBitrateData(self,value, status): # value = rate in kbit/s, status ( 1  = ok || 0 = nok (zapped?))
77                 if status:
78                         self["video"].text = "%d kbit/s" % value;
79                 else:
80                         self.videoBitrate = None
81
82         def getAudioBitrateData(self,value, status): 
83                 if status:
84                         self["audio"].text = "%d kbit/s" % value;
85                 else:
86                         self.audioBitrate = None
87
88
89 def main(session,**kwargs):
90         session.open(BitrateCalculator)
91
92 def Plugins(**kwargs):
93         list = [PluginDescriptor(name="BitrateViewer", description=_("BitrateViewer"), 
94                 where = [PluginDescriptor.WHERE_EXTENSIONSMENU ], fnc=main)]
95         return list