Browse Source

re-introduce video-feed

main
Hendrik Langer 4 years ago
parent
commit
a0230e344d
  1. 15
      raspberry/roberto/__init__.py
  2. 2
      raspberry/roberto/camera/base_camera.py
  3. 34
      raspberry/roberto/views/frontend/routes.py

15
raspberry/roberto/__init__.py

@ -7,8 +7,14 @@ from flask_socketio import SocketIO
####################### #######################
#### Configuration #### #### Configuration ####
#https://www.patricksoftwareblog.com/structuring-a-flask-project/ #https://www.patricksoftwareblog.com/structuring-a-flask-project/
####################### #######################
platform = None
try:
import RPi.GPIO as gpio
platform = 'raspberry'
except (ImportError, RuntimeError):
platform = 'generic'
# Create the instances of the Flask extensions (flask-sqlalchemy, flask-login, etc.) in # Create the instances of the Flask extensions (flask-sqlalchemy, flask-login, etc.) in
# the global scope, but without any arguments passed in. These instances are not attached # the global scope, but without any arguments passed in. These instances are not attached
@ -16,8 +22,11 @@ from flask_socketio import SocketIO
login = LoginManager() login = LoginManager()
login.login_view = "users.login" login.login_view = "users.login"
socketio = SocketIO() socketio = SocketIO()
#from roberto.camera.camera_opencv import Camera if platform == 'raspberry':
#camera = Camera() from roberto.camera.camera_pi import Camera
else:
from roberto.camera.camera_opencv import Camera
camera = Camera()
from roberto.camera.camera_gstreamer_webrtc import WebRTCCamera from roberto.camera.camera_gstreamer_webrtc import WebRTCCamera
webrtccamera = WebRTCCamera() webrtccamera = WebRTCCamera()
from roberto.Serial import Serial from roberto.Serial import Serial

2
raspberry/roberto/camera/base_camera.py

@ -97,7 +97,7 @@ class BaseCamera(object):
# if there hasn't been any clients asking for frames in # if there hasn't been any clients asking for frames in
# the last 10 seconds then stop the thread # the last 10 seconds then stop the thread
if time.time() - BaseCamera.last_access > 10: if time.time() - BaseCamera.last_access > 3:
frames_iterator.close() frames_iterator.close()
print('Stopping camera thread due to inactivity.') print('Stopping camera thread due to inactivity.')
break break

34
raspberry/roberto/views/frontend/routes.py

@ -11,23 +11,23 @@ from flask import Response
def index(): def index():
return render_template('index.html') return render_template('index.html')
#def gen(camera): def gen(camera):
# """Video streaming generator function.""" """Video streaming generator function."""
# while True: while True:
# frame = camera.get_frame() frame = camera.get_frame()
# yield (b'--frame\r\n' yield (b'--frame\r\n'
# b'Content-Type: image/jpeg\r\n\r\n' + frame + b'\r\n') b'Content-Type: image/jpeg\r\n\r\n' + frame + b'\r\n')
#
#
#@frontend_blueprint.route('/video_feed') @frontend_blueprint.route('/video_feed')
#def video_feed(): def video_feed():
# """Video streaming route. Put this in the src attribute of an img tag.""" """Video streaming route. Put this in the src attribute of an img tag."""
# from roberto import camera from roberto import camera
# camera.__init__() camera.__init__()
# response = Response(gen(camera), response = Response(gen(camera),
# mimetype='multipart/x-mixed-replace; boundary=frame') mimetype='multipart/x-mixed-replace; boundary=frame')
# response.headers.add('X-Accel-Buffering', 'no') response.headers.add('X-Accel-Buffering', 'no')
# return response return response
@frontend_blueprint.route('/gamepad.js') @frontend_blueprint.route('/gamepad.js')

Loading…
Cancel
Save