decoder.h
Upload User: wstnjxml
Upload Date: 2014-04-03
Package Size: 7248k
Code Size: 15k
Category:

Windows CE

Development Platform:

C/C++

  1. /* libOggFLAC++ - Free Lossless Audio Codec + Ogg library
  2.  * Copyright (C) 2002,2003,2004,2005  Josh Coalson
  3.  *
  4.  * Redistribution and use in source and binary forms, with or without
  5.  * modification, are permitted provided that the following conditions
  6.  * are met:
  7.  *
  8.  * - Redistributions of source code must retain the above copyright
  9.  * notice, this list of conditions and the following disclaimer.
  10.  *
  11.  * - Redistributions in binary form must reproduce the above copyright
  12.  * notice, this list of conditions and the following disclaimer in the
  13.  * documentation and/or other materials provided with the distribution.
  14.  *
  15.  * - Neither the name of the Xiph.org Foundation nor the names of its
  16.  * contributors may be used to endorse or promote products derived from
  17.  * this software without specific prior written permission.
  18.  *
  19.  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  20.  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  21.  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  22.  * A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR
  23.  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  24.  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  25.  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  26.  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  27.  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  28.  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  29.  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  30.  */
  31. #ifndef OggFLACPP__DECODER_H
  32. #define OggFLACPP__DECODER_H
  33. #include "export.h"
  34. #include "OggFLAC/file_decoder.h"
  35. #include "OggFLAC/seekable_stream_decoder.h"
  36. #include "OggFLAC/stream_decoder.h"
  37. // we only need this for the state abstraction really...
  38. #include "FLAC++/decoder.h"
  39. /** file include/OggFLAC++/decoder.h
  40.  *
  41.  *  brief
  42.  *  This module contains the classes which implement the various
  43.  *  decoders.
  44.  *
  45.  *  See the detailed documentation in the
  46.  *  link oggflacpp_decoder decoder endlink module.
  47.  */
  48. /** defgroup oggflacpp_decoder OggFLAC++/decoder.h: decoder classes
  49.  *  ingroup oggflacpp
  50.  *
  51.  *  brief
  52.  *  This module describes the three decoder layers provided by libOggFLAC++.
  53.  *
  54.  * The libOggFLAC++ decoder classes are object wrappers around their
  55.  * counterparts in libOggFLAC.  All three decoding layers available in
  56.  * libOggFLAC are also provided here.  The interface is very similar;
  57.  * make sure to read the link oggflac_decoder libOggFLAC decoder module endlink.
  58.  *
  59.  * The only real difference here is that instead of passing in C function
  60.  * pointers for callbacks, you inherit from the decoder class and provide
  61.  * implementations for the callbacks in the derived class; because of this
  62.  * there is no need for a 'client_data' property.
  63.  */
  64. namespace OggFLAC {
  65. namespace Decoder {
  66. // ============================================================
  67. //
  68. //  Equivalent: OggFLAC__StreamDecoder
  69. //
  70. // ============================================================
  71. /** defgroup oggflacpp_stream_decoder OggFLAC++/decoder.h: stream decoder class
  72.  *  ingroup oggflacpp_decoder
  73.  *
  74.  *  brief
  75.  *  This class wraps the ::OggFLAC__StreamDecoder.
  76.  *
  77.  * See the link oggflac_stream_decoder libOggFLAC stream decoder module endlink.
  78.  *
  79.  * {
  80.  */
  81. /** This class wraps the ::OggFLAC__StreamDecoder.
  82.  */
  83. class OggFLACPP_API Stream {
  84. public:
  85. class OggFLACPP_API State {
  86. public:
  87. inline State(::OggFLAC__StreamDecoderState state): state_(state) { }
  88. inline operator ::OggFLAC__StreamDecoderState() const { return state_; }
  89. inline const char *as_cstring() const { return ::OggFLAC__StreamDecoderStateString[state_]; }
  90. inline const char *resolved_as_cstring(const Stream &decoder) const { return ::OggFLAC__stream_decoder_get_resolved_state_string(decoder.decoder_); }
  91. protected:
  92. ::OggFLAC__StreamDecoderState state_;
  93. };
  94. Stream();
  95. virtual ~Stream();
  96. bool is_valid() const;
  97. inline operator bool() const { return is_valid(); }
  98. bool set_serial_number(long value);
  99. bool set_metadata_respond(::FLAC__MetadataType type);
  100. bool set_metadata_respond_application(const FLAC__byte id[4]);
  101. bool set_metadata_respond_all();
  102. bool set_metadata_ignore(::FLAC__MetadataType type);
  103. bool set_metadata_ignore_application(const FLAC__byte id[4]);
  104. bool set_metadata_ignore_all();
  105. State get_state() const;
  106. FLAC::Decoder::Stream::State get_FLAC_stream_decoder_state() const;
  107. unsigned get_channels() const;
  108. ::FLAC__ChannelAssignment get_channel_assignment() const;
  109. unsigned get_bits_per_sample() const;
  110. unsigned get_sample_rate() const;
  111. unsigned get_blocksize() const;
  112. /** Initialize the instance; as with the C interface,
  113.  *  init() should be called after construction and 'set'
  114.  *  calls but before any of the 'process' calls.
  115.  */
  116. State init();
  117. void finish();
  118. bool flush();
  119. bool reset();
  120. bool process_single();
  121. bool process_until_end_of_metadata();
  122. bool process_until_end_of_stream();
  123. protected:
  124. virtual ::FLAC__StreamDecoderReadStatus read_callback(FLAC__byte buffer[], unsigned *bytes) = 0;
  125. virtual ::FLAC__StreamDecoderWriteStatus write_callback(const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[]) = 0;
  126. virtual void metadata_callback(const ::FLAC__StreamMetadata *metadata) = 0;
  127. virtual void error_callback(::FLAC__StreamDecoderErrorStatus status) = 0;
  128. #if (defined _MSC_VER) || (defined __GNUG__ && (__GNUG__ < 2 || (__GNUG__ == 2 && __GNUC_MINOR__ < 96))) || (defined __SUNPRO_CC)
  129. // lame hack: some MSVC/GCC versions can't see a protected decoder_ from nested State::resolved_as_cstring()
  130. friend State;
  131. #endif
  132. ::OggFLAC__StreamDecoder *decoder_;
  133. private:
  134. static ::FLAC__StreamDecoderReadStatus read_callback_(const ::OggFLAC__StreamDecoder *decoder, FLAC__byte buffer[], unsigned *bytes, void *client_data);
  135. static ::FLAC__StreamDecoderWriteStatus write_callback_(const ::OggFLAC__StreamDecoder *decoder, const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data);
  136. static void metadata_callback_(const ::OggFLAC__StreamDecoder *decoder, const ::FLAC__StreamMetadata *metadata, void *client_data);
  137. static void error_callback_(const ::OggFLAC__StreamDecoder *decoder, ::FLAC__StreamDecoderErrorStatus status, void *client_data);
  138. // Private and undefined so you can't use them:
  139. Stream(const Stream &);
  140. void operator=(const Stream &);
  141. };
  142. /* } */
  143. // ============================================================
  144. //
  145. //  Equivalent: OggFLAC__SeekableStreamDecoder
  146. //
  147. // ============================================================
  148. /** defgroup oggflacpp_seekable_stream_decoder OggFLAC++/decoder.h: seekable stream decoder class
  149.  *  ingroup oggflacpp_decoder
  150.  *
  151.  *  brief
  152.  *  This class wraps the ::OggFLAC__SeekableStreamDecoder.
  153.  *
  154.  * See the link oggflac_seekable_stream_decoder libOggFLAC seekable stream decoder module endlink.
  155.  *
  156.  * {
  157.  */
  158. /** This class wraps the ::OggFLAC__SeekableStreamDecoder.
  159.  */
  160. class OggFLACPP_API SeekableStream {
  161. public:
  162. class OggFLACPP_API State {
  163. public:
  164. inline State(::OggFLAC__SeekableStreamDecoderState state): state_(state) { }
  165. inline operator ::OggFLAC__SeekableStreamDecoderState() const { return state_; }
  166. inline const char *as_cstring() const { return ::OggFLAC__SeekableStreamDecoderStateString[state_]; }
  167. inline const char *resolved_as_cstring(const SeekableStream &decoder) const { return ::OggFLAC__seekable_stream_decoder_get_resolved_state_string(decoder.decoder_); }
  168. protected:
  169. ::OggFLAC__SeekableStreamDecoderState state_;
  170. };
  171. SeekableStream();
  172. virtual ~SeekableStream();
  173. bool is_valid() const;
  174. inline operator bool() const { return is_valid(); }
  175. bool set_serial_number(long value);
  176. bool set_md5_checking(bool value);
  177. bool set_metadata_respond(::FLAC__MetadataType type);
  178. bool set_metadata_respond_application(const FLAC__byte id[4]);
  179. bool set_metadata_respond_all();
  180. bool set_metadata_ignore(::FLAC__MetadataType type);
  181. bool set_metadata_ignore_application(const FLAC__byte id[4]);
  182. bool set_metadata_ignore_all();
  183. State get_state() const;
  184. OggFLAC::Decoder::Stream::State get_stream_decoder_state() const;
  185. FLAC::Decoder::Stream::State get_FLAC_stream_decoder_state() const;
  186. bool get_md5_checking() const;
  187. unsigned get_channels() const;
  188. ::FLAC__ChannelAssignment get_channel_assignment() const;
  189. unsigned get_bits_per_sample() const;
  190. unsigned get_sample_rate() const;
  191. unsigned get_blocksize() const;
  192. State init();
  193. bool finish();
  194. bool flush();
  195. bool reset();
  196. bool process_single();
  197. bool process_until_end_of_metadata();
  198. bool process_until_end_of_stream();
  199. bool seek_absolute(FLAC__uint64 sample);
  200. protected:
  201. virtual ::OggFLAC__SeekableStreamDecoderReadStatus read_callback(FLAC__byte buffer[], unsigned *bytes) = 0;
  202. virtual ::OggFLAC__SeekableStreamDecoderSeekStatus seek_callback(FLAC__uint64 absolute_byte_offset) = 0;
  203. virtual ::OggFLAC__SeekableStreamDecoderTellStatus tell_callback(FLAC__uint64 *absolute_byte_offset) = 0;
  204. virtual ::OggFLAC__SeekableStreamDecoderLengthStatus length_callback(FLAC__uint64 *stream_length) = 0;
  205. virtual bool eof_callback() = 0;
  206. virtual ::FLAC__StreamDecoderWriteStatus write_callback(const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[]) = 0;
  207. virtual void metadata_callback(const ::FLAC__StreamMetadata *metadata) = 0;
  208. virtual void error_callback(::FLAC__StreamDecoderErrorStatus status) = 0;
  209. #if (defined _MSC_VER) || (defined __GNUG__ && (__GNUG__ < 2 || (__GNUG__ == 2 && __GNUC_MINOR__ < 96))) || (defined __SUNPRO_CC)
  210. // lame hack: some MSVC/GCC versions can't see a protected decoder_ from nested State::resolved_as_cstring()
  211. friend State;
  212. #endif
  213. ::OggFLAC__SeekableStreamDecoder *decoder_;
  214. private:
  215. static ::OggFLAC__SeekableStreamDecoderReadStatus read_callback_(const ::OggFLAC__SeekableStreamDecoder *decoder, FLAC__byte buffer[], unsigned *bytes, void *client_data);
  216. static ::OggFLAC__SeekableStreamDecoderSeekStatus seek_callback_(const ::OggFLAC__SeekableStreamDecoder *decoder, FLAC__uint64 absolute_byte_offset, void *client_data);
  217. static ::OggFLAC__SeekableStreamDecoderTellStatus tell_callback_(const ::OggFLAC__SeekableStreamDecoder *decoder, FLAC__uint64 *absolute_byte_offset, void *client_data);
  218. static ::OggFLAC__SeekableStreamDecoderLengthStatus length_callback_(const ::OggFLAC__SeekableStreamDecoder *decoder, FLAC__uint64 *stream_length, void *client_data);
  219. static FLAC__bool eof_callback_(const ::OggFLAC__SeekableStreamDecoder *decoder, void *client_data);
  220. static ::FLAC__StreamDecoderWriteStatus write_callback_(const ::OggFLAC__SeekableStreamDecoder *decoder, const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data);
  221. static void metadata_callback_(const ::OggFLAC__SeekableStreamDecoder *decoder, const ::FLAC__StreamMetadata *metadata, void *client_data);
  222. static void error_callback_(const ::OggFLAC__SeekableStreamDecoder *decoder, ::FLAC__StreamDecoderErrorStatus status, void *client_data);
  223. // Private and undefined so you can't use them:
  224. SeekableStream(const SeekableStream &);
  225. void operator=(const SeekableStream &);
  226. };
  227. /* } */
  228. // ============================================================
  229. //
  230. //  Equivalent: OggFLAC__FileDecoder
  231. //
  232. // ============================================================
  233. /** defgroup oggflacpp_file_decoder OggFLAC++/decoder.h: file decoder class
  234.  *  ingroup oggflacpp_decoder
  235.  *
  236.  *  brief
  237.  *  This class wraps the ::OggFLAC__FileDecoder.
  238.  *
  239.  * See the link oggflac_file_decoder libOggFLAC file decoder module endlink.
  240.  *
  241.  * {
  242.  */
  243. /** This class wraps the ::OggFLAC__FileDecoder.
  244.  */
  245. class OggFLACPP_API File {
  246. public:
  247. class OggFLACPP_API State {
  248. public:
  249. inline State(::OggFLAC__FileDecoderState state): state_(state) { }
  250. inline operator ::OggFLAC__FileDecoderState() const { return state_; }
  251. inline const char *as_cstring() const { return ::OggFLAC__FileDecoderStateString[state_]; }
  252. inline const char *resolved_as_cstring(const File &decoder) const { return ::OggFLAC__file_decoder_get_resolved_state_string(decoder.decoder_); }
  253. protected:
  254. ::OggFLAC__FileDecoderState state_;
  255. };
  256. File();
  257. virtual ~File();
  258. bool is_valid() const;
  259. inline operator bool() const { return is_valid(); }
  260. bool set_serial_number(long value);
  261. bool set_md5_checking(bool value);
  262. bool set_filename(const char *value); //!< 'value' may not be c NULL; use "-" for stdin
  263. bool set_metadata_respond(::FLAC__MetadataType type);
  264. bool set_metadata_respond_application(const FLAC__byte id[4]);
  265. bool set_metadata_respond_all();
  266. bool set_metadata_ignore(::FLAC__MetadataType type);
  267. bool set_metadata_ignore_application(const FLAC__byte id[4]);
  268. bool set_metadata_ignore_all();
  269. State get_state() const;
  270. OggFLAC::Decoder::SeekableStream::State get_seekable_stream_decoder_state() const;
  271. OggFLAC::Decoder::Stream::State get_stream_decoder_state() const;
  272. FLAC::Decoder::Stream::State get_FLAC_stream_decoder_state() const;
  273. bool get_md5_checking() const;
  274. unsigned get_channels() const;
  275. ::FLAC__ChannelAssignment get_channel_assignment() const;
  276. unsigned get_bits_per_sample() const;
  277. unsigned get_sample_rate() const;
  278. unsigned get_blocksize() const;
  279. State init();
  280. bool finish();
  281. bool process_single();
  282. bool process_until_end_of_metadata();
  283. bool process_until_end_of_file();
  284. bool seek_absolute(FLAC__uint64 sample);
  285. protected:
  286. virtual ::FLAC__StreamDecoderWriteStatus write_callback(const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[]) = 0;
  287. virtual void metadata_callback(const ::FLAC__StreamMetadata *metadata) = 0;
  288. virtual void error_callback(::FLAC__StreamDecoderErrorStatus status) = 0;
  289. #if (defined _MSC_VER) || (defined __GNUG__ && (__GNUG__ < 2 || (__GNUG__ == 2 && __GNUC_MINOR__ < 96))) || (defined __SUNPRO_CC)
  290. // lame hack: some MSVC/GCC versions can't see a protected decoder_ from nested State::resolved_as_cstring()
  291. friend State;
  292. #endif
  293. ::OggFLAC__FileDecoder *decoder_;
  294. private:
  295. static ::FLAC__StreamDecoderWriteStatus write_callback_(const ::OggFLAC__FileDecoder *decoder, const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data);
  296. static void metadata_callback_(const ::OggFLAC__FileDecoder *decoder, const ::FLAC__StreamMetadata *metadata, void *client_data);
  297. static void error_callback_(const ::OggFLAC__FileDecoder *decoder, ::FLAC__StreamDecoderErrorStatus status, void *client_data);
  298. // Private and undefined so you can't use them:
  299. File(const File &);
  300. void operator=(const File &);
  301. };
  302. /* } */
  303. }
  304. }
  305. #endif