Example #1
0
class server:
	"""Servidor"""
	ta = ""
	tv1 = ""
	tv2 = ""
	tv3 = ""
	tv4 = ""

	def __init__(self):
		self.ip_server = "192.168.1.128"
		self.portAudio = 5000
		self.port1 = 5001
		self.port2 = 5002
		self.port3 = 5003
		self.port4 = 5004
		
	
	def configActividad(self):
		NombreActividad= datetime.now().strftime("%d-%m-%Y-%H-%M-%S")
		root = 'db/'+ NombreActividad
		os.makedirs(root, exist_ok=True)
		self.act = actividad(root)
		print("configured activity")
	
	def activate(self):
		self.ta = Audio(ipServer=self.ip_server, portAudio = self.portAudio, file = self.act.data["audioFile"], mg = mg, idAct = self.act.id)
		self.tv1 = Video(ipServer=self.ip_server, port = self.port1, file = self.act.data["video1File"])
		self.tv2 = Video(ipServer=self.ip_server, port = self.port2, file = self.act.data["video2File"])
		self.tv3 = Video(ipServer=self.ip_server, port = self.port3, file = self.act.data["video3File"])
		self.tv4 = Video(ipServer=self.ip_server, port = self.port4, file = self.act.data["video4File"])
		print("activated")

	def start(self):
		self.ta.start()
		self.tv1.start()
		self.tv2.start()
		self.tv3.start()
		self.tv4.start()
		print("listening")
	
	def record(self):
		self.ta.record()
		self.tv1.record()
		self.tv2.record()
		self.tv3.record()
		self.tv4.record()
		self.act.startRecording()
		print("recording")

	def finished(self):
		self.ta.finished()
		self.tv1.finished()
		self.tv2.finished()
		self.tv3.finished()
		self.tv4.finished()
		self.act.endRecording()
		print("finished")
	
	def processVideo(self):
		self.op = OPVideo(mg = mg)
		self.op.getKeyPointsVideo(input = self.act.data["video1File"], outputV = self.act.data["videoout1File"],idact = self.act.id,iduser=0)
		logging.debug("video1")
		self.op = OPVideo(mg = mg)
		self.op.getKeyPointsVideo(input = self.act.data["video2File"], outputV = self.act.data["videoout2File"],idact = self.act.id,iduser=1)
		logging.debug("video2")
		self.op = OPVideo(mg = mg)
		self.op.getKeyPointsVideo(input = self.act.data["video3File"], outputV = self.act.data["videoout3File"],idact = self.act.id,iduser=2)
		logging.debug("video3")
		self.op = OPVideo(mg = mg)
		self.op.getKeyPointsVideo(input = self.act.data["video4File"], outputV = self.act.data["videoout4File"],idact = self.act.id,iduser=3)
		logging.debug("video4")
		del self.op
            tv4.start()
            print("start", flush=True)
            ta.record()
            tv1.record()
            tv2.record()
            tv3.record()
            tv4.record()
            print("record", flush=True)
            newvalues = {"$set": {"startRecording": datetime.today()}}
            mg.update_one("Activities",
                          id=ObjectId(data["id"]),
                          newvalues=newvalues)
            print("startRecording", flush=True)
            time.sleep(int(data["durationOfActivity"]) * 60)
            print("sleep", flush=True)
            ta.finished()
            tv1.finished()
            tv2.finished()
            tv3.finished()
            tv4.finished()
            print("finished", flush=True)
            newvalues = {"$set": {"endRecording": datetime.today()}}
            mg.update_one("Activities",
                          id=ObjectId(data["id"]),
                          newvalues=newvalues)
            print("endRecording", flush=True)
    else:
        print("usage: python " + pidName + ".py start|stop|end|restart",
              flush=True)

#kill main
from audio.audio import Audio
import threading
import logging
from datetime import datetime
import time

if __name__ == '__main__':
    ip_server = "192.168.1.128"
    portAudio = 5000
    output = "audio/outputTest.wav"
    audio = Audio(ipServer=ip_server,
                  portAudio=portAudio,
                  file=output,
                  mode=False)
    audio.start()
    audio.record()
    time.sleep(20)
    audio.finished()