[Flac-dev] Can a libFLAC encoder be initialize and called from inside a libFLAC decoder callback?
david at troendle.org
Tue May 24 10:16:11 PDT 2011
I am getting large, corrupted native FLAC files when trying to call the
encoder from inside the decoder. The metadata in the output file is OK.
Is initializing and calling an encoder from inside a libFLAC decoder write
callback supported? The encoder is initialized on the first write callback.
Environment is Win 7 Ult, 64-bit, VS 2008, libFLAC 1.2.1.
Here is some context. The static callback calls the instance callback.
Encoder is initialized on line with "m_HaveEncoder = InitializeEncoder();".
Samples are submitted to the encoder on line with "FLAC__bool OK =
FLAC__stream_encoder_process(m_Encoder, Buffer, Blocksize);".
I have a version that decodes to a WAV file and then re-encodes the WAV
file, but would like to avoid all that I/O.
FLAC__StreamDecoder *FLACStreamDecoder, const FLAC__Frame *Frame, const
FLAC__int32 *const Buffer, void *ClientData)
*)(ClientData))->ClassWriteCallback(FLACStreamDecoder, Frame, Buffer);
FLAC__StreamDecoder *WXUNUSED(FLACStreamDecoder), const FLAC__Frame *Frame,
const FLAC__int32 *const Buffer)
// Make sure we have an encoder.
m_HaveEncoder = InitializeEncoder();
// Tell the decoder to continue without doing anything other than
count the samples.
m_nInputSamplesProcessed += Frame->header.blocksize;
// We have a frame and we are not in test mode. We need to send it
directly to the encoder
unsigned int Blocksize = Frame->header.blocksize;
// Is this line OK?
FLAC__bool OK = FLAC__stream_encoder_process(m_Encoder, Buffer,
// Count the samples
m_nInputSamplesProcessed += Blocksize;
// Let decoder know if it can continue
return OK ? FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE :
// We need a frame. Let the decoder know we can't continue.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Flac-dev