예제 #1
0
									resolutionlabel["restxt"].setText(_("Video mode: %s") % x)
						else:
							resolutionlabel["restxt"].setText(_("Video mode: %s") % write_mode)
							print "[VideoMode] setMode - port: %s, mode: %s" % (config_port, write_mode)
						if config.av.autores.value != "disabled" and config.av.autores_label_timeout.value != '0':
							resolutionlabel.show()
						vf.close()
				except Exception, e:
					print("[VideoMode] read videomode_choices exception:" + str(e))
			elif write_mode and current_mode != write_mode:
				# the resolution remained stuck at a wrong setting after streaming when self.bufferfull was False (should be fixed now after adding BufferInfoStop)
				print "[VideoMode] not changing from",current_mode,"to",write_mode,"as self.bufferfull is",self.bufferfull

		iAVSwitch.setAspect(config.av.aspect)
		iAVSwitch.setWss(config.av.wss)
		iAVSwitch.setPolicy43(config.av.policy_43)
		iAVSwitch.setPolicy169(config.av.policy_169)

		self.delay = False
		self.detecttimer.stop()

def autostart(session):
	global resolutionlabel
	if not path.exists(resolveFilename(SCOPE_PLUGINS)+'SystemPlugins/AutoResolution'):
		if resolutionlabel is None:
			resolutionlabel = session.instantiateDialog(AutoVideoModeLabel)
		AutoVideoMode(session)
	else:
		config.av.autores.setValue(False)
		config.av.autores.save()
		configfile.save()
예제 #2
0
    def VideoChangeDetect(self):
        global resolutionlabel
        config_port = config.av.videoport.value
        config_mode = str(config.av.videomode[config_port].value).replace(
            '\n', '')
        config_res = str(config.av.videomode[config_port].value[:-1]).replace(
            '\n', '')
        config_pol = str(config.av.videomode[config_port].value[-1:]).replace(
            '\n', '')
        config_rate = str(config.av.videorate[config_mode].value).replace(
            'Hz', '').replace('\n', '')

        f = open("/proc/stb/video/videomode")
        current_mode = f.read()[:-1].replace('\n', '')
        f.close()
        if current_mode.upper() in ('PAL', 'NTSC'):
            current_mode = current_mode.upper()

        current_pol = ''
        if 'i' in current_mode:
            current_pol = 'i'
        elif 'p' in current_mode:
            current_pol = 'p'
        current_res = current_pol and current_mode.split(
            current_pol)[0].replace('\n', '') or ""
        current_rate = current_pol and current_mode.split(
            current_pol)[0].replace(
                '\n', '') and current_mode.split(current_pol)[1].replace(
                    '\n', '') or ""

        video_height = None
        video_width = None
        video_pol = None
        video_rate = None
        if path.exists("/proc/stb/vmpeg/0/yres"):
            f = open("/proc/stb/vmpeg/0/yres", "r")
            try:
                video_height = int(f.read(), 16)
            except:
                pass
            f.close()
        if path.exists("/proc/stb/vmpeg/0/xres"):
            f = open("/proc/stb/vmpeg/0/xres", "r")
            try:
                video_width = int(f.read(), 16)
            except:
                pass
            f.close()
        if path.exists("/proc/stb/vmpeg/0/progressive"):
            f = open("/proc/stb/vmpeg/0/progressive", "r")
            try:
                video_pol = "p" if int(f.read(), 16) else "i"
            except:
                pass
            f.close()
        if path.exists("/proc/stb/vmpeg/0/framerate"):
            f = open("/proc/stb/vmpeg/0/framerate", "r")
            try:
                video_rate = int(f.read())
            except:
                pass
            f.close()

        if not video_height or not video_width or not video_pol or not video_rate:
            service = self.session.nav.getCurrentService()
            if service is not None:
                info = service.info()
            else:
                info = None

            if info:
                video_height = int(
                    info.getInfo(iServiceInformation.sVideoHeight))
                video_width = int(info.getInfo(
                    iServiceInformation.sVideoWidth))
                video_pol = ("i", "p")[info.getInfo(
                    iServiceInformation.sProgressive)]
                video_rate = int(info.getInfo(iServiceInformation.sFrameRate))

        if video_height and video_width and video_pol and video_rate:
            resolutionlabel["content"].setText(
                _("Video content: %ix%i%s %iHz") %
                (video_width, video_height, video_pol,
                 (video_rate + 500) / 1000))
            if (700 < video_width <= 720
                ) and video_height <= 480 and video_rate in (23976, 24000,
                                                             29970, 59940):
                new_res = "480"
            elif (700 < video_width <= 720
                  ) and video_height <= 576 and video_rate in (25000, 50000):
                new_res = "576"
            elif (video_width == 1280) and video_height <= 720:
                new_res = "720"
            else:
                new_res = config_res

            if video_rate != -1:
                if video_rate == 25000 and video_pol == 'i':
                    new_rate = 50000
                elif video_rate == 59940 or (
                        video_rate == 29970 and video_pol
                        == 'i') or (video_rate == 29970 and video_pol == 'p'
                                    and config.av.autores.value == 'disabled'):
                    new_rate = 60000
                elif video_rate == 23976:
                    new_rate = 24000
                elif video_rate == 29970:
                    new_rate = 30000
                else:
                    new_rate = video_rate
                new_rate = str((new_rate + 500) / 1000)
            else:
                new_rate = config_rate

            if video_pol != -1:
                new_pol = str(video_pol)
            else:
                new_pol = config_pol

            write_mode = None
            new_mode = None
            if config_mode in ('PAL', 'NTSC'):
                write_mode = config_mode
            elif config.av.autores.value == 'all' or (
                    config.av.autores.value == 'hd' and int(new_res) >= 720):
                if (config.av.autores_deinterlace.value
                        and HardwareInfo().is_nextgen()) or (
                            config.av.autores_deinterlace.value
                            and not HardwareInfo().is_nextgen()
                            and int(new_res) <= 720):
                    new_pol = new_pol.replace('i', 'p')
                if new_res + new_pol + new_rate in iAVSwitch.modes_available:
                    new_mode = new_res + new_pol + new_rate
                    if new_mode == '480p24' or new_mode == '576p24':
                        new_mode = config.av.autores_480p24.value
                    if new_mode == '720p24':
                        new_mode = config.av.autores_720p24.value
                    if new_mode == '1080p24':
                        new_mode = config.av.autores_1080p24.value
                    if new_mode == '1080p25':
                        new_mode = config.av.autores_1080p25.value
                    if new_mode == '1080p30':
                        new_mode = config.av.autores_1080p30.value
                elif new_res + new_pol in iAVSwitch.modes_available:
                    new_mode = new_res + new_pol
                else:
                    new_mode = config_mode + new_rate

                write_mode = new_mode
            elif config.av.autores.value == 'hd' and int(new_res) <= 576:
                if (config.av.autores_deinterlace.value
                        and HardwareInfo().is_nextgen()) or (
                            config.av.autores_deinterlace.value
                            and not HardwareInfo().is_nextgen()
                            and not config.av.autores_sd.value == '1080i'):
                    new_mode = config.av.autores_sd.value.replace(
                        'i', 'p') + new_rate
                else:
                    if new_pol in 'p':
                        new_mode = config.av.autores_sd.value.replace(
                            'i', 'p') + new_rate
                    else:
                        new_mode = config.av.autores_sd.value + new_rate

                if new_mode == '720p24':
                    new_mode = config.av.autores_720p24.value
                if new_mode == '1080p24':
                    new_mode = config.av.autores_1080p24.value
                if new_mode == '1080p25':
                    new_mode = config.av.autores_1080p25.value
                if new_mode == '1080p30':
                    new_mode = config.av.autores_1080p30.value

                write_mode = new_mode
            else:
                if path.exists('/proc/stb/video/videomode_%shz' %
                               new_rate) and config_rate == 'multi':
                    f = open("/proc/stb/video/videomode_%shz" % new_rate, "r")
                    multi_videomode = f.read().replace('\n', '')
                    f.close()
                    if multi_videomode and (current_mode != multi_videomode):
                        write_mode = multi_videomode
                    else:
                        write_mode = current_mode
                else:
                    if new_rate == '24' and config_rate == 'multi':
                        write_mode = config_res + 'p' + new_rate

            if write_mode and current_mode != write_mode:
                resolutionlabel["restxt"].setText(
                    _("Video mode: %s") % write_mode)
                if config.av.autores.value != "disabled" and config.av.autores_label_timeout.value != '0':
                    resolutionlabel.show()
                print "[VideoMode] setMode - port: %s, mode: %s" % (
                    config_port, write_mode)
                f = open("/proc/stb/video/videomode", "w")
                f.write(write_mode)
                f.close()

        iAVSwitch.setAspect(config.av.aspect)
        iAVSwitch.setWss(config.av.wss)
        iAVSwitch.setPolicy43(config.av.policy_43)
        iAVSwitch.setPolicy169(config.av.policy_169)

        self.delay = False
        self.detecttimer.stop()
예제 #3
0
	def VideoChangeDetect(self):
		global resolutionlabel
		config_port = config.av.videoport.value
		config_mode = str(config.av.videomode[config_port].value).replace('\n','')
		config_res = str(config.av.videomode[config_port].value[:-1]).replace('\n','')
		config_pol = str(config.av.videomode[config_port].value[-1:]).replace('\n','')
		config_rate = str(config.av.videorate[config_mode].value).replace('Hz','').replace('\n','')

		f = open("/proc/stb/video/videomode")
		current_mode = f.read()[:-1].replace('\n','')
		f.close()
		if current_mode.upper() in ('PAL', 'NTSC'):
			current_mode = current_mode.upper()

		current_pol = ''
		if 'i' in current_mode:
			current_pol = 'i'
		elif 'p' in current_mode:
			current_pol = 'p'
		current_res = current_pol and current_mode.split(current_pol)[0].replace('\n','') or ""
		current_rate = current_pol and current_mode.split(current_pol)[0].replace('\n','') and current_mode.split(current_pol)[1].replace('\n','') or ""

		video_height = None
		video_width = None
		video_pol = None
		video_rate = None
		if path.exists("/proc/stb/vmpeg/0/yres"):
			f = open("/proc/stb/vmpeg/0/yres", "r")
			try:
				video_height = int(f.read(),16)
			except:
    				pass
			f.close()
		if path.exists("/proc/stb/vmpeg/0/xres"):
			f = open("/proc/stb/vmpeg/0/xres", "r")
			try:
				video_width = int(f.read(),16)
			except:
    				pass
			f.close()
		if path.exists("/proc/stb/vmpeg/0/progressive"):
			f = open("/proc/stb/vmpeg/0/progressive", "r")
			try:
				video_pol = "p" if int(f.read(),16) else "i"
			except:
    				pass
			f.close()
		if path.exists("/proc/stb/vmpeg/0/framerate"):
			f = open("/proc/stb/vmpeg/0/framerate", "r")
			try:
				video_rate = int(f.read())
			except:
    				pass
			f.close()

		if not video_height or not video_width or not video_pol or not video_rate:
			service = self.session.nav.getCurrentService()
			if service is not None:
				info = service.info()
			else:
				info = None

			if info:
				video_height = int(info.getInfo(iServiceInformation.sVideoHeight))
				video_width = int(info.getInfo(iServiceInformation.sVideoWidth))
				video_pol = ("i", "p")[info.getInfo(iServiceInformation.sProgressive)]
				video_rate = int(info.getInfo(iServiceInformation.sFrameRate))

		if video_height and video_width and video_pol and video_rate:
			resolutionlabel["content"].setText(_("Video content: %ix%i%s %iHz") % (video_width, video_height, video_pol, (video_rate + 500) / 1000))
			if (700 < video_width <= 720) and video_height <= 480 and video_rate in (23976, 24000, 29970, 59940):
				new_res = "480"
			elif (700 < video_width <= 720) and video_height <= 576 and video_rate in (25000, 50000):
				new_res = "576"
			elif (video_width == 1280) and video_height <=720:
				new_res = "720"
			else:
				new_res = config_res

			if video_rate != -1:
				if video_rate == 25000 and video_pol == 'i':
					new_rate = 50000
				elif video_rate == 59940 or (video_rate == 29970 and video_pol == 'i') or (video_rate == 29970 and video_pol == 'p' and config.av.autores.value == 'disabled'): 
					new_rate = 60000
				elif video_rate == 23976:
					new_rate = 24000
				elif video_rate == 29970:
					new_rate = 30000
				else:
					new_rate = video_rate
				new_rate = str((new_rate + 500) / 1000)
			else:
				new_rate = config_rate

			if video_pol != -1:
				new_pol = str(video_pol)
			else:
				new_pol = config_pol

			write_mode = None
			new_mode = None
			if config_mode in ('PAL', 'NTSC'):
				write_mode = config_mode
			elif config.av.autores.value == 'all' or (config.av.autores.value == 'hd' and int(new_res) >= 720):
				if (config.av.autores_deinterlace.value and HardwareInfo().is_nextgen()) or (config.av.autores_deinterlace.value and not HardwareInfo().is_nextgen() and int(new_res) <= 720):
					new_pol = new_pol.replace('i','p')
				if new_res+new_pol+new_rate in iAVSwitch.modes_available:
					new_mode = new_res+new_pol+new_rate
					if new_mode == '480p24' or new_mode == '576p24':
						new_mode = config.av.autores_480p24.value
					if new_mode == '720p24':
						new_mode = config.av.autores_720p24.value
					if new_mode == '1080p24':
						new_mode = config.av.autores_1080p24.value
					if new_mode == '1080p25':
						new_mode = config.av.autores_1080p25.value
					if new_mode == '1080p30':
						new_mode = config.av.autores_1080p30.value
				elif new_res+new_pol in iAVSwitch.modes_available:
					new_mode = new_res+new_pol
				else:
					new_mode = config_mode+new_rate

				write_mode = new_mode
			elif config.av.autores.value == 'hd' and int(new_res) <= 576:
				if (config.av.autores_deinterlace.value and HardwareInfo().is_nextgen()) or (config.av.autores_deinterlace.value and not HardwareInfo().is_nextgen() and not config.av.autores_sd.value == '1080i'):
					new_mode = config.av.autores_sd.value.replace('i','p')+new_rate
				else:
					if new_pol in 'p':
						new_mode = config.av.autores_sd.value.replace('i','p')+new_rate
					else:
						new_mode = config.av.autores_sd.value+new_rate

				if new_mode == '720p24':
					new_mode = config.av.autores_720p24.value
				if new_mode == '1080p24':
					new_mode = config.av.autores_1080p24.value
				if new_mode == '1080p25':
					new_mode = config.av.autores_1080p25.value
				if new_mode == '1080p30':
					new_mode = config.av.autores_1080p30.value

				write_mode = new_mode
			else:
				if path.exists('/proc/stb/video/videomode_%shz' % new_rate) and config_rate == 'multi':
					f = open("/proc/stb/video/videomode_%shz" % new_rate, "r")
					multi_videomode = f.read().replace('\n','')
					f.close()
					if multi_videomode and (current_mode != multi_videomode):
						write_mode = multi_videomode
					else:
						write_mode = config_mode+new_rate
			if write_mode and current_mode != write_mode:
				resolutionlabel["restxt"].setText(_("Video mode: %s") % write_mode)
				if config.av.autores.value != "disabled" and config.av.autores_label_timeout.value != '0':
					resolutionlabel.show()
				print "[VideoMode] setMode - port: %s, mode: %s" % (config_port, write_mode)
				f = open("/proc/stb/video/videomode", "w")
				f.write(write_mode)
				f.close()

		iAVSwitch.setAspect(config.av.aspect)
		iAVSwitch.setWss(config.av.wss)
		iAVSwitch.setPolicy43(config.av.policy_43)
		iAVSwitch.setPolicy169(config.av.policy_169)

		self.delay = False
		self.detecttimer.stop()
