2009-02-10 18:51:39 +01:00
|
|
|
/*
|
2017-01-03 20:48:59 +01:00
|
|
|
* Copyright 2003-2017 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"
|
2017-04-28 21:42:24 +02:00
|
|
|
#include "State.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 <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) {
|
2017-02-27 22:55:20 +01:00
|
|
|
const auto &ao = outputs.Get(i);
|
2017-01-03 07:11:57 +01:00
|
|
|
const std::lock_guard<Mutex> lock(ao.mutex);
|
2009-02-10 18:51:39 +01:00
|
|
|
|
2016-12-29 23:23:28 +01:00
|
|
|
os.Format(AUDIO_DEVICE_STATE "%d:%s\n",
|
|
|
|
ao.IsEnabled(), ao.GetName());
|
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
|
|
|
|
2015-11-11 15:34:36 +01:00
|
|
|
line = StringAfterPrefix(line, AUDIO_DEVICE_STATE);
|
|
|
|
if (line == nullptr)
|
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
|
|
|
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;
|
2017-02-27 22:55:20 +01:00
|
|
|
auto *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
|
|
|
|
2017-02-27 22:55:20 +01:00
|
|
|
ao->LockSetEnabled(false);
|
2009-07-15 16:57:37 +02:00
|
|
|
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;
|
|
|
|
}
|