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
d6ce2e36
Commit
d6ce2e36
authored
Jul 11, 2016
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
decoder/flac: move functions into struct FlacDecoder
parent
85b6a526
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
68 additions
and
64 deletions
+68
-64
FlacCommon.cxx
src/decoder/plugins/FlacCommon.cxx
+46
-52
FlacCommon.hxx
src/decoder/plugins/FlacCommon.hxx
+18
-7
FlacDecoderPlugin.cxx
src/decoder/plugins/FlacDecoderPlugin.cxx
+4
-5
No files found.
src/decoder/plugins/FlacCommon.cxx
View file @
d6ce2e36
...
...
@@ -82,40 +82,43 @@ FlacDecoder::Initialize(unsigned sample_rate, unsigned bits_per_sample,
return
true
;
}
static
void
flac_got_stream_info
(
FlacDecoder
*
data
,
const
FLAC__StreamMetadata_StreamInfo
*
stream_info
)
inline
void
FlacDecoder
::
OnStreamInfo
(
const
FLAC__StreamMetadata_StreamInfo
&
stream_info
)
{
if
(
data
->
initialized
||
data
->
unsupport
ed
)
if
(
initializ
ed
)
return
;
data
->
Initialize
(
stream_info
->
sample_rate
,
stream_info
->
bits_per_sample
,
stream_info
->
channels
,
stream_info
->
total_samples
);
Initialize
(
stream_info
.
sample_rate
,
stream_info
.
bits_per_sample
,
stream_info
.
channels
,
stream_info
.
total_samples
);
}
void
flac_metadata_common_cb
(
const
FLAC__StreamMetadata
*
block
,
FlacDecoder
*
data
)
inline
void
FlacDecoder
::
OnVorbisComment
(
const
FLAC__StreamMetadata_VorbisComment
&
vc
)
{
if
(
data
->
unsupported
)
return
;
ReplayGainInfo
rgi
;
if
(
flac_parse_replay_gain
(
rgi
,
vc
))
decoder_replay_gain
(
*
GetDecoder
(),
&
rgi
);
decoder_mixramp
(
*
GetDecoder
(),
flac_parse_mixramp
(
vc
));
tag
=
flac_vorbis_comments_to_tag
(
&
vc
);
}
void
FlacDecoder
::
OnMetadata
(
const
FLAC__StreamMetadata
&
metadata
)
{
if
(
unsupported
)
return
;
switch
(
block
->
type
)
{
switch
(
metadata
.
type
)
{
case
FLAC__METADATA_TYPE_STREAMINFO
:
flac_got_stream_info
(
data
,
&
block
->
data
.
stream_info
);
OnStreamInfo
(
metadata
.
data
.
stream_info
);
break
;
case
FLAC__METADATA_TYPE_VORBIS_COMMENT
:
if
(
flac_parse_replay_gain
(
rgi
,
block
->
data
.
vorbis_comment
))
decoder_replay_gain
(
*
data
->
GetDecoder
(),
&
rgi
);
decoder_mixramp
(
*
data
->
GetDecoder
(),
flac_parse_mixramp
(
block
->
data
.
vorbis_comment
));
data
->
tag
=
flac_vorbis_comments_to_tag
(
&
block
->
data
.
vorbis_comment
);
OnVorbisComment
(
metadata
.
data
.
vorbis_comment
);
break
;
default
:
...
...
@@ -123,24 +126,17 @@ void flac_metadata_common_cb(const FLAC__StreamMetadata * block,
}
}
/**
* This function attempts to call decoder_initialized() in case there
* was no STREAMINFO block. This is allowed for nonseekable streams,
* where the server sends us only a part of the file, without
* providing the STREAMINFO block from the beginning of the file
* (e.g. when seeking with SqueezeBox Server).
*/
static
bool
flac_got_first_frame
(
FlacDecoder
*
data
,
const
FLAC__FrameHeader
*
header
)
inline
bool
FlacDecoder
::
OnFirstFrame
(
const
FLAC__FrameHeader
&
header
)
{
if
(
data
->
unsupported
)
if
(
unsupported
)
return
false
;
return
data
->
Initialize
(
header
->
sample_rate
,
header
->
bits_per_sample
,
header
->
channels
,
/* unknown duration */
0
);
return
Initialize
(
header
.
sample_rate
,
header
.
bits_per_sample
,
header
.
channels
,
/* unknown duration */
0
);
}
FLAC__uint64
...
...
@@ -162,27 +158,25 @@ FlacDecoder::GetDeltaPosition(const FLAC__StreamDecoder &sd)
}
FLAC__StreamDecoderWriteStatus
flac_common_write
(
FlacDecoder
*
data
,
const
FLAC__Frame
*
frame
,
const
FLAC__int32
*
const
buf
[],
FLAC__uint64
nbytes
)
FlacDecoder
::
OnWrite
(
const
FLAC__Frame
&
frame
,
const
FLAC__int32
*
const
buf
[],
FLAC__uint64
nbytes
)
{
void
*
buffer
;
if
(
!
data
->
initialized
&&
!
flac_got_first_frame
(
data
,
&
frame
->
header
))
if
(
!
initialized
&&
!
OnFirstFrame
(
frame
.
header
))
return
FLAC__STREAM_DECODER_WRITE_STATUS_ABORT
;
size_t
buffer_size
=
frame
->
header
.
blocksize
*
data
->
frame_size
;
buffer
=
data
->
buffer
.
Get
(
buffer_size
);
size_t
buffer_size
=
frame
.
header
.
blocksize
*
frame_size
;
void
*
data
=
buffer
.
Get
(
buffer_size
);
flac_convert
(
buffer
,
frame
->
header
.
channels
,
data
->
audio_format
.
format
,
buf
,
0
,
frame
->
header
.
blocksize
);
flac_convert
(
data
,
frame
.
header
.
channels
,
audio_format
.
format
,
buf
,
0
,
frame
.
header
.
blocksize
);
unsigned
bit_rate
=
nbytes
*
8
*
frame
->
header
.
sample_rate
/
(
1000
*
frame
->
header
.
blocksize
);
unsigned
bit_rate
=
nbytes
*
8
*
frame
.
header
.
sample_rate
/
(
1000
*
frame
.
header
.
blocksize
);
auto
cmd
=
decoder_data
(
*
data
->
GetDecoder
(),
data
->
GetInputStream
(),
buffer
,
buffer_size
,
auto
cmd
=
decoder_data
(
*
GetDecoder
(),
GetInputStream
(),
data
,
buffer_size
,
bit_rate
);
switch
(
cmd
)
{
case
DecoderCommand
:
:
NONE
:
...
...
src/decoder/plugins/FlacCommon.hxx
View file @
d6ce2e36
...
...
@@ -72,19 +72,30 @@ struct FlacDecoder : public FlacInput {
bool
Initialize
(
unsigned
sample_rate
,
unsigned
bits_per_sample
,
unsigned
channels
,
FLAC__uint64
total_frames
);
void
OnMetadata
(
const
FLAC__StreamMetadata
&
metadata
);
FLAC__StreamDecoderWriteStatus
OnWrite
(
const
FLAC__Frame
&
frame
,
const
FLAC__int32
*
const
buf
[],
FLAC__uint64
nbytes
);
/**
* Calculate the delta (in bytes) between the last frame and
* the current frame.
*/
FLAC__uint64
GetDeltaPosition
(
const
FLAC__StreamDecoder
&
sd
);
};
void
flac_metadata_common_cb
(
const
FLAC__StreamMetadata
*
block
,
FlacDecoder
*
data
);
private
:
void
OnStreamInfo
(
const
FLAC__StreamMetadata_StreamInfo
&
stream_info
);
void
OnVorbisComment
(
const
FLAC__StreamMetadata_VorbisComment
&
vc
);
FLAC__StreamDecoderWriteStatus
flac_common_write
(
FlacDecoder
*
data
,
const
FLAC__Frame
*
frame
,
const
FLAC__int32
*
const
buf
[],
FLAC__uint64
nbytes
);
/**
* This function attempts to call decoder_initialized() in case there
* was no STREAMINFO block. This is allowed for nonseekable streams,
* where the server sends us only a part of the file, without
* providing the STREAMINFO block from the beginning of the file
* (e.g. when seeking with SqueezeBox Server).
*/
bool
OnFirstFrame
(
const
FLAC__FrameHeader
&
header
);
};
#endif
/* _FLAC_COMMON_H */
src/decoder/plugins/FlacDecoderPlugin.cxx
View file @
d6ce2e36
...
...
@@ -57,17 +57,16 @@ static void flacPrintErroredState(FLAC__StreamDecoderState state)
static
void
flacMetadata
(
gcc_unused
const
FLAC__StreamDecoder
*
dec
,
const
FLAC__StreamMetadata
*
block
,
void
*
vdata
)
{
flac_metadata_common_cb
(
block
,
(
FlacDecoder
*
)
vdata
);
auto
&
fd
=
*
(
FlacDecoder
*
)
vdata
;
fd
.
OnMetadata
(
*
block
);
}
static
FLAC__StreamDecoderWriteStatus
flac_write_cb
(
const
FLAC__StreamDecoder
*
dec
,
const
FLAC__Frame
*
frame
,
const
FLAC__int32
*
const
buf
[],
void
*
vdata
)
{
FlacDecoder
*
data
=
(
FlacDecoder
*
)
vdata
;
return
flac_common_write
(
data
,
frame
,
buf
,
data
->
GetDeltaPosition
(
*
dec
));
auto
&
fd
=
*
(
FlacDecoder
*
)
vdata
;
return
fd
.
OnWrite
(
*
frame
,
buf
,
fd
.
GetDeltaPosition
(
*
dec
));
}
static
bool
...
...
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