From d16b149c372da9e1e0be05a176f76409454013d7 Mon Sep 17 00:00:00 2001 From: Mr-Dave Date: Sun, 5 Mar 2023 19:38:38 -0700 Subject: [PATCH] Revise for explicit conversions --- configure.ac | 2 +- src/alg.cpp | 29 +++++------ src/alg_sec.cpp | 17 ++++--- src/alg_sec.hpp | 19 ++++--- src/dbse.cpp | 10 ++-- src/draw.cpp | 8 +-- src/event.cpp | 14 +++--- src/exif.cpp | 26 +++++----- src/jpegutils.cpp | 2 +- src/logger.cpp | 6 +-- src/motion_loop.cpp | 2 +- src/motionplus.hpp | 10 ++-- src/movie.cpp | 24 ++++----- src/netcam.cpp | 11 +++-- src/picture.cpp | 8 +-- src/sound.cpp | 31 ++++++------ src/video_common.cpp | 109 ++++++++++++++++++++++++----------------- src/video_loopback.cpp | 4 +- src/video_v4l2.cpp | 2 +- src/webu.cpp | 12 ++--- 20 files changed, 186 insertions(+), 160 deletions(-) diff --git a/configure.ac b/configure.ac index 57996cdf..9dd61559 100644 --- a/configure.ac +++ b/configure.ac @@ -603,7 +603,7 @@ AC_ARG_WITH([developer-flags], [DEVELOPER_FLAGS=no]) AS_IF([test "${DEVELOPER_FLAGS}" = "yes"], [ - TEMP_CPPFLAGS="$TEMP_CPPFLAGS -W -Wall -Wextra -Wformat -Wshadow -Wpointer-arith -Wwrite-strings -Winline -Wredundant-decls -Wno-long-long -ggdb -g3" + TEMP_CPPFLAGS="$TEMP_CPPFLAGS -W -Wall -Wextra -Wconversion -Wformat -Wshadow -Wpointer-arith -Wwrite-strings -Winline -Wredundant-decls -Wno-long-long -ggdb -g3" ] ) diff --git a/src/alg.cpp b/src/alg.cpp index f6dd036a..d27ed053 100644 --- a/src/alg.cpp +++ b/src/alg.cpp @@ -35,7 +35,7 @@ #define SMARTMASK_SENSITIVITY_INCR 5 typedef struct { - short y, xl, xr, dy; + int y, xl, xr, dy; } Segment; @@ -519,7 +519,7 @@ static void alg_despeckle(ctx_dev *cam) width = cam->imgs.width; height = cam->imgs.height; done = 0; - len = cam->conf->despeckle_filter.length(); + len = (int)cam->conf->despeckle_filter.length(); common_buffer = cam->imgs.common_buffer; cam->current_image->total_labels = 0; cam->imgs.largest_label = 0; @@ -573,7 +573,8 @@ static void alg_despeckle(ctx_dev *cam) void alg_tune_smartmask(ctx_dev *cam) { - int i, diff; + int i; + unsigned char diff; int motionsize = cam->imgs.motionsize; unsigned char *smartmask = cam->imgs.smartmask; unsigned char *smartmask_final = cam->imgs.smartmask_final; @@ -592,7 +593,7 @@ void alg_tune_smartmask(ctx_dev *cam) smartmask[i]--; } /* Increase smart_mask sensitivity based on the buffered values. */ - diff = smartmask_buffer[i] / sensitivity; + diff = (unsigned char)(smartmask_buffer[i] / sensitivity); if (diff) { if (smartmask[i] <= diff + 80) { @@ -610,9 +611,9 @@ void alg_tune_smartmask(ctx_dev *cam) } } /* Further expansion (here:erode due to inverted logic!) of the mask. */ - diff = alg_erode9(smartmask_final, cam->imgs.width, cam->imgs.height, + alg_erode9(smartmask_final, cam->imgs.width, cam->imgs.height, cam->imgs.common_buffer, 255); - diff = alg_erode5(smartmask_final, cam->imgs.width, cam->imgs.height, + alg_erode5(smartmask_final, cam->imgs.width, cam->imgs.height, cam->imgs.common_buffer, 255); cam->smartmask_count = cam->smartmask_ratio; } @@ -944,7 +945,7 @@ void alg_update_reference_frame(ctx_dev *cam, int action) (*ref_dyn)++; /* Motionpixel? Keep excluding from ref frame. */ } else { *ref_dyn = 0; /* Nothing special - release pixel. */ - *ref = (*ref + *image_virgin) / 2; + *ref = (unsigned char)((*ref + *image_virgin) / 2); } } else { /* No motion: copy to ref frame. */ @@ -1048,7 +1049,7 @@ static void alg_location_dist(ctx_dev *cam) if (*(out++)) { variance_x += ((x - cent->x) * (x - cent->x)); variance_y += ((y - cent->y) * (y - cent->y)); - distance_mean += sqrt( + distance_mean += (uint64_t)sqrt( ((x - cent->x) * (x - cent->x)) + ((y - cent->y) * (y - cent->y))); @@ -1074,9 +1075,9 @@ static void alg_location_dist(ctx_dev *cam) cent->maxx = cent->x + xdist / centc * 3; cent->miny = cent->y - ydist / centc * 3; cent->maxy = cent->y + ydist / centc * 3; - cent->stddev_x = sqrt((variance_x / centc)); - cent->stddev_y = sqrt((variance_y / centc)); - distance_mean = (distance_mean / centc); + cent->stddev_x = (int)sqrt((variance_x / centc)); + cent->stddev_y = (int)sqrt((variance_y / centc)); + distance_mean = (uint64_t)(distance_mean / centc); } else { cent->stddev_y = 0; cent->stddev_x = 0; @@ -1089,16 +1090,16 @@ static void alg_location_dist(ctx_dev *cam) for (x = 0; x < width; x++) { if (*(out++)) { variance_xy += ( - (sqrt(((x - cent->x) * (x - cent->x)) + + ((uint64_t)sqrt(((x - cent->x) * (x - cent->x)) + ((y - cent->y) * (y - cent->y))) - distance_mean) * - (sqrt(((x - cent->x) * (x - cent->x)) + + ((uint64_t)sqrt(((x - cent->x) * (x - cent->x)) + ((y - cent->y) * (y - cent->y))) - distance_mean)); } } } /* Per statistics, divide by n-1 for calc of a standard deviation */ if ((centc-1) > 0) { - cent->stddev_xy = sqrt((variance_xy / (centc-1))); + cent->stddev_xy = (int)sqrt((variance_xy / (centc-1))); } } diff --git a/src/alg_sec.cpp b/src/alg_sec.cpp index a91b5059..ac56349c 100644 --- a/src/alg_sec.cpp +++ b/src/alg_sec.cpp @@ -25,13 +25,16 @@ #ifdef HAVE_OPENCV -#include -#include -#include -#include -#include -#include -#include +#pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wconversion" + #include + #include + #include + #include + #include + #include + #include +#pragma GCC diagnostic pop using namespace cv; using namespace dnn; diff --git a/src/alg_sec.hpp b/src/alg_sec.hpp index ee0d55b3..126313fb 100644 --- a/src/alg_sec.hpp +++ b/src/alg_sec.hpp @@ -23,10 +23,13 @@ #ifdef HAVE_OPENCV - #include "opencv2/objdetect.hpp" - #include "opencv2/dnn.hpp" - #include "opencv2/highgui.hpp" - #include "opencv2/imgproc.hpp" + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wconversion" + #include "opencv2/objdetect.hpp" + #include "opencv2/dnn.hpp" + #include "opencv2/highgui.hpp" + #include "opencv2/imgproc.hpp" + #pragma GCC diagnostic pop #endif @@ -42,10 +45,10 @@ struct ctx_algsec_model { std::string image_type; int rotate; - float scalefactor; - float threshold; /* Threshold for motion to use on detection*/ + double scalefactor; + double threshold; /* Threshold for motion to use on detection*/ - float hog_threshold_model; /* Threshold fed into the opencv model*/ + double hog_threshold_model; /* Threshold fed into the opencv model*/ int hog_winstride; int hog_padding; @@ -63,7 +66,7 @@ struct ctx_algsec_model { std::vector dnn_classes; int dnn_width; int dnn_height; - float dnn_scale; + double dnn_scale; bool isdetected; /* Bool reset for each image as to whether a detection occurred */ diff --git a/src/dbse.cpp b/src/dbse.cpp index 07433000..d678b427 100644 --- a/src/dbse.cpp +++ b/src/dbse.cpp @@ -218,19 +218,19 @@ static void dbse_rec_assign(ctx_dbse_rec *rec, char *col_nm, char *col_val) } else if (mystrceq(col_nm,"movie_nm")) { free(rec->movie_nm); - flen = strlen(col_val); + flen = (int)strlen(col_val); rec->movie_nm = (char*)mymalloc(flen + 1); snprintf(rec->movie_nm, flen+1,"%s",col_val); } else if (mystrceq(col_nm,"movie_dir")) { free(rec->movie_dir); - flen = strlen(col_val); + flen = (int)strlen(col_val); rec->movie_dir = (char*)mymalloc(flen + 1); snprintf(rec->movie_dir, flen+1,"%s",col_val); } else if (mystrceq(col_nm,"full_nm")) { free(rec->full_nm); - flen = strlen(col_val); + flen = (int)strlen(col_val); rec->full_nm = (char*)mymalloc(flen + 1); snprintf(rec->full_nm, flen+1,"%s",col_val); if (stat(rec->full_nm, &statbuf) == 0) { @@ -245,7 +245,7 @@ static void dbse_rec_assign(ctx_dbse_rec *rec, char *col_nm, char *col_val) } else if (mystrceq(col_nm,"movie_tmc")) { free(rec->movie_tmc); - flen = strlen(col_val); + flen = (int)strlen(col_val); rec->movie_tmc = (char*)mymalloc(flen + 1); snprintf(rec->movie_tmc @@ -253,7 +253,7 @@ static void dbse_rec_assign(ctx_dbse_rec *rec, char *col_nm, char *col_val) } else if (mystrceq(col_nm,"movie_tml")) { free(rec->movie_tml); - flen = strlen(col_val); + flen = (int)strlen(col_val); rec->movie_tml = (char*)mymalloc(flen + 1); snprintf(rec->movie_tml diff --git a/src/draw.cpp b/src/draw.cpp index cd49103e..fefcef9c 100644 --- a/src/draw.cpp +++ b/src/draw.cpp @@ -1152,14 +1152,14 @@ int draw_text(unsigned char *image, int width, int height, int startx, int start txtlen = 0; while ((end = strstr(end, NEWLINE))) { if ((end - begin)>txtlen) { - txtlen = (end - begin); + txtlen = (int)(end - begin); } num_nl++; end += sizeof(NEWLINE)-1; begin = end; } if (txtlen == 0) { - txtlen = strlen(text); + txtlen = (int)strlen(text); } /* Adjust the factor if it is out of bounds @@ -1186,7 +1186,7 @@ int draw_text(unsigned char *image, int width, int height, int startx, int start begin = end = text; while ((end = strstr(end, NEWLINE))) { - int len = end-begin; + int len = (int)(end-begin); draw_textn(image, startx, starty, width, begin, len, factor); end += sizeof(NEWLINE)-1; @@ -1194,7 +1194,7 @@ int draw_text(unsigned char *image, int width, int height, int startx, int start starty += line_space; } - draw_textn(image, startx, starty, width, begin, strlen(begin), factor); + draw_textn(image, startx, starty, width, begin, (int)strlen(begin), factor); return 0; } diff --git a/src/event.cpp b/src/event.cpp index 4e6e9090..17d4cd6c 100644 --- a/src/event.cpp +++ b/src/event.cpp @@ -81,19 +81,19 @@ static void event_newfile(ctx_dev *cam, motion_event evnt static void on_picture_save_command(ctx_dev *cam, motion_event evnt ,ctx_image_data *img_data, char *fname, void *ftype, struct timespec *ts1) { - - int filetype = (unsigned long)ftype; + /*Fix me*/ + long filetype = (long)ftype; (void)evnt; (void)img_data; (void)ts1; if ((filetype & FTYPE_IMAGE_ANY) != 0 && (cam->conf->on_picture_save != "")) { - util_exec_command(cam, cam->conf->on_picture_save.c_str(), fname, filetype); + util_exec_command(cam, cam->conf->on_picture_save.c_str(), fname, (int)filetype); } if ((filetype & FTYPE_MOVIE_ANY) != 0 && (cam->conf->on_movie_start != "")) { - util_exec_command(cam, cam->conf->on_movie_start.c_str(), fname, filetype); + util_exec_command(cam, cam->conf->on_movie_start.c_str(), fname, (int)filetype); } } @@ -280,7 +280,7 @@ static void event_image_snapshot(ctx_dev *cam, motion_event evnt (void)fname; (void)ftype; - offset = cam->conf->snapshot_filename.length() - 8; + offset = (int)cam->conf->snapshot_filename.length() - 8; if (offset < 0) { offset = 1; } @@ -422,14 +422,14 @@ static void on_movie_end_command(ctx_dev *cam, motion_event evnt ,ctx_image_data *img_data, char *fname, void *ftype, struct timespec *ts1) { - int filetype = (unsigned long) ftype; + long filetype = (long) ftype; (void)evnt; (void)img_data; (void)ts1; if ((filetype & FTYPE_MOVIE_ANY) && (cam->conf->on_movie_end != "")) { - util_exec_command(cam, cam->conf->on_movie_end.c_str(), fname, filetype); + util_exec_command(cam, cam->conf->on_movie_end.c_str(), fname, (int)filetype); } } diff --git a/src/exif.cpp b/src/exif.cpp index 268b812f..e5a90726 100644 --- a/src/exif.cpp +++ b/src/exif.cpp @@ -87,22 +87,22 @@ static unsigned const char exif_tzoffset_tag[12] = { static void put_uint16(JOCTET *buf, unsigned value) { - buf[0] = ( value & 0xFF00 ) >> 8; - buf[1] = ( value & 0x00FF ); + buf[0] = (unsigned char)(( value & 0xFF00 ) >> 8); + buf[1] = (unsigned char)(( value & 0x00FF )); } static void put_sint16(JOCTET *buf, int value) { - buf[0] = ( value & 0xFF00 ) >> 8; - buf[1] = ( value & 0x00FF ); + buf[0] = (unsigned char)(( value & 0xFF00 ) >> 8); + buf[1] = (unsigned char)(( value & 0x00FF )); } static void put_uint32(JOCTET *buf, unsigned value) { - buf[0] = ( value & 0xFF000000 ) >> 24; - buf[1] = ( value & 0x00FF0000 ) >> 16; - buf[2] = ( value & 0x0000FF00 ) >> 8; - buf[3] = ( value & 0x000000FF ); + buf[0] = (unsigned char)(( value & 0xFF000000 ) >> 24); + buf[1] = (unsigned char)(( value & 0x00FF0000 ) >> 16); + buf[2] = (unsigned char)(( value & 0x0000FF00 ) >> 8); + buf[3] = (unsigned char)(( value & 0x000000FF )); } struct tiff_writing { @@ -134,7 +134,7 @@ static void put_direntry(struct tiff_writing *into, const char *data, unsigned l static void put_stringentry(struct tiff_writing *into, unsigned tag, const char *str, int with_nul) { - unsigned stringlength = strlen(str) + (with_nul?1:0); + unsigned stringlength = (int)strlen(str) + (with_nul?1:0); put_uint16(into->buf, tag); put_uint16(into->buf + 2, TIFF_TYPE_ASCII); @@ -221,7 +221,7 @@ unsigned exif_prepare(unsigned char **exif, ctx_dev *cam, if (description) { ifd0_tagcount ++; - datasize += 5 + strlen(description); /* Add 5 for NUL and alignment */ + datasize += 5 + (int)strlen(description); /* Add 5 for NUL and alignment */ } if (datetime) { @@ -236,12 +236,12 @@ unsigned exif_prepare(unsigned char **exif, ctx_dev *cam, ifd0_tagcount++; /* It would be nice to use the same offset for both tags' values, * but I don't want to write the bookkeeping for that right now */ - datasize += 2 * (5 + strlen(datetime)); + datasize += 2 * (5 + (int)strlen(datetime)); } if (subtime) { ifd1_tagcount++; - datasize += 5 + strlen(subtime); + datasize += 5 + (int)strlen(subtime); } if (box) { @@ -305,7 +305,7 @@ unsigned exif_prepare(unsigned char **exif, ctx_dev *cam, if (datetime) { memcpy(writing.buf, exif_tzoffset_tag, 12); - put_sint16(writing.buf+8, timestamp_tm.tm_gmtoff / 3600); + put_sint16(writing.buf+8, int(timestamp_tm.tm_gmtoff / 3600)); writing.buf += 12; } diff --git a/src/jpegutils.cpp b/src/jpegutils.cpp index cd4ab25a..5b04db67 100644 --- a/src/jpegutils.cpp +++ b/src/jpegutils.cpp @@ -386,7 +386,7 @@ static GLOBAL(void) _jpeg_mem_dest(j_compress_ptr cinfo, JOCTET* buf, size_t buf static GLOBAL(int) _jpeg_mem_size(j_compress_ptr cinfo) { mem_dest_ptr dest = (mem_dest_ptr) cinfo->dest; - return dest->jpegsize; + return (int)dest->jpegsize; } /* diff --git a/src/logger.cpp b/src/logger.cpp index 55dce968..5e09c56f 100644 --- a/src/logger.cpp +++ b/src/logger.cpp @@ -129,7 +129,7 @@ void motpls_log(int level, int type, int errno_flag,int fncname, const char *fmt char msg_buf[100]= {0}; va_list ap; - int threadnr; + unsigned long threadnr; static int flood_cnt = 0; static char flood_msg[1024]; @@ -159,12 +159,12 @@ void motpls_log(int level, int type, int errno_flag,int fncname, const char *fmt mythreadname_get(threadname); if (log_mode == LOGMODE_FILE) { - n = snprintf(buf, sizeof(buf), "%s [%s][%s][%02d:%s] " + n = snprintf(buf, sizeof(buf), "%s [%s][%s][%02ld:%s] " , str_time(), log_level_str[level], log_type_str[type] , threadnr, threadname ); timelen = 16; } else { - n = snprintf(buf, sizeof(buf), "[%s][%s][%02d:%s] " + n = snprintf(buf, sizeof(buf), "[%s][%s][%02ld:%s] " , log_level_str[level], log_type_str[type] , threadnr, threadname ); timelen = 0; diff --git a/src/motion_loop.cpp b/src/motion_loop.cpp index a528e883..7fcca29a 100644 --- a/src/motion_loop.cpp +++ b/src/motion_loop.cpp @@ -725,7 +725,7 @@ static void mlp_areadetect(ctx_dev *cam) if ((cam->conf->area_detect != "" ) && (cam->event_nr != cam->areadetect_eventnbr) && (cam->current_image->flags & IMAGE_TRIGGER)) { - j = cam->conf->area_detect.length(); + j = (int)cam->conf->area_detect.length(); for (i = 0; i < j; i++) { z = cam->conf->area_detect[i] - 49; /* characters are stored as ascii 48-57 (0-9) */ if ((z >= 0) && (z < 9)) { diff --git a/src/motionplus.hpp b/src/motionplus.hpp index 38f625c1..c62fc7d0 100644 --- a/src/motionplus.hpp +++ b/src/motionplus.hpp @@ -324,8 +324,8 @@ struct ctx_snd_alert { std::string alert_nm; /* Name of the alert*/ int volume_level; /* Volume level required to consider the sample*/ int volume_count; /* For each sample, number of times required to exceed volumne level*/ - float freq_low; /* Lowest frequency for detecting this alert*/ - float freq_high; /* Highest frequency for detecting this alert*/ + double freq_low; /* Lowest frequency for detecting this alert*/ + double freq_high; /* Highest frequency for detecting this alert*/ int trigger_count; /* Count of how many times it has been triggered so far*/ int trigger_threshold; /* How many times does it need to be triggered before an event*/ timespec trigger_time; /* The last time the trigger was invoked */ @@ -361,7 +361,7 @@ struct ctx_snd_fftw { fftw_complex *ff_out; int bin_max; int bin_min; - float bin_size; + double bin_size; #else int dummy; #endif @@ -369,8 +369,8 @@ struct ctx_snd_fftw { struct ctx_snd_info { std::string source; /* Source string in ALSA format e.g. hw:1,0*/ - unsigned int sample_rate; /* Sample rate of sound source*/ - uint8_t channels; /* Number of audio channels */ + int sample_rate; /* Sample rate of sound source*/ + int channels; /* Number of audio channels */ std::list alerts; /* list of sound alert criteria */ int vol_min; /* The minimum volume from alerts*/ int vol_max; /* Maximum volume of sample*/ diff --git a/src/movie.cpp b/src/movie.cpp index 1178fa73..3de07dad 100644 --- a/src/movie.cpp +++ b/src/movie.cpp @@ -141,8 +141,8 @@ static int movie_get_oformat(ctx_movie *movie) * at the end and initialized to null, so that we can just memcpy in the * extensions */ - len_full = strlen(movie->full_nm); - len_nm = strlen(movie->movie_nm); + len_full = (int)strlen(movie->full_nm); + len_nm = (int)strlen(movie->movie_nm); if (movie->tlapse == TIMELAPSE_APPEND) { movie->oc->oformat = av_guess_format("mpeg2video", NULL, NULL); @@ -1106,7 +1106,7 @@ static void movie_passthru_minpts(ctx_movie *movie) static int movie_passthru_put(ctx_movie *movie, ctx_image_data *img_data) { - int idnbr_image, idnbr_lastwritten, idnbr_stop, idnbr_firstkey; + int64_t idnbr_image, idnbr_lastwritten, idnbr_stop, idnbr_firstkey; int indx, indx_lastwritten, indx_firstkey, indx_video; if (movie->netcam_data == NULL) { @@ -1698,7 +1698,7 @@ int movie_init_norm(ctx_dev *cam, struct timespec *ts1) container = movie_init_container(cam); /* The increment of 10 is to allow for the extension and other chars*/ - len = strlen(tmp) + cam->conf->target_dir.length() + 10; + len = (int)(strlen(tmp) + cam->conf->target_dir.length() + 10); cam->movie_norm->full_nm = (char*)mymalloc(len); if (mystreq(container, "test")) { retcd = snprintf(cam->movie_norm->full_nm, len, "%s/%s_%s" @@ -1708,12 +1708,12 @@ int movie_init_norm(ctx_dev *cam, struct timespec *ts1) , cam->conf->target_dir.c_str(), tmp); } - len = cam->conf->target_dir.length() + 10; + len = (int)cam->conf->target_dir.length() + 10; cam->movie_norm->movie_dir = (char*)mymalloc(len); retcd = snprintf(cam->movie_norm->movie_dir,len,"%s" ,cam->conf->target_dir.c_str()); - len = strlen(tmp) + 10; + len = (int)strlen(tmp) + 10; cam->movie_norm->movie_nm = (char*)mymalloc(len); retcd = snprintf(cam->movie_norm->movie_nm, len, "%s", tmp); @@ -1771,7 +1771,7 @@ int movie_init_motion(ctx_dev *cam, struct timespec *ts1) container = movie_init_container(cam); /* The increment of 10 is to allow for the extension and other chars*/ - len = strlen(tmp) + cam->conf->target_dir.length() + 10; + len = (int)(strlen(tmp) + cam->conf->target_dir.length() + 10); cam->movie_norm->full_nm = (char*)mymalloc(len); if (mystreq(container, "test")) { retcd = snprintf(cam->movie_motion->full_nm, len, "%s/%s_%sm" @@ -1781,12 +1781,12 @@ int movie_init_motion(ctx_dev *cam, struct timespec *ts1) , cam->conf->target_dir.c_str(), tmp); } - len = cam->conf->target_dir.length() + 10; + len = (int)cam->conf->target_dir.length() + 10; cam->movie_norm->movie_dir = (char*)mymalloc(len); retcd = snprintf(cam->movie_norm->movie_dir,len,"%s" ,cam->conf->target_dir.c_str()); - len = strlen(tmp) + 10; + len = (int)strlen(tmp) + 10; cam->movie_norm->movie_nm = (char*)mymalloc(len); retcd = snprintf(cam->movie_norm->movie_nm, len, "%s", tmp); @@ -1837,17 +1837,17 @@ int movie_init_timelapse(ctx_dev *cam, struct timespec *ts1) , cam->conf->timelapse_filename.c_str(), ts1, NULL, 0); /* The increment of 10 is to allow for the extension and other chars*/ - len = strlen(tmp) + cam->conf->target_dir.length() + 10; + len = (int)(strlen(tmp) + cam->conf->target_dir.length() + 10); cam->movie_norm->full_nm = (char*)mymalloc(len); retcd = snprintf(cam->movie_timelapse->full_nm, len, "%s/%s" , cam->conf->target_dir.c_str(), tmp); - len = cam->conf->target_dir.length() + 10; + len = (int)cam->conf->target_dir.length() + 10; cam->movie_norm->movie_dir = (char*)mymalloc(len); retcd = snprintf(cam->movie_norm->movie_dir,len,"%s" ,cam->conf->target_dir.c_str()); - len = strlen(tmp) + 10; + len = (int)strlen(tmp) + 10; cam->movie_norm->movie_nm = (char*)mymalloc(len); retcd = snprintf(cam->movie_norm->movie_nm, len, "%s", tmp); diff --git a/src/netcam.cpp b/src/netcam.cpp index d740d3e2..0d277f24 100644 --- a/src/netcam.cpp +++ b/src/netcam.cpp @@ -50,14 +50,14 @@ static void netcam_check_buffsize(netcam_buff_ptr buff, size_t numbytes) return; } - min_size_to_alloc = numbytes - (buff->size - buff->used); + min_size_to_alloc = (int)(numbytes - (buff->size - buff->used)); real_alloc = ((min_size_to_alloc / NETCAM_BUFFSIZE) * NETCAM_BUFFSIZE); if ((min_size_to_alloc - real_alloc) > 0) { real_alloc += NETCAM_BUFFSIZE; } - new_size = buff->size + real_alloc; + new_size = (int)(buff->size + real_alloc); buff->ptr =(char*) myrealloc(buff->ptr, new_size, "netcam_check_buf_size"); @@ -362,7 +362,8 @@ static void netcam_pktarray_resize(ctx_dev *cam, bool is_highres) /* 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); + newsize =(int)(((idnbr_first - idnbr_last) * 1 ) + + ((netcam->idnbr - idnbr_last ) * 2)); if (newsize < 30) { newsize = 30; } @@ -1296,7 +1297,7 @@ static int netcam_read_image(ctx_netcam *netcam) netcam_free_pkt(netcam); if (netcam->format_context->streams[netcam->video_stream_index]->avg_frame_rate.den > 0) { - netcam->src_fps = ( + netcam->src_fps = (int)( (netcam->format_context->streams[netcam->video_stream_index]->avg_frame_rate.num / netcam->format_context->streams[netcam->video_stream_index]->avg_frame_rate.den) + 0.5); @@ -1544,7 +1545,7 @@ static void netcam_set_parms (ctx_dev *cam, ctx_netcam *netcam ) for (indx = 0; indx < netcam->params->params_count; indx++) { if (mystreq(netcam->params->params_array[indx].param_name,"decoder")) { - val_len = strlen(netcam->params->params_array[indx].param_value) + 1; + val_len = (int)strlen(netcam->params->params_array[indx].param_value) + 1; netcam->decoder_nm = (char*)mymalloc(val_len); snprintf(netcam->decoder_nm, val_len , "%s",netcam->params->params_array[indx].param_value); diff --git a/src/picture.cpp b/src/picture.cpp index 8710720c..941b6366 100644 --- a/src/picture.cpp +++ b/src/picture.cpp @@ -233,9 +233,9 @@ static void pic_save_ppm(FILE *picture, unsigned char *image, int width, int hei b = 255; } - rgb[0] = b; - rgb[1] = g; - rgb[2] = r; + rgb[0] = (unsigned char)b; + rgb[1] = (unsigned char)g; + rgb[2] = (unsigned char)r; l++; if (x%2 != 0) { @@ -433,7 +433,7 @@ unsigned char *pic_load_pgm(FILE *picture, int width, int height) } for (x = 0; x < mask_width; x++) { - image[y * mask_width + x] = (int)image[y * mask_width + x] * 255 / maxval; + image[y * mask_width + x] = (unsigned char)((int)image[y * mask_width + x] * 255 / maxval); } } diff --git a/src/sound.cpp b/src/sound.cpp index 97640f61..eadc3407 100644 --- a/src/sound.cpp +++ b/src/sound.cpp @@ -340,10 +340,11 @@ static void snd_alsa_start(ctx_dev *snd) snd_pcm_hw_params_t *hw_params; snd_pcm_uframes_t frames_per; snd_pcm_format_t actl_sndfmt; - unsigned int actl_rate; + unsigned int actl_rate, smpl_rate; int retcd; frames_per = info->frames; + smpl_rate = (unsigned int)info->sample_rate; retcd = snd_pcm_open(&alsa->pcm_dev , snd->conf->snd_device.c_str(), SND_PCM_STREAM_CAPTURE, 0); @@ -394,7 +395,7 @@ static void snd_alsa_start(ctx_dev *snd) } retcd = snd_pcm_hw_params_set_rate_near(alsa->pcm_dev - , hw_params, &info->sample_rate, 0); + , hw_params, &smpl_rate, 0); if (retcd < 0) { MOTPLS_LOG(ERR, TYPE_ALL, NO_ERRNO , _("error: snd_pcm_hw_params_set_rate_near(%s)") @@ -484,7 +485,7 @@ static void snd_alsa_start(ctx_dev *snd) /*************************************************************/ /** allocate and initialize the sound buffers */ /*************************************************************/ - info->frames = frames_per; + info->frames = (int)frames_per; info->buffer_size = info->frames * 2; info->buffer = (int16_t*)mymalloc(info->buffer_size * sizeof(int16_t)); memset(info->buffer, 0x00, info->buffer_size * sizeof(int16_t)); @@ -527,13 +528,13 @@ static void snd_alsa_capture(ctx_dev *snd) #ifdef HAVE_ALSA ctx_snd_info *info = snd->snd_info; ctx_snd_alsa *alsa = snd->snd_alsa; - int retcd; + long int retcd; retcd = snd_pcm_readi(alsa->pcm_dev, info->buffer, info->frames); if (retcd != info->frames) { MOTPLS_LOG(ERR, TYPE_ALL, NO_ERRNO , _("error: read from audio interface failed (%s)") - , snd_strerror (retcd)); + , snd_strerror((int)retcd)); snd->device_status = STATUS_CLOSED; snd->finish_dev = true; snd->restart_dev = false; @@ -567,8 +568,8 @@ static void snd_pulse_init(ctx_dev *snd) ctx_snd_info *info = snd->snd_info; const pa_sample_spec specs = { .format = PA_SAMPLE_S16LE, - .rate = info->sample_rate, - .channels = info->channels + .rate = (uint32_t)info->sample_rate, + .channels = (uint8_t)info->channels }; int errcd; @@ -750,14 +751,14 @@ static void slp_init(ctx_dev *snd) static void snd_check_alerts(ctx_dev *snd) { ctx_snd_info *info = snd->snd_info; - float freq_value; - int indx, chkval, chkcnt; - float pMaxIntensity; - int pMaxBinIndex; - float pRealNbr; - float pImaginaryNbr; - float pIntensity; - bool trigger; + double freq_value; + int indx, chkval, chkcnt; + double pMaxIntensity; + int pMaxBinIndex; + double pRealNbr; + double pImaginaryNbr; + double pIntensity; + bool trigger; std::list::iterator it; struct timespec trig_ts; diff --git a/src/video_common.cpp b/src/video_common.cpp index 9bca8fbe..d110e5b6 100644 --- a/src/video_common.cpp +++ b/src/video_common.cpp @@ -127,12 +127,14 @@ int vid_sonix_decompress(unsigned char *img_dst, unsigned char *img_src, int wid /* First two pixels in first two rows are stored as raw 8-bit. */ if (row < 2) { addr = img_src + (bitpos >> 3); - code = (addr[0] << (bitpos & 7)) | (addr[1] >> (8 - (bitpos & 7))); + code =(unsigned char)( (addr[0] << (bitpos & 7)) | + (addr[1] >> (8 - (bitpos & 7)))); bitpos += 8; *img_dst++ = code; addr = img_src + (bitpos >> 3); - code = (addr[0] << (bitpos & 7)) | (addr[1] >> (8 - (bitpos & 7))); + code = (unsigned char)((addr[0] << (bitpos & 7)) | + (addr[1] >> (8 - (bitpos & 7)))); bitpos += 8; *img_dst++ = code; @@ -142,7 +144,8 @@ int vid_sonix_decompress(unsigned char *img_dst, unsigned char *img_src, int wid while (col < width) { /* Get bitcode from bitstream. */ addr = img_src + (bitpos >> 3); - code = (addr[0] << (bitpos & 7)) | (addr[1] >> (8 - (bitpos & 7))); + code =(unsigned char)((addr[0] << (bitpos & 7)) | + (addr[1] >> (8 - (bitpos & 7)))); /* Update bit position. */ bitpos += table[code].len; @@ -169,7 +172,7 @@ int vid_sonix_decompress(unsigned char *img_dst, unsigned char *img_src, int wid } else if (val > 255) { *img_dst++ = 255; } else { - *img_dst++ = val; + *img_dst++ =(unsigned char)val; } col++; } @@ -201,56 +204,70 @@ void vid_bayer2rgb24(unsigned char *img_dst, unsigned char *img_src, long int wi if ((i & 1) == 0) { /* B */ if ((i > width) && ((i % width) > 0)) { - *scanpt++ = *rawpt; /* B */ - *scanpt++ = (*(rawpt - 1) + *(rawpt + 1) + - *(rawpt + width) + *(rawpt - width)) / 4; /* G */ - *scanpt++ = (*(rawpt - width - 1) + *(rawpt - width + 1) + - *(rawpt + width - 1) + *(rawpt + width + 1)) / 4; /* R */ + *scanpt++ = (unsigned char)(*rawpt); /* B */ + *scanpt++ = (unsigned char)((*(rawpt - 1) + + *(rawpt + 1) + + *(rawpt + width) + + *(rawpt - width)) / 4); /* G */ + *scanpt++ = (unsigned char)((*(rawpt - width - 1) + + *(rawpt - width + 1) + + *(rawpt + width - 1) + + *(rawpt + width + 1)) / 4); /* R */ } else { /* First line or left column. */ - *scanpt++ = *rawpt; /* B */ - *scanpt++ = (*(rawpt + 1) + *(rawpt + width)) / 2; /* G */ - *scanpt++ = *(rawpt + width + 1); /* R */ + *scanpt++ = (unsigned char)(*rawpt); /* B */ + *scanpt++ = (unsigned char)((*(rawpt + 1) + + *(rawpt + width)) / 2); /* G */ + *scanpt++ = (unsigned char)(*(rawpt + width + 1)); /* R */ } } else { /* (B)G */ if ((i > width) && ((i % width) < (width - 1))) { - *scanpt++ = (*(rawpt - 1) + *(rawpt + 1)) / 2; /* B */ - *scanpt++ = *rawpt; /* G */ - *scanpt++ = (*(rawpt + width) + *(rawpt - width)) / 2; /* R */ + *scanpt++ = (unsigned char)((*(rawpt - 1) + + *(rawpt + 1)) / 2); /* B */ + *scanpt++ = (unsigned char)(*rawpt); /* G */ + *scanpt++ = (unsigned char)((*(rawpt + width) + + *(rawpt - width)) / 2); /* R */ } else { /* First line or right column. */ - *scanpt++ = *(rawpt - 1); /* B */ - *scanpt++ = *rawpt; /* G */ - *scanpt++ = *(rawpt + width); /* R */ + *scanpt++ = (unsigned char)(*(rawpt - 1)); /* B */ + *scanpt++ = (unsigned char)(*rawpt); /* G */ + *scanpt++ = (unsigned char)(*(rawpt + width)); /* R */ } } } else { if ((i & 1) == 0) { /* G(R) */ if ((i < (width * (height - 1))) && ((i % width) > 0)) { - *scanpt++ = (*(rawpt + width) + *(rawpt - width)) / 2; /* B */ - *scanpt++ = *rawpt; /* G */ - *scanpt++ = (*(rawpt - 1) + *(rawpt + 1)) / 2; /* R */ + *scanpt++ =(unsigned char)( (*(rawpt + width) + + *(rawpt - width)) / 2); /* B */ + *scanpt++ =(unsigned char)( *rawpt); /* G */ + *scanpt++ =(unsigned char)( (*(rawpt - 1) + + *(rawpt + 1)) / 2); /* R */ } else { /* Bottom line or left column. */ - *scanpt++ = *(rawpt - width); /* B */ - *scanpt++ = *rawpt; /* G */ - *scanpt++ = *(rawpt + 1); /* R */ + *scanpt++ = (unsigned char)(*(rawpt - width)); /* B */ + *scanpt++ = (unsigned char)(*rawpt); /* G */ + *scanpt++ = (unsigned char)(*(rawpt + 1)); /* R */ } } else { /* R */ if (i < (width * (height - 1)) && ((i % width) < (width - 1))) { - *scanpt++ = (*(rawpt - width - 1) + *(rawpt - width + 1) + - *(rawpt + width - 1) + *(rawpt + width + 1)) / 4; /* B */ - *scanpt++ = (*(rawpt - 1) + *(rawpt + 1) + - *(rawpt - width) + *(rawpt + width)) / 4; /* G */ - *scanpt++ = *rawpt; /* R */ + *scanpt++ = (unsigned char)( (*(rawpt - width - 1) + + *(rawpt - width + 1) + + *(rawpt + width - 1) + + *(rawpt + width + 1)) / 4); /* B */ + *scanpt++ = (unsigned char)((*(rawpt - 1) + + *(rawpt + 1) + + *(rawpt - width) + + *(rawpt + width)) / 4); /* G */ + *scanpt++ = (unsigned char)(*rawpt); /* R */ } else { /* Bottom line or right column. */ - *scanpt++ = *(rawpt - width - 1); /* B */ - *scanpt++ = (*(rawpt - 1) + *(rawpt - width)) / 2; /* G */ - *scanpt++ = *rawpt; /* R */ + *scanpt++ = (unsigned char)(*(rawpt - width - 1)); /* B */ + *scanpt++ = (unsigned char)((*(rawpt - 1) + + *(rawpt - width)) / 2); /* G */ + *scanpt++ = (unsigned char)(*rawpt); /* R */ } } } @@ -278,11 +295,11 @@ void vid_yuv422to420p(unsigned char *img_dst, unsigned char *img_src, int width, dest2 = dest + (width * height) / 4; for (i = height / 2; i > 0; i--) { for (j = width / 2; j > 0; j--) { - *dest = ((int) *src + (int) *src2) / 2; + *dest = (unsigned char)(((int) *src + (int) *src2) / 2); src += 2; src2 += 2; dest++; - *dest2 = ((int) *src + (int) *src2) / 2; + *dest2 = (unsigned char)(((int) *src + (int) *src2) / 2); src += 2; src2 += 2; dest2++; @@ -316,12 +333,12 @@ void vid_yuv422pto420p(unsigned char *img_dst, unsigned char *img_src, int width src_v2 = src_v + (width/2); for (j = 0; j < (width / 2); j++) { - *dest = ((int) *src_u + (int) *src_u2) / 2; + *dest = (unsigned char)(((int) *src_u + (int) *src_u2) / 2); src_u ++; src_u2++; dest++; - *dest2 = ((int) *src_v + (int) *src_v2) / 2; + *dest2 = (unsigned char)(((int) *src_v + (int) *src_v2) / 2); src_v ++; src_v2++; dest2++; @@ -389,15 +406,15 @@ static void vid_rgb_bgr(unsigned char *img_dst, unsigned char *img_src for (loop = 0; loop < height; loop++) { for (i = 0; i < width; i += 2) { - *y++ = (9796 ** r + 19235 ** g + 3736 ** b) >> 15; - *u += ((-4784 ** r - 9437 ** g + 14221 ** b) >> 17) + 32; - *v += ((20218 ** r - 16941 ** g - 3277 ** b) >> 17) + 32; + *y++ = (unsigned char)((9796 ** r + 19235 ** g + 3736 ** b) >> 15); + *u += (unsigned char)(((-4784 ** r - 9437 ** g + 14221 ** b) >> 17) + 32); + *v += (unsigned char)(((20218 ** r - 16941 ** g - 3277 ** b) >> 17) + 32); r += 3; g += 3; b += 3; - *y++ = (9796 ** r + 19235 ** g + 3736 ** b) >> 15; - *u += ((-4784 ** r - 9437 ** g + 14221 ** b) >> 17) + 32; - *v += ((20218 ** r - 16941 ** g - 3277 ** b) >> 17) + 32; + *y++ = (unsigned char)((9796 ** r + 19235 ** g + 3736 ** b) >> 15); + *u += (unsigned char)(((-4784 ** r - 9437 ** g + 14221 ** b) >> 17) + 32); + *v += (unsigned char)(((20218 ** r - 16941 ** g - 3277 ** b) >> 17) + 32); r += 3; g += 3; b += 3; @@ -458,7 +475,7 @@ int vid_mjpegtoyuv420p(unsigned char *img_dst, unsigned char *img_src, int width } memmove(img_src, img_src + soi_pos, size - soi_pos); - size -= soi_pos; + size -= (unsigned int)soi_pos; ret = jpgutl_decode_jpeg(img_src,size, width, height, img_dst); @@ -491,9 +508,9 @@ void vid_y10torgb24(unsigned char *img_dst, unsigned char *img_src, int width, i for (src_x = 0, dst_x = 0; dst_x < src_size[0]; src_x++, dst_x++) { a = (img_src[src_y*src_stride + src_x*2+0] | (img_src[src_y*src_stride + src_x*2+1] << 8)) >> shift; - img_dst[dst_y*rgb_stride+3*dst_x+0] = a; - img_dst[dst_y*rgb_stride+3*dst_x+1] = a; - img_dst[dst_y*rgb_stride+3*dst_x+2] = a; + img_dst[dst_y*rgb_stride+3*dst_x+0] = (unsigned char)a; + img_dst[dst_y*rgb_stride+3*dst_x+1] = (unsigned char)a; + img_dst[dst_y*rgb_stride+3*dst_x+2] = (unsigned char)a; } } } diff --git a/src/video_loopback.cpp b/src/video_loopback.cpp index 4bb481f0..e1bfe6b8 100644 --- a/src/video_loopback.cpp +++ b/src/video_loopback.cpp @@ -90,7 +90,7 @@ static int vlp_open_vidpipe(void) } if ((fd = open(buffer, O_RDONLY|O_CLOEXEC)) >= 0) { - if ((len = read(fd, buffer, sizeof(buffer)-1)) < 0) { + if ((len = (int)read(fd, buffer, sizeof(buffer)-1)) < 0) { close(fd); continue; } @@ -232,7 +232,7 @@ int vlp_putpipe(int dev, unsigned char *image, int imgsize) { #if (defined(HAVE_V4L2)) && (!defined(BSD)) - return write(dev, image, imgsize); + return (int)write(dev, image, imgsize); #else (void)dev; (void)image; diff --git a/src/video_v4l2.cpp b/src/video_v4l2.cpp index d3e1229d..3cb6da05 100644 --- a/src/video_v4l2.cpp +++ b/src/video_v4l2.cpp @@ -492,7 +492,7 @@ static void v4l2_set_frequency(ctx_dev *cam) memset(&freq, 0, sizeof(struct v4l2_frequency)); freq.tuner = v4l2cam->device_tuner; freq.type = V4L2_TUNER_ANALOG_TV; - freq.frequency = (spec / 1000) * 16; + freq.frequency = (unsigned int)((spec / 1000) * 16); if (xioctl(v4l2cam, VIDIOC_S_FREQUENCY, &freq) == -1) { MOTPLS_LOG(ERR, TYPE_VIDEO, SHOW_ERRNO diff --git a/src/webu.cpp b/src/webu.cpp index 9faf634b..6cc9118c 100644 --- a/src/webu.cpp +++ b/src/webu.cpp @@ -559,7 +559,7 @@ static void webu_mhd_auth_parse(ctx_webui *webui) myfree(&webui->auth_user); myfree(&webui->auth_pass); - auth_len = webui->motapp->conf->webcontrol_authentication.length(); + auth_len = (int)webui->motapp->conf->webcontrol_authentication.length(); col_pos =(char*) strstr(webui->motapp->conf->webcontrol_authentication.c_str() ,":"); if (col_pos == NULL) { webui->auth_user = (char*)mymalloc(auth_len+1); @@ -582,7 +582,7 @@ static mhdrslt webu_mhd_auth(ctx_webui *webui) { unsigned int rand1,rand2; - srand(time(NULL)); + srand((unsigned int)time(NULL)); rand1 = (unsigned int)(42000000.0 * rand() / (RAND_MAX + 1.0)); rand2 = (unsigned int)(42000000.0 * rand() / (RAND_MAX + 1.0)); snprintf(webui->auth_opaque, WEBUI_LEN_PARM, "%08x%08x", rand1, rand2); @@ -1195,7 +1195,7 @@ static void webu_mhd_opts_localhost(ctx_mhdstart *mhdst) if (mhdst->ipv6) { memset(&mhdst->lpbk_ipv6, 0, sizeof(struct sockaddr_in6)); mhdst->lpbk_ipv6.sin6_family = AF_INET6; - mhdst->lpbk_ipv6.sin6_port = htons(mhdst->motapp->conf->webcontrol_port); + mhdst->lpbk_ipv6.sin6_port = htons((uint16_t)mhdst->motapp->conf->webcontrol_port); mhdst->lpbk_ipv6.sin6_addr = in6addr_loopback; mhdst->mhd_ops[mhdst->mhd_opt_nbr].option = MHD_OPTION_SOCK_ADDR; @@ -1206,7 +1206,7 @@ static void webu_mhd_opts_localhost(ctx_mhdstart *mhdst) } else { memset(&mhdst->lpbk_ipv4, 0, sizeof(struct sockaddr_in)); mhdst->lpbk_ipv4.sin_family = AF_INET; - mhdst->lpbk_ipv4.sin_port = htons(mhdst->motapp->conf->webcontrol_port); + mhdst->lpbk_ipv4.sin_port = htons((uint16_t)mhdst->motapp->conf->webcontrol_port); mhdst->lpbk_ipv4.sin_addr.s_addr = htonl(INADDR_LOOPBACK); mhdst->mhd_ops[mhdst->mhd_opt_nbr].option = MHD_OPTION_SOCK_ADDR; @@ -1351,7 +1351,7 @@ static void webu_init_webcontrol(ctx_motapp *motapp) mhdst.ipv6 = motapp->conf->webcontrol_ipv6; /* Set the rand number for webcontrol digest if needed */ - srand(time(NULL)); + srand((unsigned int)time(NULL)); randnbr = (unsigned int)(42000000.0 * rand() / (RAND_MAX + 1.0)); snprintf(motapp->webcontrol_digest_rand ,sizeof(motapp->webcontrol_digest_rand),"%d",randnbr); @@ -1363,7 +1363,7 @@ static void webu_init_webcontrol(ctx_motapp *motapp) motapp->webcontrol_daemon = MHD_start_daemon ( mhdst.mhd_flags - , motapp->conf->webcontrol_port + , (uint16_t)motapp->conf->webcontrol_port , NULL, NULL , &webu_answer, motapp->cam_list , MHD_OPTION_ARRAY, mhdst.mhd_ops