1 /*****************************************************************************
2 * decoder.c: Functions for the management of decoders
3 *****************************************************************************
4 * Copyright (C) 1999-2004 VideoLAN
7 * Authors: Christophe Massiot <massiot@via.ecp.fr>
8 * Gildas Bazin <gbazin@videolan.org>
9 * Laurent Aimar <fenrir@via.ecp.fr>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
24 *****************************************************************************/
26 /*****************************************************************************
28 *****************************************************************************/
32 #include <vlc/decoder.h>
34 #include <vlc/input.h>
36 #include "stream_output.h"
37 #include "input_internal.h"
39 static decoder_t * CreateDecoder( input_thread_t *, es_format_t *, int );
40 static void DeleteDecoder( decoder_t * );
42 static int DecoderThread( decoder_t * );
43 static int DecoderDecode( decoder_t * p_dec, block_t *p_block );
45 /* Buffers allocation callbacks for the decoders */
46 static aout_buffer_t *aout_new_buffer( decoder_t *, int );
47 static void aout_del_buffer( decoder_t *, aout_buffer_t * );
49 static picture_t *vout_new_buffer( decoder_t * );
50 static void vout_del_buffer( decoder_t *, picture_t * );
51 static void vout_link_picture( decoder_t *, picture_t * );
52 static void vout_unlink_picture( decoder_t *, picture_t * );
54 static subpicture_t *spu_new_buffer( decoder_t * );
55 static void spu_del_buffer( decoder_t *, subpicture_t * );
57 static es_format_t null_es_format = {0};
59 struct decoder_owner_sys_t
61 vlc_bool_t b_own_thread;
63 input_thread_t *p_input;
65 aout_instance_t *p_aout;
66 aout_input_t *p_aout_input;
68 vout_thread_t *p_vout;
70 vout_thread_t *p_spu_vout;
73 sout_instance_t *p_sout;
74 sout_packetizer_input_t *p_sout_input;
76 /* Some decoders require already packetized data (ie. not truncated) */
77 decoder_t *p_packetizer;
79 /* Current format in use by the output */
90 * Spawns a new decoder thread
92 * \param p_input the input thread
93 * \param p_es the es descriptor
94 * \return the spawned decoder object
96 decoder_t *input_DecoderNew( input_thread_t *p_input,
97 es_format_t *fmt, vlc_bool_t b_force_decoder )
99 decoder_t *p_dec = NULL;
102 /* If we are in sout mode, search for packetizer module */
103 if( p_input->p_sout && !b_force_decoder )
105 /* Create the decoder configuration structure */
106 p_dec = CreateDecoder( p_input, fmt, VLC_OBJECT_PACKETIZER );
109 msg_Err( p_input, "could not create packetizer" );
115 /* Create the decoder configuration structure */
116 p_dec = CreateDecoder( p_input, fmt, VLC_OBJECT_DECODER );
119 msg_Err( p_input, "could not create decoder" );
124 if( !p_dec->p_module )
126 msg_Err( p_dec, "no suitable decoder module for fourcc `%4.4s'.\n"
127 "VLC probably does not support this sound or video format.",
128 (char*)&p_dec->fmt_in.i_codec );
130 DeleteDecoder( p_dec );
131 vlc_object_destroy( p_dec );
135 if( p_input->p_sout && p_input->input.b_can_pace_control &&
138 msg_Dbg( p_input, "stream out mode -> no decoder thread" );
139 p_dec->p_owner->b_own_thread = VLC_FALSE;
143 var_Get( p_input, "minimize-threads", &val );
144 p_dec->p_owner->b_own_thread = !val.b_bool;
147 if( p_dec->p_owner->b_own_thread )
150 if( fmt->i_cat == AUDIO_ES )
151 i_priority = VLC_THREAD_PRIORITY_AUDIO;
153 i_priority = VLC_THREAD_PRIORITY_VIDEO;
155 /* Spawn the decoder thread */
156 if( vlc_thread_create( p_dec, "decoder", DecoderThread,
157 i_priority, VLC_FALSE ) )
159 msg_Err( p_dec, "cannot spawn decoder thread \"%s\"",
160 p_dec->p_module->psz_object_name );
161 module_Unneed( p_dec, p_dec->p_module );
162 DeleteDecoder( p_dec );
163 vlc_object_destroy( p_dec );
172 * Kills a decoder thread and waits until it's finished
174 * \param p_input the input thread
175 * \param p_es the es descriptor
178 void input_DecoderDelete( decoder_t *p_dec )
180 p_dec->b_die = VLC_TRUE;
182 if( p_dec->p_owner->b_own_thread )
184 /* Make sure the thread leaves the function by
185 * sending it an empty block. */
186 block_t *p_block = block_New( p_dec, 0 );
187 input_DecoderDecode( p_dec, p_block );
189 vlc_thread_join( p_dec );
191 /* Don't module_Unneed() here because of the dll loader that wants
192 * close() in the same thread than open()/decode() */
196 module_Unneed( p_dec, p_dec->p_module );
199 /* Delete decoder configuration */
200 DeleteDecoder( p_dec );
202 /* Delete the decoder */
203 vlc_object_destroy( p_dec );
207 * Put a block_t in the decoder's fifo.
209 * \param p_dec the decoder object
210 * \param p_block the data block
212 void input_DecoderDecode( decoder_t * p_dec, block_t *p_block )
214 if( p_dec->p_owner->b_own_thread )
216 if( p_dec->p_owner->p_input->b_out_pace_control )
219 while( !p_dec->b_die && !p_dec->b_error &&
220 p_dec->p_owner->p_fifo->i_depth > 10 )
225 else if( p_dec->p_owner->p_fifo->i_size > 50000000 /* 50 MB */ )
227 /* FIXME: ideally we would check the time amount of data
228 * in the fifo instead of its size. */
229 msg_Warn( p_dec, "decoder/packetizer fifo full (data not "
230 "consummed quickly enough), resetting fifo!" );
231 block_FifoEmpty( p_dec->p_owner->p_fifo );
234 block_FifoPut( p_dec->p_owner->p_fifo, p_block );
238 if( p_dec->b_error || p_block->i_buffer <= 0 )
240 block_Release( p_block );
244 DecoderDecode( p_dec, p_block );
249 void input_DecoderDiscontinuity( decoder_t * p_dec )
254 if( p_dec->p_owner->b_own_thread )
256 block_FifoEmpty( p_dec->p_owner->p_fifo );
259 /* Send a special block */
260 p_null = block_New( p_dec, 128 );
261 p_null->i_flags |= BLOCK_FLAG_DISCONTINUITY;
262 memset( p_null->p_buffer, 0, p_null->i_buffer );
264 input_DecoderDecode( p_dec, p_null );
267 vlc_bool_t input_DecoderEmpty( decoder_t * p_dec )
269 if( p_dec->p_owner->b_own_thread && p_dec->p_owner->p_fifo->i_depth > 0 )
278 * Create a NULL packet for padding in case of a data loss
280 * \param p_input the input thread
281 * \param p_es es descriptor
284 static void input_NullPacket( input_thread_t * p_input,
285 es_descriptor_t * p_es )
288 block_t *p_block = block_New( p_input, PADDING_PACKET_SIZE );
291 memset( p_block->p_buffer, 0, PADDING_PACKET_SIZE );
292 p_block->i_flags |= BLOCK_FLAG_DISCONTINUITY;
294 block_FifoPut( p_es->p_dec->p_owner->p_fifo, p_block );
300 * Send a NULL packet to the decoders
302 * \param p_input the input thread
305 void input_EscapeDiscontinuity( input_thread_t * p_input )
308 unsigned int i_es, i;
310 for( i_es = 0; i_es < p_input->stream.i_selected_es_number; i_es++ )
312 es_descriptor_t * p_es = p_input->stream.pp_selected_es[i_es];
314 if( p_es->p_dec != NULL )
316 for( i = 0; i < PADDING_PACKET_NUMBER; i++ )
318 input_NullPacket( p_input, p_es );
326 * Send a NULL packet to the audio decoders
328 * \param p_input the input thread
331 void input_EscapeAudioDiscontinuity( input_thread_t * p_input )
334 unsigned int i_es, i;
336 for( i_es = 0; i_es < p_input->stream.i_selected_es_number; i_es++ )
338 es_descriptor_t * p_es = p_input->stream.pp_selected_es[i_es];
340 if( p_es->p_dec != NULL && p_es->i_cat == AUDIO_ES )
342 for( i = 0; i < PADDING_PACKET_NUMBER; i++ )
344 input_NullPacket( p_input, p_es );
353 * Create a decoder object
355 * \param p_input the input thread
356 * \param p_es the es descriptor
357 * \param i_object_type Object type as define in include/vlc_objects.h
358 * \return the decoder object
360 static decoder_t * CreateDecoder( input_thread_t *p_input,
361 es_format_t *fmt, int i_object_type )
365 p_dec = vlc_object_create( p_input, i_object_type );
368 msg_Err( p_input, "out of memory" );
372 p_dec->pf_decode_audio = 0;
373 p_dec->pf_decode_video = 0;
374 p_dec->pf_decode_sub = 0;
375 p_dec->pf_packetize = 0;
377 /* Initialize the decoder fifo */
378 p_dec->p_module = NULL;
381 es_format_Copy( &p_dec->fmt_in, fmt );
382 es_format_Copy( &p_dec->fmt_out, &null_es_format );
384 /* Allocate our private structure for the decoder */
385 p_dec->p_owner = malloc( sizeof( decoder_owner_sys_t ) );
386 if( p_dec->p_owner == NULL )
388 msg_Err( p_dec, "out of memory" );
391 p_dec->p_owner->b_own_thread = VLC_TRUE;
392 p_dec->p_owner->p_input = p_input;
393 p_dec->p_owner->p_aout = NULL;
394 p_dec->p_owner->p_aout_input = NULL;
395 p_dec->p_owner->p_vout = NULL;
396 p_dec->p_owner->p_spu_vout = NULL;
397 p_dec->p_owner->i_spu_channel = 0;
398 p_dec->p_owner->p_sout = p_input->p_sout;
399 p_dec->p_owner->p_sout_input = NULL;
400 p_dec->p_owner->p_packetizer = NULL;
403 if( ( p_dec->p_owner->p_fifo = block_FifoNew( p_dec ) ) == NULL )
405 msg_Err( p_dec, "out of memory" );
409 /* Set buffers allocation callbacks for the decoders */
410 p_dec->pf_aout_buffer_new = aout_new_buffer;
411 p_dec->pf_aout_buffer_del = aout_del_buffer;
412 p_dec->pf_vout_buffer_new = vout_new_buffer;
413 p_dec->pf_vout_buffer_del = vout_del_buffer;
414 p_dec->pf_picture_link = vout_link_picture;
415 p_dec->pf_picture_unlink = vout_unlink_picture;
416 p_dec->pf_spu_buffer_new = spu_new_buffer;
417 p_dec->pf_spu_buffer_del = spu_del_buffer;
419 vlc_object_attach( p_dec, p_input );
421 /* Find a suitable decoder/packetizer module */
422 if( i_object_type == VLC_OBJECT_DECODER )
423 p_dec->p_module = module_Need( p_dec, "decoder", "$codec", 0 );
425 p_dec->p_module = module_Need( p_dec, "packetizer", "$packetizer", 0 );
427 /* Check if decoder requires already packetized data */
428 if( i_object_type == VLC_OBJECT_DECODER &&
429 p_dec->b_need_packetized && !p_dec->fmt_in.b_packetized )
431 p_dec->p_owner->p_packetizer =
432 vlc_object_create( p_input, VLC_OBJECT_PACKETIZER );
433 if( p_dec->p_owner->p_packetizer )
435 es_format_Copy( &p_dec->p_owner->p_packetizer->fmt_in,
438 es_format_Copy( &p_dec->p_owner->p_packetizer->fmt_out,
441 vlc_object_attach( p_dec->p_owner->p_packetizer, p_input );
443 p_dec->p_owner->p_packetizer->p_module =
444 module_Need( p_dec->p_owner->p_packetizer,
445 "packetizer", "$packetizer", 0 );
447 if( !p_dec->p_owner->p_packetizer->p_module )
449 es_format_Clean( &p_dec->p_owner->p_packetizer->fmt_in );
450 vlc_object_detach( p_dec->p_owner->p_packetizer );
451 vlc_object_destroy( p_dec->p_owner->p_packetizer );
460 * The decoding main loop
462 * \param p_dec the decoder
465 static int DecoderThread( decoder_t * p_dec )
469 /* The decoder's main loop */
470 while( !p_dec->b_die && !p_dec->b_error )
472 if( ( p_block = block_FifoGet( p_dec->p_owner->p_fifo ) ) == NULL )
477 if( DecoderDecode( p_dec, p_block ) != VLC_SUCCESS )
483 while( !p_dec->b_die )
485 /* Trash all received PES packets */
486 p_block = block_FifoGet( p_dec->p_owner->p_fifo );
487 if( p_block ) block_Release( p_block );
490 /* We do it here because of the dll loader that wants close() in the
491 * same thread than open()/decode() */
492 module_Unneed( p_dec, p_dec->p_module );
500 * \param p_dec the decoder object
501 * \param p_block the block to decode
502 * \return VLC_SUCCESS or an error code
504 static int DecoderDecode( decoder_t *p_dec, block_t *p_block )
506 int i_rate = p_block->i_rate;
508 if( p_block->i_buffer <= 0 )
510 block_Release( p_block );
514 if( p_dec->i_object_type == VLC_OBJECT_PACKETIZER )
516 block_t *p_sout_block;
518 while( (p_sout_block = p_dec->pf_packetize( p_dec, &p_block )) )
520 if( !p_dec->p_owner->p_sout_input )
522 es_format_Copy( &p_dec->p_owner->sout, &p_dec->fmt_out );
524 p_dec->p_owner->sout.i_group = p_dec->fmt_in.i_group;
525 p_dec->p_owner->sout.i_id = p_dec->fmt_in.i_id;
526 if( p_dec->fmt_in.psz_language )
528 p_dec->p_owner->sout.psz_language =
529 strdup( p_dec->fmt_in.psz_language );
532 p_dec->p_owner->p_sout_input =
533 sout_InputNew( p_dec->p_owner->p_sout,
534 &p_dec->p_owner->sout );
536 if( p_dec->p_owner->p_sout_input == NULL )
538 msg_Err( p_dec, "cannot create packetizer output" );
539 p_dec->b_error = VLC_TRUE;
541 while( p_sout_block )
543 block_t *p_next = p_sout_block->p_next;
544 block_Release( p_sout_block );
545 p_sout_block = p_next;
551 while( p_sout_block )
553 block_t *p_next = p_sout_block->p_next;
555 p_sout_block->p_next = NULL;
556 p_sout_block->i_rate = i_rate;
558 sout_InputSendBuffer( p_dec->p_owner->p_sout_input,
561 p_sout_block = p_next;
564 /* For now it's enough, as only sout inpact on this flag */
565 if( p_dec->p_owner->p_sout->i_out_pace_nocontrol > 0 &&
566 p_dec->p_owner->p_input->b_out_pace_control )
568 msg_Dbg( p_dec, "switching to synch mode" );
569 p_dec->p_owner->p_input->b_out_pace_control = VLC_FALSE;
571 else if( p_dec->p_owner->p_sout->i_out_pace_nocontrol <= 0 &&
572 !p_dec->p_owner->p_input->b_out_pace_control )
574 msg_Dbg( p_dec, "switching to asynch mode" );
575 p_dec->p_owner->p_input->b_out_pace_control = VLC_TRUE;
579 else if( p_dec->fmt_in.i_cat == AUDIO_ES )
581 aout_buffer_t *p_aout_buf;
583 if( p_dec->p_owner->p_packetizer )
585 block_t *p_packetized_block;
586 decoder_t *p_packetizer = p_dec->p_owner->p_packetizer;
588 while( (p_packetized_block =
589 p_packetizer->pf_packetize( p_packetizer, &p_block )) )
591 while( p_packetized_block )
593 block_t *p_next = p_packetized_block->p_next;
594 p_packetized_block->p_next = NULL;
595 p_packetized_block->i_rate = i_rate;
597 while( (p_aout_buf = p_dec->pf_decode_audio( p_dec,
598 &p_packetized_block )) )
600 aout_DecPlay( p_dec->p_owner->p_aout,
601 p_dec->p_owner->p_aout_input,
605 p_packetized_block = p_next;
609 else while( (p_aout_buf = p_dec->pf_decode_audio( p_dec, &p_block )) )
611 aout_DecPlay( p_dec->p_owner->p_aout,
612 p_dec->p_owner->p_aout_input, p_aout_buf );
615 else if( p_dec->fmt_in.i_cat == VIDEO_ES )
619 if( p_dec->p_owner->p_packetizer )
621 block_t *p_packetized_block;
622 decoder_t *p_packetizer = p_dec->p_owner->p_packetizer;
624 while( (p_packetized_block =
625 p_packetizer->pf_packetize( p_packetizer, &p_block )) )
627 while( p_packetized_block )
629 block_t *p_next = p_packetized_block->p_next;
630 p_packetized_block->p_next = NULL;
631 p_packetized_block->i_rate = i_rate;
633 while( (p_pic = p_dec->pf_decode_video( p_dec,
634 &p_packetized_block )) )
636 vout_DatePicture( p_dec->p_owner->p_vout, p_pic,
638 vout_DisplayPicture( p_dec->p_owner->p_vout, p_pic );
641 p_packetized_block = p_next;
645 else while( (p_pic = p_dec->pf_decode_video( p_dec, &p_block )) )
647 vout_DatePicture( p_dec->p_owner->p_vout, p_pic, p_pic->date );
648 vout_DisplayPicture( p_dec->p_owner->p_vout, p_pic );
651 else if( p_dec->fmt_in.i_cat == SPU_ES )
653 vout_thread_t *p_vout;
655 while( (p_spu = p_dec->pf_decode_sub( p_dec, &p_block ) ) )
657 p_vout = vlc_object_find( p_dec, VLC_OBJECT_VOUT, FIND_ANYWHERE );
660 vout_DisplaySubPicture( p_vout, p_spu );
661 vlc_object_release( p_vout );
667 msg_Err( p_dec, "unknown ES format" );
671 return p_dec->b_error ? VLC_EGENERIC : VLC_SUCCESS;
675 * Destroys a decoder object
677 * \param p_dec the decoder object
680 static void DeleteDecoder( decoder_t * p_dec )
682 msg_Dbg( p_dec, "killing decoder fourcc `%4.4s', %d PES in FIFO",
683 (char*)&p_dec->fmt_in.i_codec,
684 p_dec->p_owner->p_fifo->i_depth );
686 /* Free all packets still in the decoder fifo. */
687 block_FifoEmpty( p_dec->p_owner->p_fifo );
688 block_FifoRelease( p_dec->p_owner->p_fifo );
691 if( p_dec->p_owner->p_aout_input )
692 aout_DecDelete( p_dec->p_owner->p_aout, p_dec->p_owner->p_aout_input );
694 if( p_dec->p_owner->p_vout )
698 #define p_pic p_dec->p_owner->p_vout->render.pp_picture[i_pic]
699 /* Hack to make sure all the the pictures are freed by the decoder */
700 for( i_pic = 0; i_pic < p_dec->p_owner->p_vout->render.i_pictures;
703 if( p_pic->i_status == RESERVED_PICTURE )
704 vout_DestroyPicture( p_dec->p_owner->p_vout, p_pic );
705 if( p_pic->i_refcount > 0 )
706 vout_UnlinkPicture( p_dec->p_owner->p_vout, p_pic );
710 /* We are about to die. Reattach video output to p_vlc. */
711 vout_Request( p_dec, p_dec->p_owner->p_vout, 0, 0, 0, 0 );
714 if( p_dec->p_owner->p_sout_input )
716 sout_InputDelete( p_dec->p_owner->p_sout_input );
717 es_format_Clean( &p_dec->p_owner->sout );
720 if( p_dec->fmt_in.i_cat == SPU_ES )
722 vout_thread_t *p_vout;
724 p_vout = vlc_object_find( p_dec, VLC_OBJECT_VOUT, FIND_ANYWHERE );
727 vout_ClearOSDChannel( p_vout, p_dec->p_owner->i_spu_channel );
728 vlc_object_release( p_vout );
732 es_format_Clean( &p_dec->fmt_in );
733 es_format_Clean( &p_dec->fmt_out );
735 if( p_dec->p_owner->p_packetizer )
737 module_Unneed( p_dec->p_owner->p_packetizer,
738 p_dec->p_owner->p_packetizer->p_module );
739 es_format_Clean( &p_dec->p_owner->p_packetizer->fmt_in );
740 es_format_Clean( &p_dec->p_owner->p_packetizer->fmt_out );
741 vlc_object_detach( p_dec->p_owner->p_packetizer );
742 vlc_object_destroy( p_dec->p_owner->p_packetizer );
745 vlc_object_detach( p_dec );
747 free( p_dec->p_owner );
750 /*****************************************************************************
751 * Buffers allocation callbacks for the decoders
752 *****************************************************************************/
753 static aout_buffer_t *aout_new_buffer( decoder_t *p_dec, int i_samples )
755 decoder_owner_sys_t *p_sys = (decoder_owner_sys_t *)p_dec->p_owner;
756 aout_buffer_t *p_buffer;
758 if( p_sys->p_aout_input != NULL &&
759 ( p_dec->fmt_out.audio.i_rate != p_sys->audio.i_rate ||
760 p_dec->fmt_out.audio.i_original_channels !=
761 p_sys->audio.i_original_channels ||
762 p_dec->fmt_out.audio.i_bytes_per_frame !=
763 p_sys->audio.i_bytes_per_frame ) )
765 /* Parameters changed, restart the aout */
766 aout_DecDelete( p_sys->p_aout, p_sys->p_aout_input );
767 p_sys->p_aout_input = NULL;
770 if( p_sys->p_aout_input == NULL )
772 p_dec->fmt_out.audio.i_format = p_dec->fmt_out.i_codec;
773 p_sys->audio = p_dec->fmt_out.audio;
774 p_sys->p_aout_input =
775 aout_DecNew( p_dec, &p_sys->p_aout, &p_sys->audio );
776 if( p_sys->p_aout_input == NULL )
778 msg_Err( p_dec, "failed to create audio output" );
779 p_dec->b_error = VLC_TRUE;
782 p_dec->fmt_out.audio.i_bytes_per_frame =
783 p_sys->audio.i_bytes_per_frame;
786 p_buffer = aout_DecNewBuffer( p_sys->p_aout, p_sys->p_aout_input,
792 static void aout_del_buffer( decoder_t *p_dec, aout_buffer_t *p_buffer )
794 aout_DecDeleteBuffer( p_dec->p_owner->p_aout,
795 p_dec->p_owner->p_aout_input, p_buffer );
798 static picture_t *vout_new_buffer( decoder_t *p_dec )
800 decoder_owner_sys_t *p_sys = (decoder_owner_sys_t *)p_dec->p_owner;
803 if( p_sys->p_vout == NULL ||
804 p_dec->fmt_out.video.i_width != p_sys->video.i_width ||
805 p_dec->fmt_out.video.i_height != p_sys->video.i_height ||
806 p_dec->fmt_out.video.i_chroma != p_sys->video.i_chroma ||
807 p_dec->fmt_out.video.i_aspect != p_sys->video.i_aspect )
809 if( !p_dec->fmt_out.video.i_width ||
810 !p_dec->fmt_out.video.i_height )
812 /* Can't create a new vout without display size */
816 p_dec->fmt_out.video.i_chroma = p_dec->fmt_out.i_codec;
817 p_sys->video = p_dec->fmt_out.video;
819 p_sys->p_vout = vout_Request( p_dec, p_sys->p_vout,
820 p_sys->video.i_width,
821 p_sys->video.i_height,
822 p_sys->video.i_chroma,
823 p_sys->video.i_aspect );
825 if( p_sys->p_vout == NULL )
827 msg_Err( p_dec, "failed to create video output" );
828 p_dec->b_error = VLC_TRUE;
833 /* Get a new picture */
834 while( !(p_pic = vout_CreatePicture( p_sys->p_vout, 0, 0, 0 ) ) )
836 int i_pic, i_ready_pic = 0;
838 if( p_dec->b_die || p_dec->b_error )
843 #define p_pic p_dec->p_owner->p_vout->render.pp_picture[i_pic]
844 /* Check the decoder doesn't leak pictures */
845 for( i_pic = 0; i_pic < p_dec->p_owner->p_vout->render.i_pictures;
848 if( p_pic->i_status == READY_PICTURE )
850 if( i_ready_pic++ > 0 ) break;
854 if( p_pic->i_status != DISPLAYED_PICTURE &&
855 p_pic->i_status != RESERVED_PICTURE &&
856 p_pic->i_status != READY_PICTURE ) break;
858 if( !p_pic->i_refcount && p_pic->i_status != RESERVED_PICTURE )
861 if( i_pic == p_dec->p_owner->p_vout->render.i_pictures )
863 msg_Err( p_dec, "decoder is leaking pictures, resetting the heap" );
865 /* Just free all the pictures */
866 for( i_pic = 0; i_pic < p_dec->p_owner->p_vout->render.i_pictures;
869 if( p_pic->i_status == RESERVED_PICTURE )
870 vout_DestroyPicture( p_dec->p_owner->p_vout, p_pic );
871 if( p_pic->i_refcount > 0 )
872 vout_UnlinkPicture( p_dec->p_owner->p_vout, p_pic );
877 msleep( VOUT_OUTMEM_SLEEP );
883 static void vout_del_buffer( decoder_t *p_dec, picture_t *p_pic )
885 vout_DestroyPicture( p_dec->p_owner->p_vout, p_pic );
888 static void vout_link_picture( decoder_t *p_dec, picture_t *p_pic )
890 vout_LinkPicture( p_dec->p_owner->p_vout, p_pic );
893 static void vout_unlink_picture( decoder_t *p_dec, picture_t *p_pic )
895 vout_UnlinkPicture( p_dec->p_owner->p_vout, p_pic );
898 static subpicture_t *spu_new_buffer( decoder_t *p_dec )
900 decoder_owner_sys_t *p_sys = (decoder_owner_sys_t *)p_dec->p_owner;
901 vout_thread_t *p_vout = NULL;
905 while( i_attempts-- )
907 if( p_dec->b_die || p_dec->b_error ) break;
909 p_vout = vlc_object_find( p_dec, VLC_OBJECT_VOUT, FIND_ANYWHERE );
912 msleep( VOUT_DISPLAY_DELAY );
917 msg_Warn( p_dec, "no vout found, dropping subpicture" );
921 if( p_sys->p_spu_vout != p_vout )
923 p_sys->i_spu_channel =
924 vout_RegisterOSDChannel( p_vout );
925 p_sys->p_spu_vout = p_vout;
928 p_spu = vout_CreateSubPicture( p_vout, p_sys->i_spu_channel,
931 vlc_object_release( p_vout );
936 static void spu_del_buffer( decoder_t *p_dec, subpicture_t *p_spu )
938 vout_DestroySubPicture( p_dec->p_owner->p_vout, p_spu );