From a8734e6c94047e38c83acbac6f1405ff0c7b7b3f Mon Sep 17 00:00:00 2001 From: Saumit Dinesan Date: Fri, 12 May 2023 04:51:34 +0530 Subject: webui: Cleaning up dump+ Livestream IMPLEMENTATION --- webui/website/__init__.py | 7 +++--- webui/website/auth.py | 15 ------------- webui/website/models.py | 0 webui/website/templates/html.html | 44 ------------------------------------ webui/website/templates/live.html | 5 +++-- webui/website/views.py | 47 ++++++++++++++++++++++++++++++++++++++- 6 files changed, 52 insertions(+), 66 deletions(-) delete mode 100644 webui/website/auth.py delete mode 100644 webui/website/models.py delete mode 100644 webui/website/templates/html.html (limited to 'webui/website') diff --git a/webui/website/__init__.py b/webui/website/__init__.py index 4ca4c4b..2af8e41 100644 --- a/webui/website/__init__.py +++ b/webui/website/__init__.py @@ -4,10 +4,9 @@ def create_app(): app = Flask(__name__) app.config['SECRET_KEY'] = 'fdbcawejhfbwef' - from .views import views - from .auth import auth + from .views import views,streaming app.register_blueprint(views, url_prefix='/') - app.register_blueprint(auth, url_prefix='/') + app.register_blueprint(streaming, url_prefix='/') - return app \ No newline at end of file + return app diff --git a/webui/website/auth.py b/webui/website/auth.py deleted file mode 100644 index c44b421..0000000 --- a/webui/website/auth.py +++ /dev/null @@ -1,15 +0,0 @@ -from flask import Blueprint, render_template - -auth = Blueprint('auth', __name__) - -@auth.route('/login') -def login(): - return render_template("404.html") - -@auth.route('/logout') -def logout(): - return render_template("404.html") - -@auth.route('/signup') -def signup(): - return render_template("404.html") \ No newline at end of file diff --git a/webui/website/models.py b/webui/website/models.py deleted file mode 100644 index e69de29..0000000 diff --git a/webui/website/templates/html.html b/webui/website/templates/html.html deleted file mode 100644 index 8387ebb..0000000 --- a/webui/website/templates/html.html +++ /dev/null @@ -1,44 +0,0 @@ - - - - - - - - Document - - - - - - \ No newline at end of file diff --git a/webui/website/templates/live.html b/webui/website/templates/live.html index 5d7d62f..bd71851 100644 --- a/webui/website/templates/live.html +++ b/webui/website/templates/live.html @@ -3,7 +3,8 @@ {% block content %}
-

Hi

+ +

Live-Feed

-{% endblock %} \ No newline at end of file +{% endblock %} diff --git a/webui/website/views.py b/webui/website/views.py index 47a02f5..3523adf 100644 --- a/webui/website/views.py +++ b/webui/website/views.py @@ -1,8 +1,52 @@ -from flask import Blueprint, render_template +from flask import Blueprint, render_template, Response + +import io +import logging +import socketserver +from http import server +from threading import Condition + +from picamera2 import Picamera2 +from picamera2.encoders import JpegEncoder +from picamera2.outputs import FileOutput + views = Blueprint('views', __name__) +streaming = Blueprint('streaming', __name__) + +@streaming.route('/stream') +def stream(): + class StreamingOutput(io.BufferedIOBase): + def __init__(self): + self.frame = None + self.condition = Condition() + + def write(self, buf): + with self.condition: + self.frame = buf + self.condition.notify_all() + + def generate(): + try: + while True: + with output.condition: + output.condition.wait() + frame = output.frame + yield (b'--FRAME\r\n' + b'Content-Type: image/jpeg\r\n\r\n' + frame + b'\r\n') + except Exception as e: + logging.warning('Removed streaming client: %s', str(e)) + + output = StreamingOutput() + picam2 = Picamera2() + picam2.configure(picam2.create_video_configuration(main={"size": (640, 480)})) + picam2.start_recording(JpegEncoder(), FileOutput(output)) + + return Response(generate(), mimetype='multipart/x-mixed-replace; boundary=FRAME') + @views.route('/') +@views.route('/index.html') def home(): return render_template("home.html") @@ -10,3 +54,4 @@ def home(): def live(): return render_template("live.html") +views.register_blueprint(streaming, url_prefix='/stream') -- cgit v1.2.3