1 /*****************************************************************************
2 * decoder.c: Functions for the management of decoders
3 *****************************************************************************
4 * Copyright (C) 1999-2004 the VideoLAN team
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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
24 *****************************************************************************/
26 /*****************************************************************************
28 *****************************************************************************/
34 #include <vlc_common.h>
36 #include <vlc_block.h>
40 #include <vlc_codec.h>
43 #include <vlc_interface.h>
44 #include "audio_output/aout_internal.h"
45 #include "stream_output/stream_output.h"
46 #include "input_internal.h"
51 #include "../video_output/vout_control.h"
53 static decoder_t *CreateDecoder( input_thread_t *, es_format_t *, int, sout_instance_t *p_sout );
54 static void DeleteDecoder( decoder_t * );
56 static void *DecoderThread( vlc_object_t * );
57 static void DecoderProcess( decoder_t *, block_t * );
58 static void DecoderError( decoder_t *p_dec, block_t *p_block );
59 static void DecoderOutputChangePause( decoder_t *, bool b_paused, mtime_t i_date );
60 static void DecoderFlush( decoder_t * );
61 static void DecoderSignalBuffering( decoder_t *, bool );
62 static void DecoderFlushBuffering( decoder_t * );
64 static void DecoderUnsupportedCodec( decoder_t *, vlc_fourcc_t );
66 /* Buffers allocation callbacks for the decoders */
67 static aout_buffer_t *aout_new_buffer( decoder_t *, int );
68 static void aout_del_buffer( decoder_t *, aout_buffer_t * );
70 static picture_t *vout_new_buffer( decoder_t * );
71 static void vout_del_buffer( decoder_t *, picture_t * );
72 static void vout_link_picture( decoder_t *, picture_t * );
73 static void vout_unlink_picture( decoder_t *, picture_t * );
75 static subpicture_t *spu_new_buffer( decoder_t * );
76 static void spu_del_buffer( decoder_t *, subpicture_t * );
78 static es_format_t null_es_format;
80 struct decoder_owner_sys_t
82 int64_t i_preroll_end;
84 input_thread_t *p_input;
85 input_clock_t *p_clock;
88 vout_thread_t *p_spu_vout;
92 sout_instance_t *p_sout;
93 sout_packetizer_input_t *p_sout_input;
95 /* Some decoders require already packetized data (ie. not truncated) */
96 decoder_t *p_packetizer;
98 /* Current format in use by the output */
100 audio_format_t audio;
104 bool b_fmt_description;
105 es_format_t fmt_description;
108 block_fifo_t *p_fifo;
110 /* Lock for communication with decoder thread */
114 /* -- These variables need locking on write(only) -- */
115 aout_instance_t *p_aout;
116 aout_input_t *p_aout_input;
118 vout_thread_t *p_vout;
120 /* -- Theses variables need locking on read *and* write -- */
138 picture_t *p_picture;
139 picture_t **pp_picture_next;
141 subpicture_t *p_subpic;
142 subpicture_t **pp_subpic_next;
144 aout_buffer_t *p_audio;
145 aout_buffer_t **pp_audio_next;
148 block_t **pp_block_next;
159 decoder_t *pp_decoder[4];
166 #define DECODER_MAX_BUFFERING_COUNT (4)
167 #define DECODER_MAX_BUFFERING_AUDIO_DURATION (AOUT_MAX_PREPARE_TIME)
168 #define DECODER_MAX_BUFFERING_VIDEO_DURATION (1*CLOCK_FREQ)
170 /* Pictures which are DECODER_BOGUS_VIDEO_DELAY or more in advance probably have
171 * a bogus PTS and won't be displayed */
172 #define DECODER_BOGUS_VIDEO_DELAY ((mtime_t)(DEFAULT_PTS_DELAY * 30))
175 #define DECODER_SPU_VOUT_WAIT_DURATION ((int)(0.200*CLOCK_FREQ))
178 /*****************************************************************************
180 *****************************************************************************/
181 picture_t *decoder_NewPicture( decoder_t *p_decoder )
183 picture_t *p_picture = p_decoder->pf_vout_buffer_new( p_decoder );
185 msg_Warn( p_decoder, "can't get output picture" );
188 void decoder_DeletePicture( decoder_t *p_decoder, picture_t *p_picture )
190 p_decoder->pf_vout_buffer_del( p_decoder, p_picture );
192 void decoder_LinkPicture( decoder_t *p_decoder, picture_t *p_picture )
194 p_decoder->pf_picture_link( p_decoder, p_picture );
196 void decoder_UnlinkPicture( decoder_t *p_decoder, picture_t *p_picture )
198 p_decoder->pf_picture_unlink( p_decoder, p_picture );
201 aout_buffer_t *decoder_NewAudioBuffer( decoder_t *p_decoder, int i_size )
203 if( !p_decoder->pf_aout_buffer_new )
205 return p_decoder->pf_aout_buffer_new( p_decoder, i_size );
207 void decoder_DeleteAudioBuffer( decoder_t *p_decoder, aout_buffer_t *p_buffer )
209 p_decoder->pf_aout_buffer_del( p_decoder, p_buffer );
212 subpicture_t *decoder_NewSubpicture( decoder_t *p_decoder )
214 subpicture_t *p_subpicture = p_decoder->pf_spu_buffer_new( p_decoder );
216 msg_Warn( p_decoder, "can't get output subpicture" );
219 void decoder_DeleteSubpicture( decoder_t *p_decoder, subpicture_t *p_subpicture )
221 p_decoder->pf_spu_buffer_del( p_decoder, p_subpicture );
224 /* decoder_GetInputAttachments:
226 int decoder_GetInputAttachments( decoder_t *p_dec,
227 input_attachment_t ***ppp_attachment,
230 if( !p_dec->pf_get_attachments )
233 return p_dec->pf_get_attachments( p_dec, ppp_attachment, pi_attachment );
235 /* decoder_GetDisplayDate:
237 mtime_t decoder_GetDisplayDate( decoder_t *p_dec, mtime_t i_ts )
239 if( !p_dec->pf_get_display_date )
242 return p_dec->pf_get_display_date( p_dec, i_ts );
244 /* decoder_GetDisplayRate:
246 int decoder_GetDisplayRate( decoder_t *p_dec )
248 if( !p_dec->pf_get_display_rate )
249 return INPUT_RATE_DEFAULT;
251 return p_dec->pf_get_display_rate( p_dec );
255 * Spawns a new decoder thread
257 * \param p_input the input thread
258 * \param p_es the es descriptor
259 * \return the spawned decoder object
261 decoder_t *input_DecoderNew( input_thread_t *p_input,
262 es_format_t *fmt, input_clock_t *p_clock, sout_instance_t *p_sout )
264 decoder_t *p_dec = NULL;
268 /* If we are in sout mode, search for packetizer module */
271 /* Create the decoder configuration structure */
272 p_dec = CreateDecoder( p_input, fmt, VLC_OBJECT_PACKETIZER, p_sout );
275 msg_Err( p_input, "could not create packetizer" );
276 intf_UserFatal( p_input, false, _("Streaming / Transcoding failed"),
277 _("VLC could not open the packetizer module.") );
284 /* Create the decoder configuration structure */
285 p_dec = CreateDecoder( p_input, fmt, VLC_OBJECT_DECODER, p_sout );
288 msg_Err( p_input, "could not create decoder" );
289 intf_UserFatal( p_input, false, _("Streaming / Transcoding failed"),
290 _("VLC could not open the decoder module.") );
295 if( !p_dec->p_module )
297 DecoderUnsupportedCodec( p_dec, fmt->i_codec );
299 DeleteDecoder( p_dec );
300 vlc_object_release( p_dec );
304 p_dec->p_owner->p_clock = p_clock;
306 if( fmt->i_cat == AUDIO_ES )
307 i_priority = VLC_THREAD_PRIORITY_AUDIO;
309 i_priority = VLC_THREAD_PRIORITY_VIDEO;
311 /* Spawn the decoder thread */
312 if( vlc_thread_create( p_dec, "decoder", DecoderThread,
313 i_priority, false ) )
315 msg_Err( p_dec, "cannot spawn decoder thread" );
316 module_unneed( p_dec, p_dec->p_module );
317 DeleteDecoder( p_dec );
318 vlc_object_release( p_dec );
326 * Kills a decoder thread and waits until it's finished
328 * \param p_input the input thread
329 * \param p_es the es descriptor
332 void input_DecoderDelete( decoder_t *p_dec )
334 decoder_owner_sys_t *p_owner = p_dec->p_owner;
336 vlc_object_kill( p_dec );
338 /* Make sure we aren't paused/buffering/waiting anymore */
339 vlc_mutex_lock( &p_owner->lock );
340 p_owner->b_paused = false;
341 p_owner->b_buffering = false;
342 p_owner->b_flushing = true;
343 vlc_cond_signal( &p_owner->wait );
344 vlc_mutex_unlock( &p_owner->lock );
346 vlc_thread_join( p_dec );
347 module_unneed( p_dec, p_dec->p_module );
350 if( p_dec->p_owner->cc.b_supported )
353 for( i = 0; i < 4; i++ )
354 input_DecoderSetCcState( p_dec, false, i );
357 /* Delete decoder configuration */
358 DeleteDecoder( p_dec );
360 /* Delete the decoder */
361 vlc_object_release( p_dec );
365 * Put a block_t in the decoder's fifo.
366 * Thread-safe w.r.t. the decoder. May be a cancellation point.
368 * \param p_dec the decoder object
369 * \param p_block the data block
371 void input_DecoderDecode( decoder_t *p_dec, block_t *p_block )
373 decoder_owner_sys_t *p_owner = p_dec->p_owner;
375 if( p_owner->p_input->p->b_out_pace_control )
377 /* The fifo is not consummed when buffering and so will
379 * There is no need to lock as b_buffering is never modify
380 * inside decoder thread. */
381 if( !p_owner->b_buffering )
382 block_FifoPace( p_owner->p_fifo, 10, SIZE_MAX );
384 else if( block_FifoSize( p_owner->p_fifo ) > 50000000 /* 50 MB */ )
386 /* FIXME: ideally we would check the time amount of data
387 * in the FIFO instead of its size. */
388 msg_Warn( p_dec, "decoder/packetizer fifo full (data not "
389 "consumed quickly enough), resetting fifo!" );
390 block_FifoEmpty( p_owner->p_fifo );
393 block_FifoPut( p_owner->p_fifo, p_block );
396 bool input_DecoderIsEmpty( decoder_t * p_dec )
398 assert( !p_dec->p_owner->b_buffering );
400 /* FIXME that's not really true */
401 return block_FifoCount( p_dec->p_owner->p_fifo ) <= 0;
404 void input_DecoderIsCcPresent( decoder_t *p_dec, bool pb_present[4] )
406 decoder_owner_sys_t *p_owner = p_dec->p_owner;
409 vlc_mutex_lock( &p_owner->lock );
410 for( i = 0; i < 4; i++ )
411 pb_present[i] = p_owner->cc.pb_present[i];
412 vlc_mutex_unlock( &p_owner->lock );
414 int input_DecoderSetCcState( decoder_t *p_dec, bool b_decode, int i_channel )
416 decoder_owner_sys_t *p_owner = p_dec->p_owner;
418 //msg_Warn( p_dec, "input_DecoderSetCcState: %d @%d", b_decode, i_channel );
420 if( i_channel < 0 || i_channel >= 4 || !p_owner->cc.pb_present[i_channel] )
425 static const vlc_fourcc_t fcc[4] = {
426 VLC_FOURCC('c', 'c', '1', ' '),
427 VLC_FOURCC('c', 'c', '2', ' '),
428 VLC_FOURCC('c', 'c', '3', ' '),
429 VLC_FOURCC('c', 'c', '4', ' '),
434 es_format_Init( &fmt, SPU_ES, fcc[i_channel] );
435 p_cc = CreateDecoder( p_owner->p_input, &fmt, VLC_OBJECT_DECODER, p_owner->p_sout );
438 msg_Err( p_dec, "could not create decoder" );
439 intf_UserFatal( p_dec, false, _("Streaming / Transcoding failed"),
440 _("VLC could not open the decoder module.") );
443 else if( !p_cc->p_module )
445 DecoderUnsupportedCodec( p_dec, fcc[i_channel] );
446 DeleteDecoder( p_cc );
447 vlc_object_release( p_cc );
450 p_cc->p_owner->p_clock = p_owner->p_clock;
452 vlc_mutex_lock( &p_owner->lock );
453 p_owner->cc.pp_decoder[i_channel] = p_cc;
454 vlc_mutex_unlock( &p_owner->lock );
460 vlc_mutex_lock( &p_owner->lock );
461 p_cc = p_owner->cc.pp_decoder[i_channel];
462 p_owner->cc.pp_decoder[i_channel] = NULL;
463 vlc_mutex_unlock( &p_owner->lock );
467 vlc_object_kill( p_cc );
468 module_unneed( p_cc, p_cc->p_module );
469 DeleteDecoder( p_cc );
470 vlc_object_release( p_cc );
475 int input_DecoderGetCcState( decoder_t *p_dec, bool *pb_decode, int i_channel )
477 decoder_owner_sys_t *p_owner = p_dec->p_owner;
480 if( i_channel < 0 || i_channel >= 4 || !p_owner->cc.pb_present[i_channel] )
483 vlc_mutex_lock( &p_owner->lock );
484 *pb_decode = p_owner->cc.pp_decoder[i_channel] != NULL;
485 vlc_mutex_unlock( &p_owner->lock );
489 void input_DecoderChangePause( decoder_t *p_dec, bool b_paused, mtime_t i_date )
491 decoder_owner_sys_t *p_owner = p_dec->p_owner;
493 vlc_mutex_lock( &p_owner->lock );
495 assert( !p_owner->b_paused || !b_paused );
497 p_owner->b_paused = b_paused;
498 p_owner->pause.i_date = i_date;
499 p_owner->pause.i_ignore = 0;
500 vlc_cond_signal( &p_owner->wait );
502 DecoderOutputChangePause( p_dec, b_paused, i_date );
504 vlc_mutex_unlock( &p_owner->lock );
507 void input_DecoderChangeDelay( decoder_t *p_dec, mtime_t i_delay )
509 decoder_owner_sys_t *p_owner = p_dec->p_owner;
511 vlc_mutex_lock( &p_owner->lock );
512 p_owner->i_ts_delay = i_delay;
513 vlc_mutex_unlock( &p_owner->lock );
516 void input_DecoderStartBuffering( decoder_t *p_dec )
518 decoder_owner_sys_t *p_owner = p_dec->p_owner;
520 vlc_mutex_lock( &p_owner->lock );
522 DecoderFlush( p_dec );
524 p_owner->buffer.b_first = true;
525 p_owner->buffer.b_full = false;
526 p_owner->buffer.i_count = 0;
528 assert( !p_owner->buffer.p_picture && !p_owner->buffer.p_subpic &&
529 !p_owner->buffer.p_audio && !p_owner->buffer.p_block );
531 p_owner->buffer.p_picture = NULL;
532 p_owner->buffer.pp_picture_next = &p_owner->buffer.p_picture;
534 p_owner->buffer.p_subpic = NULL;
535 p_owner->buffer.pp_subpic_next = &p_owner->buffer.p_subpic;
537 p_owner->buffer.p_audio = NULL;
538 p_owner->buffer.pp_audio_next = &p_owner->buffer.p_audio;
540 p_owner->buffer.p_block = NULL;
541 p_owner->buffer.pp_block_next = &p_owner->buffer.p_block;
544 p_owner->b_buffering = true;
546 vlc_cond_signal( &p_owner->wait );
548 vlc_mutex_unlock( &p_owner->lock );
551 void input_DecoderStopBuffering( decoder_t *p_dec )
553 decoder_owner_sys_t *p_owner = p_dec->p_owner;
555 vlc_mutex_lock( &p_owner->lock );
557 p_owner->b_buffering = false;
559 vlc_cond_signal( &p_owner->wait );
561 vlc_mutex_unlock( &p_owner->lock );
564 void input_DecoderWaitBuffering( decoder_t *p_dec )
566 decoder_owner_sys_t *p_owner = p_dec->p_owner;
568 vlc_mutex_lock( &p_owner->lock );
570 while( vlc_object_alive( p_dec ) && p_owner->b_buffering && !p_owner->buffer.b_full )
572 block_FifoWake( p_owner->p_fifo );
573 vlc_cond_wait( &p_owner->wait, &p_owner->lock );
576 vlc_mutex_unlock( &p_owner->lock );
579 void input_DecoderFrameNext( decoder_t *p_dec, mtime_t *pi_duration )
581 decoder_owner_sys_t *p_owner = p_dec->p_owner;
585 vlc_mutex_lock( &p_owner->lock );
586 if( p_dec->fmt_in.i_cat == VIDEO_ES )
588 if( p_owner->b_paused && p_owner->p_vout )
590 vout_NextPicture( p_owner->p_vout, pi_duration );
591 p_owner->pause.i_ignore++;
592 vlc_cond_signal( &p_owner->wait );
597 /* TODO subtitle should not be flushed */
598 DecoderFlush( p_dec );
600 vlc_mutex_unlock( &p_owner->lock );
603 bool input_DecoderHasFormatChanged( decoder_t *p_dec, es_format_t *p_fmt )
605 decoder_owner_sys_t *p_owner = p_dec->p_owner;
608 vlc_mutex_lock( &p_owner->lock );
609 b_changed = p_owner->b_fmt_description;
613 es_format_Copy( p_fmt, &p_owner->fmt_description );
614 p_owner->b_fmt_description = false;
616 vlc_mutex_unlock( &p_owner->lock );
620 /*****************************************************************************
622 *****************************************************************************/
623 static int DecoderGetInputAttachments( decoder_t *p_dec,
624 input_attachment_t ***ppp_attachment,
627 return input_Control( p_dec->p_owner->p_input, INPUT_GET_ATTACHMENTS,
628 ppp_attachment, pi_attachment );
630 static mtime_t DecoderGetDisplayDate( decoder_t *p_dec, mtime_t i_ts )
632 decoder_owner_sys_t *p_owner = p_dec->p_owner;
634 vlc_mutex_lock( &p_owner->lock );
635 if( p_owner->b_buffering || p_owner->b_paused )
637 vlc_mutex_unlock( &p_owner->lock );
639 if( !p_owner->p_clock || !i_ts )
642 return input_clock_GetTS( p_owner->p_clock, NULL, p_owner->p_input->i_pts_delay, i_ts );
644 static int DecoderGetDisplayRate( decoder_t *p_dec )
646 decoder_owner_sys_t *p_owner = p_dec->p_owner;
648 if( !p_owner->p_clock )
649 return INPUT_RATE_DEFAULT;
650 return input_clock_GetRate( p_owner->p_clock );
654 static void DecoderUnsupportedCodec( decoder_t *p_dec, vlc_fourcc_t codec )
656 msg_Err( p_dec, "no suitable decoder module for fourcc `%4.4s'.\n"
657 "VLC probably does not support this sound or video format.",
659 intf_UserFatal( p_dec, false, _("No suitable decoder module"),
660 _("VLC does not support the audio or video format \"%4.4s\". "
661 "Unfortunately there is no way for you to fix this."), (char*)&codec );
666 * Create a decoder object
668 * \param p_input the input thread
669 * \param p_es the es descriptor
670 * \param i_object_type Object type as define in include/vlc_objects.h
671 * \return the decoder object
673 static decoder_t * CreateDecoder( input_thread_t *p_input,
674 es_format_t *fmt, int i_object_type, sout_instance_t *p_sout )
677 decoder_owner_sys_t *p_owner;
680 p_dec = vlc_object_create( p_input, i_object_type );
684 p_dec->pf_decode_audio = NULL;
685 p_dec->pf_decode_video = NULL;
686 p_dec->pf_decode_sub = NULL;
687 p_dec->pf_get_cc = NULL;
688 p_dec->pf_packetize = NULL;
690 /* Initialize the decoder fifo */
691 p_dec->p_module = NULL;
693 memset( &null_es_format, 0, sizeof(es_format_t) );
694 es_format_Copy( &p_dec->fmt_in, fmt );
695 es_format_Copy( &p_dec->fmt_out, &null_es_format );
697 /* Allocate our private structure for the decoder */
698 p_dec->p_owner = p_owner = malloc( sizeof( decoder_owner_sys_t ) );
699 if( p_dec->p_owner == NULL )
701 vlc_object_release( p_dec );
704 p_dec->p_owner->i_preroll_end = -1;
705 p_dec->p_owner->i_last_rate = INPUT_RATE_DEFAULT;
706 p_dec->p_owner->p_input = p_input;
707 p_dec->p_owner->p_aout = NULL;
708 p_dec->p_owner->p_aout_input = NULL;
709 p_dec->p_owner->p_vout = NULL;
710 p_dec->p_owner->p_spu_vout = NULL;
711 p_dec->p_owner->i_spu_channel = 0;
712 p_dec->p_owner->i_spu_order = 0;
713 p_dec->p_owner->p_sout = p_sout;
714 p_dec->p_owner->p_sout_input = NULL;
715 p_dec->p_owner->p_packetizer = NULL;
718 if( ( p_dec->p_owner->p_fifo = block_FifoNew() ) == NULL )
720 free( p_dec->p_owner );
721 vlc_object_release( p_dec );
725 /* Set buffers allocation callbacks for the decoders */
726 p_dec->pf_aout_buffer_new = aout_new_buffer;
727 p_dec->pf_aout_buffer_del = aout_del_buffer;
728 p_dec->pf_vout_buffer_new = vout_new_buffer;
729 p_dec->pf_vout_buffer_del = vout_del_buffer;
730 p_dec->pf_picture_link = vout_link_picture;
731 p_dec->pf_picture_unlink = vout_unlink_picture;
732 p_dec->pf_spu_buffer_new = spu_new_buffer;
733 p_dec->pf_spu_buffer_del = spu_del_buffer;
735 p_dec->pf_get_attachments = DecoderGetInputAttachments;
736 p_dec->pf_get_display_date = DecoderGetDisplayDate;
737 p_dec->pf_get_display_rate = DecoderGetDisplayRate;
739 vlc_object_attach( p_dec, p_input );
741 /* Find a suitable decoder/packetizer module */
742 if( i_object_type == VLC_OBJECT_DECODER )
743 p_dec->p_module = module_need( p_dec, "decoder", "$codec", 0 );
745 p_dec->p_module = module_need( p_dec, "packetizer", "$packetizer", 0 );
747 /* Check if decoder requires already packetized data */
748 if( i_object_type == VLC_OBJECT_DECODER &&
749 p_dec->b_need_packetized && !p_dec->fmt_in.b_packetized )
751 p_dec->p_owner->p_packetizer =
752 vlc_object_create( p_input, VLC_OBJECT_PACKETIZER );
753 if( p_dec->p_owner->p_packetizer )
755 es_format_Copy( &p_dec->p_owner->p_packetizer->fmt_in,
758 es_format_Copy( &p_dec->p_owner->p_packetizer->fmt_out,
761 vlc_object_attach( p_dec->p_owner->p_packetizer, p_input );
763 p_dec->p_owner->p_packetizer->p_module =
764 module_need( p_dec->p_owner->p_packetizer,
765 "packetizer", "$packetizer", 0 );
767 if( !p_dec->p_owner->p_packetizer->p_module )
769 es_format_Clean( &p_dec->p_owner->p_packetizer->fmt_in );
770 vlc_object_detach( p_dec->p_owner->p_packetizer );
771 vlc_object_release( p_dec->p_owner->p_packetizer );
776 /* Copy ourself the input replay gain */
777 if( fmt->i_cat == AUDIO_ES )
779 for( i = 0; i < AUDIO_REPLAY_GAIN_MAX; i++ )
781 if( !p_dec->fmt_out.audio_replay_gain.pb_peak[i] )
783 p_dec->fmt_out.audio_replay_gain.pb_peak[i] = fmt->audio_replay_gain.pb_peak[i];
784 p_dec->fmt_out.audio_replay_gain.pf_peak[i] = fmt->audio_replay_gain.pf_peak[i];
786 if( !p_dec->fmt_out.audio_replay_gain.pb_gain[i] )
788 p_dec->fmt_out.audio_replay_gain.pb_gain[i] = fmt->audio_replay_gain.pb_gain[i];
789 p_dec->fmt_out.audio_replay_gain.pf_gain[i] = fmt->audio_replay_gain.pf_gain[i];
795 vlc_mutex_init( &p_owner->lock );
796 vlc_cond_init( &p_owner->wait );
798 p_owner->b_fmt_description = false;
799 es_format_Init( &p_owner->fmt_description, UNKNOWN_ES, 0 );
801 p_owner->b_paused = false;
802 p_owner->pause.i_date = 0;
803 p_owner->pause.i_ignore = 0;
805 p_owner->b_buffering = false;
806 p_owner->buffer.b_first = true;
807 p_owner->buffer.b_full = false;
808 p_owner->buffer.i_count = 0;
809 p_owner->buffer.p_picture = NULL;
810 p_owner->buffer.p_subpic = NULL;
811 p_owner->buffer.p_audio = NULL;
812 p_owner->buffer.p_block = NULL;
814 p_owner->b_flushing = false;
817 p_owner->cc.b_supported = false;
818 if( i_object_type == VLC_OBJECT_DECODER )
820 if( p_owner->p_packetizer && p_owner->p_packetizer->pf_get_cc )
821 p_owner->cc.b_supported = true;
822 if( p_dec->pf_get_cc )
823 p_owner->cc.b_supported = true;
826 for( i = 0; i < 4; i++ )
828 p_owner->cc.pb_present[i] = false;
829 p_owner->cc.pp_decoder[i] = NULL;
831 p_owner->i_ts_delay = 0;
836 * The decoding main loop
838 * \param p_dec the decoder
840 static void *DecoderThread( vlc_object_t *p_this )
842 decoder_t *p_dec = (decoder_t *)p_this;
843 decoder_owner_sys_t *p_owner = p_dec->p_owner;
845 /* The decoder's main loop */
848 block_t *p_block = block_FifoGet( p_owner->p_fifo );
849 /* Make sure there is no cancellation point other than this one^^.
850 * If you need one, be sure to push cleanup of p_block. */
851 DecoderSignalBuffering( p_dec, p_block == NULL );
855 int canc = vlc_savecancel();
858 DecoderError( p_dec, p_block );
860 DecoderProcess( p_dec, p_block );
862 vlc_restorecancel( canc );
866 DecoderSignalBuffering( p_dec, true );
870 static void DecoderFlush( decoder_t *p_dec )
872 decoder_owner_sys_t *p_owner = p_dec->p_owner;
875 vlc_assert_locked( &p_owner->lock );
878 block_FifoEmpty( p_owner->p_fifo );
880 /* Monitor for flush end */
881 p_owner->b_flushing = true;
882 vlc_cond_signal( &p_owner->wait );
884 /* Send a special block */
885 p_null = block_New( p_dec, 128 );
888 p_null->i_flags |= BLOCK_FLAG_DISCONTINUITY;
889 p_null->i_flags |= BLOCK_FLAG_CORE_FLUSH;
890 if( !p_dec->fmt_in.b_packetized )
891 p_null->i_flags |= BLOCK_FLAG_CORRUPTED;
892 memset( p_null->p_buffer, 0, p_null->i_buffer );
894 input_DecoderDecode( p_dec, p_null );
897 while( vlc_object_alive( p_dec ) && p_owner->b_flushing )
898 vlc_cond_wait( &p_owner->wait, &p_owner->lock );
901 static void DecoderSignalFlushed( decoder_t *p_dec )
903 decoder_owner_sys_t *p_owner = p_dec->p_owner;
905 vlc_mutex_lock( &p_owner->lock );
907 if( p_owner->b_flushing )
909 p_owner->b_flushing = false;
910 vlc_cond_signal( &p_owner->wait );
913 vlc_mutex_unlock( &p_owner->lock );
916 static void DecoderSignalBuffering( decoder_t *p_dec, bool b_full )
918 decoder_owner_sys_t *p_owner = p_dec->p_owner;
920 vlc_mutex_lock( &p_owner->lock );
922 if( p_owner->b_buffering )
925 p_owner->buffer.b_full = true;
926 vlc_cond_signal( &p_owner->wait );
929 vlc_mutex_unlock( &p_owner->lock );
932 static bool DecoderIsFlushing( decoder_t *p_dec )
934 decoder_owner_sys_t *p_owner = p_dec->p_owner;
937 vlc_mutex_lock( &p_owner->lock );
939 b_flushing = p_owner->b_flushing;
941 vlc_mutex_unlock( &p_owner->lock );
946 static void DecoderWaitUnblock( decoder_t *p_dec, bool *pb_reject )
948 decoder_owner_sys_t *p_owner = p_dec->p_owner;
950 vlc_assert_locked( &p_owner->lock );
952 while( !p_owner->b_flushing )
954 if( p_owner->b_paused )
956 if( p_owner->b_buffering && !p_owner->buffer.b_full )
958 if( p_owner->pause.i_ignore > 0 )
960 p_owner->pause.i_ignore--;
966 if( !p_owner->b_buffering || !p_owner->buffer.b_full )
969 vlc_cond_wait( &p_owner->wait, &p_owner->lock );
973 *pb_reject = p_owner->b_flushing;
976 static void DecoderOutputChangePause( decoder_t *p_dec, bool b_paused, mtime_t i_date )
978 decoder_owner_sys_t *p_owner = p_dec->p_owner;
980 vlc_assert_locked( &p_owner->lock );
982 /* XXX only audio and video output have to be paused.
983 * - for sout it is useless
984 * - for subs, it is done by the vout
986 if( p_dec->fmt_in.i_cat == AUDIO_ES )
988 if( p_owner->p_aout && p_owner->p_aout_input )
989 aout_DecChangePause( p_owner->p_aout, p_owner->p_aout_input,
992 else if( p_dec->fmt_in.i_cat == VIDEO_ES )
994 if( p_owner->p_vout )
995 vout_ChangePause( p_owner->p_vout, b_paused, i_date );
998 static inline void DecoderUpdatePreroll( int64_t *pi_preroll, const block_t *p )
1000 if( p->i_flags & (BLOCK_FLAG_PREROLL|BLOCK_FLAG_DISCONTINUITY) )
1001 *pi_preroll = INT64_MAX;
1002 else if( p->i_pts > 0 )
1003 *pi_preroll = __MIN( *pi_preroll, p->i_pts );
1004 else if( p->i_dts > 0 )
1005 *pi_preroll = __MIN( *pi_preroll, p->i_dts );
1008 static mtime_t DecoderTeletextFixTs( mtime_t i_ts, mtime_t i_ts_delay )
1010 mtime_t current_date = mdate();
1012 /* FIXME I don't really like that, es_out SHOULD do it using the video pts */
1013 if( !i_ts || i_ts > current_date + 10000000 || i_ts < current_date )
1015 /* ETSI EN 300 472 Annex A : do not take into account the PTS
1016 * for teletext streams. */
1017 return current_date + 400000 + i_ts_delay;
1022 static void DecoderFixTs( decoder_t *p_dec, mtime_t *pi_ts0, mtime_t *pi_ts1,
1023 mtime_t *pi_duration, int *pi_rate, mtime_t *pi_delay, bool b_telx )
1025 decoder_owner_sys_t *p_owner = p_dec->p_owner;
1026 input_clock_t *p_clock = p_owner->p_clock;
1029 vlc_assert_locked( &p_owner->lock );
1031 const mtime_t i_ts_delay = p_owner->p_input->i_pts_delay;
1032 const mtime_t i_es_delay = p_owner->i_ts_delay;
1036 const bool b_ephemere = pi_ts1 && *pi_ts0 == *pi_ts1;
1039 *pi_ts0 = input_clock_GetTS( p_clock, &i_rate, i_ts_delay,
1040 *pi_ts0 + i_es_delay );
1041 if( pi_ts1 && *pi_ts1 > 0 )
1042 *pi_ts1 = input_clock_GetTS( p_clock, &i_rate, i_ts_delay,
1043 *pi_ts1 + i_es_delay );
1045 /* Do not create ephemere data because of rounding errors */
1046 if( !b_ephemere && pi_ts1 && *pi_ts0 == *pi_ts1 )
1050 i_rate = input_clock_GetRate( p_clock );
1053 *pi_duration = ( *pi_duration * i_rate +
1054 INPUT_RATE_DEFAULT-1 ) / INPUT_RATE_DEFAULT;
1061 *pi_ts0 = DecoderTeletextFixTs( *pi_ts0, i_ts_delay );
1062 if( pi_ts1 && *pi_ts1 <= 0 )
1068 const int r = i_rate > 0 ? i_rate : INPUT_RATE_DEFAULT;
1069 *pi_delay = i_ts_delay + i_es_delay * r / INPUT_RATE_DEFAULT;
1073 static void DecoderPlayAudio( decoder_t *p_dec, aout_buffer_t *p_audio,
1074 int *pi_played_sum, int *pi_lost_sum )
1076 decoder_owner_sys_t *p_owner = p_dec->p_owner;
1077 aout_instance_t *p_aout = p_owner->p_aout;
1078 aout_input_t *p_aout_input = p_owner->p_aout_input;
1081 if( p_audio->start_date <= 0 )
1083 msg_Warn( p_dec, "non-dated audio buffer received" );
1085 aout_BufferFree( p_audio );
1090 vlc_mutex_lock( &p_owner->lock );
1092 if( p_owner->b_buffering || p_owner->buffer.p_audio )
1094 p_audio->p_next = NULL;
1096 *p_owner->buffer.pp_audio_next = p_audio;
1097 p_owner->buffer.pp_audio_next = &p_audio->p_next;
1099 p_owner->buffer.i_count++;
1100 if( p_owner->buffer.i_count > DECODER_MAX_BUFFERING_COUNT ||
1101 p_audio->start_date - p_owner->buffer.p_audio->start_date > DECODER_MAX_BUFFERING_AUDIO_DURATION )
1103 p_owner->buffer.b_full = true;
1104 vlc_cond_signal( &p_owner->wait );
1110 bool b_has_more = false;
1112 DecoderWaitUnblock( p_dec, &b_reject );
1114 if( p_owner->b_buffering )
1116 vlc_mutex_unlock( &p_owner->lock );
1121 if( p_owner->buffer.p_audio )
1123 p_audio = p_owner->buffer.p_audio;
1125 p_owner->buffer.p_audio = p_audio->p_next;
1126 p_owner->buffer.i_count--;
1128 b_has_more = p_owner->buffer.p_audio != NULL;
1130 p_owner->buffer.pp_audio_next = &p_owner->buffer.p_audio;
1134 int i_rate = INPUT_RATE_DEFAULT;
1137 DecoderFixTs( p_dec, &p_audio->start_date, &p_audio->end_date, NULL,
1138 &i_rate, &i_delay, false );
1140 vlc_mutex_unlock( &p_owner->lock );
1143 const mtime_t i_max_date = mdate() + i_delay + AOUT_MAX_ADVANCE_TIME;
1145 if( !p_aout || !p_aout_input ||
1146 p_audio->start_date <= 0 || p_audio->start_date > i_max_date ||
1147 i_rate < INPUT_RATE_DEFAULT/AOUT_MAX_INPUT_RATE ||
1148 i_rate > INPUT_RATE_DEFAULT*AOUT_MAX_INPUT_RATE )
1151 /* Do not wait against unprotected date */
1152 const mtime_t i_deadline = p_audio->start_date - AOUT_MAX_PREPARE_TIME;
1153 while( !b_reject && i_deadline > mdate() )
1155 vlc_mutex_lock( &p_owner->lock );
1156 if( p_owner->b_flushing || p_dec->b_die )
1159 vlc_mutex_unlock( &p_owner->lock );
1162 vlc_cond_timedwait( &p_owner->wait, &p_owner->lock, i_deadline );
1163 vlc_mutex_unlock( &p_owner->lock );
1168 if( !aout_DecPlay( p_aout, p_aout_input, p_audio, i_rate ) )
1169 *pi_played_sum += 1;
1170 *pi_lost_sum += aout_DecGetResetLost( p_aout, p_aout_input );
1174 if( p_audio->start_date <= 0 )
1176 msg_Warn( p_dec, "non-dated audio buffer received" );
1178 else if( p_audio->start_date > i_max_date )
1180 msg_Warn( p_aout, "received buffer in the future (%"PRId64")",
1181 p_audio->start_date - mdate() );
1184 aout_BufferFree( p_audio );
1190 vlc_mutex_lock( &p_owner->lock );
1191 if( !p_owner->buffer.p_audio )
1193 vlc_mutex_unlock( &p_owner->lock );
1199 static void DecoderDecodeAudio( decoder_t *p_dec, block_t *p_block )
1201 decoder_owner_sys_t *p_owner = p_dec->p_owner;
1202 input_thread_t *p_input = p_owner->p_input;
1203 aout_buffer_t *p_aout_buf;
1208 while( (p_aout_buf = p_dec->pf_decode_audio( p_dec, &p_block )) )
1210 aout_instance_t *p_aout = p_owner->p_aout;
1211 aout_input_t *p_aout_input = p_owner->p_aout_input;
1217 /* It prevent freezing VLC in case of broken decoder */
1218 aout_DecDeleteBuffer( p_aout, p_aout_input, p_aout_buf );
1220 block_Release( p_block );
1225 if( p_aout_buf->start_date < p_owner->i_preroll_end )
1227 aout_DecDeleteBuffer( p_aout, p_aout_input, p_aout_buf );
1231 if( p_owner->i_preroll_end > 0 )
1233 msg_Dbg( p_dec, "End of audio preroll" );
1234 if( p_owner->p_aout && p_owner->p_aout_input )
1235 aout_DecFlush( p_owner->p_aout, p_owner->p_aout_input );
1237 p_owner->i_preroll_end = -1;
1240 DecoderPlayAudio( p_dec, p_aout_buf, &i_played, &i_lost );
1243 /* Update ugly stat */
1244 if( i_decoded > 0 || i_lost > 0 || i_played > 0 )
1246 vlc_mutex_lock( &p_input->p->counters.counters_lock);
1248 stats_UpdateInteger( p_dec, p_input->p->counters.p_lost_abuffers,
1250 stats_UpdateInteger( p_dec, p_input->p->counters.p_played_abuffers,
1252 stats_UpdateInteger( p_dec, p_input->p->counters.p_decoded_audio,
1255 vlc_mutex_unlock( &p_input->p->counters.counters_lock);
1258 static void DecoderGetCc( decoder_t *p_dec, decoder_t *p_dec_cc )
1260 decoder_owner_sys_t *p_owner = p_dec->p_owner;
1266 assert( p_dec_cc->pf_get_cc != NULL );
1268 /* Do not try retreiving CC if not wanted (sout) or cannot be retreived */
1269 if( !p_owner->cc.b_supported )
1272 p_cc = p_dec_cc->pf_get_cc( p_dec_cc, pb_present );
1276 vlc_mutex_lock( &p_owner->lock );
1277 for( i = 0, i_cc_decoder = 0; i < 4; i++ )
1279 p_owner->cc.pb_present[i] |= pb_present[i];
1280 if( p_owner->cc.pp_decoder[i] )
1284 for( i = 0; i < 4; i++ )
1286 if( !p_owner->cc.pp_decoder[i] )
1289 if( i_cc_decoder > 1 )
1290 DecoderProcess( p_owner->cc.pp_decoder[i], block_Duplicate( p_cc ) );
1292 DecoderProcess( p_owner->cc.pp_decoder[i], p_cc );
1295 vlc_mutex_unlock( &p_owner->lock );
1298 static void DecoderPlayVideo( decoder_t *p_dec, picture_t *p_picture,
1299 int *pi_played_sum, int *pi_lost_sum )
1301 decoder_owner_sys_t *p_owner = p_dec->p_owner;
1302 vout_thread_t *p_vout = p_owner->p_vout;
1303 bool b_first_buffered;
1305 if( p_picture->date <= 0 )
1307 msg_Warn( p_vout, "non-dated video buffer received" );
1309 vout_DropPicture( p_vout, p_picture );
1314 vlc_mutex_lock( &p_owner->lock );
1316 if( ( p_owner->b_buffering && !p_owner->buffer.b_first ) || p_owner->buffer.p_picture )
1318 p_picture->p_next = NULL;
1320 *p_owner->buffer.pp_picture_next = p_picture;
1321 p_owner->buffer.pp_picture_next = &p_picture->p_next;
1323 p_owner->buffer.i_count++;
1324 if( p_owner->buffer.i_count > DECODER_MAX_BUFFERING_COUNT ||
1325 p_picture->date - p_owner->buffer.p_picture->date > DECODER_MAX_BUFFERING_VIDEO_DURATION )
1327 p_owner->buffer.b_full = true;
1328 vlc_cond_signal( &p_owner->wait );
1331 b_first_buffered = p_owner->buffer.p_picture != NULL;
1333 for( ;; b_first_buffered = false )
1335 bool b_has_more = false;
1339 DecoderWaitUnblock( p_dec, &b_reject );
1341 if( p_owner->b_buffering && !p_owner->buffer.b_first )
1343 vlc_mutex_unlock( &p_owner->lock );
1346 bool b_buffering_first = p_owner->b_buffering;
1349 if( p_owner->buffer.p_picture )
1351 p_picture = p_owner->buffer.p_picture;
1353 p_owner->buffer.p_picture = p_picture->p_next;
1354 p_owner->buffer.i_count--;
1356 b_has_more = p_owner->buffer.p_picture != NULL;
1358 p_owner->buffer.pp_picture_next = &p_owner->buffer.p_picture;
1362 int i_rate = INPUT_RATE_DEFAULT;
1365 if( b_buffering_first )
1367 assert( p_owner->buffer.b_first );
1368 assert( !p_owner->buffer.i_count );
1369 msg_Dbg( p_dec, "Received first picture" );
1370 p_owner->buffer.b_first = false;
1371 p_picture->b_force = true;
1373 if( p_owner->p_clock )
1374 i_rate = input_clock_GetRate( p_owner->p_clock );
1376 DecoderFixTs( p_dec, &p_picture->date, NULL, NULL,
1377 &i_rate, &i_delay, false );
1379 vlc_mutex_unlock( &p_owner->lock );
1382 const mtime_t i_max_date = mdate() + i_delay + DECODER_BOGUS_VIDEO_DELAY;
1384 if( !p_picture->b_force && ( p_picture->date <= 0 || p_picture->date >= i_max_date ) )
1389 if( i_rate != p_owner->i_last_rate || b_first_buffered )
1391 /* Be sure to not display old picture after our own */
1392 vout_Flush( p_vout, p_picture->date );
1393 p_owner->i_last_rate = i_rate;
1395 vout_DisplayPicture( p_vout, p_picture );
1399 if( p_picture->date <= 0 )
1401 msg_Warn( p_vout, "non-dated video buffer received" );
1405 msg_Warn( p_vout, "early picture skipped (%"PRId64")",
1406 p_picture->date - mdate() );
1409 vout_DropPicture( p_vout, p_picture );
1413 vout_GetResetStatistic( p_vout, &i_tmp_display, &i_tmp_lost );
1415 *pi_played_sum += i_tmp_display;
1416 *pi_lost_sum += i_tmp_lost;
1418 if( !b_has_more || b_buffering_first )
1421 vlc_mutex_lock( &p_owner->lock );
1422 if( !p_owner->buffer.p_picture )
1424 vlc_mutex_unlock( &p_owner->lock );
1430 static void DecoderDecodeVideo( decoder_t *p_dec, block_t *p_block )
1432 decoder_owner_sys_t *p_owner = p_dec->p_owner;
1433 input_thread_t *p_input = p_owner->p_input;
1437 int i_displayed = 0;
1439 while( (p_pic = p_dec->pf_decode_video( p_dec, &p_block )) )
1441 vout_thread_t *p_vout = p_owner->p_vout;
1444 /* It prevent freezing VLC in case of broken decoder */
1445 vout_DropPicture( p_vout, p_pic );
1447 block_Release( p_block );
1453 if( p_pic->date < p_owner->i_preroll_end )
1455 vout_DropPicture( p_vout, p_pic );
1459 if( p_owner->i_preroll_end > 0 )
1461 msg_Dbg( p_dec, "End of video preroll" );
1463 vout_Flush( p_vout, 1 );
1465 p_owner->i_preroll_end = -1;
1468 if( p_dec->pf_get_cc &&
1469 ( !p_owner->p_packetizer || !p_owner->p_packetizer->pf_get_cc ) )
1470 DecoderGetCc( p_dec, p_dec );
1472 DecoderPlayVideo( p_dec, p_pic, &i_displayed, &i_lost );
1474 if( i_decoded > 0 || i_lost > 0 || i_displayed > 0 )
1476 vlc_mutex_lock( &p_input->p->counters.counters_lock );
1478 stats_UpdateInteger( p_dec, p_input->p->counters.p_decoded_video,
1480 stats_UpdateInteger( p_dec, p_input->p->counters.p_lost_pictures,
1483 stats_UpdateInteger( p_dec, p_input->p->counters.p_displayed_pictures,
1486 vlc_mutex_unlock( &p_input->p->counters.counters_lock );
1490 static void DecoderPlaySpu( decoder_t *p_dec, subpicture_t *p_subpic,
1493 decoder_owner_sys_t *p_owner = p_dec->p_owner;
1494 vout_thread_t *p_vout = p_owner->p_spu_vout;
1497 if( p_subpic->i_start <= 0 )
1499 msg_Warn( p_dec, "non-dated spu buffer received" );
1500 subpicture_Delete( p_subpic );
1505 vlc_mutex_lock( &p_owner->lock );
1507 if( p_owner->b_buffering || p_owner->buffer.p_subpic )
1509 p_subpic->p_next = NULL;
1511 *p_owner->buffer.pp_subpic_next = p_subpic;
1512 p_owner->buffer.pp_subpic_next = &p_subpic->p_next;
1514 p_owner->buffer.i_count++;
1515 /* XXX it is important to be full after the first one */
1516 if( p_owner->buffer.i_count > 0 )
1518 p_owner->buffer.b_full = true;
1519 vlc_cond_signal( &p_owner->wait );
1525 bool b_has_more = false;
1527 DecoderWaitUnblock( p_dec, &b_reject );
1529 if( p_owner->b_buffering )
1531 vlc_mutex_unlock( &p_owner->lock );
1536 if( p_owner->buffer.p_subpic )
1538 p_subpic = p_owner->buffer.p_subpic;
1540 p_owner->buffer.p_subpic = p_subpic->p_next;
1541 p_owner->buffer.i_count--;
1543 b_has_more = p_owner->buffer.p_subpic != NULL;
1545 p_owner->buffer.pp_subpic_next = &p_owner->buffer.p_subpic;
1549 DecoderFixTs( p_dec, &p_subpic->i_start, &p_subpic->i_stop, NULL,
1550 NULL, NULL, b_telx );
1552 vlc_mutex_unlock( &p_owner->lock );
1555 spu_DisplaySubpicture( p_vout->p_spu, p_subpic );
1557 subpicture_Delete( p_subpic );
1561 vlc_mutex_lock( &p_owner->lock );
1562 if( !p_owner->buffer.p_subpic )
1564 vlc_mutex_unlock( &p_owner->lock );
1570 static void DecoderPlaySout( decoder_t *p_dec, block_t *p_sout_block,
1573 decoder_owner_sys_t *p_owner = p_dec->p_owner;
1575 assert( p_owner->p_clock );
1576 assert( !p_sout_block->p_next );
1578 vlc_mutex_lock( &p_owner->lock );
1580 if( p_owner->b_buffering || p_owner->buffer.p_block )
1582 block_ChainLastAppend( &p_owner->buffer.pp_block_next, p_sout_block );
1584 p_owner->buffer.i_count++;
1585 /* XXX it is important to be full after the first one */
1586 if( p_owner->buffer.i_count > 0 )
1588 p_owner->buffer.b_full = true;
1589 vlc_cond_signal( &p_owner->wait );
1595 bool b_has_more = false;
1597 DecoderWaitUnblock( p_dec, &b_reject );
1599 if( p_owner->b_buffering )
1601 vlc_mutex_unlock( &p_owner->lock );
1606 if( p_owner->buffer.p_block )
1608 p_sout_block = p_owner->buffer.p_block;
1610 p_owner->buffer.p_block = p_sout_block->p_next;
1611 p_owner->buffer.i_count--;
1613 b_has_more = p_owner->buffer.p_block != NULL;
1615 p_owner->buffer.pp_block_next = &p_owner->buffer.p_block;
1617 p_sout_block->p_next = NULL;
1619 DecoderFixTs( p_dec, &p_sout_block->i_dts, &p_sout_block->i_pts,
1620 &p_sout_block->i_length,
1621 &p_sout_block->i_rate, NULL, b_telx );
1623 vlc_mutex_unlock( &p_owner->lock );
1626 sout_InputSendBuffer( p_owner->p_sout_input, p_sout_block );
1628 block_Release( p_sout_block );
1632 vlc_mutex_lock( &p_owner->lock );
1633 if( !p_owner->buffer.p_block )
1635 vlc_mutex_unlock( &p_owner->lock );
1642 static void DecoderFlushBuffering( decoder_t *p_dec )
1644 decoder_owner_sys_t *p_owner = p_dec->p_owner;
1646 vlc_assert_locked( &p_owner->lock );
1648 while( p_owner->buffer.p_picture )
1650 picture_t *p_picture = p_owner->buffer.p_picture;
1652 p_owner->buffer.p_picture = p_picture->p_next;
1653 p_owner->buffer.i_count--;
1655 if( p_owner->p_vout )
1656 vout_DropPicture( p_owner->p_vout, p_picture );
1658 if( !p_owner->buffer.p_picture )
1659 p_owner->buffer.pp_picture_next = &p_owner->buffer.p_picture;
1661 while( p_owner->buffer.p_audio )
1663 aout_buffer_t *p_audio = p_owner->buffer.p_audio;
1665 p_owner->buffer.p_audio = p_audio->p_next;
1666 p_owner->buffer.i_count--;
1668 aout_BufferFree( p_audio );
1670 if( !p_owner->buffer.p_audio )
1671 p_owner->buffer.pp_audio_next = &p_owner->buffer.p_audio;
1673 while( p_owner->buffer.p_subpic )
1675 subpicture_t *p_subpic = p_owner->buffer.p_subpic;
1677 p_owner->buffer.p_subpic = p_subpic->p_next;
1678 p_owner->buffer.i_count--;
1680 subpicture_Delete( p_subpic );
1682 if( !p_owner->buffer.p_subpic )
1683 p_owner->buffer.pp_subpic_next = &p_owner->buffer.p_subpic;
1685 if( p_owner->buffer.p_block )
1687 block_ChainRelease( p_owner->buffer.p_block );
1689 p_owner->buffer.i_count = 0;
1690 p_owner->buffer.p_block = NULL;
1691 p_owner->buffer.pp_block_next = &p_owner->buffer.p_block;
1695 /* This function process a block for sout
1697 static void DecoderProcessSout( decoder_t *p_dec, block_t *p_block )
1699 decoder_owner_sys_t *p_owner = (decoder_owner_sys_t *)p_dec->p_owner;
1700 const bool b_telx = p_dec->fmt_in.i_codec == VLC_FOURCC('t','e','l','x');
1701 block_t *p_sout_block;
1703 while( ( p_sout_block =
1704 p_dec->pf_packetize( p_dec, p_block ? &p_block : NULL ) ) )
1706 if( !p_owner->p_sout_input )
1708 es_format_Copy( &p_owner->sout, &p_dec->fmt_out );
1710 p_owner->sout.i_group = p_dec->fmt_in.i_group;
1711 p_owner->sout.i_id = p_dec->fmt_in.i_id;
1712 if( p_dec->fmt_in.psz_language )
1714 if( p_owner->sout.psz_language )
1715 free( p_owner->sout.psz_language );
1716 p_owner->sout.psz_language =
1717 strdup( p_dec->fmt_in.psz_language );
1720 p_owner->p_sout_input =
1721 sout_InputNew( p_owner->p_sout,
1724 if( p_owner->p_sout_input == NULL )
1726 msg_Err( p_dec, "cannot create packetizer output (%4.4s)",
1727 (char *)&p_owner->sout.i_codec );
1728 p_dec->b_error = true;
1730 while( p_sout_block )
1732 block_t *p_next = p_sout_block->p_next;
1733 block_Release( p_sout_block );
1734 p_sout_block = p_next;
1740 while( p_sout_block )
1742 block_t *p_next = p_sout_block->p_next;
1744 p_sout_block->p_next = NULL;
1746 DecoderPlaySout( p_dec, p_sout_block, b_telx );
1748 p_sout_block = p_next;
1751 /* For now it's enough, as only sout impact on this flag */
1752 if( p_owner->p_sout->i_out_pace_nocontrol > 0 &&
1753 p_owner->p_input->p->b_out_pace_control )
1755 msg_Dbg( p_dec, "switching to sync mode" );
1756 p_owner->p_input->p->b_out_pace_control = false;
1758 else if( p_owner->p_sout->i_out_pace_nocontrol <= 0 &&
1759 !p_owner->p_input->p->b_out_pace_control )
1761 msg_Dbg( p_dec, "switching to async mode" );
1762 p_owner->p_input->p->b_out_pace_control = true;
1767 /* This function process a video block
1769 static void DecoderProcessVideo( decoder_t *p_dec, block_t *p_block, bool b_flush )
1771 decoder_owner_sys_t *p_owner = (decoder_owner_sys_t *)p_dec->p_owner;
1773 if( p_owner->p_packetizer )
1775 block_t *p_packetized_block;
1776 decoder_t *p_packetizer = p_owner->p_packetizer;
1778 while( (p_packetized_block =
1779 p_packetizer->pf_packetize( p_packetizer, p_block ? &p_block : NULL )) )
1781 if( p_packetizer->fmt_out.i_extra && !p_dec->fmt_in.i_extra )
1783 es_format_Clean( &p_dec->fmt_in );
1784 es_format_Copy( &p_dec->fmt_in, &p_packetizer->fmt_out );
1786 if( p_packetizer->pf_get_cc )
1787 DecoderGetCc( p_dec, p_packetizer );
1789 while( p_packetized_block )
1791 block_t *p_next = p_packetized_block->p_next;
1792 p_packetized_block->p_next = NULL;
1794 DecoderDecodeVideo( p_dec, p_packetized_block );
1796 p_packetized_block = p_next;
1802 DecoderDecodeVideo( p_dec, p_block );
1805 if( b_flush && p_owner->p_vout )
1806 vout_Flush( p_owner->p_vout, 1 );
1809 /* This function process a audio block
1811 static void DecoderProcessAudio( decoder_t *p_dec, block_t *p_block, bool b_flush )
1813 decoder_owner_sys_t *p_owner = (decoder_owner_sys_t *)p_dec->p_owner;
1815 if( p_owner->p_packetizer )
1817 block_t *p_packetized_block;
1818 decoder_t *p_packetizer = p_owner->p_packetizer;
1820 while( (p_packetized_block =
1821 p_packetizer->pf_packetize( p_packetizer, p_block ? &p_block : NULL )) )
1823 if( p_packetizer->fmt_out.i_extra && !p_dec->fmt_in.i_extra )
1825 es_format_Clean( &p_dec->fmt_in );
1826 es_format_Copy( &p_dec->fmt_in, &p_packetizer->fmt_out );
1829 while( p_packetized_block )
1831 block_t *p_next = p_packetized_block->p_next;
1832 p_packetized_block->p_next = NULL;
1834 DecoderDecodeAudio( p_dec, p_packetized_block );
1836 p_packetized_block = p_next;
1842 DecoderDecodeAudio( p_dec, p_block );
1845 if( b_flush && p_owner->p_aout && p_owner->p_aout_input )
1846 aout_DecFlush( p_owner->p_aout, p_owner->p_aout_input );
1849 /* This function process a subtitle block
1851 static void DecoderProcessSpu( decoder_t *p_dec, block_t *p_block, bool b_flush )
1853 decoder_owner_sys_t *p_owner = p_dec->p_owner;
1854 const bool b_telx = p_dec->fmt_in.i_codec == VLC_FOURCC('t','e','l','x');
1856 input_thread_t *p_input = p_owner->p_input;
1857 vout_thread_t *p_vout;
1858 subpicture_t *p_spu;
1860 while( (p_spu = p_dec->pf_decode_sub( p_dec, p_block ? &p_block : NULL ) ) )
1862 vlc_mutex_lock( &p_input->p->counters.counters_lock );
1863 stats_UpdateInteger( p_dec, p_input->p->counters.p_decoded_sub, 1, NULL );
1864 vlc_mutex_unlock( &p_input->p->counters.counters_lock );
1866 p_vout = vlc_object_find( p_dec, VLC_OBJECT_VOUT, FIND_ANYWHERE );
1867 if( p_vout && p_owner->p_spu_vout == p_vout )
1869 /* Preroll does not work very well with subtitle */
1870 if( p_spu->i_start > 0 &&
1871 p_spu->i_start < p_owner->i_preroll_end &&
1872 ( p_spu->i_stop <= 0 || p_spu->i_stop < p_owner->i_preroll_end ) )
1874 subpicture_Delete( p_spu );
1878 DecoderPlaySpu( p_dec, p_spu, b_telx );
1883 subpicture_Delete( p_spu );
1886 vlc_object_release( p_vout );
1889 if( b_flush && p_owner->p_spu_vout )
1891 p_vout = vlc_object_find( p_dec, VLC_OBJECT_VOUT, FIND_ANYWHERE );
1893 if( p_vout && p_owner->p_spu_vout == p_vout )
1894 spu_Control( p_vout->p_spu, SPU_CHANNEL_CLEAR,
1895 p_owner->i_spu_channel );
1898 vlc_object_release( p_vout );
1903 static void DecoderProcessOnFlush( decoder_t *p_dec )
1905 decoder_owner_sys_t *p_owner = p_dec->p_owner;
1907 vlc_mutex_lock( &p_owner->lock );
1908 DecoderFlushBuffering( p_dec );
1909 vlc_mutex_unlock( &p_owner->lock );
1911 DecoderSignalFlushed( p_dec );
1916 * \param p_dec the decoder object
1917 * \param p_block the block to decode
1918 * \return VLC_SUCCESS or an error code
1920 static void DecoderProcess( decoder_t *p_dec, block_t *p_block )
1922 decoder_owner_sys_t *p_owner = (decoder_owner_sys_t *)p_dec->p_owner;
1923 const bool b_flush_request = p_block && (p_block->i_flags & BLOCK_FLAG_CORE_FLUSH);
1925 if( p_block && p_block->i_buffer <= 0 )
1927 assert( !b_flush_request );
1928 block_Release( p_block );
1933 if( p_dec->i_object_type == VLC_OBJECT_PACKETIZER )
1936 p_block->i_flags &= ~BLOCK_FLAG_CORE_PRIVATE_MASK;
1938 DecoderProcessSout( p_dec, p_block );
1943 bool b_flush = false;
1947 const bool b_flushing = p_owner->i_preroll_end == INT64_MAX;
1948 DecoderUpdatePreroll( &p_owner->i_preroll_end, p_block );
1950 b_flush = !b_flushing && b_flush_request;
1952 p_block->i_flags &= ~BLOCK_FLAG_CORE_PRIVATE_MASK;
1955 if( p_dec->fmt_in.i_cat == AUDIO_ES )
1957 DecoderProcessAudio( p_dec, p_block, b_flush );
1959 else if( p_dec->fmt_in.i_cat == VIDEO_ES )
1961 DecoderProcessVideo( p_dec, p_block, b_flush );
1963 else if( p_dec->fmt_in.i_cat == SPU_ES )
1965 DecoderProcessSpu( p_dec, p_block, b_flush );
1969 msg_Err( p_dec, "unknown ES format" );
1970 p_dec->b_error = true;
1975 if( b_flush_request )
1976 DecoderProcessOnFlush( p_dec );
1979 static void DecoderError( decoder_t *p_dec, block_t *p_block )
1981 const bool b_flush_request = p_block && (p_block->i_flags & BLOCK_FLAG_CORE_FLUSH);
1985 block_Release( p_block );
1987 if( b_flush_request )
1988 DecoderProcessOnFlush( p_dec );
1993 * Destroys a decoder object
1995 * \param p_dec the decoder object
1998 static void DeleteDecoder( decoder_t * p_dec )
2000 decoder_owner_sys_t *p_owner = p_dec->p_owner;
2002 msg_Dbg( p_dec, "killing decoder fourcc `%4.4s', %u PES in FIFO",
2003 (char*)&p_dec->fmt_in.i_codec,
2004 (unsigned)block_FifoCount( p_owner->p_fifo ) );
2006 /* Free all packets still in the decoder fifo. */
2007 block_FifoEmpty( p_owner->p_fifo );
2008 block_FifoRelease( p_owner->p_fifo );
2011 vlc_mutex_lock( &p_owner->lock );
2012 DecoderFlushBuffering( p_dec );
2013 vlc_mutex_unlock( &p_owner->lock );
2016 if( p_owner->p_aout_input )
2017 aout_DecDelete( p_owner->p_aout, p_owner->p_aout_input );
2018 if( p_owner->p_aout )
2020 vlc_object_release( p_owner->p_aout );
2021 p_owner->p_aout = NULL;
2023 if( p_owner->p_vout )
2025 /* Hack to make sure all the the pictures are freed by the decoder */
2026 vout_FixLeaks( p_owner->p_vout, true );
2028 /* We are about to die. Reattach video output to p_vlc. */
2029 vout_Request( p_dec, p_owner->p_vout, NULL );
2030 input_SendEventVout( p_owner->p_input );
2034 if( p_owner->p_sout_input )
2036 sout_InputDelete( p_owner->p_sout_input );
2037 es_format_Clean( &p_owner->sout );
2041 if( p_dec->fmt_in.i_cat == SPU_ES )
2043 vout_thread_t *p_vout;
2045 p_vout = vlc_object_find( p_dec, VLC_OBJECT_VOUT, FIND_ANYWHERE );
2048 if( p_owner->p_spu_vout == p_vout )
2049 spu_Control( p_vout->p_spu, SPU_CHANNEL_CLEAR, p_owner->i_spu_channel );
2050 vlc_object_release( p_vout );
2054 es_format_Clean( &p_dec->fmt_in );
2055 es_format_Clean( &p_dec->fmt_out );
2057 if( p_owner->p_packetizer )
2059 module_unneed( p_owner->p_packetizer,
2060 p_owner->p_packetizer->p_module );
2061 es_format_Clean( &p_owner->p_packetizer->fmt_in );
2062 es_format_Clean( &p_owner->p_packetizer->fmt_out );
2063 vlc_object_detach( p_owner->p_packetizer );
2064 vlc_object_release( p_owner->p_packetizer );
2067 es_format_Clean( &p_owner->fmt_description );
2069 vlc_cond_destroy( &p_owner->wait );
2070 vlc_mutex_destroy( &p_owner->lock );
2072 vlc_object_detach( p_dec );
2077 /*****************************************************************************
2078 * Buffers allocation callbacks for the decoders
2079 *****************************************************************************/
2080 static void DecoderUpdateFormatLocked( decoder_t *p_dec )
2082 decoder_owner_sys_t *p_owner = p_dec->p_owner;
2084 vlc_assert_locked( &p_owner->lock );
2086 es_format_Clean( &p_owner->fmt_description );
2088 p_owner->b_fmt_description = true;
2089 es_format_Copy( &p_owner->fmt_description, &p_dec->fmt_out );
2091 static vout_thread_t *aout_request_vout( void *p_private,
2092 vout_thread_t *p_vout, video_format_t *p_fmt )
2094 decoder_t *p_dec = p_private;
2096 p_vout = vout_Request( p_dec, p_vout, p_fmt );
2097 input_SendEventVout( p_dec->p_owner->p_input );
2102 static aout_buffer_t *aout_new_buffer( decoder_t *p_dec, int i_samples )
2104 decoder_owner_sys_t *p_owner = p_dec->p_owner;
2105 aout_buffer_t *p_buffer;
2107 if( p_owner->p_aout_input != NULL &&
2108 ( p_dec->fmt_out.audio.i_rate != p_owner->audio.i_rate ||
2109 p_dec->fmt_out.audio.i_original_channels !=
2110 p_owner->audio.i_original_channels ||
2111 p_dec->fmt_out.audio.i_bytes_per_frame !=
2112 p_owner->audio.i_bytes_per_frame ) )
2114 aout_input_t *p_aout_input = p_owner->p_aout_input;
2116 /* Parameters changed, restart the aout */
2117 vlc_mutex_lock( &p_owner->lock );
2119 DecoderFlushBuffering( p_dec );
2121 p_owner->p_aout_input = NULL;
2122 aout_DecDelete( p_owner->p_aout, p_aout_input );
2124 vlc_mutex_unlock( &p_owner->lock );
2127 if( p_owner->p_aout_input == NULL )
2129 const int i_force_dolby = config_GetInt( p_dec, "force-dolby-surround" );
2130 audio_sample_format_t format;
2131 aout_input_t *p_aout_input;
2132 aout_instance_t *p_aout;
2133 aout_request_vout_t request_vout;
2135 p_dec->fmt_out.audio.i_format = p_dec->fmt_out.i_codec;
2136 p_owner->audio = p_dec->fmt_out.audio;
2138 memcpy( &format, &p_owner->audio, sizeof( audio_sample_format_t ) );
2139 if( i_force_dolby &&
2140 (format.i_original_channels&AOUT_CHAN_PHYSMASK) ==
2141 (AOUT_CHAN_LEFT|AOUT_CHAN_RIGHT) )
2143 if( i_force_dolby == 1 )
2145 format.i_original_channels = format.i_original_channels |
2146 AOUT_CHAN_DOLBYSTEREO;
2148 else /* i_force_dolby == 2 */
2150 format.i_original_channels = format.i_original_channels &
2151 ~AOUT_CHAN_DOLBYSTEREO;
2155 request_vout.pf_request_vout = aout_request_vout;
2156 request_vout.p_private = p_dec;
2158 p_aout = p_owner->p_aout;
2159 p_aout_input = aout_DecNew( p_dec, &p_aout,
2160 &format, &p_dec->fmt_out.audio_replay_gain, &request_vout );
2162 vlc_mutex_lock( &p_owner->lock );
2164 p_owner->p_aout = p_aout;
2165 p_owner->p_aout_input = p_aout_input;
2166 DecoderUpdateFormatLocked( p_dec );
2168 vlc_mutex_unlock( &p_owner->lock );
2170 if( p_owner->p_aout_input == NULL )
2172 msg_Err( p_dec, "failed to create audio output" );
2173 p_dec->b_error = true;
2176 p_dec->fmt_out.audio.i_bytes_per_frame =
2177 p_owner->audio.i_bytes_per_frame;
2180 p_buffer = aout_DecNewBuffer( p_owner->p_aout_input, i_samples );
2185 static void aout_del_buffer( decoder_t *p_dec, aout_buffer_t *p_buffer )
2187 decoder_owner_sys_t *p_owner = p_dec->p_owner;
2189 aout_DecDeleteBuffer( p_owner->p_aout,
2190 p_owner->p_aout_input, p_buffer );
2194 int vout_CountPictureAvailable( vout_thread_t *p_vout );
2196 static picture_t *vout_new_buffer( decoder_t *p_dec )
2198 decoder_owner_sys_t *p_owner = p_dec->p_owner;
2200 if( p_owner->p_vout == NULL ||
2201 p_dec->fmt_out.video.i_width != p_owner->video.i_width ||
2202 p_dec->fmt_out.video.i_height != p_owner->video.i_height ||
2203 p_dec->fmt_out.video.i_chroma != p_owner->video.i_chroma ||
2204 p_dec->fmt_out.video.i_aspect != p_owner->video.i_aspect )
2206 vout_thread_t *p_vout;
2208 if( !p_dec->fmt_out.video.i_width ||
2209 !p_dec->fmt_out.video.i_height )
2211 /* Can't create a new vout without display size */
2215 if( !p_dec->fmt_out.video.i_visible_width ||
2216 !p_dec->fmt_out.video.i_visible_height )
2218 if( p_dec->fmt_in.video.i_visible_width &&
2219 p_dec->fmt_in.video.i_visible_height )
2221 p_dec->fmt_out.video.i_visible_width =
2222 p_dec->fmt_in.video.i_visible_width;
2223 p_dec->fmt_out.video.i_visible_height =
2224 p_dec->fmt_in.video.i_visible_height;
2228 p_dec->fmt_out.video.i_visible_width =
2229 p_dec->fmt_out.video.i_width;
2230 p_dec->fmt_out.video.i_visible_height =
2231 p_dec->fmt_out.video.i_height;
2235 if( p_dec->fmt_out.video.i_visible_height == 1088 &&
2236 var_CreateGetBool( p_dec, "hdtv-fix" ) )
2238 p_dec->fmt_out.video.i_visible_height = 1080;
2239 p_dec->fmt_out.video.i_sar_num *= 135;
2240 p_dec->fmt_out.video.i_sar_den *= 136;
2241 msg_Warn( p_dec, "Fixing broken HDTV stream (display_height=1088)");
2244 if( !p_dec->fmt_out.video.i_sar_num ||
2245 !p_dec->fmt_out.video.i_sar_den )
2247 p_dec->fmt_out.video.i_sar_num = p_dec->fmt_out.video.i_aspect *
2248 p_dec->fmt_out.video.i_visible_height;
2250 p_dec->fmt_out.video.i_sar_den = VOUT_ASPECT_FACTOR *
2251 p_dec->fmt_out.video.i_visible_width;
2254 vlc_ureduce( &p_dec->fmt_out.video.i_sar_num,
2255 &p_dec->fmt_out.video.i_sar_den,
2256 p_dec->fmt_out.video.i_sar_num,
2257 p_dec->fmt_out.video.i_sar_den, 50000 );
2259 p_dec->fmt_out.video.i_chroma = p_dec->fmt_out.i_codec;
2260 p_owner->video = p_dec->fmt_out.video;
2262 vlc_mutex_lock( &p_owner->lock );
2264 DecoderFlushBuffering( p_dec );
2266 p_vout = p_owner->p_vout;
2267 p_owner->p_vout = NULL;
2268 vlc_mutex_unlock( &p_owner->lock );
2270 p_vout = vout_Request( p_dec, p_vout, &p_dec->fmt_out.video );
2272 vlc_mutex_lock( &p_owner->lock );
2273 p_owner->p_vout = p_vout;
2275 DecoderUpdateFormatLocked( p_dec );
2277 vlc_mutex_unlock( &p_owner->lock );
2279 input_SendEventVout( p_owner->p_input );
2280 if( p_vout == NULL )
2282 msg_Err( p_dec, "failed to create video output" );
2283 p_dec->b_error = true;
2287 if( p_owner->video.i_rmask )
2288 p_owner->p_vout->render.i_rmask = p_owner->video.i_rmask;
2289 if( p_owner->video.i_gmask )
2290 p_owner->p_vout->render.i_gmask = p_owner->video.i_gmask;
2291 if( p_owner->video.i_bmask )
2292 p_owner->p_vout->render.i_bmask = p_owner->video.i_bmask;
2295 /* Get a new picture
2299 picture_t *p_picture;
2301 if( p_dec->b_die || p_dec->b_error )
2304 /* The video filter chain required that there is always 1 free buffer
2305 * that it will use as temporary one. It will release the temporary
2306 * buffer once its work is done, so this check is safe even if we don't
2307 * lock around both count() and create().
2309 if( vout_CountPictureAvailable( p_owner->p_vout ) >= 2 )
2311 p_picture = vout_CreatePicture( p_owner->p_vout, 0, 0, 0 );
2316 if( DecoderIsFlushing( p_dec ) )
2320 DecoderSignalBuffering( p_dec, true );
2322 /* Check the decoder doesn't leak pictures */
2323 vout_FixLeaks( p_owner->p_vout, false );
2325 /* FIXME add a vout_WaitPictureAvailable (timedwait) */
2326 msleep( VOUT_OUTMEM_SLEEP );
2330 static void vout_del_buffer( decoder_t *p_dec, picture_t *p_pic )
2332 vout_DropPicture( p_dec->p_owner->p_vout, p_pic );
2335 static void vout_link_picture( decoder_t *p_dec, picture_t *p_pic )
2337 vout_LinkPicture( p_dec->p_owner->p_vout, p_pic );
2340 static void vout_unlink_picture( decoder_t *p_dec, picture_t *p_pic )
2342 vout_UnlinkPicture( p_dec->p_owner->p_vout, p_pic );
2345 static subpicture_t *spu_new_buffer( decoder_t *p_dec )
2347 decoder_owner_sys_t *p_owner = p_dec->p_owner;
2348 vout_thread_t *p_vout = NULL;
2349 subpicture_t *p_subpic;
2350 int i_attempts = 30;
2352 while( i_attempts-- )
2354 if( p_dec->b_die || p_dec->b_error )
2357 p_vout = vlc_object_find( p_dec, VLC_OBJECT_VOUT, FIND_ANYWHERE );
2361 msleep( DECODER_SPU_VOUT_WAIT_DURATION );
2366 msg_Warn( p_dec, "no vout found, dropping subpicture" );
2370 if( p_owner->p_spu_vout != p_vout )
2372 vlc_mutex_lock( &p_owner->lock );
2374 DecoderFlushBuffering( p_dec );
2376 vlc_mutex_unlock( &p_owner->lock );
2378 spu_Control( p_vout->p_spu, SPU_CHANNEL_REGISTER,
2379 &p_owner->i_spu_channel );
2380 p_owner->i_spu_order = 0;
2381 p_owner->p_spu_vout = p_vout;
2384 p_subpic = subpicture_New();
2387 p_subpic->i_channel = p_owner->i_spu_channel;
2388 p_subpic->i_order = p_owner->i_spu_order++;
2389 p_subpic->b_subtitle = true;
2392 vlc_object_release( p_vout );
2397 static void spu_del_buffer( decoder_t *p_dec, subpicture_t *p_subpic )
2399 decoder_owner_sys_t *p_owner = p_dec->p_owner;
2400 vout_thread_t *p_vout = NULL;
2402 p_vout = vlc_object_find( p_dec, VLC_OBJECT_VOUT, FIND_ANYWHERE );
2403 if( !p_vout || p_owner->p_spu_vout != p_vout )
2406 vlc_object_release( p_vout );
2407 msg_Warn( p_dec, "no vout found, leaking subpicture" );
2411 subpicture_Delete( p_subpic );
2413 vlc_object_release( p_vout );