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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
|
--- cdda_d/if_flac.c.orig 2008-04-06 21:14:40.000000000 +0200
+++ cdda_d/if_flac.c 2008-04-06 22:11:17.000000000 +0200
@@ -57,7 +57,6 @@ typedef float FLAC__real;
#include <FLAC/format.h>
#include <FLAC/metadata.h>
#include <FLAC/stream_encoder.h>
-#include <FLAC/seekable_stream_encoder.h>
extern appdata_t app_data;
@@ -86,7 +85,6 @@ extern char *tagcomment; /* Tag commen
/* Container union for encoder instance pointers */
typedef union {
FLAC__StreamEncoder *st; /* Stream encoder */
- FLAC__SeekableStreamEncoder *sk; /* Seekable stream encoder */
} flac_desc_t;
@@ -153,76 +151,10 @@ if_flac_write_callback(
/*
- * if_flac_seekable_write_callback
- * FLAC seekable stream encoder write callback function
- *
- * Args:
- * skp - Seekable stream encoder instance descriptor
- * buf - Output data buffer
- * len - data length
- * samples - number of samples
- * frame - Current frame
- * client_data - Callback data
- *
- * Return:
- * FLAC__STREAM_ENCODER_WRITE_STATUS_OK - success
- * FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR - failure
- */
-/*ARGSUSED*/
-STATIC FLAC__StreamEncoderWriteStatus
-if_flac_seekable_write_callback(
- const FLAC__SeekableStreamEncoder *skp,
- const FLAC__byte *buf,
- unsigned int len,
- unsigned int samples,
- unsigned int frame,
- void *client_data
-)
-{
- gen_desc_t *gdp = (gen_desc_t *) client_data;
-
- if (buf == NULL || len == 0)
- /* Nothing to do */
- return FLAC__STREAM_ENCODER_WRITE_STATUS_OK;
-
- /* Write out the encoded data */
- gdp->flags |= GDESC_WRITEOUT;
- if (!gen_write_chunk(gdp, (byte_t *) buf, (size_t) len))
- return FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR;
-
- return FLAC__STREAM_ENCODER_WRITE_STATUS_OK;
-}
-
-
-/*
* if_flac_metadata_callback
* FLAC stream encoder metadata callback function
*
* Args:
- * stp - Encoder instance descriptor
- * data - Metadata buffer
- * client_data - Callback data
- *
- * Return:
- * Nothing.
- */
-/*ARGSUSED*/
-STATIC void
-if_flac_metadata_callback(
- const FLAC__StreamEncoder *stp,
- const FLAC__StreamMetadata *meta,
- void *client_data
-)
-{
- /* Do nothing: can't seek on a pipe */
-}
-
-
-/*
- * if_flac_seek_callback
- * FLAC seekable stream encoder seek callback function
- *
- * Args:
* skp - Encoder instance descriptor
* data - Metadata buffer
* client_data - Callback data
@@ -231,9 +163,9 @@ if_flac_metadata_callback(
* Nothing.
*/
/*ARGSUSED*/
-STATIC FLAC__SeekableStreamEncoderSeekStatus
-if_flac_seek_callback(
- const FLAC__SeekableStreamEncoder *skp,
+STATIC FLAC__StreamEncoderSeekStatus
+if_flac_metadata_callback(
+ const FLAC__StreamEncoder *skp,
FLAC__uint64 offset,
void *client_data
)
@@ -244,9 +176,9 @@ if_flac_seek_callback(
val = (off_t) ASSIGN32(offset);
if (gen_seek(gdp, val, SEEK_SET))
- return FLAC__SEEKABLE_STREAM_ENCODER_SEEK_STATUS_OK;
+ return FLAC__STREAM_ENCODER_SEEK_STATUS_OK;
else
- return FLAC__SEEKABLE_STREAM_ENCODER_SEEK_STATUS_ERROR;
+ return FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR;
}
@@ -635,16 +567,9 @@ if_flac_addmeta(gen_desc_t *gdp, flac_de
if (flac_mblks == 0)
return; /* No metadata to set */
- if ((gdp->flags & GDESC_ISPIPE) != 0) {
- ret = FLAC__stream_encoder_set_metadata(
- ufdp->st, flac_mlist, flac_mblks
- );
- }
- else {
- ret = FLAC__seekable_stream_encoder_set_metadata(
- ufdp->sk, flac_mlist, flac_mblks
- );
- }
+ ret = FLAC__stream_encoder_set_metadata(
+ ufdp->st, flac_mlist, flac_mblks
+ );
if (!ret) {
(void) strcpy(gdp->cdp->i->msgbuf,
"if_flac_addmeta: Failed setting metadata.");
@@ -655,7 +580,7 @@ if_flac_addmeta(gen_desc_t *gdp, flac_de
/*
* if_flac_encoder_setup
- * Create and set up the FLAC stream encoder (used for pipe output).
+ * Create and set up the FLAC stream encoder.
*
* Args:
* gdp - Pointer to the gen_desc_t structure
@@ -836,43 +761,12 @@ if_flac_encoder_setup(
/* Initialize and add metadata to FLAC output */
if_flac_addmeta(gdp, ufdp);
- /* Register write callback function */
- ret = FLAC__stream_encoder_set_write_callback(
- stp, if_flac_write_callback
- );
- if (!ret) {
- (void) strcpy(gdp->cdp->i->msgbuf,
- "if_flac_encoder_setup: "
- "Failed setting write callback.");
- DBGPRN(DBG_SND)(errfp, "%s\n", gdp->cdp->i->msgbuf);
- return FALSE;
- }
-
- /* Register metadata callback function */
- ret = FLAC__stream_encoder_set_metadata_callback(
- stp, if_flac_metadata_callback
- );
- if (!ret) {
- (void) strcpy(gdp->cdp->i->msgbuf,
- "if_flac_encoder_setup: "
- "Failed setting metadata callback.");
- DBGPRN(DBG_SND)(errfp, "%s\n", gdp->cdp->i->msgbuf);
- return FALSE;
- }
-
- /* Set callback argument */
- ret = FLAC__stream_encoder_set_client_data(stp, gdp);
- if (!ret) {
- (void) strcpy(gdp->cdp->i->msgbuf,
- "if_flac_encoder_setup: "
- "Failed setting client data.");
- DBGPRN(DBG_SND)(errfp, "%s\n", gdp->cdp->i->msgbuf);
- return FALSE;
- }
-
/* Initialize FLAC encoder */
- enc_state = FLAC__stream_encoder_init(stp);
- if (enc_state != FLAC__STREAM_ENCODER_OK) {
+ enc_state = FLAC__stream_encoder_init_stream(
+ stp, if_flac_write_callback, NULL, NULL,
+ if_flac_metadata_callback, gdp
+ );
+ if (enc_state != FLAC__STREAM_ENCODER_INIT_STATUS_OK) {
(void) sprintf(gdp->cdp->i->msgbuf,
"if_flac_encoder_setup: Encoder init error: %s",
FLAC__stream_encoder_get_resolved_state_string(stp)
@@ -908,271 +802,6 @@ if_flac_encoder_setup(
/*
- * if_flac_seekable_encoder_setup
- * Create and set up the FLAC seekable stream encoder (used for file
- * output).
- *
- * Args:
- * gdp - Pointer to the gen_desc_t structure
- * ufdp - Pointer to the flac_desc_t structure
- * pp - Pointer to the flac_parms_t structure
- *
- * Return:
- * TRUE - success
- * FALSE - failure
- */
-STATIC bool_t
-if_flac_seekable_encoder_setup(
- gen_desc_t *gdp,
- flac_desc_t *ufdp,
- flac_parms_t *pp
-)
-{
- FLAC__SeekableStreamEncoder *skp;
- FLAC__SeekableStreamEncoderState enc_state;
- FLAC__uint64 val;
- FLAC__bool ret;
-
- ufdp->sk = skp = FLAC__seekable_stream_encoder_new();
- if (skp == NULL) {
- (void) strcpy(gdp->cdp->i->msgbuf,
- "if_flac_seekable_encoder_setup: "
- "FLAC encoder instantiation failed.");
- DBGPRN(DBG_SND)(errfp, "%s\n", gdp->cdp->i->msgbuf);
- return FALSE;
- }
-
- /* Set some basic parameters */
-
- ret = FLAC__seekable_stream_encoder_set_channels(skp, 2);
- if (!ret) {
- (void) strcpy(gdp->cdp->i->msgbuf,
- "if_flac_seekable_encoder_setup: "
- "Failed setting channels.");
- DBGPRN(DBG_SND)(errfp, "%s\n", gdp->cdp->i->msgbuf);
- return FALSE;
- }
-
- ret = FLAC__seekable_stream_encoder_set_bits_per_sample(skp, 16);
- if (!ret) {
- (void) strcpy(gdp->cdp->i->msgbuf,
- "if_flac_seekable_encoder_setup: "
- "Failed setting bits per sample.");
- DBGPRN(DBG_SND)(errfp, "%s\n", gdp->cdp->i->msgbuf);
- return FALSE;
- }
-
- ret = FLAC__seekable_stream_encoder_set_sample_rate(skp, 44100);
- if (!ret) {
- (void) strcpy(gdp->cdp->i->msgbuf,
- "if_flac_seekable_encoder_setup: "
- "Failed setting sample rate.");
- DBGPRN(DBG_SND)(errfp, "%s\n", gdp->cdp->i->msgbuf);
- return FALSE;
- }
-
- val = ASSIGN64(gdp->datalen >> 2);
- ret = FLAC__seekable_stream_encoder_set_total_samples_estimate(
- skp, val
- );
- if (!ret) {
- (void) strcpy(gdp->cdp->i->msgbuf,
- "if_flac_seekable_encoder_setup: "
- "Failed setting samples estimate.");
- DBGPRN(DBG_SND)(errfp, "%s\n", gdp->cdp->i->msgbuf);
- return FALSE;
- }
-
- ret = FLAC__seekable_stream_encoder_set_streamable_subset(skp, TRUE);
- if (!ret) {
- (void) strcpy(gdp->cdp->i->msgbuf,
- "if_flac_seekable_encoder_setup: "
- "Failed setting streamable subset.");
- DBGPRN(DBG_SND)(errfp, "%s\n", gdp->cdp->i->msgbuf);
- return FALSE;
- }
-
- ret = FLAC__seekable_stream_encoder_set_do_qlp_coeff_prec_search(
- skp, pp->qlp_srch
- );
- if (!ret) {
- (void) strcpy(gdp->cdp->i->msgbuf,
- "if_flac_seekable_encoder_setup: "
- "Failed setting LP coefficient quantization search."
- );
- DBGPRN(DBG_SND)(errfp, "%s\n", gdp->cdp->i->msgbuf);
- return FALSE;
- }
-
- /* Just use default for now
- ret = FLAC__seekable_stream_encoder_set_qlp_coeff_precision(skp, 0);
- */
-
- ret = FLAC__seekable_stream_encoder_set_verify(skp, pp->vfy_mode);
- if (!ret) {
- (void) strcpy(gdp->cdp->i->msgbuf,
- "if_flac_seekable_encoder_setup: "
- "Failed setting verify mode.");
- DBGPRN(DBG_SND)(errfp, "%s\n", gdp->cdp->i->msgbuf);
- return FALSE;
- }
-
- ret = FLAC__seekable_stream_encoder_set_max_lpc_order(
- skp, pp->lpc_order
- );
- if (!ret) {
- (void) strcpy(gdp->cdp->i->msgbuf,
- "if_flac_seekable_encoder_setup: "
- "Failed setting max LPC order.");
- DBGPRN(DBG_SND)(errfp, "%s\n", gdp->cdp->i->msgbuf);
- return FALSE;
- }
-
- ret = FLAC__seekable_stream_encoder_set_blocksize(skp, pp->block_sz);
- if (!ret) {
- (void) strcpy(gdp->cdp->i->msgbuf,
- "if_flac_seekable_encoder_setup: "
- "Failed setting block size.");
- DBGPRN(DBG_SND)(errfp, "%s\n", gdp->cdp->i->msgbuf);
- return FALSE;
- }
-
- ret = FLAC__seekable_stream_encoder_set_do_mid_side_stereo(
- skp, pp->mid_side
- );
- if (!ret) {
- (void) strcpy(gdp->cdp->i->msgbuf,
- "if_flac_seekable_encoder_setup: "
- "Failed setting M/S stereo.");
- DBGPRN(DBG_SND)(errfp, "%s\n", gdp->cdp->i->msgbuf);
- return FALSE;
- }
-
- ret = FLAC__seekable_stream_encoder_set_loose_mid_side_stereo(
- skp, pp->adap_ms
- );
- if (!ret) {
- (void) strcpy(gdp->cdp->i->msgbuf,
- "if_flac_seekable_encoder_setup: "
- "Failed setting adaptive M/S stereo.");
- DBGPRN(DBG_SND)(errfp, "%s\n", gdp->cdp->i->msgbuf);
- return FALSE;
- }
-
- if (pp->min_rpo >= 0) {
- ret = FLAC__seekable_stream_encoder_set_min_residual_partition_order(
- skp, (unsigned int) pp->min_rpo
- );
- if (!ret) {
- (void) strcpy(gdp->cdp->i->msgbuf,
- "if_flac_seekable_encoder_setup: "
- "Failed setting minimum RPO.");
- DBGPRN(DBG_SND)(errfp, "%s\n", gdp->cdp->i->msgbuf);
- return FALSE;
- }
- }
-
- if (pp->max_rpo >= 0) {
- ret = FLAC__seekable_stream_encoder_set_max_residual_partition_order(
- skp, (unsigned int) pp->max_rpo
- );
- if (!ret) {
- (void) strcpy(gdp->cdp->i->msgbuf,
- "if_flac_seekable_encoder_setup: "
- "Failed setting maximum RPO.");
- DBGPRN(DBG_SND)(errfp, "%s\n", gdp->cdp->i->msgbuf);
- return FALSE;
- }
- }
-
- ret = FLAC__seekable_stream_encoder_set_do_exhaustive_model_search(
- skp, pp->exh_srch
- );
- if (!ret) {
- (void) strcpy(gdp->cdp->i->msgbuf,
- "if_flac_seekable_encoder_setup: "
- "Failed setting exhaustive model search.");
- DBGPRN(DBG_SND)(errfp, "%s\n", gdp->cdp->i->msgbuf);
- return FALSE;
- }
-
- /* Initialize and add metadata to FLAC output */
- if_flac_addmeta(gdp, ufdp);
-
- /* Register write callback function */
- ret = FLAC__seekable_stream_encoder_set_write_callback(
- skp, if_flac_seekable_write_callback
- );
- if (!ret) {
- (void) strcpy(gdp->cdp->i->msgbuf,
- "if_flac_seekable_encoder_setup: "
- "Failed setting write callback.");
- DBGPRN(DBG_SND)(errfp, "%s\n", gdp->cdp->i->msgbuf);
- return FALSE;
- }
-
- /* Register seek callback function */
- ret = FLAC__seekable_stream_encoder_set_seek_callback(
- skp, if_flac_seek_callback
- );
- if (!ret) {
- (void) strcpy(gdp->cdp->i->msgbuf,
- "if_flac_seekable_encoder_setup: "
- "Failed setting seek callback.");
- DBGPRN(DBG_SND)(errfp, "%s\n", gdp->cdp->i->msgbuf);
- return FALSE;
- }
-
- /* Set callback argument */
- ret = FLAC__seekable_stream_encoder_set_client_data(skp, gdp);
- if (!ret) {
- (void) strcpy(gdp->cdp->i->msgbuf,
- "if_flac_seekable_encoder_setup: "
- "Failed setting client data.");
- DBGPRN(DBG_SND)(errfp, "%s\n", gdp->cdp->i->msgbuf);
- return FALSE;
- }
-
- /* Initialize FLAC encoder */
- enc_state = FLAC__seekable_stream_encoder_init(skp);
- if (enc_state != FLAC__SEEKABLE_STREAM_ENCODER_OK) {
- (void) sprintf(gdp->cdp->i->msgbuf,
- "if_flac_seekable_encoder_setup: Encoder init error: %s",
- FLAC__seekable_stream_encoder_get_resolved_state_string(skp)
- );
- DBGPRN(DBG_SND)(errfp, "%s\n", gdp->cdp->i->msgbuf);
- return FALSE;
- }
-
- /* Allocate wide samples buffers for the two channels */
- fenc_buf[0] = (FLAC__int32 *) MEM_ALLOC(
- "fenc_buf0",
- (size_t) gdp->cdp->cds->chunk_bytes
- );
- if (fenc_buf[0] == NULL) {
- (void) strcpy(gdp->cdp->i->msgbuf,
- "if_flac_seekable_encoder_setup: "
- "Out of memory.");
- DBGPRN(DBG_SND)(errfp, "%s\n", gdp->cdp->i->msgbuf);
- return FALSE;
- }
- fenc_buf[1] = (FLAC__int32 *) MEM_ALLOC(
- "fenc_buf1",
- (size_t) gdp->cdp->cds->chunk_bytes
- );
- if (fenc_buf[1] == NULL) {
- (void) strcpy(gdp->cdp->i->msgbuf,
- "if_flac_seekable_encoder_setup: "
- "Out of memory.");
- DBGPRN(DBG_SND)(errfp, "%s\n", gdp->cdp->i->msgbuf);
- return FALSE;
- }
-
- return TRUE;
-}
-
-
-/*
* if_flac_init
* Initialize FLAC encoder and set up encoding parameters
*
@@ -1300,10 +929,7 @@ if_flac_init(gen_desc_t *gdp)
}
/* Set up encoder */
- if ((gdp->flags & GDESC_ISPIPE) != 0)
- ret = if_flac_encoder_setup(gdp, ufdp, &parms);
- else
- ret = if_flac_seekable_encoder_setup(gdp, ufdp, &parms);
+ ret = if_flac_encoder_setup(gdp, ufdp, &parms);
return (ret);
}
@@ -1351,16 +977,9 @@ if_flac_encode_chunk(gen_desc_t *gdp, by
DBGPRN(DBG_SND)(errfp, "\nEncoding %d samples\n", samples);
- if ((gdp->flags & GDESC_ISPIPE) != 0) {
- ret = FLAC__stream_encoder_process(
- ufdp->st, (void *) fenc_buf, (unsigned int) samples
- );
- }
- else {
- ret = FLAC__seekable_stream_encoder_process(
- ufdp->sk, (void *) fenc_buf, (unsigned int) samples
- );
- }
+ ret = FLAC__stream_encoder_process(
+ ufdp->st, (void *) fenc_buf, (unsigned int) samples
+ );
if (!ret) {
(void) strcpy(gdp->cdp->i->msgbuf,
"if_flac_encode_chunk: Process encoding failed.");
@@ -1393,14 +1012,8 @@ if_flac_halt(gen_desc_t *gdp)
ufdp = (flac_desc_t *) gdp->aux;
- if ((gdp->flags & GDESC_ISPIPE) != 0) {
- FLAC__stream_encoder_finish(ufdp->st);
- FLAC__stream_encoder_delete(ufdp->st);
- }
- else {
- FLAC__seekable_stream_encoder_finish(ufdp->sk);
- FLAC__seekable_stream_encoder_delete(ufdp->sk);
- }
+ FLAC__stream_encoder_finish(ufdp->st);
+ FLAC__stream_encoder_delete(ufdp->st);
MEM_FREE(ufdp);
gdp->aux = NULL;
|