decoder/mpg123: move code to GetAudioFormat()
This commit is contained in:
parent
65e5a43e46
commit
a20a83eb76
@ -39,13 +39,10 @@ mpd_mpg123_finish() noexcept
|
|||||||
*
|
*
|
||||||
* @param handle a handle which was created before; on error, this
|
* @param handle a handle which was created before; on error, this
|
||||||
* function will not free it
|
* function will not free it
|
||||||
* @param audio_format this parameter is filled after successful
|
|
||||||
* return
|
|
||||||
* @return true on success
|
* @return true on success
|
||||||
*/
|
*/
|
||||||
static bool
|
static bool
|
||||||
mpd_mpg123_open(mpg123_handle *handle, Path path_fs,
|
mpd_mpg123_open(mpg123_handle *handle, Path path_fs)
|
||||||
AudioFormat &audio_format)
|
|
||||||
{
|
{
|
||||||
auto np = NarrowPath(path_fs);
|
auto np = NarrowPath(path_fs);
|
||||||
int error = mpg123_open(handle, np);
|
int error = mpg123_open(handle, np);
|
||||||
@ -56,12 +53,25 @@ mpd_mpg123_open(mpg123_handle *handle, Path path_fs,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* obtain the audio format */
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert libmpg123's format to an #AudioFormat instance.
|
||||||
|
*
|
||||||
|
* @param handle a handle which was created before; on error, this
|
||||||
|
* function will not free it
|
||||||
|
* @param audio_format this parameter is filled after successful
|
||||||
|
* return
|
||||||
|
* @return true on success
|
||||||
|
*/
|
||||||
|
static bool
|
||||||
|
GetAudioFormat(mpg123_handle &handle, AudioFormat &audio_format)
|
||||||
|
{
|
||||||
long rate;
|
long rate;
|
||||||
int channels, encoding;
|
int channels, encoding;
|
||||||
error = mpg123_getformat(handle, &rate, &channels, &encoding);
|
if (const int error = mpg123_getformat(&handle, &rate, &channels, &encoding);
|
||||||
if (error != MPG123_OK) {
|
error != MPG123_OK) {
|
||||||
FmtWarning(mpg123_domain,
|
FmtWarning(mpg123_domain,
|
||||||
"mpg123_getformat() failed: {}",
|
"mpg123_getformat() failed: {}",
|
||||||
mpg123_plain_strerror(error));
|
mpg123_plain_strerror(error));
|
||||||
@ -181,7 +191,8 @@ mpd_mpg123_file_decode(DecoderClient &client, Path path_fs)
|
|||||||
AtScopeExit(handle) { mpg123_delete(handle); };
|
AtScopeExit(handle) { mpg123_delete(handle); };
|
||||||
|
|
||||||
AudioFormat audio_format;
|
AudioFormat audio_format;
|
||||||
if (!mpd_mpg123_open(handle, path_fs, audio_format))
|
if (!mpd_mpg123_open(handle, path_fs) ||
|
||||||
|
!GetAudioFormat(*handle, audio_format))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const off_t num_samples = mpg123_length(handle);
|
const off_t num_samples = mpg123_length(handle);
|
||||||
@ -273,9 +284,9 @@ mpd_mpg123_scan_file(Path path_fs, TagHandler &handler) noexcept
|
|||||||
|
|
||||||
AudioFormat audio_format;
|
AudioFormat audio_format;
|
||||||
try {
|
try {
|
||||||
if (!mpd_mpg123_open(handle, path_fs, audio_format)) {
|
if (!mpd_mpg123_open(handle, path_fs) ||
|
||||||
|
!GetAudioFormat(*handle, audio_format))
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user