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,
...
@@ -82,40 +82,43 @@ FlacDecoder::Initialize(unsigned sample_rate, unsigned bits_per_sample,
return
true
;
return
true
;
}
}
static
void
inline
void
flac_got_stream_info
(
FlacDecoder
*
data
,
FlacDecoder
::
OnStreamInfo
(
const
FLAC__StreamMetadata_StreamInfo
&
stream_info
)
const
FLAC__StreamMetadata_StreamInfo
*
stream_info
)
{
{
if
(
data
->
initialized
||
data
->
unsupport
ed
)
if
(
initializ
ed
)
return
;
return
;
data
->
Initialize
(
stream_info
->
sample_rate
,
Initialize
(
stream_info
.
sample_rate
,
stream_info
->
bits_per_sample
,
stream_info
.
bits_per_sample
,
stream_info
->
channels
,
stream_info
.
channels
,
stream_info
->
total_samples
);
stream_info
.
total_samples
);
}
}
void
flac_metadata_common_cb
(
const
FLAC__StreamMetadata
*
block
,
inline
void
FlacDecoder
*
data
)
FlacDecoder
::
OnVorbisComment
(
const
FLAC__StreamMetadata_VorbisComment
&
vc
)
{
{
if
(
data
->
unsupported
)
return
;
ReplayGainInfo
rgi
;
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
:
case
FLAC__METADATA_TYPE_STREAMINFO
:
flac_got_stream_info
(
data
,
&
block
->
data
.
stream_info
);
OnStreamInfo
(
metadata
.
data
.
stream_info
);
break
;
break
;
case
FLAC__METADATA_TYPE_VORBIS_COMMENT
:
case
FLAC__METADATA_TYPE_VORBIS_COMMENT
:
if
(
flac_parse_replay_gain
(
rgi
,
block
->
data
.
vorbis_comment
))
OnVorbisComment
(
metadata
.
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
);
break
;
break
;
default
:
default
:
...
@@ -123,24 +126,17 @@ void flac_metadata_common_cb(const FLAC__StreamMetadata * block,
...
@@ -123,24 +126,17 @@ void flac_metadata_common_cb(const FLAC__StreamMetadata * block,
}
}
}
}
/**
inline
bool
* This function attempts to call decoder_initialized() in case there
FlacDecoder
::
OnFirstFrame
(
const
FLAC__FrameHeader
&
header
)
* 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
)
{
{
if
(
data
->
unsupported
)
if
(
unsupported
)
return
false
;
return
false
;
return
data
->
Initialize
(
header
->
sample_rate
,
return
Initialize
(
header
.
sample_rate
,
header
->
bits_per_sample
,
header
.
bits_per_sample
,
header
->
channels
,
header
.
channels
,
/* unknown duration */
/* unknown duration */
0
);
0
);
}
}
FLAC__uint64
FLAC__uint64
...
@@ -162,27 +158,25 @@ FlacDecoder::GetDeltaPosition(const FLAC__StreamDecoder &sd)
...
@@ -162,27 +158,25 @@ FlacDecoder::GetDeltaPosition(const FLAC__StreamDecoder &sd)
}
}
FLAC__StreamDecoderWriteStatus
FLAC__StreamDecoderWriteStatus
flac_common_write
(
FlacDecoder
*
data
,
const
FLAC__Frame
*
frame
,
FlacDecoder
::
OnWrite
(
const
FLAC__Frame
&
frame
,
const
FLAC__int32
*
const
buf
[],
const
FLAC__int32
*
const
buf
[],
FLAC__uint64
nbytes
)
FLAC__uint64
nbytes
)
{
{
void
*
buffer
;
if
(
!
initialized
&&
!
OnFirstFrame
(
frame
.
header
))
if
(
!
data
->
initialized
&&
!
flac_got_first_frame
(
data
,
&
frame
->
header
))
return
FLAC__STREAM_DECODER_WRITE_STATUS_ABORT
;
return
FLAC__STREAM_DECODER_WRITE_STATUS_ABORT
;
size_t
buffer_size
=
frame
->
header
.
blocksize
*
data
->
frame_size
;
size_t
buffer_size
=
frame
.
header
.
blocksize
*
frame_size
;
buffer
=
data
->
buffer
.
Get
(
buffer_size
);
void
*
data
=
buffer
.
Get
(
buffer_size
);
flac_convert
(
buffer
,
frame
->
header
.
channels
,
flac_convert
(
data
,
frame
.
header
.
channels
,
data
->
audio_format
.
format
,
buf
,
audio_format
.
format
,
buf
,
0
,
frame
->
header
.
blocksize
);
0
,
frame
.
header
.
blocksize
);
unsigned
bit_rate
=
nbytes
*
8
*
frame
->
header
.
sample_rate
/
unsigned
bit_rate
=
nbytes
*
8
*
frame
.
header
.
sample_rate
/
(
1000
*
frame
->
header
.
blocksize
);
(
1000
*
frame
.
header
.
blocksize
);
auto
cmd
=
decoder_data
(
*
data
->
GetDecoder
(),
data
->
GetInputStream
(),
auto
cmd
=
decoder_data
(
*
GetDecoder
(),
GetInputStream
(),
buffer
,
buffer_size
,
data
,
buffer_size
,
bit_rate
);
bit_rate
);
switch
(
cmd
)
{
switch
(
cmd
)
{
case
DecoderCommand
:
:
NONE
:
case
DecoderCommand
:
:
NONE
:
...
...
src/decoder/plugins/FlacCommon.hxx
View file @
d6ce2e36
...
@@ -72,19 +72,30 @@ struct FlacDecoder : public FlacInput {
...
@@ -72,19 +72,30 @@ struct FlacDecoder : public FlacInput {
bool
Initialize
(
unsigned
sample_rate
,
unsigned
bits_per_sample
,
bool
Initialize
(
unsigned
sample_rate
,
unsigned
bits_per_sample
,
unsigned
channels
,
FLAC__uint64
total_frames
);
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
* Calculate the delta (in bytes) between the last frame and
* the current frame.
* the current frame.
*/
*/
FLAC__uint64
GetDeltaPosition
(
const
FLAC__StreamDecoder
&
sd
);
FLAC__uint64
GetDeltaPosition
(
const
FLAC__StreamDecoder
&
sd
);
};
void
flac_metadata_common_cb
(
const
FLAC__StreamMetadata
*
block
,
private
:
FlacDecoder
*
data
);
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
,
* This function attempts to call decoder_initialized() in case there
const
FLAC__int32
*
const
buf
[],
* was no STREAMINFO block. This is allowed for nonseekable streams,
FLAC__uint64
nbytes
);
* 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 */
#endif
/* _FLAC_COMMON_H */
src/decoder/plugins/FlacDecoderPlugin.cxx
View file @
d6ce2e36
...
@@ -57,17 +57,16 @@ static void flacPrintErroredState(FLAC__StreamDecoderState state)
...
@@ -57,17 +57,16 @@ static void flacPrintErroredState(FLAC__StreamDecoderState state)
static
void
flacMetadata
(
gcc_unused
const
FLAC__StreamDecoder
*
dec
,
static
void
flacMetadata
(
gcc_unused
const
FLAC__StreamDecoder
*
dec
,
const
FLAC__StreamMetadata
*
block
,
void
*
vdata
)
const
FLAC__StreamMetadata
*
block
,
void
*
vdata
)
{
{
flac_metadata_common_cb
(
block
,
(
FlacDecoder
*
)
vdata
);
auto
&
fd
=
*
(
FlacDecoder
*
)
vdata
;
fd
.
OnMetadata
(
*
block
);
}
}
static
FLAC__StreamDecoderWriteStatus
static
FLAC__StreamDecoderWriteStatus
flac_write_cb
(
const
FLAC__StreamDecoder
*
dec
,
const
FLAC__Frame
*
frame
,
flac_write_cb
(
const
FLAC__StreamDecoder
*
dec
,
const
FLAC__Frame
*
frame
,
const
FLAC__int32
*
const
buf
[],
void
*
vdata
)
const
FLAC__int32
*
const
buf
[],
void
*
vdata
)
{
{
FlacDecoder
*
data
=
(
FlacDecoder
*
)
vdata
;
auto
&
fd
=
*
(
FlacDecoder
*
)
vdata
;
return
fd
.
OnWrite
(
*
frame
,
buf
,
fd
.
GetDeltaPosition
(
*
dec
));
return
flac_common_write
(
data
,
frame
,
buf
,
data
->
GetDeltaPosition
(
*
dec
));
}
}
static
bool
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