예제 #4
0
                                _("Video mode: %s") % write_mode)
                            print "[VideoMode] setMode - port: %s, mode: %s" % (
                                config_port, write_mode)
                        if config.av.autores.value != "disabled" and config.av.autores_label_timeout.value != '0':
                            resolutionlabel.show()
                        vf.close()
                except Exception, e:
                    print("[VideoMode] read videomode_choices exception:" +
                          str(e))
            elif write_mode and current_mode != write_mode:
                # the resolution remained stuck at a wrong setting after streaming when self.bufferfull was False (should be fixed now after adding BufferInfoStop)
                print "[VideoMode] not changing from", current_mode, "to", write_mode, "as self.bufferfull is", self.bufferfull

        iAVSwitch.setAspect(config.av.aspect)
        iAVSwitch.setWss(config.av.wss)
        iAVSwitch.setPolicy43(config.av.policy_43)
        iAVSwitch.setPolicy169(config.av.policy_169)

        self.delay = False
        self.detecttimer.stop()


def autostart(session):
    global resolutionlabel
    if not path.exists(
            resolveFilename(SCOPE_PLUGINS) + 'SystemPlugins/AutoResolution'):
        if resolutionlabel is None:
            resolutionlabel = session.instantiateDialog(AutoVideoModeLabel)
        AutoVideoMode(session)
    else:
        config.av.autores.setValue(False)
예제 #5
0
    def VideoChangeDetect(self):
        global resolutionlabel
        config_port = config.av.videoport.value
        config_mode = str(config.av.videomode[config_port].value).replace('\n', '')
        config_res = str(config.av.videomode[config_port].value[:-1]).replace('\n', '')
        config_pol = str(config.av.videomode[config_port].value[-1:]).replace('\n', '')
        config_rate = str(config.av.videorate[config_mode].value).replace('Hz', '').replace('\n', '')
        f = open('/proc/stb/video/videomode')
        current_mode = f.read()[:-1].replace('\n', '')
        f.close()
        if current_mode.upper() in ('PAL', 'NTSC'):
            current_mode = current_mode.upper()
        current_pol = ''
        if 'i' in current_mode:
            current_pol = 'i'
        elif 'p' in current_mode:
            current_pol = 'p'
        current_res = current_pol and current_mode.split(current_pol)[0].replace('\n', '') or ''
        current_rate = current_pol and current_mode.split(current_pol)[0].replace('\n', '') and current_mode.split(current_pol)[1].replace('\n', '') or ''
        video_height = None
        video_width = None
        video_pol = None
        video_rate = None
        if path.exists('/proc/stb/vmpeg/0/yres'):
            try:
                f = open('/proc/stb/vmpeg/0/yres', 'r')
                video_height = int(f.read(), 16)
                f.close()
            except:
                video_height = 0

        if path.exists('/proc/stb/vmpeg/0/xres'):
            try:
                f = open('/proc/stb/vmpeg/0/xres', 'r')
                video_width = int(f.read(), 16)
                f.close()
            except:
                video_width = 0

        if path.exists('/proc/stb/vmpeg/0/progressive'):
            try:
                f = open('/proc/stb/vmpeg/0/progressive', 'r')
                video_pol = 'p' if int(f.read(), 16) else 'i'
                f.close()
            except:
                video_pol = 'i'

        if path.exists('/proc/stb/vmpeg/0/framerate'):
            f = open('/proc/stb/vmpeg/0/framerate', 'r')
            try:
                video_rate = int(f.read())
            except:
                video_rate = 50

            f.close()
        if not video_height or not video_width or not video_pol or not video_rate:
            service = self.session.nav.getCurrentService()
            if service is not None:
                info = service.info()
            else:
                info = None
            if info:
                video_height = int(info.getInfo(iServiceInformation.sVideoHeight))
                video_width = int(info.getInfo(iServiceInformation.sVideoWidth))
                video_pol = ('i', 'p')[info.getInfo(iServiceInformation.sProgressive)]
                video_rate = int(info.getInfo(iServiceInformation.sFrameRate))
        if video_height and video_width and video_pol and video_rate or config.av.smart1080p.value != 'false':
            resolutionlabel['content'].setText(_('Video content: %ix%i%s %iHz') % (video_width,
             video_height,
             video_pol,
             (video_rate + 500) / 1000))
            if video_height != -1:
                if video_height > 720 or video_width > 1280:
                    new_res = '1080'
                elif 576 < video_height <= 720 or video_width > 1024:
                    new_res = '720'
                elif 480 < video_height <= 576 or video_width > 720 or video_rate in (25000, 23976, 24000):
                    new_res = '576'
                else:
                    new_res = '480'
            else:
                new_res = config_res
            if video_rate != -1:
                if video_rate == 25000 and video_pol == 'i':
                    new_rate = 50000
                elif video_rate == 59940 or video_rate == 29970 and video_pol == 'i' or video_rate == 29970 and video_pol == 'p' and config.av.autores.value == 'disabled':
                    new_rate = 60000
                elif video_rate == 23976:
                    new_rate = 24000
                elif video_rate == 29970:
                    new_rate = 30000
                else:
                    new_rate = video_rate
                new_rate = str((new_rate + 500) / 1000)
            else:
                new_rate = config_rate
            if video_pol != -1:
                new_pol = str(video_pol)
            else:
                new_pol = config_pol
            write_mode = None
            new_mode = None
            if config_mode in ('PAL', 'NTSC'):
                write_mode = config_mode
            elif config.av.autores.value == 'all' or config.av.autores.value == 'hd' and int(new_res) >= 720:
                if config.av.autores_deinterlace.value and HardwareInfo().is_nextgen() or config.av.autores_deinterlace.value and not HardwareInfo().is_nextgen() and int(new_res) <= 720:
                    new_pol = new_pol.replace('i', 'p')
                if new_res + new_pol + new_rate in iAVSwitch.modes_available:
                    new_mode = new_res + new_pol + new_rate
                    if new_mode == '480p24' or new_mode == '576p24':
                        new_mode = config.av.autores_480p24.value
                    if new_mode == '720p24':
                        new_mode = config.av.autores_720p24.value
                    if new_mode == '1080p24':
                        new_mode = config.av.autores_1080p24.value
                    if new_mode == '1080p25':
                        new_mode = config.av.autores_1080p25.value
                    if new_mode == '1080p30':
                        new_mode = config.av.autores_1080p30.value
                elif new_res + new_pol in iAVSwitch.modes_available:
                    new_mode = new_res + new_pol
                else:
                    new_mode = config_mode + new_rate
                write_mode = new_mode
            elif config.av.autores.value == 'hd' and int(new_res) <= 576:
                if config.av.autores_deinterlace.value and HardwareInfo().is_nextgen() or config.av.autores_deinterlace.value and not HardwareInfo().is_nextgen() and not config.av.autores_sd.value == '1080i':
                    new_mode = config.av.autores_sd.value.replace('i', 'p') + new_rate
                elif new_pol in 'p':
                    new_mode = config.av.autores_sd.value.replace('i', 'p') + new_rate
                else:
                    new_mode = config.av.autores_sd.value + new_rate
                if new_mode == '720p24':
                    new_mode = config.av.autores_720p24.value
                if new_mode == '1080p24':
                    new_mode = config.av.autores_1080p24.value
                if new_mode == '1080p25':
                    new_mode = config.av.autores_1080p25.value
                if new_mode == '1080p30':
                    new_mode = config.av.autores_1080p30.value
                write_mode = new_mode
            elif path.exists('/proc/stb/video/videomode_%shz' % new_rate) and config_rate == 'multi':
                f = open('/proc/stb/video/videomode_%shz' % new_rate, 'r')
                multi_videomode = f.read().replace('\n', '')
                f.close()
                if multi_videomode and current_mode != multi_videomode:
                    write_mode = multi_videomode
                else:
                    write_mode = config_mode + new_rate
            if config.av.smart1080p.value != 'false':
                print 'DEBUG VIDEOMODE/ smart1080p enabled'
                ref = self.session.nav.getCurrentlyPlayingServiceReference()
                if ref is not None:
                    try:
                        mypath = ref.getPath()
                    except:
                        mypath = ''

                else:
                    mypath = ''
                if new_rate == 'multi':
                    if mypath.find('p24.') >= 0 or mypath.find('24p.') >= 0:
                        new_rate = '24'
                    elif mypath.find('p25.') >= 0 or mypath.find('25p.') >= 0:
                        new_rate = '25'
                    elif mypath.find('p30.') >= 0 or mypath.find('30p.') >= 0:
                        new_rate = '30'
                    elif mypath.find('p50.') >= 0 or mypath.find('50p.') >= 0:
                        new_rate = '50'
                    elif mypath.find('p60.') >= 0 or mypath.find('60p.') >= 0:
                        new_rate = '60'
                    else:
                        new_rate = ''
                if mypath != '':
                    if mypath.endswith('.ts'):
                        print 'DEBUG VIDEOMODE/ playing .ts file'
                        new_rate = '50'
                    else:
                        print 'DEBUG VIDEOMODE/ playing other (non .ts) file'
                else:
                    print 'DEBUG VIDEOMODE/ no path or no service reference, presumably live TV'
                    new_rate = '50'
                new_rate = new_rate.replace('25', '50')
                new_rate = new_rate.replace('30', '60')
                if config.av.smart1080p.value == '1080p50' or config.av.smart1080p.value == 'true':
                    write_mode = '1080p' + new_rate
                elif config.av.smart1080p.value == '1080i50':
                    write_mode = '1080i' + new_rate
                elif config.av.smart1080p.value == '720p50':
                    write_mode = '720p' + new_rate
            if write_mode and current_mode != write_mode and self.bufferfull:
                resolutionlabel['restxt'].setText(_('Video mode: %s') % write_mode)
                if config.av.autores.value != 'disabled' and config.av.autores_label_timeout.value != '0':
                    resolutionlabel.show()
                print '[VideoMode] setMode - port: %s, mode: %s' % (config_port, write_mode)
                changeResolution = False
                try:
                    if path.exists('/proc/stb/video/videomode_choices'):
                        vf = open('/proc/stb/video/videomode_choices')
                        values = vf.readline().replace('\n', '').split(' ', -1)
                        for x in values:
                            if x == write_mode:
                                try:
                                    f = open('/proc/stb/video/videomode', 'w')
                                    f.write(write_mode)
                                    f.close()
                                    changeResolution = True
                                except Exception as e:
                                    print '[VideoMode] write_mode exception:' + str(e)

                        if not changeResolution:
                            print '[VideoMode] setMode - port: %s, mode: %s is not available' % (config_port, write_mode)
                            resolutionlabel['restxt'].setText(_('Video mode: %s is not available') % write_mode)
                            if write_mode == '1080p24':
                                for x in values:
                                    if x == '1080p':
                                        try:
                                            f = open('/proc/stb/video/videomode', 'w')
                                            f.write(x)
                                            f.close()
                                            changeResolution = True
                                        except Exception as e:
                                            print '[VideoMode] write_mode exception:' + str(e)

                                if not changeResolution:
                                    print '[VideoMode] setMode - port: %s, mode: 1080p is also not available' % config_port
                                    resolutionlabel['restxt'].setText(_('Video mode: 1080p is also not available'))
                        vf.close()
                except Exception as e:
                    print '[VideoMode] read videomode_choices exception:' + str(e)

        iAVSwitch.setAspect(config.av.aspect)
        iAVSwitch.setWss(config.av.wss)
        iAVSwitch.setPolicy43(config.av.policy_43)
        iAVSwitch.setPolicy169(config.av.policy_169)
        self.delay = False
        self.detecttimer.stop()
예제 #6
0
    def VideoChangeDetect(self):
        config_port = config.av.videoport.getValue()
        config_mode = str(config.av.videomode[config_port].getValue()).replace(
            '\n', '')
        config_res = str(
            config.av.videomode[config_port].getValue()[:-1]).replace(
                '\n', '')
        config_pol = str(
            config.av.videomode[config_port].getValue()[-1:]).replace(
                '\n', '')
        config_rate = str(config.av.videorate[config_mode].getValue()).replace(
            'Hz', '').replace('\n', '')

        f = open("/proc/stb/video/videomode")
        current_mode = f.read()[:-1].replace('\n', '')
        f.close()
        if current_mode.upper() in ('PAL', 'NTSC'):
            current_mode = current_mode.upper()

        current_pol = ''
        if 'i' in current_mode:
            current_pol = 'i'
        elif 'p' in current_mode:
            current_pol = 'p'
        current_res = current_pol and current_mode.split(
            current_pol)[0].replace('\n', '') or ""
        current_rate = current_pol and current_mode.split(
            current_pol)[0].replace(
                '\n', '') and current_mode.split(current_pol)[1].replace(
                    '\n', '') or ""

        video_height = None
        video_width = None
        video_pol = None
        video_rate = None
        if path.exists("/proc/stb/vmpeg/0/yres"):
            f = open("/proc/stb/vmpeg/0/yres", "r")
            video_height = int(f.read(), 16)
            f.close()
        if path.exists("/proc/stb/vmpeg/0/xres"):
            f = open("/proc/stb/vmpeg/0/xres", "r")
            video_width = int(f.read(), 16)
            f.close()
        if path.exists("/proc/stb/vmpeg/0/progressive"):
            f = open("/proc/stb/vmpeg/0/progressive", "r")
            video_pol = "p" if int(f.read(), 16) else "i"
            f.close()
        if path.exists("/proc/stb/vmpeg/0/framerate"):
            f = open("/proc/stb/vmpeg/0/framerate", "r")
            try:
                video_rate = int(f.read())
            except:
                video_rate = 50
            f.close()

        if not video_height or not video_width or not video_pol or not video_rate:
            service = self.session.nav.getCurrentService()
            if service is not None:
                info = service.info()
            else:
                info = None

            if info:
                video_height = int(
                    info.getInfo(iServiceInformation.sVideoHeight))
                video_width = int(info.getInfo(
                    iServiceInformation.sVideoWidth))
                video_pol = ("i", "p")[info.getInfo(
                    iServiceInformation.sProgressive)]
                video_rate = int(info.getInfo(iServiceInformation.sFrameRate))

        if video_height and video_width and video_pol and video_rate:
            resolutionlabel["content"].setText(
                _("Video content: %ix%i%s %iHz") %
                (video_width, video_height, video_pol,
                 (video_rate + 500) / 1000))
            if video_height != -1:
                if video_height > 720 or video_width > 1280:
                    new_res = "1080"
                elif (576 < video_height <= 720) or video_width > 1024:
                    new_res = "720"
                elif (480 < video_height <=
                      576) or video_width > 720 or video_rate in (25000, 23976,
                                                                  24000):
                    new_res = "576"
                else:
                    new_res = "480"
            else:
                new_res = config_res

            if video_rate != -1:
                if video_rate == 25000 and video_pol == 'i':
                    new_rate = 50000
                elif video_rate == 59940 or (
                        video_rate == 29970 and video_pol == 'i') or (
                            video_rate == 29970 and video_pol == 'p'
                            and config.av.autores.getValue() == 'disabled'):
                    new_rate = 60000
                elif video_rate == 23976:
                    new_rate = 24000
                elif video_rate == 29970:
                    new_rate = 30000
                else:
                    new_rate = video_rate
                new_rate = str((new_rate + 500) / 1000)
            else:
                new_rate = config_rate

            if video_pol != -1:
                new_pol = str(video_pol)
            else:
                new_pol = config_pol

            write_mode = None
            new_mode = None
            if config_mode in ('PAL', 'NTSC'):
                write_mode = config_mode
            elif config.av.autores.getValue() == 'all' or (
                    config.av.autores.getValue() == 'hd'
                    and int(new_res) >= 720):
                if (config.av.autores_deinterlace.getValue()
                        and about.getCPUString() in 'BCM7346B2, BCM7425B2'
                    ) or config.av.autores_deinterlace.getValue(
                    ) and about.getCPUString(
                    ) not in 'BCM7346B2, BCM7425B2' and int(new_res) <= 720:
                    new_pol = new_pol.replace('i', 'p')
                if new_res + new_pol + new_rate in iAVSwitch.modes_available:
                    new_mode = new_res + new_pol + new_rate
                    if new_mode == '720p24':
                        new_mode = config.av.autores_720p24.getValue()
                    if new_mode == '1080p24':
                        new_mode = config.av.autores_1080p24.getValue()
                    if new_mode == '1080p25':
                        new_mode = config.av.autores_1080p25.getValue()
                    if new_mode == '1080p30':
                        new_mode = config.av.autores_1080p30.getValue()
                elif new_res + new_pol in iAVSwitch.modes_available:
                    new_mode = new_res + new_pol
                else:
                    write_mode = config_mode + new_rate

                write_mode = new_mode
            elif config.av.autores.getValue() == 'hd' and int(new_res) <= 576:
                if (
                        config.av.autores_deinterlace.getValue()
                        and about.getCPUString() in 'BCM7346B2, BCM7425B2'
                ) or config.av.autores_deinterlace.getValue(
                ) and about.getCPUString(
                ) not in 'BCM7346B2, BCM7425B2' and not config.av.autores_sd.getValue(
                ) in '1080i':
                    new_mode = config.av.autores_sd.getValue().replace(
                        'i', 'p') + new_rate
                else:
                    if new_pol in 'p':
                        new_mode = config.av.autores_sd.getValue().replace(
                            'i', 'p') + new_rate
                    else:
                        new_mode = config.av.autores_sd.getValue() + new_rate

                if new_mode == '720p24':
                    new_mode = config.av.autores_720p24.getValue()
                if new_mode == '1080p24':
                    new_mode = config.av.autores_1080p24.getValue()
                if new_mode == '1080p25':
                    new_mode = config.av.autores_1080p25.getValue()
                if new_mode == '1080p30':
                    new_mode = config.av.autores_1080p30.getValue()

                write_mode = new_mode
            else:
                if path.exists('/proc/stb/video/videomode_%shz' %
                               new_rate) and config_rate == 'multi':
                    f = open("/proc/stb/video/videomode_%shz" % new_rate, "r")
                    multi_videomode = f.read().replace('\n', '')
                    f.close()
                    if multi_videomode and (current_mode != multi_videomode):
                        write_mode = multi_videomode
                    else:
                        write_mode = config_mode + new_rate

            # workaround for bug, see http://www.opena.tv/forum/showthread.php?1642-Autoresolution-Plugin&p=38836&viewfull=1#post38836
            # always use 1080p50 for TV or .ts files
            # always use 1080p24/p50/p60 for all other videos
            if config.av.smart1080p.getValue():
                print "DEBUG VIDEOMODE/ smart1080p enabled"
                if new_rate == 'multi':
                    write_mode = '1080p'
                else:
                    new_rate = new_rate.replace('25', '50')
                    new_rate = new_rate.replace('30', '60')
                    write_mode = '1080p' + new_rate
                print "DEBUG VIDEOMODE/ new_rate:"
                print new_rate
                ref = self.session.nav.getCurrentlyPlayingServiceReference()
                if ref is not None:
                    try:
                        mypath = ref.getPath()
                    except:
                        mypath = ''
                    if mypath != '':
                        if mypath.endswith('.ts'):
                            print "DEBUG VIDEOMODE/ playing .ts file"
                            write_mode = '1080p50'  # for .ts files
                        else:
                            print "DEBUG VIDEOMODE/ playing other (non .ts) file"
                            # write_mode from above for all other videos
                    else:
                        print "DEBUG VIDEOMODE/ no path, presumably live TV"
                        write_mode = '1080p50'  # for for TV
                else:
                    print "DEBUG VIDEOMODE/ no service reference"
                    write_mode = '1080p50'  # no service reference, stay at 1080p50

            if write_mode and current_mode != write_mode and self.bufferfull:
                resolutionlabel["restxt"].setText(
                    _("Video mode: %s") % write_mode)
                if config.av.autores_label_timeout.getValue() != '0':
                    resolutionlabel.show()
                print "[VideoMode] setMode - port: %s, mode: %s" % (
                    config_port, write_mode)
                f = open("/proc/stb/video/videomode", "w")
                f.write(write_mode)
                f.close()

        iAVSwitch.setAspect(config.av.aspect)
        iAVSwitch.setWss(config.av.wss)
        iAVSwitch.setPolicy43(config.av.policy_43)
        iAVSwitch.setPolicy169(config.av.policy_169)

        self.delay = False
        self.detecttimer.stop()
