output/Thread: convert pointer to reference
This commit is contained in:
parent
67cfbfc2f3
commit
12ecfdd423
|
@ -475,7 +475,7 @@ private:
|
||||||
*/
|
*/
|
||||||
bool WaitForDelay();
|
bool WaitForDelay();
|
||||||
|
|
||||||
bool PlayChunk(const MusicChunk *chunk);
|
bool PlayChunk(const MusicChunk &chunk);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Plays all remaining chunks, until the tail of the pipe has
|
* Plays all remaining chunks, until the tail of the pipe has
|
||||||
|
|
|
@ -312,37 +312,34 @@ AudioOutput::WaitForDelay()
|
||||||
}
|
}
|
||||||
|
|
||||||
static ConstBuffer<void>
|
static ConstBuffer<void>
|
||||||
ao_chunk_data(AudioOutput *ao, const MusicChunk *chunk,
|
ao_chunk_data(AudioOutput &ao, const MusicChunk &chunk,
|
||||||
Filter *replay_gain_filter,
|
Filter *replay_gain_filter,
|
||||||
unsigned *replay_gain_serial_p)
|
unsigned *replay_gain_serial_p)
|
||||||
{
|
{
|
||||||
assert(chunk != nullptr);
|
assert(!chunk.IsEmpty());
|
||||||
assert(!chunk->IsEmpty());
|
assert(chunk.CheckFormat(ao.in_audio_format));
|
||||||
assert(chunk->CheckFormat(ao->in_audio_format));
|
|
||||||
|
|
||||||
ConstBuffer<void> data(chunk->data, chunk->length);
|
ConstBuffer<void> data(chunk.data, chunk.length);
|
||||||
|
|
||||||
(void)ao;
|
assert(data.size % ao.in_audio_format.GetFrameSize() == 0);
|
||||||
|
|
||||||
assert(data.size % ao->in_audio_format.GetFrameSize() == 0);
|
|
||||||
|
|
||||||
if (!data.IsEmpty() && replay_gain_filter != nullptr) {
|
if (!data.IsEmpty() && replay_gain_filter != nullptr) {
|
||||||
replay_gain_filter_set_mode(*replay_gain_filter,
|
replay_gain_filter_set_mode(*replay_gain_filter,
|
||||||
ao->replay_gain_mode);
|
ao.replay_gain_mode);
|
||||||
|
|
||||||
if (chunk->replay_gain_serial != *replay_gain_serial_p) {
|
if (chunk.replay_gain_serial != *replay_gain_serial_p) {
|
||||||
replay_gain_filter_set_info(*replay_gain_filter,
|
replay_gain_filter_set_info(*replay_gain_filter,
|
||||||
chunk->replay_gain_serial != 0
|
chunk.replay_gain_serial != 0
|
||||||
? &chunk->replay_gain_info
|
? &chunk.replay_gain_info
|
||||||
: nullptr);
|
: nullptr);
|
||||||
*replay_gain_serial_p = chunk->replay_gain_serial;
|
*replay_gain_serial_p = chunk.replay_gain_serial;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
data = replay_gain_filter->FilterPCM(data);
|
data = replay_gain_filter->FilterPCM(data);
|
||||||
} catch (const std::runtime_error &e) {
|
} catch (const std::runtime_error &e) {
|
||||||
FormatError(e, "\"%s\" [%s] failed to filter",
|
FormatError(e, "\"%s\" [%s] failed to filter",
|
||||||
ao->name, ao->plugin.name);
|
ao.name, ao.plugin.name);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -351,21 +348,21 @@ ao_chunk_data(AudioOutput *ao, const MusicChunk *chunk,
|
||||||
}
|
}
|
||||||
|
|
||||||
static ConstBuffer<void>
|
static ConstBuffer<void>
|
||||||
ao_filter_chunk(AudioOutput *ao, const MusicChunk *chunk)
|
ao_filter_chunk(AudioOutput &ao, const MusicChunk &chunk)
|
||||||
{
|
{
|
||||||
ConstBuffer<void> data =
|
ConstBuffer<void> data =
|
||||||
ao_chunk_data(ao, chunk, ao->replay_gain_filter_instance,
|
ao_chunk_data(ao, chunk, ao.replay_gain_filter_instance,
|
||||||
&ao->replay_gain_serial);
|
&ao.replay_gain_serial);
|
||||||
if (data.IsEmpty())
|
if (data.IsEmpty())
|
||||||
return data;
|
return data;
|
||||||
|
|
||||||
/* cross-fade */
|
/* cross-fade */
|
||||||
|
|
||||||
if (chunk->other != nullptr) {
|
if (chunk.other != nullptr) {
|
||||||
ConstBuffer<void> other_data =
|
ConstBuffer<void> other_data =
|
||||||
ao_chunk_data(ao, chunk->other,
|
ao_chunk_data(ao, *chunk.other,
|
||||||
ao->other_replay_gain_filter_instance,
|
ao.other_replay_gain_filter_instance,
|
||||||
&ao->other_replay_gain_serial);
|
&ao.other_replay_gain_serial);
|
||||||
if (other_data.IsNull())
|
if (other_data.IsNull())
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
|
@ -380,7 +377,7 @@ ao_filter_chunk(AudioOutput *ao, const MusicChunk *chunk)
|
||||||
if (data.size > other_data.size)
|
if (data.size > other_data.size)
|
||||||
data.size = other_data.size;
|
data.size = other_data.size;
|
||||||
|
|
||||||
float mix_ratio = chunk->mix_ratio;
|
float mix_ratio = chunk.mix_ratio;
|
||||||
if (mix_ratio >= 0)
|
if (mix_ratio >= 0)
|
||||||
/* reverse the mix ratio (because the
|
/* reverse the mix ratio (because the
|
||||||
arguments to pcm_mix() are reversed), but
|
arguments to pcm_mix() are reversed), but
|
||||||
|
@ -389,14 +386,14 @@ ao_filter_chunk(AudioOutput *ao, const MusicChunk *chunk)
|
||||||
case */
|
case */
|
||||||
mix_ratio = 1.0 - mix_ratio;
|
mix_ratio = 1.0 - mix_ratio;
|
||||||
|
|
||||||
void *dest = ao->cross_fade_buffer.Get(other_data.size);
|
void *dest = ao.cross_fade_buffer.Get(other_data.size);
|
||||||
memcpy(dest, other_data.data, other_data.size);
|
memcpy(dest, other_data.data, other_data.size);
|
||||||
if (!pcm_mix(ao->cross_fade_dither, dest, data.data, data.size,
|
if (!pcm_mix(ao.cross_fade_dither, dest, data.data, data.size,
|
||||||
ao->in_audio_format.format,
|
ao.in_audio_format.format,
|
||||||
mix_ratio)) {
|
mix_ratio)) {
|
||||||
FormatError(output_domain,
|
FormatError(output_domain,
|
||||||
"Cannot cross-fade format %s",
|
"Cannot cross-fade format %s",
|
||||||
sample_format_to_string(ao->in_audio_format.format));
|
sample_format_to_string(ao.in_audio_format.format));
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -407,30 +404,30 @@ ao_filter_chunk(AudioOutput *ao, const MusicChunk *chunk)
|
||||||
/* apply filter chain */
|
/* apply filter chain */
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return ao->filter_instance->FilterPCM(data);
|
return ao.filter_instance->FilterPCM(data);
|
||||||
} catch (const std::runtime_error &e) {
|
} catch (const std::runtime_error &e) {
|
||||||
FormatError(e, "\"%s\" [%s] failed to filter",
|
FormatError(e, "\"%s\" [%s] failed to filter",
|
||||||
ao->name, ao->plugin.name);
|
ao.name, ao.plugin.name);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool
|
inline bool
|
||||||
AudioOutput::PlayChunk(const MusicChunk *chunk)
|
AudioOutput::PlayChunk(const MusicChunk &chunk)
|
||||||
{
|
{
|
||||||
assert(filter_instance != nullptr);
|
assert(filter_instance != nullptr);
|
||||||
|
|
||||||
if (tags && gcc_unlikely(chunk->tag != nullptr)) {
|
if (tags && gcc_unlikely(chunk.tag != nullptr)) {
|
||||||
const ScopeUnlock unlock(mutex);
|
const ScopeUnlock unlock(mutex);
|
||||||
try {
|
try {
|
||||||
ao_plugin_send_tag(this, *chunk->tag);
|
ao_plugin_send_tag(this, *chunk.tag);
|
||||||
} catch (const std::runtime_error &e) {
|
} catch (const std::runtime_error &e) {
|
||||||
FormatError(e, "Failed to send tag to \"%s\" [%s]",
|
FormatError(e, "Failed to send tag to \"%s\" [%s]",
|
||||||
name, plugin.name);
|
name, plugin.name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
auto data = ConstBuffer<char>::FromVoid(ao_filter_chunk(this, chunk));
|
auto data = ConstBuffer<char>::FromVoid(ao_filter_chunk(*this, chunk));
|
||||||
if (data.IsNull()) {
|
if (data.IsNull()) {
|
||||||
Close(false);
|
Close(false);
|
||||||
|
|
||||||
|
@ -508,7 +505,7 @@ AudioOutput::Play()
|
||||||
n = 0;
|
n = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!PlayChunk(chunk))
|
if (!PlayChunk(*chunk))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
pipe.Consume(*chunk);
|
pipe.Consume(*chunk);
|
||||||
|
|
Loading…
Reference in New Issue