Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mpd
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Мажукин
mpd
Commits
b4e5fa5c
Commit
b4e5fa5c
authored
Nov 09, 2016
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
output/roar: migrate from class Error to C++ exceptions
parent
f12fa7e2
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
36 additions
and
58 deletions
+36
-58
RoarOutputPlugin.cxx
src/output/plugins/RoarOutputPlugin.cxx
+36
-58
No files found.
src/output/plugins/RoarOutputPlugin.cxx
View file @
b4e5fa5c
...
@@ -24,7 +24,6 @@
...
@@ -24,7 +24,6 @@
#include "../Wrapper.hxx"
#include "../Wrapper.hxx"
#include "mixer/MixerList.hxx"
#include "mixer/MixerList.hxx"
#include "thread/Mutex.hxx"
#include "thread/Mutex.hxx"
#include "util/Error.hxx"
#include "util/Domain.hxx"
#include "util/Domain.hxx"
#include "Log.hxx"
#include "Log.hxx"
...
@@ -42,31 +41,23 @@ class RoarOutput {
...
@@ -42,31 +41,23 @@ class RoarOutput {
AudioOutput
base
;
AudioOutput
base
;
std
::
string
host
,
name
;
const
std
::
string
host
,
name
;
roar_vs_t
*
vss
;
roar_vs_t
*
vss
;
int
err
;
int
err
=
ROAR_ERROR_NONE
;
int
role
;
const
int
role
;
struct
roar_connection
con
;
struct
roar_connection
con
;
struct
roar_audio_info
info
;
struct
roar_audio_info
info
;
mutable
Mutex
mutex
;
mutable
Mutex
mutex
;
bool
alive
;
bool
alive
;
public
:
public
:
RoarOutput
()
RoarOutput
(
const
ConfigBlock
&
block
);
:
base
(
roar_output_plugin
),
err
(
ROAR_ERROR_NONE
)
{}
operator
AudioOutput
*
()
{
operator
AudioOutput
*
()
{
return
&
base
;
return
&
base
;
}
}
bool
Initialize
(
const
ConfigBlock
&
block
,
Error
&
error
)
{
return
base
.
Configure
(
block
,
error
);
}
void
Configure
(
const
ConfigBlock
&
block
);
bool
Open
(
AudioFormat
&
audio_format
,
Error
&
error
);
bool
Open
(
AudioFormat
&
audio_format
,
Error
&
error
);
void
Close
();
void
Close
();
...
@@ -80,6 +71,24 @@ public:
...
@@ -80,6 +71,24 @@ public:
static
constexpr
Domain
roar_output_domain
(
"roar_output"
);
static
constexpr
Domain
roar_output_domain
(
"roar_output"
);
gcc_pure
static
int
GetConfiguredRole
(
const
ConfigBlock
&
block
)
{
const
char
*
role
=
block
.
GetBlockValue
(
"role"
);
return
role
!=
nullptr
?
roar_str2role
(
role
)
:
ROAR_ROLE_MUSIC
;
}
RoarOutput
::
RoarOutput
(
const
ConfigBlock
&
block
)
:
base
(
roar_output_plugin
,
block
),
host
(
block
.
GetBlockValue
(
"server"
,
""
)),
name
(
block
.
GetBlockValue
(
"name"
,
"MPD"
)),
role
(
GetConfiguredRole
(
block
))
{
}
inline
int
inline
int
RoarOutput
::
GetVolume
()
const
RoarOutput
::
GetVolume
()
const
{
{
...
@@ -124,30 +133,10 @@ roar_output_set_volume(RoarOutput &roar, unsigned volume)
...
@@ -124,30 +133,10 @@ roar_output_set_volume(RoarOutput &roar, unsigned volume)
roar
.
SetVolume
(
volume
);
roar
.
SetVolume
(
volume
);
}
}
inline
void
RoarOutput
::
Configure
(
const
ConfigBlock
&
block
)
{
host
=
block
.
GetBlockValue
(
"server"
,
""
);
name
=
block
.
GetBlockValue
(
"name"
,
"MPD"
);
const
char
*
_role
=
block
.
GetBlockValue
(
"role"
,
"music"
);
role
=
_role
!=
nullptr
?
roar_str2role
(
_role
)
:
ROAR_ROLE_MUSIC
;
}
static
AudioOutput
*
static
AudioOutput
*
roar_init
(
const
ConfigBlock
&
block
,
Error
&
error
)
roar_init
(
const
ConfigBlock
&
block
,
Error
&
)
{
{
RoarOutput
*
self
=
new
RoarOutput
();
return
*
new
RoarOutput
(
block
);
if
(
!
self
->
Initialize
(
block
,
error
))
{
delete
self
;
return
nullptr
;
}
self
->
Configure
(
block
);
return
*
self
;
}
}
static
void
static
void
...
@@ -186,31 +175,24 @@ roar_use_audio_format(struct roar_audio_info *info,
...
@@ -186,31 +175,24 @@ roar_use_audio_format(struct roar_audio_info *info,
}
}
inline
bool
inline
bool
RoarOutput
::
Open
(
AudioFormat
&
audio_format
,
Error
&
error
)
RoarOutput
::
Open
(
AudioFormat
&
audio_format
,
Error
&
)
{
{
const
ScopeLock
protect
(
mutex
);
const
ScopeLock
protect
(
mutex
);
if
(
roar_simple_connect
(
&
con
,
if
(
roar_simple_connect
(
&
con
,
host
.
empty
()
?
nullptr
:
host
.
c_str
(),
host
.
empty
()
?
nullptr
:
host
.
c_str
(),
name
.
c_str
())
<
0
)
{
name
.
c_str
())
<
0
)
error
.
Set
(
roar_output_domain
,
throw
std
::
runtime_error
(
"Failed to connect to Roar server"
);
"Failed to connect to Roar server"
);
return
false
;
}
vss
=
roar_vs_new_from_con
(
&
con
,
&
err
);
vss
=
roar_vs_new_from_con
(
&
con
,
&
err
);
if
(
vss
==
nullptr
||
err
!=
ROAR_ERROR_NONE
)
{
if
(
vss
==
nullptr
||
err
!=
ROAR_ERROR_NONE
)
error
.
Set
(
roar_output_domain
,
"Failed to connect to server"
);
throw
std
::
runtime_error
(
"Failed to connect to server"
);
return
false
;
}
roar_use_audio_format
(
&
info
,
audio_format
);
roar_use_audio_format
(
&
info
,
audio_format
);
if
(
roar_vs_stream
(
vss
,
&
info
,
ROAR_DIR_PLAY
,
&
err
)
<
0
)
{
if
(
roar_vs_stream
(
vss
,
&
info
,
ROAR_DIR_PLAY
,
&
err
)
<
0
)
error
.
Set
(
roar_output_domain
,
"Failed to start stream"
);
throw
std
::
runtime_error
(
"Failed to start stream"
);
return
false
;
}
roar_vs_role
(
vss
,
role
,
&
err
);
roar_vs_role
(
vss
,
role
,
&
err
);
alive
=
true
;
alive
=
true
;
...
@@ -259,18 +241,14 @@ RoarOutput::Cancel()
...
@@ -259,18 +241,14 @@ RoarOutput::Cancel()
}
}
inline
size_t
inline
size_t
RoarOutput
::
Play
(
const
void
*
chunk
,
size_t
size
,
Error
&
error
)
RoarOutput
::
Play
(
const
void
*
chunk
,
size_t
size
,
Error
&
)
{
{
if
(
vss
==
nullptr
)
{
if
(
vss
==
nullptr
)
error
.
Set
(
roar_output_domain
,
"Connection is invalid"
);
throw
std
::
runtime_error
(
"Connection is invalid"
);
return
0
;
}
ssize_t
nbytes
=
roar_vs_write
(
vss
,
chunk
,
size
,
&
err
);
ssize_t
nbytes
=
roar_vs_write
(
vss
,
chunk
,
size
,
&
err
);
if
(
nbytes
<=
0
)
{
if
(
nbytes
<=
0
)
error
.
Set
(
roar_output_domain
,
"Failed to play data"
);
throw
std
::
runtime_error
(
"Failed to play data"
);
return
0
;
}
return
nbytes
;
return
nbytes
;
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment