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
c150fd9a
Commit
c150fd9a
authored
Jan 06, 2015
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
output/oss: move functions into the struct
parent
674d1487
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
97 additions
and
107 deletions
+97
-107
OssOutputPlugin.cxx
src/output/plugins/OssOutputPlugin.cxx
+97
-107
No files found.
src/output/plugins/OssOutputPlugin.cxx
View file @
c150fd9a
...
@@ -20,6 +20,7 @@
...
@@ -20,6 +20,7 @@
#include "config.h"
#include "config.h"
#include "OssOutputPlugin.hxx"
#include "OssOutputPlugin.hxx"
#include "../OutputAPI.hxx"
#include "../OutputAPI.hxx"
#include "../Wrapper.hxx"
#include "mixer/MixerList.hxx"
#include "mixer/MixerList.hxx"
#include "system/fd_util.h"
#include "system/fd_util.h"
#include "util/ConstBuffer.hxx"
#include "util/ConstBuffer.hxx"
...
@@ -86,6 +87,41 @@ struct OssOutput {
...
@@ -86,6 +87,41 @@ struct OssOutput {
bool
Initialize
(
const
config_param
&
param
,
Error
&
error_r
)
{
bool
Initialize
(
const
config_param
&
param
,
Error
&
error_r
)
{
return
base
.
Configure
(
param
,
error_r
);
return
base
.
Configure
(
param
,
error_r
);
}
}
static
OssOutput
*
Create
(
const
config_param
&
param
,
Error
&
error
);
#ifdef AFMT_S24_PACKED
bool
Enable
(
gcc_unused
Error
&
error
)
{
pcm_export
.
Construct
();
return
true
;
}
void
Disable
()
{
pcm_export
.
Destruct
();
}
#endif
bool
Open
(
AudioFormat
&
audio_format
,
Error
&
error
);
void
Close
()
{
DoClose
();
}
size_t
Play
(
const
void
*
chunk
,
size_t
size
,
Error
&
error
);
void
Cancel
();
private
:
/**
* Sets up the OSS device which was opened before.
*/
bool
Setup
(
AudioFormat
&
audio_format
,
Error
&
error
);
/**
* Reopen the device with the saved audio_format, without any probing.
*/
bool
Reopen
(
Error
&
error
);
void
DoClose
();
};
};
static
constexpr
Domain
oss_output_domain
(
"oss_output"
);
static
constexpr
Domain
oss_output_domain
(
"oss_output"
);
...
@@ -147,7 +183,7 @@ oss_output_test_default_device(void)
...
@@ -147,7 +183,7 @@ oss_output_test_default_device(void)
return
false
;
return
false
;
}
}
static
Audio
Output
*
static
Oss
Output
*
oss_open_default
(
Error
&
error
)
oss_open_default
(
Error
&
error
)
{
{
int
err
[
ARRAY_SIZE
(
default_devices
)];
int
err
[
ARRAY_SIZE
(
default_devices
)];
...
@@ -164,7 +200,7 @@ oss_open_default(Error &error)
...
@@ -164,7 +200,7 @@ oss_open_default(Error &error)
}
}
od
->
device
=
default_devices
[
i
];
od
->
device
=
default_devices
[
i
];
return
&
od
->
base
;
return
od
;
}
}
}
}
...
@@ -197,8 +233,8 @@ oss_open_default(Error &error)
...
@@ -197,8 +233,8 @@ oss_open_default(Error &error)
return
NULL
;
return
NULL
;
}
}
static
Audio
Output
*
inline
Oss
Output
*
oss_output_init
(
const
config_param
&
param
,
Error
&
error
)
OssOutput
::
Create
(
const
config_param
&
param
,
Error
&
error
)
{
{
const
char
*
device
=
param
.
GetBlockValue
(
"device"
);
const
char
*
device
=
param
.
GetBlockValue
(
"device"
);
if
(
device
!=
NULL
)
{
if
(
device
!=
NULL
)
{
...
@@ -209,47 +245,18 @@ oss_output_init(const config_param ¶m, Error &error)
...
@@ -209,47 +245,18 @@ oss_output_init(const config_param ¶m, Error &error)
}
}
od
->
device
=
device
;
od
->
device
=
device
;
return
&
od
->
base
;
return
od
;
}
}
return
oss_open_default
(
error
);
return
oss_open_default
(
error
);
}
}
static
void
void
oss_output_finish
(
AudioOutput
*
ao
)
OssOutput
::
DoClose
()
{
OssOutput
*
od
=
(
OssOutput
*
)
ao
;
delete
od
;
}
#ifdef AFMT_S24_PACKED
static
bool
oss_output_enable
(
AudioOutput
*
ao
,
gcc_unused
Error
&
error
)
{
OssOutput
*
od
=
(
OssOutput
*
)
ao
;
od
->
pcm_export
.
Construct
();
return
true
;
}
static
void
oss_output_disable
(
AudioOutput
*
ao
)
{
{
OssOutput
*
od
=
(
OssOutput
*
)
ao
;
if
(
fd
>=
0
)
close
(
fd
);
od
->
pcm_export
.
Destruct
();
fd
=
-
1
;
}
#endif
static
void
oss_close
(
OssOutput
*
od
)
{
if
(
od
->
fd
>=
0
)
close
(
od
->
fd
);
od
->
fd
=
-
1
;
}
}
/**
/**
...
@@ -609,18 +616,14 @@ oss_setup_sample_format(int fd, AudioFormat &audio_format,
...
@@ -609,18 +616,14 @@ oss_setup_sample_format(int fd, AudioFormat &audio_format,
return
false
;
return
false
;
}
}
/**
inline
bool
* Sets up the OSS device which was opened before.
OssOutput
::
Setup
(
AudioFormat
&
_audio_format
,
Error
&
error
)
*/
static
bool
oss_setup
(
OssOutput
*
od
,
AudioFormat
&
audio_format
,
Error
&
error
)
{
{
return
oss_setup_channels
(
od
->
fd
,
audio_format
,
error
)
&&
return
oss_setup_channels
(
fd
,
_
audio_format
,
error
)
&&
oss_setup_sample_rate
(
od
->
fd
,
audio_format
,
error
)
&&
oss_setup_sample_rate
(
fd
,
_
audio_format
,
error
)
&&
oss_setup_sample_format
(
od
->
fd
,
audio_format
,
&
od
->
oss_format
,
oss_setup_sample_format
(
fd
,
_audio_format
,
&
oss_format
,
#ifdef AFMT_S24_PACKED
#ifdef AFMT_S24_PACKED
od
->
pcm_export
,
pcm_export
,
#endif
#endif
error
);
error
);
}
}
...
@@ -628,46 +631,46 @@ oss_setup(OssOutput *od, AudioFormat &audio_format,
...
@@ -628,46 +631,46 @@ oss_setup(OssOutput *od, AudioFormat &audio_format,
/**
/**
* Reopen the device with the saved audio_format, without any probing.
* Reopen the device with the saved audio_format, without any probing.
*/
*/
static
bool
inline
bool
oss_reopen
(
OssOutput
*
od
,
Error
&
error
)
OssOutput
::
Reopen
(
Error
&
error
)
{
{
assert
(
od
->
fd
<
0
);
assert
(
fd
<
0
);
od
->
fd
=
open_cloexec
(
od
->
device
,
O_WRONLY
,
0
);
fd
=
open_cloexec
(
device
,
O_WRONLY
,
0
);
if
(
od
->
fd
<
0
)
{
if
(
fd
<
0
)
{
error
.
FormatErrno
(
"Error opening OSS device
\"
%s
\"
"
,
error
.
FormatErrno
(
"Error opening OSS device
\"
%s
\"
"
,
od
->
device
);
device
);
return
false
;
return
false
;
}
}
enum
oss_setup_result
result
;
enum
oss_setup_result
result
;
const
char
*
const
msg1
=
"Failed to set channel count"
;
const
char
*
const
msg1
=
"Failed to set channel count"
;
result
=
oss_try_ioctl
(
od
->
fd
,
SNDCTL_DSP_CHANNELS
,
result
=
oss_try_ioctl
(
fd
,
SNDCTL_DSP_CHANNELS
,
od
->
audio_format
.
channels
,
msg1
,
error
);
audio_format
.
channels
,
msg1
,
error
);
if
(
result
!=
SUCCESS
)
{
if
(
result
!=
SUCCESS
)
{
oss_close
(
od
);
DoClose
(
);
if
(
result
==
UNSUPPORTED
)
if
(
result
==
UNSUPPORTED
)
error
.
Set
(
oss_output_domain
,
msg1
);
error
.
Set
(
oss_output_domain
,
msg1
);
return
false
;
return
false
;
}
}
const
char
*
const
msg2
=
"Failed to set sample rate"
;
const
char
*
const
msg2
=
"Failed to set sample rate"
;
result
=
oss_try_ioctl
(
od
->
fd
,
SNDCTL_DSP_SPEED
,
result
=
oss_try_ioctl
(
fd
,
SNDCTL_DSP_SPEED
,
od
->
audio_format
.
sample_rate
,
msg2
,
error
);
audio_format
.
sample_rate
,
msg2
,
error
);
if
(
result
!=
SUCCESS
)
{
if
(
result
!=
SUCCESS
)
{
oss_close
(
od
);
DoClose
(
);
if
(
result
==
UNSUPPORTED
)
if
(
result
==
UNSUPPORTED
)
error
.
Set
(
oss_output_domain
,
msg2
);
error
.
Set
(
oss_output_domain
,
msg2
);
return
false
;
return
false
;
}
}
const
char
*
const
msg3
=
"Failed to set sample format"
;
const
char
*
const
msg3
=
"Failed to set sample format"
;
result
=
oss_try_ioctl
(
od
->
fd
,
SNDCTL_DSP_SAMPLESIZE
,
result
=
oss_try_ioctl
(
fd
,
SNDCTL_DSP_SAMPLESIZE
,
o
d
->
o
ss_format
,
oss_format
,
msg3
,
error
);
msg3
,
error
);
if
(
result
!=
SUCCESS
)
{
if
(
result
!=
SUCCESS
)
{
oss_close
(
od
);
DoClose
(
);
if
(
result
==
UNSUPPORTED
)
if
(
result
==
UNSUPPORTED
)
error
.
Set
(
oss_output_domain
,
msg3
);
error
.
Set
(
oss_output_domain
,
msg3
);
return
false
;
return
false
;
...
@@ -676,62 +679,47 @@ oss_reopen(OssOutput *od, Error &error)
...
@@ -676,62 +679,47 @@ oss_reopen(OssOutput *od, Error &error)
return
true
;
return
true
;
}
}
static
bool
inline
bool
oss_output_open
(
AudioOutput
*
ao
,
AudioFormat
&
audio_format
,
OssOutput
::
Open
(
AudioFormat
&
_audio_format
,
Error
&
error
)
Error
&
error
)
{
{
OssOutput
*
od
=
(
OssOutput
*
)
ao
;
fd
=
open_cloexec
(
device
,
O_WRONLY
,
0
);
if
(
fd
<
0
)
{
od
->
fd
=
open_cloexec
(
od
->
device
,
O_WRONLY
,
0
);
if
(
od
->
fd
<
0
)
{
error
.
FormatErrno
(
"Error opening OSS device
\"
%s
\"
"
,
error
.
FormatErrno
(
"Error opening OSS device
\"
%s
\"
"
,
od
->
device
);
device
);
return
false
;
return
false
;
}
}
if
(
!
oss_setup
(
od
,
audio_format
,
error
))
{
if
(
!
Setup
(
_
audio_format
,
error
))
{
oss_close
(
od
);
DoClose
(
);
return
false
;
return
false
;
}
}
od
->
audio_format
=
audio_format
;
audio_format
=
_
audio_format
;
return
true
;
return
true
;
}
}
static
void
inline
void
oss_output_close
(
AudioOutput
*
ao
)
OssOutput
::
Cancel
(
)
{
{
OssOutput
*
od
=
(
OssOutput
*
)
ao
;
if
(
fd
>=
0
)
{
ioctl
(
fd
,
SNDCTL_DSP_RESET
,
0
);
oss_close
(
od
);
DoClose
();
}
static
void
oss_output_cancel
(
AudioOutput
*
ao
)
{
OssOutput
*
od
=
(
OssOutput
*
)
ao
;
if
(
od
->
fd
>=
0
)
{
ioctl
(
od
->
fd
,
SNDCTL_DSP_RESET
,
0
);
oss_close
(
od
);
}
}
}
}
static
size_t
inline
size_t
oss_output_play
(
AudioOutput
*
ao
,
const
void
*
chunk
,
size_t
size
,
OssOutput
::
Play
(
const
void
*
chunk
,
size_t
size
,
Error
&
error
)
Error
&
error
)
{
{
OssOutput
*
od
=
(
OssOutput
*
)
ao
;
ssize_t
ret
;
ssize_t
ret
;
assert
(
size
>
0
);
assert
(
size
>
0
);
/* reopen the device since it was closed by dropBufferedAudio */
/* reopen the device since it was closed by dropBufferedAudio */
if
(
od
->
fd
<
0
&&
!
oss_reopen
(
od
,
error
))
if
(
fd
<
0
&&
!
Reopen
(
error
))
return
0
;
return
0
;
#ifdef AFMT_S24_PACKED
#ifdef AFMT_S24_PACKED
const
auto
e
=
od
->
pcm_export
->
Export
({
chunk
,
size
});
const
auto
e
=
pcm_export
->
Export
({
chunk
,
size
});
chunk
=
e
.
data
;
chunk
=
e
.
data
;
size
=
e
.
size
;
size
=
e
.
size
;
#endif
#endif
...
@@ -739,40 +727,42 @@ oss_output_play(AudioOutput *ao, const void *chunk, size_t size,
...
@@ -739,40 +727,42 @@ oss_output_play(AudioOutput *ao, const void *chunk, size_t size,
assert
(
size
>
0
);
assert
(
size
>
0
);
while
(
true
)
{
while
(
true
)
{
ret
=
write
(
od
->
fd
,
chunk
,
size
);
ret
=
write
(
fd
,
chunk
,
size
);
if
(
ret
>
0
)
{
if
(
ret
>
0
)
{
#ifdef AFMT_S24_PACKED
#ifdef AFMT_S24_PACKED
ret
=
od
->
pcm_export
->
CalcSourceSize
(
ret
);
ret
=
pcm_export
->
CalcSourceSize
(
ret
);
#endif
#endif
return
ret
;
return
ret
;
}
}
if
(
ret
<
0
&&
errno
!=
EINTR
)
{
if
(
ret
<
0
&&
errno
!=
EINTR
)
{
error
.
FormatErrno
(
"Write error on %s"
,
od
->
device
);
error
.
FormatErrno
(
"Write error on %s"
,
device
);
return
0
;
return
0
;
}
}
}
}
}
}
typedef
AudioOutputWrapper
<
OssOutput
>
Wrapper
;
const
struct
AudioOutputPlugin
oss_output_plugin
=
{
const
struct
AudioOutputPlugin
oss_output_plugin
=
{
"oss"
,
"oss"
,
oss_output_test_default_device
,
oss_output_test_default_device
,
oss_output_i
nit
,
&
Wrapper
::
I
nit
,
oss_output_f
inish
,
&
Wrapper
::
F
inish
,
#ifdef AFMT_S24_PACKED
#ifdef AFMT_S24_PACKED
oss_output_e
nable
,
&
Wrapper
::
E
nable
,
oss_output_d
isable
,
&
Wrapper
::
D
isable
,
#else
#else
nullptr
,
nullptr
,
nullptr
,
nullptr
,
#endif
#endif
oss_output_o
pen
,
&
Wrapper
::
O
pen
,
oss_output_c
lose
,
&
Wrapper
::
C
lose
,
nullptr
,
nullptr
,
nullptr
,
nullptr
,
oss_output_p
lay
,
&
Wrapper
::
P
lay
,
nullptr
,
nullptr
,
oss_output_c
ancel
,
&
Wrapper
::
C
ancel
,
nullptr
,
nullptr
,
&
oss_mixer_plugin
,
&
oss_mixer_plugin
,
...
...
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