2009-02-10 18:51:39 +01:00
|
|
|
/*
|
2015-01-01 19:48:13 +01:00
|
|
|
* Copyright (C) 2003-2015 The Music Player Daemon Project
|
2009-02-10 18:51:39 +01:00
|
|
|
* http://www.musicpd.org
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
2009-03-13 18:43:16 +01:00
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2009-02-10 18:51:39 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Saving and loading the audio output states to/from the state file.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2009-11-12 09:12:38 +01:00
|
|
|
#include "config.h"
|
2013-01-02 19:52:57 +01:00
|
|
|
#include "OutputState.hxx"
|
2014-01-27 08:20:25 +01:00
|
|
|
#include "MultipleOutputs.hxx"
|
2014-01-28 11:42:54 +01:00
|
|
|
#include "Internal.hxx"
|
|
|
|
#include "Domain.hxx"
|
2013-09-27 22:31:24 +02:00
|
|
|
#include "Log.hxx"
|
2014-08-07 18:35:57 +02:00
|
|
|
#include "fs/io/BufferedOutputStream.hxx"
|
2015-11-06 09:09:02 +01:00
|
|
|
#include "util/StringCompare.hxx"
|
2009-02-10 18:51:39 +01:00
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#define AUDIO_DEVICE_STATE "audio_device_state:"
|
|
|
|
|
2009-10-08 15:22:39 +02:00
|
|
|
unsigned audio_output_state_version;
|
|
|
|
|
2009-02-10 18:51:39 +01:00
|
|
|
void
|
2014-07-30 20:58:14 +02:00
|
|
|
audio_output_state_save(BufferedOutputStream &os,
|
|
|
|
const MultipleOutputs &outputs)
|
2009-02-10 18:51:39 +01:00
|
|
|
{
|
2014-01-27 08:20:25 +01:00
|
|
|
for (unsigned i = 0, n = outputs.Size(); i != n; ++i) {
|
2014-01-28 11:34:09 +01:00
|
|
|
const AudioOutput &ao = outputs.Get(i);
|
2009-02-10 18:51:39 +01:00
|
|
|
|
2014-07-30 20:58:14 +02:00
|
|
|
os.Format(AUDIO_DEVICE_STATE "%d:%s\n", ao.enabled, ao.name);
|
2009-02-10 18:51:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-15 16:57:37 +02:00
|
|
|
bool
|
2014-01-27 08:20:25 +01:00
|
|
|
audio_output_state_read(const char *line, MultipleOutputs &outputs)
|
2009-02-10 18:51:39 +01:00
|
|
|
{
|
2009-07-15 16:57:37 +02:00
|
|
|
long value;
|
|
|
|
char *endptr;
|
|
|
|
const char *name;
|
2009-02-10 18:51:39 +01:00
|
|
|
|
2013-11-28 18:48:35 +01:00
|
|
|
if (!StringStartsWith(line, AUDIO_DEVICE_STATE))
|
2009-07-15 16:57:37 +02:00
|
|
|
return false;
|
2009-02-10 18:51:39 +01:00
|
|
|
|
2009-07-15 16:57:37 +02:00
|
|
|
line += sizeof(AUDIO_DEVICE_STATE) - 1;
|
2009-02-10 18:51:39 +01:00
|
|
|
|
2009-07-15 16:57:37 +02:00
|
|
|
value = strtol(line, &endptr, 10);
|
|
|
|
if (*endptr != ':' || (value != 0 && value != 1))
|
|
|
|
return false;
|
2009-02-10 18:51:39 +01:00
|
|
|
|
2009-07-15 16:57:37 +02:00
|
|
|
if (value != 0)
|
|
|
|
/* state is "enabled": no-op */
|
|
|
|
return true;
|
2009-02-10 18:51:39 +01:00
|
|
|
|
2009-07-15 16:57:37 +02:00
|
|
|
name = endptr + 1;
|
2014-01-28 11:34:09 +01:00
|
|
|
AudioOutput *ao = outputs.FindByName(name);
|
2009-07-15 16:57:37 +02:00
|
|
|
if (ao == NULL) {
|
2013-09-27 22:31:24 +02:00
|
|
|
FormatDebug(output_domain,
|
|
|
|
"Ignoring device state for '%s'", name);
|
2009-07-15 16:57:37 +02:00
|
|
|
return true;
|
2009-02-10 18:51:39 +01:00
|
|
|
}
|
2009-07-15 16:57:37 +02:00
|
|
|
|
|
|
|
ao->enabled = false;
|
|
|
|
return true;
|
2009-02-10 18:51:39 +01:00
|
|
|
}
|
2009-10-08 15:22:39 +02:00
|
|
|
|
|
|
|
unsigned
|
|
|
|
audio_output_state_get_version(void)
|
|
|
|
{
|
|
|
|
return audio_output_state_version;
|
|
|
|
}
|