1 /*****************************************************************************
2 * flac.c: flac decoder/encoder module making use of libflac
3 *****************************************************************************
4 * Copyright (C) 1999-2001 VLC authors and VideoLAN
7 * Authors: Gildas Bazin <gbazin@videolan.org>
8 * Sigmund Augdal Helberg <dnumgis@videolan.org>
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU Lesser General Public License as published by
12 * the Free Software Foundation; either version 2.1 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public License
21 * along with this program; if not, write to the Free Software Foundation,
22 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
25 /*****************************************************************************
27 *****************************************************************************/
29 /* workaround libflac overriding assert.h system header */
30 #define assert(x) do {} while(0)
36 #include <vlc_common.h>
37 #include <vlc_plugin.h>
38 #include <vlc_codec.h>
40 #include <FLAC/stream_decoder.h>
41 #include <FLAC/stream_encoder.h>
43 #include <vlc_block_helper.h>
46 #if defined(FLAC_API_VERSION_CURRENT) && FLAC_API_VERSION_CURRENT >= 8
47 # define USE_NEW_FLAC_API
50 /*****************************************************************************
51 * decoder_sys_t : FLAC decoder descriptor
52 *****************************************************************************/
56 * Input/Output properties
59 block_t *p_aout_buffer;
65 FLAC__StreamDecoder *p_flac;
66 FLAC__StreamMetadata_StreamInfo stream_info;
70 static const int pi_channels_maps[9] =
74 AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT,
75 AOUT_CHAN_CENTER | AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT,
76 AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_REARLEFT
77 | AOUT_CHAN_REARRIGHT,
78 AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_CENTER
79 | AOUT_CHAN_REARLEFT | AOUT_CHAN_REARRIGHT,
80 AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_CENTER
81 | AOUT_CHAN_REARLEFT | AOUT_CHAN_REARRIGHT | AOUT_CHAN_LFE,
82 AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_CENTER
83 | AOUT_CHAN_REARCENTER | AOUT_CHAN_MIDDLELEFT| AOUT_CHAN_MIDDLERIGHT
85 AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_CENTER | AOUT_CHAN_REARLEFT
86 | AOUT_CHAN_REARRIGHT | AOUT_CHAN_MIDDLELEFT | AOUT_CHAN_MIDDLERIGHT
90 /*****************************************************************************
92 *****************************************************************************/
93 static int OpenDecoder ( vlc_object_t * );
94 static void CloseDecoder ( vlc_object_t * );
97 static int OpenEncoder ( vlc_object_t * );
98 static void CloseEncoder ( vlc_object_t * );
101 static block_t *DecodeBlock( decoder_t *, block_t ** );
103 /*****************************************************************************
105 *****************************************************************************/
108 set_category( CAT_INPUT )
109 set_subcategory( SUBCAT_INPUT_ACODEC )
110 add_shortcut( "flac" )
112 set_description( N_("Flac audio decoder") )
113 set_capability( "decoder", 100 )
114 set_callbacks( OpenDecoder, CloseDecoder )
118 add_shortcut( "flac" )
119 set_description( N_("Flac audio encoder") )
120 set_capability( "encoder", 100 )
121 set_callbacks( OpenEncoder, CloseEncoder )
126 /*****************************************************************************
127 * Interleave: helper function to interleave channels
128 *****************************************************************************/
129 static void Interleave( int32_t *p_out, const int32_t * const *pp_in,
130 const unsigned char *restrict pi_index, unsigned i_nb_channels,
131 unsigned i_samples, unsigned bits )
133 unsigned shift = 32 - bits;
135 for( unsigned j = 0; j < i_samples; j++ )
136 for( unsigned i = 0; i < i_nb_channels; i++ )
137 p_out[j * i_nb_channels + i] = pp_in[pi_index[i]][j] << shift;
140 /*****************************************************************************
141 * DecoderWriteCallback: called by libflac to output decoded samples
142 *****************************************************************************/
143 static FLAC__StreamDecoderWriteStatus
144 DecoderWriteCallback( const FLAC__StreamDecoder *decoder,
145 const FLAC__Frame *frame,
146 const FLAC__int32 *const buffer[], void *client_data )
148 /* XXX it supposes our internal format is WG4 */
149 static const unsigned char ppi_reorder[1+8][8] = {
156 { 0, 1, 4, 5, 2, 3 },
157 { 0, 1, 5, 6, 4, 2, 3 },
158 { 0, 1, 6, 7, 4, 5, 2, 3 },
162 decoder_t *p_dec = (decoder_t *)client_data;
163 decoder_sys_t *p_sys = p_dec->p_sys;
165 if( p_dec->fmt_out.audio.i_channels <= 0 ||
166 p_dec->fmt_out.audio.i_channels > 8 )
167 return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
168 if( date_Get( &p_sys->end_date ) <= VLC_TS_INVALID )
169 return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
171 const unsigned char *pi_reorder = ppi_reorder[p_dec->fmt_out.audio.i_channels];
173 p_sys->p_aout_buffer =
174 decoder_NewAudioBuffer( p_dec, frame->header.blocksize );
176 if( p_sys->p_aout_buffer == NULL )
177 return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
179 Interleave( (int32_t *)p_sys->p_aout_buffer->p_buffer, buffer, pi_reorder,
180 frame->header.channels, frame->header.blocksize,
181 frame->header.bits_per_sample );
183 /* Date management (already done by packetizer) */
184 p_sys->p_aout_buffer->i_pts = date_Get( &p_sys->end_date );
185 p_sys->p_aout_buffer->i_length =
186 date_Increment( &p_sys->end_date, frame->header.blocksize ) -
187 p_sys->p_aout_buffer->i_pts;
189 return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
192 /*****************************************************************************
193 * DecoderReadCallback: called by libflac when it needs more data
194 *****************************************************************************/
195 static FLAC__StreamDecoderReadStatus
196 DecoderReadCallback( const FLAC__StreamDecoder *decoder, FLAC__byte buffer[],
197 size_t *bytes, void *client_data )
200 decoder_t *p_dec = (decoder_t *)client_data;
201 decoder_sys_t *p_sys = p_dec->p_sys;
203 if( p_sys->p_block && p_sys->p_block->i_buffer )
205 *bytes = __MIN(*bytes, p_sys->p_block->i_buffer);
206 memcpy( buffer, p_sys->p_block->p_buffer, *bytes );
207 p_sys->p_block->i_buffer -= *bytes;
208 p_sys->p_block->p_buffer += *bytes;
213 return FLAC__STREAM_DECODER_READ_STATUS_ABORT;
216 return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
219 /*****************************************************************************
220 * DecoderMetadataCallback: called by libflac to when it encounters metadata
221 *****************************************************************************/
222 static void DecoderMetadataCallback( const FLAC__StreamDecoder *decoder,
223 const FLAC__StreamMetadata *metadata,
227 decoder_t *p_dec = (decoder_t *)client_data;
228 decoder_sys_t *p_sys = p_dec->p_sys;
230 /* Setup the format */
231 p_dec->fmt_out.audio.i_rate = metadata->data.stream_info.sample_rate;
232 p_dec->fmt_out.audio.i_channels = metadata->data.stream_info.channels;
233 p_dec->fmt_out.audio.i_physical_channels =
234 p_dec->fmt_out.audio.i_original_channels =
235 pi_channels_maps[metadata->data.stream_info.channels];
236 if (!p_dec->fmt_out.audio.i_bitspersample)
237 p_dec->fmt_out.audio.i_bitspersample =
238 metadata->data.stream_info.bits_per_sample;
240 msg_Dbg( p_dec, "channels:%d samplerate:%d bitspersamples:%d",
241 p_dec->fmt_out.audio.i_channels, p_dec->fmt_out.audio.i_rate,
242 p_dec->fmt_out.audio.i_bitspersample );
244 p_sys->b_stream_info = true;
245 p_sys->stream_info = metadata->data.stream_info;
247 date_Init( &p_sys->end_date, p_dec->fmt_out.audio.i_rate, 1 );
248 date_Set( &p_sys->end_date, VLC_TS_INVALID );
251 /*****************************************************************************
252 * DecoderErrorCallback: called when the libflac decoder encounters an error
253 *****************************************************************************/
254 static void DecoderErrorCallback( const FLAC__StreamDecoder *decoder,
255 FLAC__StreamDecoderErrorStatus status,
259 decoder_t *p_dec = (decoder_t *)client_data;
263 case FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC:
264 msg_Warn( p_dec, "an error in the stream caused the decoder to "
265 "lose synchronization." );
267 case FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER:
268 msg_Err( p_dec, "the decoder encountered a corrupted frame header." );
270 case FLAC__STREAM_DECODER_ERROR_STATUS_FRAME_CRC_MISMATCH:
271 msg_Err( p_dec, "frame's data did not match the CRC in the "
275 msg_Err( p_dec, "got decoder error: %d", status );
278 FLAC__stream_decoder_flush( p_dec->p_sys->p_flac );
281 /*****************************************************************************
282 * OpenDecoder: probe the decoder and return score
283 *****************************************************************************/
284 static int OpenDecoder( vlc_object_t *p_this )
286 decoder_t *p_dec = (decoder_t*)p_this;
287 decoder_sys_t *p_sys;
289 if( p_dec->fmt_in.i_codec != VLC_CODEC_FLAC )
294 /* Allocate the memory needed to store the decoder's structure */
295 if( ( p_dec->p_sys = p_sys = malloc(sizeof(*p_sys)) ) == NULL )
299 p_sys->b_stream_info = false;
300 p_sys->p_block = NULL;
302 /* Take care of flac init */
303 if( !(p_sys->p_flac = FLAC__stream_decoder_new()) )
305 msg_Err( p_dec, "FLAC__stream_decoder_new() failed" );
310 #ifdef USE_NEW_FLAC_API
311 if( FLAC__stream_decoder_init_stream( p_sys->p_flac,
317 DecoderWriteCallback,
318 DecoderMetadataCallback,
319 DecoderErrorCallback,
321 != FLAC__STREAM_DECODER_INIT_STATUS_OK )
323 msg_Err( p_dec, "FLAC__stream_decoder_init_stream() failed" );
324 FLAC__stream_decoder_delete( p_sys->p_flac );
329 FLAC__stream_decoder_set_read_callback( p_sys->p_flac,
330 DecoderReadCallback );
331 FLAC__stream_decoder_set_write_callback( p_sys->p_flac,
332 DecoderWriteCallback );
333 FLAC__stream_decoder_set_metadata_callback( p_sys->p_flac,
334 DecoderMetadataCallback );
335 FLAC__stream_decoder_set_error_callback( p_sys->p_flac,
336 DecoderErrorCallback );
337 FLAC__stream_decoder_set_client_data( p_sys->p_flac, p_dec );
339 FLAC__stream_decoder_init( p_sys->p_flac );
342 /* Set output properties */
343 p_dec->fmt_out.i_cat = AUDIO_ES;
344 p_dec->fmt_out.i_codec = VLC_CODEC_S32N;
347 p_dec->pf_decode_audio = DecodeBlock;
350 p_dec->b_need_packetized = true;
355 /*****************************************************************************
356 * CloseDecoder: flac decoder destruction
357 *****************************************************************************/
358 static void CloseDecoder( vlc_object_t *p_this )
360 decoder_t *p_dec = (decoder_t *)p_this;
361 decoder_sys_t *p_sys = p_dec->p_sys;
363 FLAC__stream_decoder_finish( p_sys->p_flac );
364 FLAC__stream_decoder_delete( p_sys->p_flac );
367 block_Release( p_sys->p_block );
371 /*****************************************************************************
372 * ProcessHeader: process Flac header.
373 *****************************************************************************/
374 static void ProcessHeader( decoder_t *p_dec )
376 decoder_sys_t *p_sys = p_dec->p_sys;
378 if( !p_dec->fmt_in.i_extra )
381 /* Decode STREAMINFO */
382 msg_Dbg( p_dec, "decode STREAMINFO" );
383 size_t i_extra = p_dec->fmt_in.i_extra;
386 p_sys->p_block = block_Alloc( 8 + i_extra );
387 memcpy( p_sys->p_block->p_buffer + 8, p_dec->fmt_in.p_extra, i_extra );
388 memcpy( p_sys->p_block->p_buffer, "fLaC", 4);
389 uint8_t *p = p_sys->p_block->p_buffer;
390 p[4] = 0x80 | 0; /* STREAMINFO faked as last block */
393 p[7] = 34; /* block size */
396 p_sys->p_block = block_Alloc( i_extra );
397 memcpy( p_sys->p_block->p_buffer, p_dec->fmt_in.p_extra, i_extra );
400 msg_Err(p_dec, "Invalid flac header size %zu", i_extra);
403 FLAC__stream_decoder_process_until_end_of_metadata( p_sys->p_flac );
404 msg_Dbg( p_dec, "STREAMINFO decoded" );
407 /*****************************************************************************
408 * decoder_state_error: print meaningful error messages
409 *****************************************************************************/
410 static void decoder_state_error( decoder_t *p_dec,
411 FLAC__StreamDecoderState state )
415 case FLAC__STREAM_DECODER_SEARCH_FOR_METADATA:
416 msg_Dbg( p_dec, "the decoder is ready to search for metadata." );
418 case FLAC__STREAM_DECODER_READ_METADATA:
419 msg_Dbg( p_dec, "the decoder is ready to or is in the process of "
420 "reading metadata." );
422 case FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC:
423 msg_Dbg( p_dec, "the decoder is ready to or is in the process of "
424 "searching for the frame sync code." );
426 case FLAC__STREAM_DECODER_READ_FRAME:
427 msg_Dbg( p_dec, "the decoder is ready to or is in the process of "
428 "reading a frame." );
430 case FLAC__STREAM_DECODER_END_OF_STREAM:
431 msg_Dbg( p_dec, "the decoder has reached the end of the stream." );
433 #ifdef USE_NEW_FLAC_API
434 case FLAC__STREAM_DECODER_OGG_ERROR:
435 msg_Err( p_dec, "error occurred in the Ogg layer." );
437 case FLAC__STREAM_DECODER_SEEK_ERROR:
438 msg_Err( p_dec, "error occurred while seeking." );
441 case FLAC__STREAM_DECODER_ABORTED:
442 msg_Warn( p_dec, "the decoder was aborted by the read callback." );
444 #ifndef USE_NEW_FLAC_API
445 case FLAC__STREAM_DECODER_UNPARSEABLE_STREAM:
446 msg_Warn( p_dec, "the decoder encountered reserved fields in use "
450 case FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR:
451 msg_Err( p_dec, "error when allocating memory." );
453 #ifndef USE_NEW_FLAC_API
454 case FLAC__STREAM_DECODER_ALREADY_INITIALIZED:
455 msg_Err( p_dec, "FLAC__stream_decoder_init() was called when the "
456 "decoder was already initialized, usually because "
457 "FLAC__stream_decoder_finish() was not called." );
459 case FLAC__STREAM_DECODER_INVALID_CALLBACK:
460 msg_Err( p_dec, "FLAC__stream_decoder_init() was called without "
461 "all callbacks being set." );
464 case FLAC__STREAM_DECODER_UNINITIALIZED:
465 msg_Err( p_dec, "decoder in uninitialized state." );
468 msg_Warn(p_dec, "unknown error" );
472 /****************************************************************************
473 * DecodeBlock: the whole thing
474 ****************************************************************************/
475 static block_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
477 decoder_sys_t *p_sys = p_dec->p_sys;
479 if( !pp_block || !*pp_block )
481 if( (*pp_block)->i_flags&(BLOCK_FLAG_DISCONTINUITY|BLOCK_FLAG_CORRUPTED) )
483 block_Release( *pp_block );
487 if( !p_sys->b_stream_info )
488 ProcessHeader( p_dec );
490 p_sys->p_block = *pp_block;
493 if( p_sys->p_block->i_pts > VLC_TS_INVALID &&
494 p_sys->p_block->i_pts != date_Get( &p_sys->end_date ) )
495 date_Set( &p_sys->end_date, p_sys->p_block->i_pts );
497 p_sys->p_aout_buffer = 0;
499 if( !FLAC__stream_decoder_process_single( p_sys->p_flac ) )
501 decoder_state_error( p_dec,
502 FLAC__stream_decoder_get_state( p_sys->p_flac ) );
503 FLAC__stream_decoder_flush( p_dec->p_sys->p_flac );
506 /* If the decoder is in the "aborted" state,
507 * FLAC__stream_decoder_process_single() won't return an error. */
508 if( FLAC__stream_decoder_get_state(p_dec->p_sys->p_flac)
509 == FLAC__STREAM_DECODER_ABORTED )
511 FLAC__stream_decoder_flush( p_dec->p_sys->p_flac );
514 block_Release( p_sys->p_block );
515 p_sys->p_block = NULL;
517 return p_sys->p_aout_buffer;
522 /*****************************************************************************
523 * encoder_sys_t : flac encoder descriptor
524 *****************************************************************************/
534 FLAC__int32 *p_buffer;
535 unsigned int i_buffer;
542 FLAC__StreamEncoder *p_flac;
543 FLAC__StreamMetadata_StreamInfo stream_info;
551 #define STREAMINFO_SIZE 34
553 static block_t *Encode( encoder_t *, block_t * );
555 /*****************************************************************************
556 * EncoderWriteCallback: called by libflac to output encoded samples
557 *****************************************************************************/
558 static FLAC__StreamEncoderWriteStatus
559 EncoderWriteCallback( const FLAC__StreamEncoder *encoder,
560 const FLAC__byte buffer[],
561 size_t bytes, unsigned samples,
562 unsigned current_frame, void *client_data )
564 VLC_UNUSED(encoder); VLC_UNUSED(current_frame);
565 encoder_t *p_enc = (encoder_t *)client_data;
566 encoder_sys_t *p_sys = p_enc->p_sys;
571 if( p_sys->i_headers == 1 )
573 msg_Dbg( p_enc, "Writing STREAMINFO: %zu", bytes );
575 /* Backup the STREAMINFO metadata block */
576 p_enc->fmt_out.i_extra = STREAMINFO_SIZE;
577 p_enc->fmt_out.p_extra = xmalloc( STREAMINFO_SIZE );
578 memcpy(p_enc->fmt_out.p_extra, buffer + 4, STREAMINFO_SIZE );
581 return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
584 p_block = block_Alloc( bytes );
585 memcpy( p_block->p_buffer, buffer, bytes );
587 p_block->i_dts = p_block->i_pts = p_sys->i_pts;
589 p_sys->i_samples_delay -= samples;
591 p_block->i_length = (mtime_t)1000000 *
592 (mtime_t)samples / (mtime_t)p_enc->fmt_in.audio.i_rate;
595 p_sys->i_pts += p_block->i_length;
597 block_ChainAppend( &p_sys->p_chain, p_block );
599 return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
601 /*****************************************************************************
602 * EncoderMetadataCallback: called by libflac to output metadata
603 *****************************************************************************/
604 static void EncoderMetadataCallback( const FLAC__StreamEncoder *encoder,
605 const FLAC__StreamMetadata *metadata,
609 encoder_t *p_enc = (encoder_t *)client_data;
611 msg_Err( p_enc, "MetadataCallback: %i", metadata->type );
615 /*****************************************************************************
616 * OpenEncoder: probe the encoder and return score
617 *****************************************************************************/
618 static int OpenEncoder( vlc_object_t *p_this )
620 encoder_t *p_enc = (encoder_t *)p_this;
621 encoder_sys_t *p_sys;
623 if( p_enc->fmt_out.i_codec != VLC_CODEC_FLAC &&
629 /* Allocate the memory needed to store the decoder's structure */
630 if( ( p_sys = (encoder_sys_t *)malloc(sizeof(encoder_sys_t)) ) == NULL )
632 p_enc->p_sys = p_sys;
633 p_enc->pf_encode_audio = Encode;
634 p_enc->fmt_out.i_codec = VLC_CODEC_FLAC;
636 p_sys->i_headers = 0;
639 p_sys->i_samples_delay = 0;
641 /* Create flac encoder */
642 if( !(p_sys->p_flac = FLAC__stream_encoder_new()) )
644 msg_Err( p_enc, "FLAC__stream_encoder_new() failed" );
649 FLAC__stream_encoder_set_streamable_subset( p_sys->p_flac, 1 );
650 FLAC__stream_encoder_set_channels( p_sys->p_flac,
651 p_enc->fmt_in.audio.i_channels );
652 FLAC__stream_encoder_set_sample_rate( p_sys->p_flac,
653 p_enc->fmt_in.audio.i_rate );
654 FLAC__stream_encoder_set_bits_per_sample( p_sys->p_flac, 16 );
655 p_enc->fmt_in.i_codec = VLC_CODEC_S16N;
657 /* Get and store the STREAMINFO metadata block as a p_extra */
660 #ifdef USE_NEW_FLAC_API
661 if( FLAC__stream_encoder_init_stream( p_sys->p_flac,
662 EncoderWriteCallback,
665 EncoderMetadataCallback,
667 != FLAC__STREAM_ENCODER_INIT_STATUS_OK )
669 msg_Err( p_enc, "FLAC__stream_encoder_init_stream() failed" );
670 FLAC__stream_encoder_delete( p_sys->p_flac );
675 FLAC__stream_encoder_set_write_callback( p_sys->p_flac,
676 EncoderWriteCallback );
677 FLAC__stream_encoder_set_metadata_callback( p_sys->p_flac,
678 EncoderMetadataCallback );
679 FLAC__stream_encoder_set_client_data( p_sys->p_flac, p_enc );
681 FLAC__stream_encoder_init( p_sys->p_flac );
687 /****************************************************************************
688 * Encode: the whole thing
689 ****************************************************************************
690 * This function spits out ogg packets.
691 ****************************************************************************/
692 static block_t *Encode( encoder_t *p_enc, block_t *p_aout_buf )
694 encoder_sys_t *p_sys = p_enc->p_sys;
698 /* FIXME: p_aout_buf is NULL when it's time to flush*/
699 if( unlikely( !p_aout_buf ) ) return NULL;
701 p_sys->i_pts = p_aout_buf->i_pts -
702 (mtime_t)1000000 * (mtime_t)p_sys->i_samples_delay /
703 (mtime_t)p_enc->fmt_in.audio.i_rate;
705 p_sys->i_samples_delay += p_aout_buf->i_nb_samples;
707 /* Convert samples to FLAC__int32 */
708 if( p_sys->i_buffer < p_aout_buf->i_buffer * 2 )
711 xrealloc( p_sys->p_buffer, p_aout_buf->i_buffer * 2 );
712 p_sys->i_buffer = p_aout_buf->i_buffer * 2;
715 for( i = 0 ; i < p_aout_buf->i_buffer / 2 ; i++ )
717 p_sys->p_buffer[i]= ((int16_t *)p_aout_buf->p_buffer)[i];
720 FLAC__stream_encoder_process_interleaved( p_sys->p_flac, p_sys->p_buffer,
721 p_aout_buf->i_nb_samples );
723 p_chain = p_sys->p_chain;
729 /*****************************************************************************
730 * CloseEncoder: encoder destruction
731 *****************************************************************************/
732 static void CloseEncoder( vlc_object_t *p_this )
734 encoder_t *p_enc = (encoder_t *)p_this;
735 encoder_sys_t *p_sys = p_enc->p_sys;
737 FLAC__stream_encoder_delete( p_sys->p_flac );
739 free( p_sys->p_buffer );