Ejemplo n.º 1
0
    def run(self):

        # Accumulates media bytes
        media_bytes = ''

        # Starts True; set to False by Rover.close()
        while self.rover.is_active:

            # Grab bytes from rover, halting on failure
            try:
                buf = self.rover.mediasock.recv(self.buffer_size)
            except:
                break

            # Do we have a media frame start?
            k = buf.find('MO_V')

            # Yes
            if k >= 0:

                # Already have media bytes?
                if len(media_bytes) > 0:

                    # Yes: add to media bytes up through start of new
                    media_bytes += buf[0:k]

                    # Both video and audio messages are time-stamped in 10msec units
                    timestamp = bytes_to_uint(media_bytes, 23)

                    # Video bytes: call processing routine
                    if ord(media_bytes[4]) == 1:
                        self.rover.process_video_from_rover(
                            media_bytes[36:], timestamp)

                    # Audio bytes: call processing routine
                    else:
                        audio_size = bytes_to_uint(media_bytes, 36)
                        sample_audio_size = 40 + audio_size
                        offset = bytes_to_short(media_bytes, sample_audio_size)
                        index = ord(media_bytes[sample_audio_size + 2])
                        pcmsamples = decodeADPCMToPCM(
                            media_bytes[40:sample_audio_size], offset, index)
                        self.rover.process_audio_from_rover(
                            pcmsamples, timestamp)

                        # Start over with new bytes
                    media_bytes = buf[k:]

                # No media bytes yet: start with new bytes
                else:
                    media_bytes = buf[k:]

            # No: accumulate media bytes
            else:

                media_bytes += buf
Ejemplo n.º 2
0
    def run(self):

        # Accumulates media bytes
        mediabytes = ''

        # Starts True; set to False by Rover.close()
        while self.rover.is_active:

            # Grab bytes from rover, halting on failure
            try:
                buf = self.rover.mediasock.recv(self.BUFSIZE)
            except:
                break

            # Do we have a media frame start?
            k = buf.find('MO_V')

            # Yes
            if k >= 0:

                # Already have media bytes?
                if len(mediabytes) > 0:

                    # Yes: add to media bytes up through start of new
                    mediabytes += buf[0:k]

                    # Both video and audio messages are time-stamped in 10msec units
                    timestamp = bytes_to_uint(mediabytes, 23)

                    # Video bytes: call processing routine
                    if ord(mediabytes[4]) == 1:
                        self.rover.processVideo(mediabytes[36:], timestamp)

                    # Audio bytes: call processing routine
                    else:
                        audsize = bytes_to_uint(mediabytes, 36)
                        sampend = 40 + audsize
                        offset = bytes_to_short(mediabytes, sampend)
                        index = ord(mediabytes[sampend + 2])
                        pcmsamples = decodeADPCMToPCM(mediabytes[40:sampend], offset, index)
                        self.rover.processAudio(pcmsamples, timestamp)

                    # Start over with new bytes
                    mediabytes = buf[k:]

                # No media bytes yet: start with new bytes
                else:
                    mediabytes = buf[k:]

            # No: accumulate media bytes
            else:

                mediabytes += buf
Ejemplo n.º 3
0
    def iterate(self):
        # Starts True; set to False by Rover.close()
        if self.rover.is_active:
            # print "[Python] Acquiring data."

            # Grab bytes from rover, halting on failure
            try:
                buf = self.rover.mediasock.recv(self.BUFSIZE)
            except:
                return

            # Do we have a media frame start?
            k = buf.find('MO_V')

            # Yes
            if k >= 0:

                # Already have media bytes?
                if len(self.mediabytes) > 0:

                    # Yes: add to media bytes up through start of new
                    self.mediabytes += buf[0:k]

                    # Both video and audio messages are time-stamped in 10msec units
                    timestamp = bytes_to_uint(self.mediabytes, 23)

                    # Video bytes: call processing routine
                    if ord(self.mediabytes[4]) == 1:
                        self.rover.processVideo(self.mediabytes[36:],
                                                timestamp)

                    # Audio bytes: call processing routine
                    else:
                        audsize = bytes_to_uint(self.mediabytes, 36)
                        sampend = 40 + audsize
                        offset = bytes_to_short(self.mediabytes, sampend)
                        index = ord(self.mediabytes[sampend + 2])
                        pcmsamples = decodeADPCMToPCM(
                            self.mediabytes[40:sampend], offset, index)
                        # self.rover.processAudio(pcmsamples, timestamp)

                    # Start over with new bytes
                    self.mediabytes = buf[k:]

                # No media bytes yet: start with new bytes
                else:
                    self.mediabytes = buf[k:]

            # No: accumulate media bytes
            else:
                self.mediabytes += buf
Ejemplo n.º 4
0
 def run(self):
                                 
     # Accumulates media bytes
     mediabytes = ''
                         
     # Starts True; set to False by Rover.close()       
     while self.rover.is_active:
         
         # Grab bytes from rover, halting on failure            
         try:
             buf = self.rover.mediasock.recv(self.BUFSIZE)
         except:
             break
                 
         # Do we have a media frame start?        
         k = buf.find('MO_V')
         
         # Yes
         if k  >= 0:
             
             # Already have media bytes?
             if len(mediabytes) > 0:
                 
                 # Yes: add to media bytes up through start of new
                 mediabytes += buf[0:k]
                 
                 # Video bytes: call processing routine
                 if ord(mediabytes[4]) == 1:
                     self.rover.processVideo(mediabytes[36:])
                 
                 # Audio bytes: call processing routine
                 else:
                     offset = bytes_to_short(mediabytes, 200)
                     index  = ord(mediabytes[202])
                     audiobytes = decodeADPCMToPCM(mediabytes[40:200], offset, index)
                     self.rover.processAudio(audiobytes)                    
                     
                 # Start over with new bytes    
                 mediabytes = buf[k:]
          
             # No media bytes yet: start with new bytes
             else:
                 mediabytes = buf[k:]
         
         # No: accumulate media bytes
         else:
       
             mediabytes += buf