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

Connection retry timeout #589

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/bc-core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -401,11 +401,11 @@ int bc_device_config_init(struct bc_device_config *cfg, BC_DB_RES dbres)
cfg->reencode_frame_height = bc_db_get_val_int(dbres, "reencode_frame_height");

cfg->substream_mode = (int8_t)bc_db_get_val_int(dbres, "substream_mode");
cfg->connection_retry_seconds = bc_db_get_val_int(dbres, "connection_retry_seconds");

cfg->hls_window_size = bc_db_get_val_int(dbres, "hls_window_size");
cfg->hls_segment_size = bc_db_get_val_int(dbres, "hls_segment_size");
cfg->hls_segment_duration = bc_db_get_val_float(dbres, "hls_segment_duration");

return 0;
}

1 change: 1 addition & 0 deletions lib/libbluecherry.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ struct bc_device_config {
int hls_window_size;
int hls_segment_size;
double hls_segment_duration;
int connection_retry_seconds;
};

struct bc_license {
Expand Down
2 changes: 1 addition & 1 deletion misc/sql/installed_db_version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3000010
3000011
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

echo '
ALTER TABLE Devices
ADD `connection_retry_seconds` smallint(5) DEFAULT '10' AFTER `hls_window_size`;
' | mysql -h"$host" -D"$dbname" -u"$user" -p"$password"

exit 0
1 change: 1 addition & 0 deletions misc/sql/schema_mysql.sql
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ CREATE TABLE `Devices` (
`hls_segment_duration` decimal(6,3) DEFAULT '3.000',
`hls_segment_size` int(11) DEFAULT '2695168',
`hls_window_size` smallint(5) DEFAULT '5',
`connection_retry_seconds` smallint(5) DEFAULT '10',

PRIMARY KEY (`id`),
UNIQUE KEY `device_name` (`device_name`),
Expand Down
6 changes: 5 additions & 1 deletion server/bc-thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ void bc_record::run()
pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);

pthread_cleanup_push(bc_rec_thread_cleanup, NULL);
int nConnectionAttempts = 0;

while (1) {
const char *local_thread_should_die;
Expand All @@ -218,6 +219,8 @@ void bc_record::run()
check_schedule(this);

if (!bc->input->is_started()) {
log.log(Debug, "Trying to start device stream... total attempts: %d", nConnectionAttempts++);

if (bc->input->start() < 0) {
if ((start_failed & BC_MAINSTREAM_START_FAILED) == 0) {
log.log(Error, "Error starting device stream: %s", bc->input->get_error_message());
Expand Down Expand Up @@ -447,7 +450,8 @@ void bc_record::run()
msleep(10);
continue;
error:
sleep(10);
if (cfg.connection_retry_seconds)
sleep(cfg.connection_retry_seconds);
}

pthread_cleanup_pop(0);
Expand Down
1 change: 0 additions & 1 deletion www/ajax/devices.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ public function __construct(){

public function getData()
{

$this->ipCameras = new StdClass();
$this->ipCameras->arr = array();
$this->ipCameras->ok = Array();
Expand Down
1 change: 1 addition & 0 deletions www/lib/lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,7 @@
define('AIP_CHECK_ONVIF_SUCCESS', 'Successfull');
define('AIP_CHECK_ONVIF_ERROR', 'Unsuccessful');
define('AIP_LIMIT_ALLOWED_DEVICES', 'Could not add a camera, because exceeds the limit of the allowed devices.');
define('AIP_CONNECTION_RETRY_SECONDS', 'Connection retry seconds');

# HLS configuration
define('AIP_HLS_WINDOW_SIZE', 'HLS window size');
Expand Down
4 changes: 3 additions & 1 deletion www/lib/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -829,6 +829,7 @@ private static function prepareData($rawData, $self_id = false){
$data['hls_window_size'] = (empty($rawData['hls_window_size'])) ? "5" : $rawData['hls_window_size']; //default to hls window size
$data['hls_segment_duration'] = $rawData['hls_segment_duration']; //default to hls segment duration
$data['hls_segment_size'] = $rawData['hls_segment_size']; //default to hls segment size
$data['connection_retry_seconds'] = $rawData['connection_retry_seconds']; //default to connection retry seconds

//var_dump_pre($data); exit();

Expand Down Expand Up @@ -865,7 +866,8 @@ public static function create($rawData){

$hls_segment_size = $data['hls_segment_size'] ? $data['hls_segment_size'] : 0;
$hls_segment_duration = $data['hls_segment_duration'] ? $data['hls_segment_duration'] : 0;
$inputQuery = "INSERT INTO Devices (device_name, protocol, device, driver, rtsp_username, rtsp_password, resolutionX, resolutionY, mjpeg_path, model, rtsp_rtp_prefer_tcp, onvif_port, substream_path, hls_window_size, hls_segment_size, hls_segment_duration) VALUES ('{$data['device_name']}', '{$data['protocol']}', '{$data['device']}', '{$data['driver']}', '{$data['rtsp_username']}', '{$data['rtsp_password']}', 640, 480, '{$data['mjpeg_path']}', '{$data['model']}', {$data['rtsp_rtp_prefer_tcp']}, {$data['onvif_port']},'{$data['substream_path']}', {$data['hls_window_size']}, {$hls_segment_size}, {$hls_segment_duration})";
$connection_retry_seconds = $data['connection_retry_seconds'] ? $data['connection_retry_seconds'] : 0;
$inputQuery = "INSERT INTO Devices (device_name, protocol, device, driver, rtsp_username, rtsp_password, resolutionX, resolutionY, mjpeg_path, model, rtsp_rtp_prefer_tcp, onvif_port, substream_path, hls_window_size, hls_segment_size, hls_segment_duration, connection_retry_seconds) VALUES ('{$data['device_name']}', '{$data['protocol']}', '{$data['device']}', '{$data['driver']}', '{$data['rtsp_username']}', '{$data['rtsp_password']}', 640, 480, '{$data['mjpeg_path']}', '{$data['model']}', {$data['rtsp_rtp_prefer_tcp']}, {$data['onvif_port']},'{$data['substream_path']}', {$data['hls_window_size']}, {$hls_segment_size}, {$hls_segment_duration}, {$connection_retry_seconds})";

$result = data::query($inputQuery, true);
#try to automatically set the camera up
Expand Down
8 changes: 8 additions & 0 deletions www/template/ajax/addip.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,14 @@
</div>
</div>

<div class="form-group">
<label class="col-lg-4 col-md-4 control-label"><?php echo AIP_CONNECTION_RETRY_SECONDS; ?></label>

<div class="col-lg-6 col-md-6">
<input class="form-control" type="text" name="connection_retry_seconds" value="10" />
</div>
</div>

<div class="form-group">
<label class="col-lg-4 col-md-4 control-label"><?php echo AIP_SUBSTREAM_PATH; ?></label>

Expand Down
2 changes: 1 addition & 1 deletion www/template/ajax/devices.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@
<li><a href="/motionmap?id=<?php echo $device->info['id']; ?>" class="ajax-content"><?php echo DEVICE_EDIT_MMAP;?></a></li>
<li><a href="/deviceschedule?id=<?php echo $device->info['id']; ?>" class="ajax-content"><?php echo DEVICE_EDIT_SCHED;?></a></li>
<li><a href="/ptzsettings?id=<?php echo $device->info['driver']; ?>" class="ajax-content"><?php echo DEVICE_EDIT_PTZ;?></a></li>
<li><a href="/ajax/reencode.php?id=<?php echo $device->info['id']; ?>" class="ajax-content"><?php echo DEVICE_EDIT_REENCODE; ?></a></li>
<li><a href="/ajax/reencode.php?id=<?php echo $device->info['id']; ?>" class="ajax-content"><?php echo DEVICE_EDIT_REENCODE; ?></a></li>
</ul>
</div>
</div>
Expand Down
11 changes: 10 additions & 1 deletion www/template/ajax/editip.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,22 @@
</div>
</div>

<div class="form-group">
<label class="col-lg-4 col-md-4 control-label"><?php echo AIP_CONNECTION_RETRY_SECONDS; ?></label>

<div class="col-lg-6 col-md-6">
<input class="form-control" type="text" name="connection_retry_seconds" value="<?php echo $ipCamera->info['connection_retry_seconds']; ?>" />
</div>
</div>

<div class="form-group">
<label class="col-lg-4 col-md-4 control-label"><?php echo AIP_SUBSTREAM_ENABLE; ?></label>

<div class="col-lg-6 col-md-6 form-control-static">
<input class="" type="checkbox" name="substream_enabled" <?php echo (($ipCamera->info['substream_enabled'] == 1) ? ' checked="checked"' : ''); ?> />
</div>
</div>
</div>

<div class="form-group">
<label class="col-lg-4 col-md-4 control-label"><?php echo AIP_SUBSTREAM_PATH; ?></label>

Expand Down
2 changes: 2 additions & 0 deletions www/template/dist/js/addip.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ var cameraProc = function (form) {
getEl('hls_window_size', true, true, '5');
getEl('hls_segment_size', true, true, '2695168');
getEl('hls_segment_duration', true, true, '3.0');
getEl('connection_retry_seconds', true, true, '10');

getEl('camName', true, true, '');
getEl('ipAddr', true, true, '');
Expand Down Expand Up @@ -135,6 +136,7 @@ var cameraProc = function (form) {
getEl('hls_window_size', true, true, '5');
getEl('hls_segment_size', true, true, '2695168');
getEl('hls_segment_duration', true, true, '3.0');
getEl('connection_retry_seconds', true, true, '10');
}

var constructor = function () {
Expand Down