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
1c07f197
Commit
1c07f197
authored
Sep 04, 2016
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Filter/Plugin: migrate from class Error to C++ exceptions
parent
13c32111
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
72 additions
and
135 deletions
+72
-135
FilterConfig.cxx
src/filter/FilterConfig.cxx
+10
-22
FilterConfig.hxx
src/filter/FilterConfig.hxx
+5
-5
FilterPlugin.cxx
src/filter/FilterPlugin.cxx
+10
-18
FilterPlugin.hxx
src/filter/FilterPlugin.hxx
+7
-10
ChainFilterPlugin.cxx
src/filter/plugins/ChainFilterPlugin.cxx
+1
-2
ConvertFilterPlugin.cxx
src/filter/plugins/ConvertFilterPlugin.cxx
+1
-2
NormalizeFilterPlugin.cxx
src/filter/plugins/NormalizeFilterPlugin.cxx
+1
-2
NullFilterPlugin.cxx
src/filter/plugins/NullFilterPlugin.cxx
+1
-2
ReplayGainFilterPlugin.cxx
src/filter/plugins/ReplayGainFilterPlugin.cxx
+1
-2
RouteFilterPlugin.cxx
src/filter/plugins/RouteFilterPlugin.cxx
+17
-42
VolumeFilterPlugin.cxx
src/filter/plugins/VolumeFilterPlugin.cxx
+1
-2
Init.cxx
src/output/Init.cxx
+16
-18
run_filter.cxx
test/run_filter.cxx
+1
-8
No files found.
src/filter/FilterConfig.cxx
View file @
1c07f197
...
...
@@ -26,39 +26,31 @@
#include "config/ConfigGlobal.hxx"
#include "config/ConfigError.hxx"
#include "config/Block.hxx"
#include "util/Error.hxx"
#include "util/
Runtime
Error.hxx"
#include <algorithm>
#include <string.h>
static
bool
filter_chain_append_new
(
PreparedFilter
&
chain
,
const
char
*
template_name
,
Error
&
error
)
static
void
filter_chain_append_new
(
PreparedFilter
&
chain
,
const
char
*
template_name
)
{
const
auto
*
cfg
=
config_find_block
(
ConfigBlockOption
::
AUDIO_FILTER
,
"name"
,
template_name
);
if
(
cfg
==
nullptr
)
{
error
.
Format
(
config_domain
,
"filter template not found: %s"
,
template_name
);
return
false
;
}
if
(
cfg
==
nullptr
)
throw
FormatRuntimeError
(
"Filter template not found: %s"
,
template_name
);
// Instantiate one of those filter plugins with the template name as a hint
PreparedFilter
*
f
=
filter_configured_new
(
*
cfg
,
error
);
if
(
f
==
nullptr
)
// The error has already been set, just stop.
return
false
;
PreparedFilter
*
f
=
filter_configured_new
(
*
cfg
);
const
char
*
plugin_name
=
cfg
->
GetBlockValue
(
"plugin"
,
"unknown"
);
filter_chain_append
(
chain
,
plugin_name
,
f
);
return
true
;
}
bool
filter_chain_parse
(
PreparedFilter
&
chain
,
const
char
*
spec
,
Error
&
error
)
void
filter_chain_parse
(
PreparedFilter
&
chain
,
const
char
*
spec
)
{
const
char
*
const
end
=
spec
+
strlen
(
spec
);
...
...
@@ -66,9 +58,7 @@ filter_chain_parse(PreparedFilter &chain, const char *spec, Error &error)
const
char
*
comma
=
std
::
find
(
spec
,
end
,
','
);
if
(
comma
>
spec
)
{
const
std
::
string
name
(
spec
,
comma
);
if
(
!
filter_chain_append_new
(
chain
,
name
.
c_str
(),
error
))
return
false
;
filter_chain_append_new
(
chain
,
name
.
c_str
());
}
if
(
comma
==
end
)
...
...
@@ -76,6 +66,4 @@ filter_chain_parse(PreparedFilter &chain, const char *spec, Error &error)
spec
=
comma
+
1
;
}
return
true
;
}
src/filter/FilterConfig.hxx
View file @
1c07f197
...
...
@@ -26,18 +26,18 @@
#define MPD_FILTER_CONFIG_HXX
class
PreparedFilter
;
class
Error
;
/**
* Builds a filter chain from a configuration string on the form
* "name1, name2, name3, ..." by looking up each name among the
* configured filter sections.
*
* Throws std::runtime_error on error.
*
* @param chain the chain to append filters on
* @param spec the filter chain specification
* @param error space to return an error description
* @return true on success
*/
bool
filter_chain_parse
(
PreparedFilter
&
chain
,
const
char
*
spec
,
Error
&
error
);
void
filter_chain_parse
(
PreparedFilter
&
chain
,
const
char
*
spec
);
#endif
src/filter/FilterPlugin.cxx
View file @
1c07f197
...
...
@@ -22,37 +22,29 @@
#include "FilterRegistry.hxx"
#include "config/Block.hxx"
#include "config/ConfigError.hxx"
#include "util/Error.hxx"
#include "util/
Runtime
Error.hxx"
#include <assert.h>
PreparedFilter
*
filter_new
(
const
struct
filter_plugin
*
plugin
,
const
ConfigBlock
&
block
,
Error
&
error
)
filter_new
(
const
struct
filter_plugin
*
plugin
,
const
ConfigBlock
&
block
)
{
assert
(
plugin
!=
nullptr
);
assert
(
!
error
.
IsDefined
());
return
plugin
->
init
(
block
,
error
);
return
plugin
->
init
(
block
);
}
PreparedFilter
*
filter_configured_new
(
const
ConfigBlock
&
block
,
Error
&
error
)
filter_configured_new
(
const
ConfigBlock
&
block
)
{
assert
(
!
error
.
IsDefined
());
const
char
*
plugin_name
=
block
.
GetBlockValue
(
"plugin"
);
if
(
plugin_name
==
nullptr
)
{
error
.
Set
(
config_domain
,
"No filter plugin specified"
);
return
nullptr
;
}
if
(
plugin_name
==
nullptr
)
throw
std
::
runtime_error
(
"No filter plugin specified"
);
const
filter_plugin
*
plugin
=
filter_plugin_by_name
(
plugin_name
);
if
(
plugin
==
nullptr
)
{
error
.
Format
(
config_domain
,
"No such filter plugin: %s"
,
plugin_name
);
return
nullptr
;
}
if
(
plugin
==
nullptr
)
throw
FormatRuntimeError
(
"No such filter plugin: %s"
,
plugin_name
);
return
filter_new
(
plugin
,
block
,
error
);
return
filter_new
(
plugin
,
block
);
}
src/filter/FilterPlugin.hxx
View file @
1c07f197
...
...
@@ -28,7 +28,6 @@
struct
ConfigBlock
;
class
PreparedFilter
;
class
Error
;
struct
filter_plugin
{
const
char
*
name
;
...
...
@@ -36,32 +35,30 @@ struct filter_plugin {
/**
* Allocates and configures a filter.
*/
PreparedFilter
*
(
*
init
)(
const
ConfigBlock
&
block
,
Error
&
error
);
PreparedFilter
*
(
*
init
)(
const
ConfigBlock
&
block
);
};
/**
* Creates a new instance of the specified filter plugin.
*
* Throws std::runtime_error on error.
*
* @param plugin the filter plugin
* @param block configuration section
* @param error location to store the error occurring, or nullptr to
* ignore errors.
* @return a new filter object, or nullptr on error
*/
PreparedFilter
*
filter_new
(
const
struct
filter_plugin
*
plugin
,
const
ConfigBlock
&
block
,
Error
&
error
);
const
ConfigBlock
&
block
);
/**
* Creates a new filter, loads configuration and the plugin name from
* the specified configuration section.
*
* Throws std::runtime_error on error.
*
* @param block the configuration section
* @param error location to store the error occurring, or nullptr to
* ignore errors.
* @return a new filter object, or nullptr on error
*/
PreparedFilter
*
filter_configured_new
(
const
ConfigBlock
&
block
,
Error
&
error
);
filter_configured_new
(
const
ConfigBlock
&
block
);
#endif
src/filter/plugins/ChainFilterPlugin.cxx
View file @
1c07f197
...
...
@@ -93,8 +93,7 @@ public:
};
static
PreparedFilter
*
chain_filter_init
(
gcc_unused
const
ConfigBlock
&
block
,
gcc_unused
Error
&
error
)
chain_filter_init
(
gcc_unused
const
ConfigBlock
&
block
)
{
return
new
PreparedChainFilter
();
}
...
...
src/filter/plugins/ConvertFilterPlugin.cxx
View file @
1c07f197
...
...
@@ -64,8 +64,7 @@ public:
};
static
PreparedFilter
*
convert_filter_init
(
gcc_unused
const
ConfigBlock
&
block
,
gcc_unused
Error
&
error
)
convert_filter_init
(
gcc_unused
const
ConfigBlock
&
block
)
{
return
new
PreparedConvertFilter
();
}
...
...
src/filter/plugins/NormalizeFilterPlugin.cxx
View file @
1c07f197
...
...
@@ -53,8 +53,7 @@ public:
};
static
PreparedFilter
*
normalize_filter_init
(
gcc_unused
const
ConfigBlock
&
block
,
gcc_unused
Error
&
error
)
normalize_filter_init
(
gcc_unused
const
ConfigBlock
&
block
)
{
return
new
PreparedNormalizeFilter
();
}
...
...
src/filter/plugins/NullFilterPlugin.cxx
View file @
1c07f197
...
...
@@ -49,8 +49,7 @@ public:
};
static
PreparedFilter
*
null_filter_init
(
gcc_unused
const
ConfigBlock
&
block
,
gcc_unused
Error
&
error
)
null_filter_init
(
gcc_unused
const
ConfigBlock
&
block
)
{
return
new
PreparedNullFilter
();
}
...
...
src/filter/plugins/ReplayGainFilterPlugin.cxx
View file @
1c07f197
...
...
@@ -168,8 +168,7 @@ ReplayGainFilter::Update()
}
static
PreparedFilter
*
replay_gain_filter_init
(
gcc_unused
const
ConfigBlock
&
block
,
gcc_unused
Error
&
error
)
replay_gain_filter_init
(
gcc_unused
const
ConfigBlock
&
block
)
{
return
new
PreparedReplayGainFilter
();
}
...
...
src/filter/plugins/RouteFilterPlugin.cxx
View file @
1c07f197
...
...
@@ -49,7 +49,7 @@
#include "pcm/PcmBuffer.hxx"
#include "pcm/Silence.hxx"
#include "util/StringUtil.hxx"
#include "util/Error.hxx"
#include "util/
Runtime
Error.hxx"
#include "util/ConstBuffer.hxx"
#include "util/WritableBuffer.hxx"
...
...
@@ -130,16 +130,14 @@ public:
* and input channel a gets copied to output channel b, etc.
* @param block the configuration block to read
* @param filter a route_filter whose min_channels and sources[] to set
* @return true on success, false on error
*/
bool
Configure
(
const
ConfigBlock
&
block
,
Error
&
error
);
PreparedRouteFilter
(
const
ConfigBlock
&
block
);
/* virtual methods from class PreparedFilter */
Filter
*
Open
(
AudioFormat
&
af
)
override
;
};
bool
PreparedRouteFilter
::
Configure
(
const
ConfigBlock
&
block
,
Error
&
error
)
PreparedRouteFilter
::
PreparedRouteFilter
(
const
ConfigBlock
&
block
)
{
/* TODO:
* With a more clever way of marking "don't copy to output N",
...
...
@@ -160,18 +158,12 @@ PreparedRouteFilter::Configure(const ConfigBlock &block, Error &error)
char
*
endptr
;
const
unsigned
source
=
strtoul
(
routes
,
&
endptr
,
10
);
endptr
=
StripLeft
(
endptr
);
if
(
endptr
==
routes
||
*
endptr
!=
'>'
)
{
error
.
Set
(
config_domain
,
"Malformed 'routes' specification"
);
return
false
;
}
if
(
endptr
==
routes
||
*
endptr
!=
'>'
)
throw
std
::
runtime_error
(
"Malformed 'routes' specification"
);
if
(
source
>=
MAX_CHANNELS
)
{
error
.
Format
(
config_domain
,
"Invalid source channel number: %u"
,
source
);
return
false
;
}
if
(
source
>=
MAX_CHANNELS
)
throw
FormatRuntimeError
(
"Invalid source channel number: %u"
,
source
);
if
(
source
>=
min_input_channels
)
min_input_channels
=
source
+
1
;
...
...
@@ -180,18 +172,12 @@ PreparedRouteFilter::Configure(const ConfigBlock &block, Error &error)
unsigned
dest
=
strtoul
(
routes
,
&
endptr
,
10
);
endptr
=
StripLeft
(
endptr
);
if
(
endptr
==
routes
)
{
error
.
Set
(
config_domain
,
"Malformed 'routes' specification"
);
return
false
;
}
if
(
endptr
==
routes
)
throw
std
::
runtime_error
(
"Malformed 'routes' specification"
);
if
(
dest
>=
MAX_CHANNELS
)
{
error
.
Format
(
config_domain
,
"Invalid destination channel number: %u"
,
dest
);
return
false
;
}
if
(
dest
>=
MAX_CHANNELS
)
throw
FormatRuntimeError
(
"Invalid destination channel number: %u"
,
dest
);
if
(
dest
>=
min_output_channels
)
min_output_channels
=
dest
+
1
;
...
...
@@ -203,28 +189,17 @@ PreparedRouteFilter::Configure(const ConfigBlock &block, Error &error)
if
(
*
routes
==
0
)
break
;
if
(
*
routes
!=
','
)
{
error
.
Set
(
config_domain
,
"Malformed 'routes' specification"
);
return
false
;
}
if
(
*
routes
!=
','
)
throw
std
::
runtime_error
(
"Malformed 'routes' specification"
);
++
routes
;
}
return
true
;
}
static
PreparedFilter
*
route_filter_init
(
const
ConfigBlock
&
block
,
Error
&
error
)
route_filter_init
(
const
ConfigBlock
&
block
)
{
auto
*
filter
=
new
PreparedRouteFilter
();
if
(
!
filter
->
Configure
(
block
,
error
))
{
delete
filter
;
return
nullptr
;
}
return
filter
;
return
new
PreparedRouteFilter
(
block
);
}
RouteFilter
::
RouteFilter
(
const
AudioFormat
&
audio_format
,
...
...
src/filter/plugins/VolumeFilterPlugin.cxx
View file @
1c07f197
...
...
@@ -61,8 +61,7 @@ public:
};
static
PreparedFilter
*
volume_filter_init
(
gcc_unused
const
ConfigBlock
&
block
,
gcc_unused
Error
&
error
)
volume_filter_init
(
gcc_unused
const
ConfigBlock
&
block
)
{
return
new
PreparedVolumeFilter
();
}
...
...
src/output/Init.cxx
View file @
1c07f197
...
...
@@ -39,6 +39,8 @@
#include "util/Error.hxx"
#include "Log.hxx"
#include <stdexcept>
#include <assert.h>
#include <string.h>
...
...
@@ -105,8 +107,7 @@ audio_output_mixer_type(const ConfigBlock &block)
static
PreparedFilter
*
CreateVolumeFilter
()
{
return
filter_new
(
&
volume_filter_plugin
,
ConfigBlock
(),
IgnoreError
());
return
filter_new
(
&
volume_filter_plugin
,
ConfigBlock
());
}
static
Mixer
*
...
...
@@ -190,25 +191,24 @@ AudioOutput::Configure(const ConfigBlock &block, Error &error)
if
(
config_get_bool
(
ConfigOption
::
VOLUME_NORMALIZATION
,
false
))
{
auto
*
normalize_filter
=
filter_new
(
&
normalize_filter_plugin
,
ConfigBlock
(),
IgnoreError
());
filter_new
(
&
normalize_filter_plugin
,
ConfigBlock
());
assert
(
normalize_filter
!=
nullptr
);
filter_chain_append
(
*
prepared_filter
,
"normalize"
,
autoconvert_filter_new
(
normalize_filter
));
}
Error
filter_error
;
filter_chain_parse
(
*
prepared_filter
,
block
.
GetBlockValue
(
AUDIO_FILTERS
,
""
),
filter_error
);
// It's not really fatal - Part of the filter chain has been set up already
// and even an empty one will work (if only with unexpected behaviour)
if
(
filter_error
.
IsDefined
())
FormatError
(
filter_error
,
try
{
filter_chain_parse
(
*
prepared_filter
,
block
.
GetBlockValue
(
AUDIO_FILTERS
,
""
));
}
catch
(
const
std
::
runtime_error
&
e
)
{
/* It's not really fatal - Part of the filter chain
has been set up already and even an empty one will
work (if only with unexpected behaviour) */
FormatError
(
e
,
"Failed to initialize filter chain for '%s'"
,
name
);
}
/* done */
...
...
@@ -229,14 +229,13 @@ audio_output_setup(EventLoop &event_loop, AudioOutput &ao,
if
(
strcmp
(
replay_gain_handler
,
"none"
)
!=
0
)
{
ao
.
prepared_replay_gain_filter
=
filter_new
(
&
replay_gain_filter_plugin
,
block
,
IgnoreError
()
);
block
);
assert
(
ao
.
prepared_replay_gain_filter
!=
nullptr
);
ao
.
replay_gain_serial
=
0
;
ao
.
prepared_other_replay_gain_filter
=
filter_new
(
&
replay_gain_filter_plugin
,
block
,
IgnoreError
());
block
);
assert
(
ao
.
prepared_other_replay_gain_filter
!=
nullptr
);
ao
.
other_replay_gain_serial
=
0
;
...
...
@@ -276,8 +275,7 @@ audio_output_setup(EventLoop &event_loop, AudioOutput &ao,
/* the "convert" filter must be the last one in the chain */
auto
*
f
=
filter_new
(
&
convert_filter_plugin
,
ConfigBlock
(),
IgnoreError
());
auto
*
f
=
filter_new
(
&
convert_filter_plugin
,
ConfigBlock
());
assert
(
f
!=
nullptr
);
filter_chain_append
(
*
ao
.
prepared_filter
,
"convert"
,
...
...
test/run_filter.cxx
View file @
1c07f197
...
...
@@ -58,14 +58,7 @@ load_filter(const char *name)
return
nullptr
;
}
Error
error
;
auto
*
filter
=
filter_configured_new
(
*
param
,
error
);
if
(
filter
==
NULL
)
{
LogError
(
error
,
"Failed to load filter"
);
return
NULL
;
}
return
filter
;
return
filter_configured_new
(
*
param
);
}
int
main
(
int
argc
,
char
**
argv
)
...
...
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