FLAC  1.4.3
Free Lossless Audio Codec
decoder.h
Go to the documentation of this file.
1 /* libFLAC++ - Free Lossless Audio Codec library
2  * Copyright (C) 2002-2009 Josh Coalson
3  * Copyright (C) 2011-2023 Xiph.Org Foundation
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * - Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * - Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * - Neither the name of the Xiph.org Foundation nor the names of its
17  * contributors may be used to endorse or promote products derived from
18  * this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 
33 #ifndef FLACPP__DECODER_H
34 #define FLACPP__DECODER_H
35 
36 #include "export.h"
37 
38 #include <string>
39 #include "FLAC/stream_decoder.h"
40 
41 
78 namespace FLAC {
79  namespace Decoder {
80 
101  public:
105  public:
106  inline State(::FLAC__StreamDecoderState state): state_(state) { }
107  inline operator ::FLAC__StreamDecoderState() const { return state_; }
108  inline const char *as_cstring() const { return ::FLAC__StreamDecoderStateString[state_]; }
109  inline const char *resolved_as_cstring(const Stream &decoder) const { return ::FLAC__stream_decoder_get_resolved_state_string(decoder.decoder_); }
110  protected:
112  };
113 
114  Stream();
115  virtual ~Stream();
116 
118 
121  virtual bool is_valid() const;
122  inline operator bool() const { return is_valid(); }
124 
125  virtual bool set_ogg_serial_number(long value);
126  virtual bool set_md5_checking(bool value);
128  virtual bool set_metadata_respond_application(const FLAC__byte id[4]);
129  virtual bool set_metadata_respond_all();
131  virtual bool set_metadata_ignore_application(const FLAC__byte id[4]);
132  virtual bool set_metadata_ignore_all();
133 
134  /* get_state() is not virtual since we want subclasses to be able to return their own state */
135  State get_state() const;
136  virtual bool get_md5_checking() const;
137  virtual FLAC__uint64 get_total_samples() const;
138  virtual uint32_t get_channels() const;
140  virtual uint32_t get_bits_per_sample() const;
141  virtual uint32_t get_sample_rate() const;
142  virtual uint32_t get_blocksize() const;
143  virtual bool get_decode_position(FLAC__uint64 *position) const;
144 
147 
148  virtual bool finish();
149 
150  virtual bool flush();
151  virtual bool reset();
152 
153  virtual bool process_single();
156  virtual bool skip_single_frame();
157 
158  virtual bool seek_absolute(FLAC__uint64 sample);
159  protected:
161  virtual ::FLAC__StreamDecoderReadStatus read_callback(FLAC__byte buffer[], size_t *bytes) = 0;
162 
164  virtual ::FLAC__StreamDecoderSeekStatus seek_callback(FLAC__uint64 absolute_byte_offset);
165 
167  virtual ::FLAC__StreamDecoderTellStatus tell_callback(FLAC__uint64 *absolute_byte_offset);
168 
171 
173  virtual bool eof_callback();
174 
176  virtual ::FLAC__StreamDecoderWriteStatus write_callback(const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[]) = 0;
177 
180 
182  virtual void error_callback(::FLAC__StreamDecoderErrorStatus status) = 0;
183 
184 #if (defined __BORLANDC__) || (defined __GNUG__ && (__GNUG__ < 2 || (__GNUG__ == 2 && __GNUC_MINOR__ < 96))) || (defined __SUNPRO_CC)
185  // lame hack: some compilers can't see a protected decoder_ from nested State::resolved_as_cstring()
186  friend State;
187 #endif
188  ::FLAC__StreamDecoder *decoder_;
189 
190  static ::FLAC__StreamDecoderReadStatus read_callback_(const ::FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
191  static ::FLAC__StreamDecoderSeekStatus seek_callback_(const ::FLAC__StreamDecoder *decoder, FLAC__uint64 absolute_byte_offset, void *client_data);
192  static ::FLAC__StreamDecoderTellStatus tell_callback_(const ::FLAC__StreamDecoder *decoder, FLAC__uint64 *absolute_byte_offset, void *client_data);
193  static ::FLAC__StreamDecoderLengthStatus length_callback_(const ::FLAC__StreamDecoder *decoder, FLAC__uint64 *stream_length, void *client_data);
194  static FLAC__bool eof_callback_(const ::FLAC__StreamDecoder *decoder, void *client_data);
195  static ::FLAC__StreamDecoderWriteStatus write_callback_(const ::FLAC__StreamDecoder *decoder, const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data);
196  static void metadata_callback_(const ::FLAC__StreamDecoder *decoder, const ::FLAC__StreamMetadata *metadata, void *client_data);
197  static void error_callback_(const ::FLAC__StreamDecoder *decoder, ::FLAC__StreamDecoderErrorStatus status, void *client_data);
198  private:
199  // Private and undefined so you can't use them:
200  Stream(const Stream &);
201  void operator=(const Stream &);
202  };
203 
223  class FLACPP_API File: public Stream {
224  public:
225  File();
226  virtual ~File();
227 
228  using Stream::init;
231  virtual ::FLAC__StreamDecoderInitStatus init(const std::string &filename);
232  using Stream::init_ogg;
235  virtual ::FLAC__StreamDecoderInitStatus init_ogg(const std::string &filename);
236  protected:
237  // this is a dummy implementation to satisfy the pure virtual in Stream that is actually supplied internally by the C layer
238  virtual ::FLAC__StreamDecoderReadStatus read_callback(FLAC__byte buffer[], size_t *bytes);
239  private:
240  // Private and undefined so you can't use them:
241  File(const File &);
242  void operator=(const File &);
243  };
244 
245  }
246 }
247 
248 #endif
This module contains #defines and symbols for exporting function calls, and providing version informa...
This class wraps the FLAC__StreamDecoder. If you are not decoding from a file, you may need to use FL...
Definition: decoder.h:223
virtual ::FLAC__StreamDecoderInitStatus init(const std::string &filename)
See FLAC__stream_decoder_init_file()
virtual ::FLAC__StreamDecoderInitStatus init_ogg(const char *filename)
See FLAC__stream_decoder_init_ogg_file()
virtual ::FLAC__StreamDecoderInitStatus init(const char *filename)
See FLAC__stream_decoder_init_file()
virtual ::FLAC__StreamDecoderReadStatus read_callback(FLAC__byte buffer[], size_t *bytes)
see FLAC__StreamDecoderReadCallback
virtual ::FLAC__StreamDecoderInitStatus init(FILE *file)
See FLAC__stream_decoder_init_FILE()
virtual ::FLAC__StreamDecoderInitStatus init_ogg(FILE *file)
See FLAC__stream_decoder_init_ogg_FILE()
virtual ::FLAC__StreamDecoderInitStatus init_ogg(const std::string &filename)
See FLAC__stream_decoder_init_ogg_file()
Definition: decoder.h:104
This class wraps the FLAC__StreamDecoder. If you are decoding from a file, FLAC::Decoder::File may be...
Definition: decoder.h:100
virtual ::FLAC__StreamDecoderTellStatus tell_callback(FLAC__uint64 *absolute_byte_offset)
see FLAC__StreamDecoderTellCallback
virtual bool finish()
See FLAC__stream_decoder_finish()
virtual bool is_valid() const
virtual void error_callback(::FLAC__StreamDecoderErrorStatus status)=0
see FLAC__StreamDecoderErrorCallback
virtual uint32_t get_sample_rate() const
See FLAC__stream_decoder_get_sample_rate()
virtual void metadata_callback(const ::FLAC__StreamMetadata *metadata)
see FLAC__StreamDecoderMetadataCallback
virtual bool set_metadata_respond_all()
See FLAC__stream_decoder_set_metadata_respond_all()
virtual bool skip_single_frame()
See FLAC__stream_decoder_skip_single_frame()
virtual ::FLAC__StreamDecoderInitStatus init()
Seek FLAC__stream_decoder_init_stream()
virtual bool get_decode_position(FLAC__uint64 *position) const
See FLAC__stream_decoder_get_decode_position()
virtual bool get_md5_checking() const
See FLAC__stream_decoder_get_md5_checking()
virtual uint32_t get_bits_per_sample() const
See FLAC__stream_decoder_get_bits_per_sample()
virtual uint32_t get_channels() const
See FLAC__stream_decoder_get_channels()
virtual ::FLAC__StreamDecoderLengthStatus length_callback(FLAC__uint64 *stream_length)
see FLAC__StreamDecoderLengthCallback
virtual uint32_t get_blocksize() const
See FLAC__stream_decoder_get_blocksize()
virtual ::FLAC__ChannelAssignment get_channel_assignment() const
See FLAC__stream_decoder_get_channel_assignment()
virtual bool reset()
See FLAC__stream_decoder_reset()
virtual bool set_md5_checking(bool value)
See FLAC__stream_decoder_set_md5_checking()
virtual bool set_metadata_ignore_all()
See FLAC__stream_decoder_set_metadata_ignore_all()
virtual bool set_metadata_respond(::FLAC__MetadataType type)
See FLAC__stream_decoder_set_metadata_respond()
virtual bool set_metadata_respond_application(const FLAC__byte id[4])
See FLAC__stream_decoder_set_metadata_respond_application()
virtual bool flush()
See FLAC__stream_decoder_flush()
virtual bool set_ogg_serial_number(long value)
See FLAC__stream_decoder_set_ogg_serial_number()
virtual bool process_until_end_of_metadata()
See FLAC__stream_decoder_process_until_end_of_metadata()
virtual bool process_single()
See FLAC__stream_decoder_process_single()
State get_state() const
See FLAC__stream_decoder_get_state()
virtual bool eof_callback()
see FLAC__StreamDecoderEofCallback
virtual bool seek_absolute(FLAC__uint64 sample)
See FLAC__stream_decoder_seek_absolute()
virtual FLAC__uint64 get_total_samples() const
See FLAC__stream_decoder_get_total_samples()
virtual bool set_metadata_ignore_application(const FLAC__byte id[4])
See FLAC__stream_decoder_set_metadata_ignore_application()
virtual ::FLAC__StreamDecoderInitStatus init_ogg()
Seek FLAC__stream_decoder_init_ogg_stream()
virtual bool set_metadata_ignore(::FLAC__MetadataType type)
See FLAC__stream_decoder_set_metadata_ignore()
virtual ::FLAC__StreamDecoderWriteStatus write_callback(const ::FLAC__Frame *frame, const FLAC__int32 *const buffer[])=0
see FLAC__StreamDecoderWriteCallback
virtual ::FLAC__StreamDecoderSeekStatus seek_callback(FLAC__uint64 absolute_byte_offset)
see FLAC__StreamDecoderSeekCallback
virtual ::FLAC__StreamDecoderReadStatus read_callback(FLAC__byte buffer[], size_t *bytes)=0
see FLAC__StreamDecoderReadCallback
virtual bool process_until_end_of_stream()
See FLAC__stream_decoder_process_until_end_of_stream()
struct FLAC__StreamMetadata FLAC__StreamMetadata
FLAC__ChannelAssignment
Definition: format.h:388
FLAC__MetadataType
Definition: format.h:496
FLAC__StreamDecoderErrorStatus
Definition: stream_decoder.h:431
FLAC__StreamDecoderState
Definition: stream_decoder.h:202
FLAC__StreamDecoderWriteStatus
Definition: stream_decoder.h:394
FLAC__StreamDecoderTellStatus
Definition: stream_decoder.h:348
FLAC__StreamDecoderInitStatus
Definition: stream_decoder.h:256
const char *const FLAC__StreamDecoderStateString[]
FLAC__StreamDecoderSeekStatus
Definition: stream_decoder.h:325
const char * FLAC__stream_decoder_get_resolved_state_string(const FLAC__StreamDecoder *decoder)
FLAC__StreamDecoderLengthStatus
Definition: stream_decoder.h:371
FLAC__StreamDecoderReadStatus
Definition: stream_decoder.h:294
#define FLACPP_API
Definition: export.h:88
This module contains the functions which implement the stream decoder.
Definition: stream_decoder.h:470

Copyright (c) 2000-2009 Josh Coalson Copyright (c) 2011-2023 Xiph.Org Foundation