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>
44 #include <vlc_interface.h>
45 #include "audio_output/aout_internal.h"
46 #include "stream_output/stream_output.h"
47 #include "input_internal.h"
51 #include "ressource.h"
53 #include "../video_output/vout_control.h"
55 static decoder_t *CreateDecoder( input_thread_t *, es_format_t *, int, sout_instance_t *p_sout );
56 static void DeleteDecoder( decoder_t * );
58 static void *DecoderThread( vlc_object_t * );
59 static void DecoderProcess( decoder_t *, block_t * );
60 static void DecoderError( decoder_t *p_dec, block_t *p_block );
61 static void DecoderOutputChangePause( decoder_t *, bool b_paused, mtime_t i_date );
62 static void DecoderFlush( decoder_t * );
63 static void DecoderSignalBuffering( decoder_t *, bool );
64 static void DecoderFlushBuffering( decoder_t * );
66 static void DecoderUnsupportedCodec( decoder_t *, vlc_fourcc_t );
68 /* Buffers allocation callbacks for the decoders */
69 static aout_buffer_t *aout_new_buffer( decoder_t *, int );
70 static void aout_del_buffer( decoder_t *, aout_buffer_t * );
72 static picture_t *vout_new_buffer( decoder_t * );
73 static void vout_del_buffer( decoder_t *, picture_t * );
74 static void vout_link_picture( decoder_t *, picture_t * );
75 static void vout_unlink_picture( decoder_t *, picture_t * );
77 static subpicture_t *spu_new_buffer( decoder_t * );
78 static void spu_del_buffer( decoder_t *, subpicture_t * );
80 static es_format_t null_es_format;
82 struct decoder_owner_sys_t
84 int64_t i_preroll_end;
86 input_thread_t *p_input;
87 input_clock_t *p_clock;
90 vout_thread_t *p_spu_vout;
94 sout_instance_t *p_sout;
95 sout_packetizer_input_t *p_sout_input;
97 /* Some decoders require already packetized data (ie. not truncated) */
98 decoder_t *p_packetizer;
100 /* Current format in use by the output */
101 video_format_t video;
102 audio_format_t audio;
106 bool b_fmt_description;
107 es_format_t fmt_description;
108 vlc_meta_t *p_description;
111 block_fifo_t *p_fifo;
113 /* Lock for communication with decoder thread */
117 /* -- These variables need locking on write(only) -- */
118 aout_instance_t *p_aout;
119 aout_input_t *p_aout_input;
121 vout_thread_t *p_vout;
123 /* -- Theses variables need locking on read *and* write -- */
141 picture_t *p_picture;
142 picture_t **pp_picture_next;
144 subpicture_t *p_subpic;
145 subpicture_t **pp_subpic_next;
147 aout_buffer_t *p_audio;
148 aout_buffer_t **pp_audio_next;
151 block_t **pp_block_next;
162 decoder_t *pp_decoder[4];
169 #define DECODER_MAX_BUFFERING_COUNT (4)
170 #define DECODER_MAX_BUFFERING_AUDIO_DURATION (AOUT_MAX_PREPARE_TIME)
171 #define DECODER_MAX_BUFFERING_VIDEO_DURATION (1*CLOCK_FREQ)
173 /* Pictures which are DECODER_BOGUS_VIDEO_DELAY or more in advance probably have
174 * a bogus PTS and won't be displayed */
175 #define DECODER_BOGUS_VIDEO_DELAY ((mtime_t)(DEFAULT_PTS_DELAY * 30))
178 #define DECODER_SPU_VOUT_WAIT_DURATION ((int)(0.200*CLOCK_FREQ))
181 /*****************************************************************************
183 *****************************************************************************/
184 picture_t *decoder_NewPicture( decoder_t *p_decoder )
186 picture_t *p_picture = p_decoder->pf_vout_buffer_new( p_decoder );
188 msg_Warn( p_decoder, "can't get output picture" );
191 void decoder_DeletePicture( decoder_t *p_decoder, picture_t *p_picture )
193 p_decoder->pf_vout_buffer_del( p_decoder, p_picture );
195 void decoder_LinkPicture( decoder_t *p_decoder, picture_t *p_picture )
197 p_decoder->pf_picture_link( p_decoder, p_picture );
199 void decoder_UnlinkPicture( decoder_t *p_decoder, picture_t *p_picture )
201 p_decoder->pf_picture_unlink( p_decoder, p_picture );
204 aout_buffer_t *decoder_NewAudioBuffer( decoder_t *p_decoder, int i_size )
206 if( !p_decoder->pf_aout_buffer_new )
208 return p_decoder->pf_aout_buffer_new( p_decoder, i_size );
210 void decoder_DeleteAudioBuffer( decoder_t *p_decoder, aout_buffer_t *p_buffer )
212 p_decoder->pf_aout_buffer_del( p_decoder, p_buffer );
215 subpicture_t *decoder_NewSubpicture( decoder_t *p_decoder )
217 subpicture_t *p_subpicture = p_decoder->pf_spu_buffer_new( p_decoder );
219 msg_Warn( p_decoder, "can't get output subpicture" );
222 void decoder_DeleteSubpicture( decoder_t *p_decoder, subpicture_t *p_subpicture )
224 p_decoder->pf_spu_buffer_del( p_decoder, p_subpicture );
227 /* decoder_GetInputAttachments:
229 int decoder_GetInputAttachments( decoder_t *p_dec,
230 input_attachment_t ***ppp_attachment,
233 if( !p_dec->pf_get_attachments )
236 return p_dec->pf_get_attachments( p_dec, ppp_attachment, pi_attachment );
238 /* decoder_GetDisplayDate:
240 mtime_t decoder_GetDisplayDate( decoder_t *p_dec, mtime_t i_ts )
242 if( !p_dec->pf_get_display_date )
245 return p_dec->pf_get_display_date( p_dec, i_ts );
247 /* decoder_GetDisplayRate:
249 int decoder_GetDisplayRate( decoder_t *p_dec )
251 if( !p_dec->pf_get_display_rate )
252 return INPUT_RATE_DEFAULT;
254 return p_dec->pf_get_display_rate( p_dec );
258 * Spawns a new decoder thread
260 * \param p_input the input thread
261 * \param p_es the es descriptor
262 * \return the spawned decoder object
264 decoder_t *input_DecoderNew( input_thread_t *p_input,
265 es_format_t *fmt, input_clock_t *p_clock, sout_instance_t *p_sout )
267 decoder_t *p_dec = NULL;
271 /* If we are in sout mode, search for packetizer module */
274 /* Create the decoder configuration structure */
275 p_dec = CreateDecoder( p_input, fmt, VLC_OBJECT_PACKETIZER, p_sout );
278 msg_Err( p_input, "could not create packetizer" );
279 intf_UserFatal( p_input, false, _("Streaming / Transcoding failed"),
280 _("VLC could not open the packetizer module.") );
287 /* Create the decoder configuration structure */
288 p_dec = CreateDecoder( p_input, fmt, VLC_OBJECT_DECODER, p_sout );
291 msg_Err( p_input, "could not create decoder" );
292 intf_UserFatal( p_input, false, _("Streaming / Transcoding failed"),
293 _("VLC could not open the decoder module.") );
298 if( !p_dec->p_module )
300 DecoderUnsupportedCodec( p_dec, fmt->i_codec );
302 DeleteDecoder( p_dec );
303 vlc_object_release( p_dec );
307 p_dec->p_owner->p_clock = p_clock;
309 if( fmt->i_cat == AUDIO_ES )
310 i_priority = VLC_THREAD_PRIORITY_AUDIO;
312 i_priority = VLC_THREAD_PRIORITY_VIDEO;
314 /* Spawn the decoder thread */
315 if( vlc_thread_create( p_dec, "decoder", DecoderThread, i_priority ) )
317 msg_Err( p_dec, "cannot spawn decoder thread" );
318 module_unneed( p_dec, p_dec->p_module );
319 DeleteDecoder( p_dec );
320 vlc_object_release( p_dec );
328 * Kills a decoder thread and waits until it's finished
330 * \param p_input the input thread
331 * \param p_es the es descriptor
334 void input_DecoderDelete( decoder_t *p_dec )
336 decoder_owner_sys_t *p_owner = p_dec->p_owner;
338 vlc_object_kill( p_dec );
340 /* Make sure we aren't paused/buffering/waiting anymore */
341 vlc_mutex_lock( &p_owner->lock );
342 p_owner->b_paused = false;
343 p_owner->b_buffering = false;
344 p_owner->b_flushing = true;
345 vlc_cond_signal( &p_owner->wait );
346 vlc_mutex_unlock( &p_owner->lock );
348 vlc_thread_join( p_dec );
349 module_unneed( p_dec, p_dec->p_module );
352 if( p_dec->p_owner->cc.b_supported )
355 for( i = 0; i < 4; i++ )
356 input_DecoderSetCcState( p_dec, false, i );
359 /* Delete decoder configuration */
360 DeleteDecoder( p_dec );
362 /* Delete the decoder */
363 vlc_object_release( p_dec );
367 * Put a block_t in the decoder's fifo.
368 * Thread-safe w.r.t. the decoder. May be a cancellation point.
370 * \param p_dec the decoder object
371 * \param p_block the data block
373 void input_DecoderDecode( decoder_t *p_dec, block_t *p_block )
375 decoder_owner_sys_t *p_owner = p_dec->p_owner;
377 if( p_owner->p_input->p->b_out_pace_control )
379 /* The fifo is not consummed when buffering and so will
381 * There is no need to lock as b_buffering is never modify
382 * inside decoder thread. */
383 if( !p_owner->b_buffering )
384 block_FifoPace( p_owner->p_fifo, 10, SIZE_MAX );
386 else if( block_FifoSize( p_owner->p_fifo ) > 50000000 /* 50 MB */ )
388 /* FIXME: ideally we would check the time amount of data
389 * in the FIFO instead of its size. */
390 msg_Warn( p_dec, "decoder/packetizer fifo full (data not "
391 "consumed quickly enough), resetting fifo!" );
392 block_FifoEmpty( p_owner->p_fifo );
395 block_FifoPut( p_owner->p_fifo, p_block );
398 bool input_DecoderIsEmpty( decoder_t * p_dec )
400 assert( !p_dec->p_owner->b_buffering );
402 /* FIXME that's not really true */
403 return block_FifoCount( p_dec->p_owner->p_fifo ) <= 0;
406 void input_DecoderIsCcPresent( decoder_t *p_dec, bool pb_present[4] )
408 decoder_owner_sys_t *p_owner = p_dec->p_owner;
411 vlc_mutex_lock( &p_owner->lock );
412 for( i = 0; i < 4; i++ )
413 pb_present[i] = p_owner->cc.pb_present[i];
414 vlc_mutex_unlock( &p_owner->lock );
416 int input_DecoderSetCcState( decoder_t *p_dec, bool b_decode, int i_channel )
418 decoder_owner_sys_t *p_owner = p_dec->p_owner;
420 //msg_Warn( p_dec, "input_DecoderSetCcState: %d @%d", b_decode, i_channel );
422 if( i_channel < 0 || i_channel >= 4 || !p_owner->cc.pb_present[i_channel] )
427 static const vlc_fourcc_t fcc[4] = {
428 VLC_FOURCC('c', 'c', '1', ' '),
429 VLC_FOURCC('c', 'c', '2', ' '),
430 VLC_FOURCC('c', 'c', '3', ' '),
431 VLC_FOURCC('c', 'c', '4', ' '),
436 es_format_Init( &fmt, SPU_ES, fcc[i_channel] );
437 p_cc = CreateDecoder( p_owner->p_input, &fmt, VLC_OBJECT_DECODER, p_owner->p_sout );
440 msg_Err( p_dec, "could not create decoder" );
441 intf_UserFatal( p_dec, false, _("Streaming / Transcoding failed"),
442 _("VLC could not open the decoder module.") );
445 else if( !p_cc->p_module )
447 DecoderUnsupportedCodec( p_dec, fcc[i_channel] );
448 DeleteDecoder( p_cc );
449 vlc_object_release( p_cc );
452 p_cc->p_owner->p_clock = p_owner->p_clock;
454 vlc_mutex_lock( &p_owner->lock );
455 p_owner->cc.pp_decoder[i_channel] = p_cc;
456 vlc_mutex_unlock( &p_owner->lock );
462 vlc_mutex_lock( &p_owner->lock );
463 p_cc = p_owner->cc.pp_decoder[i_channel];
464 p_owner->cc.pp_decoder[i_channel] = NULL;
465 vlc_mutex_unlock( &p_owner->lock );
469 vlc_object_kill( p_cc );
470 module_unneed( p_cc, p_cc->p_module );
471 DeleteDecoder( p_cc );
472 vlc_object_release( p_cc );
477 int input_DecoderGetCcState( decoder_t *p_dec, bool *pb_decode, int i_channel )
479 decoder_owner_sys_t *p_owner = p_dec->p_owner;
482 if( i_channel < 0 || i_channel >= 4 || !p_owner->cc.pb_present[i_channel] )
485 vlc_mutex_lock( &p_owner->lock );
486 *pb_decode = p_owner->cc.pp_decoder[i_channel] != NULL;
487 vlc_mutex_unlock( &p_owner->lock );
491 void input_DecoderChangePause( decoder_t *p_dec, bool b_paused, mtime_t i_date )
493 decoder_owner_sys_t *p_owner = p_dec->p_owner;
495 vlc_mutex_lock( &p_owner->lock );
497 assert( !p_owner->b_paused || !b_paused );
499 p_owner->b_paused = b_paused;
500 p_owner->pause.i_date = i_date;
501 p_owner->pause.i_ignore = 0;
502 vlc_cond_signal( &p_owner->wait );
504 DecoderOutputChangePause( p_dec, b_paused, i_date );
506 vlc_mutex_unlock( &p_owner->lock );
509 void input_DecoderChangeDelay( decoder_t *p_dec, mtime_t i_delay )
511 decoder_owner_sys_t *p_owner = p_dec->p_owner;
513 vlc_mutex_lock( &p_owner->lock );
514 p_owner->i_ts_delay = i_delay;
515 vlc_mutex_unlock( &p_owner->lock );
518 void input_DecoderStartBuffering( decoder_t *p_dec )
520 decoder_owner_sys_t *p_owner = p_dec->p_owner;
522 vlc_mutex_lock( &p_owner->lock );
524 DecoderFlush( p_dec );
526 p_owner->buffer.b_first = true;
527 p_owner->buffer.b_full = false;
528 p_owner->buffer.i_count = 0;
530 assert( !p_owner->buffer.p_picture && !p_owner->buffer.p_subpic &&
531 !p_owner->buffer.p_audio && !p_owner->buffer.p_block );
533 p_owner->buffer.p_picture = NULL;
534 p_owner->buffer.pp_picture_next = &p_owner->buffer.p_picture;
536 p_owner->buffer.p_subpic = NULL;
537 p_owner->buffer.pp_subpic_next = &p_owner->buffer.p_subpic;
539 p_owner->buffer.p_audio = NULL;
540 p_owner->buffer.pp_audio_next = &p_owner->buffer.p_audio;
542 p_owner->buffer.p_block = NULL;
543 p_owner->buffer.pp_block_next = &p_owner->buffer.p_block;
546 p_owner->b_buffering = true;
548 vlc_cond_signal( &p_owner->wait );
550 vlc_mutex_unlock( &p_owner->lock );
553 void input_DecoderStopBuffering( decoder_t *p_dec )
555 decoder_owner_sys_t *p_owner = p_dec->p_owner;
557 vlc_mutex_lock( &p_owner->lock );
559 p_owner->b_buffering = false;
561 vlc_cond_signal( &p_owner->wait );
563 vlc_mutex_unlock( &p_owner->lock );
566 void input_DecoderWaitBuffering( decoder_t *p_dec )
568 decoder_owner_sys_t *p_owner = p_dec->p_owner;
570 vlc_mutex_lock( &p_owner->lock );
572 while( vlc_object_alive( p_dec ) && p_owner->b_buffering && !p_owner->buffer.b_full )
574 block_FifoWake( p_owner->p_fifo );
575 vlc_cond_wait( &p_owner->wait, &p_owner->lock );
578 vlc_mutex_unlock( &p_owner->lock );
581 void input_DecoderFrameNext( decoder_t *p_dec, mtime_t *pi_duration )
583 decoder_owner_sys_t *p_owner = p_dec->p_owner;
587 vlc_mutex_lock( &p_owner->lock );
588 if( p_dec->fmt_in.i_cat == VIDEO_ES )
590 if( p_owner->b_paused && p_owner->p_vout )
592 vout_NextPicture( p_owner->p_vout, pi_duration );
593 p_owner->pause.i_ignore++;
594 vlc_cond_signal( &p_owner->wait );
599 /* TODO subtitle should not be flushed */
600 DecoderFlush( p_dec );
602 vlc_mutex_unlock( &p_owner->lock );
605 bool input_DecoderHasFormatChanged( decoder_t *p_dec, es_format_t *p_fmt, vlc_meta_t **pp_meta )
607 decoder_owner_sys_t *p_owner = p_dec->p_owner;
610 vlc_mutex_lock( &p_owner->lock );
611 b_changed = p_owner->b_fmt_description;
615 es_format_Copy( p_fmt, &p_owner->fmt_description );
620 if( p_owner->p_description )
622 *pp_meta = vlc_meta_New();
624 vlc_meta_Merge( *pp_meta, p_owner->p_description );
627 p_owner->b_fmt_description = false;
629 vlc_mutex_unlock( &p_owner->lock );
633 /*****************************************************************************
635 *****************************************************************************/
636 static int DecoderGetInputAttachments( decoder_t *p_dec,
637 input_attachment_t ***ppp_attachment,
640 return input_Control( p_dec->p_owner->p_input, INPUT_GET_ATTACHMENTS,
641 ppp_attachment, pi_attachment );
643 static mtime_t DecoderGetDisplayDate( decoder_t *p_dec, mtime_t i_ts )
645 decoder_owner_sys_t *p_owner = p_dec->p_owner;
647 vlc_mutex_lock( &p_owner->lock );
648 if( p_owner->b_buffering || p_owner->b_paused )
650 vlc_mutex_unlock( &p_owner->lock );
652 if( !p_owner->p_clock || !i_ts )
655 if( input_clock_ConvertTS( p_owner->p_clock, NULL, &i_ts, NULL, INT64_MAX ) )
660 static int DecoderGetDisplayRate( decoder_t *p_dec )
662 decoder_owner_sys_t *p_owner = p_dec->p_owner;
664 if( !p_owner->p_clock )
665 return INPUT_RATE_DEFAULT;
666 return input_clock_GetRate( p_owner->p_clock );
670 static void DecoderUnsupportedCodec( decoder_t *p_dec, vlc_fourcc_t codec )
672 msg_Err( p_dec, "no suitable decoder module for fourcc `%4.4s'.\n"
673 "VLC probably does not support this sound or video format.",
675 intf_UserFatal( p_dec, false, _("No suitable decoder module"),
676 _("VLC does not support the audio or video format \"%4.4s\". "
677 "Unfortunately there is no way for you to fix this."), (char*)&codec );
682 * Create a decoder object
684 * \param p_input the input thread
685 * \param p_es the es descriptor
686 * \param i_object_type Object type as define in include/vlc_objects.h
687 * \return the decoder object
689 static decoder_t * CreateDecoder( input_thread_t *p_input,
690 es_format_t *fmt, int i_object_type, sout_instance_t *p_sout )
693 decoder_owner_sys_t *p_owner;
696 p_dec = vlc_object_create( p_input, i_object_type );
700 p_dec->pf_decode_audio = NULL;
701 p_dec->pf_decode_video = NULL;
702 p_dec->pf_decode_sub = NULL;
703 p_dec->pf_get_cc = NULL;
704 p_dec->pf_packetize = NULL;
706 /* Initialize the decoder */
707 p_dec->p_module = NULL;
709 memset( &null_es_format, 0, sizeof(es_format_t) );
710 es_format_Copy( &p_dec->fmt_in, fmt );
711 es_format_Copy( &p_dec->fmt_out, &null_es_format );
713 p_dec->p_description = NULL;
715 /* Allocate our private structure for the decoder */
716 p_dec->p_owner = p_owner = malloc( sizeof( decoder_owner_sys_t ) );
717 if( p_dec->p_owner == NULL )
719 vlc_object_release( p_dec );
722 p_dec->p_owner->i_preroll_end = -1;
723 p_dec->p_owner->i_last_rate = INPUT_RATE_DEFAULT;
724 p_dec->p_owner->p_input = p_input;
725 p_dec->p_owner->p_aout = NULL;
726 p_dec->p_owner->p_aout_input = NULL;
727 p_dec->p_owner->p_vout = NULL;
728 p_dec->p_owner->p_spu_vout = NULL;
729 p_dec->p_owner->i_spu_channel = 0;
730 p_dec->p_owner->i_spu_order = 0;
731 p_dec->p_owner->p_sout = p_sout;
732 p_dec->p_owner->p_sout_input = NULL;
733 p_dec->p_owner->p_packetizer = NULL;
736 if( ( p_dec->p_owner->p_fifo = block_FifoNew() ) == NULL )
738 free( p_dec->p_owner );
739 vlc_object_release( p_dec );
743 /* Set buffers allocation callbacks for the decoders */
744 p_dec->pf_aout_buffer_new = aout_new_buffer;
745 p_dec->pf_aout_buffer_del = aout_del_buffer;
746 p_dec->pf_vout_buffer_new = vout_new_buffer;
747 p_dec->pf_vout_buffer_del = vout_del_buffer;
748 p_dec->pf_picture_link = vout_link_picture;
749 p_dec->pf_picture_unlink = vout_unlink_picture;
750 p_dec->pf_spu_buffer_new = spu_new_buffer;
751 p_dec->pf_spu_buffer_del = spu_del_buffer;
753 p_dec->pf_get_attachments = DecoderGetInputAttachments;
754 p_dec->pf_get_display_date = DecoderGetDisplayDate;
755 p_dec->pf_get_display_rate = DecoderGetDisplayRate;
757 vlc_object_attach( p_dec, p_input );
759 /* Find a suitable decoder/packetizer module */
760 if( i_object_type == VLC_OBJECT_DECODER )
761 p_dec->p_module = module_need( p_dec, "decoder", "$codec", false );
763 p_dec->p_module = module_need( p_dec, "packetizer", "$packetizer", false );
765 /* Check if decoder requires already packetized data */
766 if( i_object_type == VLC_OBJECT_DECODER &&
767 p_dec->b_need_packetized && !p_dec->fmt_in.b_packetized )
769 p_dec->p_owner->p_packetizer =
770 vlc_object_create( p_input, VLC_OBJECT_PACKETIZER );
771 if( p_dec->p_owner->p_packetizer )
773 es_format_Copy( &p_dec->p_owner->p_packetizer->fmt_in,
776 es_format_Copy( &p_dec->p_owner->p_packetizer->fmt_out,
779 vlc_object_attach( p_dec->p_owner->p_packetizer, p_input );
781 p_dec->p_owner->p_packetizer->p_module =
782 module_need( p_dec->p_owner->p_packetizer,
783 "packetizer", "$packetizer", false );
785 if( !p_dec->p_owner->p_packetizer->p_module )
787 es_format_Clean( &p_dec->p_owner->p_packetizer->fmt_in );
788 vlc_object_detach( p_dec->p_owner->p_packetizer );
789 vlc_object_release( p_dec->p_owner->p_packetizer );
794 /* Copy ourself the input replay gain */
795 if( fmt->i_cat == AUDIO_ES )
797 for( i = 0; i < AUDIO_REPLAY_GAIN_MAX; i++ )
799 if( !p_dec->fmt_out.audio_replay_gain.pb_peak[i] )
801 p_dec->fmt_out.audio_replay_gain.pb_peak[i] = fmt->audio_replay_gain.pb_peak[i];
802 p_dec->fmt_out.audio_replay_gain.pf_peak[i] = fmt->audio_replay_gain.pf_peak[i];
804 if( !p_dec->fmt_out.audio_replay_gain.pb_gain[i] )
806 p_dec->fmt_out.audio_replay_gain.pb_gain[i] = fmt->audio_replay_gain.pb_gain[i];
807 p_dec->fmt_out.audio_replay_gain.pf_gain[i] = fmt->audio_replay_gain.pf_gain[i];
813 vlc_mutex_init( &p_owner->lock );
814 vlc_cond_init( &p_owner->wait );
816 p_owner->b_fmt_description = false;
817 es_format_Init( &p_owner->fmt_description, UNKNOWN_ES, 0 );
818 p_owner->p_description = NULL;
820 p_owner->b_paused = false;
821 p_owner->pause.i_date = 0;
822 p_owner->pause.i_ignore = 0;
824 p_owner->b_buffering = false;
825 p_owner->buffer.b_first = true;
826 p_owner->buffer.b_full = false;
827 p_owner->buffer.i_count = 0;
828 p_owner->buffer.p_picture = NULL;
829 p_owner->buffer.p_subpic = NULL;
830 p_owner->buffer.p_audio = NULL;
831 p_owner->buffer.p_block = NULL;
833 p_owner->b_flushing = false;
836 p_owner->cc.b_supported = false;
837 if( i_object_type == VLC_OBJECT_DECODER )
839 if( p_owner->p_packetizer && p_owner->p_packetizer->pf_get_cc )
840 p_owner->cc.b_supported = true;
841 if( p_dec->pf_get_cc )
842 p_owner->cc.b_supported = true;
845 for( i = 0; i < 4; i++ )
847 p_owner->cc.pb_present[i] = false;
848 p_owner->cc.pp_decoder[i] = NULL;
850 p_owner->i_ts_delay = 0;
855 * The decoding main loop
857 * \param p_dec the decoder
859 static void *DecoderThread( vlc_object_t *p_this )
861 decoder_t *p_dec = (decoder_t *)p_this;
862 decoder_owner_sys_t *p_owner = p_dec->p_owner;
864 /* The decoder's main loop */
867 block_t *p_block = block_FifoGet( p_owner->p_fifo );
869 /* Make sure there is no cancellation point other than this one^^.
870 * If you need one, be sure to push cleanup of p_block. */
871 DecoderSignalBuffering( p_dec, p_block == NULL );
875 int canc = vlc_savecancel();
878 DecoderError( p_dec, p_block );
880 DecoderProcess( p_dec, p_block );
882 vlc_restorecancel( canc );
888 static void DecoderFlush( decoder_t *p_dec )
890 decoder_owner_sys_t *p_owner = p_dec->p_owner;
893 vlc_assert_locked( &p_owner->lock );
896 block_FifoEmpty( p_owner->p_fifo );
898 /* Monitor for flush end */
899 p_owner->b_flushing = true;
900 vlc_cond_signal( &p_owner->wait );
902 /* Send a special block */
903 p_null = block_New( p_dec, 128 );
906 p_null->i_flags |= BLOCK_FLAG_DISCONTINUITY;
907 p_null->i_flags |= BLOCK_FLAG_CORE_FLUSH;
908 if( !p_dec->fmt_in.b_packetized )
909 p_null->i_flags |= BLOCK_FLAG_CORRUPTED;
910 memset( p_null->p_buffer, 0, p_null->i_buffer );
912 input_DecoderDecode( p_dec, p_null );
915 while( vlc_object_alive( p_dec ) && p_owner->b_flushing )
916 vlc_cond_wait( &p_owner->wait, &p_owner->lock );
919 static void DecoderSignalFlushed( decoder_t *p_dec )
921 decoder_owner_sys_t *p_owner = p_dec->p_owner;
923 vlc_mutex_lock( &p_owner->lock );
925 if( p_owner->b_flushing )
927 p_owner->b_flushing = false;
928 vlc_cond_signal( &p_owner->wait );
931 vlc_mutex_unlock( &p_owner->lock );
934 static void DecoderSignalBuffering( decoder_t *p_dec, bool b_full )
936 decoder_owner_sys_t *p_owner = p_dec->p_owner;
938 vlc_mutex_lock( &p_owner->lock );
940 if( p_owner->b_buffering )
943 p_owner->buffer.b_full = true;
944 vlc_cond_signal( &p_owner->wait );
947 vlc_mutex_unlock( &p_owner->lock );
950 static bool DecoderIsFlushing( decoder_t *p_dec )
952 decoder_owner_sys_t *p_owner = p_dec->p_owner;
955 vlc_mutex_lock( &p_owner->lock );
957 b_flushing = p_owner->b_flushing;
959 vlc_mutex_unlock( &p_owner->lock );
964 static void DecoderWaitUnblock( decoder_t *p_dec, bool *pb_reject )
966 decoder_owner_sys_t *p_owner = p_dec->p_owner;
968 vlc_assert_locked( &p_owner->lock );
970 while( !p_owner->b_flushing )
972 if( p_owner->b_paused )
974 if( p_owner->b_buffering && !p_owner->buffer.b_full )
976 if( p_owner->pause.i_ignore > 0 )
978 p_owner->pause.i_ignore--;
984 if( !p_owner->b_buffering || !p_owner->buffer.b_full )
987 vlc_cond_wait( &p_owner->wait, &p_owner->lock );
991 *pb_reject = p_owner->b_flushing;
994 static void DecoderOutputChangePause( decoder_t *p_dec, bool b_paused, mtime_t i_date )
996 decoder_owner_sys_t *p_owner = p_dec->p_owner;
998 vlc_assert_locked( &p_owner->lock );
1000 /* XXX only audio and video output have to be paused.
1001 * - for sout it is useless
1002 * - for subs, it is done by the vout
1004 if( p_dec->fmt_in.i_cat == AUDIO_ES )
1006 if( p_owner->p_aout && p_owner->p_aout_input )
1007 aout_DecChangePause( p_owner->p_aout, p_owner->p_aout_input,
1010 else if( p_dec->fmt_in.i_cat == VIDEO_ES )
1012 if( p_owner->p_vout )
1013 vout_ChangePause( p_owner->p_vout, b_paused, i_date );
1016 static inline void DecoderUpdatePreroll( int64_t *pi_preroll, const block_t *p )
1018 if( p->i_flags & (BLOCK_FLAG_PREROLL|BLOCK_FLAG_DISCONTINUITY) )
1019 *pi_preroll = INT64_MAX;
1020 else if( p->i_pts > 0 )
1021 *pi_preroll = __MIN( *pi_preroll, p->i_pts );
1022 else if( p->i_dts > 0 )
1023 *pi_preroll = __MIN( *pi_preroll, p->i_dts );
1026 static mtime_t DecoderTeletextFixTs( mtime_t i_ts )
1028 mtime_t current_date = mdate();
1030 /* FIXME I don't really like that, es_out SHOULD do it using the video pts */
1031 if( !i_ts || i_ts > current_date + 10000000 || i_ts < current_date )
1033 /* ETSI EN 300 472 Annex A : do not take into account the PTS
1034 * for teletext streams. */
1035 return current_date + 400000;
1040 static void DecoderFixTs( decoder_t *p_dec, mtime_t *pi_ts0, mtime_t *pi_ts1,
1041 mtime_t *pi_duration, int *pi_rate, mtime_t i_ts_bound, bool b_telx )
1043 decoder_owner_sys_t *p_owner = p_dec->p_owner;
1044 input_clock_t *p_clock = p_owner->p_clock;
1046 vlc_assert_locked( &p_owner->lock );
1048 const mtime_t i_es_delay = p_owner->i_ts_delay;
1052 const bool b_ephemere = pi_ts1 && *pi_ts0 == *pi_ts1;
1057 *pi_ts0 += i_es_delay;
1058 if( pi_ts1 && *pi_ts1 > 0 )
1059 *pi_ts1 += i_es_delay;
1060 input_clock_ConvertTS( p_clock, &i_rate, pi_ts0, pi_ts1, i_ts_bound );
1064 i_rate = input_clock_GetRate( p_clock );
1067 /* Do not create ephemere data because of rounding errors */
1068 if( !b_ephemere && pi_ts1 && *pi_ts0 == *pi_ts1 )
1072 *pi_duration = ( *pi_duration * i_rate +
1073 INPUT_RATE_DEFAULT-1 ) / INPUT_RATE_DEFAULT;
1080 *pi_ts0 = DecoderTeletextFixTs( *pi_ts0 );
1081 if( pi_ts1 && *pi_ts1 <= 0 )
1087 static void DecoderPlayAudio( decoder_t *p_dec, aout_buffer_t *p_audio,
1088 int *pi_played_sum, int *pi_lost_sum )
1090 decoder_owner_sys_t *p_owner = p_dec->p_owner;
1091 aout_instance_t *p_aout = p_owner->p_aout;
1092 aout_input_t *p_aout_input = p_owner->p_aout_input;
1095 if( p_audio->start_date <= 0 )
1097 msg_Warn( p_dec, "non-dated audio buffer received" );
1099 aout_BufferFree( p_audio );
1104 vlc_mutex_lock( &p_owner->lock );
1106 if( p_owner->b_buffering || p_owner->buffer.p_audio )
1108 p_audio->p_next = NULL;
1110 *p_owner->buffer.pp_audio_next = p_audio;
1111 p_owner->buffer.pp_audio_next = &p_audio->p_next;
1113 p_owner->buffer.i_count++;
1114 if( p_owner->buffer.i_count > DECODER_MAX_BUFFERING_COUNT ||
1115 p_audio->start_date - p_owner->buffer.p_audio->start_date > DECODER_MAX_BUFFERING_AUDIO_DURATION )
1117 p_owner->buffer.b_full = true;
1118 vlc_cond_signal( &p_owner->wait );
1124 bool b_has_more = false;
1126 DecoderWaitUnblock( p_dec, &b_reject );
1128 if( p_owner->b_buffering )
1130 vlc_mutex_unlock( &p_owner->lock );
1135 if( p_owner->buffer.p_audio )
1137 p_audio = p_owner->buffer.p_audio;
1139 p_owner->buffer.p_audio = p_audio->p_next;
1140 p_owner->buffer.i_count--;
1142 b_has_more = p_owner->buffer.p_audio != NULL;
1144 p_owner->buffer.pp_audio_next = &p_owner->buffer.p_audio;
1148 const bool b_dated = p_audio->start_date > 0;
1149 int i_rate = INPUT_RATE_DEFAULT;
1151 DecoderFixTs( p_dec, &p_audio->start_date, &p_audio->end_date, NULL,
1152 &i_rate, AOUT_MAX_ADVANCE_TIME, false );
1154 vlc_mutex_unlock( &p_owner->lock );
1156 if( !p_aout || !p_aout_input ||
1157 p_audio->start_date <= 0 ||
1158 i_rate < INPUT_RATE_DEFAULT/AOUT_MAX_INPUT_RATE ||
1159 i_rate > INPUT_RATE_DEFAULT*AOUT_MAX_INPUT_RATE )
1162 /* Do not wait against unprotected date */
1163 const mtime_t i_deadline = p_audio->start_date - AOUT_MAX_PREPARE_TIME;
1164 while( !b_reject && i_deadline > mdate() )
1166 vlc_mutex_lock( &p_owner->lock );
1167 if( p_owner->b_flushing || p_dec->b_die )
1170 vlc_mutex_unlock( &p_owner->lock );
1173 vlc_cond_timedwait( &p_owner->wait, &p_owner->lock, i_deadline );
1174 vlc_mutex_unlock( &p_owner->lock );
1179 if( !aout_DecPlay( p_aout, p_aout_input, p_audio, i_rate ) )
1180 *pi_played_sum += 1;
1181 *pi_lost_sum += aout_DecGetResetLost( p_aout, p_aout_input );
1186 msg_Warn( p_aout, "received buffer in the future" );
1188 msg_Warn( p_dec, "non-dated audio buffer received" );
1191 aout_BufferFree( p_audio );
1197 vlc_mutex_lock( &p_owner->lock );
1198 if( !p_owner->buffer.p_audio )
1200 vlc_mutex_unlock( &p_owner->lock );
1206 static void DecoderDecodeAudio( decoder_t *p_dec, block_t *p_block )
1208 decoder_owner_sys_t *p_owner = p_dec->p_owner;
1209 input_thread_t *p_input = p_owner->p_input;
1210 aout_buffer_t *p_aout_buf;
1215 while( (p_aout_buf = p_dec->pf_decode_audio( p_dec, &p_block )) )
1217 aout_instance_t *p_aout = p_owner->p_aout;
1218 aout_input_t *p_aout_input = p_owner->p_aout_input;
1222 /* It prevent freezing VLC in case of broken decoder */
1223 aout_DecDeleteBuffer( p_aout, p_aout_input, p_aout_buf );
1225 block_Release( p_block );
1230 if( p_aout_buf->start_date < p_owner->i_preroll_end )
1232 aout_DecDeleteBuffer( p_aout, p_aout_input, p_aout_buf );
1236 if( p_owner->i_preroll_end > 0 )
1238 msg_Dbg( p_dec, "End of audio preroll" );
1239 if( p_owner->p_aout && p_owner->p_aout_input )
1240 aout_DecFlush( p_owner->p_aout, p_owner->p_aout_input );
1242 p_owner->i_preroll_end = -1;
1245 DecoderPlayAudio( p_dec, p_aout_buf, &i_played, &i_lost );
1248 /* Update ugly stat */
1249 if( i_decoded > 0 || i_lost > 0 || i_played > 0 )
1251 vlc_mutex_lock( &p_input->p->counters.counters_lock);
1253 stats_UpdateInteger( p_dec, p_input->p->counters.p_lost_abuffers,
1255 stats_UpdateInteger( p_dec, p_input->p->counters.p_played_abuffers,
1257 stats_UpdateInteger( p_dec, p_input->p->counters.p_decoded_audio,
1260 vlc_mutex_unlock( &p_input->p->counters.counters_lock);
1263 static void DecoderGetCc( decoder_t *p_dec, decoder_t *p_dec_cc )
1265 decoder_owner_sys_t *p_owner = p_dec->p_owner;
1271 assert( p_dec_cc->pf_get_cc != NULL );
1273 /* Do not try retreiving CC if not wanted (sout) or cannot be retreived */
1274 if( !p_owner->cc.b_supported )
1277 p_cc = p_dec_cc->pf_get_cc( p_dec_cc, pb_present );
1281 vlc_mutex_lock( &p_owner->lock );
1282 for( i = 0, i_cc_decoder = 0; i < 4; i++ )
1284 p_owner->cc.pb_present[i] |= pb_present[i];
1285 if( p_owner->cc.pp_decoder[i] )
1289 for( i = 0; i < 4; i++ )
1291 if( !p_owner->cc.pp_decoder[i] )
1294 if( i_cc_decoder > 1 )
1295 DecoderProcess( p_owner->cc.pp_decoder[i], block_Duplicate( p_cc ) );
1297 DecoderProcess( p_owner->cc.pp_decoder[i], p_cc );
1300 vlc_mutex_unlock( &p_owner->lock );
1303 static void DecoderPlayVideo( decoder_t *p_dec, picture_t *p_picture,
1304 int *pi_played_sum, int *pi_lost_sum )
1306 decoder_owner_sys_t *p_owner = p_dec->p_owner;
1307 vout_thread_t *p_vout = p_owner->p_vout;
1308 bool b_first_buffered;
1310 if( p_picture->date <= 0 )
1312 msg_Warn( p_vout, "non-dated video buffer received" );
1314 vout_DropPicture( p_vout, p_picture );
1319 vlc_mutex_lock( &p_owner->lock );
1321 if( ( p_owner->b_buffering && !p_owner->buffer.b_first ) || p_owner->buffer.p_picture )
1323 p_picture->p_next = NULL;
1325 *p_owner->buffer.pp_picture_next = p_picture;
1326 p_owner->buffer.pp_picture_next = &p_picture->p_next;
1328 p_owner->buffer.i_count++;
1329 if( p_owner->buffer.i_count > DECODER_MAX_BUFFERING_COUNT ||
1330 p_picture->date - p_owner->buffer.p_picture->date > DECODER_MAX_BUFFERING_VIDEO_DURATION )
1332 p_owner->buffer.b_full = true;
1333 vlc_cond_signal( &p_owner->wait );
1336 b_first_buffered = p_owner->buffer.p_picture != NULL;
1338 for( ;; b_first_buffered = false )
1340 bool b_has_more = false;
1344 DecoderWaitUnblock( p_dec, &b_reject );
1346 if( p_owner->b_buffering && !p_owner->buffer.b_first )
1348 vlc_mutex_unlock( &p_owner->lock );
1351 bool b_buffering_first = p_owner->b_buffering;
1354 if( p_owner->buffer.p_picture )
1356 p_picture = p_owner->buffer.p_picture;
1358 p_owner->buffer.p_picture = p_picture->p_next;
1359 p_owner->buffer.i_count--;
1361 b_has_more = p_owner->buffer.p_picture != NULL;
1363 p_owner->buffer.pp_picture_next = &p_owner->buffer.p_picture;
1367 if( b_buffering_first )
1369 assert( p_owner->buffer.b_first );
1370 assert( !p_owner->buffer.i_count );
1371 msg_Dbg( p_dec, "Received first picture" );
1372 p_owner->buffer.b_first = false;
1373 p_picture->b_force = true;
1376 const bool b_dated = p_picture->date > 0;
1377 int i_rate = INPUT_RATE_DEFAULT;
1378 DecoderFixTs( p_dec, &p_picture->date, NULL, NULL,
1379 &i_rate, DECODER_BOGUS_VIDEO_DELAY, false );
1381 vlc_mutex_unlock( &p_owner->lock );
1384 if( !p_picture->b_force && p_picture->date <= 0 )
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 );
1400 msg_Warn( p_vout, "early picture skipped" );
1402 msg_Warn( p_vout, "non-dated video buffer received" );
1405 vout_DropPicture( p_vout, p_picture );
1409 vout_GetResetStatistic( p_vout, &i_tmp_display, &i_tmp_lost );
1411 *pi_played_sum += i_tmp_display;
1412 *pi_lost_sum += i_tmp_lost;
1414 if( !b_has_more || b_buffering_first )
1417 vlc_mutex_lock( &p_owner->lock );
1418 if( !p_owner->buffer.p_picture )
1420 vlc_mutex_unlock( &p_owner->lock );
1426 static void DecoderDecodeVideo( decoder_t *p_dec, block_t *p_block )
1428 decoder_owner_sys_t *p_owner = p_dec->p_owner;
1429 input_thread_t *p_input = p_owner->p_input;
1433 int i_displayed = 0;
1435 while( (p_pic = p_dec->pf_decode_video( p_dec, &p_block )) )
1437 vout_thread_t *p_vout = p_owner->p_vout;
1440 /* It prevent freezing VLC in case of broken decoder */
1441 vout_DropPicture( p_vout, p_pic );
1443 block_Release( p_block );
1449 if( p_pic->date < p_owner->i_preroll_end )
1451 vout_DropPicture( p_vout, p_pic );
1455 if( p_owner->i_preroll_end > 0 )
1457 msg_Dbg( p_dec, "End of video preroll" );
1459 vout_Flush( p_vout, 1 );
1461 p_owner->i_preroll_end = -1;
1464 if( p_dec->pf_get_cc &&
1465 ( !p_owner->p_packetizer || !p_owner->p_packetizer->pf_get_cc ) )
1466 DecoderGetCc( p_dec, p_dec );
1468 DecoderPlayVideo( p_dec, p_pic, &i_displayed, &i_lost );
1470 if( i_decoded > 0 || i_lost > 0 || i_displayed > 0 )
1472 vlc_mutex_lock( &p_input->p->counters.counters_lock );
1474 stats_UpdateInteger( p_dec, p_input->p->counters.p_decoded_video,
1476 stats_UpdateInteger( p_dec, p_input->p->counters.p_lost_pictures,
1479 stats_UpdateInteger( p_dec, p_input->p->counters.p_displayed_pictures,
1482 vlc_mutex_unlock( &p_input->p->counters.counters_lock );
1486 static void DecoderPlaySpu( decoder_t *p_dec, subpicture_t *p_subpic,
1489 decoder_owner_sys_t *p_owner = p_dec->p_owner;
1490 vout_thread_t *p_vout = p_owner->p_spu_vout;
1493 if( p_subpic->i_start <= 0 )
1495 msg_Warn( p_dec, "non-dated spu buffer received" );
1496 subpicture_Delete( p_subpic );
1501 vlc_mutex_lock( &p_owner->lock );
1503 if( p_owner->b_buffering || p_owner->buffer.p_subpic )
1505 p_subpic->p_next = NULL;
1507 *p_owner->buffer.pp_subpic_next = p_subpic;
1508 p_owner->buffer.pp_subpic_next = &p_subpic->p_next;
1510 p_owner->buffer.i_count++;
1511 /* XXX it is important to be full after the first one */
1512 if( p_owner->buffer.i_count > 0 )
1514 p_owner->buffer.b_full = true;
1515 vlc_cond_signal( &p_owner->wait );
1521 bool b_has_more = false;
1523 DecoderWaitUnblock( p_dec, &b_reject );
1525 if( p_owner->b_buffering )
1527 vlc_mutex_unlock( &p_owner->lock );
1532 if( p_owner->buffer.p_subpic )
1534 p_subpic = p_owner->buffer.p_subpic;
1536 p_owner->buffer.p_subpic = p_subpic->p_next;
1537 p_owner->buffer.i_count--;
1539 b_has_more = p_owner->buffer.p_subpic != NULL;
1541 p_owner->buffer.pp_subpic_next = &p_owner->buffer.p_subpic;
1545 DecoderFixTs( p_dec, &p_subpic->i_start, &p_subpic->i_stop, NULL,
1546 NULL, INT64_MAX, b_telx );
1548 vlc_mutex_unlock( &p_owner->lock );
1551 spu_DisplaySubpicture( p_vout->p_spu, p_subpic );
1553 subpicture_Delete( p_subpic );
1557 vlc_mutex_lock( &p_owner->lock );
1558 if( !p_owner->buffer.p_subpic )
1560 vlc_mutex_unlock( &p_owner->lock );
1566 static void DecoderPlaySout( decoder_t *p_dec, block_t *p_sout_block,
1569 decoder_owner_sys_t *p_owner = p_dec->p_owner;
1571 assert( p_owner->p_clock );
1572 assert( !p_sout_block->p_next );
1574 vlc_mutex_lock( &p_owner->lock );
1576 if( p_owner->b_buffering || p_owner->buffer.p_block )
1578 block_ChainLastAppend( &p_owner->buffer.pp_block_next, p_sout_block );
1580 p_owner->buffer.i_count++;
1581 /* XXX it is important to be full after the first one */
1582 if( p_owner->buffer.i_count > 0 )
1584 p_owner->buffer.b_full = true;
1585 vlc_cond_signal( &p_owner->wait );
1591 bool b_has_more = false;
1593 DecoderWaitUnblock( p_dec, &b_reject );
1595 if( p_owner->b_buffering )
1597 vlc_mutex_unlock( &p_owner->lock );
1602 if( p_owner->buffer.p_block )
1604 p_sout_block = p_owner->buffer.p_block;
1606 p_owner->buffer.p_block = p_sout_block->p_next;
1607 p_owner->buffer.i_count--;
1609 b_has_more = p_owner->buffer.p_block != NULL;
1611 p_owner->buffer.pp_block_next = &p_owner->buffer.p_block;
1613 p_sout_block->p_next = NULL;
1615 DecoderFixTs( p_dec, &p_sout_block->i_dts, &p_sout_block->i_pts,
1616 &p_sout_block->i_length,
1617 &p_sout_block->i_rate, INT64_MAX, b_telx );
1619 vlc_mutex_unlock( &p_owner->lock );
1622 sout_InputSendBuffer( p_owner->p_sout_input, p_sout_block );
1624 block_Release( p_sout_block );
1628 vlc_mutex_lock( &p_owner->lock );
1629 if( !p_owner->buffer.p_block )
1631 vlc_mutex_unlock( &p_owner->lock );
1638 static void DecoderFlushBuffering( decoder_t *p_dec )
1640 decoder_owner_sys_t *p_owner = p_dec->p_owner;
1642 vlc_assert_locked( &p_owner->lock );
1644 while( p_owner->buffer.p_picture )
1646 picture_t *p_picture = p_owner->buffer.p_picture;
1648 p_owner->buffer.p_picture = p_picture->p_next;
1649 p_owner->buffer.i_count--;
1651 if( p_owner->p_vout )
1652 vout_DropPicture( p_owner->p_vout, p_picture );
1654 if( !p_owner->buffer.p_picture )
1655 p_owner->buffer.pp_picture_next = &p_owner->buffer.p_picture;
1657 while( p_owner->buffer.p_audio )
1659 aout_buffer_t *p_audio = p_owner->buffer.p_audio;
1661 p_owner->buffer.p_audio = p_audio->p_next;
1662 p_owner->buffer.i_count--;
1664 aout_BufferFree( p_audio );
1666 if( !p_owner->buffer.p_audio )
1667 p_owner->buffer.pp_audio_next = &p_owner->buffer.p_audio;
1669 while( p_owner->buffer.p_subpic )
1671 subpicture_t *p_subpic = p_owner->buffer.p_subpic;
1673 p_owner->buffer.p_subpic = p_subpic->p_next;
1674 p_owner->buffer.i_count--;
1676 subpicture_Delete( p_subpic );
1678 if( !p_owner->buffer.p_subpic )
1679 p_owner->buffer.pp_subpic_next = &p_owner->buffer.p_subpic;
1681 if( p_owner->buffer.p_block )
1683 block_ChainRelease( p_owner->buffer.p_block );
1685 p_owner->buffer.i_count = 0;
1686 p_owner->buffer.p_block = NULL;
1687 p_owner->buffer.pp_block_next = &p_owner->buffer.p_block;
1691 /* This function process a block for sout
1693 static void DecoderProcessSout( decoder_t *p_dec, block_t *p_block )
1695 decoder_owner_sys_t *p_owner = (decoder_owner_sys_t *)p_dec->p_owner;
1696 const bool b_telx = p_dec->fmt_in.i_codec == VLC_FOURCC('t','e','l','x');
1697 block_t *p_sout_block;
1699 while( ( p_sout_block =
1700 p_dec->pf_packetize( p_dec, p_block ? &p_block : NULL ) ) )
1702 if( !p_owner->p_sout_input )
1704 es_format_Copy( &p_owner->sout, &p_dec->fmt_out );
1706 p_owner->sout.i_group = p_dec->fmt_in.i_group;
1707 p_owner->sout.i_id = p_dec->fmt_in.i_id;
1708 if( p_dec->fmt_in.psz_language )
1710 if( p_owner->sout.psz_language )
1711 free( p_owner->sout.psz_language );
1712 p_owner->sout.psz_language =
1713 strdup( p_dec->fmt_in.psz_language );
1716 p_owner->p_sout_input =
1717 sout_InputNew( p_owner->p_sout,
1720 if( p_owner->p_sout_input == NULL )
1722 msg_Err( p_dec, "cannot create packetizer output (%4.4s)",
1723 (char *)&p_owner->sout.i_codec );
1724 p_dec->b_error = true;
1726 while( p_sout_block )
1728 block_t *p_next = p_sout_block->p_next;
1729 block_Release( p_sout_block );
1730 p_sout_block = p_next;
1736 while( p_sout_block )
1738 block_t *p_next = p_sout_block->p_next;
1740 p_sout_block->p_next = NULL;
1742 DecoderPlaySout( p_dec, p_sout_block, b_telx );
1744 p_sout_block = p_next;
1747 /* For now it's enough, as only sout impact on this flag */
1748 if( p_owner->p_sout->i_out_pace_nocontrol > 0 &&
1749 p_owner->p_input->p->b_out_pace_control )
1751 msg_Dbg( p_dec, "switching to sync mode" );
1752 p_owner->p_input->p->b_out_pace_control = false;
1754 else if( p_owner->p_sout->i_out_pace_nocontrol <= 0 &&
1755 !p_owner->p_input->p->b_out_pace_control )
1757 msg_Dbg( p_dec, "switching to async mode" );
1758 p_owner->p_input->p->b_out_pace_control = true;
1763 /* This function process a video block
1765 static void DecoderProcessVideo( decoder_t *p_dec, block_t *p_block, bool b_flush )
1767 decoder_owner_sys_t *p_owner = (decoder_owner_sys_t *)p_dec->p_owner;
1769 if( p_owner->p_packetizer )
1771 block_t *p_packetized_block;
1772 decoder_t *p_packetizer = p_owner->p_packetizer;
1774 while( (p_packetized_block =
1775 p_packetizer->pf_packetize( p_packetizer, p_block ? &p_block : NULL )) )
1777 if( p_packetizer->fmt_out.i_extra && !p_dec->fmt_in.i_extra )
1779 es_format_Clean( &p_dec->fmt_in );
1780 es_format_Copy( &p_dec->fmt_in, &p_packetizer->fmt_out );
1782 if( p_packetizer->pf_get_cc )
1783 DecoderGetCc( p_dec, p_packetizer );
1785 while( p_packetized_block )
1787 block_t *p_next = p_packetized_block->p_next;
1788 p_packetized_block->p_next = NULL;
1790 DecoderDecodeVideo( p_dec, p_packetized_block );
1792 p_packetized_block = p_next;
1798 DecoderDecodeVideo( p_dec, p_block );
1801 if( b_flush && p_owner->p_vout )
1802 vout_Flush( p_owner->p_vout, 1 );
1805 /* This function process a audio block
1807 static void DecoderProcessAudio( decoder_t *p_dec, block_t *p_block, bool b_flush )
1809 decoder_owner_sys_t *p_owner = (decoder_owner_sys_t *)p_dec->p_owner;
1811 if( p_owner->p_packetizer )
1813 block_t *p_packetized_block;
1814 decoder_t *p_packetizer = p_owner->p_packetizer;
1816 while( (p_packetized_block =
1817 p_packetizer->pf_packetize( p_packetizer, p_block ? &p_block : NULL )) )
1819 if( p_packetizer->fmt_out.i_extra && !p_dec->fmt_in.i_extra )
1821 es_format_Clean( &p_dec->fmt_in );
1822 es_format_Copy( &p_dec->fmt_in, &p_packetizer->fmt_out );
1825 while( p_packetized_block )
1827 block_t *p_next = p_packetized_block->p_next;
1828 p_packetized_block->p_next = NULL;
1830 DecoderDecodeAudio( p_dec, p_packetized_block );
1832 p_packetized_block = p_next;
1838 DecoderDecodeAudio( p_dec, p_block );
1841 if( b_flush && p_owner->p_aout && p_owner->p_aout_input )
1842 aout_DecFlush( p_owner->p_aout, p_owner->p_aout_input );
1845 /* This function process a subtitle block
1847 static void DecoderProcessSpu( decoder_t *p_dec, block_t *p_block, bool b_flush )
1849 decoder_owner_sys_t *p_owner = p_dec->p_owner;
1850 const bool b_telx = p_dec->fmt_in.i_codec == VLC_FOURCC('t','e','l','x');
1852 input_thread_t *p_input = p_owner->p_input;
1853 vout_thread_t *p_vout;
1854 subpicture_t *p_spu;
1856 while( (p_spu = p_dec->pf_decode_sub( p_dec, p_block ? &p_block : NULL ) ) )
1858 vlc_mutex_lock( &p_input->p->counters.counters_lock );
1859 stats_UpdateInteger( p_dec, p_input->p->counters.p_decoded_sub, 1, NULL );
1860 vlc_mutex_unlock( &p_input->p->counters.counters_lock );
1862 p_vout = input_ressource_HoldVout( p_input->p->p_ressource );
1863 if( p_vout && p_owner->p_spu_vout == p_vout )
1865 /* Preroll does not work very well with subtitle */
1866 if( p_spu->i_start > 0 &&
1867 p_spu->i_start < p_owner->i_preroll_end &&
1868 ( p_spu->i_stop <= 0 || p_spu->i_stop < p_owner->i_preroll_end ) )
1870 subpicture_Delete( p_spu );
1874 DecoderPlaySpu( p_dec, p_spu, b_telx );
1879 subpicture_Delete( p_spu );
1882 vlc_object_release( p_vout );
1885 if( b_flush && p_owner->p_spu_vout )
1887 p_vout = input_ressource_HoldVout( p_input->p->p_ressource );
1889 if( p_vout && p_owner->p_spu_vout == p_vout )
1890 spu_Control( p_vout->p_spu, SPU_CHANNEL_CLEAR,
1891 p_owner->i_spu_channel );
1894 vlc_object_release( p_vout );
1899 static void DecoderProcessOnFlush( decoder_t *p_dec )
1901 decoder_owner_sys_t *p_owner = p_dec->p_owner;
1903 vlc_mutex_lock( &p_owner->lock );
1904 DecoderFlushBuffering( p_dec );
1905 vlc_mutex_unlock( &p_owner->lock );
1907 DecoderSignalFlushed( p_dec );
1912 * \param p_dec the decoder object
1913 * \param p_block the block to decode
1914 * \return VLC_SUCCESS or an error code
1916 static void DecoderProcess( decoder_t *p_dec, block_t *p_block )
1918 decoder_owner_sys_t *p_owner = (decoder_owner_sys_t *)p_dec->p_owner;
1919 const bool b_flush_request = p_block && (p_block->i_flags & BLOCK_FLAG_CORE_FLUSH);
1921 if( p_block && p_block->i_buffer <= 0 )
1923 assert( !b_flush_request );
1924 block_Release( p_block );
1929 if( vlc_internals( p_dec )->i_object_type == VLC_OBJECT_PACKETIZER )
1932 p_block->i_flags &= ~BLOCK_FLAG_CORE_PRIVATE_MASK;
1934 DecoderProcessSout( p_dec, p_block );
1939 bool b_flush = false;
1943 const bool b_flushing = p_owner->i_preroll_end == INT64_MAX;
1944 DecoderUpdatePreroll( &p_owner->i_preroll_end, p_block );
1946 b_flush = !b_flushing && b_flush_request;
1948 p_block->i_flags &= ~BLOCK_FLAG_CORE_PRIVATE_MASK;
1951 if( p_dec->fmt_in.i_cat == AUDIO_ES )
1953 DecoderProcessAudio( p_dec, p_block, b_flush );
1955 else if( p_dec->fmt_in.i_cat == VIDEO_ES )
1957 DecoderProcessVideo( p_dec, p_block, b_flush );
1959 else if( p_dec->fmt_in.i_cat == SPU_ES )
1961 DecoderProcessSpu( p_dec, p_block, b_flush );
1965 msg_Err( p_dec, "unknown ES format" );
1966 p_dec->b_error = true;
1971 if( b_flush_request )
1972 DecoderProcessOnFlush( p_dec );
1975 static void DecoderError( decoder_t *p_dec, block_t *p_block )
1977 const bool b_flush_request = p_block && (p_block->i_flags & BLOCK_FLAG_CORE_FLUSH);
1981 block_Release( p_block );
1983 if( b_flush_request )
1984 DecoderProcessOnFlush( p_dec );
1989 * Destroys a decoder object
1991 * \param p_dec the decoder object
1994 static void DeleteDecoder( decoder_t * p_dec )
1996 decoder_owner_sys_t *p_owner = p_dec->p_owner;
1998 msg_Dbg( p_dec, "killing decoder fourcc `%4.4s', %u PES in FIFO",
1999 (char*)&p_dec->fmt_in.i_codec,
2000 (unsigned)block_FifoCount( p_owner->p_fifo ) );
2002 /* Free all packets still in the decoder fifo. */
2003 block_FifoEmpty( p_owner->p_fifo );
2004 block_FifoRelease( p_owner->p_fifo );
2007 vlc_mutex_lock( &p_owner->lock );
2008 DecoderFlushBuffering( p_dec );
2009 vlc_mutex_unlock( &p_owner->lock );
2012 if( p_owner->p_aout_input )
2013 aout_DecDelete( p_owner->p_aout, p_owner->p_aout_input );
2014 if( p_owner->p_aout )
2016 input_ressource_RequestAout( p_owner->p_input->p->p_ressource,
2018 input_SendEventAout( p_owner->p_input );
2019 p_owner->p_aout = NULL;
2021 if( p_owner->p_vout )
2023 /* Hack to make sure all the the pictures are freed by the decoder */
2024 vout_FixLeaks( p_owner->p_vout, true );
2027 input_ressource_RequestVout( p_owner->p_input->p->p_ressource, p_owner->p_vout, NULL );
2028 input_SendEventVout( p_owner->p_input );
2032 if( p_owner->p_sout_input )
2034 sout_InputDelete( p_owner->p_sout_input );
2035 es_format_Clean( &p_owner->sout );
2039 if( p_dec->fmt_in.i_cat == SPU_ES )
2041 vout_thread_t *p_vout;
2043 p_vout = input_ressource_HoldVout( p_owner->p_input->p->p_ressource );
2046 if( p_owner->p_spu_vout == p_vout )
2047 spu_Control( p_vout->p_spu, SPU_CHANNEL_CLEAR, p_owner->i_spu_channel );
2048 vlc_object_release( p_vout );
2052 es_format_Clean( &p_dec->fmt_in );
2053 es_format_Clean( &p_dec->fmt_out );
2054 if( p_dec->p_description )
2055 vlc_meta_Delete( p_dec->p_description );
2056 es_format_Clean( &p_owner->fmt_description );
2057 if( p_owner->p_description )
2058 vlc_meta_Delete( p_owner->p_description );
2060 if( p_owner->p_packetizer )
2062 module_unneed( p_owner->p_packetizer,
2063 p_owner->p_packetizer->p_module );
2064 es_format_Clean( &p_owner->p_packetizer->fmt_in );
2065 es_format_Clean( &p_owner->p_packetizer->fmt_out );
2066 if( p_owner->p_packetizer->p_description )
2067 vlc_meta_Delete( p_owner->p_packetizer->p_description );
2068 vlc_object_detach( p_owner->p_packetizer );
2069 vlc_object_release( p_owner->p_packetizer );
2072 vlc_cond_destroy( &p_owner->wait );
2073 vlc_mutex_destroy( &p_owner->lock );
2075 vlc_object_detach( p_dec );
2080 /*****************************************************************************
2081 * Buffers allocation callbacks for the decoders
2082 *****************************************************************************/
2083 static void DecoderUpdateFormatLocked( decoder_t *p_dec )
2085 decoder_owner_sys_t *p_owner = p_dec->p_owner;
2087 vlc_assert_locked( &p_owner->lock );
2089 p_owner->b_fmt_description = true;
2091 /* Copy es_format */
2092 es_format_Clean( &p_owner->fmt_description );
2093 es_format_Copy( &p_owner->fmt_description, &p_dec->fmt_out );
2095 /* Move p_description */
2096 if( p_owner->p_description && p_dec->p_description )
2097 vlc_meta_Delete( p_owner->p_description );
2098 p_owner->p_description = p_dec->p_description;
2099 p_dec->p_description = NULL;
2101 static vout_thread_t *aout_request_vout( void *p_private,
2102 vout_thread_t *p_vout, video_format_t *p_fmt )
2104 decoder_t *p_dec = p_private;
2106 p_vout = input_ressource_RequestVout( p_dec->p_owner->p_input->p->p_ressource, p_vout, p_fmt );
2107 input_SendEventVout( p_dec->p_owner->p_input );
2112 static aout_buffer_t *aout_new_buffer( decoder_t *p_dec, int i_samples )
2114 decoder_owner_sys_t *p_owner = p_dec->p_owner;
2115 aout_buffer_t *p_buffer;
2117 if( p_owner->p_aout_input != NULL &&
2118 ( p_dec->fmt_out.audio.i_rate != p_owner->audio.i_rate ||
2119 p_dec->fmt_out.audio.i_original_channels !=
2120 p_owner->audio.i_original_channels ||
2121 p_dec->fmt_out.audio.i_bytes_per_frame !=
2122 p_owner->audio.i_bytes_per_frame ) )
2124 aout_input_t *p_aout_input = p_owner->p_aout_input;
2126 /* Parameters changed, restart the aout */
2127 vlc_mutex_lock( &p_owner->lock );
2129 DecoderFlushBuffering( p_dec );
2131 p_owner->p_aout_input = NULL;
2132 aout_DecDelete( p_owner->p_aout, p_aout_input );
2134 vlc_mutex_unlock( &p_owner->lock );
2137 if( p_owner->p_aout_input == NULL )
2139 const int i_force_dolby = config_GetInt( p_dec, "force-dolby-surround" );
2140 audio_sample_format_t format;
2141 aout_input_t *p_aout_input;
2142 aout_instance_t *p_aout;
2143 aout_request_vout_t request_vout;
2145 p_dec->fmt_out.audio.i_format = p_dec->fmt_out.i_codec;
2146 p_owner->audio = p_dec->fmt_out.audio;
2148 memcpy( &format, &p_owner->audio, sizeof( audio_sample_format_t ) );
2149 if( i_force_dolby &&
2150 (format.i_original_channels&AOUT_CHAN_PHYSMASK) ==
2151 (AOUT_CHAN_LEFT|AOUT_CHAN_RIGHT) )
2153 if( i_force_dolby == 1 )
2155 format.i_original_channels = format.i_original_channels |
2156 AOUT_CHAN_DOLBYSTEREO;
2158 else /* i_force_dolby == 2 */
2160 format.i_original_channels = format.i_original_channels &
2161 ~AOUT_CHAN_DOLBYSTEREO;
2165 request_vout.pf_request_vout = aout_request_vout;
2166 request_vout.p_private = p_dec;
2168 p_aout = p_owner->p_aout;
2170 p_aout = input_ressource_RequestAout( p_owner->p_input->p->p_ressource, NULL );
2171 p_aout_input = aout_DecNew( p_dec, &p_aout,
2172 &format, &p_dec->fmt_out.audio_replay_gain, &request_vout );
2174 vlc_mutex_lock( &p_owner->lock );
2176 p_owner->p_aout = p_aout;
2177 p_owner->p_aout_input = p_aout_input;
2178 DecoderUpdateFormatLocked( p_dec );
2180 vlc_mutex_unlock( &p_owner->lock );
2182 input_SendEventAout( p_owner->p_input );
2184 if( p_owner->p_aout_input == NULL )
2186 msg_Err( p_dec, "failed to create audio output" );
2187 p_dec->b_error = true;
2190 p_dec->fmt_out.audio.i_bytes_per_frame =
2191 p_owner->audio.i_bytes_per_frame;
2194 p_buffer = aout_DecNewBuffer( p_owner->p_aout_input, i_samples );
2199 static void aout_del_buffer( decoder_t *p_dec, aout_buffer_t *p_buffer )
2201 decoder_owner_sys_t *p_owner = p_dec->p_owner;
2203 aout_DecDeleteBuffer( p_owner->p_aout,
2204 p_owner->p_aout_input, p_buffer );
2208 int vout_CountPictureAvailable( vout_thread_t *p_vout );
2210 static picture_t *vout_new_buffer( decoder_t *p_dec )
2212 decoder_owner_sys_t *p_owner = p_dec->p_owner;
2214 if( p_owner->p_vout == NULL ||
2215 p_dec->fmt_out.video.i_width != p_owner->video.i_width ||
2216 p_dec->fmt_out.video.i_height != p_owner->video.i_height ||
2217 p_dec->fmt_out.video.i_chroma != p_owner->video.i_chroma ||
2218 p_dec->fmt_out.video.i_aspect != p_owner->video.i_aspect )
2220 vout_thread_t *p_vout;
2222 if( !p_dec->fmt_out.video.i_width ||
2223 !p_dec->fmt_out.video.i_height )
2225 /* Can't create a new vout without display size */
2229 if( !p_dec->fmt_out.video.i_visible_width ||
2230 !p_dec->fmt_out.video.i_visible_height )
2232 if( p_dec->fmt_in.video.i_visible_width &&
2233 p_dec->fmt_in.video.i_visible_height )
2235 p_dec->fmt_out.video.i_visible_width =
2236 p_dec->fmt_in.video.i_visible_width;
2237 p_dec->fmt_out.video.i_visible_height =
2238 p_dec->fmt_in.video.i_visible_height;
2242 p_dec->fmt_out.video.i_visible_width =
2243 p_dec->fmt_out.video.i_width;
2244 p_dec->fmt_out.video.i_visible_height =
2245 p_dec->fmt_out.video.i_height;
2249 if( p_dec->fmt_out.video.i_visible_height == 1088 &&
2250 var_CreateGetBool( p_dec, "hdtv-fix" ) )
2252 p_dec->fmt_out.video.i_visible_height = 1080;
2253 p_dec->fmt_out.video.i_sar_num *= 135;
2254 p_dec->fmt_out.video.i_sar_den *= 136;
2255 msg_Warn( p_dec, "Fixing broken HDTV stream (display_height=1088)");
2258 if( !p_dec->fmt_out.video.i_sar_num ||
2259 !p_dec->fmt_out.video.i_sar_den )
2261 p_dec->fmt_out.video.i_sar_num = p_dec->fmt_out.video.i_aspect *
2262 p_dec->fmt_out.video.i_visible_height;
2264 p_dec->fmt_out.video.i_sar_den = VOUT_ASPECT_FACTOR *
2265 p_dec->fmt_out.video.i_visible_width;
2268 vlc_ureduce( &p_dec->fmt_out.video.i_sar_num,
2269 &p_dec->fmt_out.video.i_sar_den,
2270 p_dec->fmt_out.video.i_sar_num,
2271 p_dec->fmt_out.video.i_sar_den, 50000 );
2273 p_dec->fmt_out.video.i_chroma = p_dec->fmt_out.i_codec;
2274 p_owner->video = p_dec->fmt_out.video;
2276 vlc_mutex_lock( &p_owner->lock );
2278 DecoderFlushBuffering( p_dec );
2280 p_vout = p_owner->p_vout;
2281 p_owner->p_vout = NULL;
2282 vlc_mutex_unlock( &p_owner->lock );
2284 p_vout = input_ressource_RequestVout( p_owner->p_input->p->p_ressource,
2285 p_vout, &p_dec->fmt_out.video );
2287 vlc_mutex_lock( &p_owner->lock );
2288 p_owner->p_vout = p_vout;
2290 DecoderUpdateFormatLocked( p_dec );
2292 vlc_mutex_unlock( &p_owner->lock );
2294 input_SendEventVout( p_owner->p_input );
2295 if( p_vout == NULL )
2297 msg_Err( p_dec, "failed to create video output" );
2298 p_dec->b_error = true;
2302 if( p_owner->video.i_rmask )
2303 p_owner->p_vout->render.i_rmask = p_owner->video.i_rmask;
2304 if( p_owner->video.i_gmask )
2305 p_owner->p_vout->render.i_gmask = p_owner->video.i_gmask;
2306 if( p_owner->video.i_bmask )
2307 p_owner->p_vout->render.i_bmask = p_owner->video.i_bmask;
2310 /* Get a new picture
2314 picture_t *p_picture;
2316 if( p_dec->b_die || p_dec->b_error )
2319 /* The video filter chain required that there is always 1 free buffer
2320 * that it will use as temporary one. It will release the temporary
2321 * buffer once its work is done, so this check is safe even if we don't
2322 * lock around both count() and create().
2324 if( vout_CountPictureAvailable( p_owner->p_vout ) >= 2 )
2326 p_picture = vout_CreatePicture( p_owner->p_vout, 0, 0, 0 );
2331 if( DecoderIsFlushing( p_dec ) )
2335 DecoderSignalBuffering( p_dec, true );
2337 /* Check the decoder doesn't leak pictures */
2338 vout_FixLeaks( p_owner->p_vout, false );
2340 /* FIXME add a vout_WaitPictureAvailable (timedwait) */
2341 msleep( VOUT_OUTMEM_SLEEP );
2345 static void vout_del_buffer( decoder_t *p_dec, picture_t *p_pic )
2347 vout_DropPicture( p_dec->p_owner->p_vout, p_pic );
2350 static void vout_link_picture( decoder_t *p_dec, picture_t *p_pic )
2352 vout_LinkPicture( p_dec->p_owner->p_vout, p_pic );
2355 static void vout_unlink_picture( decoder_t *p_dec, picture_t *p_pic )
2357 vout_UnlinkPicture( p_dec->p_owner->p_vout, p_pic );
2360 static subpicture_t *spu_new_buffer( decoder_t *p_dec )
2362 decoder_owner_sys_t *p_owner = p_dec->p_owner;
2363 vout_thread_t *p_vout = NULL;
2364 subpicture_t *p_subpic;
2365 int i_attempts = 30;
2367 while( i_attempts-- )
2369 if( p_dec->b_die || p_dec->b_error )
2372 p_vout = input_ressource_HoldVout( p_owner->p_input->p->p_ressource );
2376 msleep( DECODER_SPU_VOUT_WAIT_DURATION );
2381 msg_Warn( p_dec, "no vout found, dropping subpicture" );
2385 if( p_owner->p_spu_vout != p_vout )
2387 vlc_mutex_lock( &p_owner->lock );
2389 DecoderFlushBuffering( p_dec );
2391 vlc_mutex_unlock( &p_owner->lock );
2393 spu_Control( p_vout->p_spu, SPU_CHANNEL_REGISTER,
2394 &p_owner->i_spu_channel );
2395 p_owner->i_spu_order = 0;
2396 p_owner->p_spu_vout = p_vout;
2399 p_subpic = subpicture_New();
2402 p_subpic->i_channel = p_owner->i_spu_channel;
2403 p_subpic->i_order = p_owner->i_spu_order++;
2404 p_subpic->b_subtitle = true;
2407 vlc_object_release( p_vout );
2412 static void spu_del_buffer( decoder_t *p_dec, subpicture_t *p_subpic )
2414 decoder_owner_sys_t *p_owner = p_dec->p_owner;
2415 vout_thread_t *p_vout = NULL;
2417 p_vout = input_ressource_HoldVout( p_owner->p_input->p->p_ressource );
2418 if( !p_vout || p_owner->p_spu_vout != p_vout )
2421 vlc_object_release( p_vout );
2422 msg_Warn( p_dec, "no vout found, leaking subpicture" );
2426 subpicture_Delete( p_subpic );
2428 vlc_object_release( p_vout );