diff --git a/src/alsa_common.h b/src/alsa_common.h index e1f99453a..23c93eec1 100644 --- a/src/alsa_common.h +++ b/src/alsa_common.h @@ -3,7 +3,7 @@ * @author Martin Pulec */ /* - * Copyright (c) 2015 CESNET, z. s. p. o. + * Copyright (c) 2015-2019 CESNET, z. s. p. o. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -79,7 +79,9 @@ static inline void audio_alsa_probe(struct device_info **available_devices, } strcpy((*available_devices)[*count].id, "alsa:"); - strcat((*available_devices)[*count].id, id); + strncat((*available_devices)[*count].id, id, + sizeof (*available_devices)[*count].id - + strlen((*available_devices)[*count].id) - 1); free(id); char *name = snd_device_name_get_hint(*it, "DESC"); @@ -88,11 +90,17 @@ static inline void audio_alsa_probe(struct device_info **available_devices, char *newline = strchr(tok, '\n'); if(newline){ *newline = '\0'; - strcat((*available_devices)[*count].name, tok); - strcat((*available_devices)[*count].name, " - "); + strncat((*available_devices)[*count].name, tok, + sizeof (*available_devices)[*count].name - + strlen((*available_devices)[*count].name) - 1); + strncat((*available_devices)[*count].name, " - ", + sizeof (*available_devices)[*count].name - + strlen((*available_devices)[*count].name) - 1); tok = newline + 1; } else { - strcat((*available_devices)[*count].name, tok); + strncat((*available_devices)[*count].name, tok, + sizeof (*available_devices)[*count].name - + strlen((*available_devices)[*count].name) - 1); tok = NULL; } } diff --git a/src/audio/audio.cpp b/src/audio/audio.cpp index e9f0f0b4c..6eeaffcdf 100644 --- a/src/audio/audio.cpp +++ b/src/audio/audio.cpp @@ -53,6 +53,7 @@ #include "config_win32.h" #endif +#include #include #include #include @@ -156,8 +157,8 @@ struct state_audio { struct tx *tx_session = nullptr; - pthread_t audio_sender_thread_id, - audio_receiver_thread_id; + pthread_t audio_sender_thread_id{}, + audio_receiver_thread_id{}; bool audio_sender_thread_started = false, audio_receiver_thread_started = false; @@ -295,10 +296,11 @@ struct state_audio * audio_cfg_init(struct module *parent, const char *addrs, in s->requested_encryption = strdup(encryption); } - assert(addrs && strlen(addrs) > 0); + assert(addrs != nullptr); tmp = strdup(addrs); s->audio_participants = pdb_init(audio_delay); addr = strtok_r(tmp, ",", &unused); + assert(addr != nullptr); s->audio_network_parameters.addr = strdup(addr); s->audio_network_parameters.recv_port = recv_port; @@ -841,8 +843,8 @@ static struct response *audio_sender_process_message(struct state_audio *s, stru return new_response(RESPONSE_INT_SERV_ERR, NULL); } else { rtp_done(old_devices); - log_msg(LOG_LEVEL_NOTICE, "[control] Audio: changed SSRC from 0x%08lx to " - "0x%08lx.\n", old_ssrc, rtp_my_ssrc(s->audio_network_device)); + log_msg(LOG_LEVEL_NOTICE, "[control] Audio: changed SSRC from 0x%08" PRIx32 " to " + "0x%08" PRIx32 ".\n", old_ssrc, rtp_my_ssrc(s->audio_network_device)); } } break; diff --git a/src/audio/audio_capture.c b/src/audio/audio_capture.c index 405d53007..3dac3e101 100644 --- a/src/audio/audio_capture.c +++ b/src/audio/audio_capture.c @@ -140,6 +140,7 @@ unsigned int audio_capture_get_vidcap_flags(const char *const_device_name) char *tmp = strdup(const_device_name); char *save_ptr = NULL; char *device_name = strtok_r(tmp, ":", &save_ptr); + assert(device_name != NULL); unsigned int ret; if(strcasecmp(device_name, "embedded") == 0) { diff --git a/src/audio/playback/alsa.c b/src/audio/playback/alsa.c index 6ef52b518..51d61a2fc 100644 --- a/src/audio/playback/alsa.c +++ b/src/audio/playback/alsa.c @@ -144,7 +144,7 @@ static long get_sched_latency_ns(void) const char *proc_file = "/proc/sys/kernel/sched_latency_ns"; int fd = open(proc_file, O_RDONLY); - if (!fd) { + if (fd == -1) { return -1; } @@ -572,7 +572,7 @@ static int audio_play_alsa_reconfigure(void *state, struct audio_desc desc) log_msg(LOG_LEVEL_WARNING, MOD_NAME "Warning: cannot set period time: %s\n", snd_strerror(rc)); } else { - log_msg(LOG_LEVEL_INFO, MOD_NAME "Period size: %u frames (%lf ms)\n", s->period_size, (double) s->period_size / desc.sample_rate * 1000); + log_msg(LOG_LEVEL_INFO, MOD_NAME "Period size: %lu frames (%lf ms)\n", s->period_size, (double) s->period_size / desc.sample_rate * 1000); } unsigned int buf_len; @@ -616,7 +616,7 @@ static int audio_play_alsa_reconfigure(void *state, struct audio_desc desc) #else audio_buffer_destroy(s->buf); s->audio_buf_len_ms = get_commandline_param("low-latency-audio") ? 5 : s->sched_latency_ms * 2; - log_msg(LOG_LEVEL_INFO, "[ALSA play.] Setting audio buffer length: %d ms\n", s->audio_buf_len_ms); + log_msg(LOG_LEVEL_INFO, "[ALSA play.] Setting audio buffer length: %ld ms\n", s->audio_buf_len_ms); if (get_commandline_param("audio-buffer-len")) { s->audio_buf_len_ms = atoi(get_commandline_param("audio-buffer-len")); } diff --git a/src/capture_filter/logo.cpp b/src/capture_filter/logo.cpp index 0ac833d46..0c945641c 100644 --- a/src/capture_filter/logo.cpp +++ b/src/capture_filter/logo.cpp @@ -56,8 +56,8 @@ using namespace std; struct state_capture_filter_logo { unique_ptr logo; - unsigned int width, height; - int x, y; + unsigned int width{}, height{}; + int x{}, y{}; }; static int init(struct module *parent, const char *cfg, void **state); diff --git a/src/control_socket.cpp b/src/control_socket.cpp index 473f775b9..26df90712 100644 --- a/src/control_socket.cpp +++ b/src/control_socket.cpp @@ -236,7 +236,7 @@ int control_init(int port, int connection_type, struct control_state **state, st } else { if (force_ip_version == 6) { log_msg(LOG_LEVEL_ERROR, "Control socket: IPv6 unimplemented in client mode!\n"); - return -1; + goto error; } s->socket_fd = socket(AF_INET, SOCK_STREAM, 0); assert(s->socket_fd != INVALID_SOCKET); @@ -252,7 +252,7 @@ int control_init(int port, int connection_type, struct control_state **state, st if(err) { fprintf(stderr, "Unable to get address: %s\n", gai_strerror(err)); - return -1; + goto error; } bool connected = false; @@ -268,21 +268,22 @@ int control_init(int port, int connection_type, struct control_state **state, st if(!connected) { fprintf(stderr, "Unable to connect to localhost:%d\n", s->network_port); - delete s; - return -1; + goto error; } } -error: - if (s->socket_fd == INVALID_SOCKET) { - delete s; - return -1; - } module_register(&s->mod, root_module); *state = s; return 0; + +error: + if (s->socket_fd != INVALID_SOCKET) { + CLOSESOCKET(s->socket_fd); + } + delete s; + return -1; } void control_start(struct control_state *s) @@ -708,7 +709,9 @@ static void set_socket_nonblock(fd_t fd) { unsigned long ul; ioctlsocket(fd, FIONBIO, &ul); #else - fcntl(fd, F_SETFL, O_NONBLOCK); + if (fcntl(fd, F_SETFL, O_NONBLOCK) == -1) { + perror("fcntl"); + } #endif } diff --git a/src/debug.cpp b/src/debug.cpp index 1e01e6690..5d7def04e 100644 --- a/src/debug.cpp +++ b/src/debug.cpp @@ -44,9 +44,11 @@ #include "config.h" #include "config_unix.h" #include "config_win32.h" + +#include + #include "compat/platform_time.h" #include "debug.h" - #include "host.h" #include "rang.hpp" @@ -128,7 +130,7 @@ void debug_dump(void *lp, int len) char stuffBuff[10]; char tmpBuf[10]; - _dprintf("Dump of %ld=%lx bytes\n", len, len); + _dprintf("Dump of %d=%x bytes\n", len, len); start = 0L; while (start < len) { /* start line with pointer position key */ @@ -158,12 +160,6 @@ void debug_dump(void *lp, int len) strcat(Buff, " "); } - /* fill out incomplete lines */ - for (; j < 16; j++) { - strcat(Buff, " "); - if (j == 7) - strcat(Buff, " "); - } strcat(Buff, " "); /* display each character as character value */ diff --git a/src/debug.h b/src/debug.h index 44e9a9a9c..3301b2330 100644 --- a/src/debug.h +++ b/src/debug.h @@ -87,7 +87,9 @@ public: std::cerr << style << color; if (log_level >= LOG_LEVEL_VERBOSE) { unsigned long long time_ms = time_since_epoch_in_ms(); - std::cerr << "[" << std::fixed << std::setprecision(3) << time_ms / 1000.0 << "] "; + auto flags = std::cerr.flags(); + auto precision = std::cerr.precision(); + std::cerr << "[" << std::fixed << std::setprecision(3) << time_ms / 1000.0 << "] " << flags << precision; } return std::cerr; diff --git a/src/deltacast_common.h b/src/deltacast_common.h index 56d5dc15d..fe50d9036 100644 --- a/src/deltacast_common.h +++ b/src/deltacast_common.h @@ -216,7 +216,7 @@ static void print_available_delta_boards() { Result = VHD_GetBoardProperty(BoardHandle, VHD_CORE_BP_IS_BIDIR, (ULONG*)&IsBiDir); if (Result != VHDERR_NOERROR) { - log_msg(LOG_LEVEL_ERROR, "[DELTACAST] ERROR: Cannot check whether board channels are bidirectional. Result = 0x08" PRIX32 "\n", Result); + log_msg(LOG_LEVEL_ERROR, "[DELTACAST] ERROR: Cannot check whether board channels are bidirectional. Result = 0x%08" PRIX32 "\n", Result); return false; } diff --git a/src/export.c b/src/export.c index 87a7ce015..39140e4f7 100644 --- a/src/export.c +++ b/src/export.c @@ -120,7 +120,6 @@ static bool enable_export(struct exporter *s) s->exporting = true; - pthread_mutex_unlock(&s->lock); return true; error: diff --git a/src/hd-rum-translator/hd-rum-recompress.cpp b/src/hd-rum-translator/hd-rum-recompress.cpp index bc438683f..20746f902 100644 --- a/src/hd-rum-translator/hd-rum-recompress.cpp +++ b/src/hd-rum-translator/hd-rum-recompress.cpp @@ -44,6 +44,11 @@ #include "config_win32.h" #endif +#include +#include +#include + + #include "hd-rum-translator/hd-rum-recompress.h" #include "debug.h" @@ -52,9 +57,6 @@ #include "video_rxtx/ultragrid_rtp.h" -#include -#include - using namespace std; struct state_recompress { @@ -132,7 +134,7 @@ void recompress_process_async(void *state, shared_ptr frame) double seconds = chrono::duration_cast(now - s->t0).count() / 1000000.0; if(seconds > 5) { double fps = s->frames / seconds; - log_msg(LOG_LEVEL_INFO, "[0x%08lx->%s:%d:0x%08lx] %d frames in %g seconds = %g FPS\n", + log_msg(LOG_LEVEL_INFO, "[0x%08" PRIx32 "->%s:%d:0x%08" PRIx32 "] %d frames in %g seconds = %g FPS\n", frame->ssrc, s->host.c_str(), s->tx_port, s->video_rxtx->get_ssrc(), diff --git a/src/hd-rum-translator/hd-rum-translator.cpp b/src/hd-rum-translator/hd-rum-translator.cpp index 23314a39f..f1c11cf78 100644 --- a/src/hd-rum-translator/hd-rum-translator.cpp +++ b/src/hd-rum-translator/hd-rum-translator.cpp @@ -397,7 +397,7 @@ static void *writer(void *arg) } else { hd_rum_decompress_append_port(s->decompress, rep->recompress); hd_rum_decompress_set_active(s->decompress, rep->recompress, true); - log_msg(LOG_LEVEL_NOTICE, "Created new transcoding output port %s:%d:0x%08lx.\n", host, tx_port, recompress_get_ssrc(rep->recompress)); + log_msg(LOG_LEVEL_NOTICE, "Created new transcoding output port %s:%d:0x%08" PRIx32 ".\n", host, tx_port, recompress_get_ssrc(rep->recompress)); } } else { rep->type = replica::type_t::USE_SOCK; diff --git a/src/host.cpp b/src/host.cpp index 4ddd5acc7..20fe63f61 100644 --- a/src/host.cpp +++ b/src/host.cpp @@ -256,6 +256,8 @@ void print_capabilities(struct module *root, bool use_vidcap) } } + auto precision = cout.precision(); + // compressions cout << "[cap] Compressions:" << endl; auto compressions = get_libraries_for_class(LIBRARY_CLASS_VIDEO_COMPRESS, VIDEO_COMPRESS_ABI_VERSION); @@ -347,6 +349,8 @@ void print_capabilities(struct module *root, bool use_vidcap) for(const auto& codec : codecs){ cout << "[cap][audio_compress] " << codec.first << std::endl; } + + cout << precision; } void print_version() @@ -451,7 +455,8 @@ void print_pixel_formats(void) { } tag = codec_is_a_rgb(c) ? 'R' : 'Y'; - cout << " " << style::bold << left << setw(12) << get_codec_name(c) << style::reset << setw(0) << " " << tag << " " << setw(2) << get_bits_per_component(c) << setw(0) << " " << get_codec_name_long(c) << "\n"; + auto width = cout.width(); + cout << " " << style::bold << left << setw(12) << get_codec_name(c) << style::reset << setw(0) << " " << tag << " " << setw(2) << get_bits_per_component(c) << setw(0) << " " << get_codec_name_long(c) << setw(width) << "\n"; } } diff --git a/src/jack_common.h b/src/jack_common.h index c05577269..fe4070c89 100644 --- a/src/jack_common.h +++ b/src/jack_common.h @@ -41,6 +41,7 @@ #include #include +#include "debug.h" #include "types.h" static inline struct device_info *audio_jack_probe(const char *client_name, @@ -81,6 +82,11 @@ static inline struct device_info *audio_jack_probe(const char *client_name, ++channel_count; name = strtok_r(item, "_", &save_ptr); + if (name == NULL) { // shouldn't happen + log_msg(LOG_LEVEL_ERROR, "Incorrect JACK name: %s!\n", ports[i]); + free(item); + continue; + } if(last_name && strcmp(last_name, name) != 0) { sprintf(available_devices[*count].name, "jack:%s (%d channels)", last_name, channel_count); sprintf(available_devices[*count].id, "jack:%s", last_name); diff --git a/src/keyboard_control.cpp b/src/keyboard_control.cpp index e5ae1f1da..54a22c89e 100644 --- a/src/keyboard_control.cpp +++ b/src/keyboard_control.cpp @@ -53,6 +53,7 @@ #include "config_win32.h" #endif // HAVE_CONFIG_H +#include #include #include #include @@ -225,7 +226,7 @@ static int count_utf8_bytes(unsigned int i) { */ static int64_t get_ansi_code() { int64_t c = GETCH(); - debug_msg(MOD_NAME "Pressed %d\n", c); + debug_msg(MOD_NAME "Pressed %" PRId32 "\n", c); if (c == '[') { // CSI c = '\E' << 8 | '['; while (true) { @@ -399,7 +400,7 @@ int64_t keyboard_control::get_next_key() if (kbhit()) { #endif int64_t c = GETCH(); - debug_msg(MOD_NAME "Pressed %d\n", c); + debug_msg(MOD_NAME "Pressed %" PRId64 "\n", c); if (c == '\E') { if ((c = get_ansi_code()) == -1) { continue; @@ -887,6 +888,7 @@ bool keycontrol_register_key(struct module *receiver_mod, int64_t key, const cha struct response *r = send_message_sync(get_root_module(receiver_mod), "keycontrol", (struct message *) m, 100, SEND_MESSAGE_FLAG_QUIET | SEND_MESSAGE_FLAG_NO_STORE); if (response_get_status(r) != RESPONSE_OK) { log_msg(LOG_LEVEL_ERROR, MOD_NAME "Cannot register keyboard control (error %d)!\n", response_get_status(r)); + free_response(r); return false; } free_response(r); diff --git a/src/rtp/pbuf.cpp b/src/rtp/pbuf.cpp index eb13d0523..cd483cb18 100644 --- a/src/rtp/pbuf.cpp +++ b/src/rtp/pbuf.cpp @@ -228,15 +228,13 @@ void pbuf_destroy(struct pbuf *playout_buf) { } } +/** Add "pkt" to the frame represented by "node". The "node" has + * previously been created, and has some coded data already... + * + * New arrivals are filed to the list in descending sequence number order + */ static void add_coded_unit(struct pbuf_node *node, rtp_packet * pkt) { - /* Add "pkt" to the frame represented by "node". The "node" has */ - /* previously been created, and has some coded data already... */ - - /* New arrivals are added at the head of the list, which is stored */ - /* in descending order of packets as they arrive (NOT necessarily */ - /* descending sequence number order, as the network might reorder) */ - struct coded_data *tmp, *curr, *prv; assert(node->rtp_timestamp == pkt->ts); @@ -259,29 +257,23 @@ static void add_coded_unit(struct pbuf_node *node, rtp_packet * pkt) node->cdata = tmp; } else { curr = node->cdata; - if (curr == NULL){ - /* this is bad, out of memory, drop the packet... */ + while (curr != NULL && ((int16_t)(tmp->seqno - curr->seqno) < 0)){ + prv = curr; + curr = curr->nxt; + } + if (curr == NULL) { + tmp->nxt = NULL; + tmp->prv = prv; + prv->nxt = tmp; + }else if ((int16_t)(tmp->seqno - curr->seqno) > 0){ + tmp->nxt = curr; + tmp->prv = curr->prv; + tmp->prv->nxt = tmp; + curr->prv = tmp; + } else { + /* this is bad, something went terribly wrong... */ free(pkt); free(tmp); - } else { - while (curr != NULL && ((int16_t)(tmp->seqno - curr->seqno) < 0)){ - prv = curr; - curr = curr->nxt; - } - if (curr == NULL) { - tmp->nxt = NULL; - tmp->prv = prv; - prv->nxt = tmp; - }else if ((int16_t)(tmp->seqno - curr->seqno) > 0){ - tmp->nxt = curr; - tmp->prv = curr->prv; - tmp->prv->nxt = tmp; - curr->prv = tmp; - } else { - /* this is bad, something went terribly wrong... */ - free(pkt); - free(tmp); - } } } } diff --git a/src/rtp/rtp.c b/src/rtp/rtp.c index 3a3cebce1..5f762edf2 100644 --- a/src/rtp/rtp.c +++ b/src/rtp/rtp.c @@ -66,9 +66,14 @@ * */ +#ifdef HAVE_CONFIG_H #include "config.h" #include "config_unix.h" #include "config_win32.h" +#endif // defined HAVE_CONFIG_H + +#include + #include "memory.h" #include "debug.h" #include "net_udp.h" @@ -416,7 +421,7 @@ static void insert_rr(struct rtp *session, uint32_t reporter_ssrc, rtcp_rr * rr, cur->prev = start; cur->prev->next = cur; - debug_msg("Created new rr entry for 0x%08lx from source 0x%08lx\n", + debug_msg("Created new rr entry for 0x%08" PRIx32 " from source 0x%08" PRIx32 "\n", rr->ssrc, reporter_ssrc); return; } @@ -2518,7 +2523,7 @@ int rtp_add_csrc(struct rtp *session, uint32_t csrc) if (!s->should_advertise_sdes) { s->should_advertise_sdes = TRUE; session->csrc_count++; - debug_msg("Added CSRC 0x%08lx as CSRC %d\n", csrc, + debug_msg("Added CSRC 0x%08" PRIx32 " as CSRC %d\n", csrc, session->csrc_count); } return TRUE; @@ -3109,7 +3114,7 @@ static int add_sdes_item(uint8_t * buf, int buflen, int type, const char *val) int namelen; if (val == NULL) { - debug_msg("Cannot format SDES item. type=%d val=%xp\n", type, + debug_msg("Cannot format SDES item. type=%d val=%p\n", type, val); return 0; } @@ -3516,7 +3521,7 @@ void rtp_update(struct rtp *session, struct timeval curr_time) /* the source is timed out. */ if (s->got_bye && (delay > 2.0)) { debug_msg - ("Deleting source 0x%08lx due to reception of BYE %f seconds ago...\n", + ("Deleting source 0x%08" PRIx32 " due to reception of BYE %f seconds ago...\n", s->ssrc, delay); delete_source(session, s->ssrc); } @@ -3536,7 +3541,7 @@ void rtp_update(struct rtp *session, struct timeval curr_time) if ((s->ssrc != rtp_my_ssrc(session)) && (delay > (session->rtcp_interval * 5))) { debug_msg - ("Deleting source 0x%08lx due to timeout...\n", + ("Deleting source 0x%08" PRIx32 " due to timeout...\n", s->ssrc); delete_source(session, s->ssrc); } diff --git a/src/rtp/rtp_callback.c b/src/rtp/rtp_callback.c index 604a1ff01..6746b01a3 100644 --- a/src/rtp/rtp_callback.c +++ b/src/rtp/rtp_callback.c @@ -58,6 +58,10 @@ #include "config.h" #include "config_unix.h" #include "config_win32.h" + +#include +#include + #include "debug.h" #include "host.h" #include "pdb.h" @@ -133,7 +137,7 @@ process_sdes(struct pdb *participants, uint32_t ssrc, rtcp_sdes_item * d) /* This can happen, for example, in a partitioned multicast group. Log */ /* the event, and add the new participant to the database. */ debug_msg - ("Added previously unseen participant 0x%08x due to receipt of SDES\n", + ("Added previously unseen participant 0x%08" PRIx32 " due to receipt of SDES\n", ssrc); pdb_add(participants, ssrc); e = pdb_get(participants, ssrc); @@ -189,8 +193,8 @@ process_sdes(struct pdb *participants, uint32_t ssrc, rtcp_sdes_item * d) default: free(sdes_item); debug_msg - ("Ignored unknown SDES item (type=0x%02x) from 0x%08x\n", - ssrc); + ("Ignored unknown SDES item (type=0x%02" PRIx32 ") from 0x%08" PRIx32"\n", + d->type, ssrc); } } diff --git a/src/rtsp/rtsp_utils.c b/src/rtsp/rtsp_utils.c index 20b3889f5..6f5852885 100644 --- a/src/rtsp/rtsp_utils.c +++ b/src/rtsp/rtsp_utils.c @@ -11,7 +11,8 @@ int get_rtsp_server_port(const char *cconfig){ char *tok; char *save_ptr = NULL; char *config = strdup(cconfig); - if(strcmp((strtok_r(config, ":", &save_ptr)),"port") == 0){ + tok = strtok_r(config, ":", &save_ptr); + if (tok && strcmp(tok,"port") == 0){ if ((tok = strtok_r(NULL, ":", &save_ptr))) { port = atoi(tok); if (!(port >= 0 && port <= 65535)) { diff --git a/src/utils/jpeg_reader.c b/src/utils/jpeg_reader.c index c896e734c..a4a304f62 100644 --- a/src/utils/jpeg_reader.c +++ b/src/utils/jpeg_reader.c @@ -384,7 +384,7 @@ static int read_dht(struct jpeg_info *param, uint8_t** image) if ( length > 0 ) { length--; } else { - log_msg(LOG_LEVEL_ERROR, "[JPEG] [Error] DHT marker unexpected end when reading bit counts!\n", index); + log_msg(LOG_LEVEL_ERROR, "[JPEG] [Error] DHT marker unexpected end when reading bit counts!\n"); return -1; } } @@ -395,7 +395,7 @@ static int read_dht(struct jpeg_info *param, uint8_t** image) if ( length > 0 ) { length--; } else { - log_msg(LOG_LEVEL_ERROR, "[GPUJPEG] [Error] DHT marker unexpected end when reading huffman values!\n", index); + log_msg(LOG_LEVEL_ERROR, "[JPEG] [Error] DHT marker unexpected end when reading huffman values!\n"); return -1; } } @@ -647,7 +647,7 @@ int jpeg_read_info(uint8_t *image, int len, struct jpeg_info *info) for (unsigned int i = 0; i < sizeof req_markers / sizeof req_markers[0]; ++i) { if (!marker_present[req_markers[i]]) { log_msg(LOG_LEVEL_ERROR, "Marker \"%s\" missing in JPEG file!\n", - req_markers[i]); + jpeg_marker_name(req_markers[i])); if (req_markers[i] == JPEG_MARKER_SOF0) { log_msg(LOG_LEVEL_INFO, "Perhaps unsupported JPEG type.\n"); } diff --git a/src/video_capture/aja.cpp b/src/video_capture/aja.cpp index 14f0b03c7..872d1b57b 100644 --- a/src/video_capture/aja.cpp +++ b/src/video_capture/aja.cpp @@ -1104,10 +1104,13 @@ LINK_SPEC struct vidcap_type *vidcap_aja_probe(bool verbose, void (**deleter)(vo *deleter = free; vt = (struct vidcap_type *)calloc(1, sizeof(struct vidcap_type)); - if (vt != NULL) { - vt->name = "aja"; - vt->description = "AJA capture card"; + if (vt == nullptr) { + return nullptr; } + + vt->name = "aja"; + vt->description = "AJA capture card"; + if (!verbose) { return vt; } diff --git a/src/video_capture/banner.cpp b/src/video_capture/banner.cpp index 0429f60b5..ad68f84e3 100644 --- a/src/video_capture/banner.cpp +++ b/src/video_capture/banner.cpp @@ -160,7 +160,7 @@ static int vidcap_banner_init(struct vidcap_params *params, void **state) goto error; } - if (!in || fread(s->data, filesize, 1, in) == 0) { + if (!in || fread(s->data, filesize, 1, in) != 1) { fprintf(stderr, "Cannot read file %s\n", filename); goto error; } diff --git a/src/video_capture/file.c b/src/video_capture/file.c index f72c77d55..1de8cf63e 100644 --- a/src/video_capture/file.c +++ b/src/video_capture/file.c @@ -58,6 +58,7 @@ #include #include #include +#include #include #include #include @@ -253,7 +254,7 @@ static void *vidcap_file_worker(void *state) { } CHECK_FF(ret, FAIL_WORKER); // check the retval of av_read_frame for error other than EOF - log_msg(LOG_LEVEL_DEBUG, MOD_NAME "received %s packet, ID %d, pos %d, size %d\n", + log_msg(LOG_LEVEL_DEBUG, MOD_NAME "received %s packet, ID %d, pos %" PRId64" , size %d\n", av_get_media_type_string( s->fmt_ctx->streams[pkt.stream_index]->codecpar->codec_type), pkt.stream_index, pkt.pos, pkt.size); diff --git a/src/video_capture/import.cpp b/src/video_capture/import.cpp index 48b0a0966..0852faf4a 100644 --- a/src/video_capture/import.cpp +++ b/src/video_capture/import.cpp @@ -283,6 +283,7 @@ try { "\t{:loop|:mt_reading=|:o_direct|:exit_at_end|:fps=|:disable_audio}\n" "\t\t - overrides FPS from sequence metadata\n"); delete s; + free(tmp); return VIDCAP_INIT_NOERR; } @@ -303,7 +304,12 @@ try { char *save_ptr = NULL; char *suffix; - s->directory = strdup(strtok_r(tmp, ":", &save_ptr)); + s->directory = strtok_r(tmp, ":", &save_ptr); + if (s->directory == nullptr) { + throw string("Wrong directory name!\n"); + } + s->directory = strdup(s->directory); // make a copy + while ((suffix = strtok_r(NULL, ":", &save_ptr)) != NULL) { if (suffix[0] == '\\') { // MSW path assert(strlen(s->directory) == 1); // c:\something -> should be 'c' diff --git a/src/video_capture/rtsp.cpp b/src/video_capture/rtsp.cpp index 9ef0b06d8..1779c7d5f 100644 --- a/src/video_capture/rtsp.cpp +++ b/src/video_capture/rtsp.cpp @@ -439,6 +439,7 @@ vidcap_rtsp_grab(void *state, struct audio_frame **audio) { return s->vrtsp_state->frame; } +#define FAIL vidcap_rtsp_done(s); show_help(); return VIDCAP_INIT_FAIL; static int vidcap_rtsp_init(struct vidcap_params *params, void **state) { @@ -518,8 +519,7 @@ vidcap_rtsp_init(struct vidcap_params *params, void **state) { sprintf(s->uri, "rtsp:%s:%s", uri_tmp1, uri_tmp2); } else { printf("\n[rtsp] Wrong format for uri! \n"); - show_help(); - exit(0); + FAIL } break; case 1: @@ -536,16 +536,14 @@ vidcap_rtsp_init(struct vidcap_params *params, void **state) { s->vrtsp_state->decompress = FALSE; else { printf("\n[rtsp] Wrong format for boolean decompress flag! \n"); - show_help(); - exit(0); + FAIL } } else continue; } } else { printf("\n[rtsp] Wrong format for height! \n"); - show_help(); - exit(0); + FAIL } break; case 2: diff --git a/src/video_capture/testcard.cpp b/src/video_capture/testcard.cpp index c17a7134c..c658c3757 100644 --- a/src/video_capture/testcard.cpp +++ b/src/video_capture/testcard.cpp @@ -442,8 +442,8 @@ static int vidcap_testcard_init(struct vidcap_params *params, void **state) goto error; } - if (!in || fread(s->data, filesize, 1, in) == 0) { - fprintf(stderr, "Cannot read file %s\n", filename); + if (!in || fread(s->data, filesize, 1, in) != 1) { + log_msg(LOG_LEVEL_ERROR, "Cannot read file %s\n", filename); goto error; } diff --git a/src/video_codec.c b/src/video_codec.c index 4f79ebcad..920b4f9ab 100644 --- a/src/video_codec.c +++ b/src/video_codec.c @@ -249,7 +249,7 @@ void show_codec_help(const char *module, const codec_t *codecs8, const codec_t * if (codecs12) { printf("\t\t12bits\n"); while (*codecs12 != VIDEO_CODEC_NONE) { - printf("\t\t\t'%s' - %s\n", codec_info[*codecs12].name, codec_info[*codecs10].name_long); + printf("\t\t\t'%s' - %s\n", codec_info[*codecs12].name, codec_info[*codecs12].name_long); codecs12++; } } diff --git a/src/video_compress/cmpto_j2k.cpp b/src/video_compress/cmpto_j2k.cpp index a49ed6c02..dfcb099c7 100644 --- a/src/video_compress/cmpto_j2k.cpp +++ b/src/video_compress/cmpto_j2k.cpp @@ -101,7 +101,7 @@ struct state_video_compress_j2k { video_desc saved_desc{}; ///< for pool reconfiguration video_desc precompress_desc{}; video_desc compressed_desc{}; - void (*convertFunc)(video_frame *dst, video_frame *src); + void (*convertFunc)(video_frame *dst, video_frame *src){nullptr}; }; static void j2k_compressed_frame_dispose(struct video_frame *frame); @@ -214,6 +214,7 @@ start: { unique_lock lk(s->lock); s->in_frames--; + lk.unlock(); s->frame_popped.notify_one(); } if (!img) { @@ -346,9 +347,7 @@ static struct module * j2k_compress_init(struct module *parent, const char *c_cf return &s->module_data; error: - if (s) { - delete s; - } + delete s; return NULL; } diff --git a/src/video_compress/gpujpeg.cpp b/src/video_compress/gpujpeg.cpp index 51bd2eaf0..113e68679 100644 --- a/src/video_compress/gpujpeg.cpp +++ b/src/video_compress/gpujpeg.cpp @@ -92,8 +92,8 @@ private: int m_encoder_input_linesize; unique_ptr m_decoded; - struct gpujpeg_parameters m_encoder_param; - struct gpujpeg_image_parameters m_param_image; + struct gpujpeg_parameters m_encoder_param{}; + struct gpujpeg_image_parameters m_param_image{}; public: encoder_state(struct state_video_compress_gpujpeg *s, int device_id) : m_parent_state(s), m_device_id(device_id), m_encoder{}, m_saved_desc{}, diff --git a/src/video_decompress/cmpto_j2k.cpp b/src/video_decompress/cmpto_j2k.cpp index 8304a5091..fcdcea0bc 100644 --- a/src/video_decompress/cmpto_j2k.cpp +++ b/src/video_decompress/cmpto_j2k.cpp @@ -104,7 +104,7 @@ struct state_decompress_j2k { void (*convert)(unsigned char *dst_buffer, unsigned char *src_buffer, - unsigned int width, unsigned int height); + unsigned int width, unsigned int height){nullptr}; }; #define CHECK_OK(cmd, err_msg, action_fail) do { \ diff --git a/src/video_display/conference.cpp b/src/video_display/conference.cpp index 052e27aa8..e1234c03b 100644 --- a/src/video_display/conference.cpp +++ b/src/video_display/conference.cpp @@ -45,8 +45,10 @@ #include "video_display.h" #include "video_codec.h" +#include #include #include +#include #include #include #include @@ -551,7 +553,7 @@ static void display_conference_run(void *state) auto it = s->ssrc_list.begin(); while (it != s->ssrc_list.end()) { if (chrono::duration_cast(now - it->second) > SOURCE_TIMEOUT) { - verbose_msg("Source 0x%08lx timeout. Deleting from conference display.\n", it->first); + verbose_msg("Source 0x%08" PRIx32 " timeout. Deleting from conference display.\n", it->first); s->output->removeTile(it->first); it = s->ssrc_list.erase(it); diff --git a/src/video_display/decklink.cpp b/src/video_display/decklink.cpp index c4d9edf8f..0eea74785 100644 --- a/src/video_display/decklink.cpp +++ b/src/video_display/decklink.cpp @@ -459,6 +459,7 @@ display_decklink_getf(void *state) if (s->stereo) { IDeckLinkVideoFrame *deckLinkFrameRight = nullptr; dynamic_cast(deckLinkFrame)->GetFrameForRightEye(&deckLinkFrameRight); + assert(deckLinkFrameRight != nullptr); deckLinkFrameRight->GetBytes((void **) &out->tiles[1].data); // release immedieatelly (parent still holds the reference) deckLinkFrameRight->Release(); diff --git a/src/video_display/deltacast.cpp b/src/video_display/deltacast.cpp index da126e42d..02de58845 100644 --- a/src/video_display/deltacast.cpp +++ b/src/video_display/deltacast.cpp @@ -169,7 +169,7 @@ static int display_deltacast_putf(void *state, struct video_frame *frame, int no double seconds = tv_diff(tv, s->tv); if (seconds > 5) { double fps = s->frames / seconds; - log_msg(LOG_LEVEL_INFO, "[DELTACAST display] %" PRIu32 " frames in %g seconds = %g FPS\n", + log_msg(LOG_LEVEL_INFO, "[DELTACAST display] %lu frames in %g seconds = %g FPS\n", s->frames, seconds, fps); s->tv = tv; s->frames = 0; diff --git a/src/video_display/gl.cpp b/src/video_display/gl.cpp index d2792fc04..ee9590f42 100644 --- a/src/video_display/gl.cpp +++ b/src/video_display/gl.cpp @@ -996,8 +996,8 @@ static void glut_idle_callback(void) static int64_t translate_glut_to_ug(int key, bool is_special) { #ifdef FREEGLUT - if (is_special && (key == GLUT_KEY_CTRL_L || key == GLUT_KEY_CTRL_R) - && (key == GLUT_KEY_ALT_L || key == GLUT_KEY_ALT_R)) { + if (is_special && (key == GLUT_KEY_CTRL_L || key == GLUT_KEY_CTRL_R + || key == GLUT_KEY_ALT_L || key == GLUT_KEY_ALT_R)) { return 0; } #endif // defined FREEGLUT @@ -1131,6 +1131,7 @@ static bool display_gl_check_gl_version() { auto version = (const char *) glGetString(GL_VERSION); if (!version) { log_msg(LOG_LEVEL_ERROR, MOD_NAME "Unable to get OpenGL version!\n"); + return false; } if (atof(version) < 2.0) { log_msg(LOG_LEVEL_ERROR, MOD_NAME "ERROR: OpenGL 2.0 is not supported, try updating your drivers...\n"); diff --git a/src/video_display/multiplier.cpp b/src/video_display/multiplier.cpp index 047a0f1de..668c27725 100644 --- a/src/video_display/multiplier.cpp +++ b/src/video_display/multiplier.cpp @@ -124,6 +124,7 @@ static void *display_multiplier_init(struct module *parent, const char *fmt, uns } } else { show_help(); + delete s; return &display_init_noerr; } s->common = shared_ptr(new state_multiplier_common()); diff --git a/src/video_display/proxy.cpp b/src/video_display/proxy.cpp index a48a5e186..88f33885d 100644 --- a/src/video_display/proxy.cpp +++ b/src/video_display/proxy.cpp @@ -48,6 +48,7 @@ #include "video.h" #include "video_display.h" +#include #include #include #include @@ -200,7 +201,7 @@ static void display_proxy_run(void *state) it = s->disabled_ssrc.begin(); while (it != s->disabled_ssrc.end()) { if (chrono::duration_cast(now - it->second) > SOURCE_TIMEOUT) { - verbose_msg("Source 0x%08lx timeout. Deleting from proxy display.\n", it->first); + verbose_msg("Source 0x%08" PRIx32 " timeout. Deleting from proxy display.\n", it->first); s->disabled_ssrc.erase(it++); } else { ++it; diff --git a/src/video_display/sdl2.cpp b/src/video_display/sdl2.cpp index 662fa64ee..6241d852a 100644 --- a/src/video_display/sdl2.cpp +++ b/src/video_display/sdl2.cpp @@ -136,7 +136,7 @@ struct state_sdl2 { sdl_user_new_frame_event = SDL_RegisterEvents(2); assert(sdl_user_new_frame_event != (Uint32) -1); - sdl_user_new_message_event = sdl_user_new_message_event + 1; + sdl_user_new_message_event = sdl_user_new_frame_event + 1; } ~state_sdl2() { module_done(&mod); @@ -186,7 +186,7 @@ free_frame: double seconds = duration_cast>(tv - s->tv).count(); if (seconds > 5) { double fps = s->frames / seconds; - log_msg(LOG_LEVEL_INFO, "[SDL] %d frames in %g seconds = %g FPS\n", + log_msg(LOG_LEVEL_INFO, "[SDL] %llu frames in %g seconds = %g FPS\n", s->frames, seconds, fps); s->tv = tv; s->frames = 0; @@ -392,7 +392,7 @@ static bool create_texture(struct state_sdl2 *s, struct video_desc desc) { s->texture = SDL_CreateTexture(s->renderer, format, SDL_TEXTUREACCESS_STREAMING, desc.width, desc.height); if (!s->texture) { - log_msg(LOG_LEVEL_ERROR, "[SDL] Unable to create texture: %s\n", SDL_GetError); + log_msg(LOG_LEVEL_ERROR, "[SDL] Unable to create texture: %s\n", SDL_GetError()); return false; } diff --git a/src/video_rxtx/h264_sdp.cpp b/src/video_rxtx/h264_sdp.cpp index 738c8f8bf..29ff81752 100644 --- a/src/video_rxtx/h264_sdp.cpp +++ b/src/video_rxtx/h264_sdp.cpp @@ -153,6 +153,7 @@ void h264_sdp_video_rxtx::send_frame(shared_ptr tx_frame) if ((m_rxtx_mode & MODE_RECEIVER) == 0) { // send RTCP (receiver thread would otherwise do this struct timeval curr_time; uint32_t ts = get_std_video_local_mediatime(); + gettimeofday(&curr_time, NULL); rtp_update(m_network_devices[0], curr_time); rtp_send_ctrl(m_network_devices[0], ts, 0, curr_time); diff --git a/src/video_rxtx/rtp.cpp b/src/video_rxtx/rtp.cpp index d983a2c3a..eae4aec3b 100644 --- a/src/video_rxtx/rtp.cpp +++ b/src/video_rxtx/rtp.cpp @@ -46,6 +46,7 @@ #include "debug.h" +#include #include #include #include @@ -199,8 +200,8 @@ struct response *rtp_video_rxtx::process_sender_message(struct msg_sender *msg, return new_response(RESPONSE_INT_SERV_ERR, NULL); } else { destroy_rtp_devices(old_devices); - log_msg(LOG_LEVEL_NOTICE, "[control] Changed SSRC from 0x%08lx to " - "0x%08lx.\n", old_ssrc, rtp_my_ssrc(m_network_devices[0])); + log_msg(LOG_LEVEL_NOTICE, "[control] Changed SSRC from 0x%08" PRIx32 " to " + "0x%08" PRIx32 ".\n", old_ssrc, rtp_my_ssrc(m_network_devices[0])); } } break; diff --git a/src/vo_postprocess/crop.cpp b/src/vo_postprocess/crop.cpp index 175ec974b..aff0fe559 100644 --- a/src/vo_postprocess/crop.cpp +++ b/src/vo_postprocess/crop.cpp @@ -131,6 +131,7 @@ static int crop_postprocess_reconfigure(void *state, struct video_desc desc) s->out_desc.height = s->height ? min(s->height, desc.height) : desc.height; // make sure that width is divisible by pixel block size + assert(get_pf_block_size(desc.color_spec) != 0); int linesize = (int) (s->out_desc.width * get_bpp(desc.color_spec)) / get_pf_block_size(desc.color_spec) * get_pf_block_size(desc.color_spec); s->out_desc.width = linesize / get_bpp(desc.color_spec); @@ -147,6 +148,7 @@ static struct video_frame * crop_getf(void *state) static bool crop_postprocess(void *state, struct video_frame *in, struct video_frame *out, int req_pitch) { assert(in->tile_count == 1); + assert(get_pf_block_size(in->color_spec) != 0); auto s = static_cast(state); int src_linesize = vc_get_linesize(in->tiles[0].width, in->color_spec);