From 36b4078c624994b5d4e51c4bae184bd3f8ac7237 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Wed, 30 Sep 2020 13:59:31 -0400 Subject: [PATCH] Fix ffmpeg --- fakehdhr/__init__.py | 47 +++++++++++++++----------------------------- 1 file changed, 16 insertions(+), 31 deletions(-) diff --git a/fakehdhr/__init__.py b/fakehdhr/__init__.py index 8c8442f..14f07fb 100644 --- a/fakehdhr/__init__.py +++ b/fakehdhr/__init__.py @@ -7,7 +7,6 @@ import json import time import requests import subprocess -import errno import PIL.Image import PIL.ImageDraw import PIL.ImageFont @@ -111,7 +110,7 @@ class HDHR_Hub(): "TunerCount": self.config["fakehdhr"]["tuner_count"], "FirmwareVersion": self.config["dev"]["reporting_firmware_ver"], "DeviceID": self.config["main"]["uuid"], - "DeviceAuth": "nextpvrproxy", + "DeviceAuth": "fHDHR", "BaseURL": "http://" + base_url, "LineupURL": "http://" + base_url + "/lineup.json" } @@ -247,7 +246,7 @@ class HDHR_HTTP_Server(): return Response(image, content_type='image/png', direct_passthrough=True) @app.route('/watch', methods=['GET']) - def watch_nothing(): + def watch(): if 'method' in list(request.args.keys()): if 'channel' in list(request.args.keys()): @@ -283,39 +282,25 @@ class HDHR_HTTP_Server(): "-loglevel", "warning", "pipe:stdout" ] + ffmpeg_proc = subprocess.Popen(ffmpeg_command, stdout=subprocess.PIPE) def generate(): - - videoData = ffmpeg_proc.stdout.read(int(hdhr.config["ffmpeg"]["bytes_per_read"])) - - while True: - if not videoData: - break - else: - # from https://stackoverflow.com/questions/9932332 + try: + while True: + videoData = ffmpeg_proc.stdout.read(int(hdhr.config["ffmpeg"]["bytes_per_read"])) + if not videoData: + break try: yield videoData - time.sleep(0.1) - except IOError as e: - # Check we hit a broken pipe when trying to write back to the client - if e.errno == errno.EPIPE: - # Send SIGTERM to shutdown ffmpeg - ffmpeg_proc.terminate() - # ffmpeg writes a bit of data out to stderr after it terminates, - # need to read any hanging data to prevent a zombie process. - ffmpeg_proc.communicate() - break - else: - raise - - videoData = ffmpeg_proc.stdout.read(int(hdhr.config["ffmpeg"]["bytes_per_read"])) - - ffmpeg_proc.terminate() - try: - ffmpeg_proc.communicate() - except ValueError: - print("Connection Closed") + except Exception as e: + ffmpeg_proc.terminate() + ffmpeg_proc.communicate() + print("Connection Closed: " + str(e)) + except GeneratorExit: + ffmpeg_proc.terminate() + ffmpeg_proc.communicate() + print("Connection Closed.") return Response(stream_with_context(generate()), mimetype="audio/mpeg") abort(404)