output/roar: export volume methods

Use these instead of exposing the internal roar_t struct.
This commit is contained in:
Max Kellermann
2011-09-17 19:33:51 +02:00
parent 5e22fe488e
commit 947848ebf6
4 changed files with 78 additions and 46 deletions

View File

@@ -30,16 +30,65 @@
#include <string.h>
#include <stdint.h>
#include <roaraudio.h>
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "roaraudio"
typedef struct roar
{
roar_vs_t * vss;
int err;
char *host;
char *name;
int role;
struct roar_connection con;
struct roar_audio_info info;
GMutex *lock;
volatile bool alive;
} roar_t;
static inline GQuark
roar_output_quark(void)
{
return g_quark_from_static_string("roar_output");
}
int
roar_output_get_volume(struct roar *roar)
{
g_mutex_lock(roar->lock);
if (roar->vss && roar->alive) {
float l, r;
int error;
roar_vs_volume_get(roar->vss, &l, &r, &error);
g_mutex_unlock(roar->lock);
return (l + r) * 50;
} else {
g_mutex_unlock(roar->lock);
return 0;
}
}
bool
roar_output_set_volume(struct roar *roar, unsigned volume)
{
g_mutex_lock(roar->lock);
if (roar->vss && roar->alive) {
assert(volume <= 100);
int error;
float level = volume / 100.0;
roar_vs_volume_mono(roar->vss, level, &error);
g_mutex_unlock(roar->lock);
return true;
} else {
g_mutex_unlock(roar->lock);
return false;
}
}
static void
roar_configure(struct roar * self, const struct config_param *param)
{

View File

@@ -22,20 +22,14 @@
#ifndef __ROAR_OUTPUT_H
#define __ROAR_OUTPUT_H
#include <roaraudio.h>
#include <glib.h>
#include <stdbool.h>
typedef struct roar
{
roar_vs_t * vss;
int err;
char *host;
char *name;
int role;
struct roar_connection con;
struct roar_audio_info info;
GMutex *lock;
volatile bool alive;
} roar_t;
struct roar;
int
roar_output_get_volume(struct roar *roar);
bool
roar_output_set_volume(struct roar *roar, unsigned volume);
#endif