Пример #1
0
Файл: xine.py Проект: clones/kaa
    def _handle_command_osd_configure(self, width, height, aspect):
        if not self._osd_shmem:
            shmid = shm.getshmid(self._osd_shmkey)
            if shmid:
                self._osd_shmem = shm.memory(shmid)
                self._osd_shmem.attach()
        if not self._frame_shmem:
            shmid = shm.getshmid(self._frame_shmkey)
            if shmid:
                self._frame_shmem = shm.memory(shmid)
                self._frame_shmem.attach()

        # TODO: remember these values and emit them to new connections to
        # this signal after this point.
        self.signals["osd_configure"].emit(width, height, self._osd_shmem.addr + 16, 
                                           width, height)
Пример #2
0
    def _handle_line(self, line):
        if self._debug:
            if re.search("@@@|outbuf|overlay", line, re.I) and self._debug == 1:
                print line
            elif line[:2] not in ("A:", "V:") and self._debug == 2:
                print line
            elif self._debug == 3:
                print line

        if line.startswith("V:") or line.startswith("A:"):
            m = MPlayer.RE_STATUS.search(line)
            if m:
                old_pos = self._position
                self._position = float((m.group(1) or m.group(2)).replace(",", "."))
                if self._position - old_pos < 0 or self._position - old_pos > 1:
                    self.signals["seek"].emit(self._position)

                # XXX this logic won't work with seek-while-paused patch; state
                # will be "playing" after a seek.
                if self._state == STATE_PAUSED:
                    self.signals["pause_toggle"].emit()
                if self._state not in (STATE_PAUSED, STATE_PLAYING):
                    self.set_frame_output_mode()
                    self._state = STATE_PLAYING
                    self.signals["start"].emit()
                    self.signals["stream_changed"].emit()
                elif self._state != STATE_PLAYING:
                    self._state = STATE_PLAYING
                    self.signals["play"].emit()

        elif line.startswith("  =====  PAUSE"):
            self._state = STATE_PAUSED
            self.signals["pause_toggle"].emit()
            self.signals["pause"].emit()
            
        elif line.startswith("ID_") and line.find("=") != -1:
            attr, value = line.split("=")
            attr = attr[3:]
            info = { "VIDEO_FORMAT": ("vfourcc", str),
                     "VIDEO_BITRATE": ("vbitrate", int),
                     "VIDEO_WIDTH": ("width", int),
                     "VIDEO_HEIGHT": ("height", int),
                     "VIDEO_FPS": ("fps", float),
                     "VIDEO_ASPECT": ("aspect", float),
                     "AUDIO_FORMAT": ("afourcc", str),
                     "AUDIO_CODEC": ("acodec", str),
                     "AUDIO_BITRATE": ("abitrate", int),
                     "LENGTH": ("length", float),
                     "FILENAME": ("filename", str) }
            if attr in info:
                self._file_info[info[attr][0]] = info[attr][1](value)

        elif line.startswith("Movie-Aspect"):
            aspect = line[16:].split(":")[0].replace(",", ".")
            if aspect[0].isdigit():
                self._file_info["aspect"] = float(aspect)

        elif line.startswith("VO:"):
            m = re.search("=> (\d+)x(\d+)", line)
            if m:
                self._vo_size = vo_w, vo_h = int(m.group(1)), int(m.group(2))
                if self._window:
                    self._window.resize(self._vo_size)
                if "aspect" not in self._file_info or self._file_info["aspect"] == 0:
                    # No aspect defined, so base it on vo size.
                    self._file_info["aspect"] = vo_w / float(vo_h)

        elif line.startswith("overlay:") and line.find("reusing") == -1:
            m = re.search("(\d+)x(\d+)", line)
            if m:
                width, height = int(m.group(1)), int(m.group(2))
                try:
                    if self._overlay_shmem:
                        self._overlay_shmem.detach()
                except shm.error:
                    pass
                self._overlay_shmem = shm.memory(shm.getshmid(self._get_overlay_shm_key()))
                self._overlay_shmem.attach()

                self.signals["osd_configure"].emit(width, height, self._overlay_shmem.addr + 16,
                                                   width, height)

        elif line.startswith("outbuf:") and line.find("shmem key") != -1:
            try:
                if self._outbuf_shmem:
                    self._outbuf_shmem.detach()
            except shm.error:
                pass
            self._outbuf_shmem = shm.memory(shm.getshmid(self._get_outbuf_shm_key()))
            self._outbuf_shmem.attach()
            self.set_frame_output_mode()  # Sync

        elif line.startswith("EOF code"):
            if self._state in (STATE_PLAYING, STATE_PAUSED):
                self.signals["end"].emit()
                self._state = STATE_IDLE

        elif line.startswith("Parsing input"):
            # Delete the temporary key input file.
            file = line[line.find("file")+5:]
            os.unlink(file)

        #elif line.startswith("File not found"):
        #    file = line[line.find(":")+2:]
        #    raise IOError, (2, "No such file or directory: %s" % file)

        elif line.startswith("FATAL:"):
            raise MPlayerError, line.strip()

        elif self._debug > 3 and line.startswith("Program received signal SIGSEGV"):
            # Mplayer crashed, issue backtrace.
            self._process.write("thread apply all bt\n")

        if line.strip():
            self.signals["output"].emit(line)
            self._last_line = line
