*****************************************************************************/
#include <vlc/vlc.h>
-#include <vlc/decoder.h>
+#include <vlc_codec.h>
+#include <vlc_aout.h>
#ifdef HAVE_FLAC_STREAM_DECODER_H
# include <FLAC/stream_decoder.h>
# define USE_LIBFLAC
#endif
-#include "vlc_block_helper.h"
-#include "vlc_bits.h"
+#include <vlc_block_helper.h>
+#include <vlc_bits.h>
#define MAX_FLAC_HEADER_SIZE 16
+#if defined(FLAC_API_VERSION_CURRENT) && FLAC_API_VERSION_CURRENT >= 8
+# define USE_NEW_FLAC_API
+#endif
+
/*****************************************************************************
* decoder_sys_t : FLAC decoder descriptor
*****************************************************************************/
STATE_SEND_DATA
};
-static int pi_channels_maps[6] =
+static int pi_channels_maps[7] =
{
0,
AOUT_CHAN_CENTER,
AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_REARLEFT
| AOUT_CHAN_REARRIGHT,
AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_CENTER
- | AOUT_CHAN_REARLEFT | AOUT_CHAN_REARRIGHT
+ | AOUT_CHAN_REARLEFT | AOUT_CHAN_REARRIGHT,
+ AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_CENTER
+ | AOUT_CHAN_REARLEFT | AOUT_CHAN_REARRIGHT | AOUT_CHAN_LFE
};
/*****************************************************************************
return VLC_EGENERIC;
}
+#ifdef USE_NEW_FLAC_API
+ if( FLAC__stream_decoder_init_stream( p_sys->p_flac,
+ DecoderReadCallback,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ DecoderWriteCallback,
+ DecoderMetadataCallback,
+ DecoderErrorCallback,
+ p_dec )
+ != FLAC__STREAM_DECODER_INIT_STATUS_OK )
+ {
+ msg_Err( p_dec, "FLAC__stream_decoder_init_stream() failed" );
+ FLAC__stream_decoder_delete( p_sys->p_flac );
+ free( p_sys );
+ return VLC_EGENERIC;
+ }
+#else
FLAC__stream_decoder_set_read_callback( p_sys->p_flac,
DecoderReadCallback );
FLAC__stream_decoder_set_write_callback( p_sys->p_flac,
FLAC__stream_decoder_set_client_data( p_sys->p_flac, p_dec );
FLAC__stream_decoder_init( p_sys->p_flac );
+#endif
#endif
/* Set output properties */
}
/*****************************************************************************
- * ProcessHeader: processe Flac header.
+ * ProcessHeader: process Flac header.
*****************************************************************************/
static void ProcessHeader( decoder_t *p_dec )
{
if( !p_sys->b_stream_info ) ProcessHeader( p_dec );
+ if( p_sys->stream_info.channels > 6 )
+ {
+ msg_Err( p_dec, "This stream uses too many audio channels" );
+ return NULL;
+ }
+
if( !aout_DateGet( &p_sys->end_date ) && !(*pp_block)->i_pts )
{
/* We've just started the stream, wait for the first PTS. */
{
case FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC:
msg_Warn( p_dec, "an error in the stream caused the decoder to "
- "loose synchronization." );
+ "lose synchronization." );
break;
case FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER:
msg_Err( p_dec, "the decoder encountered a corrupted frame header." );
case FLAC__STREAM_DECODER_END_OF_STREAM:
msg_Dbg( p_dec, "the decoder has reached the end of the stream." );
break;
+#ifdef USE_NEW_FLAC_API
+ case FLAC__STREAM_DECODER_OGG_ERROR:
+ msg_Err( p_dec, "error occurred in the Ogg layer." );
+ break;
+ case FLAC__STREAM_DECODER_SEEK_ERROR:
+ msg_Err( p_dec, "error occurred while seeking." );
+ break;
+#endif
case FLAC__STREAM_DECODER_ABORTED:
msg_Warn( p_dec, "the decoder was aborted by the read callback." );
break;
+#ifndef USE_NEW_FLAC_API
case FLAC__STREAM_DECODER_UNPARSEABLE_STREAM:
msg_Warn( p_dec, "the decoder encountered reserved fields in use "
"in the stream." );
break;
+#endif
case FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR:
msg_Err( p_dec, "error when allocating memory." );
break;
+#ifndef USE_NEW_FLAC_API
case FLAC__STREAM_DECODER_ALREADY_INITIALIZED:
msg_Err( p_dec, "FLAC__stream_decoder_init() was called when the "
"decoder was already initialized, usually because "
msg_Err( p_dec, "FLAC__stream_decoder_init() was called without "
"all callbacks being set." );
break;
+#endif
case FLAC__STREAM_DECODER_UNINITIALIZED:
msg_Err( p_dec, "decoder in uninitialized state." );
break;
int i_channels;
FLAC__int32 *p_buffer;
- int i_buffer;
+ unsigned int i_buffer;
block_t *p_chain;
p_sys->i_samples_delay = 0;
/* Create flac encoder */
- p_sys->p_flac = FLAC__stream_encoder_new();
+ if( !(p_sys->p_flac = FLAC__stream_encoder_new()) )
+ {
+ msg_Err( p_enc, "FLAC__stream_encoder_new() failed" );
+ free( p_sys );
+ return VLC_EGENERIC;
+ }
FLAC__stream_encoder_set_streamable_subset( p_sys->p_flac, 1 );
FLAC__stream_encoder_set_channels( p_sys->p_flac,
FLAC__stream_encoder_set_bits_per_sample( p_sys->p_flac, 16 );
p_enc->fmt_in.i_codec = AOUT_FMT_S16_NE;
+ /* Get and store the STREAMINFO metadata block as a p_extra */
+ p_sys->p_chain = 0;
+
+#ifdef USE_NEW_FLAC_API
+ if( FLAC__stream_encoder_init_stream( p_sys->p_flac,
+ EncoderWriteCallback,
+ NULL,
+ NULL,
+ EncoderMetadataCallback,
+ p_enc )
+ != FLAC__STREAM_ENCODER_INIT_STATUS_OK )
+ {
+ msg_Err( p_enc, "FLAC__stream_encoder_init_stream() failed" );
+ FLAC__stream_encoder_delete( p_sys->p_flac );
+ free( p_sys );
+ return VLC_EGENERIC;
+ }
+#else
FLAC__stream_encoder_set_write_callback( p_sys->p_flac,
EncoderWriteCallback );
FLAC__stream_encoder_set_metadata_callback( p_sys->p_flac,
EncoderMetadataCallback );
FLAC__stream_encoder_set_client_data( p_sys->p_flac, p_enc );
- /* Get and store the STREAMINFO metadata block as a p_extra */
- p_sys->p_chain = 0;
FLAC__stream_encoder_init( p_sys->p_flac );
+#endif
return VLC_SUCCESS;
}
{
encoder_sys_t *p_sys = p_enc->p_sys;
block_t *p_chain;
- int i;
+ unsigned int i;
p_sys->i_pts = p_aout_buf->start_date -
(mtime_t)1000000 * (mtime_t)p_sys->i_samples_delay /