output/recorder: use config_param::GetBlockPath()
Supports "~/" expansion. Forces us to switch from "const char *" to AllocatedPath, which is a good thing.
This commit is contained in:
parent
153f5854e2
commit
c1f0708a5d
|
@ -25,6 +25,8 @@
|
||||||
#include "encoder/EncoderList.hxx"
|
#include "encoder/EncoderList.hxx"
|
||||||
#include "config/ConfigError.hxx"
|
#include "config/ConfigError.hxx"
|
||||||
#include "Log.hxx"
|
#include "Log.hxx"
|
||||||
|
#include "fs/AllocatedPath.hxx"
|
||||||
|
#include "fs/FileSystem.hxx"
|
||||||
#include "util/Error.hxx"
|
#include "util/Error.hxx"
|
||||||
#include "util/Domain.hxx"
|
#include "util/Domain.hxx"
|
||||||
#include "system/fd_util.h"
|
#include "system/fd_util.h"
|
||||||
|
@ -47,7 +49,7 @@ struct RecorderOutput {
|
||||||
/**
|
/**
|
||||||
* The destination file name.
|
* The destination file name.
|
||||||
*/
|
*/
|
||||||
const char *path;
|
AllocatedPath path;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The destination file descriptor.
|
* The destination file descriptor.
|
||||||
|
@ -60,7 +62,8 @@ struct RecorderOutput {
|
||||||
char buffer[32768];
|
char buffer[32768];
|
||||||
|
|
||||||
RecorderOutput()
|
RecorderOutput()
|
||||||
:base(recorder_output_plugin) {}
|
:base(recorder_output_plugin),
|
||||||
|
path(AllocatedPath::Null()) {}
|
||||||
|
|
||||||
bool Initialize(const config_param ¶m, Error &error_r) {
|
bool Initialize(const config_param ¶m, Error &error_r) {
|
||||||
return base.Configure(param, error_r);
|
return base.Configure(param, error_r);
|
||||||
|
@ -97,9 +100,10 @@ RecorderOutput::Configure(const config_param ¶m, Error &error)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
path = param.GetBlockValue("path");
|
path = param.GetBlockPath("path", error);
|
||||||
if (path == nullptr) {
|
if (path.IsNull()) {
|
||||||
error.Set(config_domain, "'path' not configured");
|
if (!error.IsDefined())
|
||||||
|
error.Set(config_domain, "'path' not configured");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -158,7 +162,8 @@ RecorderOutput::WriteToFile(const void *_data, size_t length, Error &error)
|
||||||
"write() returned 0");
|
"write() returned 0");
|
||||||
return false;
|
return false;
|
||||||
} else if (errno != EINTR) {
|
} else if (errno != EINTR) {
|
||||||
error.FormatErrno("Failed to write to '%s'", path);
|
error.FormatErrno("Failed to write to '%s'",
|
||||||
|
path.c_str());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -188,11 +193,11 @@ RecorderOutput::Open(AudioFormat &audio_format, Error &error)
|
||||||
{
|
{
|
||||||
/* create the output file */
|
/* create the output file */
|
||||||
|
|
||||||
fd = open_cloexec(path,
|
fd = OpenFile(path,
|
||||||
O_CREAT|O_WRONLY|O_TRUNC|O_BINARY,
|
O_CREAT|O_WRONLY|O_TRUNC|O_BINARY,
|
||||||
0666);
|
0666);
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
error.FormatErrno("Failed to create '%s'", path);
|
error.FormatErrno("Failed to create '%s'", path.c_str());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -200,14 +205,14 @@ RecorderOutput::Open(AudioFormat &audio_format, Error &error)
|
||||||
|
|
||||||
if (!encoder_open(encoder, audio_format, error)) {
|
if (!encoder_open(encoder, audio_format, error)) {
|
||||||
close(fd);
|
close(fd);
|
||||||
unlink(path);
|
RemoveFile(path);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!EncoderToFile(error)) {
|
if (!EncoderToFile(error)) {
|
||||||
encoder_close(encoder);
|
encoder_close(encoder);
|
||||||
close(fd);
|
close(fd);
|
||||||
unlink(path);
|
RemoveFile(path);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue