From 81e67665943698ebd064305b4c0fdc9655ff4149 Mon Sep 17 00:00:00 2001 From: Martin Pulec Date: Mon, 16 Sep 2024 09:12:50 +0200 Subject: [PATCH] rtp/audio_decoders: include-what-you-use improved including + include guard to the header --- src/rtp/audio_decoders.cpp | 100 ++++++++++++++++++------------------- src/rtp/audio_decoders.h | 14 +++++- 2 files changed, 63 insertions(+), 51 deletions(-) diff --git a/src/rtp/audio_decoders.cpp b/src/rtp/audio_decoders.cpp index b88654a3b2..f2665146eb 100644 --- a/src/rtp/audio_decoders.cpp +++ b/src/rtp/audio_decoders.cpp @@ -5,7 +5,7 @@ */ /* * Copyright (c) 2014 FundaciĆ³ i2CAT, Internet I InnovaciĆ³ Digital a Catalunya - * Copyright (c) 2012-2023 CESNET, z. s. p. o. + * Copyright (c) 2012-2024 CESNET * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -37,49 +37,49 @@ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#include "config_unix.h" -#include "config_win32.h" -#endif // HAVE_CONFIG_H - +#include "src/rtp/audio_decoders.h" + +#include // for min +#include // for atomic_uint64_t +#include // for assert +#include // for steady_clock, duration_cast, ope... +#include // for log +#include // for strtoll, atof, free, realloc +#include // for memcpy, strchr, strlen, memset +#include // for setprecision +#include // for basic_ostream, operator<<, clog +#include // for map +#include // for char_traits, allocator, operator+ +#include // for pair, move, swap +#include // for vector + +#include "audio/audio_playback.h" // for AUDIO_PLAYBACK_CTL_QUERY_FORMAT +#include "audio/codec.h" // for get_audio_codec_to_tag, audio_co... +#include "audio/resampler.hpp" // for audio_frame2_resampler +#include "audio/types.h" // for audio_frame2, audio_desc, AC_PCM +#include "audio/utils.h" // for channel_map, calculate_rms, mux_... +#include "compat/htonl.h" // for ntohl, sockaddr_storage +#include "compat/strings.h" // for strcasecmp #include "control_socket.h" +#include "crypto/openssl_decrypt.h" // for openssl_decrypt_info, OPENSSL_DE... +#include "crypto/openssl_encrypt.h" // for openssl_mode #include "debug.h" #include "host.h" #include "lib_common.h" +#include "messaging.h" // for new_response, msg_universal, che... #include "module.h" +#include "rtp/fec.h" // for fec +#include "rtp/pbuf.h" // for pbuf_audio_data, coded_data +#include "rtp/rtp.h" // for RTP_MAX_PACKET_LEN +#include "rtp/rtp_types.h" // for BUFNUM_BITS, audio_payload_hdr_t #include "tv.h" -#include "rtp/fec.h" -#include "rtp/rtp.h" -#include "rtp/rtp_callback.h" -#include "rtp/ptime.h" -#include "rtp/pbuf.h" -#include "rtp/audio_decoders.h" -#include "audio/audio_playback.h" -#include "audio/codec.h" -#include "audio/resampler.hpp" -#include "audio/types.h" -#include "audio/utils.h" -#include "crypto/crc.h" -#include "crypto/openssl_decrypt.h" +#include "types.h" // for fec_desc, fec_type #include "ug_runtime_error.hpp" #include "utils/color_out.h" #include "utils/macros.h" #include "utils/packet_counter.h" #include "utils/worker.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - using std::chrono::duration_cast; using std::chrono::seconds; using std::chrono::steady_clock; @@ -277,7 +277,7 @@ void *audio_decoder_init(char *audio_channel_map, const char *audio_scale, const s->dec_funcs = static_cast(load_library("openssl_decrypt", LIBRARY_CLASS_UNDEFINED, OPENSSL_DECRYPT_ABI_VERSION)); if (!s->dec_funcs) { - log_msg(LOG_LEVEL_ERROR, "This " PACKAGE_NAME " version was build " + log_msg(LOG_LEVEL_ERROR, "This UltraGrid version was build " "without OpenSSL support!\n"); delete s; return NULL; @@ -293,9 +293,9 @@ void *audio_decoder_init(char *audio_channel_map, const char *audio_scale, const if (!parse_channel_map_cfg(&s->channel_map, audio_channel_map)) { goto error; } - s->channel_remapping = TRUE; + s->channel_remapping = true; } else { - s->channel_remapping = FALSE; + s->channel_remapping = false; s->channel_map.map = NULL; s->channel_map.sizes = NULL; s->channel_map.size = 0; @@ -520,7 +520,7 @@ static bool audio_fec_decode(struct pbuf_audio_data *s, vector } if (!audio_decoder_reconfigure(decoder, s, received_frame, desc.ch_count, desc.bps, desc.sample_rate, audio_tag)) { - return FALSE; + return false; } } received_frame.replace(channel, 0, out + sizeof(audio_payload_hdr_t), out_len - sizeof(audio_payload_hdr_t)); @@ -542,13 +542,13 @@ int decode_audio_frame(struct coded_data *cdata, void *pbuf_data, struct pbuf_st int bufnum = 0; if(!cdata) { - return FALSE; + return false; } if (!cdata->data->m) { // skip frame without m-bit, we cannot determine number of channels // (it is maximal substream number + 1 in packet with m-bit) - return FALSE; + return false; } DEBUG_TIMER_START(audio_decode); @@ -572,13 +572,13 @@ int decode_audio_frame(struct coded_data *cdata, void *pbuf_data, struct pbuf_st if(!decoder->decrypt) { log_msg(LOG_LEVEL_WARNING, "Receiving encrypted audio data but " "no decryption key entered!\n"); - return FALSE; + return false; } } else if (PT_IS_AUDIO(pt) && !PT_AUDIO_IS_ENCRYPTED(pt)) { if(decoder->decrypt) { log_msg(LOG_LEVEL_WARNING, "Receiving unencrypted audio data " "while expecting encrypted.\n"); - return FALSE; + return false; } } else { if (pt == PT_Unassign_Type95) { @@ -586,7 +586,7 @@ int decode_audio_frame(struct coded_data *cdata, void *pbuf_data, struct pbuf_st } else { log_msg(LOG_LEVEL_WARNING, "Unknown audio packet type: %d\n", pt); } - return FALSE; + return false; } unsigned int length; @@ -597,7 +597,7 @@ int decode_audio_frame(struct coded_data *cdata, void *pbuf_data, struct pbuf_st crypto_mode = (enum openssl_mode) (encryption_hdr >> 24); if (crypto_mode == MODE_AES128_NONE || crypto_mode > MODE_AES128_MAX) { log_msg(LOG_LEVEL_WARNING, "Unknown cipher mode: %d\n", (int) crypto_mode); - return FALSE; + return false; } char *ciphertext = cdata->data->data + sizeof(crypto_payload_hdr_t) + main_hdr_len; @@ -608,7 +608,7 @@ int decode_audio_frame(struct coded_data *cdata, void *pbuf_data, struct pbuf_st ciphertext, ciphertext_len, (char *) audio_hdr, sizeof(audio_payload_hdr_t), plaintext, crypto_mode)) == 0) { - return FALSE; + return false; } data = plaintext; } else { @@ -651,7 +651,7 @@ int decode_audio_frame(struct coded_data *cdata, void *pbuf_data, struct pbuf_st uint32_t audio_tag = ntohl(audio_hdr[4]); if (!audio_decoder_reconfigure(decoder, s, received_frame, input_channels, bps, sample_rate, audio_tag)) { - return FALSE; + return false; } received_frame.replace(channel, offset, data, length); @@ -676,21 +676,21 @@ int decode_audio_frame(struct coded_data *cdata, void *pbuf_data, struct pbuf_st if (fec_params != 0) { if (!audio_fec_decode(s, fec_data, fec_params, received_frame)) { - return FALSE; + return false; } } s->frame_size = received_frame.get_data_len(); audio_frame2 decompressed = audio_codec_decompress(decoder->audio_decompress, &received_frame); if (!decompressed) { - return FALSE; + return false; } // Perform a variable rate resample if any output device has requested it if (decoder->req_resample_to != 0 || s->buffer.sample_rate != decompressed.get_sample_rate()) { int resampler_bps = decoder->resampler.align_bps(decompressed.get_bps()); if (resampler_bps <= 0) { - return FALSE; + return false; } if (resampler_bps != decompressed.get_bps()) { decompressed.change_bps(resampler_bps); @@ -699,13 +699,13 @@ int decode_audio_frame(struct coded_data *cdata, void *pbuf_data, struct pbuf_st auto [ret, remainder] = decompressed.resample_fake(decoder->resampler, decoder->req_resample_to >> ADEC_CH_RATE_SHIFT, decoder->req_resample_to & ((1LLU << ADEC_CH_RATE_SHIFT) - 1)); if (!ret) { LOG(LOG_LEVEL_INFO) << MOD_NAME << "You may try to set different sampling on sender.\n"; - return FALSE; + return false; } decoder->resample_remainder = std::move(remainder); } else { if (!decompressed.resample(decoder->resampler, s->buffer.sample_rate)) { LOG(LOG_LEVEL_INFO) << MOD_NAME << "You may try to set different sampling on sender.\n"; - return FALSE; + return false; } } } @@ -811,7 +811,7 @@ int decode_audio_frame(struct coded_data *cdata, void *pbuf_data, struct pbuf_st DEBUG_TIMER_STOP(audio_decode_compute_autoscale); DEBUG_TIMER_STOP(audio_decode); - return TRUE; + return true; } /* * Second version that uses external audio configuration, diff --git a/src/rtp/audio_decoders.h b/src/rtp/audio_decoders.h index ec663389d9..9823b5d993 100644 --- a/src/rtp/audio_decoders.h +++ b/src/rtp/audio_decoders.h @@ -3,7 +3,7 @@ * @author Martin Pulec */ /* - * Copyright (c) 2012-2021 CESNET z.s.p.o. + * Copyright (c) 2012-2024 CESNET * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -35,12 +35,23 @@ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#ifndef RTP_AUDIO_DECODERS_H_54DFB935_A1FC_48EF_A375_A044581B869F +#define RTP_AUDIO_DECODERS_H_54DFB935_A1FC_48EF_A375_A044581B869F + #ifdef __cplusplus +#include // for size_t +#include // for uint32_t extern "C" { +#else +#include // for bool +#include // for size_t +#include // for uint32_t #endif +struct audio_desc; struct coded_data; struct module; +struct pbuf_stats; typedef bool (*audio_playback_ctl_t)(void *state, int request, void *data, size_t *len); @@ -61,3 +72,4 @@ bool parse_audio_hdr(uint32_t *hdr, struct audio_desc *desc); } #endif +#endif // defined RTP_AUDIO_DECODERS_H_54DFB935_A1FC_48EF_A375_A044581B869F