Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use uStreamer launcher. #1252

Merged
merged 13 commits into from
Jan 13, 2023
Merged
9 changes: 4 additions & 5 deletions app/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import update.settings
import update.status
import version
import video_service
import video_settings

api_blueprint = flask.Blueprint('api', __name__, url_prefix='/api')
Expand Down Expand Up @@ -309,10 +310,8 @@ def settings_video_apply_post():
"""Applies the current video settings found in the settings file.

Returns:
Empty response on success, error object otherwise.
Empty response.
"""
try:
video_settings.apply()
except video_settings.Error as e:
return json_response.error(e), 500
video_service.restart()

return json_response.success()
14 changes: 14 additions & 0 deletions app/static/js/controllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -310,3 +310,17 @@ export async function getLicensingMetadata() {
redirect: "error",
}).then(processJsonResponse);
}

export async function isMjpegStreamAvailable() {
try {
const response = await fetch("/stream", {
method: "HEAD",
mode: "same-origin",
cache: "no-cache",
redirect: "error",
});
return response.ok;
} catch (error) {
return false;
}
}
9 changes: 9 additions & 0 deletions app/templates/custom-elements/video-settings-dialog.html
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,9 @@ <h3>Applying Video Settings</h3>
getVideoSettings,
saveVideoSettings,
applyVideoSettings,
isMjpegStreamAvailable,
} from "/js/controllers.js";
import { poll } from "/js/poll.js";

(function () {
const template = document.querySelector("#video-settings-template");
Expand Down Expand Up @@ -445,6 +447,13 @@ <h3>Applying Video Settings</h3>
h264Bitrate: this._getH264Bitrate(),
})
.then(applyVideoSettings)
.then(() =>
poll({
fn: isMjpegStreamAvailable,
validate: (isAvailable) => isAvailable,
interval: 1000,
})
)
.then(() => {
// Note: After the video stream stops, it doesn't try to
// reconnect. So in order to restart the video stream, we need to
Expand Down
39 changes: 0 additions & 39 deletions app/video_settings.py
Original file line number Diff line number Diff line change
@@ -1,42 +1,3 @@
import logging
import subprocess

_UPDATE_SCRIPT_PATH = '/opt/tinypilot-privileged/scripts/update-video-settings'
DEFAULT_FRAME_RATE = 30
DEFAULT_MJPEG_QUALITY = 80
DEFAULT_H264_BITRATE = 5000
logger = logging.getLogger(__name__)


class Error(Exception):
pass


class VideoSettingsUpdateError(Error):
pass


def apply():
"""Apply the current video settings found in the settings file.

This runs the ustreamer ansible role using the systemd-config tag.

Args:
None

Returns:
A string consisting of the stdout and stderr output from the
update-video-settings script.

Raises:
VideoSettingsUpdateError: If the script exits with a non-zero exit code.
"""
logger.info('Running update-video-settings')
try:
output = subprocess.check_output(['sudo', _UPDATE_SCRIPT_PATH],
stderr=subprocess.STDOUT,
universal_newlines=True)
except subprocess.CalledProcessError as e:
raise VideoSettingsUpdateError(str(e.output).strip()) from e
logger.info('update-video-settings completed successfully')
return output
1 change: 1 addition & 0 deletions bundler/bundle/install
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,4 @@ ansible-playbook \
# Persist installation settings.
cp "${INSTALL_SETTINGS_FILE}" "${TINYPILOT_SETTINGS_FILE}"
chown tinypilot:tinypilot "${TINYPILOT_SETTINGS_FILE}"
chmod 0644 "${TINYPILOT_SETTINGS_FILE}"
10 changes: 10 additions & 0 deletions debian-pkg/debian/tinypilot.postinst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ set -u
readonly TINYPILOT_USER="tinypilot"
readonly TINYPILOT_GROUP="tinypilot"
readonly TINYPILOT_HOME_DIR="/home/${TINYPILOT_USER}"
readonly TINYPILOT_SETTINGS_FILE="${TINYPILOT_HOME_DIR}/settings.yml"
readonly USTREAMER_CONFIG_FILE="/opt/ustreamer-launcher/configs.d/100-tinypilot.yml"

# Create tinypilot group if it doesn't already exist.
getent group "${TINYPILOT_GROUP}" > /dev/null || \
Expand All @@ -25,4 +27,12 @@ adduser \

chown -R "${TINYPILOT_USER}:${TINYPILOT_GROUP}" /opt/tinypilot

# Use TinyPilot's settings to override uStreamer's runtime variables.
if [[ ! -L "${USTREAMER_CONFIG_FILE}" ]]; then
ln \
--symbolic \
"${TINYPILOT_SETTINGS_FILE}" \
"${USTREAMER_CONFIG_FILE}"
fi

#DEBHELPER#
1 change: 0 additions & 1 deletion debian-pkg/etc/sudoers.d/tinypilot
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ tinypilot ALL=(ALL) NOPASSWD: /opt/tinypilot-privileged/scripts/change-hostname
tinypilot ALL=(ALL) NOPASSWD: /opt/tinypilot-privileged/scripts/collect-debug-logs
tinypilot ALL=(ALL) NOPASSWD: /opt/tinypilot-privileged/scripts/read-update-log
tinypilot ALL=(ALL) NOPASSWD: /opt/tinypilot-privileged/scripts/update
tinypilot ALL=(ALL) NOPASSWD: /opt/tinypilot-privileged/scripts/update-video-settings
tinypilot ALL=(ALL) NOPASSWD: /sbin/shutdown
tinypilot ALL=(ALL) NOPASSWD: /usr/sbin/service janus restart
tinypilot ALL=(ALL) NOPASSWD: /usr/sbin/service tinypilot-updater start
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ print_info "Checking TinyPilot updater logs..."
print_info "Checking uStreamer configuration..."
{
printf "uStreamer configuration\n"
cat /lib/systemd/system/ustreamer.service
tail --lines +1 /opt/ustreamer-launcher/configs.d/*
printf "\n"
} >> "${LOG_FILE}"

Expand Down
77 changes: 0 additions & 77 deletions debian-pkg/opt/tinypilot-privileged/scripts/update-video-settings

This file was deleted.

9 changes: 0 additions & 9 deletions dev-scripts/mock-scripts/update-video-settings

This file was deleted.