MPD  0.20.18
FlacCommon.hxx
Go to the documentation of this file.
1 /*
2  * Copyright 2003-2017 The Music Player Daemon Project
3  * http://www.musicpd.org
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 
20 /*
21  * Common data structures and functions used by FLAC and OggFLAC
22  */
23 
24 #ifndef MPD_FLAC_COMMON_HXX
25 #define MPD_FLAC_COMMON_HXX
26 
27 #include "FlacInput.hxx"
28 #include "FlacPcm.hxx"
29 #include "../DecoderAPI.hxx"
30 #include "util/ConstBuffer.hxx"
31 
32 #include <FLAC/stream_decoder.h>
33 
34 struct FlacDecoder : public FlacInput {
38  bool initialized = false;
39 
43  bool unsupported = false;
44 
49  uint16_t kbit_rate;
50 
52 
57  FLAC__uint64 position = 0;
58 
60 
67 
68  FlacDecoder(DecoderClient &_client, InputStream &_input_stream)
69  :FlacInput(_input_stream, &_client) {}
70 
74  bool Initialize(unsigned sample_rate, unsigned bits_per_sample,
75  unsigned channels, FLAC__uint64 total_frames);
76 
77  void OnMetadata(const FLAC__StreamMetadata &metadata);
78 
79  FLAC__StreamDecoderWriteStatus OnWrite(const FLAC__Frame &frame,
80  const FLAC__int32 *const buf[],
81  FLAC__uint64 nbytes);
82 
87  FLAC__uint64 GetDeltaPosition(const FLAC__StreamDecoder &sd);
88 
89 private:
90  void OnStreamInfo(const FLAC__StreamMetadata_StreamInfo &stream_info);
91  void OnVorbisComment(const FLAC__StreamMetadata_VorbisComment &vc);
92 
100  bool OnFirstFrame(const FLAC__FrameHeader &header);
101 };
102 
103 #endif /* _FLAC_COMMON_H */
ConstBuffer< void > chunk
Decoded PCM data obtained by our libFLAC write callback.
Definition: FlacCommon.hxx:66
An interface between the decoder plugin and the MPD core.
Definition: Client.hxx:39
bool unsupported
Does the FLAC file contain an unsupported audio format?
Definition: FlacCommon.hxx:43
The meta information about a song file.
Definition: Tag.hxx:34
FLAC__StreamDecoderWriteStatus OnWrite(const FLAC__Frame &frame, const FLAC__int32 *const buf[], FLAC__uint64 nbytes)
FLAC__uint64 position
End of last frame&#39;s position within the stream.
Definition: FlacCommon.hxx:57
FLAC__uint64 GetDeltaPosition(const FLAC__StreamDecoder &sd)
Calculate the delta (in bytes) between the last frame and the current frame.
uint16_t kbit_rate
The kbit_rate parameter for the next DecoderBridge::SubmitData() call.
Definition: FlacCommon.hxx:49
bool Initialize(unsigned sample_rate, unsigned bits_per_sample, unsigned channels, FLAC__uint64 total_frames)
Wrapper for DecoderClient::Ready().
FlacDecoder(DecoderClient &_client, InputStream &_input_stream)
Definition: FlacCommon.hxx:68
bool initialized
Has DecoderClient::Ready() been called yet?
Definition: FlacCommon.hxx:38
This class imports libFLAC PCM data into a PCM format supported by MPD.
Definition: FlacPcm.hxx:35
This class wraps an InputStream in libFLAC stream decoder callbacks.
Definition: FlacInput.hxx:32
void OnMetadata(const FLAC__StreamMetadata &metadata)
FlacPcmImport pcm_import
Definition: FlacCommon.hxx:51