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
68064f1a
Commit
68064f1a
authored
Jul 08, 2016
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
decoder/flac: move duplicate code to flac_data::Initialize()
parent
475ac76a
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
47 additions
and
53 deletions
+47
-53
FlacCommon.cxx
src/decoder/plugins/FlacCommon.cxx
+41
-37
FlacCommon.hxx
src/decoder/plugins/FlacCommon.hxx
+6
-7
FlacDecoderPlugin.cxx
src/decoder/plugins/FlacDecoderPlugin.cxx
+0
-9
No files found.
src/decoder/plugins/FlacCommon.cxx
View file @
68064f1a
...
@@ -59,6 +59,38 @@ flac_sample_format(unsigned bits_per_sample)
...
@@ -59,6 +59,38 @@ flac_sample_format(unsigned bits_per_sample)
}
}
}
}
bool
flac_data
::
Initialize
(
unsigned
sample_rate
,
unsigned
bits_per_sample
,
unsigned
channels
,
FLAC__uint64
total_frames
)
{
assert
(
!
initialized
);
assert
(
!
unsupported
);
::
Error
error
;
if
(
!
audio_format_init_checked
(
audio_format
,
sample_rate
,
flac_sample_format
(
bits_per_sample
),
channels
,
error
))
{
LogError
(
error
);
unsupported
=
true
;
return
false
;
}
frame_size
=
audio_format
.
GetFrameSize
();
const
auto
duration
=
total_frames
>
0
?
SignedSongTime
::
FromScale
<
uint64_t
>
(
total_frames
,
audio_format
.
sample_rate
)
:
SignedSongTime
::
Negative
();
decoder_initialized
(
decoder
,
audio_format
,
input_stream
.
IsSeekable
(),
duration
);
initialized
=
true
;
return
true
;
}
static
void
static
void
flac_got_stream_info
(
struct
flac_data
*
data
,
flac_got_stream_info
(
struct
flac_data
*
data
,
const
FLAC__StreamMetadata_StreamInfo
*
stream_info
)
const
FLAC__StreamMetadata_StreamInfo
*
stream_info
)
...
@@ -66,20 +98,10 @@ flac_got_stream_info(struct flac_data *data,
...
@@ -66,20 +98,10 @@ flac_got_stream_info(struct flac_data *data,
if
(
data
->
initialized
||
data
->
unsupported
)
if
(
data
->
initialized
||
data
->
unsupported
)
return
;
return
;
Error
error
;
data
->
Initialize
(
stream_info
->
sample_rate
,
if
(
!
audio_format_init_checked
(
data
->
audio_format
,
stream_info
->
bits_per_sample
,
stream_info
->
sample_rate
,
stream_info
->
channels
,
flac_sample_format
(
stream_info
->
bits_per_sample
),
stream_info
->
total_samples
);
stream_info
->
channels
,
error
))
{
LogError
(
error
);
data
->
unsupported
=
true
;
return
;
}
data
->
frame_size
=
data
->
audio_format
.
GetFrameSize
();
data
->
total_frames
=
stream_info
->
total_samples
;
data
->
initialized
=
true
;
}
}
void
flac_metadata_common_cb
(
const
FLAC__StreamMetadata
*
block
,
void
flac_metadata_common_cb
(
const
FLAC__StreamMetadata
*
block
,
...
@@ -123,29 +145,11 @@ flac_got_first_frame(struct flac_data *data, const FLAC__FrameHeader *header)
...
@@ -123,29 +145,11 @@ flac_got_first_frame(struct flac_data *data, const FLAC__FrameHeader *header)
if
(
data
->
unsupported
)
if
(
data
->
unsupported
)
return
false
;
return
false
;
Error
error
;
return
data
->
Initialize
(
header
->
sample_rate
,
if
(
!
audio_format_init_checked
(
data
->
audio_format
,
header
->
bits_per_sample
,
header
->
sample_rate
,
header
->
channels
,
flac_sample_format
(
header
->
bits_per_sample
),
/* unknown duration */
header
->
channels
,
error
))
{
0
);
LogError
(
error
);
data
->
unsupported
=
true
;
return
false
;
}
data
->
frame_size
=
data
->
audio_format
.
GetFrameSize
();
const
auto
duration
=
SongTime
::
FromScale
<
uint64_t
>
(
data
->
total_frames
,
data
->
audio_format
.
sample_rate
);
decoder_initialized
(
data
->
decoder
,
data
->
audio_format
,
data
->
input_stream
.
IsSeekable
(),
duration
);
data
->
total_frames
=
0
;
/* unkown duration */
data
->
initialized
=
true
;
return
true
;
}
}
FLAC__StreamDecoderWriteStatus
FLAC__StreamDecoderWriteStatus
...
...
src/decoder/plugins/FlacCommon.hxx
View file @
68064f1a
...
@@ -55,13 +55,6 @@ struct flac_data : public FlacInput {
...
@@ -55,13 +55,6 @@ struct flac_data : public FlacInput {
AudioFormat
audio_format
;
AudioFormat
audio_format
;
/**
/**
* The total number of frames in this song. 0 means unknown.
*
* This attribute is defined if "initialized" is true.
*/
FLAC__uint64
total_frames
;
/**
* End of last frame's position within the stream. This is
* End of last frame's position within the stream. This is
* used for bit rate calculations.
* used for bit rate calculations.
*/
*/
...
@@ -73,6 +66,12 @@ struct flac_data : public FlacInput {
...
@@ -73,6 +66,12 @@ struct flac_data : public FlacInput {
Tag
tag
;
Tag
tag
;
flac_data
(
Decoder
&
decoder
,
InputStream
&
input_stream
);
flac_data
(
Decoder
&
decoder
,
InputStream
&
input_stream
);
/**
* Wrapper for decoder_initialized().
*/
bool
Initialize
(
unsigned
sample_rate
,
unsigned
bits_per_sample
,
unsigned
channels
,
FLAC__uint64
total_frames
);
};
};
void
flac_metadata_common_cb
(
const
FLAC__StreamMetadata
*
block
,
void
flac_metadata_common_cb
(
const
FLAC__StreamMetadata
*
block
,
...
...
src/decoder/plugins/FlacDecoderPlugin.cxx
View file @
68064f1a
...
@@ -141,15 +141,6 @@ flac_decoder_initialize(struct flac_data *data, FLAC__StreamDecoder *sd)
...
@@ -141,15 +141,6 @@ flac_decoder_initialize(struct flac_data *data, FLAC__StreamDecoder *sd)
if
(
data
->
initialized
)
{
if
(
data
->
initialized
)
{
/* done */
/* done */
const
auto
duration2
=
data
->
total_frames
>
0
?
SignedSongTime
::
FromScale
<
uint64_t
>
(
data
->
total_frames
,
data
->
audio_format
.
sample_rate
)
:
SignedSongTime
::
Negative
();
decoder_initialized
(
data
->
decoder
,
data
->
audio_format
,
data
->
input_stream
.
IsSeekable
(),
duration2
);
return
true
;
return
true
;
}
}
...
...
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