[player] Add a index attribute to struct player_speaker_info + a getter
This commit is contained in:
parent
dc41f0d84c
commit
a983302b03
59
src/player.c
59
src/player.c
|
@ -164,6 +164,7 @@ struct speaker_get_param
|
||||||
{
|
{
|
||||||
uint64_t spk_id;
|
uint64_t spk_id;
|
||||||
uint32_t active_remote;
|
uint32_t active_remote;
|
||||||
|
uint32_t index;
|
||||||
const char *address;
|
const char *address;
|
||||||
struct player_speaker_info *spk_info;
|
struct player_speaker_info *spk_info;
|
||||||
};
|
};
|
||||||
|
@ -2516,10 +2517,11 @@ playback_seek(void *arg, int *retval)
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
device_to_speaker_info(struct player_speaker_info *spk, struct output_device *device)
|
device_to_speaker_info(struct player_speaker_info *spk, struct output_device *device, uint32_t index)
|
||||||
{
|
{
|
||||||
memset(spk, 0, sizeof(struct player_speaker_info));
|
memset(spk, 0, sizeof(struct player_speaker_info));
|
||||||
spk->id = device->id;
|
spk->id = device->id;
|
||||||
|
spk->index = index;
|
||||||
spk->active_remote = (uint32_t)device->id;
|
spk->active_remote = (uint32_t)device->id;
|
||||||
strncpy(spk->name, device->name, sizeof(spk->name));
|
strncpy(spk->name, device->name, sizeof(spk->name));
|
||||||
spk->name[sizeof(spk->name) - 1] = '\0';
|
spk->name[sizeof(spk->name) - 1] = '\0';
|
||||||
|
@ -2553,10 +2555,11 @@ speaker_enumerate(void *arg, int *retval)
|
||||||
struct spk_enum *spk_enum = arg;
|
struct spk_enum *spk_enum = arg;
|
||||||
struct output_device *device;
|
struct output_device *device;
|
||||||
struct player_speaker_info spk;
|
struct player_speaker_info spk;
|
||||||
|
int i;
|
||||||
|
|
||||||
for (device = outputs_list(); device; device = device->next)
|
for (device = outputs_list(), i = 0; device; device = device->next, i++)
|
||||||
{
|
{
|
||||||
device_to_speaker_info(&spk, device);
|
device_to_speaker_info(&spk, device, i);
|
||||||
spk_enum->cb(&spk, spk_enum->arg);
|
spk_enum->cb(&spk, spk_enum->arg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2569,13 +2572,14 @@ speaker_get_byid(void *arg, int *retval)
|
||||||
{
|
{
|
||||||
struct speaker_get_param *spk_param = arg;
|
struct speaker_get_param *spk_param = arg;
|
||||||
struct output_device *device;
|
struct output_device *device;
|
||||||
|
int i;
|
||||||
|
|
||||||
for (device = outputs_list(); device; device = device->next)
|
for (device = outputs_list(), i = 0; device; device = device->next, i++)
|
||||||
{
|
{
|
||||||
if ((device->advertised || device->selected)
|
if ((device->advertised || device->selected)
|
||||||
&& device->id == spk_param->spk_id)
|
&& device->id == spk_param->spk_id)
|
||||||
{
|
{
|
||||||
device_to_speaker_info(spk_param->spk_info, device);
|
device_to_speaker_info(spk_param->spk_info, device, i);
|
||||||
*retval = 0;
|
*retval = 0;
|
||||||
return COMMAND_END;
|
return COMMAND_END;
|
||||||
}
|
}
|
||||||
|
@ -2591,12 +2595,13 @@ speaker_get_byactiveremote(void *arg, int *retval)
|
||||||
{
|
{
|
||||||
struct speaker_get_param *spk_param = arg;
|
struct speaker_get_param *spk_param = arg;
|
||||||
struct output_device *device;
|
struct output_device *device;
|
||||||
|
int i;
|
||||||
|
|
||||||
for (device = outputs_list(); device; device = device->next)
|
for (device = outputs_list(), i = 0; device; device = device->next, i++)
|
||||||
{
|
{
|
||||||
if ((uint32_t)device->id == spk_param->active_remote)
|
if ((uint32_t)device->id == spk_param->active_remote)
|
||||||
{
|
{
|
||||||
device_to_speaker_info(spk_param->spk_info, device);
|
device_to_speaker_info(spk_param->spk_info, device, i);
|
||||||
*retval = 0;
|
*retval = 0;
|
||||||
return COMMAND_END;
|
return COMMAND_END;
|
||||||
}
|
}
|
||||||
|
@ -2614,20 +2619,41 @@ speaker_get_byaddress(void *arg, int *retval)
|
||||||
struct output_device *device;
|
struct output_device *device;
|
||||||
bool match_v4;
|
bool match_v4;
|
||||||
bool match_v6;
|
bool match_v6;
|
||||||
|
int i;
|
||||||
|
|
||||||
for (device = outputs_list(); device; device = device->next)
|
for (device = outputs_list(), i = 0; device; device = device->next, i++)
|
||||||
{
|
{
|
||||||
match_v4 = device->v4_address && (strcmp(spk_param->address, device->v4_address) == 0);
|
match_v4 = device->v4_address && (strcmp(spk_param->address, device->v4_address) == 0);
|
||||||
match_v6 = device->v6_address && (strcmp(spk_param->address, device->v6_address) == 0);
|
match_v6 = device->v6_address && (strcmp(spk_param->address, device->v6_address) == 0);
|
||||||
if (match_v4 || match_v6)
|
if (match_v4 || match_v6)
|
||||||
{
|
{
|
||||||
device_to_speaker_info(spk_param->spk_info, device);
|
device_to_speaker_info(spk_param->spk_info, device, i);
|
||||||
|
*retval = 0;
|
||||||
|
return COMMAND_END;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
*retval = -1;
|
||||||
|
return COMMAND_END;
|
||||||
|
}
|
||||||
|
|
||||||
|
static enum command_state
|
||||||
|
speaker_get_byindex(void *arg, int *retval)
|
||||||
|
{
|
||||||
|
struct speaker_get_param *spk_param = arg;
|
||||||
|
struct output_device *device;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for (device = outputs_list(), i = 0; device; device = device->next, i++)
|
||||||
|
{
|
||||||
|
if (i == spk_param->index)
|
||||||
|
{
|
||||||
|
device_to_speaker_info(spk_param->spk_info, device, i);
|
||||||
*retval = 0;
|
*retval = 0;
|
||||||
return COMMAND_END;
|
return COMMAND_END;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// No output device found with matching id
|
|
||||||
*retval = -1;
|
*retval = -1;
|
||||||
return COMMAND_END;
|
return COMMAND_END;
|
||||||
}
|
}
|
||||||
|
@ -3483,6 +3509,19 @@ player_speaker_get_byaddress(struct player_speaker_info *spk, const char *addres
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
player_speaker_get_byindex(struct player_speaker_info *spk, uint32_t index)
|
||||||
|
{
|
||||||
|
struct speaker_get_param param;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
param.index = index;
|
||||||
|
param.spk_info = spk;
|
||||||
|
|
||||||
|
ret = commands_exec_sync(cmdbase, speaker_get_byindex, NULL, ¶m);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
player_speaker_enable(uint64_t id)
|
player_speaker_enable(uint64_t id)
|
||||||
{
|
{
|
||||||
|
|
|
@ -30,6 +30,7 @@ enum player_seek_mode {
|
||||||
|
|
||||||
struct player_speaker_info {
|
struct player_speaker_info {
|
||||||
uint64_t id;
|
uint64_t id;
|
||||||
|
uint32_t index;
|
||||||
uint32_t active_remote;
|
uint32_t active_remote;
|
||||||
char name[255];
|
char name[255];
|
||||||
char output_type[50];
|
char output_type[50];
|
||||||
|
@ -106,6 +107,9 @@ player_speaker_get_byactiveremote(struct player_speaker_info *spk, uint32_t acti
|
||||||
int
|
int
|
||||||
player_speaker_get_byaddress(struct player_speaker_info *spk, const char *address);
|
player_speaker_get_byaddress(struct player_speaker_info *spk, const char *address);
|
||||||
|
|
||||||
|
int
|
||||||
|
player_speaker_get_byindex(struct player_speaker_info *spk, uint32_t index);
|
||||||
|
|
||||||
int
|
int
|
||||||
player_speaker_enable(uint64_t id);
|
player_speaker_enable(uint64_t id);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue