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
6464b4b3
Commit
6464b4b3
authored
Nov 10, 2017
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
encoder/Configured: glue code to initialize PreparedEncoder
parent
fef9747f
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
105 additions
and
51 deletions
+105
-51
Makefile.am
Makefile.am
+1
-0
Configured.cxx
src/encoder/Configured.cxx
+57
-0
Configured.hxx
src/encoder/Configured.hxx
+39
-0
RecorderOutputPlugin.cxx
src/output/plugins/RecorderOutputPlugin.cxx
+3
-14
ShoutOutputPlugin.cxx
src/output/plugins/ShoutOutputPlugin.cxx
+3
-24
HttpdOutputPlugin.cxx
src/output/plugins/httpd/HttpdOutputPlugin.cxx
+2
-13
No files found.
Makefile.am
View file @
6464b4b3
...
@@ -1198,6 +1198,7 @@ ENCODER_LIBS = \
...
@@ -1198,6 +1198,7 @@ ENCODER_LIBS = \
$(VORBISENC_LIBS)
$(VORBISENC_LIBS)
libencoder_plugins_a_SOURCES
=
\
libencoder_plugins_a_SOURCES
=
\
src/encoder/Configured.cxx src/encoder/Configured.hxx
\
src/encoder/EncoderAPI.hxx
\
src/encoder/EncoderAPI.hxx
\
src/encoder/EncoderInterface.hxx
\
src/encoder/EncoderInterface.hxx
\
src/encoder/EncoderPlugin.hxx
\
src/encoder/EncoderPlugin.hxx
\
...
...
src/encoder/Configured.cxx
0 → 100644
View file @
6464b4b3
/*
* Copyright 2003-2017 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 "Configured.hxx"
#include "EncoderList.hxx"
#include "EncoderPlugin.hxx"
#include "config/Block.hxx"
#include "util/StringAPI.hxx"
#include "util/RuntimeError.hxx"
static
const
EncoderPlugin
&
GetConfiguredEncoderPlugin
(
const
ConfigBlock
&
block
,
bool
shout_legacy
)
{
const
char
*
name
=
block
.
GetBlockValue
(
"encoder"
,
nullptr
);
if
(
name
==
nullptr
&&
shout_legacy
)
name
=
block
.
GetBlockValue
(
"encoding"
,
nullptr
);
if
(
name
==
nullptr
)
name
=
"vorbis"
;
if
(
shout_legacy
)
{
if
(
StringIsEqual
(
name
,
"ogg"
))
name
=
"vorbis"
;
else
if
(
StringIsEqual
(
name
,
"mp3"
))
name
=
"lame"
;
}
const
auto
plugin
=
encoder_plugin_get
(
name
);
if
(
plugin
==
nullptr
)
throw
FormatRuntimeError
(
"No such encoder: %s"
,
name
);
return
*
plugin
;
}
PreparedEncoder
*
CreateConfiguredEncoder
(
const
ConfigBlock
&
block
,
bool
shout_legacy
)
{
return
encoder_init
(
GetConfiguredEncoderPlugin
(
block
,
shout_legacy
),
block
);
}
src/encoder/Configured.hxx
0 → 100644
View file @
6464b4b3
/*
* Copyright 2003-2017 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_ENCODER_CONFIGURED_HXX
#define MPD_ENCODER_CONFIGURED_HXX
struct
ConfigBlock
;
class
PreparedEncoder
;
/**
* Create a #PreparedEncoder instance from the settings in the
* #ConfigBlock. Its "encoder" setting is used to choose the encoder
* plugin.
*
* Throws an exception on error.
*
* @param shout_legacy enable the "shout" plugin legacy configuration?
* i.e. fall back to setting "encoding" instead of "encoder"
*/
PreparedEncoder
*
CreateConfiguredEncoder
(
const
ConfigBlock
&
block
,
bool
shout_legacy
=
false
);
#endif
src/output/plugins/RecorderOutputPlugin.cxx
View file @
6464b4b3
...
@@ -23,14 +23,12 @@
...
@@ -23,14 +23,12 @@
#include "tag/Format.hxx"
#include "tag/Format.hxx"
#include "encoder/ToOutputStream.hxx"
#include "encoder/ToOutputStream.hxx"
#include "encoder/EncoderInterface.hxx"
#include "encoder/EncoderInterface.hxx"
#include "encoder/EncoderPlugin.hxx"
#include "encoder/Configured.hxx"
#include "encoder/EncoderList.hxx"
#include "config/ConfigError.hxx"
#include "config/ConfigError.hxx"
#include "config/ConfigPath.hxx"
#include "config/ConfigPath.hxx"
#include "Log.hxx"
#include "Log.hxx"
#include "fs/AllocatedPath.hxx"
#include "fs/AllocatedPath.hxx"
#include "fs/io/FileOutputStream.hxx"
#include "fs/io/FileOutputStream.hxx"
#include "util/RuntimeError.hxx"
#include "util/Domain.hxx"
#include "util/Domain.hxx"
#include "util/ScopeExit.hxx"
#include "util/ScopeExit.hxx"
...
@@ -109,16 +107,11 @@ private:
...
@@ -109,16 +107,11 @@ private:
};
};
RecorderOutput
::
RecorderOutput
(
const
ConfigBlock
&
block
)
RecorderOutput
::
RecorderOutput
(
const
ConfigBlock
&
block
)
:
AudioOutput
(
0
)
:
AudioOutput
(
0
),
prepared_encoder
(
CreateConfiguredEncoder
(
block
))
{
{
/* read configuration */
/* read configuration */
const
char
*
encoder_name
=
block
.
GetBlockValue
(
"encoder"
,
"vorbis"
);
const
auto
encoder_plugin
=
encoder_plugin_get
(
encoder_name
);
if
(
encoder_plugin
==
nullptr
)
throw
FormatRuntimeError
(
"No such encoder: %s"
,
encoder_name
);
path
=
block
.
GetPath
(
"path"
);
path
=
block
.
GetPath
(
"path"
);
const
char
*
fmt
=
block
.
GetBlockValue
(
"format_path"
,
nullptr
);
const
char
*
fmt
=
block
.
GetBlockValue
(
"format_path"
,
nullptr
);
...
@@ -130,10 +123,6 @@ RecorderOutput::RecorderOutput(const ConfigBlock &block)
...
@@ -130,10 +123,6 @@ RecorderOutput::RecorderOutput(const ConfigBlock &block)
if
(
!
path
.
IsNull
()
&&
fmt
!=
nullptr
)
if
(
!
path
.
IsNull
()
&&
fmt
!=
nullptr
)
throw
std
::
runtime_error
(
"Cannot have both 'path' and 'format_path'"
);
throw
std
::
runtime_error
(
"Cannot have both 'path' and 'format_path'"
);
/* initialize encoder */
prepared_encoder
.
reset
(
encoder_init
(
*
encoder_plugin
,
block
));
}
}
inline
void
inline
void
...
...
src/output/plugins/ShoutOutputPlugin.cxx
View file @
6464b4b3
...
@@ -21,8 +21,7 @@
...
@@ -21,8 +21,7 @@
#include "ShoutOutputPlugin.hxx"
#include "ShoutOutputPlugin.hxx"
#include "../OutputAPI.hxx"
#include "../OutputAPI.hxx"
#include "encoder/EncoderInterface.hxx"
#include "encoder/EncoderInterface.hxx"
#include "encoder/EncoderPlugin.hxx"
#include "encoder/Configured.hxx"
#include "encoder/EncoderList.hxx"
#include "util/RuntimeError.hxx"
#include "util/RuntimeError.hxx"
#include "util/Domain.hxx"
#include "util/Domain.hxx"
#include "util/StringAPI.hxx"
#include "util/StringAPI.hxx"
...
@@ -88,17 +87,6 @@ require_block_string(const ConfigBlock &block, const char *name)
...
@@ -88,17 +87,6 @@ require_block_string(const ConfigBlock &block, const char *name)
return
value
;
return
value
;
}
}
static
const
EncoderPlugin
*
shout_encoder_plugin_get
(
const
char
*
name
)
{
if
(
strcmp
(
name
,
"ogg"
)
==
0
)
name
=
"vorbis"
;
else
if
(
strcmp
(
name
,
"mp3"
)
==
0
)
name
=
"lame"
;
return
encoder_plugin_get
(
name
);
}
static
void
static
void
ShoutSetAudioInfo
(
shout_t
*
shout_conn
,
const
AudioFormat
&
audio_format
)
ShoutSetAudioInfo
(
shout_t
*
shout_conn
,
const
AudioFormat
&
audio_format
)
{
{
...
@@ -114,7 +102,8 @@ ShoutSetAudioInfo(shout_t *shout_conn, const AudioFormat &audio_format)
...
@@ -114,7 +102,8 @@ ShoutSetAudioInfo(shout_t *shout_conn, const AudioFormat &audio_format)
ShoutOutput
::
ShoutOutput
(
const
ConfigBlock
&
block
)
ShoutOutput
::
ShoutOutput
(
const
ConfigBlock
&
block
)
:
AudioOutput
(
FLAG_PAUSE
),
:
AudioOutput
(
FLAG_PAUSE
),
shout_conn
(
shout_new
()),
shout_conn
(
shout_new
()),
shout_meta
(
shout_metadata_new
())
shout_meta
(
shout_metadata_new
()),
prepared_encoder
(
CreateConfiguredEncoder
(
block
,
true
))
{
{
NeedFullyDefinedAudioFormat
();
NeedFullyDefinedAudioFormat
();
...
@@ -156,16 +145,6 @@ ShoutOutput::ShoutOutput(const ConfigBlock &block)
...
@@ -156,16 +145,6 @@ ShoutOutput::ShoutOutput(const ConfigBlock &block)
throw
std
::
runtime_error
(
"bitrate must be a positive integer"
);
throw
std
::
runtime_error
(
"bitrate must be a positive integer"
);
}
}
const
char
*
encoding
=
block
.
GetBlockValue
(
"encoder"
,
nullptr
);
if
(
encoding
==
nullptr
)
encoding
=
block
.
GetBlockValue
(
"encoding"
,
"vorbis"
);
const
auto
encoder_plugin
=
shout_encoder_plugin_get
(
encoding
);
if
(
encoder_plugin
==
nullptr
)
throw
FormatRuntimeError
(
"couldn't find shout encoder plugin
\"
%s
\"
"
,
encoding
);
prepared_encoder
.
reset
(
encoder_init
(
*
encoder_plugin
,
block
));
const
char
*
const
mime_type
=
prepared_encoder
->
GetMimeType
();
const
char
*
const
mime_type
=
prepared_encoder
->
GetMimeType
();
unsigned
shout_format
;
unsigned
shout_format
;
...
...
src/output/plugins/httpd/HttpdOutputPlugin.cxx
View file @
6464b4b3
...
@@ -23,15 +23,13 @@
...
@@ -23,15 +23,13 @@
#include "HttpdClient.hxx"
#include "HttpdClient.hxx"
#include "output/OutputAPI.hxx"
#include "output/OutputAPI.hxx"
#include "encoder/EncoderInterface.hxx"
#include "encoder/EncoderInterface.hxx"
#include "encoder/EncoderPlugin.hxx"
#include "encoder/Configured.hxx"
#include "encoder/EncoderList.hxx"
#include "net/UniqueSocketDescriptor.hxx"
#include "net/UniqueSocketDescriptor.hxx"
#include "net/SocketAddress.hxx"
#include "net/SocketAddress.hxx"
#include "net/ToString.hxx"
#include "net/ToString.hxx"
#include "Page.hxx"
#include "Page.hxx"
#include "IcyMetaDataServer.hxx"
#include "IcyMetaDataServer.hxx"
#include "event/Call.hxx"
#include "event/Call.hxx"
#include "util/RuntimeError.hxx"
#include "util/Domain.hxx"
#include "util/Domain.hxx"
#include "util/DeleteDisposer.hxx"
#include "util/DeleteDisposer.hxx"
#include "Log.hxx"
#include "Log.hxx"
...
@@ -52,6 +50,7 @@ inline
...
@@ -52,6 +50,7 @@ inline
HttpdOutput
::
HttpdOutput
(
EventLoop
&
_loop
,
const
ConfigBlock
&
block
)
HttpdOutput
::
HttpdOutput
(
EventLoop
&
_loop
,
const
ConfigBlock
&
block
)
:
AudioOutput
(
FLAG_ENABLE_DISABLE
|
FLAG_PAUSE
),
:
AudioOutput
(
FLAG_ENABLE_DISABLE
|
FLAG_PAUSE
),
ServerSocket
(
_loop
),
ServerSocket
(
_loop
),
prepared_encoder
(
CreateConfiguredEncoder
(
block
)),
defer_broadcast
(
_loop
,
BIND_THIS_METHOD
(
OnDeferredBroadcast
))
defer_broadcast
(
_loop
,
BIND_THIS_METHOD
(
OnDeferredBroadcast
))
{
{
/* read configuration */
/* read configuration */
...
@@ -61,12 +60,6 @@ HttpdOutput::HttpdOutput(EventLoop &_loop, const ConfigBlock &block)
...
@@ -61,12 +60,6 @@ HttpdOutput::HttpdOutput(EventLoop &_loop, const ConfigBlock &block)
unsigned
port
=
block
.
GetBlockValue
(
"port"
,
8000u
);
unsigned
port
=
block
.
GetBlockValue
(
"port"
,
8000u
);
const
char
*
encoder_name
=
block
.
GetBlockValue
(
"encoder"
,
"vorbis"
);
const
auto
encoder_plugin
=
encoder_plugin_get
(
encoder_name
);
if
(
encoder_plugin
==
nullptr
)
throw
FormatRuntimeError
(
"No such encoder: %s"
,
encoder_name
);
clients_max
=
block
.
GetBlockValue
(
"max_clients"
,
0u
);
clients_max
=
block
.
GetBlockValue
(
"max_clients"
,
0u
);
/* set up bind_to_address */
/* set up bind_to_address */
...
@@ -77,10 +70,6 @@ HttpdOutput::HttpdOutput(EventLoop &_loop, const ConfigBlock &block)
...
@@ -77,10 +70,6 @@ HttpdOutput::HttpdOutput(EventLoop &_loop, const ConfigBlock &block)
else
else
AddPort
(
port
);
AddPort
(
port
);
/* initialize encoder */
prepared_encoder
.
reset
(
encoder_init
(
*
encoder_plugin
,
block
));
/* determine content type */
/* determine content type */
content_type
=
prepared_encoder
->
GetMimeType
();
content_type
=
prepared_encoder
->
GetMimeType
();
if
(
content_type
==
nullptr
)
if
(
content_type
==
nullptr
)
...
...
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