1
/* EasyFLAC - A thin decoding wrapper around libFLAC and libOggFLAC to
2
* make your code less ugly.
4
* Copyright 2003 - Stan Seibert <volsung@xiph.org>
5
* This code is licensed under a BSD style license:
7
* Redistribution and use in source and binary forms, with or without
8
* modification, are permitted provided that the following conditions are
11
* - Redistributions of source code must retain the above copyright
12
* notice, this list of conditions and the following disclaimer.
14
* - Redistributions in binary form must reproduce the above copyright
15
* notice, this list of conditions and the following disclaimer in the
16
* documentation and/or other materials provided with the distribution.
18
* - Neither the name of the Xiph.org Foundation nor the names of its
19
* contributors may be used to endorse or promote products derived from
20
* this software without specific prior written permission.
22
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION
26
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34
************************************************************************
36
* The motivation for this wrapper is to avoid issues where you need to
37
* decode both FLAC and Ogg FLAC but don't want to enclose all of your code
38
* in enormous if blocks where the body of the two branches is essentially
39
* the same. For example, you don't want to do something like this:
43
* OggFLAC__blah_blah();
44
* OggFLAC__more_stuff();
52
* when you really just want this:
54
* EasyFLAC__blah_blah();
55
* EasyFLAC__more_stuff();
57
* This is even more cumbersome when you have to deal with constants.
59
* EasyFLAC uses essentially the same API as
60
* FLAC__stream_decoder with two additions:
62
* - EasyFLAC__is_oggflac() for those rare occassions when you might
63
* need to distiguish the difference cases.
65
* - EasyFLAC__stream_decoder_new() takes a parameter to select when
66
* you are reading FLAC or Ogg FLAC.
68
* The constants are all FLAC__stream_decoder_*.
70
* WARNING: Always call EasyFLAC__set_client_data() even if all you
71
* want to do is set the client data to NULL.
77
#include <FLAC/stream_decoder.h>
78
#include <OggFLAC/stream_decoder.h>
85
typedef struct EasyFLAC__StreamDecoder EasyFLAC__StreamDecoder;
88
typedef FLAC__StreamDecoderReadStatus (*EasyFLAC__StreamDecoderReadCallback)(const EasyFLAC__StreamDecoder *decoder, FLAC__byte buffer[], unsigned *bytes, void *client_data);
89
typedef FLAC__StreamDecoderWriteStatus (*EasyFLAC__StreamDecoderWriteCallback)(const EasyFLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data);
90
typedef void (*EasyFLAC__StreamDecoderMetadataCallback)(const EasyFLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data);
91
typedef void (*EasyFLAC__StreamDecoderErrorCallback)(const EasyFLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data);
93
struct EasyFLAC__StreamDecoder {
94
FLAC__bool is_oggflac;
95
FLAC__StreamDecoder *flac;
96
OggFLAC__StreamDecoder *oggflac;
98
EasyFLAC__StreamDecoderReadCallback read;
99
EasyFLAC__StreamDecoderWriteCallback write;
100
EasyFLAC__StreamDecoderMetadataCallback metadata;
101
EasyFLAC__StreamDecoderErrorCallback error;
108
FLAC__bool EasyFLAC__is_oggflac(EasyFLAC__StreamDecoder *decoder);
110
EasyFLAC__StreamDecoder *EasyFLAC__stream_decoder_new(FLAC__bool is_oggflac);
111
void EasyFLAC__stream_decoder_delete(EasyFLAC__StreamDecoder *decoder);
112
FLAC__bool EasyFLAC__set_read_callback(EasyFLAC__StreamDecoder *decoder, EasyFLAC__StreamDecoderReadCallback value);
113
FLAC__bool EasyFLAC__set_write_callback(EasyFLAC__StreamDecoder *decoder, EasyFLAC__StreamDecoderWriteCallback value);
114
FLAC__bool EasyFLAC__set_metadata_callback(EasyFLAC__StreamDecoder *decoder, EasyFLAC__StreamDecoderMetadataCallback value);
115
FLAC__bool EasyFLAC__set_error_callback(EasyFLAC__StreamDecoder *decoder, EasyFLAC__StreamDecoderErrorCallback value);
116
FLAC__bool EasyFLAC__set_client_data(EasyFLAC__StreamDecoder *decoder, void *value);
117
FLAC__bool EasyFLAC__set_metadata_respond(EasyFLAC__StreamDecoder *decoder, FLAC__MetadataType type);
118
FLAC__bool EasyFLAC__set_metadata_respond_application(EasyFLAC__StreamDecoder *decoder, const FLAC__byte id[4]);
119
FLAC__bool EasyFLAC__set_metadata_respond_all(EasyFLAC__StreamDecoder *decoder);
120
FLAC__bool EasyFLAC__set_metadata_ignore(EasyFLAC__StreamDecoder *decoder, FLAC__MetadataType type);
121
FLAC__bool EasyFLAC__set_metadata_ignore_application(EasyFLAC__StreamDecoder *decoder, const FLAC__byte id[4]);
122
FLAC__bool EasyFLAC__set_metadata_ignore_all(EasyFLAC__StreamDecoder *decoder);
123
FLAC__StreamDecoderState EasyFLAC__get_state(const EasyFLAC__StreamDecoder *decoder);
124
unsigned EasyFLAC__get_channels(const EasyFLAC__StreamDecoder *decoder);
125
FLAC__ChannelAssignment EasyFLAC__get_channel_assignment(const EasyFLAC__StreamDecoder *decoder);
126
unsigned EasyFLAC__get_bits_per_sample(const EasyFLAC__StreamDecoder *decoder);
127
unsigned EasyFLAC__get_sample_rate(const EasyFLAC__StreamDecoder *decoder);
128
unsigned EasyFLAC__get_blocksize(const EasyFLAC__StreamDecoder *decoder);
129
FLAC__StreamDecoderState EasyFLAC__init(EasyFLAC__StreamDecoder *decoder);
130
void EasyFLAC__finish(EasyFLAC__StreamDecoder *decoder);
131
FLAC__bool EasyFLAC__flush(EasyFLAC__StreamDecoder *decoder);
132
FLAC__bool EasyFLAC__reset(EasyFLAC__StreamDecoder *decoder);
133
FLAC__bool EasyFLAC__process_single(EasyFLAC__StreamDecoder *decoder);
134
FLAC__bool EasyFLAC__process_until_end_of_metadata(EasyFLAC__StreamDecoder *decoder);
135
FLAC__bool EasyFLAC__process_until_end_of_stream(EasyFLAC__StreamDecoder *decoder);