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
4531e4cc
Commit
4531e4cc
authored
Aug 18, 2018
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
filter/LoadChain: move code to class FilterFactory
Eliminate a use of GetGlobalConfig().
parent
1ba35e1f
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
119 additions
and
39 deletions
+119
-39
Makefile.am
Makefile.am
+1
-0
Factory.cxx
src/filter/Factory.cxx
+40
-0
Factory.hxx
src/filter/Factory.hxx
+40
-0
LoadChain.cxx
src/filter/LoadChain.cxx
+7
-24
LoadChain.hxx
src/filter/LoadChain.hxx
+2
-2
Filtered.hxx
src/output/Filtered.hxx
+6
-2
Init.cxx
src/output/Init.cxx
+10
-5
MultipleOutputs.cxx
src/output/MultipleOutputs.cxx
+13
-6
No files found.
Makefile.am
View file @
4531e4cc
...
...
@@ -1834,6 +1834,7 @@ libfilter_plugins_a_SOURCES = \
libfilter_glue_a_SOURCES
=
\
src/filter/FilterRegistry.cxx src/filter/FilterRegistry.hxx
\
src/filter/Factory.cxx src/filter/Factory.hxx
\
src/filter/LoadOne.cxx src/filter/LoadOne.hxx
\
src/filter/LoadChain.cxx src/filter/LoadChain.hxx
...
...
src/filter/Factory.cxx
0 → 100644
View file @
4531e4cc
/*
* Copyright 2003-2018 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 "config.h"
#include "Factory.hxx"
#include "LoadOne.hxx"
#include "Prepared.hxx"
#include "config/Data.hxx"
#include "config/Block.hxx"
#include "util/RuntimeError.hxx"
std
::
unique_ptr
<
PreparedFilter
>
FilterFactory
::
MakeFilter
(
const
char
*
name
)
{
const
auto
*
cfg
=
config
.
FindBlock
(
ConfigBlockOption
::
AUDIO_FILTER
,
"name"
,
name
);
if
(
cfg
==
nullptr
)
throw
FormatRuntimeError
(
"Filter template not found: %s"
,
name
);
cfg
->
SetUsed
();
return
filter_configured_new
(
*
cfg
);
}
src/filter/Factory.hxx
0 → 100644
View file @
4531e4cc
/*
* Copyright 2003-2018 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.
*/
#ifndef MPD_FILTER_FACTORY_HXX
#define MPD_FILTER_FACTORY_HXX
#include "check.h"
#include <memory>
struct
ConfigData
;
class
PreparedFilter
;
class
FilterFactory
{
const
ConfigData
&
config
;
public
:
explicit
FilterFactory
(
const
ConfigData
&
_config
)
noexcept
:
config
(
_config
)
{}
std
::
unique_ptr
<
PreparedFilter
>
MakeFilter
(
const
char
*
name
);
};
#endif
src/filter/LoadChain.cxx
View file @
4531e4cc
...
...
@@ -19,43 +19,26 @@
#include "config.h"
#include "LoadChain.hxx"
#include "
LoadOne
.hxx"
#include "
Factory
.hxx"
#include "Prepared.hxx"
#include "plugins/ChainFilterPlugin.hxx"
#include "config/Param.hxx"
#include "config/Option.hxx"
#include "config/Data.hxx"
#include "config/Domain.hxx"
#include "config/Block.hxx"
#include "util/RuntimeError.hxx"
#include <algorithm>
#include <string>
#include <string.h>
static
void
filter_chain_append_new
(
PreparedFilter
&
chain
,
const
ConfigData
&
config
,
filter_chain_append_new
(
PreparedFilter
&
chain
,
FilterFactory
&
factory
,
const
char
*
template_name
)
{
const
auto
*
cfg
=
config
.
FindBlock
(
ConfigBlockOption
::
AUDIO_FILTER
,
"name"
,
template_name
);
if
(
cfg
==
nullptr
)
throw
FormatRuntimeError
(
"Filter template not found: %s"
,
template_name
);
cfg
->
SetUsed
();
// Instantiate one of those filter plugins with the template name as a hint
auto
f
=
filter_configured_new
(
*
cfg
);
const
char
*
plugin_name
=
cfg
->
GetBlockValue
(
"plugin"
,
"unknown"
);
filter_chain_append
(
chain
,
plugin_name
,
std
::
move
(
f
));
filter_chain_append
(
chain
,
template_name
,
factory
.
MakeFilter
(
template_name
));
}
void
filter_chain_parse
(
PreparedFilter
&
chain
,
const
ConfigData
&
config
,
FilterFactory
&
factory
,
const
char
*
spec
)
{
const
char
*
const
end
=
spec
+
strlen
(
spec
);
...
...
@@ -64,7 +47,7 @@ filter_chain_parse(PreparedFilter &chain,
const
char
*
comma
=
std
::
find
(
spec
,
end
,
','
);
if
(
comma
>
spec
)
{
const
std
::
string
name
(
spec
,
comma
);
filter_chain_append_new
(
chain
,
config
,
name
.
c_str
());
filter_chain_append_new
(
chain
,
factory
,
name
.
c_str
());
}
if
(
comma
==
end
)
...
...
src/filter/LoadChain.hxx
View file @
4531e4cc
...
...
@@ -20,7 +20,7 @@
#ifndef MPD_FILTER_LOAD_CHAIN_HXX
#define MPD_FILTER_LOAD_CHAIN_HXX
struct
ConfigData
;
class
FilterFactory
;
class
PreparedFilter
;
/**
...
...
@@ -36,7 +36,7 @@ class PreparedFilter;
*/
void
filter_chain_parse
(
PreparedFilter
&
chain
,
const
ConfigData
&
config
,
FilterFactory
&
factory
,
const
char
*
spec
);
#endif
src/output/Filtered.hxx
View file @
4531e4cc
...
...
@@ -28,6 +28,7 @@
#include <map>
#include <chrono>
class
FilterFactory
;
class
PreparedFilter
;
class
MusicPipe
;
class
EventLoop
;
...
...
@@ -127,12 +128,14 @@ public:
*/
FilteredAudioOutput
(
const
char
*
_plugin_name
,
std
::
unique_ptr
<
AudioOutput
>
&&
_output
,
const
ConfigBlock
&
block
);
const
ConfigBlock
&
block
,
FilterFactory
*
filter_factory
);
~
FilteredAudioOutput
();
private
:
void
Configure
(
const
ConfigBlock
&
block
);
void
Configure
(
const
ConfigBlock
&
block
,
FilterFactory
*
filter_factory
);
public
:
void
Setup
(
EventLoop
&
event_loop
,
...
...
@@ -235,6 +238,7 @@ std::unique_ptr<FilteredAudioOutput>
audio_output_new
(
EventLoop
&
event_loop
,
const
ReplayGainConfig
&
replay_gain_config
,
const
ConfigBlock
&
block
,
FilterFactory
*
filter_factory
,
MixerListener
&
mixer_listener
);
#endif
src/output/Init.cxx
View file @
4531e4cc
...
...
@@ -54,10 +54,11 @@
FilteredAudioOutput
::
FilteredAudioOutput
(
const
char
*
_plugin_name
,
std
::
unique_ptr
<
AudioOutput
>
&&
_output
,
const
ConfigBlock
&
block
)
const
ConfigBlock
&
block
,
FilterFactory
*
filter_factory
)
:
plugin_name
(
_plugin_name
),
output
(
std
::
move
(
_output
))
{
Configure
(
block
);
Configure
(
block
,
filter_factory
);
}
static
const
AudioOutputPlugin
*
...
...
@@ -148,7 +149,8 @@ audio_output_load_mixer(EventLoop &event_loop, FilteredAudioOutput &ao,
}
void
FilteredAudioOutput
::
Configure
(
const
ConfigBlock
&
block
)
FilteredAudioOutput
::
Configure
(
const
ConfigBlock
&
block
,
FilterFactory
*
filter_factory
)
{
if
(
!
block
.
IsNull
())
{
name
=
block
.
GetBlockValue
(
AUDIO_OUTPUT_NAME
);
...
...
@@ -181,7 +183,8 @@ FilteredAudioOutput::Configure(const ConfigBlock &block)
}
try
{
filter_chain_parse
(
*
prepared_filter
,
GetGlobalConfig
(),
if
(
filter_factory
!=
nullptr
)
filter_chain_parse
(
*
prepared_filter
,
*
filter_factory
,
block
.
GetBlockValue
(
AUDIO_FILTERS
,
""
));
}
catch
(...)
{
/* It's not really fatal - Part of the filter chain
...
...
@@ -256,6 +259,7 @@ std::unique_ptr<FilteredAudioOutput>
audio_output_new
(
EventLoop
&
event_loop
,
const
ReplayGainConfig
&
replay_gain_config
,
const
ConfigBlock
&
block
,
FilterFactory
*
filter_factory
,
MixerListener
&
mixer_listener
)
{
const
AudioOutputPlugin
*
plugin
;
...
...
@@ -286,7 +290,8 @@ audio_output_new(EventLoop &event_loop,
assert
(
ao
!=
nullptr
);
auto
f
=
std
::
make_unique
<
FilteredAudioOutput
>
(
plugin
->
name
,
std
::
move
(
ao
),
block
);
std
::
move
(
ao
),
block
,
filter_factory
);
f
->
Setup
(
event_loop
,
replay_gain_config
,
plugin
->
mixer_plugin
,
mixer_listener
,
block
);
...
...
src/output/MultipleOutputs.cxx
View file @
4531e4cc
...
...
@@ -23,6 +23,7 @@
#include "Domain.hxx"
#include "MusicPipe.hxx"
#include "MusicChunk.hxx"
#include "filter/Factory.hxx"
#include "config/Block.hxx"
#include "config/Data.hxx"
#include "config/Option.hxx"
...
...
@@ -51,9 +52,11 @@ static std::unique_ptr<FilteredAudioOutput>
LoadOutput
(
EventLoop
&
event_loop
,
const
ReplayGainConfig
&
replay_gain_config
,
MixerListener
&
mixer_listener
,
const
ConfigBlock
&
block
)
const
ConfigBlock
&
block
,
FilterFactory
*
filter_factory
)
try
{
return
audio_output_new
(
event_loop
,
replay_gain_config
,
block
,
filter_factory
,
mixer_listener
);
}
catch
(...)
{
if
(
block
.
line
>
0
)
...
...
@@ -67,11 +70,12 @@ static AudioOutputControl *
LoadOutputControl
(
EventLoop
&
event_loop
,
const
ReplayGainConfig
&
replay_gain_config
,
MixerListener
&
mixer_listener
,
AudioOutputClient
&
client
,
const
ConfigBlock
&
block
)
AudioOutputClient
&
client
,
const
ConfigBlock
&
block
,
FilterFactory
*
filter_factory
)
{
auto
output
=
LoadOutput
(
event_loop
,
replay_gain_config
,
mixer_listener
,
block
);
block
,
filter_factory
);
auto
*
control
=
new
AudioOutputControl
(
std
::
move
(
output
),
client
);
try
{
...
...
@@ -91,12 +95,14 @@ MultipleOutputs::Configure(EventLoop &event_loop,
const
ReplayGainConfig
&
replay_gain_config
,
AudioOutputClient
&
client
)
{
FilterFactory
filter_factory
(
config
);
for
(
const
auto
&
block
:
config
.
GetBlockList
(
ConfigBlockOption
::
AUDIO_OUTPUT
))
{
block
.
SetUsed
();
auto
*
output
=
LoadOutputControl
(
event_loop
,
replay_gain_config
,
mixer_listener
,
client
,
block
);
client
,
block
,
&
filter_factory
);
if
(
FindByName
(
output
->
GetName
())
!=
nullptr
)
throw
FormatRuntimeError
(
"output devices with identical "
"names: %s"
,
output
->
GetName
());
...
...
@@ -110,7 +116,8 @@ MultipleOutputs::Configure(EventLoop &event_loop,
auto
*
output
=
LoadOutputControl
(
event_loop
,
replay_gain_config
,
mixer_listener
,
client
,
empty
);
client
,
empty
,
nullptr
);
outputs
.
push_back
(
output
);
}
}
...
...
@@ -125,7 +132,7 @@ MultipleOutputs::AddNullOutput(EventLoop &event_loop,
auto
*
output
=
LoadOutputControl
(
event_loop
,
replay_gain_config
,
mixer_listener
,
client
,
block
);
client
,
block
,
nullptr
);
outputs
.
push_back
(
output
);
}
...
...
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