3f320ff956d9dded3a2ba3be7e1338eb28d840ae
[platform/upstream/flac.git] / include / OggFLAC++ / decoder.h
1 /* libOggFLAC++ - Free Lossless Audio Codec + Ogg library
2  * Copyright (C) 2002  Josh Coalson
3  *
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.
8  *
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.
13  *
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.
18  */
19
20 #ifndef OggFLACPP__DECODER_H
21 #define OggFLACPP__DECODER_H
22
23 #include "OggFLAC/stream_decoder.h"
24 // we only need this for the state abstraction really...
25 #include "FLAC++/decoder.h"
26
27
28 /** \file include/OggFLAC++/decoder.h
29  *
30  *  \brief
31  *  This module contains the classes which implement the various
32  *  decoders.
33  *
34  *  See the detailed documentation in the
35  *  \link oggflacpp_decoder decoder \endlink module.
36  */
37
38 /** \defgroup oggflacpp_decoder OggFLAC++/decoder.h: decoder classes
39  *  \ingroup oggflacpp
40  *
41  *  \brief
42  *  This module describes the decoder layers provided by libOggFLAC++.
43  *
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.
48  *
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.
53  */
54
55 namespace OggFLAC {
56         namespace Decoder {
57
58                 // ============================================================
59                 //
60                 //  Equivalent: OggFLAC__StreamDecoder
61                 //
62                 // ============================================================
63
64                 /** \defgroup oggflacpp_stream_decoder OggFLAC++/decoder.h: stream decoder class
65                  *  \ingroup oggflacpp_decoder
66                  *
67                  *  \brief
68                  *  This class wraps the ::OggFLAC__StreamDecoder.
69                  *
70                  * See the \link oggflac_stream_decoder libOggFLAC stream decoder module \endlink.
71                  *
72                  * \{
73                  */
74
75                 /** This class wraps the ::OggFLAC__StreamDecoder.
76                  */
77                 class Stream {
78                 public:
79                         class State {
80                         public:
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_]; }
84                         protected:
85                                 ::OggFLAC__StreamDecoderState state_;
86                         };
87
88                         Stream();
89                         virtual ~Stream();
90
91                         bool is_valid() const;
92                         inline operator bool() const { return is_valid(); }
93
94                         bool set_serial_number(long value);
95                         bool set_metadata_respond(::FLAC__MetadataType type);
96                         bool set_metadata_respond_application(const FLAC__byte id[4]);
97                         bool set_metadata_respond_all();
98                         bool set_metadata_ignore(::FLAC__MetadataType type);
99                         bool set_metadata_ignore_application(const FLAC__byte id[4]);
100                         bool set_metadata_ignore_all();
101
102                         State get_state() const;
103                         FLAC::Decoder::Stream::State get_FLAC_stream_decoder_state() const;
104                         unsigned get_channels() const;
105                         ::FLAC__ChannelAssignment get_channel_assignment() const;
106                         unsigned get_bits_per_sample() const;
107                         unsigned get_sample_rate() const;
108                         unsigned get_blocksize() const;
109
110                         State init();
111
112                         void finish();
113
114                         bool flush();
115                         bool reset();
116
117                         bool process_single();
118                         bool process_until_end_of_metadata();
119                         bool process_until_end_of_stream();
120                 protected:
121                         virtual ::FLAC__StreamDecoderReadStatus read_callback(FLAC__byte buffer[], unsigned *bytes) = 0;
122                         virtual ::FLAC__StreamDecoderWriteStatus write_callback(const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[]) = 0;
123                         virtual void metadata_callback(const ::FLAC__StreamMetadata *metadata) = 0;
124                         virtual void error_callback(::FLAC__StreamDecoderErrorStatus status) = 0;
125
126                         ::OggFLAC__StreamDecoder *decoder_;
127                 private:
128                         static ::FLAC__StreamDecoderReadStatus read_callback_(const ::OggFLAC__StreamDecoder *decoder, FLAC__byte buffer[], unsigned *bytes, void *client_data);
129                         static ::FLAC__StreamDecoderWriteStatus write_callback_(const ::OggFLAC__StreamDecoder *decoder, const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data);
130                         static void metadata_callback_(const ::OggFLAC__StreamDecoder *decoder, const ::FLAC__StreamMetadata *metadata, void *client_data);
131                         static void error_callback_(const ::OggFLAC__StreamDecoder *decoder, ::FLAC__StreamDecoderErrorStatus status, void *client_data);
132
133                         // Private and undefined so you can't use them:
134                         Stream(const Stream &);
135                         void operator=(const Stream &);
136                 };
137
138                 /* \} */
139
140         };
141 };
142
143 #endif