static void close_output(void) { FLAC_ctx *ctx; ctx = flac_ctx; if (ctx == NULL) return; if (dpm.fd < 0) { flac_session_close(); return; } #ifdef LEGACY_FLAC if (flac_options.isogg) { #ifdef AU_OGGFLAC if ((ctx->state.ogg = OggFLAC__stream_encoder_get_state(ctx->encoder.ogg.stream)) != OggFLAC__STREAM_ENCODER_OK) { ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "OggFLAC stream encoder is invalid (%s)", OggFLAC__StreamEncoderStateString[ctx->state.ogg]); /* fall through */ } } else #endif /* AU_OGGFLAC */ if (flac_options.seekable) { if ((ctx->state.s_flac = FLAC__seekable_stream_encoder_get_state(ctx->encoder.flac.s_stream)) != FLAC__SEEKABLE_STREAM_ENCODER_OK) { ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "FLAC stream encoder is invalid (%s)", FLAC__SeekableStreamEncoderStateString[ctx->state.s_flac]); /* fall through */ } } else { if ((ctx->state.flac = FLAC__stream_encoder_get_state(ctx->encoder.flac.stream)) != FLAC__STREAM_ENCODER_OK) { ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "FLAC stream encoder is invalid (%s)", FLAC__StreamEncoderStateString[ctx->state.flac]); /* fall through */ } } #else /* !LEGACY_FLAC */ if ((ctx->state.flac = FLAC__stream_encoder_get_state(ctx->encoder.flac.stream)) != FLAC__STREAM_ENCODER_OK) { ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "FLAC stream encoder is invalid (%s)", FLAC__StreamEncoderStateString[ctx->state.flac]); /* fall through */ } #endif ctl->cmsg(CMSG_INFO, VERB_NORMAL, "Wrote %lu/%lu bytes(%g%% compressed)", ctx->out_bytes, ctx->in_bytes, ((double)ctx->out_bytes / (double)ctx->in_bytes) * 100.); flac_session_close(); #ifdef AU_FLAC_DLL g_free_libFLAC_dll (); #endif #ifdef AU_OGGFLAC_DLL g_free_libOggFLAC_dll (); #endif }
FLAC_API FLAC__SeekableStreamEncoderState FLAC__file_encoder_get_seekable_stream_encoder_state(const FLAC__FileEncoder *encoder) { FLAC__ASSERT(0 != encoder); FLAC__ASSERT(0 != encoder->private_); return FLAC__seekable_stream_encoder_get_state(encoder->private_->seekable_stream_encoder); }
static int output_data(char *buf, int32 nbytes) { FLAC__int32 *oggbuf; FLAC__int16 *s; int i; int nch = (dpm.encoding & PE_MONO) ? 1 : 2; FLAC_ctx *ctx = flac_ctx; if (dpm.fd < 0) return 0; if (ctx == NULL) { ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "FLAC stream is not initialized"); return -1; } oggbuf = (FLAC__int32 *)safe_malloc(nbytes * sizeof(FLAC__int32) / nch); /* packing 16 -> 32 bit sample */ s = (FLAC__int16 *)buf; for (i = 0; i < nbytes / nch; i++) { oggbuf[i] = *s++; } #ifdef LEGACY_FLAC #ifdef AU_OGGFLAC if (flac_options.isogg) { ctx->state.ogg = OggFLAC__stream_encoder_get_state(ctx->encoder.ogg.stream); if (ctx->state.ogg != OggFLAC__STREAM_ENCODER_OK) { if (ctx->state.ogg == OggFLAC__STREAM_ENCODER_FLAC_STREAM_ENCODER_ERROR) { ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "FLAC stream verify error (%s)", FLAC__StreamDecoderStateString[OggFLAC__stream_encoder_get_verify_decoder_state(ctx->encoder.ogg.stream)]); } ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "cannot encode OggFLAC stream (%s)", OggFLAC__StreamEncoderStateString[ctx->state.ogg]); flac_session_close(); return -1; } if (!OggFLAC__stream_encoder_process_interleaved(ctx->encoder.ogg.stream, oggbuf, nbytes / nch / 2)) { ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "cannot encode OggFLAC stream"); flac_session_close(); return -1; } } else #endif /* AU_OGGFLAC */ if (flac_options.seekable) { ctx->state.s_flac = FLAC__seekable_stream_encoder_get_state(ctx->encoder.flac.s_stream); if (ctx->state.s_flac != FLAC__STREAM_ENCODER_OK) { if (ctx->state.s_flac == FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR || ctx->state.s_flac == FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA) { ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "FLAC stream verify error (%s)", FLAC__SeekableStreamDecoderStateString[FLAC__seekable_stream_encoder_get_verify_decoder_state(ctx->encoder.flac.s_stream)]); } else { ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "cannot encode FLAC stream (%s)", FLAC__SeekableStreamEncoderStateString[ctx->state.s_flac]); } flac_session_close(); return -1; } if (!FLAC__seekable_stream_encoder_process_interleaved(ctx->encoder.flac.s_stream, oggbuf, nbytes / nch / 2 )) { ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "cannot encode FLAC stream"); flac_session_close(); return -1; } } else { ctx->state.flac = FLAC__stream_encoder_get_state(ctx->encoder.flac.stream); if (ctx->state.flac != FLAC__STREAM_ENCODER_OK) { if (ctx->state.flac == FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR || ctx->state.flac == FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA) { ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "FLAC stream verify error (%s)", FLAC__StreamDecoderStateString[FLAC__stream_encoder_get_verify_decoder_state(ctx->encoder.flac.stream)]); } else { ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "cannot encode FLAC stream (%s)", FLAC__StreamEncoderStateString[ctx->state.flac]); } flac_session_close(); return -1; } if (!FLAC__stream_encoder_process_interleaved(ctx->encoder.flac.stream, oggbuf, nbytes / nch / 2 )) { ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "cannot encode FLAC stream"); flac_session_close(); return -1; } } #else /* !LEGACY_FLAC */ ctx->state.flac = FLAC__stream_encoder_get_state(ctx->encoder.flac.stream); if (ctx->state.flac != FLAC__STREAM_ENCODER_OK) { if (ctx->state.flac == FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR | FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA) { ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "FLAC stream verify error (%s)", FLAC__StreamDecoderStateString[FLAC__stream_encoder_get_verify_decoder_state(ctx->encoder.flac.stream)]); } else { ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "cannot encode FLAC stream (%s)", FLAC__StreamEncoderStateString[ctx->state.flac]); } flac_session_close(); return -1; } if (!FLAC__stream_encoder_process_interleaved(ctx->encoder.flac.stream, oggbuf, nbytes / nch / 2 )) { ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "cannot encode FLAC stream"); flac_session_close(); return -1; } #endif ctx->in_bytes += nbytes; free(oggbuf); return 0; }