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
8d70d10a
Commit
8d70d10a
authored
Jan 25, 2017
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
output/httpd: use AudioOutputWrapper
parent
ddd8b16f
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
96 deletions
+43
-96
HttpdInternal.hxx
src/output/plugins/httpd/HttpdInternal.hxx
+15
-3
HttpdOutputPlugin.cxx
src/output/plugins/httpd/HttpdOutputPlugin.cxx
+28
-93
No files found.
src/output/plugins/httpd/HttpdInternal.hxx
View file @
8d70d10a
...
...
@@ -26,6 +26,7 @@
#define MPD_OUTPUT_HTTPD_INTERNAL_H
#include "HttpdClient.hxx"
#include "output/Wrapper.hxx"
#include "output/Internal.hxx"
#include "output/Timer.hxx"
#include "thread/Mutex.hxx"
...
...
@@ -49,6 +50,8 @@ class Encoder;
struct
Tag
;
class
HttpdOutput
final
:
ServerSocket
,
DeferredMonitor
{
friend
struct
AudioOutputWrapper
<
HttpdOutput
>
;
AudioOutput
base
;
/**
...
...
@@ -152,9 +155,7 @@ public:
HttpdOutput
(
EventLoop
&
_loop
,
const
ConfigBlock
&
block
);
~
HttpdOutput
();
operator
AudioOutput
*
()
{
return
&
base
;
}
static
HttpdOutput
*
Create
(
const
ConfigBlock
&
block
);
#if CLANG_OR_GCC_VERSION(4,7)
constexpr
...
...
@@ -168,6 +169,14 @@ public:
void
Bind
();
void
Unbind
();
void
Enable
()
{
Bind
();
}
void
Disable
()
{
Unbind
();
}
/**
* Caller must lock the mutex.
*
...
...
@@ -249,6 +258,9 @@ public:
void
CancelAllClients
();
void
Cancel
();
bool
Pause
();
private
:
virtual
void
RunDeferred
()
override
;
...
...
src/output/plugins/httpd/HttpdOutputPlugin.cxx
View file @
8d70d10a
...
...
@@ -117,18 +117,10 @@ HttpdOutput::Unbind()
});
}
static
Audio
Output
*
httpd_output_init
(
const
ConfigBlock
&
block
)
Httpd
Output
*
HttpdOutput
::
Create
(
const
ConfigBlock
&
block
)
{
return
*
new
HttpdOutput
(
io_thread_get
(),
block
);
}
static
void
httpd_output_finish
(
AudioOutput
*
ao
)
{
HttpdOutput
*
httpd
=
HttpdOutput
::
Cast
(
ao
);
delete
httpd
;
return
new
HttpdOutput
(
io_thread_get
(),
block
);
}
/**
...
...
@@ -247,22 +239,6 @@ HttpdOutput::ReadPage()
return
Page
::
Copy
(
buffer
,
size
);
}
static
void
httpd_output_enable
(
AudioOutput
*
ao
)
{
HttpdOutput
*
httpd
=
HttpdOutput
::
Cast
(
ao
);
httpd
->
Bind
();
}
static
void
httpd_output_disable
(
AudioOutput
*
ao
)
{
HttpdOutput
*
httpd
=
HttpdOutput
::
Cast
(
ao
);
httpd
->
Unbind
();
}
inline
void
HttpdOutput
::
OpenEncoder
(
AudioFormat
&
audio_format
)
{
...
...
@@ -282,6 +258,8 @@ HttpdOutput::Open(AudioFormat &audio_format)
assert
(
!
open
);
assert
(
clients
.
empty
());
const
std
::
lock_guard
<
Mutex
>
protect
(
mutex
);
OpenEncoder
(
audio_format
);
/* initialize other attributes */
...
...
@@ -291,20 +269,12 @@ HttpdOutput::Open(AudioFormat &audio_format)
open
=
true
;
}
static
void
httpd_output_open
(
AudioOutput
*
ao
,
AudioFormat
&
audio_format
)
{
HttpdOutput
*
httpd
=
HttpdOutput
::
Cast
(
ao
);
const
std
::
lock_guard
<
Mutex
>
protect
(
httpd
->
mutex
);
httpd
->
Open
(
audio_format
);
}
inline
void
HttpdOutput
::
Close
()
{
assert
(
open
);
const
std
::
lock_guard
<
Mutex
>
protect
(
mutex
);
assert
(
open
);
open
=
false
;
delete
timer
;
...
...
@@ -319,15 +289,6 @@ HttpdOutput::Close()
delete
encoder
;
}
static
void
httpd_output_close
(
AudioOutput
*
ao
)
{
HttpdOutput
*
httpd
=
HttpdOutput
::
Cast
(
ao
);
const
std
::
lock_guard
<
Mutex
>
protect
(
httpd
->
mutex
);
httpd
->
Close
();
}
void
HttpdOutput
::
RemoveClient
(
HttpdClient
&
client
)
{
...
...
@@ -365,14 +326,6 @@ HttpdOutput::Delay() const
:
std
::
chrono
::
steady_clock
::
duration
::
zero
();
}
static
std
::
chrono
::
steady_clock
::
duration
httpd_output_delay
(
AudioOutput
*
ao
)
{
HttpdOutput
*
httpd
=
HttpdOutput
::
Cast
(
ao
);
return
httpd
->
Delay
();
}
void
HttpdOutput
::
BroadcastPage
(
Page
*
page
)
{
...
...
@@ -426,22 +379,12 @@ HttpdOutput::Play(const void *chunk, size_t size)
return
size
;
}
static
size_t
httpd_output_play
(
AudioOutput
*
ao
,
const
void
*
chunk
,
size_t
size
)
{
HttpdOutput
*
httpd
=
HttpdOutput
::
Cast
(
ao
);
return
httpd
->
Play
(
chunk
,
size
);
}
static
bool
httpd_output_pause
(
AudioOutput
*
ao
)
bool
HttpdOutput
::
Pause
()
{
HttpdOutput
*
httpd
=
HttpdOutput
::
Cast
(
ao
);
if
(
httpd
->
LockHasClients
())
{
if
(
LockHasClients
())
{
static
const
char
silence
[
1020
]
=
{
0
};
httpd
->
Play
(
silence
,
sizeof
(
silence
));
Play
(
silence
,
sizeof
(
silence
));
}
return
true
;
...
...
@@ -503,14 +446,6 @@ HttpdOutput::SendTag(const Tag &tag)
}
}
static
void
httpd_output_tag
(
AudioOutput
*
ao
,
const
Tag
&
tag
)
{
HttpdOutput
*
httpd
=
HttpdOutput
::
Cast
(
ao
);
httpd
->
SendTag
(
tag
);
}
inline
void
HttpdOutput
::
CancelAllClients
()
{
...
...
@@ -528,30 +463,30 @@ HttpdOutput::CancelAllClients()
cond
.
broadcast
();
}
static
void
httpd_output_cancel
(
AudioOutput
*
ao
)
void
HttpdOutput
::
Cancel
(
)
{
HttpdOutput
*
httpd
=
HttpdOutput
::
Cast
(
ao
);
BlockingCall
(
io_thread_get
(),
[
httpd
](){
httpd
->
CancelAllClients
();
BlockingCall
(
io_thread_get
(),
[
this
](){
CancelAllClients
();
});
}
typedef
AudioOutputWrapper
<
HttpdOutput
>
Wrapper
;
const
struct
AudioOutputPlugin
httpd_output_plugin
=
{
"httpd"
,
nullptr
,
httpd_output_i
nit
,
httpd_output_f
inish
,
httpd_output_e
nable
,
httpd_output_d
isable
,
httpd_output_o
pen
,
httpd_output_c
lose
,
httpd_output_d
elay
,
httpd_output_t
ag
,
httpd_output_p
lay
,
&
Wrapper
::
I
nit
,
&
Wrapper
::
F
inish
,
&
Wrapper
::
E
nable
,
&
Wrapper
::
D
isable
,
&
Wrapper
::
O
pen
,
&
Wrapper
::
C
lose
,
&
Wrapper
::
D
elay
,
&
Wrapper
::
SendT
ag
,
&
Wrapper
::
P
lay
,
nullptr
,
httpd_output_c
ancel
,
httpd_output_p
ause
,
&
Wrapper
::
C
ancel
,
&
Wrapper
::
P
ause
,
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