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
720bf51b
Commit
720bf51b
authored
Sep 09, 2016
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
input/alsa: simplify OpenDevice(), merge redundant recovery code
parent
26bdb724
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
35 additions
and
30 deletions
+35
-30
AlsaInputPlugin.cxx
src/input/plugins/AlsaInputPlugin.cxx
+35
-30
No files found.
src/input/plugins/AlsaInputPlugin.cxx
View file @
720bf51b
...
...
@@ -241,59 +241,47 @@ AlsaInputStream::Recover(int err)
return
err
;
}
inline
snd_pcm_t
*
AlsaInputStream
::
OpenDevice
(
const
char
*
devic
e
,
int
rate
,
snd_pcm_format_t
format
,
int
channels
,
Error
&
error
)
static
bool
ConfigureCapture
(
snd_pcm_t
*
capture_handl
e
,
int
rate
,
snd_pcm_format_t
format
,
int
channels
,
Error
&
error
)
{
snd_pcm_t
*
capture_handle
;
int
err
;
if
((
err
=
snd_pcm_open
(
&
capture_handle
,
device
,
SND_PCM_STREAM_CAPTURE
,
0
))
<
0
)
{
error
.
Format
(
alsa_input_domain
,
"Failed to open device: %s (%s)"
,
device
,
snd_strerror
(
err
));
return
nullptr
;
}
snd_pcm_hw_params_t
*
hw_params
;
if
((
err
=
snd_pcm_hw_params_malloc
(
&
hw_params
))
<
0
)
{
error
.
Format
(
alsa_input_domain
,
"Cannot allocate hardware parameter structure (%s)"
,
snd_strerror
(
err
));
snd_pcm_close
(
capture_handle
);
return
nullptr
;
return
false
;
}
if
((
err
=
snd_pcm_hw_params_any
(
capture_handle
,
hw_params
))
<
0
)
{
error
.
Format
(
alsa_input_domain
,
"Cannot initialize hardware parameter structure (%s)"
,
snd_strerror
(
err
));
snd_pcm_hw_params_free
(
hw_params
);
snd_pcm_close
(
capture_handle
);
return
nullptr
;
return
false
;
}
if
((
err
=
snd_pcm_hw_params_set_access
(
capture_handle
,
hw_params
,
SND_PCM_ACCESS_RW_INTERLEAVED
))
<
0
)
{
error
.
Format
(
alsa_input_domain
,
"Cannot set access type (%s)"
,
snd_strerror
(
err
));
snd_pcm_hw_params_free
(
hw_params
);
snd_pcm_close
(
capture_handle
);
return
nullptr
;
return
false
;
}
if
((
err
=
snd_pcm_hw_params_set_format
(
capture_handle
,
hw_params
,
format
))
<
0
)
{
snd_pcm_hw_params_free
(
hw_params
);
snd_pcm_close
(
capture_handle
);
error
.
Format
(
alsa_input_domain
,
"Cannot set sample format (%s)"
,
snd_strerror
(
err
));
return
nullptr
;
return
false
;
}
if
((
err
=
snd_pcm_hw_params_set_channels
(
capture_handle
,
hw_params
,
channels
))
<
0
)
{
snd_pcm_hw_params_free
(
hw_params
);
snd_pcm_close
(
capture_handle
);
error
.
Format
(
alsa_input_domain
,
"Cannot set channels (%s)"
,
snd_strerror
(
err
));
return
nullptr
;
return
false
;
}
if
((
err
=
snd_pcm_hw_params_set_rate
(
capture_handle
,
hw_params
,
rate
,
0
))
<
0
)
{
snd_pcm_hw_params_free
(
hw_params
);
snd_pcm_close
(
capture_handle
);
error
.
Format
(
alsa_input_domain
,
"Cannot set sample rate (%s)"
,
snd_strerror
(
err
));
return
nullptr
;
return
false
;
}
/* period needs to be big enough so that poll() doesn't fire too often,
...
...
@@ -309,16 +297,14 @@ AlsaInputStream::OpenDevice(const char *device,
error
.
Format
(
alsa_input_domain
,
"Cannot set period size (%s)"
,
snd_strerror
(
err
));
snd_pcm_hw_params_free
(
hw_params
);
snd_pcm_close
(
capture_handle
);
return
nullptr
;
return
false
;
}
if
((
err
=
snd_pcm_hw_params
(
capture_handle
,
hw_params
))
<
0
)
{
error
.
Format
(
alsa_input_domain
,
"Cannot set parameters (%s)"
,
snd_strerror
(
err
));
snd_pcm_hw_params_free
(
hw_params
);
snd_pcm_close
(
capture_handle
);
return
nullptr
;
return
false
;
}
snd_pcm_hw_params_free
(
hw_params
);
...
...
@@ -333,20 +319,39 @@ AlsaInputStream::OpenDevice(const char *device,
error
.
Format
(
alsa_input_domain
,
"unable to set start threshold (%s)"
,
snd_strerror
(
err
));
snd_pcm_sw_params_free
(
sw_params
);
snd_pcm_close
(
capture_handle
);
return
nullptr
;
return
false
;
}
if
((
err
=
snd_pcm_sw_params
(
capture_handle
,
sw_params
))
<
0
)
{
error
.
Format
(
alsa_input_domain
,
"unable to install sw params (%s)"
,
snd_strerror
(
err
));
snd_pcm_sw_params_free
(
sw_params
);
snd_pcm_close
(
capture_handle
);
return
nullptr
;
return
false
;
}
snd_pcm_sw_params_free
(
sw_params
);
return
true
;
}
inline
snd_pcm_t
*
AlsaInputStream
::
OpenDevice
(
const
char
*
device
,
int
rate
,
snd_pcm_format_t
format
,
int
channels
,
Error
&
error
)
{
snd_pcm_t
*
capture_handle
;
int
err
;
if
((
err
=
snd_pcm_open
(
&
capture_handle
,
device
,
SND_PCM_STREAM_CAPTURE
,
0
))
<
0
)
{
error
.
Format
(
alsa_input_domain
,
"Failed to open device: %s (%s)"
,
device
,
snd_strerror
(
err
));
return
nullptr
;
}
if
(
!
ConfigureCapture
(
capture_handle
,
rate
,
format
,
channels
,
error
))
{
snd_pcm_close
(
capture_handle
);
return
nullptr
;
}
snd_pcm_prepare
(
capture_handle
);
return
capture_handle
;
...
...
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