1 /* libOggFLAC++ - Free Lossless Audio Codec + Ogg library
2 * Copyright (C) 2002 Josh Coalson
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
20 #ifndef OggFLACPP__DECODER_H
21 #define OggFLACPP__DECODER_H
23 #include "OggFLAC/stream_decoder.h"
24 // we only need this for the state abstraction really...
25 #include "FLAC++/decoder.h"
28 /** \file include/OggFLAC++/decoder.h
31 * This module contains the classes which implement the various
34 * See the detailed documentation in the
35 * \link oggflacpp_decoder decoder \endlink module.
38 /** \defgroup oggflacpp_decoder OggFLAC++/decoder.h: decoder classes
42 * This module describes the decoder layers provided by libOggFLAC++.
44 * The libOggFLAC++ decoder classes are object wrappers around their
45 * counterparts in libOggFLAC. Only the stream decoding layer in
46 * libOggFLAC provided here. The interface is very similar;
47 * make sure to read the \link oggflac_decoder libOggFLAC decoder module \endlink.
49 * The only real difference here is that instead of passing in C function
50 * pointers for callbacks, you inherit from the decoder class and provide
51 * implementations for the callbacks in the derived class; because of this
52 * there is no need for a 'client_data' property.
58 // ============================================================
60 // Equivalent: OggFLAC__StreamDecoder
62 // ============================================================
64 /** \defgroup oggflacpp_stream_decoder OggFLAC++/decoder.h: stream decoder class
65 * \ingroup oggflacpp_decoder
68 * This class wraps the ::OggFLAC__StreamDecoder.
70 * See the \link oggflac_stream_decoder libOggFLAC stream decoder module \endlink.
75 /** This class wraps the ::OggFLAC__StreamDecoder.
81 inline State(::OggFLAC__StreamDecoderState state): state_(state) { }
82 inline operator ::OggFLAC__StreamDecoderState() const { return state_; }
83 inline const char *as_cstring() const { return ::OggFLAC__StreamDecoderStateString[state_]; }
85 ::OggFLAC__StreamDecoderState state_;
91 bool is_valid() const;
92 inline operator bool() const { return is_valid(); }
94 bool set_metadata_respond(::FLAC__MetadataType type);
95 bool set_metadata_respond_application(const FLAC__byte id[4]);
96 bool set_metadata_respond_all();
97 bool set_metadata_ignore(::FLAC__MetadataType type);
98 bool set_metadata_ignore_application(const FLAC__byte id[4]);
99 bool set_metadata_ignore_all();
101 State get_state() const;
102 FLAC::Decoder::Stream::State get_FLAC_stream_decoder_state() const;
103 unsigned get_channels() const;
104 ::FLAC__ChannelAssignment get_channel_assignment() const;
105 unsigned get_bits_per_sample() const;
106 unsigned get_sample_rate() const;
107 unsigned get_blocksize() const;
116 bool process_single();
117 bool process_until_end_of_metadata();
118 bool process_until_end_of_stream();
120 virtual ::FLAC__StreamDecoderReadStatus read_callback(FLAC__byte buffer[], unsigned *bytes) = 0;
121 virtual ::FLAC__StreamDecoderWriteStatus write_callback(const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[]) = 0;
122 virtual void metadata_callback(const ::FLAC__StreamMetadata *metadata) = 0;
123 virtual void error_callback(::FLAC__StreamDecoderErrorStatus status) = 0;
125 ::OggFLAC__StreamDecoder *decoder_;
127 static ::FLAC__StreamDecoderReadStatus read_callback_(const ::OggFLAC__StreamDecoder *decoder, FLAC__byte buffer[], unsigned *bytes, void *client_data);
128 static ::FLAC__StreamDecoderWriteStatus write_callback_(const ::OggFLAC__StreamDecoder *decoder, const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data);
129 static void metadata_callback_(const ::OggFLAC__StreamDecoder *decoder, const ::FLAC__StreamMetadata *metadata, void *client_data);
130 static void error_callback_(const ::OggFLAC__StreamDecoder *decoder, ::FLAC__StreamDecoderErrorStatus status, void *client_data);
132 // Private and undefined so you can't use them:
133 Stream(const Stream &);
134 void operator=(const Stream &);