output/pipewire: check pw_stream_connect() errors
This commit is contained in:
parent
1f780b7209
commit
f447b7615e
34
src/lib/pipewire/Error.cxx
Normal file
34
src/lib/pipewire/Error.cxx
Normal file
@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright 2003-2021 The Music Player Daemon Project
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "Error.hxx"
|
||||
|
||||
#include <spa/utils/result.h>
|
||||
|
||||
namespace PipeWire {
|
||||
|
||||
ErrorCategory error_category;
|
||||
|
||||
std::string
|
||||
ErrorCategory::message(int condition) const
|
||||
{
|
||||
return spa_strerror(condition);
|
||||
}
|
||||
|
||||
} // namespace Avahi
|
45
src/lib/pipewire/Error.hxx
Normal file
45
src/lib/pipewire/Error.hxx
Normal file
@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright 2003-2021 The Music Player Daemon Project
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <system_error>
|
||||
|
||||
struct AvahiClient;
|
||||
|
||||
namespace PipeWire {
|
||||
|
||||
class ErrorCategory final : public std::error_category {
|
||||
public:
|
||||
const char *name() const noexcept override {
|
||||
return "pipewire";
|
||||
}
|
||||
|
||||
std::string message(int condition) const override;
|
||||
};
|
||||
|
||||
extern ErrorCategory error_category;
|
||||
|
||||
inline std::system_error
|
||||
MakeError(int error, const char *msg) noexcept
|
||||
{
|
||||
return std::system_error(error, error_category, msg);
|
||||
}
|
||||
|
||||
} // namespace PipeWire
|
@ -12,3 +12,17 @@ pipewire_dep = declare_dependency(
|
||||
# disable it at the command line
|
||||
compile_args: ['-Wno-pedantic'],
|
||||
)
|
||||
|
||||
pipewire = static_library(
|
||||
'pipewire',
|
||||
'Error.cxx',
|
||||
include_directories: inc,
|
||||
dependencies: [
|
||||
pipewire_dep,
|
||||
],
|
||||
)
|
||||
|
||||
pipewire_dep = declare_dependency(
|
||||
link_with: pipewire,
|
||||
dependencies: pipewire_dep,
|
||||
)
|
||||
|
@ -18,6 +18,7 @@
|
||||
*/
|
||||
|
||||
#include "PipeWireOutputPlugin.hxx"
|
||||
#include "lib/pipewire/Error.hxx"
|
||||
#include "lib/pipewire/ThreadLoop.hxx"
|
||||
#include "../OutputAPI.hxx"
|
||||
#include "../Error.hxx"
|
||||
@ -488,14 +489,17 @@ PipeWireOutput::Open(AudioFormat &audio_format)
|
||||
params[0] = spa_format_audio_raw_build(&pod_builder,
|
||||
SPA_PARAM_EnumFormat, &raw);
|
||||
|
||||
pw_stream_connect(stream,
|
||||
PW_DIRECTION_OUTPUT,
|
||||
target_id,
|
||||
(enum pw_stream_flags)(PW_STREAM_FLAG_AUTOCONNECT |
|
||||
PW_STREAM_FLAG_INACTIVE |
|
||||
PW_STREAM_FLAG_MAP_BUFFERS |
|
||||
PW_STREAM_FLAG_RT_PROCESS),
|
||||
params, 1);
|
||||
int error =
|
||||
pw_stream_connect(stream,
|
||||
PW_DIRECTION_OUTPUT,
|
||||
target_id,
|
||||
(enum pw_stream_flags)(PW_STREAM_FLAG_AUTOCONNECT |
|
||||
PW_STREAM_FLAG_INACTIVE |
|
||||
PW_STREAM_FLAG_MAP_BUFFERS |
|
||||
PW_STREAM_FLAG_RT_PROCESS),
|
||||
params, 1);
|
||||
if (error < 0)
|
||||
throw PipeWire::MakeError(error, "Failed to connect stream");
|
||||
}
|
||||
|
||||
void
|
||||
|
Loading…
Reference in New Issue
Block a user