You'll want to run it in another thread.  You can block the FLAC decoding
thread (via semaphore, SetEvent, etc) until the other thread fills your
buffer up to a certain amount.

> Hi,
>
> I've trying to decode a FLAC audio stream. I have a reader which sends
> raw byte data to my FLAC wrapper class. Only once the decode function
> below returns, the reader will send new data.
> Hence I want to decode until the stream is empty, but I will add new
> data to the stream once it is empty.
>
> *void **MyFlacCoder::**decode(char *data, int bytes)
> {
>          mBuffer = input;
>          mBufferBytes = bytes;
> FLAC__stream_decoder_process_until_end_of_stream(mDecoder);
> }
> *
> My read callback looks as follows:
> *
> FLAC__StreamDecoderReadStatus flacReadDecode(const FLAC__StreamDecoder
> *decoder, FLAC__byte buffer[], size_t *bytes, void *client)
> {
>      MyFlacCoder *coder = (MyFlacCoder*) client;
>      int size =min(*bytes, coder->mBufferBytes);
>      if(size <= 0)
>      {
>          *bytes = 0;
>          return FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM;
>      }
>      memcpy(buffer, coder->mBuffer, size);
>      *bytes = size;
>      coder->mBuffer += size;
>      coder->mBufferBytes -= size;
>      return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
> }*
>
> As far as I understand*FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM*
> notifies FLAC to stop decoding (no more data will come). However, in my
> case I only want FLAC to "pause" and still keep the data that was not
> processed yet, until new data is available and I call
> *FLAC__stream_decoder_process_until_end_of_stream* again. So
> *FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM* in my case actually
> means that the current stream has no more data, but I will add new data
> to the stream once it's empty. The problem is that frames might overlap.
> Hence I can clear FLAC's buffer, because there might still be half a
> frame in the buffer that couldn't be decoded yet.
>
> Any suggestions on how I can do this?
>
> Thank you
> Christoph
> _______________________________________________
> Flac mailing list
> Flac@xiph.org
> http://lists.xiph.org/mailman/listinfo/flac
>

_______________________________________________
Flac mailing list
Flac@xiph.org
http://lists.xiph.org/mailman/listinfo/flac

Reply via email to