예제 #7
0
	def VideoChangeDetect(self):
		config_port = config.av.videoport.value
		config_mode = str(config.av.videomode[config_port].value).replace('\n','')
		config_res = str(config.av.videomode[config_port].value[:-1]).replace('\n','')
		config_pol = str(config.av.videomode[config_port].value[-1:]).replace('\n','')
		config_rate = str(config.av.videorate[config_mode].value).replace('Hz','').replace('\n','')

		f = open("/proc/stb/video/videomode")
		current_mode = f.read()[:-1].replace('\n','')
		f.close()
		if current_mode.upper() in ('PAL', 'NTSC'):
			current_mode = current_mode.upper()

		current_pol = ''
		if 'i' in current_mode:
			current_pol = 'i'
		elif 'p' in current_mode:
			current_pol = 'p'
		current_res = current_pol and current_mode.split(current_pol)[0].replace('\n','') or ""
		current_rate = current_pol and current_mode.split(current_pol)[0].replace('\n','') and current_mode.split(current_pol)[1].replace('\n','') or ""

		video_height = None
		video_width = None
		video_pol = None
		video_rate = None
		if path.exists("/proc/stb/vmpeg/0/yres"):
			f = open("/proc/stb/vmpeg/0/yres", "r")
			video_height = int(f.read(),16)
			f.close()
		if path.exists("/proc/stb/vmpeg/0/xres"):
			f = open("/proc/stb/vmpeg/0/xres", "r")
			video_width = int(f.read(),16)
			f.close()
		if path.exists("/proc/stb/vmpeg/0/progressive"):
			f = open("/proc/stb/vmpeg/0/progressive", "r")
			video_pol = "p" if int(f.read(),16) else "i"
			f.close()
		if path.exists("/proc/stb/vmpeg/0/framerate"):
			f = open("/proc/stb/vmpeg/0/framerate", "r")
			try:
				video_rate = int(f.read())
			except:
				video_rate = 50
			f.close()

		if not video_height or not video_width or not video_pol or not video_rate:
			service = self.session.nav.getCurrentService()
			if service is not None:
				info = service.info()
			else:
				info = None

			if info:
				video_height = int(info.getInfo(iServiceInformation.sVideoHeight))
				video_width = int(info.getInfo(iServiceInformation.sVideoWidth))
				video_pol = ("i", "p")[info.getInfo(iServiceInformation.sProgressive)]
				video_rate = int(info.getInfo(iServiceInformation.sFrameRate))

		if video_height and video_width and video_pol and video_rate:
			resolutionlabel["content"].setText(_("Video content: %ix%i%s %iHz") % (video_width, video_height, video_pol, (video_rate + 500) / 1000))
			if video_height != -1:
				if video_height > 720 or video_width > 1280:
					new_res = "1080"
				elif (576 < video_height <= 720) or video_width > 1024:
					new_res = "720"
				elif (480 < video_height <= 576) or video_width > 720 or video_rate in (25000, 23976, 24000):
					new_res = "576"
				else:
					new_res = "480"
			else:
				new_res = config_res

			if video_rate != -1:
				if video_rate == 25000 and video_pol == 'i':
					new_rate = 50000
				elif video_rate == 59940 or (video_rate == 29970 and video_pol == 'i') or (video_rate == 29970 and video_pol == 'p' and config.av.autores.value == 'disabled'): 
					new_rate = 60000
				elif video_rate == 23976:
					new_rate = 24000
				elif video_rate == 29970:
					new_rate = 30000
				else:
					new_rate = video_rate
				new_rate = str((new_rate + 500) / 1000)
			else:
				new_rate = config_rate

			if video_pol != -1:
				new_pol = str(video_pol)
			else:
				new_pol = config_pol

			write_mode = None
			new_mode = None
			if config_mode in ('PAL', 'NTSC'):
				write_mode = config_mode
			elif config.av.autores.value == 'all' or (config.av.autores.value == 'hd' and int(new_res) >= 720):
				if (config.av.autores_deinterlace.value and HardwareInfo().is_nextgen()) or (config.av.autores_deinterlace.value and not HardwareInfo().is_nextgen() and int(new_res) <= 720):
					new_pol = new_pol.replace('i','p')
				if new_res+new_pol+new_rate in iAVSwitch.modes_available:
					new_mode = new_res+new_pol+new_rate
					if new_mode == '720p24':
						new_mode = config.av.autores_720p24.value
					if new_mode == '1080p24':
						new_mode = config.av.autores_1080p24.value
					if new_mode == '1080p25':
						new_mode = config.av.autores_1080p25.value
					if new_mode == '1080p30':
						new_mode = config.av.autores_1080p30.value
				elif new_res+new_pol in iAVSwitch.modes_available:
					new_mode = new_res+new_pol
				else:
					write_mode = config_mode+new_rate

				write_mode = new_mode
			elif config.av.autores.value == 'hd' and int(new_res) <= 576:
				if (config.av.autores_deinterlace.value and HardwareInfo().is_nextgen()) or (config.av.autores_deinterlace.value and not HardwareInfo().is_nextgen() and not config.av.autores_sd.value == '1080i'):
					new_mode = config.av.autores_sd.value.replace('i','p')+new_rate
				else:
					if new_pol in 'p':
						new_mode = config.av.autores_sd.value.replace('i','p')+new_rate
					else:
						new_mode = config.av.autores_sd.value+new_rate

				if new_mode == '720p24':
					new_mode = config.av.autores_720p24.value
				if new_mode == '1080p24':
					new_mode = config.av.autores_1080p24.value
				if new_mode == '1080p25':
					new_mode = config.av.autores_1080p25.value
				if new_mode == '1080p30':
					new_mode = config.av.autores_1080p30.value

				write_mode = new_mode
			else:
				if path.exists('/proc/stb/video/videomode_%shz' % new_rate) and config_rate == 'multi':
					f = open("/proc/stb/video/videomode_%shz" % new_rate, "r")
					multi_videomode = f.read().replace('\n','')
					f.close()
					if multi_videomode and (current_mode != multi_videomode):
						write_mode = multi_videomode
					else:
						write_mode = config_mode+new_rate

			# workaround for bug, see http://www.opena.tv/forum/showthread.php?1642-Autoresolution-Plugin&p=38836&viewfull=1#post38836
			# always use a fixed resolution and frame rate   (e.g. 1080p50 if supported) for TV or .ts files
			# always use a fixed resolution and correct rate (e.g. 1080p24/p50/p60 for all other videos
			if config.av.smart1080p.value != 'false':
				print "DEBUG VIDEOMODE/ smart1080p enabled"
				ref = self.session.nav.getCurrentlyPlayingServiceReference()
				if ref is not None:
					try:
						mypath = ref.getPath()
					except:
						mypath = ''
				else:
					mypath = ''
				if new_rate == 'multi':
					# no frame rate information available, check if filename (or directory name) contains a hint
					# (allow user to force a frame rate this way):
					if   (mypath.find('p24.') >= 0) or (mypath.find('24p.') >= 0):
						new_rate = '24'
					elif (mypath.find('p25.') >= 0) or (mypath.find('25p.') >= 0):
						new_rate = '25'
					elif (mypath.find('p30.') >= 0) or (mypath.find('30p.') >= 0):
						new_rate = '30'
					elif (mypath.find('p50.') >= 0) or (mypath.find('50p.') >= 0):
						new_rate = '50'
					elif (mypath.find('p60.') >= 0) or (mypath.find('60p.') >= 0):
						new_rate = '60'
					else:
						new_rate = '' # omit frame rate specifier, e.g. '1080p' instead of '1080p50' if there is no clue
				if mypath != '':
					if mypath.endswith('.ts'):
						print "DEBUG VIDEOMODE/ playing .ts file"
						new_rate = '50' # for .ts files
					else:
						print "DEBUG VIDEOMODE/ playing other (non .ts) file"
						# new_rate from above for all other videos
				else:
					print "DEBUG VIDEOMODE/ no path or no service reference, presumably live TV"
					new_rate = '50' # for TV / or no service reference, then stay at 1080p50
				
				new_rate = new_rate.replace('25', '50')
				new_rate = new_rate.replace('30', '60')
				
				if  (config.av.smart1080p.value == '1080p50') or (config.av.smart1080p.value == 'true'): # for compatibility with old ConfigEnableDisable
					write_mode = '1080p' + new_rate
				elif config.av.smart1080p.value == '1080i50':
					write_mode = '1080i' + new_rate
				elif config.av.smart1080p.value == '720p50':
					write_mode = '720p' + new_rate

			if write_mode and current_mode != write_mode and self.bufferfull:
				resolutionlabel["restxt"].setText(_("Video mode: %s") % write_mode)
				if config.av.autores_label_timeout.value != '0':
					resolutionlabel.show()
				print "[VideoMode] setMode - port: %s, mode: %s" % (config_port, write_mode)
				f = open("/proc/stb/video/videomode", "w")
				f.write(write_mode)
				f.close()

		iAVSwitch.setAspect(config.av.aspect)
		iAVSwitch.setWss(config.av.wss)
		iAVSwitch.setPolicy43(config.av.policy_43)
		iAVSwitch.setPolicy169(config.av.policy_169)

		self.delay = False
		self.detecttimer.stop()
