| 1 | # Copyright (C) 2007 SPARTA, Inc. |
|---|
| 2 | # This software is licensed under the GPLv3 license, included in |
|---|
| 3 | # ./GPLv3-LICENSE.txt in the source distribution |
|---|
| 4 | |
|---|
| 5 | import os |
|---|
| 6 | import agent |
|---|
| 7 | from distributions import * |
|---|
| 8 | from seerplatform import run, spawn |
|---|
| 9 | |
|---|
| 10 | class StreamingVideoAgent(agent.TrafgenAgent): |
|---|
| 11 | |
|---|
| 12 | agenttype = 'VIDEO' |
|---|
| 13 | |
|---|
| 14 | def __init__(self): |
|---|
| 15 | agent.TrafgenAgent.__init__(self) |
|---|
| 16 | self.addVarType('file', 'string', 'run1150') |
|---|
| 17 | self.addVarType('type', 'string', 'rtp') |
|---|
| 18 | self.addVarType('time', 'string', '100') |
|---|
| 19 | |
|---|
| 20 | def serverExec(self): |
|---|
| 21 | if (self.whiteboard.incAndGet('VIDEO_SERVER_COUNT') == 1): |
|---|
| 22 | self.log.info("Starting video server") |
|---|
| 23 | spawn("SEERVideoServer %s/data" % (os.environ.get('SEERBASE')), self.log) |
|---|
| 24 | |
|---|
| 25 | def serverStop(self): |
|---|
| 26 | if (self.whiteboard.decAndGet('VIDEO_SERVER_COUNT') == 0): |
|---|
| 27 | self.log.info("Stopping video server") |
|---|
| 28 | run("killall SEERVideoServer", self.log) |
|---|
| 29 | |
|---|
| 30 | def clientInit(self): |
|---|
| 31 | """ Save a copy of current variables for client executions """ |
|---|
| 32 | self.file = self.getVar("file") ## filename to use 'minus the .ts part' |
|---|
| 33 | self.type = self.getVar("type") ## udp, rtp or tcp |
|---|
| 34 | self.time = self.getVar("time") ## length to keep streaming |
|---|
| 35 | |
|---|
| 36 | def clientExec(self, src, dst, size): |
|---|
| 37 | cmd = "openRTSP -d %d " % (int(eval(self.time))) |
|---|
| 38 | if (src is not None): |
|---|
| 39 | cmd += "-I %s " % (src) |
|---|
| 40 | |
|---|
| 41 | if (self.type == 'tcp'): |
|---|
| 42 | cmd += "-t rtsp://%s:8554/%s.rtp " % (dst, self.file) |
|---|
| 43 | else: |
|---|
| 44 | cmd += "rtsp://%s:8554/%s.%s " % (dst, self.file, self.type) |
|---|
| 45 | |
|---|
| 46 | # We print this on stdout so it goes with redirected stdout |
|---|
| 47 | print("Starting " + cmd) |
|---|
| 48 | subpid = spawn(cmd, None) |
|---|