summaryrefslogtreecommitdiff
path: root/audio/vorbis-tools/patches/patch-aj
blob: 6f8e29961630096f9d2d052282fda0bcc8367b02 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
$NetBSD: patch-aj,v 1.1 2007/01/13 15:35:52 wiz Exp $

--- oggenc/flac.c.orig	2005-06-03 10:15:10.000000000 +0000
+++ oggenc/flac.c
@@ -20,15 +20,21 @@
 #include "platform.h"
 #include "resample.h"
 
-#define DEFAULT_FLAC_FRAME_SIZE 4608
+#if NEED_EASYFLAC
+static FLAC__StreamDecoderReadStatus easyflac_read_callback(const EasyFLAC__StreamDecoder *decoder, FLAC__byte buffer[], unsigned *bytes, void *client_data);
+static FLAC__StreamDecoderWriteStatus easyflac_write_callback(const EasyFLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data);
+static void easyflac_metadata_callback(const EasyFLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data);
+static void easyflac_error_callback(const EasyFLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data);
+#else
+static FLAC__StreamDecoderReadStatus read_callback(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
+static FLAC__StreamDecoderWriteStatus write_callback(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data);
+static void metadata_callback(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data);
+static void error_callback(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data);
+static FLAC__bool eof_callback(const FLAC__StreamDecoder *decoder, void *client_data);
+#endif
 
-FLAC__StreamDecoderReadStatus easyflac_read_callback(const EasyFLAC__StreamDecoder *decoder, FLAC__byte buffer[], unsigned *bytes, void *client_data);
-FLAC__StreamDecoderWriteStatus easyflac_write_callback(const EasyFLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data);
-void easyflac_metadata_callback(const EasyFLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data);
-void easyflac_error_callback(const EasyFLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data);
-
-void resize_buffer(flacfile *flac, int newchannels, int newsamples);
-void copy_comments (vorbis_comment *v_comments, FLAC__StreamMetadata_VorbisComment *f_comments);
+static void resize_buffer(flacfile *flac, int newchannels, int newsamples);
+static void copy_comments (vorbis_comment *v_comments, FLAC__StreamMetadata_VorbisComment *f_comments);
 
 
 int flac_id(unsigned char *buf, int len)
@@ -76,6 +82,7 @@ int flac_open(FILE *in, oe_enc_opt *opt,
 	flac->in = in;
 
 	/* Setup FLAC decoder */
+#if NEED_EASYFLAC
 	flac->decoder = EasyFLAC__stream_decoder_new(oggflac_id(oldbuf, buflen));
 	EasyFLAC__set_client_data(flac->decoder, flac);
 	EasyFLAC__set_read_callback(flac->decoder, &easyflac_read_callback);
@@ -85,13 +92,31 @@ int flac_open(FILE *in, oe_enc_opt *opt,
 	EasyFLAC__set_metadata_respond(flac->decoder, FLAC__METADATA_TYPE_STREAMINFO);
 	EasyFLAC__set_metadata_respond(flac->decoder, FLAC__METADATA_TYPE_VORBIS_COMMENT);
 	EasyFLAC__init(flac->decoder);
+#else
+	flac->decoder = FLAC__stream_decoder_new();
+	FLAC__stream_decoder_set_md5_checking(flac->decoder, false);
+	FLAC__stream_decoder_set_metadata_respond(flac->decoder, FLAC__METADATA_TYPE_STREAMINFO);
+	FLAC__stream_decoder_set_metadata_respond(flac->decoder, FLAC__METADATA_TYPE_VORBIS_COMMENT);
+	if(oggflac_id(oldbuf, buflen))
+		FLAC__stream_decoder_init_ogg_stream(flac->decoder, read_callback, /*seek_callback=*/0, /*tell_callback=*/0, /*length_callback=*/0, eof_callback, write_callback, metadata_callback, error_callback, flac);
+	else
+		FLAC__stream_decoder_init_stream(flac->decoder, read_callback, /*seek_callback=*/0, /*tell_callback=*/0, /*length_callback=*/0, eof_callback, write_callback, metadata_callback, error_callback, flac);
+#endif
 	
 	/* Callback will set the total samples and sample rate */
+#if NEED_EASYFLAC
 	EasyFLAC__process_until_end_of_metadata(flac->decoder);
+#else
+	FLAC__stream_decoder_process_until_end_of_metadata(flac->decoder);
+#endif
 
 	/* Callback will set the number of channels and resize the 
 	   audio buffer */
+#if NEED_EASYFLAC
 	EasyFLAC__process_single(flac->decoder);
+#else
+	FLAC__stream_decoder_process_single(flac->decoder);
+#endif
 	
 	/* Copy format info for caller */
 	opt->rate = flac->rate;
@@ -133,11 +158,19 @@ long flac_read(void *in, float **buffer,
 		}
 		else if (!flac->eos)
 		{
+#if NEED_EASYFLAC
 			ret = EasyFLAC__process_single(flac->decoder);
 			if (!ret ||
 			    EasyFLAC__get_state(flac->decoder)
 			    == FLAC__STREAM_DECODER_END_OF_STREAM)
 				flac->eos = 1;  /* Bail out! */
+#else
+			ret = FLAC__stream_decoder_process_single(flac->decoder);
+			if (!ret ||
+			    FLAC__stream_decoder_get_state(flac->decoder)
+			    == FLAC__STREAM_DECODER_END_OF_STREAM)
+				flac->eos = 1;  /* Bail out! */
+#endif
 		} else
 			break;
 	}
@@ -157,13 +190,22 @@ void flac_close(void *info)
 	free(flac->buf);
 	free(flac->oldbuf);
 	free(flac->comments);
+#if NEED_EASYFLAC
 	EasyFLAC__finish(flac->decoder);
 	EasyFLAC__stream_decoder_delete(flac->decoder);
+#else
+	FLAC__stream_decoder_finish(flac->decoder);
+	FLAC__stream_decoder_delete(flac->decoder);
+#endif
 	free(flac);
 }
 
 
+#if NEED_EASYFLAC
 FLAC__StreamDecoderReadStatus easyflac_read_callback(const EasyFLAC__StreamDecoder *decoder, FLAC__byte buffer[], unsigned *bytes, void *client_data)
+#else
+FLAC__StreamDecoderReadStatus read_callback(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data)
+#endif
 {
 	flacfile *flac = (flacfile *) client_data;
 	int i = 0;
@@ -200,7 +242,11 @@ FLAC__StreamDecoderReadStatus easyflac_r
 	return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;	 
 }
 
+#if NEED_EASYFLAC
 FLAC__StreamDecoderWriteStatus easyflac_write_callback(const EasyFLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data)
+#else
+FLAC__StreamDecoderWriteStatus write_callback(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data)
+#endif
 {
 	flacfile *flac = (flacfile *) client_data;
 	int samples = frame->header.blocksize;
@@ -221,7 +267,11 @@ FLAC__StreamDecoderWriteStatus easyflac_
 	return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
 }
 
+#if NEED_EASYFLAC
 void easyflac_metadata_callback(const EasyFLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data)
+#else
+void metadata_callback(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data)
+#endif
 {
 	flacfile *flac = (flacfile *) client_data;
 
@@ -240,11 +290,24 @@ void easyflac_metadata_callback(const Ea
 	}
 }
 
+#if NEED_EASYFLAC
 void easyflac_error_callback(const EasyFLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data)
+#else
+void error_callback(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data)
+#endif
+{
+	flacfile *flac = (flacfile *) client_data;
+
+}
+
+#if !NEED_EASYFLAC
+FLAC__bool eof_callback(const FLAC__StreamDecoder *decoder, void *client_data)
 {
 	flacfile *flac = (flacfile *) client_data;
 
+	return feof(flac->in)? true : false;
 }
+#endif
 
 
 void resize_buffer(flacfile *flac, int newchannels, int newsamples)
@@ -292,4 +355,3 @@ void copy_comments (vorbis_comment *v_co
 		free(comment);
 	}
 }
-