Пример #3
0
    def _child_handle_line(self, line):
        if re.search("@@@|outbuf|overlay", line, re.I):
            childlog(line)
        elif line[:2] not in ("A:", "V:"):
            childlog(line)

        if line.startswith("V:") or line.startswith("A:"):
            m = MPlayer.RE_STATUS.search(line)
            if m:
                old_pos = self.position
                p = (m.group(1) or m.group(2)).replace(",", ".")
                self.position = float(p)
                # if self.position - old_pos < 0 or \
                # self.position - old_pos > 1:
                # self.signals["seek"].emit(self.position)

                # XXX this logic won't work with seek-while-paused patch; state
                # will be "playing" after a seek.
                if self.state == STATE_PAUSED:
                    self.state = STATE_PLAYING
                if self.state == STATE_OPEN:
                    self.set_frame_output_mode()
                    self._mplayer.sub_visibility(False)
                    self.state = STATE_PLAYING
                    self.signals["stream_changed"].emit()

        elif line.startswith("  =====  PAUSE"):
            self.state = STATE_PAUSED

        elif line.startswith("ID_") and line.find("=") != -1:
            attr, value = line.split('=', 1)
            attr = attr[3:]
            info = { "VIDEO_FORMAT": ("vfourcc", str),
                     "VIDEO_BITRATE": ("vbitrate", int),
                     "VIDEO_WIDTH": ("width", int),
                     "VIDEO_HEIGHT": ("height", int),
                     "VIDEO_FPS": ("fps", float),
                     "VIDEO_ASPECT": ("aspect", float),
                     "AUDIO_FORMAT": ("afourcc", str),
                     "AUDIO_CODEC": ("acodec", str),
                     "AUDIO_BITRATE": ("abitrate", int),
                     "AUDIO_NCH": ("channels", int),
                     "LENGTH": ("length", float),
                     "FILENAME": ("filename", str) }
            if attr in info:
                self.streaminfo[info[attr][0]] = info[attr][1](value)

        elif line.startswith("Movie-Aspect"):
            aspect = line[16:].split(":")[0].replace(",", ".")
            if aspect[0].isdigit():
                self.streaminfo["aspect"] = float(aspect)

        elif line.startswith("VO:"):
            m = re.search("=> (\d+)x(\d+)", line)
            if m:
                vo_w, vo_h = int(m.group(1)), int(m.group(2))
                if "aspect" not in self.streaminfo or \
                       self.streaminfo["aspect"] == 0:
                    # No aspect defined, so base it on vo size.
                    self.streaminfo["aspect"] = vo_w / float(vo_h)

        elif line.startswith("overlay:") and line.find("reusing") == -1:
            m = re.search("(\d+)x(\d+)", line)
            if m:
                width, height = int(m.group(1)), int(m.group(2))
                try:
                    if self._osd_shmem:
                        self._osd_shmem.detach()
                except shm.error:
                    pass
                self._osd_shmem = shm.memory(\
                    shm.getshmid(self._osd_shmkey))
                self._osd_shmem.attach()

                self.signals["osd_configure"].emit(\
                    width, height, self._osd_shmem.addr + 16, width, height)

        elif line.startswith("outbuf:") and line.find("shmem key") != -1:
            try:
                if self._frame_shmem:
                    self._frame_shmem.detach()
            except shm.error:
                pass
            self._frame_shmem = shm.memory(shm.getshmid(self._frame_shmkey))
            self._frame_shmem.attach()
            self.set_frame_output_mode()  # Sync

        elif line.startswith("EOF code"):
            if self.state in (STATE_PLAYING, STATE_PAUSED):
                # The player may be idle bow, but we can't set the
                # state. If we do, generic will start a new file while
                # the mplayer process is still running and that does
                # not work. Unless we reuse mplayer proccesses we
                # don't react on EOF and only handle the dead
                # proccess.
                # self.state = STATE_IDLE
                pass

        elif line.startswith("FATAL:"):
            log.error(line.strip())