예제 #8
0
    def VideoChangeDetect(self):
        global resolutionlabel
        config_port = config.av.videoport.value
        config_mode = str(config.av.videomode[config_port].value).replace(
            '\n', '')
        config_res = str(config.av.videomode[config_port].value[:-1]).replace(
            '\n', '')
        config_pol = str(config.av.videomode[config_port].value[-1:]).replace(
            '\n', '')
        config_rate = str(config.av.videorate[config_mode].value).replace(
            'Hz', '').replace('\n', '')

        f = open("/proc/stb/video/videomode")
        current_mode = f.read()[:-1].replace('\n', '')
        f.close()
        if current_mode.upper() in ('PAL', 'NTSC'):
            current_mode = current_mode.upper()

        current_pol = ''
        if 'i' in current_mode:
            current_pol = 'i'
        elif 'p' in current_mode:
            current_pol = 'p'
        current_res = current_pol and current_mode.split(
            current_pol)[0].replace('\n', '') or ""
        current_rate = current_pol and current_mode.split(
            current_pol)[0].replace(
                '\n', '') and current_mode.split(current_pol)[1].replace(
                    '\n', '') or ""

        video_height = None
        video_width = None
        video_pol = None
        video_rate = None
        if path.exists("/proc/stb/vmpeg/0/yres"):
            try:
                f = open("/proc/stb/vmpeg/0/yres", "r")
                video_height = int(f.read(), 16)
                f.close()
            except:
                video_height = 0
        if path.exists("/proc/stb/vmpeg/0/xres"):
            try:
                f = open("/proc/stb/vmpeg/0/xres", "r")
                video_width = int(f.read(), 16)
                f.close()
            except:
                video_width = 0
        if path.exists("/proc/stb/vmpeg/0/progressive"):
            try:
                f = open("/proc/stb/vmpeg/0/progressive", "r")
                video_pol = "p" if int(f.read(), 16) else "i"
                f.close()
            except:
                video_pol = "i"
        if path.exists("/proc/stb/vmpeg/0/framerate"):
            f = open("/proc/stb/vmpeg/0/framerate", "r")
            try:
                video_rate = int(f.read())
            except:
                video_rate = 50
            f.close()

        if not video_height or not video_width or not video_pol or not video_rate:
            service = self.session.nav.getCurrentService()
            if service is not None:
                info = service.info()
            else:
                info = None

            if info:
                video_height = int(
                    info.getInfo(iServiceInformation.sVideoHeight))
                video_width = int(info.getInfo(
                    iServiceInformation.sVideoWidth))
                video_pol = ("i", "p")[info.getInfo(
                    iServiceInformation.sProgressive)]
                video_rate = int(info.getInfo(iServiceInformation.sFrameRate))

        if (video_height and video_width and video_pol
                and video_rate) or (config.av.smart1080p.value != 'false'):
            resolutionlabel["content"].setText(
                _("Video content: %ix%i%s %iHz") %
                (video_width, video_height, video_pol,
                 (video_rate + 500) / 1000))
            if video_height != -1:
                if video_height > 720 or video_width > 1280:
                    new_res = "1080"
                elif (576 < video_height <= 720) or video_width > 1024:
                    new_res = "720"
                elif (480 < video_height <=
                      576) or video_width > 720 or video_rate in (25000, 23976,
                                                                  24000):
                    new_res = "576"
                else:
                    new_res = "480"
            else:
                new_res = config_res

            if video_rate != -1:
                if video_rate == 25000 and video_pol == 'i':
                    new_rate = 50000
                elif video_rate == 59940 or (
                        video_rate == 29970 and video_pol
                        == 'i') or (video_rate == 29970 and video_pol == 'p'
                                    and config.av.autores.value == 'disabled'):
                    new_rate = 60000
                elif video_rate == 23976:
                    new_rate = 24000
                elif video_rate == 29970:
                    new_rate = 30000
                else:
                    new_rate = video_rate
                new_rate = str((new_rate + 500) / 1000)
            else:
                new_rate = config_rate

            if video_pol != -1:
                new_pol = str(video_pol)
            else:
                new_pol = config_pol

            write_mode = None
            new_mode = None
            if config_mode in ('PAL', 'NTSC'):
                write_mode = config_mode
            elif config.av.autores.value == 'all' or (
                    config.av.autores.value == 'hd' and int(new_res) >= 720):
                if (config.av.autores_deinterlace.value
                        and HardwareInfo().is_nextgen()) or (
                            config.av.autores_deinterlace.value
                            and not HardwareInfo().is_nextgen()
                            and int(new_res) <= 720):
                    new_pol = new_pol.replace('i', 'p')
                if new_res + new_pol + new_rate in iAVSwitch.modes_available:
                    new_mode = new_res + new_pol + new_rate
                    if new_mode == '480p24' or new_mode == '576p24':
                        new_mode = config.av.autores_480p24.value
                    if new_mode == '720p24':
                        new_mode = config.av.autores_720p24.value
                    if new_mode == '1080p24':
                        new_mode = config.av.autores_1080p24.value
                    if new_mode == '1080p25':
                        new_mode = config.av.autores_1080p25.value
                    if new_mode == '1080p30':
                        new_mode = config.av.autores_1080p30.value
                elif new_res + new_pol in iAVSwitch.modes_available:
                    new_mode = new_res + new_pol
                else:
                    new_mode = config_mode + new_rate

                write_mode = new_mode
            elif config.av.autores.value == 'hd' and int(new_res) <= 576:
                if (config.av.autores_deinterlace.value
                        and HardwareInfo().is_nextgen()) or (
                            config.av.autores_deinterlace.value
                            and not HardwareInfo().is_nextgen()
                            and not config.av.autores_sd.value == '1080i'):
                    new_mode = config.av.autores_sd.value.replace(
                        'i', 'p') + new_rate
                else:
                    if new_pol in 'p':
                        new_mode = config.av.autores_sd.value.replace(
                            'i', 'p') + new_rate
                    else:
                        new_mode = config.av.autores_sd.value + new_rate

                if new_mode == '720p24':
                    new_mode = config.av.autores_720p24.value
                if new_mode == '1080p24':
                    new_mode = config.av.autores_1080p24.value
                if new_mode == '1080p25':
                    new_mode = config.av.autores_1080p25.value
                if new_mode == '1080p30':
                    new_mode = config.av.autores_1080p30.value

                write_mode = new_mode
            else:
                if path.exists('/proc/stb/video/videomode_%shz' %
                               new_rate) and config_rate == 'multi':
                    f = open("/proc/stb/video/videomode_%shz" % new_rate, "r")
                    multi_videomode = f.read().replace('\n', '')
                    f.close()
                    if multi_videomode and (current_mode != multi_videomode):
                        write_mode = multi_videomode
                    else:
                        write_mode = config_mode + new_rate

            # workaround for bug, see http://www.opena.tv/forum/showthread.php?1642-Autoresolution-Plugin&p=38836&viewfull=1#post38836
            # always use a fixed resolution and frame rate   (e.g. 1080p50 if supported) for TV or .ts files
            # always use a fixed resolution and correct rate (e.g. 1080p24/p50/p60 for all other videos
            if config.av.smart1080p.value != 'false':
                print "DEBUG VIDEOMODE/ smart1080p enabled"
                ref = self.session.nav.getCurrentlyPlayingServiceReference()
                if ref is not None:
                    try:
                        mypath = ref.getPath()
                    except:
                        mypath = ''
                else:
                    mypath = ''
                if new_rate == 'multi':
                    # no frame rate information available, check if filename (or directory name) contains a hint
                    # (allow user to force a frame rate this way):
                    if (mypath.find('p24.') >= 0) or (mypath.find('24p.') >=
                                                      0):
                        new_rate = '24'
                    elif (mypath.find('p25.') >= 0) or (mypath.find('25p.') >=
                                                        0):
                        new_rate = '25'
                    elif (mypath.find('p30.') >= 0) or (mypath.find('30p.') >=
                                                        0):
                        new_rate = '30'
                    elif (mypath.find('p50.') >= 0) or (mypath.find('50p.') >=
                                                        0):
                        new_rate = '50'
                    elif (mypath.find('p60.') >= 0) or (mypath.find('60p.') >=
                                                        0):
                        new_rate = '60'
                    else:
                        new_rate = ''  # omit frame rate specifier, e.g. '1080p' instead of '1080p50' if there is no clue
                if mypath != '':
                    if mypath.endswith('.ts'):
                        print "DEBUG VIDEOMODE/ playing .ts file"
                        new_rate = '50'  # for .ts files
                    else:
                        print "DEBUG VIDEOMODE/ playing other (non .ts) file"
                        # new_rate from above for all other videos
                else:
                    print "DEBUG VIDEOMODE/ no path or no service reference, presumably live TV"
                    new_rate = '50'  # for TV / or no service reference, then stay at 1080p50

                new_rate = new_rate.replace('25', '50')
                new_rate = new_rate.replace('30', '60')

                if (config.av.smart1080p.value == '1080p50') or (
                        config.av.smart1080p.value == 'true'
                ):  # for compatibility with old ConfigEnableDisable
                    write_mode = '1080p' + new_rate
                elif config.av.smart1080p.value == '1080i50':
                    write_mode = '1080i' + new_rate
                elif config.av.smart1080p.value == '720p50':
                    write_mode = '720p' + new_rate

            if write_mode and current_mode != write_mode and self.bufferfull:
                resolutionlabel["restxt"].setText(
                    _("Video mode: %s") % write_mode)
                if config.av.autores.value != "disabled" and config.av.autores_label_timeout.value != '0':
                    resolutionlabel.show()
                print "[VideoMode] setMode - port: %s, mode: %s" % (
                    config_port, write_mode)
                f = open("/proc/stb/video/videomode", "w")
                f.write(write_mode)
                f.close()

        iAVSwitch.setAspect(config.av.aspect)
        iAVSwitch.setWss(config.av.wss)
        iAVSwitch.setPolicy43(config.av.policy_43)
        iAVSwitch.setPolicy169(config.av.policy_169)

        self.delay = False
        self.detecttimer.stop()
예제 #9
0
	def VideoChangeDetect(self):
		config_port = config.av.videoport.getValue()
		config_mode = str(config.av.videomode[config_port].getValue()).replace('\n','')
		config_res = str(config.av.videomode[config_port].getValue()[:-1]).replace('\n','')
		config_pol = str(config.av.videomode[config_port].getValue()[-1:]).replace('\n','')
		config_rate = str(config.av.videorate[config_mode].getValue()).replace('Hz','').replace('\n','')

		print 'config port:',config_port
		print 'config mode:',config_mode
		print 'config res:',config_res
		print 'config pol:',config_pol
		print 'config rate:',config_rate
		print ' '

		f = open("/proc/stb/video/videomode")
		current_mode = f.read()[:-1].replace('\n','')
		f.close()
		if current_mode.upper() in ('PAL', 'NTSC'):
			current_mode = current_mode.upper()

		current_pol = ''
		if 'i' in current_mode:
			current_pol = 'i'
		elif 'p' in current_mode:
			current_pol = 'p'
		current_res = current_pol and current_mode.split(current_pol)[0].replace('\n','') or ""
		current_rate = current_pol and current_mode.split(current_pol)[0].replace('\n','') and current_mode.split(current_pol)[1].replace('\n','') or ""

		print 'current mode:',current_mode
		print 'current res:',current_res
		print 'current pol:',current_pol
		print 'current rate:',current_rate
		print ' '


		video_height = None
		video_width = None
		video_pol = None
		video_rate = None
		if path.exists("/proc/stb/vmpeg/0/yres"):
			f = open("/proc/stb/vmpeg/0/yres", "r")
			video_height = int(f.read(),16)
			f.close()
		if path.exists("/proc/stb/vmpeg/0/xres"):
			f = open("/proc/stb/vmpeg/0/xres", "r")
			video_width = int(f.read(),16)
			f.close()
		if path.exists("/proc/stb/vmpeg/0/progressive"):
			f = open("/proc/stb/vmpeg/0/progressive", "r")
			video_pol = "p" if int(f.read(),16) else "i"
			f.close()
		if path.exists("/proc/stb/vmpeg/0/framerate"):
			f = open("/proc/stb/vmpeg/0/framerate", "r")
			try:
				video_rate = int(f.read())
			except:
				video_rate = 50
			f.close()

		if not video_height or not video_width or not video_pol or not video_rate:
			service = self.session.nav.getCurrentService()
			if service is not None:
				info = service.info()
			else:
				info = None

			if info:
				video_height = int(info.getInfo(iServiceInformation.sVideoHeight))
				video_width = int(info.getInfo(iServiceInformation.sVideoWidth))
				video_pol = ("i", "p")[info.getInfo(iServiceInformation.sProgressive)]
				video_rate = int(info.getInfo(iServiceInformation.sFrameRate))

		if video_height and video_width and video_pol and video_rate:
			print 'video height:',video_height
			print 'video width:',video_width
			print 'video pol:',video_pol
			print 'video rate:',video_rate
			print ' '

			resolutionlabel["content"].setText(_("Video content: %ix%i%s %iHz") % (video_width, video_height, video_pol, (video_rate + 500) / 1000))

			if video_height != -1:
				if video_height > 720 or video_width > 1280:
					new_res = "1080"
				elif (video_height > 576 and video_height <= 720) or video_width > 1024:
					new_res = "720"
				elif (video_height > 480 and video_height <= 576) or video_width > 720 or video_rate in (25000, 23976, 24000):
					new_res = "576"
				else:
					new_res = "480"
			else:
				new_res = config_res

			if video_rate != -1:
				print 'VID TEST1'
				if video_rate == 25000 and video_pol == 'i':
					print 'VID TEST2'
					new_rate = 50000
				elif video_rate == 59940 or (video_rate == 29970 and video_pol == 'i') or (video_rate == 29970 and video_pol == 'p' and config.av.autores.getValue() == 'disabled'): 
					print 'VID TEST3'
					new_rate = 60000
				elif video_rate == 23976:
					print 'VID TEST4'
					new_rate = 24000
				elif video_rate == 29970:
					print 'VID TEST5'
					new_rate = 30000
				else:
					print 'VID TEST6'
					new_rate = video_rate
				print 'VID TEST7'
				new_rate = str((new_rate + 500) / 1000)
			else:
				print 'VID TEST8'
				new_rate = config_rate

			if video_pol != -1:
				new_pol = str(video_pol)
			else:
				new_pol = config_pol

			print 'new res:',new_res
			print 'new pol:',new_pol
			print 'new rate:',new_rate

			print 'config.av.autores:',config.av.autores.getValue()
			print 'config.av.autores_sd:',config.av.autores_sd.getValue()
			print 'config.av.autores_deinterlace:',config.av.autores_deinterlace.getValue()
			write_mode = None
			new_mode = None
			if config_mode in ('PAL', 'NTSC'):
				write_mode = config_mode
			elif config.av.autores.getValue() == 'all' or (config.av.autores.getValue() == 'hd' and int(new_res) >= 720):
				if (config.av.autores_deinterlace.getValue() and about.getCPUString() in 'BCM7346B2, BCM7425B2') or config.av.autores_deinterlace.getValue() and about.getCPUString() not in 'BCM7346B2, BCM7425B2' and int(new_res) <= 720:
					print '[VideoMode] deinterlace video'
					new_pol = new_pol.replace('i','p')
				if new_res+new_pol+new_rate in iAVSwitch.modes_available:
					new_mode = new_res+new_pol+new_rate
					if new_mode == '720p24':
						new_mode = config.av.autores_720p24.getValue()
					if new_mode == '1080p24':
						new_mode = config.av.autores_1080p24.getValue()
					if new_mode == '1080p25':
						new_mode = config.av.autores_1080p25.getValue()
					if new_mode == '1080p30':
						new_mode = config.av.autores_1080p30.getValue()
				elif new_res+new_pol in iAVSwitch.modes_available:
					new_mode = new_res+new_pol
				else:
					write_mode = config_mode+new_rate

				print 'new mode:',new_mode

				write_mode = new_mode
			elif config.av.autores.getValue() == 'hd' and int(new_res) <= 576:
				if (config.av.autores_deinterlace.getValue() and about.getCPUString() in 'BCM7346B2, BCM7425B2') or config.av.autores_deinterlace.getValue() and about.getCPUString() not in 'BCM7346B2, BCM7425B2' and not config.av.autores_sd.getValue() in '1080i':
					new_mode = config.av.autores_sd.getValue().replace('i','p')+new_rate
				else:
					if new_pol in ('p'):
						new_mode = config.av.autores_sd.getValue().replace('i','p')+new_rate
					else:
						new_mode = config.av.autores_sd.getValue()+new_rate

				if new_mode == '720p24':
					new_mode = config.av.autores_720p24.getValue()
				if new_mode == '1080p24':
					new_mode = config.av.autores_1080p24.getValue()
				if new_mode == '1080p25':
					new_mode = config.av.autores_1080p25.getValue()
				if new_mode == '1080p30':
					new_mode = config.av.autores_1080p30.getValue()

				write_mode = new_mode
			else:
				if path.exists('/proc/stb/video/videomode_%shz' % new_rate) and config_rate == 'multi':
					f = open("/proc/stb/video/videomode_%shz" % new_rate, "r")
					multi_videomode = f.read().replace('\n','')
					print 'multi_videomode:',multi_videomode
					f.close()
					if multi_videomode and (current_mode != multi_videomode):
						write_mode = multi_videomode
					else:
						write_mode = config_mode+new_rate

				print 'new mode:',write_mode

			print ' '
			print 'CURRENT MODE:',current_mode
			print 'NEW MODE:',write_mode
			print ' '
			if write_mode and current_mode != write_mode and self.bufferfull:
				resolutionlabel["restxt"].setText(_("Video mode: %s") % write_mode)
				if config.av.autores_label_timeout.getValue() != '0':
					resolutionlabel.show()
				print "[VideoMode] setMode - port: %s, mode: %s" % (config_port, write_mode)
				f = open("/proc/stb/video/videomode", "w")
				f.write(write_mode)
				f.close()

		iAVSwitch.setAspect(config.av.aspect)
		iAVSwitch.setWss(config.av.wss)
		iAVSwitch.setPolicy43(config.av.policy_43)
		iAVSwitch.setPolicy169(config.av.policy_169)

		self.delay = False
		self.detecttimer.stop()
예제 #10
0
	def VideoChangeDetect(self):
		self.delay = False

		config_port = config.av.videoport.value
		config_mode = str(config.av.videomode[config_port].value).strip()
		config_res = str(config.av.videomode[config_port].value).strip()[:-1]
		config_rate = str(config.av.videorate[config_mode].value).strip().replace('Hz', '')

		if not (config_rate == "multi" or config.av.autores.value):
			return

		if config_mode.upper() == 'PAL':
			config_mode = "576i"
		if config_mode.upper() == 'NTSC':
			config_mode = "480i"

		f = open("/proc/stb/video/videomode")
		current_mode = f.read().strip()
		f.close()
		if current_mode.upper() == 'PAL':
			current_mode = "576i"
		if current_mode.upper() == 'NTSC':
			current_mode = "480i"

		service = self.session.nav.getCurrentService()
		if not service:
			return

		info = service.info()
		if not info:
			return

		video_height = int(info.getInfo(iServiceInformation.sVideoHeight))
		video_width = int(info.getInfo(iServiceInformation.sVideoWidth))
		video_framerate = int(info.getInfo(iServiceInformation.sFrameRate))
		video_progressive = int(info.getInfo(iServiceInformation.sProgressive))

		if not ((0 < video_height <= 2160) and (0 < video_width <= 4096)):

			def _fromProc(pathname, base=10):
				res = None
				if path.exists(pathname):
					f = open(pathname, "r")
					try:
						val = int(f.read(), base)
						if val >= 0:
							res = val
					except:
						pass
					f.close()
				return res

			video_height = _fromProc("/proc/stb/vmpeg/0/yres", 16)
			video_width = _fromProc("/proc/stb/vmpeg/0/xres", 16)
			video_framerate = _fromProc("/proc/stb/vmpeg/0/framerate")
			video_progressive = _fromProc("/proc/stb/vmpeg/0/progressive")

		if not ((0 < video_height <= 2160) and (0 < video_width <= 4096)):
			print "[VideoMode] Can not determine video characteristics from service or /proc - do nothing"
			return

		if video_progressive == 0:
			video_fieldrate = 2 * video_framerate
		else:
			video_fieldrate = video_framerate

