FLAC Re: [MPlayer-dev-eng] wishlist again and again

Arpi arpi at thot.banki.hu
Fri Jun 6 23:33:35 CEST 2003


Hi,

> > LOL, an even stupider design. Wow, where do they get the idiots to
> > make this stuff??
> 
> from xiph.org, where else? (the authors of .ogg container and other idiotism)

btw it isn't so bad.

i've hacked together a small sample app for flac file decoding, it can be
easily transformed to ad_flac.c (store sh_audio in clientdata, implement
read callback as wrapper to demuxer, implement write callback as channel
interleaver to sh_audio->audio_buffer, and in the decoder() func keep
calling FLAC__stream_decoder_process_single() until EOF or enough data
decoded)

compile:  gcc faszom.c -lFLAC -lm

src:

#include <stdio.h>
#include <stdlib.h>

#include <FLAC/stream_decoder.h>

static FILE* f1;

static void meta_cb(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data){
    printf("meta_cb: %p\n",metadata);
}

static void error_cb(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data){
    printf("error_cb: %p\n",status);
}

static FLAC__StreamDecoderReadStatus read_cb(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], unsigned *bytes, void *client_data){
    printf("read: buffer size: %d bytes\n",*bytes);
    *bytes=fread(buffer,1,*bytes,f1);
    printf("read: readed %d bytes\n",*bytes);
    if(*bytes<=0) return FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM;
    return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
}

static FLAC__StreamDecoderWriteStatus write_cb(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data){
    printf("write: %d samples, %dHz %dch %dbits\n",
	frame->header.blocksize, frame->header.sample_rate, frame->header.channels, frame->header.bits_per_sample);
    return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
    // return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
}


int main(){
    FLAC__StreamDecoder* dec=FLAC__stream_decoder_new();

    FLAC__stream_decoder_set_read_callback(dec,read_cb);
    FLAC__stream_decoder_set_write_callback(dec,write_cb);
    FLAC__stream_decoder_set_metadata_callback(dec,meta_cb);
    FLAC__stream_decoder_set_error_callback(dec,error_cb);
    FLAC__stream_decoder_set_client_data(dec,(void*)0xDEADBEEF);

    f1=fopen("audiodump.flac","rb");

    FLAC__stream_decoder_init(dec);
#if 0
    FLAC__stream_decoder_process_until_end_of_stream(dec);
#else
    while(1){
	printf("Calling FLAC__stream_decoder_process_single()\n");
        FLAC__stream_decoder_process_single(dec);
	printf("Returned from FLAC__stream_decoder_process_single()\n\n");
    }
#endif
    FLAC__stream_decoder_finish(dec);

    fclose(f1);
    return 0;
}


sample output:

Calling FLAC__stream_decoder_process_single()
read: buffer size: 65472 bytes
read: readed 65472 bytes
meta_cb: 0x8049f18
Returned from FLAC__stream_decoder_process_single()

Calling FLAC__stream_decoder_process_single()
Returned from FLAC__stream_decoder_process_single()

Calling FLAC__stream_decoder_process_single()
Returned from FLAC__stream_decoder_process_single()

Calling FLAC__stream_decoder_process_single()
Returned from FLAC__stream_decoder_process_single()

Calling FLAC__stream_decoder_process_single()
write: 4608 samples, 44100Hz 2ch 16bits
Returned from FLAC__stream_decoder_process_single()

Calling FLAC__stream_decoder_process_single()
write: 4608 samples, 44100Hz 2ch 16bits
Returned from FLAC__stream_decoder_process_single()

Calling FLAC__stream_decoder_process_single()
read: buffer size: 65472 bytes
read: readed 65472 bytes
write: 4608 samples, 44100Hz 2ch 16bits
Returned from FLAC__stream_decoder_process_single()

Calling FLAC__stream_decoder_process_single()
write: 4608 samples, 44100Hz 2ch 16bits
Returned from FLAC__stream_decoder_process_single()

..



A'rpi / Astral & ESP-team

--
Developer of MPlayer G2, the Movie Framework for all - http://www.MPlayerHQ.hu



More information about the MPlayer-dev-eng mailing list