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
6d79a1cd
Commit
6d79a1cd
authored
Jan 30, 2013
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
output/httpd: add constructor, destructor, Configure()
parent
ad5eb2f8
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
66 additions
and
50 deletions
+66
-50
HttpdInternal.hxx
src/output/HttpdInternal.hxx
+7
-2
HttpdOutputPlugin.cxx
src/output/HttpdOutputPlugin.cxx
+59
-48
No files found.
src/output/HttpdInternal.hxx
View file @
6d79a1cd
...
...
@@ -34,8 +34,8 @@
#include <forward_list>
#include <stdbool.h>
struct
config_param
;
class
EventLoop
;
class
ServerSocket
;
class
HttpdClient
;
...
...
@@ -124,6 +124,11 @@ struct HttpdOutput {
*/
guint
clients_max
,
clients_cnt
;
HttpdOutput
(
EventLoop
&
_loop
);
~
HttpdOutput
();
bool
Configure
(
const
config_param
*
param
,
GError
**
error_r
);
bool
Bind
(
GError
**
error_r
);
void
Unbind
();
...
...
src/output/HttpdOutputPlugin.cxx
View file @
6d79a1cd
...
...
@@ -58,6 +58,26 @@ static void
httpd_listen_in_event
(
int
fd
,
const
struct
sockaddr
*
address
,
size_t
address_length
,
int
uid
,
void
*
ctx
);
inline
HttpdOutput
::
HttpdOutput
(
EventLoop
&
_loop
)
:
encoder
(
nullptr
),
unflushed_input
(
0
),
server_socket
(
new
ServerSocket
(
_loop
,
httpd_listen_in_event
,
this
)),
metadata
(
nullptr
)
{
}
HttpdOutput
::~
HttpdOutput
()
{
if
(
metadata
!=
nullptr
)
metadata
->
Unref
();
if
(
encoder
!=
nullptr
)
encoder_finish
(
encoder
);
delete
server_socket
;
}
inline
bool
HttpdOutput
::
Bind
(
GError
**
error_r
)
{
...
...
@@ -76,23 +96,14 @@ HttpdOutput::Unbind()
server_socket
->
Close
();
}
static
struct
audio_output
*
httpd_output_init
(
const
struct
config_param
*
param
,
GError
**
error
)
inline
bool
HttpdOutput
::
Configure
(
const
config_param
*
param
,
GError
**
error_r
)
{
HttpdOutput
*
httpd
=
new
HttpdOutput
();
if
(
!
ao_base_init
(
&
httpd
->
base
,
&
httpd_output_plugin
,
param
,
error
))
{
g_free
(
httpd
);
return
NULL
;
}
/* read configuration */
httpd
->
name
=
config_get_block_string
(
param
,
"name"
,
"Set name in config"
);
httpd
->
genre
=
config_get_block_string
(
param
,
"genre"
,
"Set genre in config"
);
httpd
->
website
=
config_get_block_string
(
param
,
"website"
,
"Set website in config"
);
name
=
config_get_block_string
(
param
,
"name"
,
"Set name in config"
);
genre
=
config_get_block_string
(
param
,
"genre"
,
"Set genre in config"
);
website
=
config_get_block_string
(
param
,
"website"
,
"Set website in config"
);
guint
port
=
config_get_block_unsigned
(
param
,
"port"
,
8000
);
...
...
@@ -101,49 +112,54 @@ httpd_output_init(const struct config_param *param,
const
struct
encoder_plugin
*
encoder_plugin
=
encoder_plugin_get
(
encoder_name
);
if
(
encoder_plugin
==
NULL
)
{
g_set_error
(
error
,
httpd_output_quark
(),
0
,
g_set_error
(
error
_r
,
httpd_output_quark
(),
0
,
"No such encoder: %s"
,
encoder_name
);
ao_base_finish
(
&
httpd
->
base
);
g_free
(
httpd
);
return
NULL
;
return
false
;
}
httpd
->
clients_max
=
config_get_block_unsigned
(
param
,
"max_clients"
,
0
);
clients_max
=
config_get_block_unsigned
(
param
,
"max_clients"
,
0
);
/* set up bind_to_address */
httpd
->
server_socket
=
new
ServerSocket
(
*
main_loop
,
httpd_listen_in_event
,
httpd
);
const
char
*
bind_to_address
=
config_get_block_string
(
param
,
"bind_to_address"
,
NULL
);
bool
success
=
bind_to_address
!=
NULL
&&
strcmp
(
bind_to_address
,
"any"
)
!=
0
?
httpd
->
server_socket
->
AddHost
(
bind_to_address
,
port
,
error
)
:
httpd
->
server_socket
->
AddPort
(
port
,
error
);
if
(
!
success
)
{
ao_base_finish
(
&
httpd
->
base
);
g_free
(
httpd
);
return
NULL
;
}
/* initialize metadata */
httpd
->
metadata
=
NULL
;
httpd
->
unflushed_input
=
0
;
?
server_socket
->
AddHost
(
bind_to_address
,
port
,
error_r
)
:
server_socket
->
AddPort
(
port
,
error_r
);
if
(
!
success
)
return
false
;
/* initialize encoder */
httpd
->
encoder
=
encoder_init
(
encoder_plugin
,
param
,
error
);
if
(
httpd
->
encoder
==
NULL
)
{
ao_base_finish
(
&
httpd
->
base
);
g_free
(
httpd
);
return
NULL
;
}
encoder
=
encoder_init
(
encoder_plugin
,
param
,
error_r
);
if
(
encoder
==
nullptr
)
return
false
;
/* determine content type */
httpd
->
content_type
=
encoder_get_mime_type
(
httpd
->
encoder
);
if
(
httpd
->
content_type
==
NULL
)
{
httpd
->
content_type
=
"application/octet-stream"
;
content_type
=
encoder_get_mime_type
(
encoder
);
if
(
content_type
==
nullptr
)
content_type
=
"application/octet-stream"
;
return
true
;
}
static
struct
audio_output
*
httpd_output_init
(
const
struct
config_param
*
param
,
GError
**
error_r
)
{
HttpdOutput
*
httpd
=
new
HttpdOutput
(
*
main_loop
);
if
(
!
ao_base_init
(
&
httpd
->
base
,
&
httpd_output_plugin
,
param
,
error_r
))
{
delete
httpd
;
return
nullptr
;
}
if
(
!
httpd
->
Configure
(
param
,
error_r
))
{
ao_base_finish
(
&
httpd
->
base
);
delete
httpd
;
return
nullptr
;
}
return
&
httpd
->
base
;
...
...
@@ -154,11 +170,6 @@ httpd_output_finish(struct audio_output *ao)
{
HttpdOutput
*
httpd
=
(
HttpdOutput
*
)
ao
;
if
(
httpd
->
metadata
)
httpd
->
metadata
->
Unref
();
encoder_finish
(
httpd
->
encoder
);
delete
httpd
->
server_socket
;
ao_base_finish
(
&
httpd
->
base
);
delete
httpd
;
}
...
...
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