Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

output modules #210

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
7 changes: 7 additions & 0 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@
#include "git-version.h"
#include "logging.h"
#include "output.h"
#ifdef HAVE_GST
# include "output_gstreamer.h"
#endif
#include "upnp_service.h"
#include "upnp_control.h"
#include "upnp_device.h"
Expand Down Expand Up @@ -229,6 +232,10 @@ int main(int argc, char **argv)
g_thread_init (NULL); // Was necessary < glib 2.32, deprecated since.
#endif

#ifdef HAVE_GST
output_append_module(&gstreamer_output);
#endif

if (!process_cmdline(argc, argv)) {
return EXIT_FAILURE;
}
Expand Down
68 changes: 35 additions & 33 deletions src/output.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,54 +42,56 @@
#endif
#include "output.h"

static struct output_module *modules[] = {
#ifdef HAVE_GST
&gstreamer_output,
#else
// this will be a runtime error, but there is not much point
// in waiting till then.
#error "No output configured. You need to ./configure --with-gstreamer"
#endif
};
static struct output_module *modules = NULL;

static struct output_module *output_module = NULL;

void output_dump_modules(void)
void output_append_module(struct output_module *new)
{
int count;
if (new == NULL)
return;
new->next = modules;
modules = new;
}

count = sizeof(modules) / sizeof(struct output_module *);
if (count == 0) {
void output_dump_modules(void)
{
struct output_module *module = modules;
if (modules == NULL)
puts(" NONE!");
} else {
int i;
for (i=0; i<count; i++) {
else
{
int i = 0;
while (module != NULL)
{
printf("Available output: %s\t%s%s\n",
modules[i]->shortname,
modules[i]->description,
modules->shortname,
modules->description,
(i==0) ? " (default)" : "");
i = 1;
module = module->next;
}
}
}

int output_init(const char *shortname)
{
int count;

count = sizeof(modules) / sizeof(struct output_module *);
if (count == 0) {
struct output_module *module = modules;
if (module == NULL) {
Log_error("output", "No output module available");
return -1;
}

if (shortname == NULL) {
output_module = modules[0];
output_module = module;
} else {
int i;
for (i=0; i<count; i++) {
if (strcmp(modules[i]->shortname, shortname)==0) {
output_module = modules[i];
while (module != NULL)
{
if (strcmp(module->shortname, shortname)==0) {
output_module = module;
break;
}
module = module->next;
}
}

Expand Down Expand Up @@ -132,16 +134,16 @@ int output_loop()

int output_add_options(GOptionContext *ctx)
{
int count, i;

count = sizeof(modules) / sizeof(struct output_module *);
for (i = 0; i < count; ++i) {
if (modules[i]->add_options) {
int result = modules[i]->add_options(ctx);
struct output_module *module = modules;
while (module != NULL)
{
if (module->add_options) {
int result = module->add_options(ctx);
if (result != 0) {
return result;
}
}
module = module->next;
}

return 0;
Expand Down
3 changes: 3 additions & 0 deletions src/output.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ typedef void (*output_transition_cb_t)(enum PlayFeedback);
// callback with changes we send back to the controlling layer.
typedef void (*output_update_meta_cb_t)(const struct SongMetaData *);

struct output_module;
void output_append_module(struct output_module *new);

int output_init(const char *shortname);
int output_add_options(GOptionContext *ctx);
void output_dump_modules(void);
Expand Down
1 change: 1 addition & 0 deletions src/output_gstreamer.c
Original file line number Diff line number Diff line change
Expand Up @@ -595,4 +595,5 @@ struct output_module gstreamer_output = {
.set_volume = output_gstreamer_set_volume,
.get_mute = output_gstreamer_get_mute,
.set_mute = output_gstreamer_set_mute,
.next = NULL,
};
2 changes: 2 additions & 0 deletions src/output_module.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ struct output_module {
int (*set_volume)(float);
int (*get_mute)(int *);
int (*set_mute)(int);

struct output_module *next;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that this struct is part of the public interface how to implement an output module, the linked list pointer is probably not part of what we'd like to expose.

So the maintenance of the list should be outside of this struct, even if it is more cumbersome than an intrusive data structure. Public interfaces should be as lean and clean as possible and not leak internal implementation details.

};

#endif