#!/usr/bin/env python

import subprocess
import time
import os
import sys

if len (sys.argv) != 2:
  print "Usage: test-launch-client.py <number-of-clients>"
  sys.exit (1)

cmd = "gst-launch-1.0 rtspsrc location=rtsp://127.0.0.1:8554/test latency=300 ! decodebin ! fakesink"
args = cmd.split (" ")

clients_launched = 1
while clients_launched <= int(sys.argv[1]):
  print "launching client %d" % clients_launched
  p = subprocess.Popen (args,
                        stdin=open(os.devnull,'rb'),
                        stdout=open(os.devnull,'wb'),
                        stderr=open(os.devnull,'wb'))
  time.sleep (3)
  p.terminate ()
  clients_launched += 1
