mirror of
https://github.com/Motion-Project/motion.git
synced 2026-03-05 23:07:05 -05:00
Use braces on if statements
This commit is contained in:
78
src/alg.cpp
78
src/alg.cpp
@@ -652,7 +652,9 @@ void alg_despeckle(struct ctx_cam *cam)
|
||||
unsigned char *out, *common_buffer;
|
||||
|
||||
if ((cam->conf->despeckle_filter == "") || cam->current_image->diffs <= 0) {
|
||||
if (cam->imgs.labelsize_max) cam->imgs.labelsize_max = 0;
|
||||
if (cam->imgs.labelsize_max) {
|
||||
cam->imgs.labelsize_max = 0;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -671,12 +673,16 @@ void alg_despeckle(struct ctx_cam *cam)
|
||||
switch (cam->conf->despeckle_filter[i]) {
|
||||
case 'E':
|
||||
diffs = alg_erode9(out, width, height, common_buffer, 0);
|
||||
if (diffs == 0) i = len;
|
||||
if (diffs == 0) {
|
||||
i = len;
|
||||
}
|
||||
done = 1;
|
||||
break;
|
||||
case 'e':
|
||||
diffs = alg_erode5(out, width, height, common_buffer, 0);
|
||||
if (diffs == 0) i = len;
|
||||
if (diffs == 0) {
|
||||
i = len;
|
||||
}
|
||||
done = 1;
|
||||
break;
|
||||
case 'D':
|
||||
@@ -698,7 +704,9 @@ void alg_despeckle(struct ctx_cam *cam)
|
||||
|
||||
/* If conf.despeckle_filter contains any valid action EeDdl */
|
||||
if (done) {
|
||||
if (done != 2) cam->imgs.labelsize_max = 0; // Disable Labeling
|
||||
if (done != 2) {
|
||||
cam->imgs.labelsize_max = 0; // Disable Labeling
|
||||
}
|
||||
cam->current_image->diffs = diffs;
|
||||
return;
|
||||
} else {
|
||||
@@ -725,8 +733,9 @@ void alg_tune_smartmask(struct ctx_cam *cam)
|
||||
|
||||
for (i = 0; i < motionsize; i++) {
|
||||
/* Decrease smart_mask sensitivity every 5*speed seconds only. */
|
||||
if (smartmask[i] > 0)
|
||||
if (smartmask[i] > 0) {
|
||||
smartmask[i]--;
|
||||
}
|
||||
/* Increase smart_mask sensitivity based on the buffered values. */
|
||||
diff = smartmask_buffer[i] / sensitivity;
|
||||
|
||||
@@ -896,7 +905,9 @@ static int alg_diff_masksmart(struct ctx_cam *cam, unsigned char *new_img)
|
||||
if (cam->event_nr != cam->prev_event) {
|
||||
(*smartmask_buffer) += SMARTMASK_SENSITIVITY_INCR;
|
||||
}
|
||||
if (!*smartmask_final) curdiff = 0;
|
||||
if (!*smartmask_final) {
|
||||
curdiff = 0;
|
||||
}
|
||||
}
|
||||
smartmask_final++;
|
||||
smartmask_buffer++;
|
||||
@@ -926,7 +937,9 @@ static char alg_diff_fast(struct ctx_cam *cam, int max_n_changes, unsigned char
|
||||
unsigned char *ref = imgs->ref;
|
||||
int curdiff;
|
||||
|
||||
if (!step % 2) step++;
|
||||
if (!step % 2) {
|
||||
step++;
|
||||
}
|
||||
|
||||
max_n_changes /= step;
|
||||
|
||||
@@ -936,7 +949,7 @@ static char alg_diff_fast(struct ctx_cam *cam, int max_n_changes, unsigned char
|
||||
curdiff = abs(*ref - *new_var); /* Using a temp variable is 12% faster. */
|
||||
if (curdiff > noise) {
|
||||
diffs++;
|
||||
if (diffs > max_n_changes){
|
||||
if (diffs > max_n_changes) {
|
||||
|
||||
//MOTION_LOG(ERR, TYPE_ALL, NO_ERRNO
|
||||
//,"Lots of fast diffs %d detected.", diffs);
|
||||
@@ -957,7 +970,7 @@ static char alg_diff_fast(struct ctx_cam *cam, int max_n_changes, unsigned char
|
||||
static void alg_diff_standard(struct ctx_cam *cam)
|
||||
{
|
||||
|
||||
if (cam->smartmask_speed == 0){
|
||||
if (cam->smartmask_speed == 0) {
|
||||
if (cam->imgs.mask == NULL) {
|
||||
cam->current_image->diffs = alg_diff_nomask(cam, cam->imgs.image_vprvcy);
|
||||
} else {
|
||||
@@ -993,8 +1006,9 @@ void alg_lightswitch(struct ctx_cam *cam)
|
||||
if (cam->conf->lightswitch_percent >= 1 && !cam->lost_connection) {
|
||||
if (cam->current_image->diffs > (cam->imgs.motionsize * cam->conf->lightswitch_percent / 100)) {
|
||||
MOTION_LOG(INF, TYPE_ALL, NO_ERRNO, _("Lightswitch detected"));
|
||||
if (cam->frame_skip < (unsigned int)cam->conf->lightswitch_frames)
|
||||
if (cam->frame_skip < (unsigned int)cam->conf->lightswitch_frames) {
|
||||
cam->frame_skip = (unsigned int)cam->conf->lightswitch_frames;
|
||||
}
|
||||
cam->current_image->diffs = 0;
|
||||
alg_update_reference_frame(cam, RESET_REF_FRAME);
|
||||
}
|
||||
@@ -1024,8 +1038,10 @@ void alg_update_reference_frame(struct ctx_cam *cam, int action)
|
||||
unsigned char *smartmask = cam->imgs.smartmask_final;
|
||||
unsigned char *out = cam->imgs.image_motion.image_norm;
|
||||
|
||||
if (cam->lastrate > 5) /* Match rate limit */
|
||||
if (cam->lastrate > 5) {
|
||||
/* Match rate limit */
|
||||
accept_timer /= (cam->lastrate / 3);
|
||||
}
|
||||
|
||||
if (action == UPDATE_REF_FRAME) { /* Black&white only for better performance. */
|
||||
threshold_ref = cam->noise * EXCLUDE_LEVEL_PERCENT / 100;
|
||||
@@ -1102,10 +1118,18 @@ static void alg_new_location_center(ctx_cam *cam)
|
||||
}
|
||||
|
||||
/* This allows for the redcross and boxes to be drawn*/
|
||||
if (cent->x < 10) cent->x = 15;
|
||||
if (cent->y < 10) cent->y = 15;
|
||||
if ((cent->x + 10) > width) cent->x = width - 15;
|
||||
if ((cent->y + 10) > height) cent->y = height - 15;
|
||||
if (cent->x < 10) {
|
||||
cent->x = 15;
|
||||
}
|
||||
if (cent->y < 10) {
|
||||
cent->y = 15;
|
||||
}
|
||||
if ((cent->x + 10) > width) {
|
||||
cent->x = width - 15;
|
||||
}
|
||||
if ((cent->y + 10) > height) {
|
||||
cent->y = height - 15;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1141,15 +1165,15 @@ static void alg_new_location_dist(ctx_cam *cam)
|
||||
/* ToDo: We should store this number for the variance calc...*/
|
||||
distance_mean += sqrt(pow((x - cent->x), 2) + pow((y - cent->y), 2));
|
||||
|
||||
if (x > cent->x){
|
||||
if (x > cent->x) {
|
||||
xdist += x - cent->x;
|
||||
} else if (x < cent->x){
|
||||
} else if (x < cent->x) {
|
||||
xdist += cent->x - x;
|
||||
}
|
||||
|
||||
if (y > cent->y){
|
||||
if (y > cent->y) {
|
||||
ydist += y - cent->y;
|
||||
} else if (y < cent->y){
|
||||
} else if (y < cent->y) {
|
||||
ydist += cent->y - y;
|
||||
}
|
||||
|
||||
@@ -1198,27 +1222,27 @@ static void alg_new_location_minmax(ctx_cam *cam)
|
||||
int height = cam->imgs.height;
|
||||
ctx_coord *cent = &cam->current_image->location;
|
||||
|
||||
if (cent->maxx > width - 1){
|
||||
if (cent->maxx > width - 1) {
|
||||
cent->maxx = width - 1;
|
||||
} else if (cent->maxx < 0){
|
||||
} else if (cent->maxx < 0) {
|
||||
cent->maxx = 0;
|
||||
}
|
||||
|
||||
if (cent->maxy > height - 1){
|
||||
if (cent->maxy > height - 1) {
|
||||
cent->maxy = height - 1;
|
||||
} else if (cent->maxy < 0){
|
||||
} else if (cent->maxy < 0) {
|
||||
cent->maxy = 0;
|
||||
}
|
||||
|
||||
if (cent->minx > width - 1){
|
||||
if (cent->minx > width - 1) {
|
||||
cent->minx = width - 1;
|
||||
} else if (cent->minx < 0){
|
||||
} else if (cent->minx < 0) {
|
||||
cent->minx = 0;
|
||||
}
|
||||
|
||||
if (cent->miny > height - 1){
|
||||
if (cent->miny > height - 1) {
|
||||
cent->miny = height - 1;
|
||||
} else if (cent->miny < 0){
|
||||
} else if (cent->miny < 0) {
|
||||
cent->miny = 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -62,7 +62,9 @@ static void algsec_img_show(ctx_cam *cam, Mat &mat_src
|
||||
double w = src_weights[indx0];
|
||||
|
||||
for (indx1=0; indx1<src_pos.size(); indx1++) {
|
||||
if (indx1 != indx0 && (r & src_pos[indx1])==r) break;
|
||||
if (indx1 != indx0 && (r & src_pos[indx1])==r) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ((indx1==src_pos.size()) && (w > algmdl.threshold_motion)) {
|
||||
fltr_pos.push_back(r);
|
||||
@@ -482,7 +484,9 @@ static void *algsec_handler(void *arg)
|
||||
}
|
||||
cam->algsec->detecting = false;
|
||||
/*Set the event based isdetected bool */
|
||||
if (cam->algsec->models.isdetected) cam->algsec->isdetected = true;
|
||||
if (cam->algsec->models.isdetected) {
|
||||
cam->algsec->isdetected = true;
|
||||
}
|
||||
} else {
|
||||
SLEEP(0,interval)
|
||||
}
|
||||
@@ -578,7 +582,9 @@ void algsec_detect(ctx_cam *cam)
|
||||
{
|
||||
/*This function runs on the camera thread */
|
||||
#ifdef HAVE_OPENCV
|
||||
if (cam->algsec->frame_cnt > 0) cam->algsec->frame_cnt--;
|
||||
if (cam->algsec->frame_cnt > 0) {
|
||||
cam->algsec->frame_cnt--;
|
||||
}
|
||||
|
||||
if (cam->algsec->frame_cnt == 0){
|
||||
|
||||
|
||||
1096
src/conf.cpp
1096
src/conf.cpp
File diff suppressed because it is too large
Load Diff
12
src/dbse.cpp
12
src/dbse.cpp
@@ -29,7 +29,7 @@ static int dbse_global_edits(struct ctx_cam **cam_list)
|
||||
|
||||
int retcd = 0;
|
||||
|
||||
if (cam_list[0]->conf->database_dbname == ""){
|
||||
if (cam_list[0]->conf->database_dbname == "") {
|
||||
MOTION_LOG(ERR, TYPE_DB, NO_ERRNO
|
||||
,_("Invalid database name"));
|
||||
retcd = -1;
|
||||
@@ -37,13 +37,13 @@ static int dbse_global_edits(struct ctx_cam **cam_list)
|
||||
if ((((cam_list[0]->conf->database_type == "mysql")) ||
|
||||
((cam_list[0]->conf->database_type == "mariadb")) ||
|
||||
((cam_list[0]->conf->database_type == "pgsql"))) &&
|
||||
(cam_list[0]->conf->database_port == 0)){
|
||||
(cam_list[0]->conf->database_port == 0)) {
|
||||
MOTION_LOG(ERR, TYPE_DB, NO_ERRNO
|
||||
,_("Must specify database port for mysql/mariadb/pgsql"));
|
||||
retcd = -1;
|
||||
}
|
||||
|
||||
if (retcd == -1){
|
||||
if (retcd == -1) {
|
||||
MOTION_LOG(ERR, TYPE_DB, NO_ERRNO
|
||||
,_("Database functionality disabled."));
|
||||
cam_list[0]->conf->database_type = "";
|
||||
@@ -81,7 +81,7 @@ void dbse_global_deinit(struct ctx_motapp *motapp)
|
||||
#endif /* HAVE_MYSQL */
|
||||
|
||||
indx = 0;
|
||||
while (motapp->cam_list[indx] != NULL){
|
||||
while (motapp->cam_list[indx] != NULL) {
|
||||
if (motapp->cam_list[indx]->dbse != NULL) {
|
||||
free(motapp->cam_list[indx]->dbse);
|
||||
}
|
||||
@@ -102,7 +102,9 @@ void dbse_global_init(struct ctx_motapp *motapp)
|
||||
}
|
||||
|
||||
if (motapp->cam_list[0]->conf->database_type != "") {
|
||||
if (dbse_global_edits(motapp->cam_list) == -1) return;
|
||||
if (dbse_global_edits(motapp->cam_list) == -1) {
|
||||
return;
|
||||
}
|
||||
|
||||
MOTION_LOG(DBG, TYPE_DB, NO_ERRNO,_("Initializing database"));
|
||||
/* Initialize all the database items */
|
||||
|
||||
51
src/draw.cpp
51
src/draw.cpp
@@ -1087,13 +1087,17 @@ static int draw_textn(unsigned char *image, int startx, int starty, int width
|
||||
int pos, line_offset, next_char_offs;
|
||||
unsigned char *image_ptr, *char_ptr;
|
||||
|
||||
if (startx > width / 2)
|
||||
if (startx > width / 2) {
|
||||
startx -= len * (6 * factor);
|
||||
}
|
||||
|
||||
if (startx + len * 6 * factor >= width)
|
||||
if (startx + len * 6 * factor >= width) {
|
||||
len = (width-startx-1)/(6*factor);
|
||||
}
|
||||
|
||||
if ((startx < 1) || (starty < 1) || (len < 1)) return 0;
|
||||
if ((startx < 1) || (starty < 1) || (len < 1)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
line_offset = width - (7 * factor);
|
||||
next_char_offs = (width * 8 * factor) - (6 * factor);
|
||||
@@ -1147,24 +1151,32 @@ int draw_text(unsigned char *image, int width, int height, int startx, int start
|
||||
begin = end = text;
|
||||
txtlen = 0;
|
||||
while ((end = strstr(end, NEWLINE))) {
|
||||
if ((end - begin)>txtlen) txtlen = (end - begin);
|
||||
if ((end - begin)>txtlen) {
|
||||
txtlen = (end - begin);
|
||||
}
|
||||
num_nl++;
|
||||
end += sizeof(NEWLINE)-1;
|
||||
begin = end;
|
||||
}
|
||||
if (txtlen == 0) txtlen = strlen(text);
|
||||
if (txtlen == 0) {
|
||||
txtlen = strlen(text);
|
||||
}
|
||||
|
||||
/* Adjust the factor if it is out of bounds
|
||||
* txtlen at this point is the approx length of longest line
|
||||
*/
|
||||
if ((txtlen * 7 * factor) > width){
|
||||
if ((txtlen * 7 * factor) > width) {
|
||||
factor = (width / (txtlen * 7));
|
||||
if (factor <= 0) factor = 1;
|
||||
if (factor <= 0) {
|
||||
factor = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (((num_nl+1) * 8 * factor) > height){
|
||||
if (((num_nl+1) * 8 * factor) > height) {
|
||||
factor = (height / ((num_nl+1) * 8));
|
||||
if (factor <= 0) factor = 1;
|
||||
if (factor <= 0) {
|
||||
factor = 1;
|
||||
}
|
||||
}
|
||||
|
||||
line_space = factor * 9;
|
||||
@@ -1216,18 +1228,24 @@ void draw_init_scale(struct ctx_cam *cam)
|
||||
*/
|
||||
|
||||
cam->text_scale = cam->conf->text_scale;
|
||||
if (cam->text_scale <= 0) cam->text_scale = 1;
|
||||
if (cam->text_scale <= 0) {
|
||||
cam->text_scale = 1;
|
||||
}
|
||||
|
||||
if ((cam->text_scale * 10 * 2) > (cam->imgs.width / 4)) {
|
||||
cam->text_scale = (cam->imgs.width / (4 * 10 * 2));
|
||||
if (cam->text_scale <= 0) cam->text_scale = 1;
|
||||
if (cam->text_scale <= 0) {
|
||||
cam->text_scale = 1;
|
||||
}
|
||||
MOTION_LOG(WRN, TYPE_ALL, NO_ERRNO
|
||||
,_("Invalid text scale. Adjusted to %d"), cam->text_scale);
|
||||
}
|
||||
|
||||
if ((cam->text_scale * 10 * 2) > (cam->imgs.height / 4)) {
|
||||
cam->text_scale = (cam->imgs.height / (4 * 10 * 2));
|
||||
if (cam->text_scale <= 0) cam->text_scale = 1;
|
||||
if (cam->text_scale <= 0) {
|
||||
cam->text_scale = 1;
|
||||
}
|
||||
MOTION_LOG(WRN, TYPE_ALL, NO_ERRNO
|
||||
,_("Invalid text scale. Adjusted to %d"), cam->text_scale);
|
||||
}
|
||||
@@ -1485,8 +1503,9 @@ void draw_smartmask(struct ctx_cam *cam, unsigned char *out)
|
||||
out_y = out;
|
||||
/* Set colour intensity for smartmask. */
|
||||
for (i = 0; i < imgs->motionsize; i++) {
|
||||
if (smartmask[i] == 0)
|
||||
if (smartmask[i] == 0) {
|
||||
*out_y = 0;
|
||||
}
|
||||
out_y++;
|
||||
}
|
||||
}
|
||||
@@ -1523,8 +1542,9 @@ void draw_fixed_mask(struct ctx_cam *cam, unsigned char *out)
|
||||
out_y = out;
|
||||
/* Set colour intensity for mask. */
|
||||
for (i = 0; i < imgs->motionsize; i++) {
|
||||
if (mask[i] == 0)
|
||||
if (mask[i] == 0) {
|
||||
*out_y = 0;
|
||||
}
|
||||
out_y++;
|
||||
}
|
||||
}
|
||||
@@ -1561,8 +1581,9 @@ void draw_largest_label(struct ctx_cam *cam, unsigned char *out)
|
||||
out_y = out;
|
||||
/* Set intensity for coloured label to have better visibility. */
|
||||
for (i = 0; i < imgs->motionsize; i++) {
|
||||
if (*labels++ & 32768)
|
||||
if (*labels++ & 32768) {
|
||||
*out_y = 0;
|
||||
}
|
||||
out_y++;
|
||||
}
|
||||
}
|
||||
|
||||
104
src/event.cpp
104
src/event.cpp
@@ -101,11 +101,13 @@ static void on_picture_save_command(struct ctx_cam *cam, motion_event evnt
|
||||
(void)img_data;
|
||||
(void)ts1;
|
||||
|
||||
if ((filetype & FTYPE_IMAGE_ANY) != 0 && (cam->conf->on_picture_save != ""))
|
||||
if ((filetype & FTYPE_IMAGE_ANY) != 0 && (cam->conf->on_picture_save != "")) {
|
||||
util_exec_command(cam, cam->conf->on_picture_save.c_str(), fname, filetype);
|
||||
}
|
||||
|
||||
if ((filetype & FTYPE_MPEG_ANY) != 0 && (cam->conf->on_movie_start != ""))
|
||||
if ((filetype & FTYPE_MPEG_ANY) != 0 && (cam->conf->on_movie_start != "")) {
|
||||
util_exec_command(cam, cam->conf->on_movie_start.c_str(), fname, filetype);
|
||||
}
|
||||
}
|
||||
|
||||
static void on_motion_detected_command(struct ctx_cam *cam, motion_event evnt
|
||||
@@ -118,8 +120,9 @@ static void on_motion_detected_command(struct ctx_cam *cam, motion_event evnt
|
||||
(void)ftype;
|
||||
(void)ts1;
|
||||
|
||||
if (cam->conf->on_motion_detected != "")
|
||||
if (cam->conf->on_motion_detected != "") {
|
||||
util_exec_command(cam, cam->conf->on_motion_detected.c_str(), NULL, 0);
|
||||
}
|
||||
}
|
||||
|
||||
static void event_sqlfirstmotion(struct ctx_cam *cam, motion_event evnt
|
||||
@@ -149,7 +152,7 @@ static void event_sqlnewfile(struct ctx_cam *cam, motion_event evnt
|
||||
(void)img_data;
|
||||
|
||||
/* Only log the file types we want */
|
||||
if ((cam->conf->database_type == "") || (sqltype & cam->dbse->sql_mask) == 0){
|
||||
if ((cam->conf->database_type == "") || (sqltype & cam->dbse->sql_mask) == 0) {
|
||||
return;
|
||||
} else {
|
||||
dbse_newfile(cam, fname, sqltype, ts1);
|
||||
@@ -167,7 +170,7 @@ static void event_sqlfileclose(struct ctx_cam *cam, motion_event evnt
|
||||
(void)img_data;
|
||||
|
||||
/* Only log the file types we want */
|
||||
if ((cam->conf->database_type == "") || (sqltype & cam->dbse->sql_mask) == 0){
|
||||
if ((cam->conf->database_type == "") || (sqltype & cam->dbse->sql_mask) == 0) {
|
||||
return;
|
||||
} else {
|
||||
dbse_fileclose(cam, fname, sqltype, ts1);
|
||||
@@ -186,8 +189,9 @@ static void on_area_command(struct ctx_cam *cam, motion_event evnt
|
||||
(void)ftype;
|
||||
(void)ts1;
|
||||
|
||||
if (cam->conf->on_area_detected != "")
|
||||
if (cam->conf->on_area_detected != "") {
|
||||
util_exec_command(cam, cam->conf->on_area_detected.c_str(), NULL, 0);
|
||||
}
|
||||
}
|
||||
|
||||
static void on_event_start_command(struct ctx_cam *cam, motion_event evnt
|
||||
@@ -200,8 +204,9 @@ static void on_event_start_command(struct ctx_cam *cam, motion_event evnt
|
||||
(void)ftype;
|
||||
(void)ts1;
|
||||
|
||||
if (cam->conf->on_event_start != "")
|
||||
if (cam->conf->on_event_start != "") {
|
||||
util_exec_command(cam, cam->conf->on_event_start.c_str(), NULL, 0);
|
||||
}
|
||||
}
|
||||
|
||||
static void on_event_end_command(struct ctx_cam *cam, motion_event evnt
|
||||
@@ -214,8 +219,9 @@ static void on_event_end_command(struct ctx_cam *cam, motion_event evnt
|
||||
(void)ftype;
|
||||
(void)ts1;
|
||||
|
||||
if (cam->conf->on_event_end != "")
|
||||
if (cam->conf->on_event_end != "") {
|
||||
util_exec_command(cam, cam->conf->on_event_end.c_str(), NULL, 0);
|
||||
}
|
||||
}
|
||||
|
||||
static void event_stream_put(struct ctx_cam *cam, motion_event evnt
|
||||
@@ -241,9 +247,10 @@ static void event_vlp_putpipe(struct ctx_cam *cam, motion_event evnt
|
||||
(void)ts1;
|
||||
|
||||
if (*(int *)ftype >= 0) {
|
||||
if (vlp_putpipe(*(int *)ftype, img_data->image_norm, cam->imgs.size_norm) == -1)
|
||||
if (vlp_putpipe(*(int *)ftype, img_data->image_norm, cam->imgs.size_norm) == -1) {
|
||||
MOTION_LOG(ERR, TYPE_EVENTS, SHOW_ERRNO
|
||||
,_("Failed to put image into video pipe"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -270,7 +277,7 @@ static void event_image_detect(struct ctx_cam *cam, motion_event evnt
|
||||
mystrftime(cam, filename, sizeof(filename), cam->conf->picture_filename.c_str(), ts1, NULL, 0);
|
||||
retcd = snprintf(fullfilename, PATH_MAX, "%s/%s.%s"
|
||||
, cam->conf->target_dir.c_str(), filename, imageext(cam));
|
||||
if ((retcd < 0) || (retcd >= PATH_MAX)){
|
||||
if ((retcd < 0) || (retcd >= PATH_MAX)) {
|
||||
MOTION_LOG(ERR, TYPE_EVENTS, NO_ERRNO
|
||||
,_("Error creating image file name"));
|
||||
return;
|
||||
@@ -302,7 +309,7 @@ static void event_imagem_detect(struct ctx_cam *cam, motion_event evnt
|
||||
mystrftime(cam, filename, sizeof(filename), cam->conf->picture_filename.c_str(), ts1, NULL, 0);
|
||||
retcd = snprintf(fullfilename, PATH_MAX, "%s/%sm.%s"
|
||||
, cam->conf->target_dir.c_str(), filename, imageext(cam));
|
||||
if ((retcd < 0) || (retcd >= PATH_MAX)){
|
||||
if ((retcd < 0) || (retcd >= PATH_MAX)) {
|
||||
MOTION_LOG(ERR, TYPE_EVENTS, NO_ERRNO
|
||||
,_("Error creating image motion file name"));
|
||||
return;
|
||||
@@ -313,7 +320,7 @@ static void event_imagem_detect(struct ctx_cam *cam, motion_event evnt
|
||||
mystrftime(cam, filename, sizeof(filename), cam->conf->picture_filename.c_str(), ts1, NULL, 0);
|
||||
retcd = snprintf(fullfilename, PATH_MAX, "%s/%sr.%s"
|
||||
, cam->conf->target_dir.c_str(), filename, imageext(cam));
|
||||
if ((retcd < 0) || (retcd >= PATH_MAX)){
|
||||
if ((retcd < 0) || (retcd >= PATH_MAX)) {
|
||||
MOTION_LOG(ERR, TYPE_EVENTS, NO_ERRNO
|
||||
,_("Error creating image motion roi file name"));
|
||||
return;
|
||||
@@ -338,15 +345,21 @@ static void event_image_snapshot(struct ctx_cam *cam, motion_event evnt
|
||||
(void)ftype;
|
||||
|
||||
offset = cam->conf->snapshot_filename.length() - 8;
|
||||
if (offset < 0) offset = 1;
|
||||
if (offset < 0) {
|
||||
offset = 1;
|
||||
}
|
||||
|
||||
if (cam->conf->snapshot_filename.compare(offset, 8, "lastsnap") != 0) {
|
||||
mystrftime(cam, filepath, sizeof(filepath), cam->conf->snapshot_filename.c_str(), ts1, NULL, 0);
|
||||
retcd = snprintf(filename, PATH_MAX, "%s.%s", filepath, imageext(cam));
|
||||
if (retcd <0) MOTION_LOG(INF, TYPE_STREAM, NO_ERRNO, _("Error option"));
|
||||
if (retcd <0) {
|
||||
MOTION_LOG(INF, TYPE_STREAM, NO_ERRNO, _("Error option"));
|
||||
}
|
||||
|
||||
retcd =snprintf(fullfilename, PATH_MAX, "%s/%s", cam->conf->target_dir.c_str(), filename);
|
||||
if (retcd <0) MOTION_LOG(INF, TYPE_STREAM, NO_ERRNO, _("Error option"));
|
||||
if (retcd <0) {
|
||||
MOTION_LOG(INF, TYPE_STREAM, NO_ERRNO, _("Error option"));
|
||||
}
|
||||
|
||||
pic_save_norm(cam, fullfilename, img_data->image_norm, FTYPE_IMAGE_SNAPSHOT);
|
||||
event(cam, EVENT_FILECREATE, NULL, fullfilename, (void *)FTYPE_IMAGE_SNAPSHOT, ts1);
|
||||
@@ -362,10 +375,14 @@ static void event_image_snapshot(struct ctx_cam *cam, motion_event evnt
|
||||
} else {
|
||||
mystrftime(cam, filepath, sizeof(filepath), cam->conf->snapshot_filename.c_str(), ts1, NULL, 0);
|
||||
retcd = snprintf(filename, PATH_MAX, "%s.%s", filepath, imageext(cam));
|
||||
if (retcd <0) MOTION_LOG(INF, TYPE_STREAM, NO_ERRNO, _("Error option"));
|
||||
if (retcd <0) {
|
||||
MOTION_LOG(INF, TYPE_STREAM, NO_ERRNO, _("Error option"));
|
||||
}
|
||||
|
||||
retcd = snprintf(fullfilename, PATH_MAX, "%s/%s", cam->conf->target_dir.c_str(), filename);
|
||||
if (retcd <0) MOTION_LOG(INF, TYPE_STREAM, NO_ERRNO, _("Error option"));
|
||||
if (retcd <0) {
|
||||
MOTION_LOG(INF, TYPE_STREAM, NO_ERRNO, _("Error option"));
|
||||
}
|
||||
|
||||
remove(fullfilename);
|
||||
pic_save_norm(cam, fullfilename, img_data->image_norm, FTYPE_IMAGE_SNAPSHOT);
|
||||
@@ -397,7 +414,7 @@ static void event_image_preview(struct ctx_cam *cam, motion_event evnt
|
||||
, &cam->imgs.image_preview.imgts, NULL, 0);
|
||||
retcd = snprintf(previewname, PATH_MAX, "%s/%s.%s"
|
||||
, cam->conf->target_dir.c_str(), filename, imageext(cam));
|
||||
if ((retcd < 0) || (retcd >= PATH_MAX)){
|
||||
if ((retcd < 0) || (retcd >= PATH_MAX)) {
|
||||
MOTION_LOG(ERR, TYPE_EVENTS, NO_ERRNO
|
||||
,_("Error creating preview file name"));
|
||||
return;
|
||||
@@ -425,8 +442,9 @@ static void event_camera_lost(struct ctx_cam *cam, motion_event evnt
|
||||
(void)ftype;
|
||||
(void)ts1;
|
||||
|
||||
if (cam->conf->on_camera_lost != "")
|
||||
if (cam->conf->on_camera_lost != "") {
|
||||
util_exec_command(cam, cam->conf->on_camera_lost.c_str(), NULL, 0);
|
||||
}
|
||||
}
|
||||
|
||||
static void event_secondary_detect(struct ctx_cam *cam, motion_event evnt
|
||||
@@ -441,8 +459,9 @@ static void event_secondary_detect(struct ctx_cam *cam, motion_event evnt
|
||||
|
||||
MOTION_LOG(NTC, TYPE_EVENTS, NO_ERRNO,_("Event secondary detect"));
|
||||
|
||||
if (cam->conf->on_secondary_detect != "")
|
||||
if (cam->conf->on_secondary_detect != "") {
|
||||
util_exec_command(cam, cam->conf->on_secondary_detect.c_str(), NULL, 0);
|
||||
}
|
||||
}
|
||||
|
||||
static void event_camera_found(struct ctx_cam *cam, motion_event evnt
|
||||
@@ -455,8 +474,9 @@ static void event_camera_found(struct ctx_cam *cam, motion_event evnt
|
||||
(void)ftype;
|
||||
(void)ts1;
|
||||
|
||||
if (cam->conf->on_camera_found != "")
|
||||
if (cam->conf->on_camera_found != "") {
|
||||
util_exec_command(cam, cam->conf->on_camera_found.c_str(), NULL, 0);
|
||||
}
|
||||
}
|
||||
|
||||
static void on_movie_end_command(struct ctx_cam *cam, motion_event evnt
|
||||
@@ -469,8 +489,9 @@ static void on_movie_end_command(struct ctx_cam *cam, motion_event evnt
|
||||
(void)img_data;
|
||||
(void)ts1;
|
||||
|
||||
if ((filetype & FTYPE_MPEG_ANY) && (cam->conf->on_movie_end != ""))
|
||||
if ((filetype & FTYPE_MPEG_ANY) && (cam->conf->on_movie_end != "")) {
|
||||
util_exec_command(cam, cam->conf->on_movie_end.c_str(), fname, filetype);
|
||||
}
|
||||
}
|
||||
|
||||
static void event_extpipe_end(struct ctx_cam *cam, motion_event evnt
|
||||
@@ -510,7 +531,9 @@ static void event_create_extpipe(struct ctx_cam *cam, motion_event evnt
|
||||
mystrftime(cam, stamp, sizeof(stamp), cam->conf->movie_filename.c_str(), ts1, NULL, 0);
|
||||
retcd = snprintf(cam->extpipefilename, PATH_MAX - 4, "%s/%s"
|
||||
, cam->conf->target_dir.c_str(), stamp);
|
||||
if (retcd <0) MOTION_LOG(INF, TYPE_STREAM, NO_ERRNO, _("Error option"));
|
||||
if (retcd <0) {
|
||||
MOTION_LOG(INF, TYPE_STREAM, NO_ERRNO, _("Error option"));
|
||||
}
|
||||
|
||||
if (access(cam->conf->target_dir.c_str(), W_OK)!= 0) {
|
||||
/* Permission denied */
|
||||
@@ -522,8 +545,9 @@ static void event_create_extpipe(struct ctx_cam *cam, motion_event evnt
|
||||
} else if (errno == ENOENT) {
|
||||
MOTION_LOG(ERR, TYPE_EVENTS, SHOW_ERRNO
|
||||
,_("path not found, trying to create it %s ..."), cam->conf->target_dir.c_str());
|
||||
if (mycreate_path(cam->extpipefilename) == -1)
|
||||
if (mycreate_path(cam->extpipefilename) == -1) {
|
||||
return ;
|
||||
}
|
||||
}
|
||||
else {
|
||||
MOTION_LOG(ERR, TYPE_EVENTS, SHOW_ERRNO
|
||||
@@ -533,14 +557,15 @@ static void event_create_extpipe(struct ctx_cam *cam, motion_event evnt
|
||||
}
|
||||
|
||||
/* Always create any path specified as file name */
|
||||
if (mycreate_path(cam->extpipefilename) == -1)
|
||||
if (mycreate_path(cam->extpipefilename) == -1) {
|
||||
return ;
|
||||
}
|
||||
|
||||
mystrftime(cam, stamp, sizeof(stamp), cam->conf->movie_extpipe.c_str()
|
||||
, ts1, cam->extpipefilename, 0);
|
||||
|
||||
retcd = snprintf(cam->extpipecmdline, PATH_MAX, "%s", stamp);
|
||||
if ((retcd < 0 ) || (retcd >= PATH_MAX)){
|
||||
if ((retcd < 0 ) || (retcd >= PATH_MAX)) {
|
||||
MOTION_LOG(ERR, TYPE_EVENTS, NO_ERRNO
|
||||
, _("Error specifying command line: %s"), cam->extpipecmdline);
|
||||
return;
|
||||
@@ -579,14 +604,16 @@ static void event_extpipe_put(struct ctx_cam *cam, motion_event evnt
|
||||
passthrough = mycheck_passthrough(cam);
|
||||
/* Check that is open */
|
||||
if ((cam->extpipe_open) && (fileno(cam->extpipe) > 0)) {
|
||||
if ((cam->imgs.size_high > 0) && (!passthrough)){
|
||||
if (!fwrite(img_data->image_high, cam->imgs.size_high, 1, cam->extpipe))
|
||||
if ((cam->imgs.size_high > 0) && (!passthrough)) {
|
||||
if (!fwrite(img_data->image_high, cam->imgs.size_high, 1, cam->extpipe)) {
|
||||
MOTION_LOG(ERR, TYPE_EVENTS, SHOW_ERRNO
|
||||
,_("Error writing in pipe , state error %d"), ferror(cam->extpipe));
|
||||
}
|
||||
} else {
|
||||
if (!fwrite(img_data->image_norm, cam->imgs.size_norm, 1, cam->extpipe))
|
||||
if (!fwrite(img_data->image_norm, cam->imgs.size_norm, 1, cam->extpipe)) {
|
||||
MOTION_LOG(ERR, TYPE_EVENTS, SHOW_ERRNO
|
||||
,_("Error writing in pipe , state error %d"), ferror(cam->extpipe));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
MOTION_LOG(ERR, TYPE_EVENTS, NO_ERRNO
|
||||
@@ -611,7 +638,9 @@ static void event_new_video(struct ctx_cam *cam, motion_event evnt
|
||||
|
||||
MOTION_LOG(INF, TYPE_EVENTS, NO_ERRNO, _("Source FPS %d"), cam->movie_fps);
|
||||
|
||||
if (cam->movie_fps < 2) cam->movie_fps = 2;
|
||||
if (cam->movie_fps < 2) {
|
||||
cam->movie_fps = 2;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -626,11 +655,13 @@ static void event_movie_newfile(struct ctx_cam *cam, motion_event evnt
|
||||
(void)fname;
|
||||
(void)ftype;
|
||||
|
||||
if (!cam->conf->movie_output && !cam->conf->movie_output_motion) return;
|
||||
if (!cam->conf->movie_output && !cam->conf->movie_output_motion) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (cam->conf->movie_output) {
|
||||
retcd = movie_init_norm(cam, ts1);
|
||||
if (retcd < 0){
|
||||
if (retcd < 0) {
|
||||
MOTION_LOG(ERR, TYPE_EVENTS, NO_ERRNO
|
||||
,_("Error opening ctx_cam for movie output."));
|
||||
free(cam->movie_norm);
|
||||
@@ -642,7 +673,7 @@ static void event_movie_newfile(struct ctx_cam *cam, motion_event evnt
|
||||
|
||||
if (cam->conf->movie_output_motion) {
|
||||
retcd = movie_init_motion(cam, ts1);
|
||||
if (retcd < 0){
|
||||
if (retcd < 0) {
|
||||
MOTION_LOG(ERR, TYPE_EVENTS, NO_ERRNO
|
||||
,_("Error creating motion file [%s]"), cam->movie_motion->filename);
|
||||
free(cam->movie_motion);
|
||||
@@ -664,7 +695,7 @@ static void event_movie_timelapse(struct ctx_cam *cam, motion_event evnt
|
||||
|
||||
if (!cam->movie_timelapse) {
|
||||
retcd = movie_init_timelapse(cam, ts1);
|
||||
if (retcd < 0){
|
||||
if (retcd < 0) {
|
||||
MOTION_LOG(ERR, TYPE_EVENTS, NO_ERRNO
|
||||
,_("Error creating timelapse file [%s]"), cam->movie_timelapse->filename);
|
||||
free(cam->movie_timelapse);
|
||||
@@ -690,7 +721,7 @@ static void event_movie_put(struct ctx_cam *cam, motion_event evnt
|
||||
(void)ftype;
|
||||
|
||||
if (cam->movie_norm) {
|
||||
if (movie_put_image(cam->movie_norm, img_data, ts1) == -1){
|
||||
if (movie_put_image(cam->movie_norm, img_data, ts1) == -1) {
|
||||
MOTION_LOG(ERR, TYPE_EVENTS, NO_ERRNO, _("Error encoding image"));
|
||||
}
|
||||
}
|
||||
@@ -895,7 +926,8 @@ void event(struct ctx_cam *cam, motion_event evnt
|
||||
int i=-1;
|
||||
|
||||
while (event_handlers[++i].handler) {
|
||||
if (evnt == event_handlers[i].type)
|
||||
if (evnt == event_handlers[i].type) {
|
||||
event_handlers[i].handler(cam, evnt, img_data, fname, ftype, ts1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
15
src/exif.cpp
15
src/exif.cpp
@@ -287,11 +287,13 @@ unsigned exif_prepare(unsigned char **exif, const struct ctx_cam *cam,
|
||||
put_uint16(writing.buf, ifd0_tagcount);
|
||||
writing.buf += 2;
|
||||
|
||||
if (description)
|
||||
if (description) {
|
||||
put_stringentry(&writing, TIFF_TAG_IMAGE_DESCRIPTION, description, 1);
|
||||
}
|
||||
|
||||
if (datetime)
|
||||
if (datetime) {
|
||||
put_stringentry(&writing, TIFF_TAG_DATETIME, datetime, 1);
|
||||
}
|
||||
|
||||
if (ifd1_tagcount > 0) {
|
||||
/* Offset of IFD1 - TIFF header + IFD0 size. */
|
||||
@@ -318,14 +320,17 @@ unsigned exif_prepare(unsigned char **exif, const struct ctx_cam *cam,
|
||||
memcpy(writing.buf + 2, exif_version_tag, 12); /* tag 0x9000 */
|
||||
writing.buf += 14;
|
||||
|
||||
if (datetime)
|
||||
if (datetime) {
|
||||
put_stringentry(&writing, EXIF_TAG_ORIGINAL_DATETIME, datetime, 1);
|
||||
}
|
||||
|
||||
if (box)
|
||||
if (box) {
|
||||
put_subjectarea(&writing, box);
|
||||
}
|
||||
|
||||
if (subtime)
|
||||
if (subtime) {
|
||||
put_stringentry(&writing, EXIF_TAG_ORIGINAL_DATETIME_SS, subtime, 0);
|
||||
}
|
||||
|
||||
put_uint32(writing.buf, 0); /* Next IFD = 0 (no next IFD) */
|
||||
writing.buf += 4;
|
||||
|
||||
@@ -70,8 +70,9 @@ static void add_huff_table(j_decompress_ptr dinfo, JHUFF_TBL **htblptr, const UI
|
||||
/* Define a Huffman table */
|
||||
int nsymbols, len;
|
||||
|
||||
if (*htblptr == NULL)
|
||||
if (*htblptr == NULL) {
|
||||
*htblptr = jpeg_alloc_huff_table((j_common_ptr) dinfo);
|
||||
}
|
||||
|
||||
/* Copy the number-of-symbols-of-each-code-length counts. */
|
||||
memcpy((*htblptr)->bits, bits, sizeof((*htblptr)->bits));
|
||||
@@ -86,8 +87,9 @@ static void add_huff_table(j_decompress_ptr dinfo, JHUFF_TBL **htblptr, const UI
|
||||
for (len = 1; len <= 16; len++)
|
||||
nsymbols += bits[len];
|
||||
|
||||
if (nsymbols < 1 || nsymbols > 256)
|
||||
if (nsymbols < 1 || nsymbols > 256) {
|
||||
MOTION_LOG(ERR, TYPE_ALL, NO_ERRNO, _("%s: Given jpeg buffer was too small"));
|
||||
}
|
||||
|
||||
memcpy((*htblptr)->huffval, val, nsymbols * sizeof(UINT8));
|
||||
}
|
||||
@@ -209,8 +211,9 @@ static boolean jpgutl_fill_input_buffer(j_decompress_ptr cinfo)
|
||||
static void jpgutl_skip_data(j_decompress_ptr cinfo, long num_bytes)
|
||||
{
|
||||
if (num_bytes > 0) {
|
||||
if (num_bytes > (long) cinfo->src->bytes_in_buffer)
|
||||
if (num_bytes > (long) cinfo->src->bytes_in_buffer) {
|
||||
num_bytes = (long) cinfo->src->bytes_in_buffer;
|
||||
}
|
||||
cinfo->src->next_input_byte += (size_t) num_bytes;
|
||||
cinfo->src->bytes_in_buffer -= (size_t) num_bytes;
|
||||
}
|
||||
@@ -510,7 +513,9 @@ int jpgutl_decode_jpeg (unsigned char *jpeg_data_in, int jpeg_data_len,
|
||||
* only a partial image could be returned which would
|
||||
* trigger many false positive motion detections
|
||||
*/
|
||||
if (jerr.warning_seen > 2) return -1;
|
||||
if (jerr.warning_seen > 2) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
|
||||
@@ -51,7 +51,9 @@ static int log_get_type(const char *type)
|
||||
void log_set_type(const char *new_logtype)
|
||||
{
|
||||
|
||||
if ( mystreq(new_logtype, log_type_str[log_type]) ) return;
|
||||
if ( mystreq(new_logtype, log_type_str[log_type]) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
pthread_mutex_lock(&log_motapp->mutex_parms);
|
||||
log_type = log_get_type(new_logtype);
|
||||
@@ -62,7 +64,9 @@ void log_set_type(const char *new_logtype)
|
||||
void log_set_level(int new_loglevel)
|
||||
{
|
||||
|
||||
if (new_loglevel == log_level) return;
|
||||
if (new_loglevel == log_level) {
|
||||
return;
|
||||
}
|
||||
|
||||
pthread_mutex_lock(&log_motapp->mutex_parms);
|
||||
log_level = new_loglevel;
|
||||
@@ -77,11 +81,11 @@ static void log_set_mode(int mode)
|
||||
|
||||
log_mode = mode;
|
||||
|
||||
if (mode == LOGMODE_SYSLOG && prev_mode != LOGMODE_SYSLOG){
|
||||
if (mode == LOGMODE_SYSLOG && prev_mode != LOGMODE_SYSLOG) {
|
||||
openlog("motion", LOG_PID, LOG_USER);
|
||||
}
|
||||
|
||||
if (mode != LOGMODE_SYSLOG && prev_mode == LOGMODE_SYSLOG){
|
||||
if (mode != LOGMODE_SYSLOG && prev_mode == LOGMODE_SYSLOG) {
|
||||
closelog();
|
||||
}
|
||||
}
|
||||
@@ -95,7 +99,7 @@ static void log_set_logfile(const char *logfile_name)
|
||||
logfile = myfopen(logfile_name, "a");
|
||||
|
||||
/* If logfile was opened correctly */
|
||||
if (logfile){
|
||||
if (logfile) {
|
||||
log_set_mode(LOGMODE_FILE);
|
||||
}
|
||||
|
||||
@@ -139,8 +143,12 @@ void motion_log(int level, int type, int errno_flag,int fncname, const char *fmt
|
||||
pthread_mutex_unlock(&log_motapp->mutex_parms);
|
||||
|
||||
/*Exit if not our level or type */
|
||||
if (level > applvl) return;
|
||||
if ((apptyp != TYPE_ALL) && (apptyp != type)) return;
|
||||
if (level > applvl) {
|
||||
return;
|
||||
}
|
||||
if ((apptyp != TYPE_ALL) && (apptyp != type)) {
|
||||
return;
|
||||
}
|
||||
|
||||
threadnr = (unsigned long)pthread_getspecific(tls_key_threadnr);
|
||||
|
||||
@@ -161,7 +169,7 @@ void motion_log(int level, int type, int errno_flag,int fncname, const char *fmt
|
||||
}
|
||||
|
||||
/* Prepend the format specifier for the function name */
|
||||
if (fncname){
|
||||
if (fncname) {
|
||||
snprintf(usrfmt, sizeof (usrfmt),"%s: %s", "%s", fmt);
|
||||
} else {
|
||||
snprintf(usrfmt, sizeof (usrfmt),"%s",fmt);
|
||||
@@ -200,10 +208,10 @@ void motion_log(int level, int type, int errno_flag,int fncname, const char *fmt
|
||||
#endif
|
||||
}
|
||||
|
||||
if ((mystreq(buf,flood_msg)) && (flood_cnt <= 5000)){
|
||||
if ((mystreq(buf,flood_msg)) && (flood_cnt <= 5000)) {
|
||||
flood_cnt++;
|
||||
} else {
|
||||
if (flood_cnt > 1){
|
||||
if (flood_cnt > 1) {
|
||||
if (log_mode == LOGMODE_FILE) {
|
||||
snprintf(flood_repeats,1024,"%s [%s] [%s] [%02d:%s] Above message repeats %d times"
|
||||
, str_time(), log_level_str[level], log_type_str[type]
|
||||
|
||||
@@ -109,7 +109,7 @@ static void set_video_port_format(ctx_mmalcam_ptr mmalcam, MMAL_ES_FORMAT_T *for
|
||||
set_port_format(mmalcam, format);
|
||||
format->es->video.frame_rate.num = mmalcam->framerate;
|
||||
format->es->video.frame_rate.den = VIDEO_FRAME_RATE_DEN;
|
||||
if (mmalcam->framerate > 30){
|
||||
if (mmalcam->framerate > 30) {
|
||||
/* The pi noir camera could not determine autoexpose at high frame rates */
|
||||
MOTION_LOG(WRN, TYPE_VIDEO, NO_ERRNO, _("A high frame rate can cause problems with exposure of images"));
|
||||
MOTION_LOG(WRN, TYPE_VIDEO, NO_ERRNO, _("If autoexposure is not working, try a lower frame rate."));
|
||||
@@ -411,8 +411,9 @@ int mmalcam_next(struct ctx_cam *cam, struct ctx_image_data *img_data)
|
||||
#ifdef HAVE_MMAL
|
||||
ctx_mmalcam_ptr mmalcam;
|
||||
|
||||
if ((!cam) || (!cam->mmalcam))
|
||||
if ((!cam) || (!cam->mmalcam)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
mmalcam = cam->mmalcam;
|
||||
|
||||
@@ -440,9 +441,10 @@ int mmalcam_next(struct ctx_cam *cam, struct ctx_image_data *img_data)
|
||||
status = mmal_port_send_buffer(mmalcam->camera_capture_port, new_buffer);
|
||||
}
|
||||
|
||||
if (!new_buffer || status != MMAL_SUCCESS)
|
||||
if (!new_buffer || status != MMAL_SUCCESS) {
|
||||
MOTION_LOG(ERR, TYPE_VIDEO, NO_ERRNO
|
||||
,_("Unable to return a buffer to the camera video port"));
|
||||
}
|
||||
}
|
||||
|
||||
rotate_map(cam,img_data);
|
||||
|
||||
@@ -49,7 +49,7 @@ static void mlp_ring_resize(struct ctx_cam *cam, int new_size)
|
||||
|
||||
if (cam->event_nr != cam->prev_event) {
|
||||
|
||||
if (new_size < cam->imgs.ring_size){
|
||||
if (new_size < cam->imgs.ring_size) {
|
||||
smallest = new_size;
|
||||
} else {
|
||||
smallest = cam->imgs.ring_size;
|
||||
@@ -61,14 +61,14 @@ static void mlp_ring_resize(struct ctx_cam *cam, int new_size)
|
||||
|
||||
tmp =(struct ctx_image_data*) mymalloc(new_size * sizeof(struct ctx_image_data));
|
||||
|
||||
if (smallest > 0){
|
||||
if (smallest > 0) {
|
||||
memcpy(tmp, cam->imgs.image_ring, sizeof(struct ctx_image_data) * smallest);
|
||||
}
|
||||
|
||||
for(i = smallest; i < new_size; i++) {
|
||||
tmp[i].image_norm =(unsigned char*) mymalloc(cam->imgs.size_norm);
|
||||
memset(tmp[i].image_norm, 0x80, cam->imgs.size_norm); /* initialize to grey */
|
||||
if (cam->imgs.size_high > 0){
|
||||
if (cam->imgs.size_high > 0) {
|
||||
tmp[i].image_high =(unsigned char*) mymalloc(cam->imgs.size_high);
|
||||
memset(tmp[i].image_high, 0x80, cam->imgs.size_high);
|
||||
}
|
||||
@@ -91,11 +91,15 @@ static void mlp_ring_destroy(struct ctx_cam *cam)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (cam->imgs.image_ring == NULL) return;
|
||||
if (cam->imgs.image_ring == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (i = 0; i < cam->imgs.ring_size; i++){
|
||||
for (i = 0; i < cam->imgs.ring_size; i++) {
|
||||
free(cam->imgs.image_ring[i].image_norm);
|
||||
if (cam->imgs.size_high >0 ) free(cam->imgs.image_ring[i].image_high);
|
||||
if (cam->imgs.size_high >0 ) {
|
||||
free(cam->imgs.image_ring[i].image_high);
|
||||
}
|
||||
}
|
||||
free(cam->imgs.image_ring);
|
||||
|
||||
@@ -109,13 +113,13 @@ static void mlp_ring_process_debug(struct ctx_cam *cam)
|
||||
char tmp[32];
|
||||
const char *t;
|
||||
|
||||
if (cam->imgs.image_ring[cam->imgs.ring_out].flags & IMAGE_TRIGGER){
|
||||
if (cam->imgs.image_ring[cam->imgs.ring_out].flags & IMAGE_TRIGGER) {
|
||||
t = "Trigger";
|
||||
} else if (cam->imgs.image_ring[cam->imgs.ring_out].flags & IMAGE_MOTION){
|
||||
} else if (cam->imgs.image_ring[cam->imgs.ring_out].flags & IMAGE_MOTION) {
|
||||
t = "Motion";
|
||||
} else if (cam->imgs.image_ring[cam->imgs.ring_out].flags & IMAGE_PRECAP){
|
||||
} else if (cam->imgs.image_ring[cam->imgs.ring_out].flags & IMAGE_PRECAP) {
|
||||
t = "Precap";
|
||||
} else if (cam->imgs.image_ring[cam->imgs.ring_out].flags & IMAGE_POSTCAP){
|
||||
} else if (cam->imgs.image_ring[cam->imgs.ring_out].flags & IMAGE_POSTCAP) {
|
||||
t = "Postcap";
|
||||
} else {
|
||||
t = "Other";
|
||||
@@ -136,20 +140,22 @@ static void mlp_ring_process(struct ctx_cam *cam)
|
||||
struct ctx_image_data *saved_current_image = cam->current_image;
|
||||
|
||||
do {
|
||||
if ((cam->imgs.image_ring[cam->imgs.ring_out].flags & (IMAGE_SAVE | IMAGE_SAVED)) != IMAGE_SAVE){
|
||||
if ((cam->imgs.image_ring[cam->imgs.ring_out].flags & (IMAGE_SAVE | IMAGE_SAVED)) != IMAGE_SAVE) {
|
||||
break;
|
||||
}
|
||||
|
||||
cam->current_image = &cam->imgs.image_ring[cam->imgs.ring_out];
|
||||
|
||||
if (cam->imgs.image_ring[cam->imgs.ring_out].shot < cam->conf->framerate) {
|
||||
if (cam->motapp->log_level >= DBG) mlp_ring_process_debug(cam);
|
||||
if (cam->motapp->log_level >= DBG) {
|
||||
mlp_ring_process_debug(cam);
|
||||
}
|
||||
|
||||
event(cam, EVENT_IMAGE_DETECTED,
|
||||
&cam->imgs.image_ring[cam->imgs.ring_out], NULL, NULL,
|
||||
&cam->imgs.image_ring[cam->imgs.ring_out].imgts);
|
||||
|
||||
if (cam->movie_last_shot >= 0){
|
||||
if (cam->movie_last_shot >= 0) {
|
||||
cam->movie_last_shot = cam->imgs.image_ring[cam->imgs.ring_out].shot;
|
||||
}
|
||||
}
|
||||
@@ -196,7 +202,7 @@ static void mlp_detected_trigger(struct ctx_cam *cam, struct ctx_image_data *img
|
||||
MOTION_LOG(NTC, TYPE_ALL, NO_ERRNO, _("Motion detected - starting event %d"),
|
||||
cam->event_nr);
|
||||
|
||||
if (cam->new_img & (NEWIMG_FIRST | NEWIMG_BEST | NEWIMG_CENTER)){
|
||||
if (cam->new_img & (NEWIMG_FIRST | NEWIMG_BEST | NEWIMG_CENTER)) {
|
||||
pic_save_preview(cam, img);
|
||||
}
|
||||
|
||||
@@ -247,10 +253,10 @@ static void mlp_detected(struct ctx_cam *cam, struct ctx_image_data *img)
|
||||
mlp_detected_trigger(cam, img);
|
||||
|
||||
if (img->shot < conf->framerate) {
|
||||
if (conf->stream_motion && !cam->motapp->setup_mode && img->shot != 1){
|
||||
if (conf->stream_motion && !cam->motapp->setup_mode && img->shot != 1) {
|
||||
event(cam, EVENT_STREAM, img, NULL, NULL, &img->imgts);
|
||||
}
|
||||
if (conf->picture_output_motion != "off"){
|
||||
if (conf->picture_output_motion != "off") {
|
||||
event(cam, EVENT_IMAGEM_DETECTED, NULL, NULL, NULL, &img->imgts);
|
||||
}
|
||||
}
|
||||
@@ -262,7 +268,9 @@ static void mlp_detected(struct ctx_cam *cam, struct ctx_image_data *img)
|
||||
static void mlp_mask_privacy(struct ctx_cam *cam)
|
||||
{
|
||||
|
||||
if (cam->imgs.mask_privacy == NULL) return;
|
||||
if (cam->imgs.mask_privacy == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* This function uses long operations to process 4 (32 bit) or 8 (64 bit)
|
||||
@@ -280,11 +288,14 @@ static void mlp_mask_privacy(struct ctx_cam *cam)
|
||||
int indx_max; /* 1 if we are only doing norm, 2 if we are doing both norm and high */
|
||||
|
||||
indx_img = 1;
|
||||
indx_max = 1;
|
||||
if (cam->imgs.size_high > 0) indx_max = 2;
|
||||
if (cam->imgs.size_high > 0) {
|
||||
indx_max = 2;
|
||||
} else {
|
||||
indx_max = 1;
|
||||
}
|
||||
increment = sizeof(unsigned long);
|
||||
|
||||
while (indx_img <= indx_max){
|
||||
while (indx_img <= indx_max) {
|
||||
if (indx_img == 1) {
|
||||
/* Normal Resolution */
|
||||
index_y = cam->imgs.height * cam->imgs.width;
|
||||
@@ -328,7 +339,9 @@ static void mlp_mask_privacy(struct ctx_cam *cam)
|
||||
}
|
||||
|
||||
while (--index_crcb >= 0) {
|
||||
if (*(mask++) == 0x00) *image = 0x80; // Mask last remaining bytes.
|
||||
if (*(mask++) == 0x00) {
|
||||
*image = 0x80; // Mask last remaining bytes.
|
||||
}
|
||||
image += 1;
|
||||
}
|
||||
|
||||
@@ -423,9 +436,9 @@ int mlp_cam_next(struct ctx_cam *cam, struct ctx_image_data *img_data)
|
||||
}
|
||||
|
||||
if (cam->camera_type == CAMERA_TYPE_NETCAM) {
|
||||
if (cam->video_dev == -1)
|
||||
if (cam->video_dev == -1) {
|
||||
return NETCAM_GENERAL_ERROR;
|
||||
|
||||
}
|
||||
return netcam_next(cam, img_data);
|
||||
}
|
||||
|
||||
@@ -478,12 +491,15 @@ static void mlp_init_firstimage(struct ctx_cam *cam)
|
||||
cam->current_image = &cam->imgs.image_ring[cam->imgs.ring_in];
|
||||
if (cam->video_dev >= 0) {
|
||||
for (indx = 0; indx < 5; indx++) {
|
||||
if (mlp_cam_next(cam, cam->current_image) == 0) break;
|
||||
if (mlp_cam_next(cam, cam->current_image) == 0) {
|
||||
break;
|
||||
}
|
||||
SLEEP(2, 0);
|
||||
}
|
||||
|
||||
if (indx >= 5) {
|
||||
memset(cam->current_image->image_norm, 0x80, cam->imgs.size_norm); /* initialize to grey */
|
||||
memset(cam->current_image->image_norm, 0x80, cam->imgs.size_norm);
|
||||
/* initialize to grey */
|
||||
draw_text(cam->current_image->image_norm , cam->imgs.width, cam->imgs.height,
|
||||
10, 20, "Error capturing first image", cam->text_scale);
|
||||
MOTION_LOG(ERR, TYPE_ALL, NO_ERRNO, _("Error capturing first image"));
|
||||
@@ -502,7 +518,7 @@ static int mlp_check_szimg(struct ctx_cam *cam)
|
||||
,cam->imgs.width, cam->imgs.height);
|
||||
return -1;
|
||||
}
|
||||
if ((cam->imgs.width < 64) || (cam->imgs.height < 64)){
|
||||
if ((cam->imgs.width < 64) || (cam->imgs.height < 64)) {
|
||||
MOTION_LOG(ERR, TYPE_ALL, NO_ERRNO
|
||||
,_("Motion only supports width and height greater than or equal to 64 %dx%d")
|
||||
,cam->imgs.width, cam->imgs.height);
|
||||
@@ -562,7 +578,7 @@ static void mlp_init_buffers(struct ctx_cam *cam)
|
||||
cam->imgs.image_preview.image_norm =(unsigned char*) mymalloc(cam->imgs.size_norm);
|
||||
cam->imgs.common_buffer =(unsigned char*) mymalloc(3 * cam->imgs.width * cam->imgs.height);
|
||||
cam->imgs.image_secondary =(unsigned char*) mymalloc(3 * cam->imgs.width * cam->imgs.height);
|
||||
if (cam->imgs.size_high > 0){
|
||||
if (cam->imgs.size_high > 0) {
|
||||
cam->imgs.image_preview.image_high =(unsigned char*) mymalloc(cam->imgs.size_high);
|
||||
}
|
||||
|
||||
@@ -584,7 +600,7 @@ static void mlp_init_values(struct ctx_cam *cam)
|
||||
cam->noise = cam->conf->noise_level;
|
||||
|
||||
cam->threshold = cam->conf->threshold;
|
||||
if (cam->conf->threshold_maximum > cam->conf->threshold ){
|
||||
if (cam->conf->threshold_maximum > cam->conf->threshold ) {
|
||||
cam->threshold_maximum = cam->conf->threshold_maximum;
|
||||
} else {
|
||||
cam->threshold_maximum = (cam->imgs.height * cam->imgs.width * 3) / 2;
|
||||
@@ -643,7 +659,7 @@ static void mlp_init_ref(struct ctx_cam *cam)
|
||||
|
||||
memcpy(cam->imgs.image_vprvcy, cam->current_image->image_norm, cam->imgs.size_norm);
|
||||
|
||||
if (cam->conf->primary_method == 0){
|
||||
if (cam->conf->primary_method == 0) {
|
||||
alg_update_reference_frame(cam, RESET_REF_FRAME);
|
||||
} else if (cam->conf->primary_method == 1) {
|
||||
//alg_new_update_frame(cam);
|
||||
@@ -661,13 +677,19 @@ static int mlp_init(struct ctx_cam *cam)
|
||||
|
||||
pthread_setspecific(tls_key_threadnr, (void *)((unsigned long)cam->threadnr));
|
||||
|
||||
if (init_camera_type(cam) != 0 ) return -1;
|
||||
if (init_camera_type(cam) != 0 ) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
mlp_init_values(cam);
|
||||
|
||||
if (mlp_init_cam_start(cam) != 0) return -1;
|
||||
if (mlp_init_cam_start(cam) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (mlp_check_szimg(cam) != 0) return -1;
|
||||
if (mlp_check_szimg(cam) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
mlp_ring_resize(cam, 1); /* Create a initial precapture ring buffer with 1 frame */
|
||||
|
||||
@@ -717,7 +739,9 @@ void mlp_cleanup(struct ctx_cam *cam)
|
||||
|
||||
algsec_deinit(cam);
|
||||
|
||||
if (cam->video_dev >= 0) mlp_cam_close(cam);
|
||||
if (cam->video_dev >= 0) {
|
||||
mlp_cam_close(cam);
|
||||
}
|
||||
|
||||
free(cam->imgs.image_motion.image_norm);
|
||||
cam->imgs.image_motion.image_norm = NULL;
|
||||
@@ -749,19 +773,29 @@ void mlp_cleanup(struct ctx_cam *cam)
|
||||
free(cam->imgs.smartmask_buffer);
|
||||
cam->imgs.smartmask_buffer = NULL;
|
||||
|
||||
if (cam->imgs.mask) free(cam->imgs.mask);
|
||||
if (cam->imgs.mask) {
|
||||
free(cam->imgs.mask);
|
||||
}
|
||||
cam->imgs.mask = NULL;
|
||||
|
||||
if (cam->imgs.mask_privacy) free(cam->imgs.mask_privacy);
|
||||
if (cam->imgs.mask_privacy) {
|
||||
free(cam->imgs.mask_privacy);
|
||||
}
|
||||
cam->imgs.mask_privacy = NULL;
|
||||
|
||||
if (cam->imgs.mask_privacy_uv) free(cam->imgs.mask_privacy_uv);
|
||||
if (cam->imgs.mask_privacy_uv) {
|
||||
free(cam->imgs.mask_privacy_uv);
|
||||
}
|
||||
cam->imgs.mask_privacy_uv = NULL;
|
||||
|
||||
if (cam->imgs.mask_privacy_high) free(cam->imgs.mask_privacy_high);
|
||||
if (cam->imgs.mask_privacy_high) {
|
||||
free(cam->imgs.mask_privacy_high);
|
||||
}
|
||||
cam->imgs.mask_privacy_high = NULL;
|
||||
|
||||
if (cam->imgs.mask_privacy_high_uv) free(cam->imgs.mask_privacy_high_uv);
|
||||
if (cam->imgs.mask_privacy_high_uv) {
|
||||
free(cam->imgs.mask_privacy_high_uv);
|
||||
}
|
||||
cam->imgs.mask_privacy_high_uv = NULL;
|
||||
|
||||
free(cam->imgs.common_buffer);
|
||||
@@ -773,7 +807,7 @@ void mlp_cleanup(struct ctx_cam *cam)
|
||||
free(cam->imgs.image_preview.image_norm);
|
||||
cam->imgs.image_preview.image_norm = NULL;
|
||||
|
||||
if (cam->imgs.size_high > 0){
|
||||
if (cam->imgs.size_high > 0) {
|
||||
free(cam->imgs.image_preview.image_high);
|
||||
cam->imgs.image_preview.image_high = NULL;
|
||||
}
|
||||
@@ -834,13 +868,15 @@ static void mlp_prepare(struct ctx_cam *cam)
|
||||
cam->frame_last_ts.tv_nsec = cam->frame_curr_ts.tv_nsec;
|
||||
clock_gettime(CLOCK_REALTIME, &cam->frame_curr_ts);
|
||||
|
||||
if (cam->conf->pre_capture < 0)
|
||||
if (cam->conf->pre_capture < 0) {
|
||||
cam->conf->pre_capture = 0;
|
||||
}
|
||||
|
||||
frame_buffer_size = cam->conf->pre_capture + cam->conf->minimum_motion_frames;
|
||||
|
||||
if (cam->imgs.ring_size != frame_buffer_size)
|
||||
if (cam->imgs.ring_size != frame_buffer_size) {
|
||||
mlp_ring_resize(cam, frame_buffer_size);
|
||||
}
|
||||
|
||||
if (cam->frame_last_ts.tv_sec != cam->frame_curr_ts.tv_sec) {
|
||||
cam->lastrate = cam->shots + 1;
|
||||
@@ -848,8 +884,9 @@ static void mlp_prepare(struct ctx_cam *cam)
|
||||
|
||||
if (cam->conf->minimum_frame_time) {
|
||||
cam->minimum_frame_time_downcounter--;
|
||||
if (cam->minimum_frame_time_downcounter == 0)
|
||||
if (cam->minimum_frame_time_downcounter == 0) {
|
||||
cam->get_image = 1;
|
||||
}
|
||||
} else {
|
||||
cam->get_image = 1;
|
||||
}
|
||||
@@ -857,8 +894,9 @@ static void mlp_prepare(struct ctx_cam *cam)
|
||||
|
||||
cam->shots++;
|
||||
|
||||
if (cam->startup_frames > 0)
|
||||
if (cam->startup_frames > 0) {
|
||||
cam->startup_frames--;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -872,13 +910,15 @@ static void mlp_resetimages(struct ctx_cam *cam)
|
||||
}
|
||||
|
||||
/* ring_buffer_in is pointing to current pos, update before put in a new image */
|
||||
if (++cam->imgs.ring_in >= cam->imgs.ring_size)
|
||||
if (++cam->imgs.ring_in >= cam->imgs.ring_size) {
|
||||
cam->imgs.ring_in = 0;
|
||||
}
|
||||
|
||||
/* Check if we have filled the ring buffer, throw away last image */
|
||||
if (cam->imgs.ring_in == cam->imgs.ring_out) {
|
||||
if (++cam->imgs.ring_out >= cam->imgs.ring_size)
|
||||
if (++cam->imgs.ring_out >= cam->imgs.ring_size) {
|
||||
cam->imgs.ring_out = 0;
|
||||
}
|
||||
}
|
||||
|
||||
cam->current_image = &cam->imgs.image_ring[cam->imgs.ring_in];
|
||||
@@ -914,7 +954,9 @@ static int mlp_retry(struct ctx_cam *cam)
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (mlp_check_szimg(cam) != 0) return 1;
|
||||
if (mlp_check_szimg(cam) != 0) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* If the netcam has different dimensions than in the config file
|
||||
@@ -940,7 +982,9 @@ static int mlp_retry(struct ctx_cam *cam)
|
||||
* and the mlp_cam_start ONLY re-populates the height/width so we can check the size here.
|
||||
*/
|
||||
size_high = (cam->imgs.width_high * cam->imgs.height_high * 3) / 2;
|
||||
if (cam->imgs.size_high != size_high) return 1;
|
||||
if (cam->imgs.size_high != size_high) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -953,10 +997,11 @@ static int mlp_capture(struct ctx_cam *cam)
|
||||
int vid_return_code = 0; /* Return code used when calling mlp_cam_next */
|
||||
struct timespec ts1;
|
||||
|
||||
if (cam->video_dev >= 0)
|
||||
if (cam->video_dev >= 0) {
|
||||
vid_return_code = mlp_cam_next(cam, cam->current_image);
|
||||
else
|
||||
} else {
|
||||
vid_return_code = 1; /* Non fatal error */
|
||||
}
|
||||
|
||||
if (vid_return_code == 0) {
|
||||
cam->lost_connection = 0;
|
||||
@@ -986,7 +1031,7 @@ static int mlp_capture(struct ctx_cam *cam)
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (cam->connectionlosttime == 0){
|
||||
if (cam->connectionlosttime == 0) {
|
||||
cam->connectionlosttime = cam->frame_curr_ts.tv_sec;
|
||||
}
|
||||
|
||||
@@ -998,10 +1043,11 @@ static int mlp_capture(struct ctx_cam *cam)
|
||||
} else {
|
||||
cam->lost_connection = 1;
|
||||
|
||||
if (cam->video_dev >= 0)
|
||||
if (cam->video_dev >= 0) {
|
||||
tmpin = "CONNECTION TO CAMERA LOST\\nSINCE %Y-%m-%d %T";
|
||||
else
|
||||
} else {
|
||||
tmpin = "UNABLE TO OPEN VIDEO DEVICE\\nSINCE %Y-%m-%d %T";
|
||||
}
|
||||
|
||||
ts1.tv_sec=cam->connectionlosttime;
|
||||
ts1.tv_nsec = 0;
|
||||
@@ -1039,7 +1085,7 @@ static void mlp_detection(struct ctx_cam *cam)
|
||||
}
|
||||
|
||||
if ( !cam->pause ) {
|
||||
if (cam->conf->primary_method == 0){
|
||||
if (cam->conf->primary_method == 0) {
|
||||
alg_diff(cam);
|
||||
alg_lightswitch(cam);
|
||||
alg_despeckle(cam);
|
||||
@@ -1061,12 +1107,12 @@ static void mlp_tuning(struct ctx_cam *cam)
|
||||
alg_noise_tune(cam, cam->imgs.image_vprvcy);
|
||||
}
|
||||
|
||||
if (cam->conf->threshold_tune){
|
||||
if (cam->conf->threshold_tune) {
|
||||
alg_threshold_tune(cam, cam->current_image->diffs, cam->detecting_motion);
|
||||
}
|
||||
|
||||
if ((cam->current_image->diffs > cam->threshold) &&
|
||||
(cam->current_image->diffs < cam->threshold_maximum)){
|
||||
(cam->current_image->diffs < cam->threshold_maximum)) {
|
||||
alg_locate_center_size(&cam->imgs
|
||||
, cam->imgs.width
|
||||
, cam->imgs.height
|
||||
@@ -1090,35 +1136,38 @@ static void mlp_overlay(struct ctx_cam *cam)
|
||||
((cam->conf->picture_output_motion != "off") ||
|
||||
cam->conf->movie_output_motion ||
|
||||
cam->motapp->setup_mode ||
|
||||
(cam->stream.motion.cnct_count > 0)))
|
||||
(cam->stream.motion.cnct_count > 0))) {
|
||||
draw_smartmask(cam, cam->imgs.image_motion.image_norm);
|
||||
}
|
||||
|
||||
if (cam->imgs.largest_label &&
|
||||
((cam->conf->picture_output_motion != "off") ||
|
||||
cam->conf->movie_output_motion ||
|
||||
cam->motapp->setup_mode ||
|
||||
(cam->stream.motion.cnct_count > 0)))
|
||||
(cam->stream.motion.cnct_count > 0))) {
|
||||
draw_largest_label(cam, cam->imgs.image_motion.image_norm);
|
||||
}
|
||||
|
||||
if (cam->imgs.mask &&
|
||||
((cam->conf->picture_output_motion != "off") ||
|
||||
cam->conf->movie_output_motion ||
|
||||
cam->motapp->setup_mode ||
|
||||
(cam->stream.motion.cnct_count > 0)))
|
||||
(cam->stream.motion.cnct_count > 0))) {
|
||||
draw_fixed_mask(cam, cam->imgs.image_motion.image_norm);
|
||||
}
|
||||
|
||||
if (cam->conf->text_changes) {
|
||||
if (!cam->pause)
|
||||
if (!cam->pause) {
|
||||
sprintf(tmp, "%d", cam->current_image->diffs);
|
||||
else
|
||||
} else {
|
||||
sprintf(tmp, "-");
|
||||
|
||||
}
|
||||
draw_text(cam->current_image->image_norm, cam->imgs.width, cam->imgs.height,
|
||||
cam->imgs.width - 10, 10, tmp, cam->text_scale);
|
||||
}
|
||||
|
||||
if (cam->motapp->setup_mode || (cam->stream.motion.cnct_count > 0)) {
|
||||
if (cam->conf->primary_method == 0){
|
||||
if (cam->conf->primary_method == 0) {
|
||||
sprintf(tmp, "D:%5d L:%3d N:%3d", cam->current_image->diffs,
|
||||
cam->current_image->total_labels, cam->noise);
|
||||
draw_text(cam->imgs.image_motion.image_norm, cam->imgs.width, cam->imgs.height,
|
||||
@@ -1169,8 +1218,9 @@ static void mlp_actions_emulate(struct ctx_cam *cam)
|
||||
|
||||
int indx;
|
||||
|
||||
if ( (cam->detecting_motion == FALSE) && (cam->movie_norm != NULL) )
|
||||
if ( (cam->detecting_motion == FALSE) && (cam->movie_norm != NULL) ) {
|
||||
movie_reset_start_time(cam->movie_norm, &cam->current_image->imgts);
|
||||
}
|
||||
|
||||
cam->detecting_motion = TRUE;
|
||||
if (cam->conf->post_capture > 0) {
|
||||
@@ -1179,7 +1229,7 @@ static void mlp_actions_emulate(struct ctx_cam *cam)
|
||||
|
||||
cam->current_image->flags |= (IMAGE_TRIGGER | IMAGE_SAVE);
|
||||
/* Mark all images in image_ring to be saved */
|
||||
for (indx = 0; indx < cam->imgs.ring_size; indx++){
|
||||
for (indx = 0; indx < cam->imgs.ring_size; indx++) {
|
||||
cam->imgs.image_ring[indx].flags |= IMAGE_SAVE;
|
||||
}
|
||||
|
||||
@@ -1193,8 +1243,10 @@ static void mlp_actions_motion(struct ctx_cam *cam)
|
||||
int pos = cam->imgs.ring_in;
|
||||
|
||||
for (indx = 0; indx < cam->conf->minimum_motion_frames; indx++) {
|
||||
if (cam->imgs.image_ring[pos].flags & IMAGE_MOTION) frame_count++;
|
||||
if (pos == 0){
|
||||
if (cam->imgs.image_ring[pos].flags & IMAGE_MOTION) {
|
||||
frame_count++;
|
||||
}
|
||||
if (pos == 0) {
|
||||
pos = cam->imgs.ring_size-1;
|
||||
} else {
|
||||
pos--;
|
||||
@@ -1205,13 +1257,13 @@ static void mlp_actions_motion(struct ctx_cam *cam)
|
||||
|
||||
cam->current_image->flags |= (IMAGE_TRIGGER | IMAGE_SAVE);
|
||||
|
||||
if ( (cam->detecting_motion == FALSE) && (cam->movie_norm != NULL) ){
|
||||
if ( (cam->detecting_motion == FALSE) && (cam->movie_norm != NULL) ) {
|
||||
movie_reset_start_time(cam->movie_norm, &cam->current_image->imgts);
|
||||
}
|
||||
cam->detecting_motion = TRUE;
|
||||
cam->postcap = cam->conf->post_capture;
|
||||
|
||||
for (indx = 0; indx < cam->imgs.ring_size; indx++){
|
||||
for (indx = 0; indx < cam->imgs.ring_size; indx++) {
|
||||
cam->imgs.image_ring[indx].flags |= IMAGE_SAVE;
|
||||
}
|
||||
|
||||
@@ -1249,8 +1301,8 @@ static void mlp_actions_event(struct ctx_cam *cam)
|
||||
|
||||
mlp_track_center(cam);
|
||||
|
||||
if (cam->algsec_inuse){
|
||||
if (cam->algsec->isdetected){
|
||||
if (cam->algsec_inuse) {
|
||||
if (cam->algsec->isdetected) {
|
||||
event(cam, EVENT_SECDETECT, NULL, NULL, NULL, &cam->current_image->imgts);
|
||||
}
|
||||
cam->algsec->isdetected = false;
|
||||
@@ -1284,15 +1336,19 @@ static void mlp_actions(struct ctx_cam *cam)
|
||||
cam->postcap--;
|
||||
} else {
|
||||
cam->current_image->flags |= IMAGE_PRECAP;
|
||||
if ((cam->conf->event_gap == 0) && cam->detecting_motion) cam->event_stop = TRUE;
|
||||
if ((cam->conf->event_gap == 0) && cam->detecting_motion) {
|
||||
cam->event_stop = TRUE;
|
||||
}
|
||||
cam->detecting_motion = FALSE;
|
||||
}
|
||||
|
||||
if (cam->current_image->flags & IMAGE_SAVE){
|
||||
if (cam->current_image->flags & IMAGE_SAVE) {
|
||||
cam->lasttime = cam->current_image->imgts.tv_sec;
|
||||
}
|
||||
|
||||
if (cam->detecting_motion) algsec_detect(cam);
|
||||
if (cam->detecting_motion) {
|
||||
algsec_detect(cam);
|
||||
}
|
||||
|
||||
mlp_areadetect(cam);
|
||||
|
||||
@@ -1362,23 +1418,24 @@ static void mlp_timelapse(struct ctx_cam *cam)
|
||||
(cam->frame_curr_ts.tv_sec % 60 < cam->frame_last_ts.tv_sec % 60) &&
|
||||
cam->shots == 0) {
|
||||
|
||||
if (cam->conf->timelapse_mode == "daily"){
|
||||
if (timestamp_tm.tm_hour == 0)
|
||||
if (cam->conf->timelapse_mode == "daily") {
|
||||
if (timestamp_tm.tm_hour == 0) {
|
||||
event(cam, EVENT_TIMELAPSEEND, NULL, NULL, NULL, &cam->current_image->imgts);
|
||||
} else if (cam->conf->timelapse_mode == "hourly"){
|
||||
}
|
||||
} else if (cam->conf->timelapse_mode == "hourly") {
|
||||
event(cam, EVENT_TIMELAPSEEND, NULL, NULL, NULL, &cam->current_image->imgts);
|
||||
} else if (cam->conf->timelapse_mode == "weekly-sunday"){
|
||||
if (timestamp_tm.tm_wday == 0 &&
|
||||
timestamp_tm.tm_hour == 0)
|
||||
} else if (cam->conf->timelapse_mode == "weekly-sunday") {
|
||||
if (timestamp_tm.tm_wday == 0 && timestamp_tm.tm_hour == 0) {
|
||||
event(cam, EVENT_TIMELAPSEEND, NULL, NULL, NULL, &cam->current_image->imgts);
|
||||
} else if (cam->conf->timelapse_mode == "weekly-monday"){
|
||||
if (timestamp_tm.tm_wday == 1 &&
|
||||
timestamp_tm.tm_hour == 0)
|
||||
}
|
||||
} else if (cam->conf->timelapse_mode == "weekly-monday") {
|
||||
if (timestamp_tm.tm_wday == 1 && timestamp_tm.tm_hour == 0) {
|
||||
event(cam, EVENT_TIMELAPSEEND, NULL, NULL, NULL, &cam->current_image->imgts);
|
||||
} else if (cam->conf->timelapse_mode == "monthly"){
|
||||
if (timestamp_tm.tm_mday == 1 &&
|
||||
timestamp_tm.tm_hour == 0)
|
||||
}
|
||||
} else if (cam->conf->timelapse_mode == "monthly") {
|
||||
if (timestamp_tm.tm_mday == 1 && timestamp_tm.tm_hour == 0) {
|
||||
event(cam, EVENT_TIMELAPSEEND, NULL, NULL, NULL, &cam->current_image->imgts);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1409,7 +1466,7 @@ static void mlp_loopback(struct ctx_cam *cam)
|
||||
} else {
|
||||
event(cam, EVENT_IMAGE, cam->current_image, NULL, &cam->pipe, &cam->current_image->imgts);
|
||||
|
||||
if (!cam->conf->stream_motion || cam->shots == 0){
|
||||
if (!cam->conf->stream_motion || cam->shots == 0) {
|
||||
event(cam, EVENT_STREAM, cam->current_image, NULL, NULL, &cam->current_image->imgts);
|
||||
}
|
||||
}
|
||||
@@ -1422,18 +1479,20 @@ static void mlp_parmsupdate(struct ctx_cam *cam)
|
||||
{
|
||||
|
||||
/* Check for some config parameter changes but only every second */
|
||||
if (cam->shots != 0) return;
|
||||
if (cam->shots != 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (cam->parms_changed ) {
|
||||
draw_init_scale(cam); /* Initialize and validate text_scale */
|
||||
|
||||
if (cam->conf->picture_output == "on"){
|
||||
if (cam->conf->picture_output == "on") {
|
||||
cam->new_img = NEWIMG_ON;
|
||||
} else if (cam->conf->picture_output == "first"){
|
||||
} else if (cam->conf->picture_output == "first") {
|
||||
cam->new_img = NEWIMG_FIRST;
|
||||
} else if (cam->conf->picture_output == "best"){
|
||||
} else if (cam->conf->picture_output == "best") {
|
||||
cam->new_img = NEWIMG_BEST;
|
||||
} else if (cam->conf->picture_output == "center"){
|
||||
} else if (cam->conf->picture_output == "center") {
|
||||
cam->new_img = NEWIMG_CENTER;
|
||||
} else {
|
||||
cam->new_img = NEWIMG_OFF;
|
||||
@@ -1441,19 +1500,19 @@ static void mlp_parmsupdate(struct ctx_cam *cam)
|
||||
|
||||
if (cam->conf->locate_motion_mode == "on") {
|
||||
cam->locate_motion_mode = LOCATE_ON;
|
||||
} else if (cam->conf->locate_motion_mode == "preview"){
|
||||
} else if (cam->conf->locate_motion_mode == "preview") {
|
||||
cam->locate_motion_mode = LOCATE_PREVIEW;
|
||||
} else {
|
||||
cam->locate_motion_mode = LOCATE_OFF;
|
||||
}
|
||||
|
||||
if (cam->conf->locate_motion_style == "box"){
|
||||
if (cam->conf->locate_motion_style == "box") {
|
||||
cam->locate_motion_style = LOCATE_BOX;
|
||||
} else if (cam->conf->locate_motion_style == "redbox"){
|
||||
} else if (cam->conf->locate_motion_style == "redbox") {
|
||||
cam->locate_motion_style = LOCATE_REDBOX;
|
||||
} else if (cam->conf->locate_motion_style == "cross"){
|
||||
} else if (cam->conf->locate_motion_style == "cross") {
|
||||
cam->locate_motion_style = LOCATE_CROSS;
|
||||
} else if (cam->conf->locate_motion_style == "redcross"){
|
||||
} else if (cam->conf->locate_motion_style == "redcross") {
|
||||
cam->locate_motion_style = LOCATE_REDCROSS;
|
||||
} else {
|
||||
cam->locate_motion_style = LOCATE_BOX;
|
||||
@@ -1473,13 +1532,13 @@ static void mlp_parmsupdate(struct ctx_cam *cam)
|
||||
dbse_sqlmask_update(cam);
|
||||
|
||||
cam->threshold = cam->conf->threshold;
|
||||
if (cam->conf->threshold_maximum > cam->conf->threshold ){
|
||||
if (cam->conf->threshold_maximum > cam->conf->threshold ) {
|
||||
cam->threshold_maximum = cam->conf->threshold_maximum;
|
||||
} else {
|
||||
cam->threshold_maximum = (cam->imgs.height * cam->imgs.width * 3) / 2;
|
||||
}
|
||||
|
||||
if (!cam->conf->noise_tune){
|
||||
if (!cam->conf->noise_tune) {
|
||||
cam->noise = cam->conf->noise_level;
|
||||
}
|
||||
|
||||
@@ -1502,7 +1561,7 @@ static void mlp_frametiming(struct ctx_cam *cam)
|
||||
int64_t avgtime;
|
||||
|
||||
/* Shuffle the last wait times*/
|
||||
for (indx=0; indx<AVGCNT-1; indx++){
|
||||
for (indx=0; indx<AVGCNT-1; indx++) {
|
||||
cam->frame_wait[indx]=cam->frame_wait[indx+1];
|
||||
}
|
||||
|
||||
@@ -1519,7 +1578,7 @@ static void mlp_frametiming(struct ctx_cam *cam)
|
||||
((ts2.tv_nsec - cam->frame_curr_ts.tv_nsec)/1000);
|
||||
|
||||
avgtime = 0;
|
||||
for (indx=0; indx<AVGCNT; indx++){
|
||||
for (indx=0; indx<AVGCNT; indx++) {
|
||||
avgtime = avgtime + cam->frame_wait[indx];
|
||||
}
|
||||
avgtime = (avgtime/AVGCNT);
|
||||
@@ -1545,13 +1604,17 @@ void *motion_loop(void *arg)
|
||||
cam->watchdog = cam->conf->watchdog_tmo;
|
||||
cam->running_cam = TRUE;
|
||||
|
||||
if (mlp_init(cam) == 0){
|
||||
if (mlp_init(cam) == 0) {
|
||||
while (!cam->finish_cam || cam->event_stop) {
|
||||
mlp_prepare(cam);
|
||||
if (cam->get_image) {
|
||||
mlp_resetimages(cam);
|
||||
if (mlp_retry(cam) == 1) break;
|
||||
if (mlp_capture(cam) == 1) break;
|
||||
if (mlp_retry(cam) == 1) {
|
||||
break;
|
||||
}
|
||||
if (mlp_capture(cam) == 1) {
|
||||
break;
|
||||
}
|
||||
mlp_detection(cam);
|
||||
mlp_tuning(cam);
|
||||
mlp_overlay(cam);
|
||||
|
||||
@@ -42,7 +42,7 @@ static void motion_signal_process(struct ctx_motapp *motapp)
|
||||
if (motapp->cam_list != NULL) {
|
||||
indx = 0;
|
||||
while (motapp->cam_list[indx] != NULL) {
|
||||
if (motapp->cam_list[indx]->conf->snapshot_interval){
|
||||
if (motapp->cam_list[indx]->conf->snapshot_interval) {
|
||||
motapp->cam_list[indx]->snapshot = true;
|
||||
}
|
||||
indx++;
|
||||
@@ -167,7 +167,7 @@ static void motion_remove_pid(struct ctx_motapp *motapp)
|
||||
if ((motapp->daemon) &&
|
||||
(motapp->pid_file != "") &&
|
||||
(motapp->restart_all == false)) {
|
||||
if (!unlink(motapp->pid_file.c_str())){
|
||||
if (!unlink(motapp->pid_file.c_str())) {
|
||||
MOTION_LOG(NTC, TYPE_ALL, NO_ERRNO, _("Removed process id file (pid file)."));
|
||||
} else{
|
||||
MOTION_LOG(ERR, TYPE_ALL, SHOW_ERRNO, _("Error removing pid file"));
|
||||
@@ -222,7 +222,7 @@ static void motion_daemon(struct ctx_motapp *motapp)
|
||||
* Changing dir to root enables people to unmount a disk
|
||||
* without having to stop Motion
|
||||
*/
|
||||
if (chdir("/")){
|
||||
if (chdir("/")) {
|
||||
MOTION_LOG(ERR, TYPE_ALL, SHOW_ERRNO, _("Could not change directory"));
|
||||
}
|
||||
|
||||
@@ -253,7 +253,7 @@ static void motion_daemon(struct ctx_motapp *motapp)
|
||||
}
|
||||
|
||||
/* Now it is safe to add the PID creation to the logs */
|
||||
if (pidf){
|
||||
if (pidf) {
|
||||
MOTION_LOG(NTC, TYPE_ALL, NO_ERRNO
|
||||
,_("Created process id file %s. Process ID is %d")
|
||||
,motapp->pid_file.c_str(), getpid());
|
||||
@@ -287,7 +287,7 @@ static void motion_camera_ids(struct ctx_cam **cam_list)
|
||||
/* Set defaults */
|
||||
indx = 0;
|
||||
while (cam_list[indx] != NULL){
|
||||
if (cam_list[indx]->conf->camera_id > 0){
|
||||
if (cam_list[indx]->conf->camera_id > 0) {
|
||||
cam_list[indx]->camera_id = cam_list[indx]->conf->camera_id;
|
||||
} else {
|
||||
cam_list[indx]->camera_id = indx;
|
||||
@@ -298,15 +298,19 @@ static void motion_camera_ids(struct ctx_cam **cam_list)
|
||||
invalid_ids = false;
|
||||
indx = 0;
|
||||
while (cam_list[indx] != NULL){
|
||||
if (cam_list[indx]->camera_id > 32000) invalid_ids = true;
|
||||
if (cam_list[indx]->camera_id > 32000) {
|
||||
invalid_ids = true;
|
||||
}
|
||||
indx2 = indx + 1;
|
||||
while (cam_list[indx2] != NULL){
|
||||
if (cam_list[indx]->camera_id == cam_list[indx2]->camera_id) invalid_ids = true;
|
||||
if (cam_list[indx]->camera_id == cam_list[indx2]->camera_id) {
|
||||
invalid_ids = true;
|
||||
}
|
||||
indx2++;
|
||||
}
|
||||
indx++;
|
||||
}
|
||||
if (invalid_ids){
|
||||
if (invalid_ids) {
|
||||
MOTION_LOG(ERR, TYPE_ALL, NO_ERRNO
|
||||
,_("Camara IDs are not unique or have values over 32,000. Falling back to thread numbers"));
|
||||
indx = 0;
|
||||
@@ -393,7 +397,7 @@ static void motion_startup(struct ctx_motapp *motapp, int daemonize, int argc, c
|
||||
}
|
||||
}
|
||||
|
||||
if (motapp->setup_mode){
|
||||
if (motapp->setup_mode) {
|
||||
MOTION_LOG(NTC, TYPE_ALL, NO_ERRNO,_("Motion running in setup mode."));
|
||||
}
|
||||
|
||||
@@ -469,7 +473,9 @@ static void motion_watchdog(struct ctx_motapp *motapp, int indx)
|
||||
* Best to just not get into a watchdog situation...
|
||||
*/
|
||||
|
||||
if (!motapp->cam_list[indx]->running_cam) return;
|
||||
if (!motapp->cam_list[indx]->running_cam) {
|
||||
return;
|
||||
}
|
||||
|
||||
motapp->cam_list[indx]->watchdog--;
|
||||
if (motapp->cam_list[indx]->watchdog == 0) {
|
||||
@@ -485,11 +491,11 @@ static void motion_watchdog(struct ctx_motapp *motapp, int indx)
|
||||
,_("Thread %d - Watchdog timeout did NOT restart, killing it!")
|
||||
, motapp->cam_list[indx]->threadnr);
|
||||
if ((motapp->cam_list[indx]->camera_type == CAMERA_TYPE_NETCAM) &&
|
||||
(motapp->cam_list[indx]->netcam != NULL)){
|
||||
(motapp->cam_list[indx]->netcam != NULL)) {
|
||||
pthread_cancel(motapp->cam_list[indx]->netcam->thread_id);
|
||||
}
|
||||
if ((motapp->cam_list[indx]->camera_type == CAMERA_TYPE_NETCAM) &&
|
||||
(motapp->cam_list[indx]->netcam_high != NULL)){
|
||||
(motapp->cam_list[indx]->netcam_high != NULL)) {
|
||||
pthread_cancel(motapp->cam_list[indx]->netcam_high->thread_id);
|
||||
}
|
||||
pthread_cancel(motapp->cam_list[indx]->thread_id);
|
||||
@@ -501,7 +507,7 @@ static void motion_watchdog(struct ctx_motapp *motapp, int indx)
|
||||
, motapp->cam_list[indx]->threadnr);
|
||||
|
||||
if ((motapp->cam_list[indx]->camera_type == CAMERA_TYPE_NETCAM) &&
|
||||
(motapp->cam_list[indx]->netcam != NULL)){
|
||||
(motapp->cam_list[indx]->netcam != NULL)) {
|
||||
if (!motapp->cam_list[indx]->netcam->handler_finished &&
|
||||
pthread_kill(motapp->cam_list[indx]->netcam->thread_id, 0) == ESRCH) {
|
||||
motapp->cam_list[indx]->netcam->handler_finished = true;
|
||||
@@ -514,7 +520,7 @@ static void motion_watchdog(struct ctx_motapp *motapp, int indx)
|
||||
}
|
||||
}
|
||||
if ((motapp->cam_list[indx]->camera_type == CAMERA_TYPE_NETCAM) &&
|
||||
(motapp->cam_list[indx]->netcam_high != NULL)){
|
||||
(motapp->cam_list[indx]->netcam_high != NULL)) {
|
||||
if (!motapp->cam_list[indx]->netcam_high->handler_finished &&
|
||||
pthread_kill(motapp->cam_list[indx]->netcam_high->thread_id, 0) == ESRCH) {
|
||||
motapp->cam_list[indx]->netcam_high->handler_finished = true;
|
||||
@@ -527,7 +533,7 @@ static void motion_watchdog(struct ctx_motapp *motapp, int indx)
|
||||
}
|
||||
}
|
||||
if (motapp->cam_list[indx]->running_cam &&
|
||||
pthread_kill(motapp->cam_list[indx]->thread_id, 0) == ESRCH){
|
||||
pthread_kill(motapp->cam_list[indx]->thread_id, 0) == ESRCH) {
|
||||
MOTION_LOG(DBG, TYPE_ALL, NO_ERRNO
|
||||
,_("Thread %d - Cleaning thread.")
|
||||
, motapp->cam_list[indx]->threadnr);
|
||||
@@ -559,7 +565,7 @@ static int motion_check_threadcount(struct ctx_motapp *motapp)
|
||||
thrdcnt = 0;
|
||||
|
||||
for (indx = (motapp->cam_list[1] != NULL ? 1 : 0); motapp->cam_list[indx]; indx++) {
|
||||
if (motapp->cam_list[indx]->running_cam || motapp->cam_list[indx]->restart_cam){
|
||||
if (motapp->cam_list[indx]->running_cam || motapp->cam_list[indx]->restart_cam) {
|
||||
thrdcnt++;
|
||||
}
|
||||
}
|
||||
|
||||
282
src/movie.cpp
282
src/movie.cpp
@@ -59,10 +59,11 @@ static void movie_encode_nal(struct ctx_movie *movie)
|
||||
movie_free_nal(movie);
|
||||
movie->nal_info_len = movie->pkt.size;
|
||||
movie->nal_info =(char*) malloc(movie->nal_info_len);
|
||||
if (movie->nal_info)
|
||||
if (movie->nal_info) {
|
||||
memcpy(movie->nal_info, &movie->pkt.data[0], movie->nal_info_len);
|
||||
else
|
||||
} else {
|
||||
movie->nal_info_len = 0;
|
||||
}
|
||||
} else if (movie->nal_info) {
|
||||
int old_size = movie->pkt.size;
|
||||
av_grow_packet(&movie->pkt, movie->nal_info_len);
|
||||
@@ -76,8 +77,7 @@ static int movie_timelapse_exists(const char *fname)
|
||||
{
|
||||
FILE *file;
|
||||
file = fopen(fname, "r");
|
||||
if (file)
|
||||
{
|
||||
if (file) {
|
||||
fclose(file);
|
||||
return 1;
|
||||
}
|
||||
@@ -89,7 +89,9 @@ static int movie_timelapse_append(struct ctx_movie *movie, AVPacket pkt)
|
||||
FILE *file;
|
||||
|
||||
file = fopen(movie->filename, "a");
|
||||
if (!file) return -1;
|
||||
if (!file) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
fwrite(pkt.data,1,pkt.size,file);
|
||||
|
||||
@@ -101,17 +103,17 @@ static int movie_timelapse_append(struct ctx_movie *movie, AVPacket pkt)
|
||||
static void movie_free_context(struct ctx_movie *movie)
|
||||
{
|
||||
|
||||
if (movie->picture != NULL){
|
||||
if (movie->picture != NULL) {
|
||||
myframe_free(movie->picture);
|
||||
movie->picture = NULL;
|
||||
}
|
||||
|
||||
if (movie->ctx_codec != NULL){
|
||||
if (movie->ctx_codec != NULL) {
|
||||
myavcodec_close(movie->ctx_codec);
|
||||
movie->ctx_codec = NULL;
|
||||
}
|
||||
|
||||
if (movie->oc != NULL){
|
||||
if (movie->oc != NULL) {
|
||||
avformat_free_context(movie->oc);
|
||||
movie->oc = NULL;
|
||||
}
|
||||
@@ -140,7 +142,7 @@ static int movie_get_oformat(struct ctx_movie *movie)
|
||||
codec_name[codec_name_len] = 0;
|
||||
|
||||
retcd = snprintf(basename,PATH_MAX,"%s",movie->filename);
|
||||
if ((retcd < 0) || (retcd >= PATH_MAX)){
|
||||
if ((retcd < 0) || (retcd >= PATH_MAX)) {
|
||||
MOTION_LOG(ERR, TYPE_ENCODER, NO_ERRNO
|
||||
,_("Error setting base file name"));
|
||||
movie_free_context(movie);
|
||||
@@ -148,12 +150,14 @@ static int movie_get_oformat(struct ctx_movie *movie)
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (movie->tlapse == TIMELAPSE_APPEND){
|
||||
if (movie->tlapse == TIMELAPSE_APPEND) {
|
||||
movie->oc->oformat = av_guess_format ("mpeg2video", NULL, NULL);
|
||||
if (movie->oc->oformat) movie->oc->oformat->video_codec = MY_CODEC_ID_MPEG2VIDEO;
|
||||
if (movie->oc->oformat) {
|
||||
movie->oc->oformat->video_codec = MY_CODEC_ID_MPEG2VIDEO;
|
||||
}
|
||||
retcd = snprintf(movie->filename,PATH_MAX,"%s.mpg",basename);
|
||||
if ((!movie->oc->oformat) ||
|
||||
(retcd < 0) || (retcd >= PATH_MAX)){
|
||||
(retcd < 0) || (retcd >= PATH_MAX)) {
|
||||
MOTION_LOG(ERR, TYPE_ENCODER, NO_ERRNO
|
||||
,_("Error setting timelapse append for codec %s"), codec_name);
|
||||
movie_free_context(movie);
|
||||
@@ -167,41 +171,53 @@ static int movie_get_oformat(struct ctx_movie *movie)
|
||||
if (mystreq(codec_name, "flv")) {
|
||||
movie->oc->oformat = av_guess_format("flv", NULL, NULL);
|
||||
retcd = snprintf(movie->filename,PATH_MAX,"%s.flv",basename);
|
||||
if (movie->oc->oformat) movie->oc->oformat->video_codec = MY_CODEC_ID_FLV1;
|
||||
if (movie->oc->oformat) {
|
||||
movie->oc->oformat->video_codec = MY_CODEC_ID_FLV1;
|
||||
}
|
||||
}
|
||||
|
||||
if (mystreq(codec_name, "ogg")) {
|
||||
movie->oc->oformat = av_guess_format("ogg", NULL, NULL);
|
||||
retcd = snprintf(movie->filename,PATH_MAX,"%s.ogg",basename);
|
||||
if (movie->oc->oformat) movie->oc->oformat->video_codec = MY_CODEC_ID_THEORA;
|
||||
if (movie->oc->oformat) {
|
||||
movie->oc->oformat->video_codec = MY_CODEC_ID_THEORA;
|
||||
}
|
||||
}
|
||||
|
||||
if (mystreq(codec_name, "vp8")) {
|
||||
movie->oc->oformat = av_guess_format("webm", NULL, NULL);
|
||||
retcd = snprintf(movie->filename,PATH_MAX,"%s.webm",basename);
|
||||
if (movie->oc->oformat) movie->oc->oformat->video_codec = MY_CODEC_ID_VP8;
|
||||
if (movie->oc->oformat) {
|
||||
movie->oc->oformat->video_codec = MY_CODEC_ID_VP8;
|
||||
}
|
||||
}
|
||||
|
||||
if (mystreq(codec_name, "mp4")) {
|
||||
movie->oc->oformat = av_guess_format("mp4", NULL, NULL);
|
||||
retcd = snprintf(movie->filename,PATH_MAX,"%s.mp4",basename);
|
||||
if (movie->oc->oformat) movie->oc->oformat->video_codec = MY_CODEC_ID_H264;
|
||||
if (movie->oc->oformat) {
|
||||
movie->oc->oformat->video_codec = MY_CODEC_ID_H264;
|
||||
}
|
||||
}
|
||||
|
||||
if (mystreq(codec_name, "mkv")) {
|
||||
movie->oc->oformat = av_guess_format("matroska", NULL, NULL);
|
||||
retcd = snprintf(movie->filename,PATH_MAX,"%s.mkv",basename);
|
||||
if (movie->oc->oformat) movie->oc->oformat->video_codec = MY_CODEC_ID_H264;
|
||||
if (movie->oc->oformat) {
|
||||
movie->oc->oformat->video_codec = MY_CODEC_ID_H264;
|
||||
}
|
||||
}
|
||||
|
||||
if (mystreq(codec_name, "hevc")) {
|
||||
movie->oc->oformat = av_guess_format("mp4", NULL, NULL);
|
||||
retcd = snprintf(movie->filename,PATH_MAX,"%s.mp4",basename);
|
||||
if (movie->oc->oformat) movie->oc->oformat->video_codec = MY_CODEC_ID_HEVC;
|
||||
if (movie->oc->oformat) {
|
||||
movie->oc->oformat->video_codec = MY_CODEC_ID_HEVC;
|
||||
}
|
||||
}
|
||||
|
||||
//Check for valid results
|
||||
if ((retcd < 0) || (retcd >= PATH_MAX)){
|
||||
if ((retcd < 0) || (retcd >= PATH_MAX)) {
|
||||
MOTION_LOG(ERR, TYPE_ENCODER, NO_ERRNO
|
||||
,_("Error setting file name"));
|
||||
movie_free_context(movie);
|
||||
@@ -237,19 +253,19 @@ static int movie_encode_video(struct ctx_movie *movie)
|
||||
char errstr[128];
|
||||
|
||||
retcd = avcodec_send_frame(movie->ctx_codec, movie->picture);
|
||||
if (retcd < 0 ){
|
||||
if (retcd < 0 ) {
|
||||
av_strerror(retcd, errstr, sizeof(errstr));
|
||||
MOTION_LOG(ERR, TYPE_ENCODER, NO_ERRNO
|
||||
,_("Error sending frame for encoding:%s"),errstr);
|
||||
return -1;
|
||||
}
|
||||
retcd = avcodec_receive_packet(movie->ctx_codec, &movie->pkt);
|
||||
if (retcd == AVERROR(EAGAIN)){
|
||||
if (retcd == AVERROR(EAGAIN)) {
|
||||
//Buffered packet. Throw special return code
|
||||
mypacket_unref(movie->pkt);
|
||||
return -2;
|
||||
}
|
||||
if (retcd < 0 ){
|
||||
if (retcd < 0 ) {
|
||||
av_strerror(retcd, errstr, sizeof(errstr));
|
||||
MOTION_LOG(ERR, TYPE_ENCODER, NO_ERRNO
|
||||
,_("Error receiving encoded packet video:%s"),errstr);
|
||||
@@ -257,7 +273,7 @@ static int movie_encode_video(struct ctx_movie *movie)
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (movie->preferred_codec == USER_CODEC_V4L2M2M){
|
||||
if (movie->preferred_codec == USER_CODEC_V4L2M2M) {
|
||||
movie_encode_nal(movie);
|
||||
}
|
||||
|
||||
@@ -270,20 +286,20 @@ static int movie_encode_video(struct ctx_movie *movie)
|
||||
int got_packet_ptr;
|
||||
|
||||
retcd = avcodec_encode_video2(movie->ctx_codec, &movie->pkt, movie->picture, &got_packet_ptr);
|
||||
if (retcd < 0 ){
|
||||
if (retcd < 0 ) {
|
||||
av_strerror(retcd, errstr, sizeof(errstr));
|
||||
MOTION_LOG(ERR, TYPE_ENCODER, NO_ERRNO, _("Error encoding video:%s"),errstr);
|
||||
//Packet is freed upon failure of encoding
|
||||
return -1;
|
||||
}
|
||||
if (got_packet_ptr == 0){
|
||||
if (got_packet_ptr == 0) {
|
||||
//Buffered packet. Throw special return code
|
||||
mypacket_unref(movie->pkt);
|
||||
return -2;
|
||||
}
|
||||
|
||||
/* This kills compiler warnings. Nal setting is only for recent movie versions*/
|
||||
if (movie->preferred_codec == USER_CODEC_V4L2M2M){
|
||||
if (movie->preferred_codec == USER_CODEC_V4L2M2M) {
|
||||
movie_encode_nal(movie);
|
||||
}
|
||||
|
||||
@@ -299,12 +315,12 @@ static int movie_encode_video(struct ctx_movie *movie)
|
||||
video_outbuf =(uint8_t *) mymalloc(video_outbuf_size);
|
||||
|
||||
retcd = avcodec_encode_video(movie->strm_video->codec, video_outbuf, video_outbuf_size, movie->picture);
|
||||
if (retcd < 0 ){
|
||||
if (retcd < 0 ) {
|
||||
MOTION_LOG(ERR, TYPE_ENCODER, NO_ERRNO, _("Error encoding video"));
|
||||
mypacket_unref(movie->pkt);
|
||||
return -1;
|
||||
}
|
||||
if (retcd == 0 ){
|
||||
if (retcd == 0 ) {
|
||||
// No bytes encoded => buffered=>special handling
|
||||
mypacket_unref(movie->pkt);
|
||||
return -2;
|
||||
@@ -314,8 +330,9 @@ static int movie_encode_video(struct ctx_movie *movie)
|
||||
movie->pkt.size = retcd;
|
||||
movie->pkt.data = video_outbuf;
|
||||
|
||||
if (movie->picture->key_frame == 1)
|
||||
movie->pkt.flags |= AV_PKT_FLAG_KEY;
|
||||
if (movie->picture->key_frame == 1) {
|
||||
movie->pkt.flags |= AV_PKT_FLAG_KEY;
|
||||
}
|
||||
|
||||
movie->pkt.pts = movie->picture->pts;
|
||||
movie->pkt.dts = movie->pkt.pts;
|
||||
@@ -323,7 +340,7 @@ static int movie_encode_video(struct ctx_movie *movie)
|
||||
free(video_outbuf);
|
||||
|
||||
/* This kills compiler warnings. Nal setting is only for recent movie versions*/
|
||||
if (movie->preferred_codec == USER_CODEC_V4L2M2M){
|
||||
if (movie->preferred_codec == USER_CODEC_V4L2M2M) {
|
||||
movie_encode_nal(movie);
|
||||
}
|
||||
|
||||
@@ -343,7 +360,7 @@ static int movie_set_pts(struct ctx_movie *movie, const struct timespec *ts1)
|
||||
movie->picture->pts = movie->last_pts;
|
||||
} else {
|
||||
pts_interval = ((1000000L * (ts1->tv_sec - movie->start_time.tv_sec)) + (ts1->tv_nsec/1000) - (movie->start_time.tv_nsec/1000));
|
||||
if (pts_interval < 0){
|
||||
if (pts_interval < 0) {
|
||||
/* This can occur when we have pre-capture frames. Reset start time of video. */
|
||||
movie_reset_start_time(movie, ts1);
|
||||
pts_interval = 0;
|
||||
@@ -354,16 +371,16 @@ static int movie_set_pts(struct ctx_movie *movie, const struct timespec *ts1)
|
||||
} else
|
||||
movie->picture->pts = av_rescale_q(pts_interval,(AVRational){1, 1000000L},movie->strm_video->time_base) + movie->base_pts;
|
||||
|
||||
if (movie->test_mode == TRUE){
|
||||
if (movie->test_mode == TRUE) {
|
||||
MOTION_LOG(INF, TYPE_ENCODER, NO_ERRNO
|
||||
,_("PTS %" PRId64 " Base PTS %" PRId64 " ms interval %" PRId64 " timebase %d-%d")
|
||||
,movie->picture->pts,movie->base_pts,pts_interval
|
||||
,movie->strm_video->time_base.num,movie->strm_video->time_base.den);
|
||||
}
|
||||
|
||||
if (movie->picture->pts <= movie->last_pts){
|
||||
if (movie->picture->pts <= movie->last_pts) {
|
||||
//We have a problem with our motion loop timing and sending frames or the rounding into the PTS.
|
||||
if (movie->test_mode == TRUE){
|
||||
if (movie->test_mode == TRUE) {
|
||||
MOTION_LOG(INF, TYPE_ENCODER, NO_ERRNO, _("BAD TIMING!! Frame skipped."));
|
||||
}
|
||||
return -1;
|
||||
@@ -377,11 +394,14 @@ static int movie_set_quality(struct ctx_movie *movie)
|
||||
{
|
||||
|
||||
movie->opts = 0;
|
||||
if (movie->quality > 100) movie->quality = 100;
|
||||
if (movie->quality > 100) {
|
||||
movie->quality = 100;
|
||||
}
|
||||
if (movie->ctx_codec->codec_id == MY_CODEC_ID_H264 ||
|
||||
movie->ctx_codec->codec_id == MY_CODEC_ID_HEVC){
|
||||
if (movie->quality <= 0)
|
||||
movie->ctx_codec->codec_id == MY_CODEC_ID_HEVC) {
|
||||
if (movie->quality <= 0) {
|
||||
movie->quality = 45; // default to 45% quality
|
||||
}
|
||||
|
||||
/* This next if statement needs validation. Are mpeg4omx
|
||||
* and v4l2m2m even MY_CODEC_ID_H264 or MY_CODEC_ID_HEVC
|
||||
@@ -394,8 +414,10 @@ static int movie_set_quality(struct ctx_movie *movie)
|
||||
// bit_rate = movie->width * movie->height * movie->fps * quality_factor
|
||||
movie->quality = (int)(((int64_t)movie->width * movie->height * movie->fps * movie->quality) >> 7);
|
||||
// Clip bit rate to min
|
||||
if (movie->quality < 4000) // magic number
|
||||
if (movie->quality < 4000) {
|
||||
// magic number
|
||||
movie->quality = 4000;
|
||||
}
|
||||
movie->ctx_codec->profile = FF_PROFILE_H264_HIGH;
|
||||
movie->ctx_codec->bit_rate = movie->quality;
|
||||
av_dict_set(&movie->opts, "preset", "ultrafast", 0);
|
||||
@@ -418,7 +440,7 @@ static int movie_set_quality(struct ctx_movie *movie)
|
||||
}
|
||||
} else {
|
||||
/* The selection of 8000 is a subjective number based upon viewing output files */
|
||||
if (movie->quality > 0){
|
||||
if (movie->quality > 0) {
|
||||
movie->quality =(int)(((100-movie->quality)*(100-movie->quality)*(100-movie->quality) * 8000) / 1000000) + 1;
|
||||
movie->ctx_codec->flags |= MY_CODEC_FLAG_QSCALE;
|
||||
movie->ctx_codec->global_quality=movie->quality;
|
||||
@@ -460,8 +482,9 @@ static const char *movie_codec_is_blacklisted(const char *codec_name)
|
||||
|
||||
i_mx = (size_t)(sizeof(blacklisted_codec)/sizeof(blacklisted_codec[0]));
|
||||
for (i = 0; i < i_mx; i++) {
|
||||
if (mystreq(codec_name, blacklisted_codec[i].codec_name))
|
||||
if (mystreq(codec_name, blacklisted_codec[i].codec_name)) {
|
||||
return blacklisted_codec[i].reason;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
@@ -488,8 +511,9 @@ static int movie_set_codec_preferred(struct ctx_movie *movie)
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!movie->codec)
|
||||
if (!movie->codec) {
|
||||
movie->codec = avcodec_find_encoder(movie->oc->oformat->video_codec);
|
||||
}
|
||||
if (!movie->codec) {
|
||||
MOTION_LOG(ERR, TYPE_ENCODER, NO_ERRNO
|
||||
,_("Codec %s not found"), movie->codec_name);
|
||||
@@ -497,18 +521,19 @@ static int movie_set_codec_preferred(struct ctx_movie *movie)
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (mystreq(movie->codec->name, "h264_v4l2m2m")){
|
||||
if (mystreq(movie->codec->name, "h264_v4l2m2m")) {
|
||||
movie->preferred_codec = USER_CODEC_V4L2M2M;
|
||||
} else if (mystreq(movie->codec->name, "h264_omx")){
|
||||
} else if (mystreq(movie->codec->name, "h264_omx")) {
|
||||
movie->preferred_codec = USER_CODEC_H264OMX;
|
||||
} else if (mystreq(movie->codec->name, "mpeg4_omx")){
|
||||
} else if (mystreq(movie->codec->name, "mpeg4_omx")) {
|
||||
movie->preferred_codec = USER_CODEC_MPEG4OMX;
|
||||
} else {
|
||||
movie->preferred_codec = USER_CODEC_DEFAULT;
|
||||
}
|
||||
|
||||
if (movie->codec_name[codec_name_len])
|
||||
if (movie->codec_name[codec_name_len]) {
|
||||
MOTION_LOG(NTC, TYPE_ENCODER, NO_ERRNO,_("Using codec %s"), movie->codec->name);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
@@ -522,7 +547,9 @@ static int movie_set_codec(struct ctx_movie *movie)
|
||||
int chkrate;
|
||||
|
||||
retcd = movie_set_codec_preferred(movie);
|
||||
if (retcd != 0) return retcd;
|
||||
if (retcd != 0) {
|
||||
return retcd;
|
||||
}
|
||||
|
||||
#if (MYFFVER >= 57041)
|
||||
//If we provide the codec to this, it results in a memory leak. ffmpeg ticket: 5714
|
||||
@@ -552,9 +579,9 @@ static int movie_set_codec(struct ctx_movie *movie)
|
||||
if (movie->tlapse != TIMELAPSE_NONE) {
|
||||
movie->ctx_codec->gop_size = 1;
|
||||
} else {
|
||||
if (movie->fps <= 5){
|
||||
if (movie->fps <= 5) {
|
||||
movie->ctx_codec->gop_size = 1;
|
||||
} else if (movie->fps > 30){
|
||||
} else if (movie->fps > 30) {
|
||||
movie->ctx_codec->gop_size = 15;
|
||||
} else {
|
||||
movie->ctx_codec->gop_size = (movie->fps / 2);
|
||||
@@ -566,7 +593,7 @@ static int movie_set_codec(struct ctx_movie *movie)
|
||||
** a very poor quality playback. We can set the FPS to a higher number and
|
||||
** then let the PTS display the frames correctly.
|
||||
*/
|
||||
if ((movie->tlapse == TIMELAPSE_NONE) && (movie->fps <= 5)){
|
||||
if ((movie->tlapse == TIMELAPSE_NONE) && (movie->fps <= 5)) {
|
||||
if (mystreq(movie->codec_name, "flv") ||
|
||||
mystreq(movie->codec_name, "mp4") ||
|
||||
mystreq(movie->codec_name, "hevc")) {
|
||||
@@ -582,13 +609,13 @@ static int movie_set_codec(struct ctx_movie *movie)
|
||||
movie->ctx_codec->height = movie->height;
|
||||
movie->ctx_codec->time_base.num = 1;
|
||||
movie->ctx_codec->time_base.den = movie->fps;
|
||||
if (movie->preferred_codec == USER_CODEC_V4L2M2M){
|
||||
if (movie->preferred_codec == USER_CODEC_V4L2M2M) {
|
||||
movie->ctx_codec->pix_fmt = AV_PIX_FMT_NV21;
|
||||
} else {
|
||||
movie->ctx_codec->pix_fmt = MY_PIX_FMT_YUV420P;
|
||||
}
|
||||
movie->ctx_codec->max_b_frames = 0;
|
||||
if (mystreq(movie->codec_name, "ffv1")){
|
||||
if (mystreq(movie->codec_name, "ffv1")) {
|
||||
movie->ctx_codec->strict_std_compliance = -2;
|
||||
movie->ctx_codec->level = 3;
|
||||
}
|
||||
@@ -604,7 +631,7 @@ static int movie_set_codec(struct ctx_movie *movie)
|
||||
}
|
||||
|
||||
retcd = movie_set_quality(movie);
|
||||
if (retcd < 0){
|
||||
if (retcd < 0) {
|
||||
MOTION_LOG(ERR, TYPE_ENCODER, NO_ERRNO, _("Unable to set quality"));
|
||||
return -1;
|
||||
}
|
||||
@@ -625,7 +652,7 @@ static int movie_set_codec(struct ctx_movie *movie)
|
||||
retcd = avcodec_open2(movie->ctx_codec, movie->codec, &movie->opts);
|
||||
chkrate++;
|
||||
}
|
||||
if (retcd < 0){
|
||||
if (retcd < 0) {
|
||||
av_strerror(retcd, errstr, sizeof(errstr));
|
||||
MOTION_LOG(ERR, TYPE_ENCODER, NO_ERRNO, _("Could not open codec %s"),errstr);
|
||||
av_dict_free(&movie->opts);
|
||||
@@ -669,23 +696,28 @@ static int movie_alloc_video_buffer(AVFrame *frame, int align)
|
||||
int ret, i, padded_height;
|
||||
int plane_padding = FFMAX(16 + 16/*STRIDE_ALIGN*/, align);
|
||||
|
||||
if (!desc)
|
||||
if (!desc) {
|
||||
return AVERROR(EINVAL);
|
||||
}
|
||||
|
||||
if ((ret = av_image_check_size(frame->width, frame->height, 0, NULL)) < 0)
|
||||
if ((ret = av_image_check_size(frame->width, frame->height, 0, NULL)) < 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (!frame->linesize[0]) {
|
||||
if (align <= 0)
|
||||
if (align <= 0) {
|
||||
align = 32; /* STRIDE_ALIGN. Should be av_cpu_max_align() */
|
||||
}
|
||||
|
||||
for(i=1; i<=align; i+=i) {
|
||||
ret = av_image_fill_linesizes(frame->linesize,(enum AVPixelFormat) frame->format,
|
||||
FFALIGN(frame->width, i));
|
||||
if (ret < 0)
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
if (!(frame->linesize[0] & (align-1)))
|
||||
}
|
||||
if (!(frame->linesize[0] & (align-1))) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < 4 && frame->linesize[i]; i++)
|
||||
@@ -693,9 +725,14 @@ static int movie_alloc_video_buffer(AVFrame *frame, int align)
|
||||
}
|
||||
|
||||
padded_height = FFALIGN(frame->height, 32);
|
||||
if ((ret = av_image_fill_pointers(frame->data,(enum AVPixelFormat) frame->format, padded_height,
|
||||
NULL, frame->linesize)) < 0)
|
||||
ret = av_image_fill_pointers(frame->data
|
||||
,(enum AVPixelFormat) frame->format
|
||||
, padded_height
|
||||
, NULL
|
||||
, frame->linesize);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
frame->buf[0] = av_buffer_alloc(ret + 4*plane_padding);
|
||||
if (!frame->buf[0]) {
|
||||
@@ -734,8 +771,9 @@ static int movie_set_picture(struct ctx_movie *movie)
|
||||
}
|
||||
|
||||
/* Take care of variable bitrate setting. */
|
||||
if (movie->quality)
|
||||
if (movie->quality) {
|
||||
movie->picture->quality = movie->quality;
|
||||
}
|
||||
|
||||
movie->picture->linesize[0] = movie->ctx_codec->width;
|
||||
movie->picture->linesize[1] = movie->ctx_codec->width / 2;
|
||||
@@ -767,7 +805,7 @@ static int movie_set_outputfile(struct ctx_movie *movie)
|
||||
|
||||
#if (MYFFVER < 58000)
|
||||
retcd = snprintf(movie->oc->filename, sizeof(movie->oc->filename), "%s", movie->filename);
|
||||
if ((retcd < 0) || (retcd >= PATH_MAX)){
|
||||
if ((retcd < 0) || (retcd >= PATH_MAX)) {
|
||||
MOTION_LOG(ERR, TYPE_ENCODER, NO_ERRNO
|
||||
,_("Error setting file name"));
|
||||
return -1;
|
||||
@@ -809,7 +847,7 @@ static int movie_set_outputfile(struct ctx_movie *movie)
|
||||
* items here
|
||||
*/
|
||||
retcd = avformat_write_header(movie->oc, NULL);
|
||||
if (retcd < 0){
|
||||
if (retcd < 0) {
|
||||
av_strerror(retcd, errstr, sizeof(errstr));
|
||||
MOTION_LOG(ERR, TYPE_ENCODER, NO_ERRNO
|
||||
,_("Could not write movie header %s"),errstr);
|
||||
@@ -837,7 +875,7 @@ static int movie_flush_codec(struct ctx_movie *movie)
|
||||
int recv_cd = 0;
|
||||
char errstr[128];
|
||||
|
||||
if (movie->passthrough){
|
||||
if (movie->passthrough) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -845,7 +883,7 @@ static int movie_flush_codec(struct ctx_movie *movie)
|
||||
recv_cd = 0;
|
||||
if (movie->tlapse == TIMELAPSE_NONE) {
|
||||
retcd = avcodec_send_frame(movie->ctx_codec, NULL);
|
||||
if (retcd < 0 ){
|
||||
if (retcd < 0 ) {
|
||||
av_strerror(retcd, errstr, sizeof(errstr));
|
||||
MOTION_LOG(ERR, TYPE_ENCODER, NO_ERRNO
|
||||
,_("Error entering draining mode:%s"),errstr);
|
||||
@@ -856,8 +894,8 @@ static int movie_flush_codec(struct ctx_movie *movie)
|
||||
movie->pkt.data = NULL;
|
||||
movie->pkt.size = 0;
|
||||
recv_cd = avcodec_receive_packet(movie->ctx_codec, &movie->pkt);
|
||||
if (recv_cd != AVERROR_EOF){
|
||||
if (recv_cd < 0){
|
||||
if (recv_cd != AVERROR_EOF) {
|
||||
if (recv_cd < 0) {
|
||||
av_strerror(recv_cd, errstr, sizeof(errstr));
|
||||
MOTION_LOG(ERR, TYPE_ENCODER, NO_ERRNO
|
||||
,_("Error draining codec:%s"),errstr);
|
||||
@@ -908,8 +946,8 @@ static int movie_put_frame(struct ctx_movie *movie, const struct timespec *ts1)
|
||||
}
|
||||
|
||||
retcd = movie_encode_video(movie);
|
||||
if (retcd != 0){
|
||||
if (retcd != -2){
|
||||
if (retcd != 0) {
|
||||
if (retcd != -2) {
|
||||
MOTION_LOG(ERR, TYPE_ENCODER, NO_ERRNO, _("Error while encoding picture"));
|
||||
}
|
||||
mypacket_unref(movie->pkt);
|
||||
@@ -1016,14 +1054,16 @@ static int movie_passthru_put(struct ctx_movie *movie, struct ctx_image_data *im
|
||||
int idnbr_image, idnbr_lastwritten, idnbr_stop, idnbr_firstkey;
|
||||
int indx, indx_lastwritten, indx_firstkey;
|
||||
|
||||
if (movie->netcam_data == NULL) return -1;
|
||||
if (movie->netcam_data == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ((movie->netcam_data->status == NETCAM_NOTCONNECTED ) ||
|
||||
(movie->netcam_data->status == NETCAM_RECONNECTING ) ){
|
||||
(movie->netcam_data->status == NETCAM_RECONNECTING ) ) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (movie->high_resolution){
|
||||
if (movie->high_resolution) {
|
||||
idnbr_image = img_data->idnbr_high;
|
||||
} else {
|
||||
idnbr_image = img_data->idnbr_norm;
|
||||
@@ -1038,27 +1078,27 @@ static int movie_passthru_put(struct ctx_movie *movie, struct ctx_image_data *im
|
||||
|
||||
for(indx = 0; indx < movie->netcam_data->pktarray_size; indx++) {
|
||||
if ((movie->netcam_data->pktarray[indx].iswritten) &&
|
||||
(movie->netcam_data->pktarray[indx].idnbr > idnbr_lastwritten)){
|
||||
(movie->netcam_data->pktarray[indx].idnbr > idnbr_lastwritten)) {
|
||||
idnbr_lastwritten=movie->netcam_data->pktarray[indx].idnbr;
|
||||
indx_lastwritten = indx;
|
||||
}
|
||||
if ((movie->netcam_data->pktarray[indx].idnbr > idnbr_stop) &&
|
||||
(movie->netcam_data->pktarray[indx].idnbr <= idnbr_image)){
|
||||
(movie->netcam_data->pktarray[indx].idnbr <= idnbr_image)) {
|
||||
idnbr_stop=movie->netcam_data->pktarray[indx].idnbr;
|
||||
}
|
||||
if ((movie->netcam_data->pktarray[indx].iskey) &&
|
||||
(movie->netcam_data->pktarray[indx].idnbr <= idnbr_firstkey)){
|
||||
(movie->netcam_data->pktarray[indx].idnbr <= idnbr_firstkey)) {
|
||||
idnbr_firstkey=movie->netcam_data->pktarray[indx].idnbr;
|
||||
indx_firstkey = indx;
|
||||
}
|
||||
}
|
||||
|
||||
if (idnbr_stop == 0){
|
||||
if (idnbr_stop == 0) {
|
||||
pthread_mutex_unlock(&movie->netcam_data->mutex_pktarray);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (indx_lastwritten != -1){
|
||||
if (indx_lastwritten != -1) {
|
||||
indx = indx_lastwritten;
|
||||
} else if (indx_firstkey != -1) {
|
||||
indx = indx_firstkey;
|
||||
@@ -1073,9 +1113,13 @@ static int movie_passthru_put(struct ctx_movie *movie, struct ctx_image_data *im
|
||||
(movie->netcam_data->pktarray[indx].idnbr <= idnbr_image)) {
|
||||
movie_passthru_write(movie, indx);
|
||||
}
|
||||
if (movie->netcam_data->pktarray[indx].idnbr == idnbr_stop) break;
|
||||
if (movie->netcam_data->pktarray[indx].idnbr == idnbr_stop) {
|
||||
break;
|
||||
}
|
||||
indx++;
|
||||
if (indx == movie->netcam_data->pktarray_size ) indx = 0;
|
||||
if (indx == movie->netcam_data->pktarray_size ) {
|
||||
indx = 0;
|
||||
}
|
||||
}
|
||||
pthread_mutex_unlock(&movie->netcam_data->mutex_pktarray);
|
||||
return 0;
|
||||
@@ -1171,13 +1215,13 @@ static int movie_passthru_streams(struct ctx_movie *movie)
|
||||
static int movie_passthru_check(struct ctx_movie *movie)
|
||||
{
|
||||
if ((movie->netcam_data->status == NETCAM_NOTCONNECTED ) ||
|
||||
(movie->netcam_data->status == NETCAM_RECONNECTING ) ){
|
||||
(movie->netcam_data->status == NETCAM_RECONNECTING )) {
|
||||
MOTION_LOG(NTC, TYPE_ENCODER, NO_ERRNO
|
||||
,_("rtsp camera not ready for pass-through."));
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (movie->netcam_data == NULL){
|
||||
if (movie->netcam_data == NULL) {
|
||||
MOTION_LOG(ERR, TYPE_ENCODER, NO_ERRNO, _("RTSP context not available."));
|
||||
return -1;
|
||||
}
|
||||
@@ -1224,7 +1268,7 @@ static int movie_passthru_open(struct ctx_movie *movie)
|
||||
}
|
||||
|
||||
retcd = movie_set_outputfile(movie);
|
||||
if (retcd < 0){
|
||||
if (retcd < 0) {
|
||||
MOTION_LOG(ERR, TYPE_ENCODER, NO_ERRNO, _("Could not set the output file"));
|
||||
return -1;
|
||||
}
|
||||
@@ -1258,14 +1302,13 @@ void movie_avcodec_log(void *ignoreme, int errno_flag, const char *fmt, va_list
|
||||
* are not necessarily our errors.
|
||||
*/
|
||||
|
||||
if (errno_flag <= AV_LOG_WARNING){
|
||||
if (errno_flag <= AV_LOG_WARNING) {
|
||||
retcd = vsnprintf(buf, sizeof(buf), fmt, vl);
|
||||
if (retcd >=1024){
|
||||
if (retcd >=1024) {
|
||||
MOTION_LOG(DBG, TYPE_ENCODER, NO_ERRNO, "av message truncated %d bytes",(retcd - 1024));
|
||||
}
|
||||
end = buf + strlen(buf);
|
||||
if (end > buf && end[-1] == '\n')
|
||||
{
|
||||
if (end > buf && end[-1] == '\n') {
|
||||
*--end = 0;
|
||||
}
|
||||
|
||||
@@ -1279,7 +1322,7 @@ static void movie_put_pix_nv21(struct ctx_movie *movie, struct ctx_image_data *i
|
||||
unsigned char *image,*imagecr, *imagecb;
|
||||
int cr_len, x, y;
|
||||
|
||||
if (movie->high_resolution){
|
||||
if (movie->high_resolution) {
|
||||
image = img_data->image_high;
|
||||
} else {
|
||||
image = img_data->image_norm;
|
||||
@@ -1305,7 +1348,7 @@ static void movie_put_pix_yuv420(struct ctx_movie *movie, struct ctx_image_data
|
||||
{
|
||||
unsigned char *image;
|
||||
|
||||
if (movie->high_resolution){
|
||||
if (movie->high_resolution) {
|
||||
image = img_data->image_high;
|
||||
} else {
|
||||
image = img_data->image_norm;
|
||||
@@ -1344,8 +1387,7 @@ void movie_global_deinit(void)
|
||||
|
||||
#if (MYFFVER < 58000)
|
||||
/* TODO Determine if this is even needed for old versions */
|
||||
if (av_lockmgr_register(NULL) < 0)
|
||||
{
|
||||
if (av_lockmgr_register(NULL) < 0) {
|
||||
MOTION_LOG(EMG, TYPE_ALL, SHOW_ERRNO
|
||||
,_("av_lockmgr_register reset failed on cleanup"));
|
||||
}
|
||||
@@ -1389,19 +1431,19 @@ int movie_open(struct ctx_movie *movie)
|
||||
}
|
||||
|
||||
retcd = movie_set_stream(movie);
|
||||
if (retcd < 0){
|
||||
if (retcd < 0) {
|
||||
MOTION_LOG(ERR, TYPE_ENCODER, NO_ERRNO, _("Could not set the stream"));
|
||||
return -1;
|
||||
}
|
||||
|
||||
retcd = movie_set_picture(movie);
|
||||
if (retcd < 0){
|
||||
if (retcd < 0) {
|
||||
MOTION_LOG(ERR, TYPE_ENCODER, NO_ERRNO, _("Could not set the stream"));
|
||||
return -1;
|
||||
}
|
||||
|
||||
retcd = movie_set_outputfile(movie);
|
||||
if (retcd < 0){
|
||||
if (retcd < 0) {
|
||||
MOTION_LOG(ERR, TYPE_ENCODER, NO_ERRNO, _("Could not set the stream"));
|
||||
return -1;
|
||||
}
|
||||
@@ -1415,10 +1457,10 @@ void movie_close(struct ctx_movie *movie)
|
||||
|
||||
if (movie != NULL) {
|
||||
|
||||
if (movie_flush_codec(movie) < 0){
|
||||
if (movie_flush_codec(movie) < 0) {
|
||||
MOTION_LOG(ERR, TYPE_ENCODER, NO_ERRNO, _("Error flushing codec"));
|
||||
}
|
||||
if (movie->oc->pb != NULL){
|
||||
if (movie->oc->pb != NULL) {
|
||||
if (movie->tlapse != TIMELAPSE_APPEND) {
|
||||
av_write_trailer(movie->oc);
|
||||
}
|
||||
@@ -1456,7 +1498,7 @@ int movie_put_image(struct ctx_movie *movie, struct ctx_image_data *img_data, co
|
||||
}
|
||||
|
||||
movie->gop_cnt ++;
|
||||
if (movie->gop_cnt == movie->ctx_codec->gop_size ){
|
||||
if (movie->gop_cnt == movie->ctx_codec->gop_size ) {
|
||||
movie->picture->pict_type = AV_PICTURE_TYPE_I;
|
||||
movie->picture->key_frame = 1;
|
||||
movie->gop_cnt = 0;
|
||||
@@ -1474,14 +1516,14 @@ int movie_put_image(struct ctx_movie *movie, struct ctx_image_data *img_data, co
|
||||
while ((retcd == -2) && (movie->tlapse != TIMELAPSE_NONE)) {
|
||||
retcd = movie_put_frame(movie, ts1);
|
||||
cnt++;
|
||||
if (cnt > 50){
|
||||
if (cnt > 50) {
|
||||
MOTION_LOG(ERR, TYPE_ENCODER, NO_ERRNO
|
||||
,_("Excessive attempts to clear buffered packet"));
|
||||
retcd = -1;
|
||||
}
|
||||
}
|
||||
//non timelapse buffered is ok
|
||||
if (retcd == -2){
|
||||
if (retcd == -2) {
|
||||
retcd = 0;
|
||||
MOTION_LOG(DBG, TYPE_ENCODER, NO_ERRNO, _("Buffered packet"));
|
||||
}
|
||||
@@ -1494,8 +1536,9 @@ int movie_put_image(struct ctx_movie *movie, struct ctx_image_data *img_data, co
|
||||
void movie_reset_start_time(struct ctx_movie *movie, const struct timespec *ts1)
|
||||
{
|
||||
int64_t one_frame_interval = av_rescale_q(1,(AVRational){1, movie->fps}, movie->strm_video->time_base);
|
||||
if (one_frame_interval <= 0)
|
||||
if (one_frame_interval <= 0) {
|
||||
one_frame_interval = 1;
|
||||
}
|
||||
movie->base_pts = movie->last_pts + one_frame_interval;
|
||||
|
||||
movie->start_time.tv_sec = ts1->tv_sec;
|
||||
@@ -1520,16 +1563,27 @@ static const char* movie_init_codec(struct ctx_cam *cam)
|
||||
if (cam->conf->movie_codec == "test") {
|
||||
MOTION_LOG(NTC, TYPE_ENCODER, NO_ERRNO, "Running test of the various output formats.");
|
||||
codenbr = cam->event_nr % 10;
|
||||
if (codenbr == 1) return "flv";
|
||||
else if (codenbr == 2) return "ogg";
|
||||
else if (codenbr == 3) return "vp8";
|
||||
else if (codenbr == 4) return "mp4";
|
||||
else if (codenbr == 5) return "mkv";
|
||||
else if (codenbr == 6) return "hevc";
|
||||
else if (codenbr == 7) return "flv";
|
||||
else if (codenbr == 8) return "ogg";
|
||||
else if (codenbr == 9) return "vp8";
|
||||
else return "mkv";
|
||||
if (codenbr == 1) {
|
||||
return "flv";
|
||||
} else if (codenbr == 2) {
|
||||
return "ogg";
|
||||
} else if (codenbr == 3) {
|
||||
return "vp8";
|
||||
} else if (codenbr == 4) {
|
||||
return "mp4";
|
||||
} else if (codenbr == 5) {
|
||||
return "mkv";
|
||||
} else if (codenbr == 6) {
|
||||
return "hevc";
|
||||
} else if (codenbr == 7) {
|
||||
return "flv";
|
||||
} else if (codenbr == 8) {
|
||||
return "ogg";
|
||||
} else if (codenbr == 9) {
|
||||
return "vp8";
|
||||
} else {
|
||||
return "mkv";
|
||||
}
|
||||
}
|
||||
|
||||
return cam->conf->movie_codec.c_str();
|
||||
@@ -1554,12 +1608,12 @@ int movie_init_norm(struct ctx_cam *cam, struct timespec *ts1)
|
||||
retcd = snprintf(cam->movie_norm->filename, PATH_MAX, "%s/%s"
|
||||
, cam->conf->target_dir.c_str(), stamp);
|
||||
}
|
||||
if ((retcd < 0) || (retcd >= PATH_MAX)){
|
||||
if ((retcd < 0) || (retcd >= PATH_MAX)) {
|
||||
MOTION_LOG(ERR, TYPE_ENCODER, NO_ERRNO
|
||||
,_("Error setting file name"));
|
||||
return -1;
|
||||
}
|
||||
if (cam->imgs.size_high > 0){
|
||||
if (cam->imgs.size_high > 0) {
|
||||
cam->movie_norm->width = cam->imgs.width_high;
|
||||
cam->movie_norm->height = cam->imgs.height_high;
|
||||
cam->movie_norm->high_resolution = TRUE;
|
||||
@@ -1611,7 +1665,7 @@ int movie_init_motion(struct ctx_cam *cam, struct timespec *ts1)
|
||||
retcd = snprintf(cam->movie_motion->filename, PATH_MAX, "%s/%sm"
|
||||
, cam->conf->target_dir.c_str(), stamp);
|
||||
}
|
||||
if ((retcd < 0) || (retcd >= PATH_MAX)){
|
||||
if ((retcd < 0) || (retcd >= PATH_MAX)) {
|
||||
MOTION_LOG(ERR, TYPE_ENCODER, NO_ERRNO
|
||||
,_("Error setting file name"));
|
||||
return -1;
|
||||
@@ -1663,7 +1717,7 @@ int movie_init_timelapse(struct ctx_cam *cam, struct timespec *ts1)
|
||||
, _("Error setting timelapse file name %s"), tmp);
|
||||
}
|
||||
|
||||
if ((cam->imgs.size_high > 0) && (!cam->movie_passthrough)){
|
||||
if ((cam->imgs.size_high > 0) && (!cam->movie_passthrough)) {
|
||||
cam->movie_timelapse->width = cam->imgs.width_high;
|
||||
cam->movie_timelapse->height = cam->imgs.height_high;
|
||||
cam->movie_timelapse->high_resolution = TRUE;
|
||||
|
||||
348
src/netcam.cpp
348
src/netcam.cpp
@@ -46,14 +46,16 @@ static void netcam_check_buffsize(netcam_buff_ptr buff, size_t numbytes)
|
||||
int real_alloc;
|
||||
int new_size;
|
||||
|
||||
if ((buff->size - buff->used) >= numbytes)
|
||||
if ((buff->size - buff->used) >= numbytes) {
|
||||
return;
|
||||
}
|
||||
|
||||
min_size_to_alloc = numbytes - (buff->size - buff->used);
|
||||
real_alloc = ((min_size_to_alloc / NETCAM_BUFFSIZE) * NETCAM_BUFFSIZE);
|
||||
|
||||
if ((min_size_to_alloc - real_alloc) > 0)
|
||||
if ((min_size_to_alloc - real_alloc) > 0) {
|
||||
real_alloc += NETCAM_BUFFSIZE;
|
||||
}
|
||||
|
||||
new_size = buff->size + real_alloc;
|
||||
|
||||
@@ -162,15 +164,15 @@ static void netcam_url_parse(struct url_t *parse_url, const char *text_url)
|
||||
regex_t pattbuf;
|
||||
regmatch_t matches[10];
|
||||
|
||||
if (!strncmp(text_url, "file", 4))
|
||||
if (!strncmp(text_url, "file", 4)) {
|
||||
re = "(file)://(((.*):(.*))@)?([/:])?(:([0-9]+))?($|(/[^*]*))";
|
||||
|
||||
if (!strncmp(text_url, "jpeg", 4))
|
||||
}
|
||||
if (!strncmp(text_url, "jpeg", 4)) {
|
||||
re = "(jpeg)://(((.*):(.*))@)?([/:])?(:([0-9]+))?($|(/[^*]*))";
|
||||
|
||||
if (!strncmp(text_url, "v4l2", 4))
|
||||
}
|
||||
if (!strncmp(text_url, "v4l2", 4)) {
|
||||
re = "(v4l2)://(((.*):(.*))@)?([/:])?(:([0-9]+))?($|(/[^*]*))";
|
||||
|
||||
}
|
||||
/* Note that log messages are commented out to avoid leaking info related
|
||||
* to user/host/pass etc. Keeing them in the code for easier debugging if
|
||||
* it is needed
|
||||
@@ -223,14 +225,15 @@ static void netcam_url_parse(struct url_t *parse_url, const char *text_url)
|
||||
}
|
||||
if (((!parse_url->port) && (parse_url->service)) ||
|
||||
((parse_url->port > 65535) && (parse_url->service))) {
|
||||
if (mystreq(parse_url->service, "http"))
|
||||
if (mystreq(parse_url->service, "http")) {
|
||||
parse_url->port = 80;
|
||||
else if (mystreq(parse_url->service, "ftp"))
|
||||
} else if (mystreq(parse_url->service, "ftp")) {
|
||||
parse_url->port = 21;
|
||||
else if (mystreq(parse_url->service, "rtmp"))
|
||||
} else if (mystreq(parse_url->service, "rtmp")) {
|
||||
parse_url->port = 1935;
|
||||
else if (mystreq(parse_url->service, "rtsp"))
|
||||
} else if (mystreq(parse_url->service, "rtsp")) {
|
||||
parse_url->port = 554;
|
||||
}
|
||||
MOTION_LOG(INF, TYPE_NETCAM, NO_ERRNO, _("Using port number %d"),parse_url->port);
|
||||
}
|
||||
|
||||
@@ -271,7 +274,9 @@ static int netcam_check_pixfmt(struct ctx_netcam *netcam)
|
||||
|
||||
retcd = -1;
|
||||
if (((enum AVPixelFormat)netcam->frame->format == MY_PIX_FMT_YUV420P) ||
|
||||
((enum AVPixelFormat)netcam->frame->format == MY_PIX_FMT_YUVJ420P)) retcd = 0;
|
||||
((enum AVPixelFormat)netcam->frame->format == MY_PIX_FMT_YUVJ420P)) {
|
||||
retcd = 0;
|
||||
}
|
||||
|
||||
return retcd;
|
||||
|
||||
@@ -282,7 +287,7 @@ static void netcam_pktarray_free(struct ctx_netcam *netcam)
|
||||
|
||||
int indx;
|
||||
pthread_mutex_lock(&netcam->mutex_pktarray);
|
||||
if (netcam->pktarray_size > 0){
|
||||
if (netcam->pktarray_size > 0) {
|
||||
for(indx = 0; indx < netcam->pktarray_size; indx++) {
|
||||
if (netcam->pktarray[indx].packet.data != NULL) {
|
||||
mypacket_unref(netcam->pktarray[indx].packet);
|
||||
@@ -315,11 +320,11 @@ static void netcam_null_context(struct ctx_netcam *netcam)
|
||||
static void netcam_close_context(struct ctx_netcam *netcam)
|
||||
{
|
||||
|
||||
if (netcam->swsctx != NULL) sws_freeContext(netcam->swsctx);
|
||||
if (netcam->swsframe_in != NULL) myframe_free(netcam->swsframe_in);
|
||||
if (netcam->swsframe_out != NULL) myframe_free(netcam->swsframe_out);
|
||||
if (netcam->frame != NULL) myframe_free(netcam->frame);
|
||||
if (netcam->pktarray != NULL) netcam_pktarray_free(netcam);
|
||||
if (netcam->swsctx != NULL) sws_freeContext(netcam->swsctx);
|
||||
if (netcam->swsframe_in != NULL) myframe_free(netcam->swsframe_in);
|
||||
if (netcam->swsframe_out != NULL) myframe_free(netcam->swsframe_out);
|
||||
if (netcam->frame != NULL) myframe_free(netcam->frame);
|
||||
if (netcam->pktarray != NULL) netcam_pktarray_free(netcam);
|
||||
if (netcam->codec_context != NULL) myavcodec_close(netcam->codec_context);
|
||||
if (netcam->format_context != NULL) avformat_close_input(&netcam->format_context);
|
||||
if (netcam->transfer_format != NULL) avformat_close_input(&netcam->transfer_format);
|
||||
@@ -353,7 +358,7 @@ static void netcam_pktarray_resize(struct ctx_cam *cam, int is_highres)
|
||||
struct packet_item *tmp;
|
||||
int newsize;
|
||||
|
||||
if (is_highres){
|
||||
if (is_highres) {
|
||||
idnbr_last = cam->imgs.image_ring[cam->imgs.ring_out].idnbr_high;
|
||||
idnbr_first = cam->imgs.image_ring[cam->imgs.ring_in].idnbr_high;
|
||||
netcam = cam->netcam_high;
|
||||
@@ -363,17 +368,21 @@ static void netcam_pktarray_resize(struct ctx_cam *cam, int is_highres)
|
||||
netcam = cam->netcam;
|
||||
}
|
||||
|
||||
if (!netcam->passthrough) return;
|
||||
if (!netcam->passthrough) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* The 30 is arbitrary */
|
||||
/* Double the size plus double last diff so we don't catch our tail */
|
||||
newsize =((idnbr_first - idnbr_last) * 1 ) + ((netcam->idnbr - idnbr_last ) * 2);
|
||||
if (newsize < 30) newsize = 30;
|
||||
if (newsize < 30) {
|
||||
newsize = 30;
|
||||
}
|
||||
|
||||
pthread_mutex_lock(&netcam->mutex_pktarray);
|
||||
if ((netcam->pktarray_size < newsize) || (netcam->pktarray_size < 30)){
|
||||
if ((netcam->pktarray_size < newsize) || (netcam->pktarray_size < 30)) {
|
||||
tmp =(packet_item*) mymalloc(newsize * sizeof(struct packet_item));
|
||||
if (netcam->pktarray_size > 0 ){
|
||||
if (netcam->pktarray_size > 0 ) {
|
||||
memcpy(tmp, netcam->pktarray, sizeof(struct packet_item) * netcam->pktarray_size);
|
||||
}
|
||||
for(indx = netcam->pktarray_size; indx < newsize; indx++) {
|
||||
@@ -385,7 +394,9 @@ static void netcam_pktarray_resize(struct ctx_cam *cam, int is_highres)
|
||||
tmp[indx].iswritten = false;
|
||||
}
|
||||
|
||||
if (netcam->pktarray != NULL) free(netcam->pktarray);
|
||||
if (netcam->pktarray != NULL) {
|
||||
free(netcam->pktarray);
|
||||
}
|
||||
netcam->pktarray = tmp;
|
||||
netcam->pktarray_size = newsize;
|
||||
|
||||
@@ -405,13 +416,13 @@ static void netcam_pktarray_add(struct ctx_netcam *netcam)
|
||||
|
||||
pthread_mutex_lock(&netcam->mutex_pktarray);
|
||||
|
||||
if (netcam->pktarray_size == 0){
|
||||
if (netcam->pktarray_size == 0) {
|
||||
pthread_mutex_unlock(&netcam->mutex_pktarray);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Recall pktarray_size is one based but pktarray is zero based */
|
||||
if (netcam->pktarray_index == (netcam->pktarray_size-1) ){
|
||||
if (netcam->pktarray_index == (netcam->pktarray_size-1)) {
|
||||
indx_next = 0;
|
||||
} else {
|
||||
indx_next = netcam->pktarray_index + 1;
|
||||
@@ -456,8 +467,8 @@ static int netcam_decode_sw(struct ctx_netcam *netcam)
|
||||
char errstr[128];
|
||||
|
||||
retcd = avcodec_receive_frame(netcam->codec_context, netcam->frame);
|
||||
if ((netcam->interrupted) || (netcam->finish) || (retcd < 0) ){
|
||||
if (retcd == AVERROR(EAGAIN)){
|
||||
if ((netcam->interrupted) || (netcam->finish) || (retcd < 0)) {
|
||||
if (retcd == AVERROR(EAGAIN)) {
|
||||
retcd = 0;
|
||||
} else if (retcd == AVERROR_INVALIDDATA) {
|
||||
MOTION_LOG(INF, TYPE_NETCAM, NO_ERRNO
|
||||
@@ -493,8 +504,8 @@ static int netcam_decode_vaapi(struct ctx_netcam *netcam)
|
||||
hw_frame = myframe_alloc();
|
||||
|
||||
retcd = avcodec_receive_frame(netcam->codec_context, hw_frame);
|
||||
if ((netcam->interrupted) || (netcam->finish) || (retcd < 0) ){
|
||||
if (retcd == AVERROR(EAGAIN)){
|
||||
if ((netcam->interrupted) || (netcam->finish) || (retcd < 0)) {
|
||||
if (retcd == AVERROR(EAGAIN)) {
|
||||
retcd = 0;
|
||||
} else if (retcd == AVERROR_INVALIDDATA) {
|
||||
MOTION_LOG(INF, TYPE_NETCAM, NO_ERRNO
|
||||
@@ -549,10 +560,12 @@ static int netcam_decode_video(struct ctx_netcam *netcam)
|
||||
* We should consider adding a maximum count of these errors and reset every time
|
||||
* we get a good image.
|
||||
*/
|
||||
if (netcam->finish) return 0; /* This just speeds up the shutdown time */
|
||||
if (netcam->finish) {
|
||||
return 0; /* This just speeds up the shutdown time */
|
||||
}
|
||||
|
||||
retcd = avcodec_send_packet(netcam->codec_context, &netcam->packet_recv);
|
||||
if ((netcam->interrupted) || (netcam->finish)){
|
||||
if ((netcam->interrupted) || (netcam->finish)) {
|
||||
MOTION_LOG(INF, TYPE_NETCAM, NO_ERRNO
|
||||
,_("%s: Interrupted or finish on send")
|
||||
,netcam->cameratype);
|
||||
@@ -564,7 +577,7 @@ static int netcam_decode_video(struct ctx_netcam *netcam)
|
||||
,netcam->cameratype);
|
||||
return 0;
|
||||
}
|
||||
if (retcd < 0 && retcd != AVERROR_EOF){
|
||||
if (retcd < 0 && retcd != AVERROR_EOF) {
|
||||
av_strerror(retcd, errstr, sizeof(errstr));
|
||||
MOTION_LOG(INF, TYPE_NETCAM, NO_ERRNO
|
||||
,_("%s: Error sending packet to codec: %s")
|
||||
@@ -572,7 +585,7 @@ static int netcam_decode_video(struct ctx_netcam *netcam)
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (netcam->hw_type == AV_HWDEVICE_TYPE_VAAPI ){
|
||||
if (netcam->hw_type == AV_HWDEVICE_TYPE_VAAPI) {
|
||||
retcd = netcam_decode_vaapi(netcam);
|
||||
} else {
|
||||
retcd = netcam_decode_sw(netcam);
|
||||
@@ -589,11 +602,13 @@ static int netcam_decode_video(struct ctx_netcam *netcam)
|
||||
(void)netcam_decode_sw;
|
||||
(void)netcam_decode_vaapi;
|
||||
|
||||
if (netcam->finish) return 0; /* This just speeds up the shutdown time */
|
||||
|
||||
if (netcam->finish) {
|
||||
return 0; /* This just speeds up the shutdown time */
|
||||
}
|
||||
retcd = avcodec_decode_video2(netcam->codec_context, netcam->frame, &check, &netcam->packet_recv);
|
||||
if ((netcam->interrupted) || (netcam->finish)) return -1;
|
||||
|
||||
if ((netcam->interrupted) || (netcam->finish)) {
|
||||
return -1;
|
||||
}
|
||||
if (retcd == AVERROR_INVALIDDATA) {
|
||||
MOTION_LOG(INF, TYPE_NETCAM, NO_ERRNO, _("Ignoring packet with invalid data"));
|
||||
return 0;
|
||||
@@ -605,8 +620,9 @@ static int netcam_decode_video(struct ctx_netcam *netcam)
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (check == 0 || retcd == 0) return 0;
|
||||
|
||||
if (check == 0 || retcd == 0) {
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
#endif
|
||||
|
||||
@@ -618,7 +634,9 @@ static int netcam_decode_packet(struct ctx_netcam *netcam)
|
||||
int frame_size;
|
||||
int retcd;
|
||||
|
||||
if (netcam->finish) return -1; /* This just speeds up the shutdown time */
|
||||
if (netcam->finish) {
|
||||
return -1; /* This just speeds up the shutdown time */
|
||||
}
|
||||
|
||||
if (netcam->packet_recv.stream_index == netcam->audio_stream_index) {
|
||||
MOTION_LOG(ERR, TYPE_NETCAM, NO_ERRNO
|
||||
@@ -627,8 +645,9 @@ static int netcam_decode_packet(struct ctx_netcam *netcam)
|
||||
}
|
||||
|
||||
retcd = netcam_decode_video(netcam);
|
||||
if (retcd <= 0) return retcd;
|
||||
|
||||
if (retcd <= 0) {
|
||||
return retcd;
|
||||
}
|
||||
frame_size = myimage_get_buffer_size((enum AVPixelFormat) netcam->frame->format
|
||||
,netcam->frame->width
|
||||
,netcam->frame->height);
|
||||
@@ -658,8 +677,9 @@ static void netcam_hwdecoders(struct ctx_netcam *netcam)
|
||||
{
|
||||
#if ( MYFFVER >= 57083)
|
||||
/* High Res pass through does not decode images into frames*/
|
||||
if (netcam->high_resolution && netcam->passthrough) return;
|
||||
|
||||
if (netcam->high_resolution && netcam->passthrough) {
|
||||
return;
|
||||
}
|
||||
if ((netcam->hw_type == AV_HWDEVICE_TYPE_NONE) && (netcam->first_image)) {
|
||||
MOTION_LOG(INF, TYPE_NETCAM, NO_ERRNO
|
||||
,_("%s: HW Devices: ")
|
||||
@@ -693,7 +713,9 @@ static enum AVPixelFormat netcam_getfmt_vaapi(AVCodecContext *avctx, const enum
|
||||
(void)avctx;
|
||||
|
||||
for (p = pix_fmts; *p != -1; p++) {
|
||||
if (*p == AV_PIX_FMT_VAAPI) return *p;
|
||||
if (*p == AV_PIX_FMT_VAAPI) {
|
||||
return *p;
|
||||
}
|
||||
}
|
||||
|
||||
MOTION_LOG(ERR, TYPE_NETCAM, NO_ERRNO,_("Failed to get vaapi pix format"));
|
||||
@@ -710,11 +732,11 @@ static void netcam_decoder_error(struct ctx_netcam *netcam, int retcd, const cha
|
||||
char errstr[128];
|
||||
int indx;
|
||||
|
||||
if (netcam->interrupted){
|
||||
if (netcam->interrupted) {
|
||||
MOTION_LOG(ERR, TYPE_NETCAM, NO_ERRNO
|
||||
,_("%s: Interrupted"),netcam->cameratype);
|
||||
} else {
|
||||
if (retcd < 0){
|
||||
if (retcd < 0) {
|
||||
av_strerror(retcd, errstr, sizeof(errstr));
|
||||
MOTION_LOG(ERR, TYPE_NETCAM, NO_ERRNO
|
||||
,_("%s: %s: %s"),netcam->cameratype,fnc_nm, errstr);
|
||||
@@ -763,7 +785,7 @@ static int netcam_init_vaapi(struct ctx_netcam *netcam)
|
||||
,_("%s: Initializing vaapi decoder"),netcam->cameratype);
|
||||
|
||||
netcam->hw_type = av_hwdevice_find_type_by_name("vaapi");
|
||||
if (netcam->hw_type == AV_HWDEVICE_TYPE_NONE){
|
||||
if (netcam->hw_type == AV_HWDEVICE_TYPE_NONE) {
|
||||
MOTION_LOG(ERR, TYPE_NETCAM, NO_ERRNO,_("%s: Unable to find vaapi hw device")
|
||||
, netcam->cameratype);
|
||||
netcam_decoder_error(netcam, 0, "av_hwdevice");
|
||||
@@ -771,7 +793,7 @@ static int netcam_init_vaapi(struct ctx_netcam *netcam)
|
||||
}
|
||||
|
||||
netcam->codec_context = avcodec_alloc_context3(netcam->decoder);
|
||||
if ((netcam->codec_context == NULL) || (netcam->interrupted)){
|
||||
if ((netcam->codec_context == NULL) || (netcam->interrupted)) {
|
||||
netcam_decoder_error(netcam, 0, "avcodec_alloc_context3");
|
||||
return -1;
|
||||
}
|
||||
@@ -791,7 +813,7 @@ static int netcam_init_vaapi(struct ctx_netcam *netcam)
|
||||
AV_HWACCEL_FLAG_IGNORE_LEVEL;
|
||||
|
||||
retcd = av_hwdevice_ctx_create(&netcam->hw_device_ctx, netcam->hw_type, NULL, NULL, 0);
|
||||
if (retcd < 0){
|
||||
if (retcd < 0) {
|
||||
netcam_decoder_error(netcam, retcd, "hwctx");
|
||||
return -1;
|
||||
}
|
||||
@@ -825,13 +847,13 @@ static int netcam_init_swdecoder(struct ctx_netcam *netcam)
|
||||
if (netcam->decoder == NULL) {
|
||||
netcam->decoder = avcodec_find_decoder(netcam->strm->codecpar->codec_id);
|
||||
}
|
||||
if ((netcam->decoder == NULL) || (netcam->interrupted)){
|
||||
if ((netcam->decoder == NULL) || (netcam->interrupted)) {
|
||||
netcam_decoder_error(netcam, 0, "avcodec_find_decoder");
|
||||
return -1;
|
||||
}
|
||||
|
||||
netcam->codec_context = avcodec_alloc_context3(netcam->decoder);
|
||||
if ((netcam->codec_context == NULL) || (netcam->interrupted)){
|
||||
if ((netcam->codec_context == NULL) || (netcam->interrupted)) {
|
||||
netcam_decoder_error(netcam, 0, "avcodec_alloc_context3");
|
||||
return -1;
|
||||
}
|
||||
@@ -870,13 +892,15 @@ static int netcam_open_codec(struct ctx_netcam *netcam)
|
||||
|
||||
int retcd;
|
||||
|
||||
if (netcam->finish) return -1; /* This just speeds up the shutdown time */
|
||||
if (netcam->finish) {
|
||||
return -1; /* This just speeds up the shutdown time */
|
||||
}
|
||||
|
||||
netcam_hwdecoders(netcam);
|
||||
|
||||
retcd = av_find_best_stream(netcam->format_context
|
||||
, AVMEDIA_TYPE_AUDIO, -1, -1, NULL, 0);
|
||||
if ((retcd < 0) || (netcam->interrupted)){
|
||||
if ((retcd < 0) || (netcam->interrupted)) {
|
||||
netcam->audio_stream_index = -1;
|
||||
} else {
|
||||
netcam->audio_stream_index = retcd;
|
||||
@@ -885,15 +909,15 @@ static int netcam_open_codec(struct ctx_netcam *netcam)
|
||||
netcam->decoder = NULL;
|
||||
retcd = av_find_best_stream(netcam->format_context
|
||||
, AVMEDIA_TYPE_VIDEO, -1, -1, &netcam->decoder, 0);
|
||||
if ((retcd < 0) || (netcam->interrupted)){
|
||||
if ((retcd < 0) || (netcam->interrupted)) {
|
||||
netcam_decoder_error(netcam, retcd, "av_find_best_stream");
|
||||
return -1;
|
||||
}
|
||||
netcam->video_stream_index = retcd;
|
||||
netcam->strm = netcam->format_context->streams[netcam->video_stream_index];
|
||||
|
||||
if (mystrceq(netcam->decoder_nm,"vaapi")){
|
||||
if (netcam_init_vaapi(netcam) < 0){
|
||||
if (mystrceq(netcam->decoder_nm,"vaapi")) {
|
||||
if (netcam_init_vaapi(netcam) < 0) {
|
||||
netcam_decoder_error(netcam, retcd, "hwvaapi_init");
|
||||
return -1;
|
||||
}
|
||||
@@ -902,7 +926,7 @@ static int netcam_open_codec(struct ctx_netcam *netcam)
|
||||
}
|
||||
|
||||
retcd = avcodec_open2(netcam->codec_context, netcam->decoder, NULL);
|
||||
if ((retcd < 0) || (netcam->interrupted)){
|
||||
if ((retcd < 0) || (netcam->interrupted)) {
|
||||
netcam_decoder_error(netcam, retcd, "avcodec_open2");
|
||||
return -1;
|
||||
}
|
||||
@@ -955,7 +979,7 @@ static int netcam_interrupt(void *ctx)
|
||||
{
|
||||
struct ctx_netcam *netcam = (struct ctx_netcam *)ctx;
|
||||
|
||||
if (netcam->finish){
|
||||
if (netcam->finish) {
|
||||
netcam->interrupted = true;
|
||||
return true;
|
||||
}
|
||||
@@ -998,11 +1022,13 @@ static int netcam_interrupt(void *ctx)
|
||||
static int netcam_open_sws(struct ctx_netcam *netcam)
|
||||
{
|
||||
|
||||
if (netcam->finish) return -1; /* This just speeds up the shutdown time */
|
||||
if (netcam->finish) {
|
||||
return -1; /* This just speeds up the shutdown time */
|
||||
}
|
||||
|
||||
netcam->swsframe_in = myframe_alloc();
|
||||
if (netcam->swsframe_in == NULL) {
|
||||
if (netcam->status == NETCAM_NOTCONNECTED){
|
||||
if (netcam->status == NETCAM_NOTCONNECTED) {
|
||||
MOTION_LOG(ERR, TYPE_NETCAM, NO_ERRNO
|
||||
, _("%s: Unable to allocate swsframe_in.")
|
||||
, netcam->cameratype);
|
||||
@@ -1013,7 +1039,7 @@ static int netcam_open_sws(struct ctx_netcam *netcam)
|
||||
|
||||
netcam->swsframe_out = myframe_alloc();
|
||||
if (netcam->swsframe_out == NULL) {
|
||||
if (netcam->status == NETCAM_NOTCONNECTED){
|
||||
if (netcam->status == NETCAM_NOTCONNECTED) {
|
||||
MOTION_LOG(ERR, TYPE_NETCAM, NO_ERRNO
|
||||
, _("%s: Unable to allocate swsframe_out.")
|
||||
, netcam->cameratype);
|
||||
@@ -1026,7 +1052,7 @@ static int netcam_open_sws(struct ctx_netcam *netcam)
|
||||
* The scaling context is used to change dimensions to config file and
|
||||
* also if the format sent by the camera is not YUV420.
|
||||
*/
|
||||
if (netcam_check_pixfmt(netcam) != 0){
|
||||
if (netcam_check_pixfmt(netcam) != 0) {
|
||||
MOTION_LOG(INF, TYPE_NETCAM, NO_ERRNO
|
||||
, _("%s: Pixel format %d will be converted.")
|
||||
, netcam->cameratype, netcam->frame->format);
|
||||
@@ -1041,7 +1067,7 @@ static int netcam_open_sws(struct ctx_netcam *netcam)
|
||||
,MY_PIX_FMT_YUV420P
|
||||
,SWS_BICUBIC,NULL,NULL,NULL);
|
||||
if (netcam->swsctx == NULL) {
|
||||
if (netcam->status == NETCAM_NOTCONNECTED){
|
||||
if (netcam->status == NETCAM_NOTCONNECTED) {
|
||||
MOTION_LOG(ERR, TYPE_NETCAM, NO_ERRNO
|
||||
, _("%s: Unable to allocate scaling context.")
|
||||
, netcam->cameratype);
|
||||
@@ -1055,7 +1081,7 @@ static int netcam_open_sws(struct ctx_netcam *netcam)
|
||||
,netcam->imgsize.width
|
||||
,netcam->imgsize.height);
|
||||
if (netcam->swsframe_size <= 0) {
|
||||
if (netcam->status == NETCAM_NOTCONNECTED){
|
||||
if (netcam->status == NETCAM_NOTCONNECTED) {
|
||||
MOTION_LOG(ERR, TYPE_NETCAM, NO_ERRNO
|
||||
, _("%s: Error determining size of frame out")
|
||||
, netcam->cameratype);
|
||||
@@ -1079,10 +1105,14 @@ static int netcam_resize(struct ctx_netcam *netcam)
|
||||
char errstr[128];
|
||||
uint8_t *buffer_out;
|
||||
|
||||
if (netcam->finish) return -1; /* This just speeds up the shutdown time */
|
||||
if (netcam->finish) {
|
||||
return -1; /* This just speeds up the shutdown time */
|
||||
}
|
||||
|
||||
if (netcam->swsctx == NULL) {
|
||||
if (netcam_open_sws(netcam) < 0) return -1;
|
||||
if (netcam_open_sws(netcam) < 0) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
retcd=myimage_fill_arrays(
|
||||
@@ -1092,7 +1122,7 @@ static int netcam_resize(struct ctx_netcam *netcam)
|
||||
,netcam->frame->width
|
||||
,netcam->frame->height);
|
||||
if (retcd < 0) {
|
||||
if (netcam->status == NETCAM_NOTCONNECTED){
|
||||
if (netcam->status == NETCAM_NOTCONNECTED) {
|
||||
av_strerror(retcd, errstr, sizeof(errstr));
|
||||
MOTION_LOG(ERR, TYPE_NETCAM, NO_ERRNO
|
||||
,_("%s: Error allocating picture in: %s")
|
||||
@@ -1111,7 +1141,7 @@ static int netcam_resize(struct ctx_netcam *netcam)
|
||||
,netcam->imgsize.width
|
||||
,netcam->imgsize.height);
|
||||
if (retcd < 0) {
|
||||
if (netcam->status == NETCAM_NOTCONNECTED){
|
||||
if (netcam->status == NETCAM_NOTCONNECTED) {
|
||||
av_strerror(retcd, errstr, sizeof(errstr));
|
||||
MOTION_LOG(ERR, TYPE_NETCAM, NO_ERRNO
|
||||
,_("%s: Error allocating picture out: %s")
|
||||
@@ -1130,7 +1160,7 @@ static int netcam_resize(struct ctx_netcam *netcam)
|
||||
,netcam->swsframe_out->data
|
||||
,netcam->swsframe_out->linesize);
|
||||
if (retcd < 0) {
|
||||
if (netcam->status == NETCAM_NOTCONNECTED){
|
||||
if (netcam->status == NETCAM_NOTCONNECTED) {
|
||||
av_strerror(retcd, errstr, sizeof(errstr));
|
||||
MOTION_LOG(ERR, TYPE_NETCAM, NO_ERRNO
|
||||
,_("%s: Error resizing/reformatting: %s")
|
||||
@@ -1148,7 +1178,7 @@ static int netcam_resize(struct ctx_netcam *netcam)
|
||||
,netcam->imgsize.height
|
||||
,netcam->swsframe_size);
|
||||
if (retcd < 0) {
|
||||
if (netcam->status == NETCAM_NOTCONNECTED){
|
||||
if (netcam->status == NETCAM_NOTCONNECTED) {
|
||||
av_strerror(retcd, errstr, sizeof(errstr));
|
||||
MOTION_LOG(ERR, TYPE_NETCAM, NO_ERRNO
|
||||
,_("%s: Error putting frame into output buffer: %s")
|
||||
@@ -1172,7 +1202,9 @@ static int netcam_read_image(struct ctx_netcam *netcam)
|
||||
char errstr[128];
|
||||
netcam_buff *xchg;
|
||||
|
||||
if (netcam->finish) return -1; /* This just speeds up the shutdown time */
|
||||
if (netcam->finish) {
|
||||
return -1; /* This just speeds up the shutdown time */
|
||||
}
|
||||
|
||||
av_init_packet(&netcam->packet_recv);
|
||||
netcam->packet_recv.data = NULL;
|
||||
@@ -1190,7 +1222,9 @@ static int netcam_read_image(struct ctx_netcam *netcam)
|
||||
|
||||
while ((!haveimage) && (!netcam->interrupted)) {
|
||||
retcd = av_read_frame(netcam->format_context, &netcam->packet_recv);
|
||||
if (retcd < 0 ) errcnt++;
|
||||
if (retcd < 0 ) {
|
||||
errcnt++;
|
||||
}
|
||||
if ((netcam->interrupted) || (errcnt > 1)) {
|
||||
if (netcam->interrupted) {
|
||||
MOTION_LOG(INF, TYPE_NETCAM, NO_ERRNO
|
||||
@@ -1219,9 +1253,9 @@ static int netcam_read_image(struct ctx_netcam *netcam)
|
||||
size_decoded = netcam_decode_packet(netcam);
|
||||
}
|
||||
}
|
||||
if (size_decoded > 0 ){
|
||||
if (size_decoded > 0) {
|
||||
haveimage = true;
|
||||
} else if (size_decoded == 0){
|
||||
} else if (size_decoded == 0) {
|
||||
/* Did not fail, just didn't get anything. Try again */
|
||||
mypacket_unref(netcam->packet_recv);
|
||||
av_init_packet(&netcam->packet_recv);
|
||||
@@ -1247,7 +1281,7 @@ static int netcam_read_image(struct ctx_netcam *netcam)
|
||||
if ((netcam->imgsize.width != netcam->frame->width) ||
|
||||
(netcam->imgsize.height != netcam->frame->height) ||
|
||||
(netcam_check_pixfmt(netcam) != 0)) {
|
||||
if (netcam_resize(netcam) < 0){
|
||||
if (netcam_resize(netcam) < 0) {
|
||||
mypacket_unref(netcam->packet_recv);
|
||||
netcam_close_context(netcam);
|
||||
return -1;
|
||||
@@ -1257,7 +1291,9 @@ static int netcam_read_image(struct ctx_netcam *netcam)
|
||||
|
||||
pthread_mutex_lock(&netcam->mutex);
|
||||
netcam->idnbr++;
|
||||
if (netcam->passthrough) netcam_pktarray_add(netcam);
|
||||
if (netcam->passthrough) {
|
||||
netcam_pktarray_add(netcam);
|
||||
}
|
||||
if (!(netcam->high_resolution && netcam->passthrough) &&
|
||||
(netcam->packet_recv.stream_index == netcam->video_stream_index)) {
|
||||
xchg = netcam->img_latest;
|
||||
@@ -1268,7 +1304,7 @@ static int netcam_read_image(struct ctx_netcam *netcam)
|
||||
|
||||
mypacket_unref(netcam->packet_recv);
|
||||
|
||||
if (netcam->format_context->streams[netcam->video_stream_index]->avg_frame_rate.den > 0){
|
||||
if (netcam->format_context->streams[netcam->video_stream_index]->avg_frame_rate.den > 0) {
|
||||
netcam->src_fps = (
|
||||
(netcam->format_context->streams[netcam->video_stream_index]->avg_frame_rate.num /
|
||||
netcam->format_context->streams[netcam->video_stream_index]->avg_frame_rate.den) +
|
||||
@@ -1294,13 +1330,17 @@ static int netcam_read_image(struct ctx_netcam *netcam)
|
||||
static int netcam_ntc(struct ctx_netcam *netcam)
|
||||
{
|
||||
|
||||
if ((netcam->finish) || (!netcam->first_image)) return 0;
|
||||
if ((netcam->finish) || (!netcam->first_image)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* High Res pass through does not decode images into frames*/
|
||||
if (netcam->high_resolution && netcam->passthrough) return 0;
|
||||
if (netcam->high_resolution && netcam->passthrough) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ((netcam->imgsize.width != netcam->frame->width) ||
|
||||
(netcam->imgsize.height != netcam->frame->height) ){
|
||||
(netcam->imgsize.height != netcam->frame->height)) {
|
||||
MOTION_LOG(NTC, TYPE_NETCAM, NO_ERRNO, "");
|
||||
MOTION_LOG(NTC, TYPE_NETCAM, NO_ERRNO, "******************************************************");
|
||||
MOTION_LOG(NTC, TYPE_NETCAM, NO_ERRNO, _("The network camera is sending pictures at %dx%d")
|
||||
@@ -1401,7 +1441,7 @@ static void netcam_set_path (struct ctx_cam *cam, struct ctx_netcam *netcam )
|
||||
memset(&url, 0, sizeof(url));
|
||||
memset(userpass,0,PATH_MAX);
|
||||
|
||||
if (netcam->high_resolution){
|
||||
if (netcam->high_resolution) {
|
||||
netcam_url_parse(&url, cam->conf->netcam_high_url.c_str());
|
||||
} else {
|
||||
netcam_url_parse(&url, cam->conf->netcam_url.c_str());
|
||||
@@ -1411,7 +1451,7 @@ static void netcam_set_path (struct ctx_cam *cam, struct ctx_netcam *netcam )
|
||||
cam->conf->netcam_userpass.copy(userpass, PATH_MAX);
|
||||
} else if (url.userpass != NULL) {
|
||||
retcd = snprintf(userpass,PATH_MAX,"%s",url.userpass);
|
||||
if ((retcd <0) || (retcd>=PATH_MAX)){
|
||||
if ((retcd <0) || (retcd>=PATH_MAX)) {
|
||||
MOTION_LOG(INF, TYPE_NETCAM, NO_ERRNO,_("Error getting userpass"));
|
||||
}
|
||||
}
|
||||
@@ -1591,7 +1631,7 @@ static int netcam_copy_stream(struct ctx_netcam *netcam)
|
||||
transfer_stream = avformat_new_stream(netcam->transfer_format, NULL);
|
||||
stream_in = netcam->format_context->streams[indx];
|
||||
retcd = avcodec_parameters_copy(transfer_stream->codecpar, stream_in->codecpar);
|
||||
if (retcd < 0){
|
||||
if (retcd < 0) {
|
||||
MOTION_LOG(ERR, TYPE_NETCAM, NO_ERRNO
|
||||
,_("%s: Unable to copy codec parameters")
|
||||
, netcam->cameratype);
|
||||
@@ -1607,7 +1647,9 @@ static int netcam_copy_stream(struct ctx_netcam *netcam)
|
||||
return 0;
|
||||
#else
|
||||
/* This is disabled in the mycheck_passthrough but we need it here for compiling */
|
||||
if (netcam != NULL) MOTION_LOG(INF, TYPE_ENCODER, NO_ERRNO, _("ffmpeg too old"));
|
||||
if (netcam != NULL) {
|
||||
MOTION_LOG(INF, TYPE_ENCODER, NO_ERRNO, _("ffmpeg too old"));
|
||||
}
|
||||
return -1;
|
||||
#endif
|
||||
|
||||
@@ -1619,10 +1661,12 @@ static int netcam_open_context(struct ctx_netcam *netcam)
|
||||
int retcd;
|
||||
char errstr[128];
|
||||
|
||||
if (netcam->finish) return -1;
|
||||
if (netcam->finish) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (netcam->path == NULL) {
|
||||
if (netcam->status == NETCAM_NOTCONNECTED){
|
||||
if (netcam->status == NETCAM_NOTCONNECTED) {
|
||||
MOTION_LOG(ERR, TYPE_NETCAM, NO_ERRNO, _("Null path passed to connect"));
|
||||
}
|
||||
return -1;
|
||||
@@ -1641,15 +1685,17 @@ static int netcam_open_context(struct ctx_netcam *netcam)
|
||||
netcam_set_options(netcam);
|
||||
|
||||
retcd = avformat_open_input(&netcam->format_context, netcam->path, NULL, &netcam->opts);
|
||||
if ((retcd < 0) || (netcam->interrupted) || (netcam->finish) ){
|
||||
if (netcam->status == NETCAM_NOTCONNECTED){
|
||||
if ((retcd < 0) || (netcam->interrupted) || (netcam->finish) ) {
|
||||
if (netcam->status == NETCAM_NOTCONNECTED) {
|
||||
av_strerror(retcd, errstr, sizeof(errstr));
|
||||
MOTION_LOG(ERR, TYPE_NETCAM, NO_ERRNO
|
||||
,_("%s: Unable to open camera(%s): %s")
|
||||
, netcam->cameratype, netcam->camera_name, errstr);
|
||||
}
|
||||
av_dict_free(&netcam->opts);
|
||||
if (netcam->interrupted) netcam_close_context(netcam);
|
||||
if (netcam->interrupted) {
|
||||
netcam_close_context(netcam);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
av_dict_free(&netcam->opts);
|
||||
@@ -1659,8 +1705,8 @@ static int netcam_open_context(struct ctx_netcam *netcam)
|
||||
|
||||
/* fill out stream information */
|
||||
retcd = avformat_find_stream_info(netcam->format_context, NULL);
|
||||
if ((retcd < 0) || (netcam->interrupted) || (netcam->finish) ){
|
||||
if (netcam->status == NETCAM_NOTCONNECTED){
|
||||
if ((retcd < 0) || (netcam->interrupted) || (netcam->finish) ) {
|
||||
if (netcam->status == NETCAM_NOTCONNECTED) {
|
||||
av_strerror(retcd, errstr, sizeof(errstr));
|
||||
MOTION_LOG(ERR, TYPE_NETCAM, NO_ERRNO
|
||||
,_("%s: Unable to find stream info: %s")
|
||||
@@ -1678,8 +1724,8 @@ static int netcam_open_context(struct ctx_netcam *netcam)
|
||||
mythreadname_set("av",netcam->threadnbr,netcam->camera_name);
|
||||
retcd = netcam_open_codec(netcam);
|
||||
mythreadname_set(NULL, 0, netcam->threadname);
|
||||
if ((retcd < 0) || (netcam->interrupted) || (netcam->finish) ){
|
||||
if (netcam->status == NETCAM_NOTCONNECTED){
|
||||
if ((retcd < 0) || (netcam->interrupted) || (netcam->finish) ) {
|
||||
if (netcam->status == NETCAM_NOTCONNECTED) {
|
||||
av_strerror(retcd, errstr, sizeof(errstr));
|
||||
MOTION_LOG(ERR, TYPE_NETCAM, NO_ERRNO
|
||||
,_("%s: Unable to open codec context: %s")
|
||||
@@ -1702,14 +1748,14 @@ static int netcam_open_context(struct ctx_netcam *netcam)
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (netcam->high_resolution){
|
||||
if (netcam->high_resolution) {
|
||||
netcam->imgsize.width = netcam->codec_context->width;
|
||||
netcam->imgsize.height = netcam->codec_context->height;
|
||||
}
|
||||
|
||||
netcam->frame = myframe_alloc();
|
||||
if (netcam->frame == NULL) {
|
||||
if (netcam->status == NETCAM_NOTCONNECTED){
|
||||
if (netcam->status == NETCAM_NOTCONNECTED) {
|
||||
MOTION_LOG(ERR, TYPE_NETCAM, NO_ERRNO
|
||||
,_("%s: Unable to allocate frame."),netcam->cameratype);
|
||||
}
|
||||
@@ -1717,10 +1763,10 @@ static int netcam_open_context(struct ctx_netcam *netcam)
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (netcam->passthrough){
|
||||
if (netcam->passthrough) {
|
||||
retcd = netcam_copy_stream(netcam);
|
||||
if ((retcd < 0) || (netcam->interrupted)){
|
||||
if (netcam->status == NETCAM_NOTCONNECTED){
|
||||
if ((retcd < 0) || (netcam->interrupted)) {
|
||||
if (netcam->status == NETCAM_NOTCONNECTED) {
|
||||
MOTION_LOG(ERR, TYPE_NETCAM, NO_ERRNO
|
||||
,_("%s: Failed to copy stream for pass-through.")
|
||||
,netcam->cameratype);
|
||||
@@ -1731,8 +1777,8 @@ static int netcam_open_context(struct ctx_netcam *netcam)
|
||||
|
||||
/* Validate that the previous steps opened the camera */
|
||||
retcd = netcam_read_image(netcam);
|
||||
if ((retcd < 0) || (netcam->interrupted)){
|
||||
if (netcam->status == NETCAM_NOTCONNECTED){
|
||||
if ((retcd < 0) || (netcam->interrupted)) {
|
||||
if (netcam->status == NETCAM_NOTCONNECTED) {
|
||||
MOTION_LOG(ERR, TYPE_NETCAM, NO_ERRNO
|
||||
,_("%s: Failed to read first image"),netcam->cameratype);
|
||||
}
|
||||
@@ -1747,11 +1793,17 @@ static int netcam_open_context(struct ctx_netcam *netcam)
|
||||
static int netcam_connect(struct ctx_netcam *netcam)
|
||||
{
|
||||
|
||||
if (netcam_open_context(netcam) < 0) return -1;
|
||||
if (netcam_open_context(netcam) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (netcam_ntc(netcam) < 0 ) return -1;
|
||||
if (netcam_ntc(netcam) < 0 ) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (netcam_read_image(netcam) < 0) return -1;
|
||||
if (netcam_read_image(netcam) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* We use the status for determining whether to grab a image from
|
||||
* the Motion loop(see "next" function). When we are initially starting,
|
||||
@@ -1759,7 +1811,7 @@ static int netcam_connect(struct ctx_netcam *netcam)
|
||||
* Motion loop to start quite yet on this first image so we do
|
||||
* not set the status to connected
|
||||
*/
|
||||
if (!netcam->first_image){
|
||||
if (!netcam->first_image) {
|
||||
netcam->status = NETCAM_CONNECTED;
|
||||
|
||||
MOTION_LOG(NTC, TYPE_NETCAM, NO_ERRNO
|
||||
@@ -1770,7 +1822,7 @@ static int netcam_connect(struct ctx_netcam *netcam)
|
||||
, _("%s: Netcam capture FPS is %d.")
|
||||
, netcam->cameratype, netcam->capture_rate);
|
||||
|
||||
if (netcam->src_fps > 0){
|
||||
if (netcam->src_fps > 0) {
|
||||
MOTION_LOG(NTC, TYPE_NETCAM, NO_ERRNO
|
||||
, _("%s: Camera source is %d FPS")
|
||||
, netcam->cameratype, netcam->src_fps);
|
||||
@@ -1780,7 +1832,7 @@ static int netcam_connect(struct ctx_netcam *netcam)
|
||||
, netcam->cameratype);
|
||||
}
|
||||
|
||||
if (netcam->capture_rate < netcam->src_fps){
|
||||
if (netcam->capture_rate < netcam->src_fps) {
|
||||
MOTION_LOG(WRN, TYPE_NETCAM, NO_ERRNO
|
||||
, _("%s: Capture FPS less than camera FPS. Decoding errors will occur.")
|
||||
, netcam->cameratype);
|
||||
@@ -1799,22 +1851,24 @@ static void netcam_shutdown(struct ctx_netcam *netcam)
|
||||
if (netcam) {
|
||||
netcam_close_context(netcam);
|
||||
|
||||
if (netcam->path != NULL) free(netcam->path);
|
||||
if (netcam->path != NULL) {
|
||||
free(netcam->path);
|
||||
}
|
||||
netcam->path = NULL;
|
||||
|
||||
if (netcam->img_latest != NULL){
|
||||
if (netcam->img_latest != NULL) {
|
||||
free(netcam->img_latest->ptr);
|
||||
free(netcam->img_latest);
|
||||
}
|
||||
netcam->img_latest = NULL;
|
||||
|
||||
if (netcam->img_recv != NULL){
|
||||
if (netcam->img_recv != NULL) {
|
||||
free(netcam->img_recv->ptr);
|
||||
free(netcam->img_recv);
|
||||
}
|
||||
netcam->img_recv = NULL;
|
||||
|
||||
if (netcam->decoder_nm != NULL){
|
||||
if (netcam->decoder_nm != NULL) {
|
||||
free(netcam->decoder_nm);
|
||||
}
|
||||
netcam->decoder_nm = NULL;
|
||||
@@ -1832,7 +1886,9 @@ static void netcam_handler_wait(struct ctx_netcam *netcam)
|
||||
{
|
||||
long usec_maxrate, usec_delay;
|
||||
|
||||
if (netcam->capture_rate < 1) netcam->capture_rate = 1;
|
||||
if (netcam->capture_rate < 1) {
|
||||
netcam->capture_rate = 1;
|
||||
}
|
||||
|
||||
usec_maxrate = (1000000L / netcam->capture_rate);
|
||||
|
||||
@@ -1842,7 +1898,7 @@ static void netcam_handler_wait(struct ctx_netcam *netcam)
|
||||
((netcam->frame_curr_tm.tv_sec - netcam->frame_prev_tm.tv_sec) * 1000000L) -
|
||||
((netcam->frame_curr_tm.tv_nsec - netcam->frame_prev_tm.tv_nsec)/1000);
|
||||
|
||||
if ((usec_delay > 0) && (usec_delay < 1000000L)){
|
||||
if ((usec_delay > 0) && (usec_delay < 1000000L)) {
|
||||
SLEEP(0, usec_delay * 1000);
|
||||
}
|
||||
|
||||
@@ -1854,7 +1910,7 @@ static void netcam_handler_reconnect(struct ctx_netcam *netcam)
|
||||
int retcd;
|
||||
|
||||
if ((netcam->status == NETCAM_CONNECTED) ||
|
||||
(netcam->status == NETCAM_READINGIMAGE)){
|
||||
(netcam->status == NETCAM_READINGIMAGE)) {
|
||||
MOTION_LOG(ERR, TYPE_NETCAM, NO_ERRNO
|
||||
,_("%s: Reconnecting with camera...."),netcam->cameratype);
|
||||
}
|
||||
@@ -1866,10 +1922,10 @@ static void netcam_handler_reconnect(struct ctx_netcam *netcam)
|
||||
* before we go into the long wait phase
|
||||
*/
|
||||
retcd = netcam_connect(netcam);
|
||||
if (retcd < 0){
|
||||
if (netcam->reconnect_count < 100){
|
||||
if (retcd < 0) {
|
||||
if (netcam->reconnect_count < 100) {
|
||||
netcam->reconnect_count++;
|
||||
} else if (netcam->reconnect_count == 100){
|
||||
} else if (netcam->reconnect_count == 100) {
|
||||
MOTION_LOG(NTC, TYPE_NETCAM, NO_ERRNO
|
||||
,_("%s: Camera did not reconnect."), netcam->cameratype);
|
||||
MOTION_LOG(NTC, TYPE_NETCAM, NO_ERRNO
|
||||
@@ -1967,10 +2023,12 @@ static int netcam_start_handler(struct ctx_netcam *netcam)
|
||||
wait_counter = 60;
|
||||
while (wait_counter > 0) {
|
||||
pthread_mutex_lock(&netcam->mutex);
|
||||
if (netcam->img_latest->ptr != NULL ) wait_counter = -1;
|
||||
if (netcam->img_latest->ptr != NULL ) {
|
||||
wait_counter = -1;
|
||||
}
|
||||
pthread_mutex_unlock(&netcam->mutex);
|
||||
|
||||
if (wait_counter > 0 ){
|
||||
if (wait_counter > 0 ) {
|
||||
MOTION_LOG(INF, TYPE_NETCAM, NO_ERRNO
|
||||
,_("%s: Waiting for first image from the handler."),netcam->cameratype);
|
||||
SLEEP(0,5000000);
|
||||
@@ -1992,14 +2050,19 @@ int netcam_setup(struct ctx_cam *cam)
|
||||
cam->netcam = NULL;
|
||||
cam->netcam_high = NULL;
|
||||
|
||||
if (netcam_set_dimensions(cam) < 0 ) return -1;
|
||||
if (netcam_set_dimensions(cam) < 0 ) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
indx_cam = 1;
|
||||
indx_max = 1;
|
||||
if (cam->conf->netcam_high_url != "") indx_max = 2;
|
||||
if (cam->conf->netcam_high_url != "") {
|
||||
indx_max = 2;
|
||||
} else {
|
||||
indx_max = 1;
|
||||
}
|
||||
|
||||
while (indx_cam <= indx_max){
|
||||
if (indx_cam == 1){
|
||||
if (indx_cam == 1) {
|
||||
cam->netcam = netcam_new_context();
|
||||
if (cam->netcam == NULL) {
|
||||
MOTION_LOG(ERR, TYPE_NETCAM, NO_ERRNO
|
||||
@@ -2023,10 +2086,12 @@ int netcam_setup(struct ctx_cam *cam)
|
||||
|
||||
netcam_set_parms(cam, netcam);
|
||||
|
||||
if (netcam_connect(netcam) < 0) return -1;
|
||||
if (netcam_connect(netcam) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
retcd = netcam_read_image(netcam);
|
||||
if (retcd < 0){
|
||||
if (retcd < 0) {
|
||||
MOTION_LOG(CRT, TYPE_NETCAM, NO_ERRNO
|
||||
,_("Failed trying to read first image - retval:%d"), retcd);
|
||||
netcam->status = NETCAM_NOTCONNECTED;
|
||||
@@ -2041,12 +2106,14 @@ int netcam_setup(struct ctx_cam *cam)
|
||||
* to set the dimension parameters here (it is done in the set_parms). For high res
|
||||
* we must get the dimensions from the first image captured
|
||||
*/
|
||||
if (netcam->high_resolution){
|
||||
if (netcam->high_resolution) {
|
||||
cam->imgs.width_high = netcam->imgsize.width;
|
||||
cam->imgs.height_high = netcam->imgsize.height;
|
||||
}
|
||||
|
||||
if (netcam_start_handler(netcam) < 0 ) return -1;
|
||||
if (netcam_start_handler(netcam) < 0 ) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
indx_cam++;
|
||||
}
|
||||
@@ -2061,7 +2128,7 @@ int netcam_next(struct ctx_cam *cam, struct ctx_image_data *img_data)
|
||||
/* This is called from the motion loop thread */
|
||||
|
||||
if ((cam->netcam->status == NETCAM_RECONNECTING) ||
|
||||
(cam->netcam->status == NETCAM_NOTCONNECTED)){
|
||||
(cam->netcam->status == NETCAM_NOTCONNECTED)) {
|
||||
return 1;
|
||||
}
|
||||
pthread_mutex_lock(&cam->netcam->mutex);
|
||||
@@ -2072,9 +2139,11 @@ int netcam_next(struct ctx_cam *cam, struct ctx_image_data *img_data)
|
||||
img_data->idnbr_norm = cam->netcam->idnbr;
|
||||
pthread_mutex_unlock(&cam->netcam->mutex);
|
||||
|
||||
if (cam->netcam_high){
|
||||
if (cam->netcam_high) {
|
||||
if ((cam->netcam_high->status == NETCAM_RECONNECTING) ||
|
||||
(cam->netcam_high->status == NETCAM_NOTCONNECTED)) return 1;
|
||||
(cam->netcam_high->status == NETCAM_NOTCONNECTED)) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
pthread_mutex_lock(&cam->netcam_high->mutex);
|
||||
netcam_pktarray_resize(cam, true);
|
||||
@@ -2107,17 +2176,20 @@ void netcam_cleanup(struct ctx_cam *cam, int init_retry_flag)
|
||||
struct ctx_netcam *netcam;
|
||||
|
||||
indx_cam = 1;
|
||||
indx_max = 1;
|
||||
if (cam->netcam_high) indx_max = 2;
|
||||
if (cam->netcam_high) {
|
||||
indx_max = 2;
|
||||
} else {
|
||||
indx_max = 1;
|
||||
}
|
||||
|
||||
while (indx_cam <= indx_max) {
|
||||
if (indx_cam == 1){
|
||||
if (indx_cam == 1) {
|
||||
netcam = cam->netcam;
|
||||
} else {
|
||||
netcam = cam->netcam_high;
|
||||
}
|
||||
|
||||
if (netcam){
|
||||
if (netcam) {
|
||||
MOTION_LOG(INF, TYPE_NETCAM, NO_ERRNO
|
||||
,_("%s: Shutting down network camera."),netcam->cameratype);
|
||||
|
||||
@@ -2139,7 +2211,7 @@ void netcam_cleanup(struct ctx_cam *cam, int init_retry_flag)
|
||||
/* pthread_kill(netcam->thread_id); */
|
||||
pthread_cancel(netcam->thread_id);
|
||||
pthread_kill(netcam->thread_id, SIGVTALRM); /* This allows the cancel to be processed */
|
||||
if (!init_retry_flag){
|
||||
if (!init_retry_flag) {
|
||||
pthread_mutex_lock(&netcam->motapp->global_lock);
|
||||
netcam->motapp->threads_running--;
|
||||
pthread_mutex_unlock(&netcam->motapp->global_lock);
|
||||
@@ -2154,7 +2226,7 @@ void netcam_cleanup(struct ctx_cam *cam, int init_retry_flag)
|
||||
|
||||
free(netcam);
|
||||
netcam = NULL;
|
||||
if (indx_cam == 1){
|
||||
if (indx_cam == 1) {
|
||||
MOTION_LOG(NTC, TYPE_NETCAM, NO_ERRNO
|
||||
,_("Norm: Shut down complete."));
|
||||
} else {
|
||||
|
||||
@@ -70,14 +70,14 @@ static void pic_save_webp(FILE *fp, unsigned char *image, int width, int height,
|
||||
#ifdef HAVE_WEBP
|
||||
/* Create a config present and check for compatible library version */
|
||||
WebPConfig webp_config;
|
||||
if (!WebPConfigPreset(&webp_config, WEBP_PRESET_DEFAULT, (float) quality)){
|
||||
if (!WebPConfigPreset(&webp_config, WEBP_PRESET_DEFAULT, (float) quality)) {
|
||||
MOTION_LOG(ERR, TYPE_CORE, NO_ERRNO, _("libwebp version error"));
|
||||
return;
|
||||
}
|
||||
|
||||
/* Create the input data structure and check for compatible library version */
|
||||
WebPPicture webp_image;
|
||||
if (!WebPPictureInit(&webp_image)){
|
||||
if (!WebPPictureInit(&webp_image)) {
|
||||
MOTION_LOG(ERR, TYPE_CORE, NO_ERRNO,_("libwebp version error"));
|
||||
return;
|
||||
}
|
||||
@@ -85,7 +85,7 @@ static void pic_save_webp(FILE *fp, unsigned char *image, int width, int height,
|
||||
/* Allocate the image buffer based on image width and height */
|
||||
webp_image.width = width;
|
||||
webp_image.height = height;
|
||||
if (!WebPPictureAlloc(&webp_image)){
|
||||
if (!WebPPictureAlloc(&webp_image)) {
|
||||
MOTION_LOG(ERR, TYPE_CORE, NO_ERRNO,_("libwebp image buffer allocation error"));
|
||||
return;
|
||||
}
|
||||
@@ -102,9 +102,9 @@ static void pic_save_webp(FILE *fp, unsigned char *image, int width, int height,
|
||||
webp_image.custom_ptr = (void*) &webp_writer;
|
||||
|
||||
/* Encode the YUV image as webp */
|
||||
if (!WebPEncode(&webp_config, &webp_image))
|
||||
if (!WebPEncode(&webp_config, &webp_image)) {
|
||||
MOTION_LOG(WRN, TYPE_CORE, NO_ERRNO,_("libwebp image compression error"));
|
||||
|
||||
}
|
||||
/* A bitstream object is needed for the muxing proces */
|
||||
WebPData webp_bitstream;
|
||||
webp_bitstream.bytes = webp_writer.mem;
|
||||
@@ -122,8 +122,9 @@ static void pic_save_webp(FILE *fp, unsigned char *image, int width, int height,
|
||||
}
|
||||
|
||||
/* Write the webp final bitstream to the file */
|
||||
if (fwrite(webp_output.bytes, sizeof(uint8_t), webp_output.size, fp) != webp_output.size)
|
||||
if (fwrite(webp_output.bytes, sizeof(uint8_t), webp_output.size, fp) != webp_output.size) {
|
||||
MOTION_LOG(ERR, TYPE_CORE, NO_ERRNO,_("unable to save webp image to file"));
|
||||
}
|
||||
|
||||
#if WEBP_ENCODER_ABI_VERSION > 0x0202
|
||||
/* writer.mem must be freed by calling WebPMemoryWriterClear */
|
||||
@@ -210,18 +211,24 @@ static void pic_save_ppm(FILE *picture, unsigned char *image, int width, int hei
|
||||
r = r >> 16;
|
||||
g = g >> 16;
|
||||
b = b >> 16;
|
||||
if (r < 0)
|
||||
|
||||
if (r < 0) {
|
||||
r = 0;
|
||||
else if (r > 255)
|
||||
} else if (r > 255) {
|
||||
r = 255;
|
||||
if (g < 0)
|
||||
}
|
||||
|
||||
if (g < 0) {
|
||||
g = 0;
|
||||
else if (g > 255)
|
||||
} else if (g > 255) {
|
||||
g = 255;
|
||||
if (b < 0)
|
||||
}
|
||||
|
||||
if (b < 0) {
|
||||
b = 0;
|
||||
else if (b > 255)
|
||||
} else if (b > 255) {
|
||||
b = 255;
|
||||
}
|
||||
|
||||
rgb[0] = b;
|
||||
rgb[1] = g;
|
||||
@@ -250,7 +257,7 @@ int pic_put_memory(struct ctx_cam *cam, unsigned char* dest_image, int image_siz
|
||||
struct timespec ts1;
|
||||
|
||||
clock_gettime(CLOCK_REALTIME, &ts1);
|
||||
if (!cam->conf->stream_grey){
|
||||
if (!cam->conf->stream_grey) {
|
||||
return jpgutl_put_yuv420p(dest_image, image_size, image,
|
||||
width, height, quality, cam ,&ts1, NULL);
|
||||
} else {
|
||||
@@ -328,7 +335,9 @@ void pic_save_roi(struct ctx_cam *cam, char *file, unsigned char *image)
|
||||
|
||||
bx = &cam->current_image->location;
|
||||
|
||||
if ((bx->width <64) || (bx->height <64)) return;
|
||||
if ((bx->width <64) || (bx->height <64)) {
|
||||
return;
|
||||
}
|
||||
|
||||
picture = myfopen(file, "w");
|
||||
if (!picture) {
|
||||
@@ -383,8 +392,9 @@ unsigned char *pic_load_pgm(FILE *picture, int width, int height)
|
||||
/* Skip comment */
|
||||
line[0] = '#';
|
||||
while (line[0] == '#')
|
||||
if (!fgets(line, 255, picture))
|
||||
if (!fgets(line, 255, picture)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Read image size */
|
||||
if (sscanf(line, "%d %d", &mask_width, &mask_height) != 2) {
|
||||
@@ -396,8 +406,9 @@ unsigned char *pic_load_pgm(FILE *picture, int width, int height)
|
||||
/* Maximum value */
|
||||
line[0] = '#';
|
||||
while (line[0] == '#')
|
||||
if (!fgets(line, 255, picture))
|
||||
if (!fgets(line, 255, picture)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (sscanf(line, "%d", &maxval) != 1) {
|
||||
MOTION_LOG(ERR, TYPE_ALL, SHOW_ERRNO
|
||||
@@ -413,11 +424,13 @@ unsigned char *pic_load_pgm(FILE *picture, int width, int height)
|
||||
image =(unsigned char*) mymalloc((mask_width * mask_height * 3) / 2);
|
||||
|
||||
for (y = 0; y < mask_height; y++) {
|
||||
if ((int)fread(&image[y * mask_width], 1, mask_width, picture) != mask_width)
|
||||
if ((int)fread(&image[y * mask_width], 1, mask_width, picture) != mask_width) {
|
||||
MOTION_LOG(ERR, TYPE_ALL, SHOW_ERRNO, "Failed reading image data from pgm file");
|
||||
}
|
||||
|
||||
for (x = 0; x < mask_width; x++)
|
||||
for (x = 0; x < mask_width; x++) {
|
||||
image[y * mask_width + x] = (int)image[y * mask_width + x] * 255 / maxval;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -521,7 +534,7 @@ void pic_save_preview(struct ctx_cam *cam, struct ctx_image_data *img)
|
||||
|
||||
/* Copy the actual images for norm and high */
|
||||
memcpy(cam->imgs.image_preview.image_norm, img->image_norm, cam->imgs.size_norm);
|
||||
if (cam->imgs.size_high > 0){
|
||||
if (cam->imgs.size_high > 0) {
|
||||
memcpy(cam->imgs.image_preview.image_high, img->image_high, cam->imgs.size_high);
|
||||
}
|
||||
|
||||
@@ -529,8 +542,9 @@ void pic_save_preview(struct ctx_cam *cam, struct ctx_image_data *img)
|
||||
* If we set output_all to yes and during the event
|
||||
* there is no image with motion, diffs is 0, we are not going to save the preview event
|
||||
*/
|
||||
if (cam->imgs.image_preview.diffs == 0)
|
||||
if (cam->imgs.image_preview.diffs == 0) {
|
||||
cam->imgs.image_preview.diffs = 1;
|
||||
}
|
||||
|
||||
draw_locate_preview(cam, img);
|
||||
|
||||
@@ -567,7 +581,7 @@ void pic_init_privacy(struct ctx_cam *cam)
|
||||
|
||||
/* We only need the "or" mask for the U & V chrominance area. */
|
||||
cam->imgs.mask_privacy_uv =(unsigned char*) mymalloc((cam->imgs.height * cam->imgs.width) / 2);
|
||||
if (cam->imgs.size_high > 0){
|
||||
if (cam->imgs.size_high > 0) {
|
||||
MOTION_LOG(INF, TYPE_ALL, NO_ERRNO
|
||||
,_("Opening high resolution privacy mask file"));
|
||||
rewind(picture);
|
||||
@@ -591,11 +605,14 @@ void pic_init_privacy(struct ctx_cam *cam)
|
||||
,_("Mask privacy file \"%s\" loaded."), cam->conf->mask_privacy.c_str());
|
||||
|
||||
indx_img = 1;
|
||||
indx_max = 1;
|
||||
if (cam->imgs.size_high > 0) indx_max = 2;
|
||||
if (cam->imgs.size_high > 0) {
|
||||
indx_max = 2;
|
||||
} else {
|
||||
indx_max = 1;
|
||||
}
|
||||
|
||||
while (indx_img <= indx_max){
|
||||
if (indx_img == 1){
|
||||
if (indx_img == 1) {
|
||||
start_cr = (cam->imgs.height * cam->imgs.width);
|
||||
offset_cb = ((cam->imgs.height * cam->imgs.width)/4);
|
||||
start_cb = start_cr + offset_cb;
|
||||
@@ -617,7 +634,7 @@ void pic_init_privacy(struct ctx_cam *cam)
|
||||
for (indxcol = 0; indxcol < indx_width; indxcol++) {
|
||||
y_index = indxcol + (indxrow * indx_width);
|
||||
if (img_temp[y_index] == 0xff) {
|
||||
if ((indxcol % 2 == 0) && (indxrow % 2 == 0) ){
|
||||
if ((indxcol % 2 == 0) && (indxrow % 2 == 0) ) {
|
||||
uv_index = (indxcol/2) + ((indxrow * indx_width)/4);
|
||||
img_temp[start_cr + uv_index] = 0xff;
|
||||
img_temp[start_cb + uv_index] = 0xff;
|
||||
@@ -626,7 +643,7 @@ void pic_init_privacy(struct ctx_cam *cam)
|
||||
}
|
||||
} else {
|
||||
img_temp[y_index] = 0x00;
|
||||
if ((indxcol % 2 == 0) && (indxrow % 2 == 0) ){
|
||||
if ((indxcol % 2 == 0) && (indxrow % 2 == 0) ) {
|
||||
uv_index = (indxcol/2) + ((indxrow * indx_width)/4);
|
||||
img_temp[start_cr + uv_index] = 0x00;
|
||||
img_temp[start_cb + uv_index] = 0x00;
|
||||
|
||||
@@ -244,15 +244,19 @@ void rotate_init(struct ctx_cam *cam)
|
||||
* If we're not rotating, let's exit once we have setup the capture dimensions
|
||||
* and output dimensions properly.
|
||||
*/
|
||||
if (cam->rotate_data->degrees == 0) return;
|
||||
if (cam->rotate_data->degrees == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Allocate memory if rotating 90 or 270 degrees, because those rotations
|
||||
* cannot be performed in-place (they can, but it would be too slow).
|
||||
*/
|
||||
if ((cam->rotate_data->degrees == 90) || (cam->rotate_data->degrees == 270)){
|
||||
if ((cam->rotate_data->degrees == 90) || (cam->rotate_data->degrees == 270)) {
|
||||
cam->rotate_data->buffer_norm =(unsigned char*) mymalloc(size_norm);
|
||||
if (size_high > 0 ) cam->rotate_data->buffer_high =(unsigned char*) mymalloc(size_high);
|
||||
if (size_high > 0 ) {
|
||||
cam->rotate_data->buffer_high =(unsigned char*) mymalloc(size_high);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -271,13 +275,15 @@ void rotate_init(struct ctx_cam *cam)
|
||||
void rotate_deinit(struct ctx_cam *cam)
|
||||
{
|
||||
|
||||
if (cam->rotate_data->buffer_norm)
|
||||
if (cam->rotate_data->buffer_norm) {
|
||||
free(cam->rotate_data->buffer_norm);
|
||||
}
|
||||
|
||||
if (cam->rotate_data->buffer_high)
|
||||
if (cam->rotate_data->buffer_high) {
|
||||
free(cam->rotate_data->buffer_high);
|
||||
}
|
||||
|
||||
if (cam->rotate_data != NULL){
|
||||
if (cam->rotate_data != NULL) {
|
||||
free(cam->rotate_data);
|
||||
cam->rotate_data = NULL;
|
||||
}
|
||||
@@ -316,11 +322,16 @@ int rotate_map(struct ctx_cam *cam, struct ctx_image_data *img_data)
|
||||
unsigned char *img;
|
||||
unsigned char *temp_buff;
|
||||
|
||||
if (cam->rotate_data->degrees == 0 && cam->rotate_data->axis == FLIP_TYPE_NONE) return 0;
|
||||
if (cam->rotate_data->degrees == 0 && cam->rotate_data->axis == FLIP_TYPE_NONE) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
indx = 0;
|
||||
indx_max = 0;
|
||||
if ((cam->rotate_data->capture_width_high != 0) && (cam->rotate_data->capture_height_high != 0)) indx_max = 1;
|
||||
if ((cam->rotate_data->capture_width_high != 0) && (cam->rotate_data->capture_height_high != 0)) {
|
||||
indx_max = 1;
|
||||
} else {
|
||||
indx_max = 0;
|
||||
}
|
||||
|
||||
while (indx <= indx_max) {
|
||||
deg = cam->rotate_data->degrees;
|
||||
@@ -328,7 +339,7 @@ int rotate_map(struct ctx_cam *cam, struct ctx_image_data *img_data)
|
||||
wh4 = 0;
|
||||
w2 = 0;
|
||||
h2 = 0;
|
||||
if (indx == 0 ){
|
||||
if (indx == 0 ) {
|
||||
img = img_data->image_norm;
|
||||
width = cam->rotate_data->capture_width_norm;
|
||||
height = cam->rotate_data->capture_height_norm;
|
||||
|
||||
36
src/util.cpp
36
src/util.cpp
@@ -410,11 +410,12 @@ size_t mystrftime(const struct ctx_cam *cam, char *s, size_t max, const char *us
|
||||
break;
|
||||
|
||||
case 'C': // text_event
|
||||
if (cam->text_event_string[0])
|
||||
if (cam->text_event_string[0]) {
|
||||
snprintf(tempstr, PATH_MAX, "%*s", width,
|
||||
cam->text_event_string);
|
||||
else
|
||||
} else {
|
||||
++pos_userformat;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'w': // picture width
|
||||
@@ -432,17 +433,19 @@ size_t mystrftime(const struct ctx_cam *cam, char *s, size_t max, const char *us
|
||||
break;
|
||||
}
|
||||
|
||||
if (filename)
|
||||
if (filename) {
|
||||
snprintf(tempstr, PATH_MAX, "%*s", width, filename);
|
||||
else
|
||||
} else {
|
||||
++pos_userformat;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'n': // sqltype
|
||||
if (sqltype)
|
||||
if (sqltype) {
|
||||
sprintf(tempstr, "%*d", width, sqltype);
|
||||
else
|
||||
} else {
|
||||
++pos_userformat;
|
||||
}
|
||||
break;
|
||||
|
||||
case '{': // long format specifier word.
|
||||
@@ -451,15 +454,18 @@ size_t mystrftime(const struct ctx_cam *cam, char *s, size_t max, const char *us
|
||||
while ((*pos_userformat != '}') && (*pos_userformat != 0))
|
||||
++pos_userformat;
|
||||
mystrftime_long (cam, width, word, (int)(pos_userformat-word), tempstr);
|
||||
if (*pos_userformat == '\0') --pos_userformat;
|
||||
if (*pos_userformat == '\0') {
|
||||
--pos_userformat;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case '$': // thread name
|
||||
if (cam->conf->camera_name != "")
|
||||
if (cam->conf->camera_name != "") {
|
||||
cam->conf->camera_name.copy(tempstr, PATH_MAX);
|
||||
else
|
||||
} else {
|
||||
++pos_userformat;
|
||||
}
|
||||
break;
|
||||
|
||||
default: // Any other code is copied with the %-sign
|
||||
@@ -561,7 +567,9 @@ static void mytranslate_locale_chg(const char *langcd)
|
||||
/* Invoke external function to change locale*/
|
||||
++_nl_msg_cat_cntr;
|
||||
#else
|
||||
if (langcd != NULL) MOTION_LOG(NTC, TYPE_ALL, NO_ERRNO,"No native language support");
|
||||
if (langcd != NULL) {
|
||||
MOTION_LOG(NTC, TYPE_ALL, NO_ERRNO,"No native language support");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -593,7 +601,7 @@ char* mytranslate_text(const char *msgid, int setnls)
|
||||
{
|
||||
static int nls_enabled = TRUE;
|
||||
|
||||
if (setnls == 0){
|
||||
if (setnls == 0) {
|
||||
if (nls_enabled) {
|
||||
MOTION_LOG(NTC, TYPE_ALL, NO_ERRNO,_("Disabling native language support"));
|
||||
}
|
||||
@@ -796,7 +804,7 @@ int mycopy_packet(AVPacket *dest_pkt, AVPacket *src_pkt)
|
||||
* We therefore disable the pass through recording and
|
||||
* for this function, simply do not do anything
|
||||
*/
|
||||
if (dest_pkt == src_pkt ){
|
||||
if (dest_pkt == src_pkt ) {
|
||||
return 0;
|
||||
} else {
|
||||
return 0;
|
||||
@@ -992,7 +1000,7 @@ void util_parms_parse_qte(struct ctx_params *params, std::string &parmline)
|
||||
if (indxcm == std::string::npos) {
|
||||
if (indxnm_st == std::string::npos) {
|
||||
indxvl_st = indxeq + 1;
|
||||
if (indxvl_st >= parmline.length()){
|
||||
if (indxvl_st >= parmline.length()) {
|
||||
indxvl_st = parmline.length() - 1;
|
||||
}
|
||||
indxvl_en = parmline.length() - 1;
|
||||
@@ -1140,7 +1148,7 @@ void util_parms_update(struct ctx_params *params, std::string &confline)
|
||||
std::string parmline;
|
||||
|
||||
for (indx = 0; indx < params->params_count; indx++) {
|
||||
if (indx == 0){
|
||||
if (indx == 0) {
|
||||
parmline = " ";
|
||||
} else {
|
||||
parmline += ",";
|
||||
|
||||
@@ -434,7 +434,7 @@ int vid_mjpegtoyuv420p(unsigned char *img_dst, unsigned char *img_src, int width
|
||||
ptr_buffer =(unsigned char*) memmem(img_src + soi_pos + 1, size - soi_pos - 1, "\xff\xd8", 2);
|
||||
}
|
||||
|
||||
if (soi_pos != 0){
|
||||
if (soi_pos != 0) {
|
||||
MOTION_LOG(INF, TYPE_VIDEO, NO_ERRNO,_("SOI position adjusted by %d bytes."), soi_pos);
|
||||
}
|
||||
|
||||
|
||||
@@ -114,7 +114,9 @@ static int vlp_open_vidpipe(void)
|
||||
|
||||
if ((tfd = open(buffer, O_RDWR|O_CLOEXEC)) >= 0) {
|
||||
strncpy(pipepath, buffer, sizeof(pipepath));
|
||||
if (pipe_fd >= 0) close(pipe_fd);
|
||||
if (pipe_fd >= 0) {
|
||||
close(pipe_fd);
|
||||
}
|
||||
pipe_fd = tfd;
|
||||
break;
|
||||
}
|
||||
@@ -125,8 +127,9 @@ static int vlp_open_vidpipe(void)
|
||||
|
||||
closedir(dir);
|
||||
|
||||
if (pipe_fd >= 0)
|
||||
if (pipe_fd >= 0) {
|
||||
MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO,_("Opened %s as pipe output"), pipepath);
|
||||
}
|
||||
|
||||
return pipe_fd;
|
||||
}
|
||||
@@ -143,9 +146,11 @@ static void vlp_show_vcap(struct v4l2_capability *cap)
|
||||
MOTION_LOG(INF, TYPE_VIDEO, NO_ERRNO, "cap.bus_info: %s",cap->bus_info);
|
||||
MOTION_LOG(INF, TYPE_VIDEO, NO_ERRNO, "cap.card: %u.%u.%u",(vers >> 16) & 0xFF,(vers >> 8) & 0xFF,vers & 0xFF);
|
||||
MOTION_LOG(INF, TYPE_VIDEO, NO_ERRNO, "Device capabilities");
|
||||
for (i=0;cap_list[i].code;i++)
|
||||
if (c & cap_list[i].code)
|
||||
for (i=0;cap_list[i].code;i++) {
|
||||
if (c & cap_list[i].code) {
|
||||
MOTION_LOG(INF, TYPE_VIDEO, NO_ERRNO, "%s",cap_list[i].cap);
|
||||
}
|
||||
}
|
||||
MOTION_LOG(INF, TYPE_VIDEO, NO_ERRNO, "------------------------");
|
||||
}
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
/* Allocate buffers if needed */
|
||||
static void webu_stream_mjpeg_checkbuffers(struct webui_ctx *webui)
|
||||
{
|
||||
if (webui->resp_size < (size_t)webui->cam->imgs.size_norm){
|
||||
if (webui->resp_size < (size_t)webui->cam->imgs.size_norm) {
|
||||
if (webui->resp_image != NULL) {
|
||||
free(webui->resp_image);
|
||||
webui->resp_image = NULL;
|
||||
@@ -57,12 +57,16 @@ static void webu_stream_mjpeg_delay(struct webui_ctx *webui)
|
||||
*/
|
||||
stream_delay = ((time_curr.tv_nsec - webui->time_last.tv_nsec)) +
|
||||
((time_curr.tv_sec - webui->time_last.tv_sec)*1000000000);
|
||||
if (stream_delay < 0) stream_delay = 0;
|
||||
if (stream_delay > 1000000000 ) stream_delay = 1000000000;
|
||||
if (stream_delay < 0) {
|
||||
stream_delay = 0;
|
||||
}
|
||||
if (stream_delay > 1000000000 ) {
|
||||
stream_delay = 1000000000;
|
||||
}
|
||||
|
||||
if (webui->stream_fps >= 1){
|
||||
if (webui->stream_fps >= 1) {
|
||||
stream_rate = ( (1000000000 / webui->stream_fps) - stream_delay);
|
||||
if ((stream_rate > 0) && (stream_rate < 1000000000)){
|
||||
if ((stream_rate > 0) && (stream_rate < 1000000000)) {
|
||||
SLEEP(0,stream_rate);
|
||||
} else if (stream_rate == 1000000000) {
|
||||
SLEEP(1,0);
|
||||
@@ -82,19 +86,19 @@ static void webu_stream_mjpeg_getimg(struct webui_ctx *webui)
|
||||
memset(webui->resp_image, '\0', webui->resp_size);
|
||||
|
||||
/* Assign to a local pointer the stream we want */
|
||||
if (webui->cnct_type == WEBUI_CNCT_FULL){
|
||||
if (webui->cnct_type == WEBUI_CNCT_FULL) {
|
||||
local_stream = &webui->cam->stream.norm;
|
||||
|
||||
} else if (webui->cnct_type == WEBUI_CNCT_SUB){
|
||||
} else if (webui->cnct_type == WEBUI_CNCT_SUB) {
|
||||
local_stream = &webui->cam->stream.sub;
|
||||
|
||||
} else if (webui->cnct_type == WEBUI_CNCT_MOTION){
|
||||
} else if (webui->cnct_type == WEBUI_CNCT_MOTION) {
|
||||
local_stream = &webui->cam->stream.motion;
|
||||
|
||||
} else if (webui->cnct_type == WEBUI_CNCT_SOURCE){
|
||||
} else if (webui->cnct_type == WEBUI_CNCT_SOURCE) {
|
||||
local_stream = &webui->cam->stream.source;
|
||||
|
||||
} else if (webui->cnct_type == WEBUI_CNCT_SECONDARY){
|
||||
} else if (webui->cnct_type == WEBUI_CNCT_SECONDARY) {
|
||||
local_stream = &webui->cam->stream.secondary;
|
||||
|
||||
} else {
|
||||
@@ -104,7 +108,7 @@ static void webu_stream_mjpeg_getimg(struct webui_ctx *webui)
|
||||
/* Copy jpg from the motion loop thread */
|
||||
pthread_mutex_lock(&webui->cam->stream.mutex);
|
||||
if ((!webui->cam->detecting_motion) &&
|
||||
(webui->motapp->cam_list[webui->threadnbr]->conf->stream_motion)){
|
||||
(webui->motapp->cam_list[webui->threadnbr]->conf->stream_motion)) {
|
||||
webui->stream_fps = 1;
|
||||
} else {
|
||||
webui->stream_fps = webui->motapp->cam_list[webui->threadnbr]->conf->stream_maxrate;
|
||||
@@ -146,9 +150,11 @@ static ssize_t webu_stream_mjpeg_response (void *cls, uint64_t pos, char *buf, s
|
||||
|
||||
(void)pos; /*Remove compiler warning */
|
||||
|
||||
if (webui->cam->motapp->webcontrol_finish) return -1;
|
||||
if (webui->cam->motapp->webcontrol_finish) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ((webui->stream_pos == 0) || (webui->resp_used == 0)){
|
||||
if ((webui->stream_pos == 0) || (webui->resp_used == 0)) {
|
||||
|
||||
webu_stream_mjpeg_delay(webui);
|
||||
|
||||
@@ -157,7 +163,9 @@ static ssize_t webu_stream_mjpeg_response (void *cls, uint64_t pos, char *buf, s
|
||||
|
||||
webu_stream_mjpeg_getimg(webui);
|
||||
|
||||
if (webui->resp_used == 0) return 0;
|
||||
if (webui->resp_used == 0) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
if ((webui->resp_used - webui->stream_pos) > max) {
|
||||
@@ -169,7 +177,7 @@ static ssize_t webu_stream_mjpeg_response (void *cls, uint64_t pos, char *buf, s
|
||||
memcpy(buf, webui->resp_image + webui->stream_pos, sent_bytes);
|
||||
|
||||
webui->stream_pos = webui->stream_pos + sent_bytes;
|
||||
if (webui->stream_pos >= webui->resp_used){
|
||||
if (webui->stream_pos >= webui->resp_used) {
|
||||
webui->stream_pos = 0;
|
||||
}
|
||||
|
||||
@@ -187,19 +195,19 @@ static void webu_stream_static_getimg(struct webui_ctx *webui)
|
||||
memset(webui->resp_image, '\0', webui->resp_size);
|
||||
|
||||
/* Assign to a local pointer the stream we want */
|
||||
if (webui->cnct_type == WEBUI_CNCT_FULL){
|
||||
if (webui->cnct_type == WEBUI_CNCT_FULL) {
|
||||
local_stream = &webui->cam->stream.norm;
|
||||
|
||||
} else if (webui->cnct_type == WEBUI_CNCT_SUB){
|
||||
} else if (webui->cnct_type == WEBUI_CNCT_SUB) {
|
||||
local_stream = &webui->cam->stream.sub;
|
||||
|
||||
} else if (webui->cnct_type == WEBUI_CNCT_MOTION){
|
||||
} else if (webui->cnct_type == WEBUI_CNCT_MOTION) {
|
||||
local_stream = &webui->cam->stream.motion;
|
||||
|
||||
} else if (webui->cnct_type == WEBUI_CNCT_SOURCE){
|
||||
} else if (webui->cnct_type == WEBUI_CNCT_SOURCE) {
|
||||
local_stream = &webui->cam->stream.source;
|
||||
|
||||
} else if (webui->cnct_type == WEBUI_CNCT_SECONDARY){
|
||||
} else if (webui->cnct_type == WEBUI_CNCT_SECONDARY) {
|
||||
local_stream = &webui->cam->stream.secondary;
|
||||
|
||||
} else {
|
||||
@@ -207,7 +215,7 @@ static void webu_stream_static_getimg(struct webui_ctx *webui)
|
||||
}
|
||||
|
||||
pthread_mutex_lock(&webui->cam->stream.mutex);
|
||||
if (local_stream->jpeg_data == NULL){
|
||||
if (local_stream->jpeg_data == NULL) {
|
||||
pthread_mutex_unlock(&webui->cam->stream.mutex);
|
||||
return;
|
||||
}
|
||||
@@ -281,7 +289,7 @@ static void webu_stream_cnct_count(struct webui_ctx *webui)
|
||||
pthread_mutex_unlock(&webui->cam->stream.mutex);
|
||||
}
|
||||
|
||||
if (cnct_count == 1){
|
||||
if (cnct_count == 1) {
|
||||
/* This is the first connection so we need to wait half a sec
|
||||
* so that the motion loop on the other thread can update image
|
||||
*/
|
||||
@@ -327,7 +335,9 @@ static mhdrslt webu_stream_mjpeg(struct webui_ctx *webui)
|
||||
mhdrslt retcd;
|
||||
struct MHD_Response *response;
|
||||
|
||||
if (webu_stream_checks(webui) == -1) return MHD_NO;
|
||||
if (webu_stream_checks(webui) == -1) {
|
||||
return MHD_NO;
|
||||
}
|
||||
|
||||
webu_stream_cnct_count(webui);
|
||||
|
||||
@@ -337,12 +347,12 @@ static mhdrslt webu_stream_mjpeg(struct webui_ctx *webui)
|
||||
|
||||
response = MHD_create_response_from_callback (MHD_SIZE_UNKNOWN, 1024
|
||||
,&webu_stream_mjpeg_response, webui, NULL);
|
||||
if (!response){
|
||||
if (!response) {
|
||||
MOTION_LOG(ERR, TYPE_STREAM, NO_ERRNO, _("Invalid response"));
|
||||
return MHD_NO;
|
||||
}
|
||||
|
||||
if (webui->motapp->cam_list[0]->conf->webcontrol_cors_header != ""){
|
||||
if (webui->motapp->cam_list[0]->conf->webcontrol_cors_header != "") {
|
||||
MHD_add_response_header(response, MHD_HTTP_HEADER_ACCESS_CONTROL_ALLOW_ORIGIN
|
||||
, webui->motapp->cam_list[0]->conf->webcontrol_cors_header.c_str());
|
||||
}
|
||||
@@ -364,7 +374,9 @@ static mhdrslt webu_stream_static(struct webui_ctx *webui)
|
||||
struct MHD_Response *response;
|
||||
char resp_used[20];
|
||||
|
||||
if (webu_stream_checks(webui) == -1) return MHD_NO;
|
||||
if (webu_stream_checks(webui) == -1) {
|
||||
return MHD_NO;
|
||||
}
|
||||
|
||||
webu_stream_cnct_count(webui);
|
||||
|
||||
@@ -379,12 +391,12 @@ static mhdrslt webu_stream_static(struct webui_ctx *webui)
|
||||
|
||||
response = MHD_create_response_from_buffer (webui->resp_size
|
||||
,(void *)webui->resp_image, MHD_RESPMEM_MUST_COPY);
|
||||
if (!response){
|
||||
if (!response) {
|
||||
MOTION_LOG(ERR, TYPE_STREAM, NO_ERRNO, _("Invalid response"));
|
||||
return MHD_NO;
|
||||
}
|
||||
|
||||
if (webui->motapp->cam_list[0]->conf->webcontrol_cors_header != ""){
|
||||
if (webui->motapp->cam_list[0]->conf->webcontrol_cors_header != "") {
|
||||
MHD_add_response_header (response, MHD_HTTP_HEADER_ACCESS_CONTROL_ALLOW_ORIGIN
|
||||
, webui->motapp->cam_list[0]->conf->webcontrol_cors_header.c_str());
|
||||
}
|
||||
@@ -462,32 +474,32 @@ void webu_stream_deinit(struct ctx_cam *cam)
|
||||
|
||||
pthread_mutex_destroy(&cam->stream.mutex);
|
||||
|
||||
if (cam->imgs.image_substream != NULL){
|
||||
if (cam->imgs.image_substream != NULL) {
|
||||
free(cam->imgs.image_substream);
|
||||
cam->imgs.image_substream = NULL;
|
||||
}
|
||||
|
||||
if (cam->stream.norm.jpeg_data != NULL){
|
||||
if (cam->stream.norm.jpeg_data != NULL) {
|
||||
free(cam->stream.norm.jpeg_data);
|
||||
cam->stream.norm.jpeg_data = NULL;
|
||||
}
|
||||
|
||||
if (cam->stream.sub.jpeg_data != NULL){
|
||||
if (cam->stream.sub.jpeg_data != NULL) {
|
||||
free(cam->stream.sub.jpeg_data);
|
||||
cam->stream.sub.jpeg_data = NULL;
|
||||
}
|
||||
|
||||
if (cam->stream.motion.jpeg_data != NULL){
|
||||
if (cam->stream.motion.jpeg_data != NULL) {
|
||||
free(cam->stream.motion.jpeg_data);
|
||||
cam->stream.motion.jpeg_data = NULL;
|
||||
}
|
||||
|
||||
if (cam->stream.source.jpeg_data != NULL){
|
||||
if (cam->stream.source.jpeg_data != NULL) {
|
||||
free(cam->stream.source.jpeg_data);
|
||||
cam->stream.source.jpeg_data = NULL;
|
||||
}
|
||||
|
||||
if (cam->stream.secondary.jpeg_data != NULL){
|
||||
if (cam->stream.secondary.jpeg_data != NULL) {
|
||||
free(cam->stream.secondary.jpeg_data);
|
||||
cam->stream.secondary.jpeg_data = NULL;
|
||||
}
|
||||
@@ -498,7 +510,7 @@ void webu_stream_deinit(struct ctx_cam *cam)
|
||||
static void webu_stream_getimg_norm(struct ctx_cam *cam, struct ctx_image_data *img_data)
|
||||
{
|
||||
/*This is on the motion_loop thread */
|
||||
if (cam->stream.norm.jpeg_data == NULL){
|
||||
if (cam->stream.norm.jpeg_data == NULL) {
|
||||
cam->stream.norm.jpeg_data =(unsigned char*)mymalloc(cam->imgs.size_norm);
|
||||
}
|
||||
if (img_data->image_norm != NULL && cam->stream.norm.consumed) {
|
||||
@@ -521,7 +533,7 @@ static void webu_stream_getimg_sub(struct ctx_cam *cam, struct ctx_image_data *i
|
||||
|
||||
int subsize;
|
||||
|
||||
if (cam->stream.sub.jpeg_data == NULL){
|
||||
if (cam->stream.sub.jpeg_data == NULL) {
|
||||
cam->stream.sub.jpeg_data =(unsigned char*)mymalloc(cam->imgs.size_norm);
|
||||
}
|
||||
if (img_data->image_norm != NULL && cam->stream.sub.consumed) {
|
||||
@@ -530,7 +542,7 @@ static void webu_stream_getimg_sub(struct ctx_cam *cam, struct ctx_image_data *i
|
||||
((cam->imgs.height % 16) == 0)) {
|
||||
|
||||
subsize = ((cam->imgs.width / 2) * (cam->imgs.height / 2) * 3 / 2);
|
||||
if (cam->imgs.image_substream == NULL){
|
||||
if (cam->imgs.image_substream == NULL) {
|
||||
cam->imgs.image_substream =(unsigned char*)mymalloc(subsize);
|
||||
}
|
||||
pic_scale_img(cam->imgs.width
|
||||
@@ -564,7 +576,7 @@ static void webu_stream_getimg_motion(struct ctx_cam *cam)
|
||||
{
|
||||
/*This is on the motion_loop thread */
|
||||
|
||||
if (cam->stream.motion.jpeg_data == NULL){
|
||||
if (cam->stream.motion.jpeg_data == NULL) {
|
||||
cam->stream.motion.jpeg_data =(unsigned char*)mymalloc(cam->imgs.size_norm);
|
||||
}
|
||||
if (cam->imgs.image_motion.image_norm != NULL && cam->stream.motion.consumed) {
|
||||
@@ -585,7 +597,7 @@ static void webu_stream_getimg_source(struct ctx_cam *cam)
|
||||
{
|
||||
/*This is on the motion_loop thread */
|
||||
|
||||
if (cam->stream.source.jpeg_data == NULL){
|
||||
if (cam->stream.source.jpeg_data == NULL) {
|
||||
cam->stream.source.jpeg_data =(unsigned char*)mymalloc(cam->imgs.size_norm);
|
||||
}
|
||||
if (cam->imgs.image_virgin != NULL && cam->stream.source.consumed) {
|
||||
@@ -608,14 +620,14 @@ static void webu_stream_getimg_secondary(struct ctx_cam *cam)
|
||||
|
||||
if (cam->imgs.size_secondary>0) {
|
||||
pthread_mutex_lock(&cam->algsec->mutex);
|
||||
if (cam->stream.secondary.jpeg_data == NULL){
|
||||
if (cam->stream.secondary.jpeg_data == NULL) {
|
||||
cam->stream.secondary.jpeg_data =(unsigned char*)mymalloc(cam->imgs.size_norm);
|
||||
}
|
||||
memcpy(cam->stream.secondary.jpeg_data,cam->imgs.image_secondary,cam->imgs.size_secondary);
|
||||
cam->stream.secondary.jpeg_size = cam->imgs.size_secondary;
|
||||
pthread_mutex_unlock(&cam->algsec->mutex);
|
||||
} else {
|
||||
if (cam->stream.secondary.jpeg_data != NULL){
|
||||
if (cam->stream.secondary.jpeg_data != NULL) {
|
||||
free(cam->stream.secondary.jpeg_data);
|
||||
cam->stream.secondary.jpeg_data = NULL;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user