treewide: mark things static and const

Mark some structures, arrays static/const at various places.
In some cases this prevents unnecessary initialization
when a function is entered.

All in all, the text segments across all shared
libraries are reduced by about 2 KiB. However,
the total size increases by about 2 KiB as well.
This commit is contained in:
Barnabás Pőcze 2021-06-27 17:47:13 +02:00
parent 48dbb4da3c
commit f5d51162c4
54 changed files with 303 additions and 241 deletions

View file

@ -61,7 +61,7 @@ struct impl {
static int codec_fill_caps(const struct a2dp_codec *codec, uint32_t flags,
uint8_t caps[A2DP_MAX_CAPS_SIZE])
{
const a2dp_aac_t a2dp_aac = {
static const a2dp_aac_t a2dp_aac = {
.object_type =
/* NOTE: AAC Long Term Prediction and AAC Scalable are
* not supported by the FDK-AAC library. */
@ -86,11 +86,12 @@ static int codec_fill_caps(const struct a2dp_codec *codec, uint32_t flags,
.vbr = 1,
AAC_INIT_BITRATE(DEFAULT_AAC_BITRATE)
};
memcpy(caps, &a2dp_aac, sizeof(a2dp_aac));
return sizeof(a2dp_aac);
}
static struct a2dp_codec_config
static const struct a2dp_codec_config
aac_frequencies[] = {
{ AAC_SAMPLING_FREQ_48000, 48000, 11 },
{ AAC_SAMPLING_FREQ_44100, 44100, 10 },
@ -106,7 +107,7 @@ aac_frequencies[] = {
{ AAC_SAMPLING_FREQ_8000, 8000, 0 },
};
static struct a2dp_codec_config
static const struct a2dp_codec_config
aac_channel_modes[] = {
{ AAC_CHANNELS_2, 2, 1 },
{ AAC_CHANNELS_1, 1, 0 },

View file

@ -76,7 +76,7 @@ static int codec_fill_caps(const struct a2dp_codec *codec, uint32_t flags,
return actual_conf_size;
}
static struct a2dp_codec_config
static const struct a2dp_codec_config
aptx_frequencies[] = {
{ APTX_SAMPLING_FREQ_48000, 48000, 3 },
{ APTX_SAMPLING_FREQ_44100, 44100, 2 },

View file

@ -81,7 +81,7 @@ struct impl {
static int codec_fill_caps(const struct a2dp_codec *codec, uint32_t flags, uint8_t caps[A2DP_MAX_CAPS_SIZE])
{
const a2dp_ldac_t a2dp_ldac = {
static const a2dp_ldac_t a2dp_ldac = {
.info.vendor_id = LDAC_VENDOR_ID,
.info.codec_id = LDAC_CODEC_ID,
.frequency = LDACBT_SAMPLING_FREQ_044100 |
@ -92,11 +92,12 @@ static int codec_fill_caps(const struct a2dp_codec *codec, uint32_t flags, uint8
LDACBT_CHANNEL_MODE_DUAL_CHANNEL |
LDACBT_CHANNEL_MODE_STEREO,
};
memcpy(caps, &a2dp_ldac, sizeof(a2dp_ldac));
return sizeof(a2dp_ldac);
}
static struct a2dp_codec_config
static const struct a2dp_codec_config
ldac_frequencies[] = {
{ LDACBT_SAMPLING_FREQ_044100, 44100, 3 },
{ LDACBT_SAMPLING_FREQ_048000, 48000, 2 },
@ -104,7 +105,7 @@ ldac_frequencies[] = {
{ LDACBT_SAMPLING_FREQ_096000, 96000, 0 },
};
static struct a2dp_codec_config
static const struct a2dp_codec_config
ldac_channel_modes[] = {
{ LDACBT_CHANNEL_MODE_STEREO, 2, 2 },
{ LDACBT_CHANNEL_MODE_DUAL_CHANNEL, 2, 1 },

View file

@ -55,7 +55,7 @@ struct impl {
static int codec_fill_caps(const struct a2dp_codec *codec, uint32_t flags,
uint8_t caps[A2DP_MAX_CAPS_SIZE])
{
const a2dp_sbc_t a2dp_sbc = {
static const a2dp_sbc_t a2dp_sbc = {
.frequency =
SBC_SAMPLING_FREQ_16000 |
SBC_SAMPLING_FREQ_32000 |
@ -80,6 +80,7 @@ static int codec_fill_caps(const struct a2dp_codec *codec, uint32_t flags,
.min_bitpool = SBC_MIN_BITPOOL,
.max_bitpool = SBC_MAX_BITPOOL,
};
memcpy(caps, &a2dp_sbc, sizeof(a2dp_sbc));
return sizeof(a2dp_sbc);
}
@ -121,7 +122,7 @@ static uint8_t default_bitpool(uint8_t freq, uint8_t mode, bool xq)
}
static struct a2dp_codec_config
static const struct a2dp_codec_config
sbc_frequencies[] = {
{ SBC_SAMPLING_FREQ_48000, 48000, 3 },
{ SBC_SAMPLING_FREQ_44100, 44100, 2 },
@ -129,13 +130,13 @@ sbc_frequencies[] = {
{ SBC_SAMPLING_FREQ_16000, 16000, 0 },
};
static struct a2dp_codec_config
static const struct a2dp_codec_config
sbc_xq_frequencies[] = {
{ SBC_SAMPLING_FREQ_44100, 44100, 1 },
{ SBC_SAMPLING_FREQ_48000, 48000, 0 },
};
static struct a2dp_codec_config
static const struct a2dp_codec_config
sbc_channel_modes[] = {
{ SBC_CHANNEL_MODE_JOINT_STEREO, 2, 3 },
{ SBC_CHANNEL_MODE_STEREO, 2, 2 },
@ -143,7 +144,7 @@ sbc_channel_modes[] = {
{ SBC_CHANNEL_MODE_MONO, 1, 0 },
};
static struct a2dp_codec_config
static const struct a2dp_codec_config
sbc_xq_channel_modes[] = {
{ SBC_CHANNEL_MODE_DUAL_CHANNEL, 2, 2 },
{ SBC_CHANNEL_MODE_JOINT_STEREO, 2, 1 },
@ -158,7 +159,7 @@ static int codec_select_config(const struct a2dp_codec *codec, uint32_t flags,
a2dp_sbc_t conf;
int bitpool, i;
size_t n;
struct a2dp_codec_config * configs;
const struct a2dp_codec_config *configs;
bool xq = false;

View file

@ -134,7 +134,7 @@ extern struct a2dp_codec a2dp_codec_aptx;
extern struct a2dp_codec a2dp_codec_aptx_hd;
#endif
const struct a2dp_codec *a2dp_codec_list[] = {
static const struct a2dp_codec * const a2dp_codec_list[] = {
#if ENABLE_LDAC
&a2dp_codec_ldac,
#endif
@ -150,6 +150,7 @@ const struct a2dp_codec *a2dp_codec_list[] = {
#endif
&a2dp_codec_sbc_xq,
&a2dp_codec_sbc,
NULL,
NULL
};
const struct a2dp_codec **a2dp_codecs = a2dp_codec_list;
const struct a2dp_codec * const * const a2dp_codecs = a2dp_codec_list;

View file

@ -371,7 +371,7 @@ struct a2dp_codec {
int (*increase_bitpool) (void *data);
};
extern const struct a2dp_codec **a2dp_codecs;
extern const struct a2dp_codec * const * const a2dp_codecs;
struct a2dp_codec_config {
uint32_t config;

View file

@ -698,9 +698,11 @@ static bool rfcomm_hfp_ag(struct spa_source *source, char* buf)
/* retrieve supported codecs */
/* response has the form AT+BAC=<codecID1>,<codecID2>,<codecIDx>
strategy: split the string into tokens */
static const char separators[] = "=,";
char* token;
char separators[] = "=,";
int cntr = 0;
token = strtok (buf, separators);
while (token != NULL)
{
@ -855,13 +857,14 @@ static bool rfcomm_hfp_ag(struct spa_source *source, char* buf)
static bool rfcomm_hfp_hf(struct spa_source *source, char* buf)
{
static const char separators[] = "\r\n:";
struct rfcomm *rfcomm = source->data;
struct impl *backend = rfcomm->backend;
unsigned int features;
unsigned int gain;
unsigned int selected_codec;
char* token;
char separators[] = "\r\n:";
token = strtok(buf, separators);
while (token != NULL)

View file

@ -2534,7 +2534,7 @@ static int a2dp_codec_switch_cmp(const void *a, const void *b)
}
/* Ensure there's a transport for at least one of the listed codecs */
int spa_bt_device_ensure_a2dp_codec(struct spa_bt_device *device, const struct a2dp_codec **codecs)
int spa_bt_device_ensure_a2dp_codec(struct spa_bt_device *device, const struct a2dp_codec * const *codecs)
{
struct spa_bt_a2dp_codec_switch *sw;
struct spa_bt_remote_endpoint *ep;

View file

@ -163,7 +163,7 @@ static void init_node(struct impl *this, struct node *node, uint32_t id)
static const struct a2dp_codec *get_a2dp_codec(enum spa_bluetooth_audio_codec id)
{
const struct a2dp_codec **c;
const struct a2dp_codec * const *c;
for (c = a2dp_codecs; *c; ++c)
if ((*c)->id == id)
@ -684,7 +684,9 @@ static int set_profile(struct impl *this, uint32_t profile, enum spa_bluetooth_a
*/
if (profile == DEVICE_PROFILE_A2DP && !(this->bt_dev->connected_profiles & SPA_BT_PROFILE_A2DP_SOURCE)) {
int ret;
const struct a2dp_codec *codec_list[2], **codecs, *a2dp_codec;
const struct a2dp_codec *codec_list[2];
const struct a2dp_codec * const *codecs;
const struct a2dp_codec *a2dp_codec;
a2dp_codec = get_a2dp_codec(codec);
if (a2dp_codec == NULL) {

View file

@ -463,7 +463,7 @@ struct spa_bt_device *spa_bt_device_find_by_address(struct spa_bt_monitor *monit
int spa_bt_device_add_profile(struct spa_bt_device *device, enum spa_bt_profile profile);
int spa_bt_device_connect_profile(struct spa_bt_device *device, enum spa_bt_profile profile);
int spa_bt_device_check_profiles(struct spa_bt_device *device, bool force);
int spa_bt_device_ensure_a2dp_codec(struct spa_bt_device *device, const struct a2dp_codec **codecs);
int spa_bt_device_ensure_a2dp_codec(struct spa_bt_device *device, const struct a2dp_codec * const *codecs);
bool spa_bt_device_supports_a2dp_codec(struct spa_bt_device *device, const struct a2dp_codec *codec);
const struct a2dp_codec **spa_bt_device_get_supported_a2dp_codecs(struct spa_bt_device *device, size_t *count);
int spa_bt_device_ensure_hfp_codec(struct spa_bt_device *device, unsigned int codec);

View file

@ -693,18 +693,19 @@ static int impl_node_send_command(void *object, const struct spa_command *comman
static void emit_node_info(struct impl *this, bool full)
{
bool is_ag = (this->transport->profile & SPA_BT_PROFILE_HEADSET_AUDIO_GATEWAY);
struct spa_dict_item ag_node_info_items[] = {
static const struct spa_dict_item hu_node_info_items[] = {
{ SPA_KEY_DEVICE_API, "bluez5" },
{ SPA_KEY_MEDIA_CLASS, "Audio/Sink" },
{ SPA_KEY_NODE_DRIVER, "true" },
};
const struct spa_dict_item ag_node_info_items[] = {
{ SPA_KEY_DEVICE_API, "bluez5" },
{ SPA_KEY_MEDIA_CLASS, "Stream/Input/Audio" },
{ "media.name", ((this->transport && this->transport->device->name) ?
this->transport->device->name : "HSP/HFP") },
};
struct spa_dict_item hu_node_info_items[] = {
{ SPA_KEY_DEVICE_API, "bluez5" },
{ SPA_KEY_MEDIA_CLASS, "Audio/Sink" },
{ SPA_KEY_NODE_DRIVER, "true" },
};
bool is_ag = (this->transport->profile & SPA_BT_PROFILE_HEADSET_AUDIO_GATEWAY);
uint64_t old = full ? this->info.change_mask : 0;
if (full)
@ -1311,7 +1312,7 @@ static const struct spa_dict_item info_items[] = {
static const struct spa_dict info = SPA_DICT_INIT_ARRAY(info_items);
struct spa_handle_factory spa_sco_sink_factory = {
const struct spa_handle_factory spa_sco_sink_factory = {
SPA_VERSION_HANDLE_FACTORY,
SPA_NAME_API_BLUEZ5_SCO_SINK,
&info,

View file

@ -722,20 +722,21 @@ static int impl_node_send_command(void *object, const struct spa_command *comman
static void emit_node_info(struct impl *this, bool full)
{
bool is_ag = this->transport && (this->transport->profile & SPA_BT_PROFILE_HEADSET_AUDIO_GATEWAY);
char latency[64] = "128/8000";
struct spa_dict_item ag_node_info_items[] = {
{ SPA_KEY_DEVICE_API, "bluez5" },
{ SPA_KEY_MEDIA_CLASS, "Stream/Output/Audio" },
{ SPA_KEY_NODE_LATENCY, latency },
{ "media.name", ((this->transport && this->transport->device->name) ?
this->transport->device->name : "HSP/HFP") },
};
struct spa_dict_item hu_node_info_items[] = {
static const struct spa_dict_item hu_node_info_items[] = {
{ SPA_KEY_DEVICE_API, "bluez5" },
{ SPA_KEY_MEDIA_CLASS, "Audio/Source" },
{ SPA_KEY_NODE_DRIVER, "true" },
};
char latency[64] = "128/8000";
const struct spa_dict_item ag_node_info_items[] = {
{ SPA_KEY_DEVICE_API, "bluez5" },
{ SPA_KEY_MEDIA_CLASS, "Stream/Output/Audio" },
{ SPA_KEY_NODE_LATENCY, latency },
{ "media.name", ((this->transport && this->transport->device->name) ?
this->transport->device->name : "HSP/HFP") },
};
bool is_ag = this->transport && (this->transport->profile & SPA_BT_PROFILE_HEADSET_AUDIO_GATEWAY);
uint64_t old = full ? this->info.change_mask : 0;
if (full)
@ -1372,7 +1373,7 @@ static const struct spa_dict_item info_items[] = {
static const struct spa_dict info = SPA_DICT_INIT_ARRAY(info_items);
struct spa_handle_factory spa_sco_source_factory = {
const struct spa_handle_factory spa_sco_source_factory = {
SPA_VERSION_HANDLE_FACTORY,
SPA_NAME_API_BLUEZ5_SCO_SOURCE,
&info,