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
Hide 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 @@
#include "../Wrapper.hxx"
#include "mixer/MixerList.hxx"
#include "thread/Mutex.hxx"
#include "util/Error.hxx"
#include "util/Domain.hxx"
#include "Log.hxx"
...
...
@@ -42,31 +41,23 @@ class RoarOutput {
AudioOutput
base
;
std
::
string
host
,
name
;
const
std
::
string
host
,
name
;
roar_vs_t
*
vss
;
int
err
;
int
role
;
int
err
=
ROAR_ERROR_NONE
;
const
int
role
;
struct
roar_connection
con
;
struct
roar_audio_info
info
;
mutable
Mutex
mutex
;
bool
alive
;
public
:
RoarOutput
()
:
base
(
roar_output_plugin
),
err
(
ROAR_ERROR_NONE
)
{}
RoarOutput
(
const
ConfigBlock
&
block
);
operator
AudioOutput
*
()
{
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
);
void
Close
();
...
...
@@ -80,6 +71,24 @@ public:
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
RoarOutput
::
GetVolume
()
const
{
...
...
@@ -124,30 +133,10 @@ roar_output_set_volume(RoarOutput &roar, unsigned 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
*
roar_init
(
const
ConfigBlock
&
block
,
Error
&
error
)
roar_init
(
const
ConfigBlock
&
block
,
Error
&
)
{
RoarOutput
*
self
=
new
RoarOutput
();
if
(
!
self
->
Initialize
(
block
,
error
))
{
delete
self
;
return
nullptr
;
}
self
->
Configure
(
block
);
return
*
self
;
return
*
new
RoarOutput
(
block
);
}
static
void
...
...
@@ -186,31 +175,24 @@ roar_use_audio_format(struct roar_audio_info *info,
}
inline
bool
RoarOutput
::
Open
(
AudioFormat
&
audio_format
,
Error
&
error
)
RoarOutput
::
Open
(
AudioFormat
&
audio_format
,
Error
&
)
{
const
ScopeLock
protect
(
mutex
);
if
(
roar_simple_connect
(
&
con
,
host
.
empty
()
?
nullptr
:
host
.
c_str
(),
name
.
c_str
())
<
0
)
{
error
.
Set
(
roar_output_domain
,
"Failed to connect to Roar server"
);
return
false
;
}
name
.
c_str
())
<
0
)
throw
std
::
runtime_error
(
"Failed to connect to Roar server"
);
vss
=
roar_vs_new_from_con
(
&
con
,
&
err
);
if
(
vss
==
nullptr
||
err
!=
ROAR_ERROR_NONE
)
{
error
.
Set
(
roar_output_domain
,
"Failed to connect to server"
);
return
false
;
}
if
(
vss
==
nullptr
||
err
!=
ROAR_ERROR_NONE
)
throw
std
::
runtime_error
(
"Failed to connect to server"
);
roar_use_audio_format
(
&
info
,
audio_format
);
if
(
roar_vs_stream
(
vss
,
&
info
,
ROAR_DIR_PLAY
,
&
err
)
<
0
)
{
error
.
Set
(
roar_output_domain
,
"Failed to start stream"
);
return
false
;
}
if
(
roar_vs_stream
(
vss
,
&
info
,
ROAR_DIR_PLAY
,
&
err
)
<
0
)
throw
std
::
runtime_error
(
"Failed to start stream"
);
roar_vs_role
(
vss
,
role
,
&
err
);
alive
=
true
;
...
...
@@ -259,18 +241,14 @@ RoarOutput::Cancel()
}
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
)
{
error
.
Set
(
roar_output_domain
,
"Connection is invalid"
);
return
0
;
}
if
(
vss
==
nullptr
)
throw
std
::
runtime_error
(
"Connection is invalid"
);
ssize_t
nbytes
=
roar_vs_write
(
vss
,
chunk
,
size
,
&
err
);
if
(
nbytes
<=
0
)
{
error
.
Set
(
roar_output_domain
,
"Failed to play data"
);
return
0
;
}
if
(
nbytes
<=
0
)
throw
std
::
runtime_error
(
"Failed to play data"
);
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