def processVideoMessage(): global firstVideo, screen, frameCount while True: ret, data, image, timestamp = ManifoldPython.getMulticastData( videoPort) if not ret: return try: jsonObj = json.loads(data) if firstVideo: firstVideo = False size = (int(jsonObj[vdefs.WIDTH]), int(jsonObj[vdefs.HEIGHT])) screen = pygame.display.set_mode(size) imageFile = cStringIO.StringIO(image) imageSurface = pygame.image.load(imageFile) screen.blit(imageSurface, (0, 0)) pygame.draw.rect(screen, (0, 0, 0), (10, 5, 600, 30)) label = myfont.render( 'Frame rate: %d fps, %s:%03d' % (frameRate, time.ctime(timestamp), (timestamp * 1000) % 1000), 1, (255, 255, 255)) screen.blit(label, (20, 10)) pygame.display.flip() frameCount += 1 except: print("video data error", sys.exc_info()[0], sys.exc_info()[1])
def processReceivedMessage(): # have to throw away frames to ensure queue empty - processing load is too high # in some cases for the forwarding to work correctly while True: global processingFaceRec, faceRecMessage, faceRecImage, processingForward, forwardMessage, forwardImage, forwardTS, inPort ret, data, image, timestamp = ManifoldPython.getMulticastData(inPort) if not ret: return try: if processingForward: continue jsonObj = json.loads(data) if not processingFaceRec: faceRecMessage = copy.deepcopy(jsonObj) faceRecImage = image processingFaceRec=True if not processingForward: forwardMessage = copy.deepcopy(jsonObj) forwardImage = image forwardTS = timestamp processingForward=True except: print ("Receive JSON error", sys.exc_info()[0],sys.exc_info()[1]) return
def receiveThread(): global processing, jsonToProcess, imageToProcess, imageTS, receiveThreadExit while not receiveThreadExit: ret, data, image, timestamp = ManifoldPython.getMulticastData(inPort) if not ret: time.sleep(0.001) continue if processing: time.sleep(0.001) continue try: jsonObj = json.loads(data) if not processing: jsonToProcess = jsonObj imageToProcess = image imageTS = timestamp processing=True except: print ("JSON error", sys.exc_info()[0],sys.exc_info()[1])
def processReceivedText(): ret, data, binaryData, timestamp = ManifoldPython.getMulticastData( ttyInPort) if not ret: return try: print(binaryData) except: print("JSON error", sys.exc_info()[0], sys.exc_info()[1])
def processCompletion(): global completionToProcess, gotCompletion ret, data, binaryData, timestamp = ManifoldPython.getMulticastData(sinkPort) if not ret: return if gotCompletion: return completionToProcess = data gotCompletion = True
def processReceivedMessage(): global topicMap while True: try: ret, data, nothing, timestamp = ManifoldPython.getMulticastData( inPort) if not ret: return topicMap[inTopic].newJSONData(data) except: print("Sensor data error", sys.exc_info()[0], sys.exc_info()[1])
def processReceivedMessage(): global processing, jsonToProcess, imageToProcess, imageTS ret, data, image, timestamp = ManifoldPython.getMulticastData(inPort) if not ret: return try: jsonObj = json.loads(data) if not processing: jsonToProcess = jsonObj imageToProcess = image imageTS = timestamp processing = True except: print("JSON error", sys.exc_info()[0], sys.exc_info()[1])
def audioThread(): firstAudio = True audioStream = None audioDevice = pyaudio.PyAudio() # Activate the audio stream audioPort = ManifoldPython.addMulticastSink(audioTopic) if (audioPort == -1): print("Failed to activate audio stream") ManifoldPython.stop() sys.exit() while not audioThreadExit: ret, data, samples, timestamp = ManifoldPython.getMulticastData( audioPort) if not ret: time.sleep(0.001) continue try: jsonObj = json.loads(data) if firstAudio: firstAudio = False audioStream = audioDevice.open(format=pyaudio.paInt16, channels=int( jsonObj[adefs.CHANNELS]), rate=int(jsonObj[adefs.RATE]), output=True) audioStream.write(samples) except: print("audio data error", sys.exc_info()[0], sys.exc_info()[1]) try: audioStream.stop_stream() audioStream.close() except: pass audioDevice.terminate() ManifoldPython.removeService(audioPort)