Skip to content
This repository has been archived by the owner on Aug 27, 2022. It is now read-only.

Commit

Permalink
feature (gphoto preview): allow to start gphoto2 preview in background
Browse files Browse the repository at this point in the history
Change-Id: I93b3d03f4203932aa98b0dae0037446dc26f6a17
  • Loading branch information
andi34 committed Nov 17, 2020
1 parent 2b9ff8e commit 820f408
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 33 deletions.
1 change: 1 addition & 0 deletions config/config.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
// Please read https://github.com/andi34/photobooth/wiki/FAQ#how-to-use-a-live-stream-as-background-at-countdown
// possible preview_mode values: none, device_cam, url, gphoto
$config['preview_mode'] = 'none';
$config['preview_gphoto_bsm'] = true;
$config['previewCamTakesPic'] = false;
$config['previewCamFlipHorizontal'] = true;
// possible ipCamPreviewRotation values: '0deg', '90deg', -90deg', '180deg', '45deg', '-45deg'
Expand Down
5 changes: 5 additions & 0 deletions lib/configsetup.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,11 @@
],
'value' => $config['preview_mode']
],
'preview_gphoto_bsm' => [
'type' => 'checkbox',
'name' => 'preview_gphoto_bsm',
'value' => $config['preview_gphoto_bsm']
],
'previewCamTakesPic' => [
'type' => 'checkbox',
'name' => 'previewCamTakesPic',
Expand Down
2 changes: 2 additions & 0 deletions resources/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@
"manual_previewCamFlipHorizontal": "If enabled, preview from device cam is flipped horizontal.",
"manual_previewCamTakesPic": "If enabled, a picture is taken from device cam instead executing the \"Take picture command\". Please note that the resolution depends on the given hight and width because it's acts like taking a screenshot.",
"manual_preview_camera_mode": "Choose between front- or back facing camera mode of your device cam.",
"manual_preview_gphoto_bsm": "If enabled, gphoto2 live preview is started once a photo get triggered. This results in a delay of ~3 seconds until the preview is visible at countdown. If disabled, a preview is generated in background which results in a high battery usage and also a general slowdown.",
"manual_preview_ipCamPreviewRotation": "Choose to rotate the preview from URL.",
"manual_preview_ipCamURL": "CSS style to use a stream from an URL for preview while countdown. <p>Example: <code>url(../img/bg_bluegray.jpg)</code></p>",
"manual_preview_mode": "Choose a live preview mode. By default live preview is disabled, you can choose between a preview at countdown by your device cam and a preview from a URL. Preview \"from device cam\" will always use the camera of the device where Photobooth get opened in a Browser (e.g. on a tablet it will always show the tablet camera while on a smartphone it will always show the smartphone camera instead)! A secure origin or exception is required! You can find out how to set an exception <a href=\"https://medium.com/@Carmichaelize/enabling-the-microphone-camera-in-chrome-for-local-unsecure-origins-9c90c3149339\" target=\"_blank\">here</a>.",
Expand Down Expand Up @@ -293,6 +294,7 @@
"previewCamFlipHorizontal": "Flip image from device cam horizontally",
"previewCamTakesPic": "Device cam takes picture",
"preview_camera_mode": "Camera facing mode",
"preview_gphoto_bsm": "Battery saving mode on gphoto2 live preview",
"preview_ipCamPreviewRotation": "Rotate preview from URL",
"preview_ipCamURL": "Preview-URL",
"preview_mode": "Preview mode",
Expand Down
104 changes: 71 additions & 33 deletions src/js/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ const photoBooth = (function () {

resultPage.hide();
startPage.addClass('open');
if (config.previewCamBackground) {
if (config.previewCamBackground || (config.preview_mode == 'gphoto ' && !config.preview_gphoto_bsm)) {
api.startVideo('preview');
}

Expand Down Expand Up @@ -163,40 +163,78 @@ const photoBooth = (function () {
}

if (config.preview_mode === 'gphoto') {
jQuery
.post('api/takeVideo.php', dataVideo)
.done(function (result) {
console.log('Start webcam', result);
pid = result.pid;
const getMedia =
navigator.mediaDevices.getUserMedia ||
navigator.mediaDevices.webkitGetUserMedia ||
navigator.mediaDevices.mozGetUserMedia ||
false;

if (!getMedia) {
return;
}
if (!config.preview_gphoto_bsm && mode === 'preview') {
jQuery
.post('api/takeVideo.php', dataVideo)
.done(function (result) {
console.log('Start webcam', result);
pid = result.pid;
})
.fail(function (xhr, status, result) {
console.log('Could not start webcam', result);
});
} else if (!config.preview_gphoto_bsm && mode === 'view') {
const getMedia =
navigator.mediaDevices.getUserMedia ||
navigator.mediaDevices.webkitGetUserMedia ||
navigator.mediaDevices.mozGetUserMedia ||
false;

if (!getMedia) {
return;
}

if (config.previewCamFlipHorizontal) {
$('#video--view').addClass('flip-horizontal');
$('#video--preview').addClass('flip-horizontal');
}
if (config.previewCamFlipHorizontal) {
$('#video--view').addClass('flip-horizontal');
$('#video--preview').addClass('flip-horizontal');
}

getMedia
.call(navigator.mediaDevices, webcamConstraints)
.then(function (stream) {
$('#video--view').show();
videoView.srcObject = stream;
api.stream = stream;
})
.catch(function (error) {
console.log('Could not get user media: ', error);
});
})
.fail(function (xhr, status, result) {
console.log('Could not start webcam', result);
});
getMedia
.call(navigator.mediaDevices, webcamConstraints)
.then(function (stream) {
$('#video--view').show();
videoView.srcObject = stream;
api.stream = stream;
})
.catch(function (error) {
console.log('Could not get user media: ', error);
});
} else {
jQuery
.post('api/takeVideo.php', dataVideo)
.done(function (result) {
console.log('Start webcam', result);
pid = result.pid;
const getMedia =
navigator.mediaDevices.getUserMedia ||
navigator.mediaDevices.webkitGetUserMedia ||
navigator.mediaDevices.mozGetUserMedia ||
false;

if (!getMedia) {
return;
}

if (config.previewCamFlipHorizontal) {
$('#video--view').addClass('flip-horizontal');
$('#video--preview').addClass('flip-horizontal');
}

getMedia
.call(navigator.mediaDevices, webcamConstraints)
.then(function (stream) {
$('#video--view').show();
videoView.srcObject = stream;
api.stream = stream;
})
.catch(function (error) {
console.log('Could not get user media: ', error);
});
})
.fail(function (xhr, status, result) {
console.log('Could not start webcam', result);
});
}
} else {
const getMedia =
navigator.mediaDevices.getUserMedia ||
Expand Down

0 comments on commit 820f408

Please sign in to comment.