output/Internal: add various trivial getter methods

This commit is contained in:
Max Kellermann 2016-12-29 23:23:28 +01:00
parent 61a151c803
commit 4484411a77
6 changed files with 38 additions and 13 deletions

View File

@ -45,7 +45,7 @@ output_mixer_get_volume(const AudioOutput &ao)
} catch (const std::runtime_error &e) { } catch (const std::runtime_error &e) {
FormatError(e, FormatError(e,
"Failed to read mixer for '%s'", "Failed to read mixer for '%s'",
ao.name); ao.GetName());
return -1; return -1;
} }
} }
@ -88,7 +88,7 @@ output_mixer_set_volume(AudioOutput &ao, unsigned volume)
} catch (const std::runtime_error &e) { } catch (const std::runtime_error &e) {
FormatError(e, FormatError(e,
"Failed to set mixer for '%s'", "Failed to set mixer for '%s'",
ao.name); ao.GetName());
return false; return false;
} }
} }

View File

@ -42,7 +42,7 @@ AudioOutput::~AudioOutput()
void void
audio_output_free(AudioOutput *ao) audio_output_free(AudioOutput *ao)
{ {
assert(!ao->open); assert(!ao->IsOpen());
assert(!ao->fail_timer.IsDefined()); assert(!ao->fail_timer.IsDefined());
assert(!ao->thread.IsDefined()); assert(!ao->thread.IsDefined());

View File

@ -288,14 +288,38 @@ public:
void BeginDestroy(); void BeginDestroy();
void FinishDestroy(); void FinishDestroy();
const char *GetName() const {
return name;
}
/**
* Caller must lock the mutex.
*/
bool IsEnabled() const {
return enabled;
}
/**
* Caller must lock the mutex.
*/
bool IsOpen() const { bool IsOpen() const {
return open; return open;
} }
/**
* Caller must lock the mutex.
*/
bool IsCommandFinished() const { bool IsCommandFinished() const {
return command == Command::NONE; return command == Command::NONE;
} }
/**
* Caller must lock the mutex.
*/
const std::exception_ptr &GetLastError() const {
return last_error;
}
/** /**
* Waits for command completion. * Waits for command completion.
* *

View File

@ -76,9 +76,9 @@ MultipleOutputs::Configure(EventLoop &event_loop,
auto output = LoadOutput(event_loop, replay_gain_config, auto output = LoadOutput(event_loop, replay_gain_config,
mixer_listener, mixer_listener,
client, *param); client, *param);
if (FindByName(output->name) != nullptr) if (FindByName(output->GetName()) != nullptr)
throw FormatRuntimeError("output devices with identical " throw FormatRuntimeError("output devices with identical "
"names: %s", output->name); "names: %s", output->GetName());
outputs.push_back(output); outputs.push_back(output);
} }
@ -97,7 +97,7 @@ AudioOutput *
MultipleOutputs::FindByName(const char *name) const MultipleOutputs::FindByName(const char *name) const
{ {
for (auto i : outputs) for (auto i : outputs)
if (strcmp(i->name, name) == 0) if (strcmp(i->GetName(), name) == 0)
return i; return i;
return nullptr; return nullptr;
@ -217,13 +217,13 @@ MultipleOutputs::Open(const AudioFormat audio_format,
for (auto ao : outputs) { for (auto ao : outputs) {
const ScopeLock lock(ao->mutex); const ScopeLock lock(ao->mutex);
if (ao->enabled) if (ao->IsEnabled())
enabled = true; enabled = true;
if (ao->open) if (ao->IsOpen())
ret = true; ret = true;
else if (ao->last_error && !first_error) else if (!first_error)
first_error = ao->last_error; first_error = ao->GetLastError();
} }
if (!enabled) { if (!enabled) {
@ -265,7 +265,7 @@ MultipleOutputs::ClearTailChunk(const MusicChunk *chunk,
/* this mutex will be unlocked by the caller when it's /* this mutex will be unlocked by the caller when it's
ready */ ready */
ao->mutex.lock(); ao->mutex.lock();
locked[i] = ao->open; locked[i] = ao->IsOpen();
if (!locked[i]) { if (!locked[i]) {
ao->mutex.unlock(); ao->mutex.unlock();

View File

@ -37,6 +37,6 @@ printAudioDevices(Response &r, const MultipleOutputs &outputs)
r.Format("outputid: %i\n" r.Format("outputid: %i\n"
"outputname: %s\n" "outputname: %s\n"
"outputenabled: %i\n", "outputenabled: %i\n",
i, ao.name, ao.enabled); i, ao.GetName(), ao.IsEnabled());
} }
} }

View File

@ -45,7 +45,8 @@ audio_output_state_save(BufferedOutputStream &os,
const AudioOutput &ao = outputs.Get(i); const AudioOutput &ao = outputs.Get(i);
const ScopeLock lock(ao.mutex); const ScopeLock lock(ao.mutex);
os.Format(AUDIO_DEVICE_STATE "%d:%s\n", ao.enabled, ao.name); os.Format(AUDIO_DEVICE_STATE "%d:%s\n",
ao.IsEnabled(), ao.GetName());
} }
} }