Multiple cameras partially working

Change-Id: I27279ef2e3c302946fb25c2a0c5eb32e9279d6b2
diff --git a/Makefile b/Makefile
index 1ca4c1f..3ce37b2 100644
--- a/Makefile
+++ b/Makefile
@@ -24,10 +24,10 @@
 PIP = $(VENV)/bin/pip
 IMAGE = person-detection-app
 
+
 help:
 	echo "$$PROJECT_HELP_MSG" | less
 
-
 $(VENV): $(VENV)/touchfile
 
 $(VENV)/touchfile: requirements.txt
@@ -54,6 +54,9 @@
 run-native-cam: $(VENV)
 	. ./bin/person_detection.sh -i cam
 
+lint:
+	flake8 --exclude=.tox person_detection
+
 test:
 
 
diff --git a/person_detection/app.py b/person_detection/app.py
index 13e7abc..5e3a5c7 100644
--- a/person_detection/app.py
+++ b/person_detection/app.py
@@ -8,7 +8,7 @@
 if os.environ.get('CAMERA'):
     Camera = import_module('camera_' + os.environ['CAMERA']).Camera
 else:
-    #from camera import Camera
+    # from camera import Camera
     from person_detection import Camera
 
 # Raspberry Pi camera module (requires picamera package)
@@ -20,7 +20,7 @@
 @app.route('/')
 def index():
     """Video streaming home page."""
-    return render_template('index.html')
+    return render_template('index.html', devices=[0, 1])
 
 
 def gen(camera):
@@ -30,14 +30,17 @@
         yield (b'--frame\r\n'
                b'Content-Type: image/jpeg\r\n\r\n' + frame + b'\r\n')
 
-
-@app.route('/video_feed')
-def video_feed():
+@app.route('/video_feed/<device>')
+def video_feed(device):
     """Video streaming route. Put this in the src attribute of an img tag."""
-    camera = Camera(args)
+    global args
+    camera = Camera(int(device), args)
     return Response(gen(camera),
                     mimetype='multipart/x-mixed-replace; boundary=frame')
 
+def name_to_port(name):
+    return int(name)
+
 def build_argparser():
     parser = ArgumentParser(add_help=False)
     args = parser.add_argument_group('Options')
@@ -61,6 +64,7 @@
 
     return parser
 
+
 if __name__ == '__main__':
     args = build_argparser().parse_args()
     app.run(host='0.0.0.0', threaded=True)
diff --git a/person_detection/base_camera.py b/person_detection/base_camera.py
index 74b8f08..a479166 100644
--- a/person_detection/base_camera.py
+++ b/person_detection/base_camera.py
@@ -56,6 +56,7 @@
     frame = None  # current frame is stored here by background thread
     last_access = 0  # time of last client access to the camera
     event = CameraEvent()
+    port = 0 # default starting port offset
 
     def __init__(self):
         """Start the background camera thread if it isn't running yet."""
diff --git a/person_detection/person_detection.py b/person_detection/person_detection.py
index f5963fb..32d2bc2 100644
--- a/person_detection/person_detection.py
+++ b/person_detection/person_detection.py
@@ -43,7 +43,7 @@
 
 class Camera(BaseCamera):
 
-    def __init__(self, args):
+    def __init__(self, port, args):
         log.basicConfig(format="[ %(levelname)s ] %(message)s", level=log.INFO, stream=sys.stdout)
         model_xml = args.model
         model_bin = os.path.splitext(model_xml)[0] + ".bin"
@@ -66,7 +66,7 @@
             self.input_stream = 0
         elif args.input == 'gstreamer':
             # gst rtp sink
-            self.input_stream = 'udpsrc port=5000 caps = " application/x-rtp, encoding-name=JPEG,payload=26" ! rtpjpegdepay ! decodebin ! videoconvert ! appsink'
+            self.input_stream = 'udpsrc port=' + port + 'caps = " application/x-rtp, encoding-name=JPEG,payload=26" ! rtpjpegdepay ! decodebin ! videoconvert ! appsink'
             #input_stream = 'udpsrc port=5000 caps = "application/x-rtp, media=(string)video, clock-rate=(int)90000, encoding-name=(string)H264, payload=(int)96" ! rtph264depay ! decodebin ! videoconvert ! appsink'
         else:
             self.input_stream = args.input
@@ -78,6 +78,7 @@
         else:
             self.labels_map = None
 
+        self.port = port
         self.args = args
 
         super(Camera, self).__init__()
diff --git a/person_detection/templates/index.html b/person_detection/templates/index.html
index 26ab1e8..43a4c6b 100644
--- a/person_detection/templates/index.html
+++ b/person_detection/templates/index.html
@@ -4,6 +4,8 @@
   </head>
   <body>
     <h1>Person Detection - Aether Edge Application</h1>
-    <img src="{{ url_for('video_feed') }}">
+    {% for x in devices %}
+      <img src="{{ url_for('video_feed', device=x) }}">
+    {% endfor %}
   </body>
 </html>