Merge branch 'v0.22.x'
This commit is contained in:
@@ -29,6 +29,7 @@
|
||||
#include "pcm/Convert.hxx"
|
||||
#include "fs/Path.hxx"
|
||||
#include "fs/NarrowPath.hxx"
|
||||
#include "io/FileDescriptor.hxx"
|
||||
#include "util/ConstBuffer.hxx"
|
||||
#include "util/StaticFifoBuffer.hxx"
|
||||
#include "util/OptionDef.hxx"
|
||||
@@ -101,26 +102,21 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
try {
|
||||
const auto c = ParseCommandLine(argc, argv);
|
||||
static void
|
||||
RunConvert(PcmConvert &convert, size_t in_frame_size,
|
||||
FileDescriptor in_fd, FileDescriptor out_fd)
|
||||
{
|
||||
in_fd.SetBinaryMode();
|
||||
out_fd.SetBinaryMode();
|
||||
|
||||
SetLogThreshold(c.verbose ? LogLevel::DEBUG : LogLevel::INFO);
|
||||
const GlobalInit init(c.config_path);
|
||||
|
||||
const size_t in_frame_size = c.in_audio_format.GetFrameSize();
|
||||
|
||||
PcmConvert state(c.in_audio_format, c.out_audio_format);
|
||||
|
||||
StaticFifoBuffer<uint8_t, 4096> buffer;
|
||||
StaticFifoBuffer<std::byte, 4096> buffer;
|
||||
|
||||
while (true) {
|
||||
{
|
||||
const auto dest = buffer.Write();
|
||||
assert(!dest.empty());
|
||||
|
||||
ssize_t nbytes = read(0, dest.data, dest.size);
|
||||
ssize_t nbytes = in_fd.Read(dest.data, dest.size);
|
||||
if (nbytes <= 0)
|
||||
break;
|
||||
|
||||
@@ -136,20 +132,31 @@ try {
|
||||
|
||||
buffer.Consume(src.size);
|
||||
|
||||
auto output = state.Convert({src.data, src.size});
|
||||
|
||||
[[maybe_unused]] ssize_t ignored = write(1, output.data,
|
||||
output.size);
|
||||
auto output = convert.Convert({src.data, src.size});
|
||||
out_fd.FullWrite(output.data, output.size);
|
||||
}
|
||||
|
||||
while (true) {
|
||||
auto output = state.Flush();
|
||||
auto output = convert.Flush();
|
||||
if (output.IsNull())
|
||||
break;
|
||||
|
||||
[[maybe_unused]] ssize_t ignored = write(1, output.data,
|
||||
output.size);
|
||||
out_fd.FullWrite(output.data, output.size);
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
try {
|
||||
const auto c = ParseCommandLine(argc, argv);
|
||||
|
||||
SetLogThreshold(c.verbose ? LogLevel::DEBUG : LogLevel::INFO);
|
||||
const GlobalInit init(c.config_path);
|
||||
|
||||
PcmConvert state(c.in_audio_format, c.out_audio_format);
|
||||
RunConvert(state, c.in_audio_format.GetFrameSize(),
|
||||
FileDescriptor(STDIN_FILENO),
|
||||
FileDescriptor(STDOUT_FILENO));
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
} catch (...) {
|
||||
|
@@ -164,6 +164,8 @@ static int
|
||||
dump_input_stream(InputStream &is, FileDescriptor out,
|
||||
offset_type seek, size_t chunk_size)
|
||||
{
|
||||
out.SetBinaryMode();
|
||||
|
||||
std::unique_lock<Mutex> lock(is.mutex);
|
||||
|
||||
if (seek > 0)
|
||||
|
@@ -31,6 +31,7 @@
|
||||
#include "util/StringBuffer.hxx"
|
||||
#include "util/RuntimeError.hxx"
|
||||
#include "util/ScopeExit.hxx"
|
||||
#include "util/StaticFifoBuffer.hxx"
|
||||
#include "util/PrintException.hxx"
|
||||
#include "LogBackend.hxx"
|
||||
|
||||
@@ -113,8 +114,11 @@ LoadAudioOutput(const ConfigData &config, EventLoop &event_loop,
|
||||
}
|
||||
|
||||
static void
|
||||
run_output(AudioOutput &ao, AudioFormat audio_format)
|
||||
RunOutput(AudioOutput &ao, AudioFormat audio_format,
|
||||
FileDescriptor in_fd)
|
||||
{
|
||||
in_fd.SetBinaryMode();
|
||||
|
||||
/* open the audio output */
|
||||
|
||||
ao.Enable();
|
||||
@@ -126,33 +130,40 @@ run_output(AudioOutput &ao, AudioFormat audio_format)
|
||||
fprintf(stderr, "audio_format=%s\n",
|
||||
ToString(audio_format).c_str());
|
||||
|
||||
size_t frame_size = audio_format.GetFrameSize();
|
||||
const size_t in_frame_size = audio_format.GetFrameSize();
|
||||
|
||||
/* play */
|
||||
|
||||
size_t length = 0;
|
||||
char buffer[4096];
|
||||
StaticFifoBuffer<std::byte, 4096> buffer;
|
||||
|
||||
while (true) {
|
||||
if (length < sizeof(buffer)) {
|
||||
ssize_t nbytes = read(0, buffer + length,
|
||||
sizeof(buffer) - length);
|
||||
{
|
||||
const auto dest = buffer.Write();
|
||||
assert(!dest.empty());
|
||||
|
||||
ssize_t nbytes = in_fd.Read(dest.data, dest.size);
|
||||
if (nbytes <= 0)
|
||||
break;
|
||||
|
||||
length += (size_t)nbytes;
|
||||
buffer.Append(nbytes);
|
||||
}
|
||||
|
||||
size_t play_length = (length / frame_size) * frame_size;
|
||||
if (play_length > 0) {
|
||||
size_t consumed = ao.Play(buffer, play_length);
|
||||
auto src = buffer.Read();
|
||||
assert(!src.empty());
|
||||
|
||||
assert(consumed <= length);
|
||||
assert(consumed % frame_size == 0);
|
||||
src.size -= src.size % in_frame_size;
|
||||
if (src.empty())
|
||||
continue;
|
||||
|
||||
length -= consumed;
|
||||
memmove(buffer, buffer + consumed, length);
|
||||
}
|
||||
size_t consumed = ao.Play(src.data, src.size);
|
||||
|
||||
assert(consumed <= src.size);
|
||||
assert(consumed % in_frame_size == 0);
|
||||
|
||||
buffer.Consume(consumed);
|
||||
}
|
||||
|
||||
ao.Drain();
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
@@ -174,7 +185,7 @@ try {
|
||||
|
||||
/* do it */
|
||||
|
||||
run_output(*ao, c.audio_format);
|
||||
RunOutput(*ao, c.audio_format, FileDescriptor(STDIN_FILENO));
|
||||
|
||||
/* cleanup and exit */
|
||||
|
||||
|
Reference in New Issue
Block a user