#		print "[VideoMode] VideoChangeDetect current_mode: %s, new width: %d, height: %d, framerate: %d, progressive: %d" % (
#			current_mode, video_width, video_height, video_framerate, video_progressive)

		p_string = ""
		if video_progressive == 0:
			p_string = "i"
		elif video_progressive == 1:
			p_string = "p"

		global resolutionlabel
		resolutionlabel["content"].setText("%s %ix%i%s %iHz" % (_("Video content:"), video_width, video_height, p_string, (video_fieldrate + 500) / 1000))

		if (700 < video_width <= 720) and video_height <= 480 and video_framerate in (23976, 24000, 29970, 30000, 59940, 60000):
			new_res = "480"
		elif (700 < video_width <= 720) and video_height <= 576 and video_framerate in (25000, 50000):
			new_res = "576"
		elif (video_width == 1280) and video_height <=720:
			new_res = "720"
		else:
			new_res = config_res

		new_rate = config_rate

		if config.av.autores.value and video_framerate > 0:
			new_rate = str((video_fieldrate + 500) / 1000)

		if new_rate == "multi":
			if video_framerate in (25000, 50000):
				new_rate = "50"
			else:
				new_rate = "60"

		new_mode = None
		if config.av.autores.value:
			if new_res == "480" and new_rate == "24":
				new_mode = config.av.autores_sd24.value
			elif new_res == "576" and new_rate == "25":
				new_mode = config.av.autores_sd25.value
			elif new_res == "480" and new_rate == "30":
				new_mode = config.av.autores_sd30.value
			elif new_res == "576" and new_rate == "50" and video_progressive == 0:
				new_mode = config.av.autores_sd50i.value
			elif new_res == "576" and new_rate == "50" and video_progressive == 1:
				new_mode = config.av.autores_sd50p.value
			elif new_res == "480" and new_rate == "60" and video_progressive == 0:
				new_mode = config.av.autores_sd60i.value
			elif new_res == "480" and new_rate == "60" and video_progressive == 1:
				new_mode = config.av.autores_sd60p.value
			elif new_res == "720" and new_rate == "24":
				new_mode = config.av.autores_ed24.value
			elif new_res == "720" and new_rate == "25":
				new_mode = config.av.autores_ed25.value
			elif new_res == "720" and new_rate == "30":
				new_mode = config.av.autores_ed30.value
			elif new_res == "720" and new_rate == "50":
				new_mode = config.av.autores_ed50.value
			elif new_res == "720" and new_rate == "60":
				new_mode = config.av.autores_ed60.value
			elif new_res == "1080" and new_rate == "24":
				new_mode = config.av.autores_hd24.value
			elif new_res == "1080" and new_rate == "25":
				new_mode = config.av.autores_hd25.value
			elif new_res == "1080" and new_rate == "30":
				new_mode = config.av.autores_hd30.value
			elif new_res == "1080" and new_rate == "50":
				new_mode = config.av.autores_hd50.value
			elif new_res == "1080" and new_rate == "60":
				new_mode = config.av.autores_hd60.value
			else:
				print "[VideoMode] autores could not find a mode for res=%s, rate=%s" % (new_res, new_rate)
		elif config_rate == 'multi' and path.exists('/proc/stb/video/videomode_%shz' % new_rate):
			try:
				f = open("/proc/stb/video/videomode_%shz" % new_rate, "r")
				multi_videomode = f.read().strip()
				f.close()
				if multi_videomode:
					new_mode = multi_videomode
			except:
				print "[VideoMode] exception when trying to find multi mode for", new_rate

		if not new_mode:
			print "[VideoMode] still don't have a new_mode making one from config_mode=%s, newrate=%s" % (config_mode, new_rate)
			new_mode = config_mode + new_rate

		if new_mode != current_mode:
			try:
				f = open("/proc/stb/video/videomode", "w")
				f.write(new_mode)
				f.close()

				resolutionlabel["restxt"].setText(_("Video mode: %s") % new_mode)
				resolutionlabel.hide()  # Need to hide then show to restart the timer
				if config.av.autores.value and int(config.av.autores_label_timeout.value) > 0:
					resolutionlabel.show()
			except:
				print "[VideoMode] FAILED to setMode - port: %s, mode: %s" % (config_port, new_mode)

		iAVSwitch.setAspect(config.av.aspect)
		iAVSwitch.setWss(config.av.wss)
		iAVSwitch.setPolicy43(config.av.policy_43)
		iAVSwitch.setPolicy169(config.av.policy_169)
예제 #11
0
파일: VideoMode.py 프로젝트: zukon/enigma2
    def VideoChangeDetect(self):
        global resolutionlabel
        config_port = config.av.videoport.value
        config_mode = str(config.av.videomode[config_port].value).replace(
            "\n", "")
        config_res = str(config.av.videomode[config_port].value[:-1]).replace(
            "\n", "")
        config_pol = str(config.av.videomode[config_port].value[-1:]).replace(
            "\n", "")
        config_rate = str(config.av.videorate[config_mode].value).replace(
            "Hz", "").replace("\n", "")
        with open("/proc/stb/video/videomode", "r") as fd:
            current_mode = fd.read()[:-1].replace("\n", "")
        if current_mode.upper() in ("PAL", "NTSC"):
            current_mode = current_mode.upper()
        current_pol = ""
        if "i" in current_mode:
            current_pol = "i"
        elif "p" in current_mode:
            current_pol = "p"
        current_res = current_pol and current_mode.split(
            current_pol)[0].replace("\n", "") or ""
        current_rate = current_pol and current_mode.split(
            current_pol)[0].replace(
                "\n", "") and current_mode.split(current_pol)[1].replace(
                    "\n", "") or ""
        video_height = None
        video_width = None
        video_pol = None
        video_rate = None
        if path.exists("/proc/stb/vmpeg/0/yres"):
            with open("/proc/stb/vmpeg/0/yres", "r") as fd:
                try:
                    video_height = int(fd.read(), 16)
                except Exception:
                    pass
        if path.exists("/proc/stb/vmpeg/0/xres"):
            with open("/proc/stb/vmpeg/0/xres", "r") as fd:
                try:
                    video_width = int(fd.read(), 16)
                except Exception:
                    pass
        if path.exists("/proc/stb/vmpeg/0/progressive"):
            with open("/proc/stb/vmpeg/0/progressive", "r") as fd:
                try:
                    video_pol = "p" if int(fd.read(), 16) else "i"
                except Exception:
                    pass
        if path.exists("/proc/stb/vmpeg/0/framerate"):
            with open("/proc/stb/vmpeg/0/framerate", "r") as fd:
                try:
                    video_rate = int(fd.read())
                except Exception:
                    pass
        if not video_height or not video_width or not video_pol or not video_rate:
            service = self.session.nav.getCurrentService()
            if service is not None:
                info = service.info()
            else:
                info = None
            if info:
                video_height = int(
                    info.getInfo(iServiceInformation.sVideoHeight))
                video_width = int(info.getInfo(
                    iServiceInformation.sVideoWidth))
                video_pol = ("i", "p")[info.getInfo(
                    iServiceInformation.sProgressive)]
                video_rate = int(info.getInfo(iServiceInformation.sFrameRate))
        if video_height and video_width and video_pol and video_rate:
            resolutionlabel["content"].setText(
                _("Video content: %ix%i%s %iHz") %
                (video_width, video_height, video_pol,
                 (video_rate + 500) // 1000))
            if (1 < video_width <=
                    1024) and video_height <= 480 and video_rate in (
                        23976, 24000, 25000, 29970, 50000, 59940):
                new_res = "480"
            elif (1 < video_width <= 1024
                  ) and video_height <= 576 and video_rate in (23976, 24000,
                                                               25000, 50000):
                new_res = "576"
            elif (video_width == 1280) and video_height <= 720:
                new_res = "720"
            elif (video_width == 1920) and video_height <= 1080:
                new_res = "1080"
            elif (video_width == 3840) and video_height > 1080:
                new_res = "2160"
            else:
                new_res = config_res
            if video_rate != -1:
                if video_rate == 25000 and video_pol == "i":
                    new_rate = 50000
                elif video_rate == 59940 or (
                        video_rate == 29970 and video_pol
                        == "i") or (video_rate == 29970 and video_pol == "p"
                                    and config.av.autores.value == "disabled"):
                    new_rate = 60000
                elif video_rate == 23976:
                    new_rate = 24000
                elif video_rate == 29970:
                    new_rate = 30000
                else:
                    new_rate = video_rate
                new_rate = str((new_rate + 500) // 1000)
            else:
                new_rate = config_rate

            if video_pol != -1:
                new_pol = str(video_pol)
            else:
                new_pol = config_pol
            write_mode = None
            new_mode = None
            if config_mode in ("PAL", "NTSC"):
                write_mode = config_mode
            elif config.av.autores.value == "all" or (
                    config.av.autores.value == "hd" and int(new_res) >= 720):
                if (config.av.autores_deinterlace.value
                        and HardwareInfo().is_nextgen()) or (
                            config.av.autores_deinterlace.value
                            and not HardwareInfo().is_nextgen()
                            and int(new_res) <= 720):
                    new_pol = new_pol.replace("i", "p")
                if new_res + new_pol + new_rate in iAV.readAvailableModes():
                    new_mode = new_res + new_pol + new_rate
                    if new_mode == "480p24" or new_mode == "576p24":
                        new_mode = config.av.autores_480p24.value
                    if new_mode == "720p24":
                        new_mode = config.av.autores_720p24.value
                    if new_mode == "1080p24":
                        new_mode = config.av.autores_1080p24.value
                    if new_mode == "1080p25":
                        new_mode = config.av.autores_1080p25.value
                    if new_mode == "1080p30":
                        new_mode = config.av.autores_1080p30.value
                    if new_mode == "2160p24":
                        new_mode = config.av.autores_2160p24.value
                    if new_mode == "2160p25" or new_mode == "2160p50":
                        new_mode = config.av.autores_2160p25.value
                    if new_mode == "2160p30" or new_mode == "2160p60" or new_mode == "2160p":
                        new_mode = config.av.autores_2160p30.value
                elif new_res + new_pol in iAV.readAvailableModes():
                    new_mode = new_res + new_pol
                    if new_mode == "2160p30" or new_mode == "2160p60" or new_mode == "2160p":
                        new_mode = config.av.autores_2160p30.value
                else:
                    new_mode = config_mode + new_rate
                write_mode = new_mode
            elif config.av.autores.value == "hd" and int(new_res) <= 576:
                if (config.av.autores_deinterlace.value
                        and HardwareInfo().is_nextgen()) or (
                            config.av.autores_deinterlace.value
                            and not HardwareInfo().is_nextgen()
                            and not config.av.autores_sd.value == "1080i"):
                    new_mode = config.av.autores_sd.value.replace(
                        "i", "p") + new_rate
                else:
                    if new_pol in "p":
                        new_mode = config.av.autores_sd.value.replace(
                            "i", "p") + new_rate
                    else:
                        new_mode = config.av.autores_sd.value + new_rate
                if new_mode == "720p24":
                    new_mode = config.av.autores_720p24.value
                if new_mode == "1080p24":
                    new_mode = config.av.autores_1080p24.value
                if new_mode == "1080p25":
                    new_mode = config.av.autores_1080p25.value
                if new_mode == "1080p30":
                    new_mode = config.av.autores_1080p30.value
                if new_mode == "2160p24":
                    new_mode = config.av.autores_2160p24.value
                if new_mode == "2160p25":
                    new_mode = config.av.autores_2160p25.value
                if new_mode == "2160p30":
                    new_mode = config.av.autores_2160p30.value
                write_mode = new_mode
            else:
                if path.exists("/proc/stb/video/videomode_%shz" %
                               new_rate) and config_rate == "multi":
                    try:
                        with open("/proc/stb/video/videomode_%shz" % new_rate,
                                  "r") as fd:
                            multi_videomode = fd.read().replace("\n", "")
                        if multi_videomode and (current_mode !=
                                                multi_videomode):
                            write_mode = multi_videomode
                        else:
                            write_mode = current_mode
                    except IOError:
                        write_mode = current_mode
            if write_mode and current_mode != write_mode:
                resolutionlabel["restxt"].setText(
                    _("Video mode: %s") % write_mode)
                if config.av.autores.value != "disabled" and config.av.autores_label_timeout.value != "0":
                    resolutionlabel.show()
                print("[VideoMode] setMode - port: %s, mode: %s" %
                      (config_port, write_mode))
                with open("/proc/stb/video/videomode", "w") as fd:
                    fd.write(write_mode)
        iAV.setAspect(config.av.aspect)
        iAV.setWss(config.av.wss)
        iAV.setPolicy43(config.av.policy_43)
        iAV.setPolicy169(config.av.policy_169)
        self.delay = False
        self.detecttimer.stop()
예제 #12
0
파일: VideoMode.py 프로젝트: TwolDE2/ATV65
	def VideoChangeDetect(self):
		# info: autoresolution preview or save settings call this function with session = None / ~338, ~374
		global resolutionlabel
		config_port, config_mode, config_res, config_pol, config_rate = getConfig_videomode(config.av.videomode, config.av.videorate)
		config_mode = config_mode.replace('p30', 'p')

		f = open("/proc/stb/video/videomode")
		current_mode = f.read()[:-1].replace('\n', '')
		f.close()
		if current_mode.upper() in ('PAL', 'NTSC'):
			current_mode = current_mode.upper()

		current_pol = ''
		if 'i' in current_mode:
			current_pol = 'i'
		elif 'p' in current_mode:
			current_pol = 'p'
		current_res = current_pol and current_mode.split(current_pol)[0].replace('\n', '') or ""
		current_rate = current_pol and current_mode.split(current_pol)[0].replace('\n', '') and current_mode.split(current_pol)[1].replace('\n', '') or ""

		write_mode = None
		new_mode = None
		video_height = None
		video_width = None
		video_pol = None
		video_rate = None
		if path.exists("/proc/stb/vmpeg/0/yres"):
			try:
				f = open("/proc/stb/vmpeg/0/yres", "r")
				video_height = int(f.read(), 16)
				f.close()
			except:
				video_height = 0
		if path.exists("/proc/stb/vmpeg/0/xres"):
			try:
				f = open("/proc/stb/vmpeg/0/xres", "r")
				video_width = int(f.read(), 16)
				f.close()
			except:
				video_width = 0
		if path.exists("/proc/stb/vmpeg/0/progressive"):
			try:
				f = open("/proc/stb/vmpeg/0/progressive", "r")
				video_pol = "p" if int(f.read(), 16) else "i"
				f.close()
			except:
				video_pol = "i"
		if path.exists("/proc/stb/vmpeg/0/framerate"):
			f = open("/proc/stb/vmpeg/0/framerate", "r")
			try:
				video_rate = int(f.read())
			except:
				video_rate = 50
			f.close()

		if not video_height or not video_width or not video_pol or not video_rate:
			service = self.session and self.session.nav.getCurrentService()
			if service is not None:
				info = service.info()
			else:
				info = None

			if info:
				video_height = int(info.getInfo(iServiceInformation.sVideoHeight))
				video_width = int(info.getInfo(iServiceInformation.sVideoWidth))
				video_pol = ("i", "p")[info.getInfo(iServiceInformation.sProgressive)]
				video_rate = int(info.getInfo(iServiceInformation.sFrameRate))

		print("[VideoMode] detect video height: %s, width: %s, pol: %s, rate: %s (current video mode: %s)" % (video_height, video_width, video_pol, video_rate, current_mode))
		if video_height and video_width and video_pol and video_rate:
			label_rate = (video_rate + 500) / 1000
			if video_pol == 'i':
				label_rate *= 2
			resolutionlabel["content"].setText(_("Video content: %ix%i%s %iHz") % (video_width, video_height, video_pol, label_rate))
			if video_height != -1:
				if video_height > 720 or video_width > 1280:
					new_res = "1080"
				elif (576 < video_height <= 720) or video_width > 1024:
					new_res = "720"
				elif (480 < video_height <= 576) or video_width > 720 or video_rate in (25000, 23976, 24000):
					new_res = "576"
				else:
					new_res = "480"
			else:
				new_res = config_res

			if video_rate != -1:
				if video_rate == 25000 and video_pol == 'i':
					new_rate = 50000
				elif video_rate == 59940 or (video_rate == 29970 and video_pol == 'i'):
					new_rate = 60000
				elif video_rate == 23976:
					new_rate = 24000
				elif video_rate == 29970:
					new_rate = 30000
				else:
					new_rate = video_rate
				new_rate = str((new_rate + 500) / 1000)
			else:
				new_rate = config_rate

			if video_pol != -1:
				new_pol = str(video_pol)
			else:
				new_pol = config_pol

			autorestyp = ""
			if config_mode in ('PAL', 'NTSC'):
				autorestyp = 'PAL or NTSC'
				write_mode = config_mode

			elif config.av.autores.value == 'simple':
				autorestyp = 'simple'
				new_rate = (video_rate + 500) / 1000
				if video_height <= 576 and int(config_res) >= 576: #sd
					if config.av.autores_rate_sd[config.av.autores_mode_sd[config.av.videoport.value].value].value in ("auto", "multi"):
						if video_pol == 'i':
							new_rate *= 2
					else:
						new_rate = config.av.autores_rate_sd[config.av.autores_mode_sd[config.av.videoport.value].value].value.replace('Hz', '')
					new_mode = config.av.autores_mode_sd[config_port].value.replace('p30', 'p')
				elif video_height <= 720 and int(config_res) >= 720: #hd
					if config.av.autores_rate_hd[config.av.autores_mode_hd[config.av.videoport.value].value].value in ("auto", "multi"):
						if video_pol == 'i':
							new_rate *= 2
					else:
						new_rate = config.av.autores_rate_hd[config.av.autores_mode_hd[config.av.videoport.value].value].value.replace('Hz', '')
					new_mode = config.av.autores_mode_hd[config_port].value.replace('p30', 'p')
				elif video_height <= 1080 and int(config_res) >= 1080: #fhd
					if config.av.autores_rate_fhd[config.av.autores_mode_fhd[config.av.videoport.value].value].value in ("auto", "multi"):
						if video_pol == 'i':
							new_rate *= 2
					else:
						new_rate = config.av.autores_rate_fhd[config.av.autores_mode_fhd[config.av.videoport.value].value].value.replace('Hz', '')
					new_mode = config.av.autores_mode_fhd[config_port].value.replace('p30', 'p')
					if new_mode == '1080p' and not config.av.autores_1080i_deinterlace.value and video_height == 1080 and video_pol == 'i':
						new_mode = '1080i'
				elif video_height <= 2160 and int(config_res) >= 2160: #uhd
					if config.av.autores_rate_uhd[config.av.autores_mode_uhd[config.av.videoport.value].value].value in ("auto", "multi"):
						if video_pol == 'i':
							new_rate *= 2
					else:
						new_rate = config.av.autores_rate_uhd[config.av.autores_mode_uhd[config.av.videoport.value].value].value.replace('Hz', '')
					new_mode = config.av.autores_mode_uhd[config_port].value.replace('p30', 'p')
				else:
					if config_rate not in ("auto", "multi"):
						new_rate = config_rate
					new_mode = config_mode
				new_rate = str(new_rate)

				if new_mode[-1:] == 'p':
					new_rate = setProgressiveRate((video_rate + 500) / 1000 * (int(video_pol == 'i') + 1), new_rate, new_mode[:-1], config_res, config_rate)

				if new_mode + new_rate in iAVSwitch.readAvailableModes():
					write_mode = new_mode + new_rate
				elif new_mode in iAVSwitch.readAvailableModes():
					write_mode = new_mode
				else:
					if config_rate not in ("auto", "multi") and int(new_rate) > int(config_rate):
						new_rate = config_rate
					if config_mode + new_rate in iAVSwitch.readAvailableModes():
						write_mode = config_mode + new_rate
					else:
						write_mode = config_mode

			elif config.av.autores.value == 'native':
				autorestyp = 'native'
				new_rate = (video_rate + 500) / 1000
				new_pol = video_pol
				new_res = str(video_height)
				if video_pol == 'i':
					new_rate *= 2

				min_port, min_mode, min_res, min_pol, min_rate = getConfig_videomode(config.av.autores_mode_sd, config.av.autores_rate_sd)

				if video_height <= int(min_res):
					if new_pol == 'i' and min_pol == 'p':
						new_pol = min_pol
					if min_rate not in ("auto", "multi") and new_rate < int(min_rate):
						new_rate = min_rate
					new_res = min_res
				if video_height >= int(config_res) or int(new_res) >= int(config_res):
					new_res = config_res
					if video_pol == 'p' and config_pol == 'i':
						new_pol = config_pol
					if config_rate not in ("auto", "multi") and int(config_rate) < new_rate:
						new_rate = config_rate
				new_rate = str(new_rate)

				if new_pol == 'p':
					new_rate = setProgressiveRate((video_rate + 500) / 1000 * (int(video_pol == 'i') + 1), new_rate, new_res, config_res, config_rate)

				if new_res + new_pol + new_rate in iAVSwitch.readAvailableModes():
					write_mode = new_res + new_pol + new_rate
				elif new_res + new_pol in iAVSwitch.readAvailableModes():
					write_mode = new_res + new_pol
				elif new_res + min_pol + new_rate in iAVSwitch.readAvailableModes():
					write_mode = new_res + min_pol + new_rate
				elif new_res + min_pol in iAVSwitch.readAvailableModes():
					write_mode = new_res + min_pol
				else:
					if config.av.autores_unknownres.value == 'next':
						if video_height <= 576 and int(config_res) >= 576:
							new_res = '576'
						elif video_height <= 720 and int(config_res) >= 720:
							new_res = '720'
						elif video_height <= 1080 and int(config_res) >= 1080:
							new_res = '1080'
						elif video_height <= 2160 and int(config_res) >= 2160:
							new_res = '2160'
					elif config.av.autores_unknownres.value == 'highest':
						new_res = config_res
					if new_pol == 'p':
						new_rate = setProgressiveRate((video_rate + 500) / 1000 * (int(video_pol == 'i') + 1), new_rate, new_res, config_res, config_rate)
					if new_res + new_pol + new_rate in iAVSwitch.readAvailableModes():
						write_mode = new_res + new_pol + new_rate
					elif new_res + new_pol in iAVSwitch.readAvailableModes():
						write_mode = new_res + new_pol
					elif new_res + min_pol + new_rate in iAVSwitch.readAvailableModes():
						write_mode = new_res + min_pol + new_rate
					elif new_res + min_pol in iAVSwitch.readAvailableModes():
						write_mode = new_res + min_pol
					else:
						if config_rate not in ("auto", "multi") and int(new_rate) > int(config_rate):
							new_rate = config_rate
						if config_mode + new_rate in iAVSwitch.readAvailableModes():
							write_mode = config_mode + new_rate
						else:
							write_mode = config_mode

			elif config.av.autores.value == 'all' or (config.av.autores.value == 'hd' and int(new_res) >= 720):
				autorestyp = 'all or hd'
				if config.av.autores_deinterlace.value:
					new_pol = new_pol.replace('i', 'p')
				if new_res + new_pol + new_rate in iAVSwitch.readAvailableModes():
					new_mode = new_res + new_pol + new_rate
					if new_mode == '480p24' or new_mode == '576p24':
						new_mode = config.av.autores_480p24.value
					if new_mode == '720p24':
						new_mode = config.av.autores_720p24.value
					if new_mode == '1080p24':
						new_mode = config.av.autores_1080p24.value
					if new_mode == '1080p25':
						new_mode = config.av.autores_1080p25.value
					if new_mode == '1080p30':
						new_mode = config.av.autores_1080p30.value
					if new_mode == '2160p24':
						new_mode = config.av.autores_2160p24.value
					if new_mode == '2160p25' or new_mode == '2160p50':
						new_mode = config.av.autores_2160p25.value
					if new_mode == '2160p30' or new_mode == '2160p60' or new_mode == '2160p':
						new_mode = config.av.autores_2160p30.value
				elif new_res + new_pol in iAVSwitch.readAvailableModes():
					new_mode = new_res + new_pol
					if new_mode == '2160p30' or new_mode == '2160p60' or new_mode == '2160p':
						new_mode = config.av.autores_2160p30.value
				else:
					new_mode = config_mode + new_rate

				write_mode = new_mode
			elif config.av.autores.value == 'hd' and int(new_res) <= 576:
				autorestyp = 'hd'
				if new_pol == "p":
					new_mode = config.av.autores_sd.value.replace('i', 'p') + new_rate
				else:
					new_mode = config.av.autores_sd.value + new_rate
					if config.av.autores_deinterlace.value:
						test_new_mode = config.av.autores_sd.value.replace('i', 'p') + new_rate
						if test_new_mode in iAVSwitch.readAvailableModes():
							new_mode = test_new_mode

				if new_mode == '720p24':
					new_mode = config.av.autores_720p24.value
				if new_mode == '1080p24':
					new_mode = config.av.autores_1080p24.value
				if new_mode == '1080p25':
					new_mode = config.av.autores_1080p25.value
				if new_mode == '1080p30':
					new_mode = config.av.autores_1080p30.value
				if new_mode == '2160p24':
					new_mode = config.av.autores_2160p24.value
				if new_mode == '2160p25':
					new_mode = config.av.autores_2160p25.value
				if new_mode == '2160p30':
					new_mode = config.av.autores_2160p30.value

				write_mode = new_mode
			else:
				autorestyp = 'no match'
				if path.exists('/proc/stb/video/videomode_%shz' % new_rate) and config_rate in ("auto", "multi"):
					f = open("/proc/stb/video/videomode_%shz" % new_rate, "r")
					multi_videomode = f.read().replace('\n', '')
					f.close()
					if multi_videomode and (current_mode != multi_videomode):
						write_mode = multi_videomode
					else:
						write_mode = config_mode + new_rate

			# workaround for bug, see https://www.opena.tv/forum/showthread.php?1642-Autoresolution-Plugin&p=38836&viewfull=1#post38836
			# always use a fixed resolution and frame rate   (e.g. 1080p50 if supported) for TV or .ts files
			# always use a fixed resolution and correct rate (e.g. 1080p24/p50/p60 for all other videos
			if config.av.smart1080p.value != 'false' and config.av.autores.value in ('all', 'hd'):
				autorestyp = 'smart1080p mode'
				ref = self.session and self.session.nav.getCurrentlyPlayingServiceReference()
				if ref is not None:
					try:
						mypath = ref.getPath()
					except:
						mypath = ''
				else:
					mypath = ''
				# no frame rate information available, check if filename (or directory name) contains a hint
				# (allow user to force a frame rate this way):
				if (mypath.find('p24.') >= 0) or (mypath.find('24p.') >= 0):
					new_rate = '24'
				elif (mypath.find('p25.') >= 0) or (mypath.find('25p.') >= 0):
					new_rate = '25'
				elif (mypath.find('p30.') >= 0) or (mypath.find('30p.') >= 0):
					new_rate = '30'
				elif (mypath.find('p50.') >= 0) or (mypath.find('50p.') >= 0):
					new_rate = '50'
				elif (mypath.find('p60.') >= 0) or (mypath.find('60p.') >= 0):
					new_rate = '60'
				elif new_rate in ("auto", "multi"):
					new_rate = '' # omit frame rate specifier, e.g. '1080p' instead of '1080p50' if there is no clue
				if mypath != '':
					if mypath.endswith('.ts'):
						print("DEBUG VIDEOMODE/ playing .ts file")
						new_rate = '50' # for .ts files
					else:
						print("DEBUG VIDEOMODE/ playing other (non .ts) file")
						# new_rate from above for all other videos
				else:
					print("DEBUG VIDEOMODE/ no path or no service reference, presumably live TV")
					new_rate = '50' # for TV / or no service reference, then stay at 1080p50

				new_rate = new_rate.replace('25', '50')
				new_rate = new_rate.replace('30', '60')

				if (config.av.smart1080p.value == '1080p50') or (config.av.smart1080p.value == 'true'): # for compatibility with old ConfigEnableDisable
					write_mode = '1080p' + new_rate
				elif config.av.smart1080p.value == '2160p50':
					write_mode = '2160p' + new_rate
				elif config.av.smart1080p.value == '1080i50':
					if new_rate == '24':
						write_mode = '1080p24' # instead of 1080i24
					else:
						write_mode = '1080i' + new_rate
				elif config.av.smart1080p.value == '720p50':
					write_mode = '720p' + new_rate
				#print "[VideoMode] smart1080p mode, selecting ",write_mode

			if write_mode and current_mode != write_mode and self.bufferfull or self.firstrun:
				# first we read now the real available values for every stb,
				# before we try to write the new mode
				changeResolution = False
				try:
					if path.exists("/proc/stb/video/videomode_choices"):
						vf = open("/proc/stb/video/videomode_choices")
						values = vf.readline().replace("\n", "").split(" ", -1)
						for x in values:
							if x == write_mode:
								try:
									f = open("/proc/stb/video/videomode", "w")
									f.write(write_mode)
									f.close()
									changeResolution = True
								except Exception as e:
									print("[VideoMode] write_mode exception:" + str(e))

						if not changeResolution:
							print("[VideoMode] setMode - port: %s, mode: %s is not available" % (config_port, write_mode))
							resolutionlabel["restxt"].setText(_("Video mode: %s not available") % write_mode)
							# we try to go for not available 1080p24/1080p30/1080p60 to change to 1080p from 60hz_choices if available
							# TODO: can we make it easier, or more important --> smaller ?
							# should we outsourced that way, like two new "def ..."
							# or some other stuff, not like this?
							if (write_mode == "1080p24") or (write_mode == "1080p30") or (write_mode == "1080p60"):
								for x in values:
									if x == "1080p":
										try:
											f = open("/proc/stb/video/videomode", "w")
											f.write(x)
											f.close()
											changeResolution = True
										except Exception as e:
											print("[VideoMode] write_mode exception:" + str(e))
								if not changeResolution:
									print("[VideoMode] setMode - port: %s, mode: 1080p is also not available" % config_port)
									resolutionlabel["restxt"].setText(_("Video mode: 1080p also not available"))
								else:
									print("[VideoMode] setMode - port: %s, mode: 1080p" % config_port)
									resolutionlabel["restxt"].setText(_("Video mode: 1080p"))
							if (write_mode == "2160p24") or (write_mode == "2160p30") or (write_mode == "2160p60"):
								for x in values:
									if x == "2160p":
										try:
											f = open("/proc/stb/video/videomode", "w")
											f.write(x)
											f.close()
											changeResolution = True
										except Exception as e:
											print("[VideoMode] write_mode exception:" + str(e))
								if not changeResolution:
									print("[VideoMode] setMode - port: %s, mode: 2160p is also not available" % config_port)
									resolutionlabel["restxt"].setText(_("Video mode: 2160p also not available"))
								else:
									print("[VideoMode] setMode - port: %s, mode: 2160p" % config_port)
									resolutionlabel["restxt"].setText(_("Video mode: 2160p"))
						else:
							resolutionlabel["restxt"].setText(_("Video mode: %s") % write_mode)
							print("[VideoMode] setMode - port: %s, mode: %s (autoresTyp: '%s')" % (config_port, write_mode, autorestyp))
						if config.av.autores_label_timeout.value != '0':
							resolutionlabel.show()
						vf.close()
				except Exception as e:
					print("[VideoMode] read videomode_choices exception:" + str(e))
			elif write_mode and current_mode != write_mode:
				# the resolution remained stuck at a wrong setting after streaming when self.bufferfull was False (should be fixed now after adding BufferInfoStop)
				print("[VideoMode] not changing from", current_mode, "to", write_mode, "as self.bufferfull is", self.bufferfull)

		if write_mode and write_mode != current_mode or self.firstrun:
			iAVSwitch.setAspect(config.av.aspect)
			iAVSwitch.setWss(config.av.wss)
			iAVSwitch.setPolicy43(config.av.policy_43)
			if hasattr(config.av, 'policy_169'):
				iAVSwitch.setPolicy169(config.av.policy_169)

		self.firstrun = False
		self.delay = False
		self.detecttimer.stop()
예제 #13
0
    def VideoChangeDetect(self):
        self.delay = False

        config_port = config.av.videoport.value
        config_mode = str(config.av.videomode[config_port].value).strip()
        config_res = str(config.av.videomode[config_port].value).strip()[:-1]
        config_rate = str(
            config.av.videorate[config_mode].value).strip().replace('Hz', '')

        if not (config_rate == "multi" or config.av.autores.value):
            return

        if config_mode.upper() == 'PAL':
            config_mode = "576i"
        if config_mode.upper() == 'NTSC':
            config_mode = "480i"

        f = open("/proc/stb/video/videomode")
        current_mode = f.read().strip()
        f.close()
        if current_mode.upper() == 'PAL':
            current_mode = "576i"
        if current_mode.upper() == 'NTSC':
            current_mode = "480i"

        service = self.session.nav.getCurrentService()
        if not service:
            return

        info = service.info()
        if not info:
            return

        video_height = int(info.getInfo(iServiceInformation.sVideoHeight))
        video_width = int(info.getInfo(iServiceInformation.sVideoWidth))
        video_framerate = int(info.getInfo(iServiceInformation.sFrameRate))
        video_progressive = int(info.getInfo(iServiceInformation.sProgressive))

        if not ((0 < video_height <= 2160) and (0 < video_width <= 4096)):

            def _fromProc(pathname, base=10):
                res = None
                if path.exists(pathname):
                    f = open(pathname, "r")
                    try:
                        val = int(f.read(), base)
                        if val >= 0:
                            res = val
                    except:
                        pass
                    f.close()
                return res

            video_height = _fromProc("/proc/stb/vmpeg/0/yres", 16)
            video_width = _fromProc("/proc/stb/vmpeg/0/xres", 16)
            video_framerate = _fromProc("/proc/stb/vmpeg/0/framerate")
            video_progressive = _fromProc("/proc/stb/vmpeg/0/progressive")

        if not ((0 < video_height <= 2160) and (0 < video_width <= 4096)):
            print "[VideoMode] Can not determine video characteristics from service or /proc - do nothing"
            return

        if video_progressive == 0:
            video_fieldrate = 2 * video_framerate
        else:
            video_fieldrate = video_framerate


#		print "[VideoMode] VideoChangeDetect current_mode: %s, new width: %d, height: %d, framerate: %d, progressive: %d" % (
#			current_mode, video_width, video_height, video_framerate, video_progressive)

        p_string = ""
        if video_progressive == 0:
            p_string = "i"
        elif video_progressive == 1:
            p_string = "p"

        global resolutionlabel
        resolutionlabel["content"].setText(
            "%s %ix%i%s %iHz" %
            (_("Video content:"), video_width, video_height, p_string,
             (video_fieldrate + 500) / 1000))

        if (700 < video_width <=
                720) and video_height <= 480 and video_framerate in (
                    23976, 24000, 29970, 30000, 59940, 60000):
            new_res = "480"
        elif (700 < video_width <= 720
              ) and video_height <= 576 and video_framerate in (25000, 50000):
            new_res = "576"
        elif (video_width == 1280) and video_height <= 720:
            new_res = "720"
        else:
            new_res = config_res

        new_rate = config_rate

        if config.av.autores.value and video_framerate > 0:
            new_rate = str((video_fieldrate + 500) / 1000)

        if new_rate == "multi":
            if video_framerate in (25000, 50000):
                new_rate = "50"
            else:
                new_rate = "60"

        new_mode = None
        if config.av.autores.value:
            if new_res == "480" and new_rate == "24":
                new_mode = config.av.autores_sd24.value
            elif new_res == "576" and new_rate == "25":
                new_mode = config.av.autores_sd25.value
            elif new_res == "480" and new_rate == "30":
                new_mode = config.av.autores_sd30.value
            elif new_res == "576" and new_rate == "50" and video_progressive == 0:
                new_mode = config.av.autores_sd50i.value
            elif new_res == "576" and new_rate == "50" and video_progressive == 1:
                new_mode = config.av.autores_sd50p.value
            elif new_res == "480" and new_rate == "60" and video_progressive == 0:
                new_mode = config.av.autores_sd60i.value
            elif new_res == "480" and new_rate == "60" and video_progressive == 1:
                new_mode = config.av.autores_sd60p.value
            elif new_res == "720" and new_rate == "24":
                new_mode = config.av.autores_ed24.value
            elif new_res == "720" and new_rate == "25":
                new_mode = config.av.autores_ed25.value
            elif new_res == "720" and new_rate == "30":
                new_mode = config.av.autores_ed30.value
            elif new_res == "720" and new_rate == "50":
                new_mode = config.av.autores_ed50.value
            elif new_res == "720" and new_rate == "60":
                new_mode = config.av.autores_ed60.value
            elif new_res == "1080" and new_rate == "24":
                new_mode = config.av.autores_hd24.value
            elif new_res == "1080" and new_rate == "25":
                new_mode = config.av.autores_hd25.value
            elif new_res == "1080" and new_rate == "30":
                new_mode = config.av.autores_hd30.value
            elif new_res == "1080" and new_rate == "50":
                new_mode = config.av.autores_hd50.value
            elif new_res == "1080" and new_rate == "60":
                new_mode = config.av.autores_hd60.value
            else:
                print "[VideoMode] autores could not find a mode for res=%s, rate=%s" % (
                    new_res, new_rate)
        elif config_rate == 'multi' and path.exists(
                '/proc/stb/video/videomode_%shz' % new_rate):
            try:
                f = open("/proc/stb/video/videomode_%shz" % new_rate, "r")
                multi_videomode = f.read().strip()
                f.close()
                if multi_videomode:
                    new_mode = multi_videomode
            except:
                print "[VideoMode] exception when trying to find multi mode for", new_rate

        if not new_mode:
            print "[VideoMode] still don't have a new_mode making one from config_mode=%s, newrate=%s" % (
                config_mode, new_rate)
            new_mode = config_mode + new_rate

        if new_mode != current_mode:
            try:
                f = open("/proc/stb/video/videomode", "w")
                f.write(new_mode)
                f.close()

                resolutionlabel["restxt"].setText(
                    _("Video mode: %s") % new_mode)
                resolutionlabel.hide(
                )  # Need to hide then show to restart the timer
                if config.av.autores.value and int(
                        config.av.autores_label_timeout.value) > 0:
                    resolutionlabel.show()
            except:
                print "[VideoMode] FAILED to setMode - port: %s, mode: %s" % (
                    config_port, new_mode)

        iAVSwitch.setAspect(config.av.aspect)
        iAVSwitch.setWss(config.av.wss)
        iAVSwitch.setPolicy43(config.av.policy_43)
        iAVSwitch.setPolicy169(config.av.policy_169)
예제 #14
0
    def VideoChangeDetect(self):
        config_port = config.av.videoport.getValue()
        config_mode = str(config.av.videomode[config_port].getValue()).replace(
            '\n', '')
        config_res = str(
            config.av.videomode[config_port].getValue()[:-1]).replace(
                '\n', '')
        config_pol = str(
            config.av.videomode[config_port].getValue()[-1:]).replace(
                '\n', '')
        config_rate = str(config.av.videorate[config_mode].getValue()).replace(
            'Hz', '').replace('\n', '')

        print 'config port:', config_port
        print 'config mode:', config_mode
        print 'config res:', config_res
        print 'config pol:', config_pol
        print 'config rate:', config_rate
        print ' '

        f = open("/proc/stb/video/videomode")
        current_mode = f.read()[:-1].replace('\n', '')
        f.close()
        if current_mode.upper() in ('PAL', 'NTSC'):
            current_mode = current_mode.upper()

        current_pol = ''
        if current_mode.find('i') != -1:
            current_pol = 'i'
        elif current_mode.find('p') != -1:
            current_pol = 'p'
        current_res = current_pol and current_mode.split(
            current_pol)[0].replace('\n', '') or ""
        current_rate = current_pol and current_mode.split(
            current_pol)[0].replace(
                '\n', '') and current_mode.split(current_pol)[1].replace(
                    '\n', '') or ""

        print 'current mode:', current_mode
        print 'current res:', current_res
        print 'current pol:', current_pol
        print 'current rate:', current_rate
        print ' '

        video_height = None
        video_width = None
        video_pol = None
        video_rate = None
        if path.exists("/proc/stb/vmpeg/0/yres"):
            f = open("/proc/stb/vmpeg/0/yres", "r")
            video_height = int(f.read(), 16)
            f.close()
        if path.exists("/proc/stb/vmpeg/0/xres"):
            f = open("/proc/stb/vmpeg/0/xres", "r")
            video_width = int(f.read(), 16)
            f.close()
        if path.exists("/proc/stb/vmpeg/0/progressive"):
            f = open("/proc/stb/vmpeg/0/progressive", "r")
            video_pol = "p" if int(f.read(), 16) else "i"
            f.close()
        if path.exists("/proc/stb/vmpeg/0/framerate"):
            f = open("/proc/stb/vmpeg/0/framerate", "r")
            try:
                video_rate = int(f.read())
            except:
                video_rate = 50
            f.close()

        if not video_height or not video_width or not video_pol or not video_rate:
            service = self.session.nav.getCurrentService()
            if service is not None:
                info = service.info()
            else:
                info = None

            if info:
                video_height = int(
                    info.getInfo(iServiceInformation.sVideoHeight))
                video_width = int(info.getInfo(
                    iServiceInformation.sVideoWidth))
                video_pol = ("i", "p")[info.getInfo(
                    iServiceInformation.sProgressive)]
                video_rate = int(info.getInfo(iServiceInformation.sFrameRate))

        if video_height and video_width and video_pol and video_rate:
            print 'video height:', video_height
            print 'video width:', video_width
            print 'video pol:', video_pol
            print 'video rate:', video_rate
            print ' '

            resolutionlabel["content"].setText(
                _("Video content: %ix%i%s %iHz") %
                (video_width, video_height, video_pol,
                 (video_rate + 500) / 1000))

            if video_height != -1:
                if video_height > 720:
                    new_res = "1080"
                elif video_height > 576 and video_height <= 720:
                    new_res = "720"
                elif video_height > 480 and video_height <= 576:
                    new_res = "576"
                else:
                    new_res = "480"
            else:
                new_res = config_res

            if video_rate != -1:
                if video_rate == 23976:
                    new_rate = 24000
                elif video_rate == 29970 and config.av.autores_all_res.getValue(
                ) and video_pol == 'p':
                    new_rate = 30000
                elif video_rate == 25000 and (
                        not config.av.autores_all_res.getValue()
                        or video_pol == 'i'):
                    new_rate = 50000
                elif video_rate == 59940 or (
                        video_rate == 29970 and
                    (not config.av.autores_all_res.getValue()
                     or video_pol == 'i')):
                    new_rate = 60000
                else:
                    new_rate = video_rate
                new_rate = str((new_rate + 500) / 1000)
            else:
                new_rate = config_rate

            if video_pol != -1:
                new_pol = str(video_pol)
            else:
                new_pol = config_pol

            print 'new res:', new_res
            print 'new pol:', new_pol
            print 'new rate:', new_rate

            print 'config.av.autores:', config.av.autores.getValue()
            write_mode = None
            new_mode = None
            if config_mode in ('PAL', 'NTSC'):
                write_mode = config_mode
            elif config.av.autores.getValue() == 'all' or (
                    config.av.autores.getValue() == 'hd'
                    and int(new_res) >= 720):
                if new_res + new_pol + new_rate in iAVSwitch.modes_available:
                    new_mode = new_res + new_pol + new_rate
                elif new_res + new_pol in iAVSwitch.modes_available:
                    new_mode = new_res + new_pol
                else:
                    write_mode = config_mode + current_rate

                print 'new mode:', new_mode

                write_mode = new_mode
            elif config.av.autores.getValue() == 'hd' and int(new_res) <= 576:
                write_mode = config_res + current_pol + current_rate
            else:
                if path.exists('/proc/stb/video/videomode_%shz' %
                               new_rate) and config_rate == 'multi':
                    f = open("/proc/stb/video/videomode_%shz" % new_rate, "r")
                    multi_videomode = f.read().replace('\n', '')
                    print 'multi_videomode:', multi_videomode
                    f.close()
                    if multi_videomode and (current_mode != multi_videomode):
                        write_mode = multi_videomode
                    else:
                        write_mode = config_mode + current_rate

                print 'new mode:', write_mode

            print ' '
            print 'CURRENT MODE:', current_mode
            print 'NEW MODE:', write_mode
            print ' '
            if write_mode and current_mode != write_mode and self.bufferfull:
                resolutionlabel["restxt"].setText(
                    _("Video mode: %s") % write_mode)
                if config.av.autores_label_timeout.getValue() != '0':
                    resolutionlabel.show()
                print "[VideoMode] setMode - port: %s, mode: %s" % (
                    config_port, write_mode)
                f = open("/proc/stb/video/videomode", "w")
                f.write(write_mode)
                f.close()

        iAVSwitch.setAspect(config.av.aspect)
        iAVSwitch.setWss(config.av.wss)
        iAVSwitch.setPolicy43(config.av.policy_43)
        iAVSwitch.setPolicy169(config.av.policy_169)

        self.delay = False
        self.detecttimer.stop()
예제 #15
0
파일: VideoMode.py 프로젝트: postla/enigma2
	def VideoChangeDetect(self):
		config_port = config.av.videoport.getValue()
		config_mode = str(config.av.videomode[config_port].getValue()).replace('\n','')
		config_res = str(config.av.videomode[config_port].getValue()[:-1]).replace('\n','')
		config_pol = str(config.av.videomode[config_port].getValue()[-1:]).replace('\n','')
		config_rate = str(config.av.videorate[config_mode].getValue()).replace('Hz','').replace('\n','')

		f = open("/proc/stb/video/videomode")
		current_mode = f.read()[:-1].replace('\n','')
		f.close()
		if current_mode.upper() in ('PAL', 'NTSC'):
			current_mode = current_mode.upper()

		current_pol = ''
		if 'i' in current_mode:
			current_pol = 'i'
		elif 'p' in current_mode:
			current_pol = 'p'
		current_res = current_pol and current_mode.split(current_pol)[0].replace('\n','') or ""
		current_rate = current_pol and current_mode.split(current_pol)[0].replace('\n','') and current_mode.split(current_pol)[1].replace('\n','') or ""

		video_height = None
		video_width = None
		video_pol = None
		video_rate = None
		if path.exists("/proc/stb/vmpeg/0/yres"):
			f = open("/proc/stb/vmpeg/0/yres", "r")
			video_height = int(f.read(),16)
			f.close()
		if path.exists("/proc/stb/vmpeg/0/xres"):
			f = open("/proc/stb/vmpeg/0/xres", "r")
			video_width = int(f.read(),16)
			f.close()
		if path.exists("/proc/stb/vmpeg/0/progressive"):
			f = open("/proc/stb/vmpeg/0/progressive", "r")
			video_pol = "p" if int(f.read(),16) else "i"
			f.close()
		if path.exists("/proc/stb/vmpeg/0/framerate"):
			f = open("/proc/stb/vmpeg/0/framerate", "r")
			try:
				video_rate = int(f.read())
			except:
				video_rate = 50
			f.close()

		if not video_height or not video_width or not video_pol or not video_rate:
			service = self.session.nav.getCurrentService()
			if service is not None:
				info = service.info()
			else:
				info = None

			if info:
				video_height = int(info.getInfo(iServiceInformation.sVideoHeight))
				video_width = int(info.getInfo(iServiceInformation.sVideoWidth))
				video_pol = ("i", "p")[info.getInfo(iServiceInformation.sProgressive)]
				video_rate = int(info.getInfo(iServiceInformation.sFrameRate))

		if video_height and video_width and video_pol and video_rate:
			resolutionlabel["content"].setText(_("Video content: %ix%i%s %iHz") % (video_width, video_height, video_pol, (video_rate + 500) / 1000))
			if video_height != -1:
				if video_height > 720 or video_width > 1280:
					new_res = "1080"
				elif (576 < video_height <= 720) or video_width > 1024:
					new_res = "720"
				elif (480 < video_height <= 576) or video_width > 720 or video_rate in (25000, 23976, 24000):
					new_res = "576"
				else:
					new_res = "480"
			else:
				new_res = config_res

			if video_rate != -1:
				if video_rate == 25000 and video_pol == 'i':
					new_rate = 50000
				elif video_rate == 59940 or (video_rate == 29970 and video_pol == 'i') or (video_rate == 29970 and video_pol == 'p' and config.av.autores.getValue() == 'disabled'): 
					new_rate = 60000
				elif video_rate == 23976:
					new_rate = 24000
				elif video_rate == 29970:
					new_rate = 30000
				else:
					new_rate = video_rate
				new_rate = str((new_rate + 500) / 1000)
			else:
				new_rate = config_rate

			if video_pol != -1:
				new_pol = str(video_pol)
			else:
				new_pol = config_pol

			write_mode = None
			new_mode = None
			if config_mode in ('PAL', 'NTSC'):
				write_mode = config_mode
			elif config.av.autores.getValue() == 'all' or (config.av.autores.getValue() == 'hd' and int(new_res) >= 720):
				if (config.av.autores_deinterlace.getValue() and about.getCPUString() in 'BCM7346B2, BCM7425B2') or config.av.autores_deinterlace.getValue() and about.getCPUString() not in 'BCM7346B2, BCM7425B2' and int(new_res) <= 720:
					new_pol = new_pol.replace('i','p')
				if new_res+new_pol+new_rate in iAVSwitch.modes_available:
					new_mode = new_res+new_pol+new_rate
					if new_mode == '720p24':
						new_mode = config.av.autores_720p24.getValue()
					if new_mode == '1080p24':
						new_mode = config.av.autores_1080p24.getValue()
					if new_mode == '1080p25':
						new_mode = config.av.autores_1080p25.getValue()
					if new_mode == '1080p30':
						new_mode = config.av.autores_1080p30.getValue()
				elif new_res+new_pol in iAVSwitch.modes_available:
					new_mode = new_res+new_pol
				else:
					write_mode = config_mode+new_rate

				write_mode = new_mode
			elif config.av.autores.getValue() == 'hd' and int(new_res) <= 576:
				if (config.av.autores_deinterlace.getValue() and about.getCPUString() in 'BCM7346B2, BCM7425B2') or config.av.autores_deinterlace.getValue() and about.getCPUString() not in 'BCM7346B2, BCM7425B2' and not config.av.autores_sd.getValue() in '1080i':
					new_mode = config.av.autores_sd.getValue().replace('i','p')+new_rate
				else:
					if new_pol in 'p':
						new_mode = config.av.autores_sd.getValue().replace('i','p')+new_rate
					else:
						new_mode = config.av.autores_sd.getValue()+new_rate

				if new_mode == '720p24':
					new_mode = config.av.autores_720p24.getValue()
				if new_mode == '1080p24':
					new_mode = config.av.autores_1080p24.getValue()
				if new_mode == '1080p25':
					new_mode = config.av.autores_1080p25.getValue()
				if new_mode == '1080p30':
					new_mode = config.av.autores_1080p30.getValue()

				write_mode = new_mode
			else:
				if path.exists('/proc/stb/video/videomode_%shz' % new_rate) and config_rate == 'multi':
					f = open("/proc/stb/video/videomode_%shz" % new_rate, "r")
					multi_videomode = f.read().replace('\n','')
					f.close()
					if multi_videomode and (current_mode != multi_videomode):
						write_mode = multi_videomode
					else:
						write_mode = config_mode+new_rate

			# workaround for bug, see http://www.opena.tv/forum/showthread.php?1642-Autoresolution-Plugin&p=38836&viewfull=1#post38836
			# always use 1080p50 for TV or .ts files
			# always use 1080p24/p50/p60 for all other videos
			if config.av.smart1080p.getValue():
				print "DEBUG VIDEOMODE/ smart1080p enabled"
				if new_rate == 'multi':
					write_mode = '1080p'
				else:
					new_rate = new_rate.replace('25', '50')
					new_rate = new_rate.replace('30', '60')
					write_mode = '1080p' + new_rate
				print "DEBUG VIDEOMODE/ new_rate:"
				print new_rate	
				ref = self.session.nav.getCurrentlyPlayingServiceReference()
				if ref is not None:
					try:
						mypath = ref.getPath()
					except:
						mypath = ''
					if mypath != '':
						if mypath.endswith('.ts'):
							print "DEBUG VIDEOMODE/ playing .ts file"
							write_mode = '1080p50' # for .ts files
						else:
							print "DEBUG VIDEOMODE/ playing other (non .ts) file"
							# write_mode from above for all other videos
					else:
						print "DEBUG VIDEOMODE/ no path, presumably live TV"
						write_mode = '1080p50' # for for TV
				else:
					print "DEBUG VIDEOMODE/ no service reference"
					write_mode = '1080p50' # no service reference, stay at 1080p50

			if write_mode and current_mode != write_mode and self.bufferfull:
				resolutionlabel["restxt"].setText(_("Video mode: %s") % write_mode)
				if config.av.autores_label_timeout.getValue() != '0':
					resolutionlabel.show()
				print "[VideoMode] setMode - port: %s, mode: %s" % (config_port, write_mode)
				f = open("/proc/stb/video/videomode", "w")
				f.write(write_mode)
				f.close()

		iAVSwitch.setAspect(config.av.aspect)
		iAVSwitch.setWss(config.av.wss)
		iAVSwitch.setPolicy43(config.av.policy_43)
		iAVSwitch.setPolicy169(config.av.policy_169)

		self.delay = False
		self.detecttimer.stop()
예제 #16
0
    def VideoChangeDetect(self):
        global resolutionlabel
        config_port = config.av.videoport.value
        config_mode = str(config.av.videomode[config_port].value).replace(
            '\n', '')
        config_res = str(config.av.videomode[config_port].value[:-1]).replace(
            '\n', '')
        config_pol = str(config.av.videomode[config_port].value[-1:]).replace(
            '\n', '')
        config_rate = str(config.av.videorate[config_mode].value).replace(
            'Hz', '').replace('\n', '')
        f = open('/proc/stb/video/videomode')
        current_mode = f.read()[:-1].replace('\n', '')
        f.close()
        if current_mode.upper() in ('PAL', 'NTSC'):
            current_mode = current_mode.upper()
        current_pol = ''
        if 'i' in current_mode:
            current_pol = 'i'
        elif 'p' in current_mode:
            current_pol = 'p'
        current_res = current_pol and current_mode.split(
            current_pol)[0].replace('\n', '') or ''
        current_rate = current_pol and current_mode.split(
            current_pol)[0].replace(
                '\n', '') and current_mode.split(current_pol)[1].replace(
                    '\n', '') or ''
        video_height = None
        video_width = None
        video_pol = None
        video_rate = None
        if path.exists('/proc/stb/vmpeg/0/yres'):
            try:
                f = open('/proc/stb/vmpeg/0/yres', 'r')
                video_height = int(f.read(), 16)
                f.close()
            except:
                video_height = 0

        if path.exists('/proc/stb/vmpeg/0/xres'):
            try:
                f = open('/proc/stb/vmpeg/0/xres', 'r')
                video_width = int(f.read(), 16)
                f.close()
            except:
                video_width = 0

        if path.exists('/proc/stb/vmpeg/0/progressive'):
            try:
                f = open('/proc/stb/vmpeg/0/progressive', 'r')
                video_pol = 'p' if int(f.read(), 16) else 'i'
                f.close()
            except:
                video_pol = 'i'

        if path.exists('/proc/stb/vmpeg/0/framerate'):
            f = open('/proc/stb/vmpeg/0/framerate', 'r')
            try:
                video_rate = int(f.read())
            except:
                video_rate = 50

            f.close()
        if not video_height or not video_width or not video_pol or not video_rate:
            service = self.session.nav.getCurrentService()
            if service is not None:
                info = service.info()
            else:
                info = None
            if info:
                video_height = int(
                    info.getInfo(iServiceInformation.sVideoHeight))
                video_width = int(info.getInfo(
                    iServiceInformation.sVideoWidth))
                video_pol = ('i', 'p')[info.getInfo(
                    iServiceInformation.sProgressive)]
                video_rate = int(info.getInfo(iServiceInformation.sFrameRate))
        if video_height and video_width and video_pol and video_rate or config.av.smart1080p.value != 'false':
            resolutionlabel['content'].setText(
                _('Video content: %ix%i%s %iHz') %
                (video_width, video_height, video_pol,
                 (video_rate + 500) / 1000))
            if video_height != -1:
                if video_height > 720 or video_width > 1280:
                    new_res = '1080'
                elif 576 < video_height <= 720 or video_width > 1024:
                    new_res = '720'
                elif 480 < video_height <= 576 or video_width > 720 or video_rate in (
                        25000, 23976, 24000):
                    new_res = '576'
                else:
                    new_res = '480'
            else:
                new_res = config_res
            if video_rate != -1:
                if video_rate == 25000 and video_pol == 'i':
                    new_rate = 50000
                elif video_rate == 59940 or video_rate == 29970 and video_pol == 'i' or video_rate == 29970 and video_pol == 'p' and config.av.autores.value == 'disabled':
                    new_rate = 60000
                elif video_rate == 23976:
                    new_rate = 24000
                elif video_rate == 29970:
                    new_rate = 30000
                else:
                    new_rate = video_rate
                new_rate = str((new_rate + 500) / 1000)
            else:
                new_rate = config_rate
            if video_pol != -1:
                new_pol = str(video_pol)
            else:
                new_pol = config_pol
            write_mode = None
            new_mode = None
            if config_mode in ('PAL', 'NTSC'):
                write_mode = config_mode
            elif config.av.autores.value == 'all' or config.av.autores.value == 'hd' and int(
                    new_res) >= 720:
                if config.av.autores_deinterlace.value and HardwareInfo(
                ).is_nextgen(
                ) or config.av.autores_deinterlace.value and not HardwareInfo(
                ).is_nextgen() and int(new_res) <= 720:
                    new_pol = new_pol.replace('i', 'p')
                if new_res + new_pol + new_rate in iAVSwitch.modes_available:
                    new_mode = new_res + new_pol + new_rate
                    if new_mode == '480p24' or new_mode == '576p24':
                        new_mode = config.av.autores_480p24.value
                    if new_mode == '720p24':
                        new_mode = config.av.autores_720p24.value
                    if new_mode == '1080p24':
                        new_mode = config.av.autores_1080p24.value
                    if new_mode == '1080p25':
                        new_mode = config.av.autores_1080p25.value
                    if new_mode == '1080p30':
                        new_mode = config.av.autores_1080p30.value
                elif new_res + new_pol in iAVSwitch.modes_available:
                    new_mode = new_res + new_pol
                else:
                    new_mode = config_mode + new_rate
                write_mode = new_mode
            elif config.av.autores.value == 'hd' and int(new_res) <= 576:
                if config.av.autores_deinterlace.value and HardwareInfo(
                ).is_nextgen(
                ) or config.av.autores_deinterlace.value and not HardwareInfo(
                ).is_nextgen() and not config.av.autores_sd.value == '1080i':
                    new_mode = config.av.autores_sd.value.replace(
                        'i', 'p') + new_rate
                elif new_pol in 'p':
                    new_mode = config.av.autores_sd.value.replace(
                        'i', 'p') + new_rate
                else:
                    new_mode = config.av.autores_sd.value + new_rate
                if new_mode == '720p24':
                    new_mode = config.av.autores_720p24.value
                if new_mode == '1080p24':
                    new_mode = config.av.autores_1080p24.value
                if new_mode == '1080p25':
                    new_mode = config.av.autores_1080p25.value
                if new_mode == '1080p30':
                    new_mode = config.av.autores_1080p30.value
                write_mode = new_mode
            elif path.exists('/proc/stb/video/videomode_%shz' %
                             new_rate) and config_rate == 'multi':
                f = open('/proc/stb/video/videomode_%shz' % new_rate, 'r')
                multi_videomode = f.read().replace('\n', '')
                f.close()
                if multi_videomode and current_mode != multi_videomode:
                    write_mode = multi_videomode
                else:
                    write_mode = config_mode + new_rate
            if config.av.smart1080p.value != 'false':
                print 'DEBUG VIDEOMODE/ smart1080p enabled'
                ref = self.session.nav.getCurrentlyPlayingServiceReference()
                if ref is not None:
                    try:
                        mypath = ref.getPath()
                    except:
                        mypath = ''

                else:
                    mypath = ''
                if new_rate == 'multi':
                    if mypath.find('p24.') >= 0 or mypath.find('24p.') >= 0:
                        new_rate = '24'
                    elif mypath.find('p25.') >= 0 or mypath.find('25p.') >= 0:
                        new_rate = '25'
                    elif mypath.find('p30.') >= 0 or mypath.find('30p.') >= 0:
                        new_rate = '30'
                    elif mypath.find('p50.') >= 0 or mypath.find('50p.') >= 0:
                        new_rate = '50'
                    elif mypath.find('p60.') >= 0 or mypath.find('60p.') >= 0:
                        new_rate = '60'
                    else:
                        new_rate = ''
                if mypath != '':
                    if mypath.endswith('.ts'):
                        print 'DEBUG VIDEOMODE/ playing .ts file'
                        new_rate = '50'
                    else:
                        print 'DEBUG VIDEOMODE/ playing other (non .ts) file'
                else:
                    print 'DEBUG VIDEOMODE/ no path or no service reference, presumably live TV'
                    new_rate = '50'
                new_rate = new_rate.replace('25', '50')
                new_rate = new_rate.replace('30', '60')
                if config.av.smart1080p.value == '1080p50' or config.av.smart1080p.value == 'true':
                    write_mode = '1080p' + new_rate
                elif config.av.smart1080p.value == '1080i50':
                    write_mode = '1080i' + new_rate
                elif config.av.smart1080p.value == '720p50':
                    write_mode = '720p' + new_rate
            if write_mode and current_mode != write_mode and self.bufferfull:
                changeResolution = False
                try:
                    if path.exists('/proc/stb/video/videomode_choices'):
                        vf = open('/proc/stb/video/videomode_choices')
                        values = vf.readline().replace('\n', '').split(' ', -1)
                        for x in values:
                            if x == write_mode:
                                try:
                                    f = open('/proc/stb/video/videomode', 'w')
                                    f.write(write_mode)
                                    f.close()
                                    changeResolution = True
                                except Exception as e:
                                    print '[VideoMode] write_mode exception:' + str(
                                        e)

                        if not changeResolution:
                            print '[VideoMode] setMode - port: %s, mode: %s is not available' % (
                                config_port, write_mode)
                            resolutionlabel['restxt'].setText(
                                _('Video mode: %s not available') % write_mode)
                            if write_mode == '1080p24':
                                for x in values:
                                    if x == '1080p':
                                        try:
                                            f = open(
                                                '/proc/stb/video/videomode',
                                                'w')
                                            f.write(x)
                                            f.close()
                                            changeResolution = True
                                        except Exception as e:
                                            print '[VideoMode] write_mode exception:' + str(
                                                e)

                                if not changeResolution:
                                    print '[VideoMode] setMode - port: %s, mode: 1080p is also not available' % config_port
                                    resolutionlabel['restxt'].setText(
                                        _('Video mode: 1080p also not available'
                                          ))
                                else:
                                    print '[VideoMode] setMode - port: %s, mode: %s' % (
                                        config_port, x)
                                    resolutionlabel['restxt'].setText(
                                        _('Video mode: %s') % x)
                        else:
                            resolutionlabel['restxt'].setText(
                                _('Video mode: %s') % write_mode)
                            print '[VideoMode] setMode - port: %s, mode: %s' % (
                                config_port, write_mode)
                        if config.av.autores.value != 'disabled' and config.av.autores_label_timeout.value != '0':
                            resolutionlabel.show()
                        vf.close()
                except Exception as e:
                    print '[VideoMode] read videomode_choices exception:' + str(
                        e)

        iAVSwitch.setAspect(config.av.aspect)
        iAVSwitch.setWss(config.av.wss)
        iAVSwitch.setPolicy43(config.av.policy_43)
        iAVSwitch.setPolicy169(config.av.policy_169)
        self.delay = False
        self.detecttimer.stop()
        return