+
+ /* Cleanup */
+ if( p_dec->p_owner->p_aout_input )
+ aout_DecDelete( p_dec->p_owner->p_aout, p_dec->p_owner->p_aout_input );
+
+ if( p_dec->p_owner->p_vout )
+ {
+ int i_pic;
+
+ /* Hack to make sure all the the pictures are freed by the decoder */
+ for( i_pic = 0; i_pic < p_dec->p_owner->p_vout->render.i_pictures;
+ i_pic++ )
+ {
+ if( p_dec->p_owner->p_vout->render.pp_picture[i_pic]->i_status ==
+ RESERVED_PICTURE )
+ vout_DestroyPicture( p_dec->p_owner->p_vout,
+ p_dec->p_owner->p_vout->render.pp_picture[i_pic] );
+ if( p_dec->p_owner->p_vout->render.pp_picture[i_pic]->i_refcount
+ > 0 )
+ vout_UnlinkPicture( p_dec->p_owner->p_vout,
+ p_dec->p_owner->p_vout->render.pp_picture[i_pic] );
+ }
+
+ /* We are about to die. Reattach video output to p_vlc. */
+ vout_Request( p_dec, p_dec->p_owner->p_vout, 0, 0, 0, 0 );
+ }
+
+ if( p_dec->p_owner->p_sout )
+ sout_InputDelete( p_dec->p_owner->p_sout );
+
+ free( p_dec->p_owner );
+
+}
+
+/*****************************************************************************
+ * Buffers allocation callbacks for the decoders
+ *****************************************************************************/
+static aout_buffer_t *aout_new_buffer( decoder_t *p_dec, int i_samples )
+{
+ decoder_owner_sys_t *p_sys = (decoder_owner_sys_t *)p_dec->p_owner;
+ aout_buffer_t *p_buffer;
+
+ if( p_sys->p_aout_input != NULL &&
+ ( p_dec->fmt_out.audio.i_rate != p_sys->audio.i_rate ||
+ p_dec->fmt_out.audio.i_original_channels !=
+ p_sys->audio.i_original_channels ||
+ p_dec->fmt_out.audio.i_bytes_per_frame !=
+ p_sys->audio.i_bytes_per_frame ) )
+ {
+ /* Parameters changed, restart the aout */
+ aout_DecDelete( p_sys->p_aout, p_sys->p_aout_input );
+ p_sys->p_aout_input = NULL;
+ }
+
+ if( p_sys->p_aout_input == NULL )
+ {
+ p_dec->fmt_out.audio.i_format = p_dec->fmt_out.i_codec;
+ p_sys->audio = p_dec->fmt_out.audio;
+ p_sys->p_aout_input =
+ aout_DecNew( p_dec, &p_sys->p_aout, &p_sys->audio );
+ if( p_sys->p_aout_input == NULL )
+ {
+ msg_Err( p_dec, "failed to create audio output" );
+ return NULL;
+ }
+ p_dec->fmt_out.audio.i_bytes_per_frame =
+ p_sys->audio.i_bytes_per_frame;
+ }
+
+ p_buffer = aout_DecNewBuffer( p_sys->p_aout, p_sys->p_aout_input,
+ i_samples );
+
+ return p_buffer;
+}
+
+static void aout_del_buffer( decoder_t *p_dec, aout_buffer_t *p_buffer )
+{
+ aout_DecDeleteBuffer( p_dec->p_owner->p_aout,
+ p_dec->p_owner->p_aout_input, p_buffer );
+}
+
+static picture_t *vout_new_buffer( decoder_t *p_dec )
+{
+ decoder_owner_sys_t *p_sys = (decoder_owner_sys_t *)p_dec->p_owner;
+ picture_t *p_pic;
+
+ if( p_sys->p_vout == NULL ||
+ p_dec->fmt_out.video.i_width != p_sys->video.i_width ||
+ p_dec->fmt_out.video.i_height != p_sys->video.i_height ||
+ p_dec->fmt_out.video.i_chroma != p_sys->video.i_chroma ||
+ p_dec->fmt_out.video.i_aspect != p_sys->video.i_aspect )
+ {
+ if( !p_dec->fmt_out.video.i_width ||
+ !p_dec->fmt_out.video.i_height )
+ {
+ /* Can't create a new vout without display size */
+ return NULL;
+ }
+
+ p_dec->fmt_out.video.i_chroma = p_dec->fmt_out.i_codec;
+ p_sys->video = p_dec->fmt_out.video;
+
+ p_sys->p_vout = vout_Request( p_dec, p_sys->p_vout,
+ p_sys->video.i_width,
+ p_sys->video.i_height,
+ p_sys->video.i_chroma,
+ p_sys->video.i_aspect );
+
+ if( p_sys->p_vout == NULL )
+ {
+ msg_Err( p_dec, "failed to create video output" );
+ return NULL;
+ }
+ }
+
+ /* Get a new picture */
+ while( !(p_pic = vout_CreatePicture( p_sys->p_vout, 0, 0, 0 ) ) )
+ {
+ if( p_dec->b_die || p_dec->b_error )
+ {
+ return NULL;
+ }
+ msleep( VOUT_OUTMEM_SLEEP );
+ }
+
+ return p_pic;
+}
+
+static void vout_del_buffer( decoder_t *p_dec, picture_t *p_pic )
+{
+ vout_DestroyPicture( p_dec->p_owner->p_vout, p_pic );