summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichał Cichoń <michcic@gmail.com>2015-12-05 16:05:51 +0100
committerMichał Cichoń <michcic@gmail.com>2015-12-05 16:05:51 +0100
commitb0176f24ac3e68ef314a9a4ab87f6b2248777614 (patch)
tree99d27abdbc7d46e4af5bf563173c9edac6a0e1d7
parentb7a10d561acfa4cc7f8ae15722a7de28ee961d03 (diff)
downloadpianobar-windows-b0176f24ac3e68ef314a9a4ab87f6b2248777614.tar.gz
pianobar-windows-b0176f24ac3e68ef314a9a4ab87f6b2248777614.tar.bz2
pianobar-windows-b0176f24ac3e68ef314a9a4ab87f6b2248777614.zip
Add 'player' configuration option to select player back end. Current valid values:
- 'ds' - for Direct Show - 'mf' - for Windows Media Foundation (default) If not present, backends will be initialized in order: mf, ds
-rw-r--r--src/main.c11
-rw-r--r--src/player/backends/direct_show.c1
-rw-r--r--src/player/backends/media_foundation.cpp1
-rw-r--r--src/player/player2.c11
-rw-r--r--src/player/player2.h2
-rw-r--r--src/player/player2_private.h1
-rw-r--r--src/settings.c5
-rw-r--r--src/settings.h1
8 files changed, 28 insertions, 5 deletions
diff --git a/src/main.c b/src/main.c
index 900e56e..99793f3 100644
--- a/src/main.c
+++ b/src/main.c
@@ -337,11 +337,18 @@ int main (int argc, char **argv) {
BarConsoleSetTitle (TITLE);
/* init some things */
- BarPlayer2Init (&app.player);
-
BarSettingsInit (&app.settings);
BarSettingsRead (&app.settings);
+ if (!BarPlayer2Init (&app.player, app.settings.player))
+ {
+ if (app.settings.player)
+ BarUiMsg(&app.settings, MSG_ERR, "Player \"%s\" initialization failed.", app.settings.player);
+ else
+ BarUiMsg(&app.settings, MSG_ERR, "Player initialization failed.");
+ return 0;
+ }
+
PianoReturn_t pret;
if ((pret = PianoInit (&app.ph, app.settings.partnerUser,
app.settings.partnerPassword, app.settings.device,
diff --git a/src/player/backends/direct_show.c b/src/player/backends/direct_show.c
index d6597c0..111f042 100644
--- a/src/player/backends/direct_show.c
+++ b/src/player/backends/direct_show.c
@@ -442,6 +442,7 @@ static bool DSPlayerIsFinished(player2_t player)
player2_iface player2_direct_show =
{
+ .Id = "ds",
.Name = "Direct Show",
.Create = DSPlayerCreate,
.Destroy = DSPlayerDestroy,
diff --git a/src/player/backends/media_foundation.cpp b/src/player/backends/media_foundation.cpp
index 749a6f3..6aa0d00 100644
--- a/src/player/backends/media_foundation.cpp
+++ b/src/player/backends/media_foundation.cpp
@@ -1088,6 +1088,7 @@ extern "C" bool WMFPlayerIsFinished(player2_t player)
extern "C" player2_iface player2_windows_media_foundation =
{
+ /*.Id =*/ "mf",
/*.Name =*/ "Windows Media Foundation",
/*.Create =*/ WMFPlayerCreate,
/*.Destroy =*/ WMFPlayerDestroy,
diff --git a/src/player/player2.c b/src/player/player2.c
index c95600c..cd9beae 100644
--- a/src/player/player2.c
+++ b/src/player/player2.c
@@ -28,6 +28,7 @@ THE SOFTWARE.
#include "config.h"
#include "player2_private.h"
#include <stdlib.h>
+#include <string.h>
#include <memory.h>
# define length_of(x) (sizeof(x)/sizeof(*(x)))
@@ -44,7 +45,7 @@ struct _player_t
player2_t player;
};
-bool BarPlayer2Init(player2_t* outPlayer)
+bool BarPlayer2Init(player2_t* outPlayer, const char* defaultPlayer)
{
player2_t player;
struct _player_t result;
@@ -56,7 +57,13 @@ bool BarPlayer2Init(player2_t* outPlayer)
{
player2_iface* backend = player2_backends[i];
- result.player = backend->Create();
+ bool acceptPlayer = true;
+ if (defaultPlayer && !(strcmp(backend->Id, defaultPlayer) == 0))
+ acceptPlayer = false;
+
+ if (acceptPlayer)
+ result.player = backend->Create();
+
if (result.player)
{
result.backend = backend;
diff --git a/src/player/player2.h b/src/player/player2.h
index d50d76f..710b35d 100644
--- a/src/player/player2.h
+++ b/src/player/player2.h
@@ -31,7 +31,7 @@ THE SOFTWARE.
typedef struct _player_t *player2_t;
-bool BarPlayer2Init(player2_t* outPlayer);
+bool BarPlayer2Init(player2_t* outPlayer, const char* defaultPlayer);
void BarPlayer2Destroy(player2_t player);
void BarPlayer2SetVolume(player2_t player, float volume);
float BarPlayer2GetVolume(player2_t player);
diff --git a/src/player/player2_private.h b/src/player/player2_private.h
index 054b81f..757a07e 100644
--- a/src/player/player2_private.h
+++ b/src/player/player2_private.h
@@ -8,6 +8,7 @@
typedef struct _player2_iface
{
+ const char* Id;
const char* Name;
player2_t (*Create) ();
void (*Destroy) (player2_t player);
diff --git a/src/settings.c b/src/settings.c
index d58eb5c..0765bc8 100644
--- a/src/settings.c
+++ b/src/settings.c
@@ -131,6 +131,7 @@ void BarSettingsDestroy (BarSettings_t *settings) {
free (settings->npStationFormat);
free (settings->listSongFormat);
free (settings->titleFormat);
+ free (settings->player);
free (settings->fifo);
free (settings->rpcHost);
free (settings->rpcTlsPort);
@@ -177,6 +178,7 @@ void BarSettingsRead (BarSettings_t *settings) {
settings->npStationFormat = strdup ("Station \"%n\" (%i)");
settings->listSongFormat = strdup ("%i) %a - %t%r");
settings->titleFormat = strdup (TITLE " - \"%t\" by \"%a\" on \"%l\"%r%@%s");
+ settings->player = NULL;
settings->rpcHost = strdup (PIANO_RPC_HOST);
settings->rpcTlsPort = NULL;
settings->partnerUser = strdup ("android");
@@ -332,6 +334,9 @@ void BarSettingsRead (BarSettings_t *settings) {
} else if (streq ("format_title", key)) {
free (settings->titleFormat);
settings->titleFormat = strdup (val);
+ } else if (streq ("player", key)) {
+ free (settings->player);
+ settings->player = strdup (val);
} else if (streq ("fifo", key)) {
free (settings->fifo);
settings->fifo = BarSettingsExpandTilde (val, userhome);
diff --git a/src/settings.h b/src/settings.h
index 8718b34..78d0e45 100644
--- a/src/settings.h
+++ b/src/settings.h
@@ -102,6 +102,7 @@ typedef struct {
char *npStationFormat;
char *listSongFormat;
char *titleFormat;
+ char *player;
char *fifo;
char *rpcHost, *rpcTlsPort, *partnerUser, *partnerPassword, *device, *inkey, *outkey, *caBundle;
char keys[BAR_KS_COUNT];