1 /*****************************************************************************
2 * input_programs.c: es_descriptor_t, pgrm_descriptor_t management
3 *****************************************************************************
4 * Copyright (C) 1999-2002 VideoLAN
5 * $Id: input_programs.c,v 1.112 2003/05/15 23:05:59 gbazin Exp $
7 * Authors: Christophe Massiot <massiot@via.ecp.fr>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
22 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
28 #include <string.h> /* memcpy(), memset() */
32 #include "stream_control.h"
33 #include "input_ext-intf.h"
34 #include "input_ext-dec.h"
35 #include "input_ext-plugins.h"
38 * NOTICE : all of these functions expect you to have taken the lock on
39 * p_input->stream.lock
42 /* Navigation callbacks */
43 static int ProgramCallback( vlc_object_t *, char const *,
44 vlc_value_t, vlc_value_t, void * );
45 static int TitleCallback( vlc_object_t *, char const *,
46 vlc_value_t, vlc_value_t, void * );
47 static int ChapterCallback( vlc_object_t *, char const *,
48 vlc_value_t, vlc_value_t, void * );
49 static int NavigationCallback( vlc_object_t *, char const *,
50 vlc_value_t, vlc_value_t, void * );
51 static int ESCallback( vlc_object_t *, char const *,
52 vlc_value_t, vlc_value_t, void * );
54 /*****************************************************************************
55 * input_InitStream: init the stream descriptor of the given input
56 *****************************************************************************/
57 int input_InitStream( input_thread_t * p_input, size_t i_data_len )
61 p_input->stream.i_stream_id = 0;
63 /* initialized to 0 since we don't give the signal to the interface
64 * before the end of input initialization */
65 p_input->stream.b_changed = 0;
66 p_input->stream.pp_es = NULL;
67 p_input->stream.pp_selected_es = NULL;
68 p_input->stream.p_removed_es = NULL;
69 p_input->stream.p_newly_selected_es = NULL;
70 p_input->stream.pp_programs = NULL;
71 p_input->stream.p_selected_program = NULL;
72 p_input->stream.p_new_program = NULL;
76 if ( (p_input->stream.p_demux_data = malloc( i_data_len )) == NULL )
78 msg_Err( p_input, "out of memory" );
81 memset( p_input->stream.p_demux_data, 0, i_data_len );
85 p_input->stream.p_demux_data = NULL;
88 var_Create( p_input, "intf-change", VLC_VAR_BOOL );
89 val.b_bool = VLC_TRUE;
90 var_Set( p_input, "intf-change", val );
92 /* Create a few object variables used for navigation in the interfaces */
93 var_Create( p_input, "program", VLC_VAR_INTEGER | VLC_VAR_HASCHOICE );
94 text.psz_string = _("Program");
95 var_Change( p_input, "program", VLC_VAR_SETTEXT, &text, NULL );
97 var_Create( p_input, "title", VLC_VAR_INTEGER | VLC_VAR_HASCHOICE );
98 text.psz_string = _("Title");
99 var_Change( p_input, "title", VLC_VAR_SETTEXT, &text, NULL );
100 var_Create( p_input, "next-title", VLC_VAR_VOID );
101 text.psz_string = _("Next title");
102 var_Change( p_input, "next-title", VLC_VAR_SETTEXT, &text, NULL );
103 var_Create( p_input, "prev-title", VLC_VAR_VOID );
104 text.psz_string = _("Previous title");
105 var_Change( p_input, "prev-title", VLC_VAR_SETTEXT, &text, NULL );
107 var_Create( p_input, "chapter", VLC_VAR_INTEGER | VLC_VAR_HASCHOICE );
108 text.psz_string = _("Chapter");
109 var_Change( p_input, "chapter", VLC_VAR_SETTEXT, &text, NULL );
110 var_Create( p_input, "next-chapter", VLC_VAR_VOID );
111 text.psz_string = _("Next Chapter");
112 var_Change( p_input, "next-chapter", VLC_VAR_SETTEXT, &text, NULL );
113 var_Create( p_input, "prev-chapter", VLC_VAR_VOID );
114 text.psz_string = _("Previous Chapter");
115 var_Change( p_input, "prev-chapter", VLC_VAR_SETTEXT, &text, NULL );
117 var_Create( p_input, "navigation", VLC_VAR_VARIABLE | VLC_VAR_HASCHOICE );
118 text.psz_string = _("Navigation");
119 var_Change( p_input, "navigation", VLC_VAR_SETTEXT, &text, NULL );
121 var_Create( p_input, "video-es", VLC_VAR_INTEGER | VLC_VAR_HASCHOICE );
122 text.psz_string = _("Video track");
123 var_Change( p_input, "video-es", VLC_VAR_SETTEXT, &text, NULL );
124 var_Create( p_input, "audio-es", VLC_VAR_INTEGER | VLC_VAR_HASCHOICE );
125 text.psz_string = _("Audio track");
126 var_Change( p_input, "audio-es", VLC_VAR_SETTEXT, &text, NULL );
127 var_Create( p_input, "spu-es", VLC_VAR_INTEGER | VLC_VAR_HASCHOICE );
128 text.psz_string = _("Subtitles track");
129 var_Change( p_input, "spu-es", VLC_VAR_SETTEXT, &text, NULL );
131 var_AddCallback( p_input, "program", ProgramCallback, NULL );
132 var_AddCallback( p_input, "title", TitleCallback, NULL );
133 var_AddCallback( p_input, "next-title", TitleCallback, NULL );
134 var_AddCallback( p_input, "prev-title", TitleCallback, NULL );
135 var_AddCallback( p_input, "chapter", ChapterCallback, NULL );
136 var_AddCallback( p_input, "next-chapter", ChapterCallback, NULL );
137 var_AddCallback( p_input, "prev-chapter", ChapterCallback, NULL );
138 var_AddCallback( p_input, "video-es", ESCallback, NULL );
139 var_AddCallback( p_input, "audio-es", ESCallback, NULL );
140 var_AddCallback( p_input, "spu-es", ESCallback, NULL );
145 /*****************************************************************************
146 * input_EndStream: free all stream descriptors
147 *****************************************************************************/
148 void input_EndStream( input_thread_t * p_input )
150 /* Free all programs and associated ES, and associated decoders. */
151 while( p_input->stream.i_pgrm_number )
153 input_DelProgram( p_input, p_input->stream.pp_programs[0] );
156 /* Free standalone ES */
157 while( p_input->stream.i_es_number )
159 input_DelES( p_input, p_input->stream.pp_es[0] );
163 while( p_input->stream.i_area_nb )
165 input_DelArea( p_input, p_input->stream.pp_areas[0] );
168 /* Free selected ES */
169 if( p_input->stream.pp_selected_es != NULL )
171 free( p_input->stream.pp_selected_es );
174 if( p_input->stream.p_demux_data != NULL )
176 free( p_input->stream.p_demux_data );
179 /* Free navigation variables */
180 var_Destroy( p_input, "program" );
181 var_Destroy( p_input, "title" );
182 var_Destroy( p_input, "chapter" );
183 var_Destroy( p_input, "video-es" );
184 var_Destroy( p_input, "audio-es" );
185 var_Destroy( p_input, "spu-es" );
186 var_Destroy( p_input, "intf-change" );
189 /*****************************************************************************
190 * input_FindProgram: returns a pointer to a program described by its ID
191 *****************************************************************************/
192 pgrm_descriptor_t * input_FindProgram( input_thread_t * p_input,
197 for( i = 0; i < p_input->stream.i_pgrm_number; i++ )
199 if( p_input->stream.pp_programs[i]->i_number == i_pgrm_id )
201 return p_input->stream.pp_programs[i];
208 /*****************************************************************************
209 * input_AddProgram: add and init a program descriptor
210 *****************************************************************************
211 * This program descriptor will be referenced in the given stream descriptor
212 *****************************************************************************/
213 pgrm_descriptor_t * input_AddProgram( input_thread_t * p_input,
214 u16 i_pgrm_id, size_t i_data_len )
216 /* Where to add the pgrm */
217 pgrm_descriptor_t * p_pgrm = malloc( sizeof(pgrm_descriptor_t) );
222 msg_Err( p_input, "out of memory" );
226 /* Init this entry */
227 p_pgrm->i_number = i_pgrm_id;
229 p_pgrm->i_version = 0;
231 p_pgrm->i_es_number = 0;
232 p_pgrm->pp_es = NULL;
234 input_ClockInit( p_pgrm );
236 p_pgrm->i_synchro_state = SYNCHRO_START;
240 p_pgrm->p_demux_data = malloc( i_data_len );
241 if( p_pgrm->p_demux_data == NULL )
243 msg_Err( p_input, "out of memory" );
246 memset( p_pgrm->p_demux_data, 0, i_data_len );
250 p_pgrm->p_demux_data = NULL;
253 /* Add an entry to the list of program associated with the stream */
254 INSERT_ELEM( p_input->stream.pp_programs,
255 p_input->stream.i_pgrm_number,
256 p_input->stream.i_pgrm_number,
259 val.i_int = i_pgrm_id;
260 var_Change( p_input, "program", VLC_VAR_ADDCHOICE, &val, NULL );
265 /*****************************************************************************
266 * input_DelProgram: destroy a program descriptor
267 *****************************************************************************
268 * All ES descriptions referenced in the descriptor will be deleted.
269 *****************************************************************************/
270 void input_DelProgram( input_thread_t * p_input, pgrm_descriptor_t * p_pgrm )
272 unsigned int i_pgrm_index;
275 /* Find the program in the programs table */
276 for( i_pgrm_index = 0; i_pgrm_index < p_input->stream.i_pgrm_number;
279 if( p_input->stream.pp_programs[i_pgrm_index] == p_pgrm )
283 /* If the program wasn't found, do nothing */
284 if( i_pgrm_index == p_input->stream.i_pgrm_number )
286 msg_Err( p_input, "program does not belong to this input" );
290 val.i_int = i_pgrm_index;
291 var_Change( p_input, "program", VLC_VAR_DELCHOICE, &val, NULL );
293 /* Free the structures that describe the es that belongs to that program */
294 while( p_pgrm->i_es_number )
296 input_DelES( p_input, p_pgrm->pp_es[0] );
299 /* Free the demux data */
300 if( p_pgrm->p_demux_data != NULL )
302 free( p_pgrm->p_demux_data );
305 /* Remove this program from the stream's list of programs */
306 REMOVE_ELEM( p_input->stream.pp_programs,
307 p_input->stream.i_pgrm_number,
310 /* Free the description of this program */
314 /*****************************************************************************
315 * input_AddArea: add and init an area descriptor
316 *****************************************************************************
317 * This area descriptor will be referenced in the given stream descriptor
318 *****************************************************************************/
319 input_area_t * input_AddArea( input_thread_t * p_input,
320 uint16_t i_area_id, uint16_t i_part_nb )
322 /* Where to add the pgrm */
323 input_area_t * p_area = malloc( sizeof(input_area_t) );
329 msg_Err( p_input, "out of memory" );
333 /* Init this entry */
334 p_area->i_id = i_area_id;
335 p_area->i_part_nb = i_part_nb;
340 p_area->i_seek = NO_SEEK;
342 /* Add an entry to the list of program associated with the stream */
343 INSERT_ELEM( p_input->stream.pp_areas,
344 p_input->stream.i_area_nb,
345 p_input->stream.i_area_nb,
348 /* Don't add empty areas */
352 /* Take care of the navigation variables */
353 val.i_int = i_area_id;
354 var_Change( p_input, "title", VLC_VAR_ADDCHOICE, &val, NULL );
356 val.psz_string = malloc( sizeof("title ") + 5 );
359 vlc_value_t val2, text, text2;
361 sprintf( val.psz_string, "title %2i", i_area_id );
362 var_Destroy( p_input, val.psz_string );
363 var_Create( p_input, val.psz_string, VLC_VAR_INTEGER |
364 VLC_VAR_HASCHOICE | VLC_VAR_ISCOMMAND );
365 var_AddCallback( p_input, val.psz_string, NavigationCallback,
366 (void *)(int)i_area_id );
368 text.psz_string = malloc( strlen( _("Title %i") ) + 20 );
369 if( text.psz_string )
370 sprintf( text.psz_string, _("Title %i"), i_area_id );
372 var_Change( p_input, "navigation", VLC_VAR_ADDCHOICE, &val, &text );
374 if( text.psz_string ) free( text.psz_string );
376 text2.psz_string = malloc( strlen( _("Chapter %i") ) + 20 );
378 for( i = 1; i <= i_part_nb; i++ )
382 if( text2.psz_string )
383 sprintf( text2.psz_string, _("Chapter %i"), i );
385 var_Change( p_input, val.psz_string,
386 VLC_VAR_ADDCHOICE, &val2, &text2 );
389 if( text2.psz_string ) free( text2.psz_string );
395 /*****************************************************************************
396 * input_SetProgram: changes the current program
397 *****************************************************************************/
398 int input_SetProgram( input_thread_t * p_input, pgrm_descriptor_t * p_new_prg )
400 unsigned int i_es_index;
401 int i_required_audio_es;
402 int i_required_spu_es;
407 if ( p_input->stream.p_selected_program )
409 for ( i_es_index = 1 ; /* 0 should be the PMT */
410 i_es_index < p_input->stream.p_selected_program->
414 #define p_es p_input->stream.p_selected_program->pp_es[i_es_index]
415 if ( p_es->p_decoder_fifo ) /* if the ES was selected */
417 input_UnselectES( p_input , p_es );
422 /* Get the number of the required audio stream */
423 if( config_GetInt( p_input, "audio" ) )
425 /* Default is the first one */
426 i_required_audio_es = config_GetInt( p_input, "audio-channel" );
427 if( i_required_audio_es < 0 )
429 i_required_audio_es = 1;
434 i_required_audio_es = 0;
437 /* Same thing for subtitles */
438 if( config_GetInt( p_input, "video" ) )
440 /* for spu, default is none */
441 i_required_spu_es = config_GetInt( p_input, "spu-channel" );
442 if( i_required_spu_es < 0 )
444 i_required_spu_es = 0;
449 i_required_spu_es = 0;
452 for( i_es_index = 0 ; i_es_index < p_new_prg->i_es_number ; i_es_index ++ )
454 switch( p_new_prg->pp_es[i_es_index]->i_cat )
457 msg_Dbg( p_input, "selecting ES %x",
458 p_new_prg->pp_es[i_es_index]->i_id );
459 input_SelectES( p_input, p_new_prg->pp_es[i_es_index] );
463 if( i_audio_es <= i_required_audio_es )
465 msg_Dbg( p_input, "selecting ES %x",
466 p_new_prg->pp_es[i_es_index]->i_id );
467 input_SelectES( p_input, p_new_prg->pp_es[i_es_index]);
470 /* Not sure this one is fully specification-compliant */
473 if( i_spu_es <= i_required_spu_es )
475 msg_Dbg( p_input, "selecting ES %x",
476 p_new_prg->pp_es[i_es_index]->i_id );
477 input_SelectES( p_input, p_new_prg->pp_es[i_es_index] );
481 msg_Dbg( p_input, "ES %x has unknown type",
482 p_new_prg->pp_es[i_es_index]->i_id );
489 p_input->stream.p_selected_program = p_new_prg;
491 /* Update the navigation variables without triggering a callback */
492 val.i_int = p_new_prg->i_number;
493 var_Change( p_input, "program", VLC_VAR_SETVALUE, &val, NULL );
498 /*****************************************************************************
499 * input_DelArea: destroy a area descriptor
500 *****************************************************************************
501 * All ES descriptions referenced in the descriptor will be deleted.
502 *****************************************************************************/
503 void input_DelArea( input_thread_t * p_input, input_area_t * p_area )
505 unsigned int i_area_index;
508 /* Find the area in the areas table */
509 for( i_area_index = 0; i_area_index < p_input->stream.i_area_nb;
512 if( p_input->stream.pp_areas[i_area_index] == p_area )
516 /* If the area wasn't found, do nothing */
517 if( i_area_index == p_input->stream.i_area_nb )
519 msg_Err( p_input, "area does not belong to this input" );
523 /* Take care of the navigation variables */
524 val.psz_string = malloc( sizeof("title ") + 5 );
527 sprintf( val.psz_string, "title %i", p_area->i_id );
528 var_Change( p_input, "navigation", VLC_VAR_DELCHOICE, &val, NULL );
529 var_Destroy( p_input, val.psz_string );
532 /* Remove this area from the stream's list of areas */
533 REMOVE_ELEM( p_input->stream.pp_areas,
534 p_input->stream.i_area_nb,
537 /* Free the description of this area */
542 /*****************************************************************************
543 * input_FindES: returns a pointer to an ES described by its ID
544 *****************************************************************************/
545 es_descriptor_t * input_FindES( input_thread_t * p_input, uint16_t i_es_id )
549 for( i = 0; i < p_input->stream.i_es_number; i++ )
551 if( p_input->stream.pp_es[i]->i_id == i_es_id )
553 return p_input->stream.pp_es[i];
560 /*****************************************************************************
562 *****************************************************************************
563 * Reserve a slot in the table of ES descriptors for the ES and add it to the
564 * list of ES of p_pgrm. If p_pgrm if NULL, then the ES is considered as stand
566 *****************************************************************************/
567 es_descriptor_t * input_AddES( input_thread_t * p_input,
568 pgrm_descriptor_t * p_pgrm, u16 i_es_id,
569 int i_category, char const *psz_desc,
572 es_descriptor_t * p_es;
573 vlc_value_t val, text;
574 char *psz_var = NULL;
576 p_es = (es_descriptor_t *)malloc( sizeof(es_descriptor_t) );
579 msg_Err( p_input, "out of memory" );
583 INSERT_ELEM( p_input->stream.pp_es,
584 p_input->stream.i_es_number,
585 p_input->stream.i_es_number,
588 /* Init its values */
589 p_es->i_id = i_es_id;
591 p_es->p_decoder_fifo = NULL;
592 p_es->i_cat = i_category;
593 p_es->i_demux_fd = 0;
595 p_es->c_invalid_packets = 0;
596 p_es->b_force_decoder = VLC_FALSE;
600 p_es->p_demux_data = malloc( i_data_len );
601 if( p_es->p_demux_data == NULL )
603 msg_Err( p_input, "out of memory" );
606 memset( p_es->p_demux_data, 0, i_data_len );
610 p_es->p_demux_data = NULL;
612 p_es->p_waveformatex = NULL;
613 p_es->p_bitmapinfoheader = NULL;
615 /* Add this ES to the program definition if one is given */
618 INSERT_ELEM( p_pgrm->pp_es,
622 p_es->p_pgrm = p_pgrm;
632 psz_var = "audio-es";
638 psz_var = "video-es";
644 /* Get the number of ES already added */
645 var_Change( p_input, psz_var, VLC_VAR_CHOICESCOUNT, &val, NULL );
650 /* First one, we need to add the "Disable" choice */
651 val2.i_int = -1; text.psz_string = _("Disable");
652 var_Change( p_input, psz_var, VLC_VAR_ADDCHOICE, &val2, &text );
656 /* Take care of the ES description */
659 p_es->psz_desc = strdup( psz_desc );
663 p_es->psz_desc = malloc( strlen( _("Track %i") ) + 20 );
665 sprintf( p_es->psz_desc, _("Track %i"), val.i_int );
668 val.i_int = p_es->i_id;
669 text.psz_string = p_es->psz_desc;
670 var_Change( p_input, psz_var, VLC_VAR_ADDCHOICE, &val, &text );
672 else p_es->psz_desc = NULL;
677 /*****************************************************************************
679 *****************************************************************************/
680 void input_DelES( input_thread_t * p_input, es_descriptor_t * p_es )
682 unsigned int i_index, i_es_index;
683 pgrm_descriptor_t * p_pgrm;
684 char * psz_var = NULL;
687 /* Find the ES in the ES table */
688 for( i_es_index = 0; i_es_index < p_input->stream.i_es_number;
691 if( p_input->stream.pp_es[i_es_index] == p_es )
695 /* If the ES wasn't found, do nothing */
696 if( i_es_index == p_input->stream.i_es_number )
698 msg_Err( p_input, "ES does not belong to this input" );
702 /* Remove es from its associated variable */
703 switch( p_es->i_cat )
706 psz_var = "audio-es";
712 psz_var = "video-es";
718 val.i_int = p_es->i_id;
719 var_Change( p_input, psz_var, VLC_VAR_DELCHOICE, &val, NULL );
721 /* Remove the "Disable" entry if needed */
722 var_Change( p_input, psz_var, VLC_VAR_CHOICESCOUNT, &val, NULL );
726 var_Change( p_input, psz_var, VLC_VAR_DELCHOICE, &val, NULL );
730 /* Kill associated decoder, if any. */
731 if( p_es->p_decoder_fifo != NULL )
733 input_EndDecoder( p_input, p_es );
736 /* Remove this ES from the description of the program if it is associated
738 p_pgrm = p_es->p_pgrm;
741 for( i_index = 0; i_index < p_pgrm->i_es_number; i_index++ )
743 if( p_pgrm->pp_es[i_index] == p_es )
745 REMOVE_ELEM( p_pgrm->pp_es,
753 /* Free the demux data */
754 if( p_es->p_demux_data != NULL )
756 free( p_es->p_demux_data );
758 if( p_es->p_waveformatex )
760 free( p_es->p_waveformatex );
762 if( p_es->p_bitmapinfoheader )
764 free( p_es->p_bitmapinfoheader );
767 /* Free the description string */
768 if( p_es->psz_desc != NULL )
770 free( p_es->psz_desc );
773 /* Find the ES in the ES table */
774 for( i_es_index = 0; i_es_index < p_input->stream.i_es_number;
777 if( p_input->stream.pp_es[i_es_index] == p_es )
781 /* Remove this ES from the stream's list of ES */
782 REMOVE_ELEM( p_input->stream.pp_es,
783 p_input->stream.i_es_number,
790 /*****************************************************************************
791 * input_SelectES: selects an ES and spawns the associated decoder
792 *****************************************************************************
793 * Remember we are still supposed to have stream_lock when entering this
795 *****************************************************************************/
796 int input_SelectES( input_thread_t * p_input, es_descriptor_t * p_es )
799 char *psz_var = NULL;
803 msg_Err( p_input, "nothing to do in input_SelectES" );
807 if( ((p_es->i_cat == VIDEO_ES) || (p_es->i_cat == SPU_ES))
808 && !config_GetInt( p_input, "video" ) )
811 "video is disabled, not selecting ES 0x%x", p_es->i_id );
815 if( (p_es->i_cat == AUDIO_ES) && !config_GetInt( p_input, "audio" ) )
818 "audio is disabled, not selecting ES 0x%x", p_es->i_id );
822 msg_Dbg( p_input, "selecting ES 0x%x", p_es->i_id );
824 if( p_es->p_decoder_fifo != NULL )
826 msg_Err( p_input, "ES 0x%x is already selected", p_es->i_id );
830 /* Release the lock, not to block the input thread during
831 * the creation of the thread. */
832 vlc_mutex_unlock( &p_input->stream.stream_lock );
833 p_es->p_decoder_fifo = input_RunDecoder( p_input, p_es );
834 vlc_mutex_lock( &p_input->stream.stream_lock );
836 if( p_es->p_decoder_fifo == NULL )
841 /* Update the es variable without triggering a callback */
842 switch( p_es->i_cat )
845 psz_var = "audio-es";
851 psz_var = "video-es";
857 val.i_int = p_es->i_id;
858 var_Change( p_input, psz_var, VLC_VAR_SETVALUE, &val, NULL );
864 /*****************************************************************************
865 * input_UnselectES: removes an ES from the list of selected ES
866 *****************************************************************************/
867 int input_UnselectES( input_thread_t * p_input, es_descriptor_t * p_es )
869 unsigned int i_index = 0;
871 char *psz_var = NULL;
875 msg_Err( p_input, "nothing to do in input_UnselectES" );
879 msg_Dbg( p_input, "unselecting ES 0x%x", p_es->i_id );
881 if( p_es->p_decoder_fifo == NULL )
883 msg_Err( p_input, "ES 0x%x is not selected", p_es->i_id );
887 /* Update the es variable without triggering a callback */
888 switch( p_es->i_cat )
891 psz_var = "audio-es";
897 psz_var = "video-es";
904 var_Change( p_input, psz_var, VLC_VAR_SETVALUE, &val, NULL );
907 /* Actually unselect the ES */
908 input_EndDecoder( p_input, p_es );
911 if( ( p_es->p_decoder_fifo == NULL ) &&
912 ( p_input->stream.i_selected_es_number > 0 ) )
914 while( ( i_index < p_input->stream.i_selected_es_number - 1 ) &&
915 ( p_input->stream.pp_selected_es[i_index] != p_es ) )
920 /* XXX: no need to memmove, we have unsorted data */
921 REMOVE_ELEM( p_input->stream.pp_selected_es,
922 p_input->stream.i_selected_es_number,
925 if( p_input->stream.i_selected_es_number == 0 )
927 msg_Dbg( p_input, "no more selected ES" );
935 /*****************************************************************************
936 * Navigation callback: a bunch of navigation variables are used as an
937 * alternative to the navigation API.
938 *****************************************************************************/
939 static int ProgramCallback( vlc_object_t *p_this, char const *psz_cmd,
940 vlc_value_t oldval, vlc_value_t newval, void *p_data )
942 input_thread_t *p_input = (input_thread_t *)p_this;
945 if( oldval.i_int == newval.i_int )
948 vlc_mutex_lock( &p_input->stream.stream_lock );
949 if( ( newval.i_int > 0 ) )
951 vlc_mutex_unlock( &p_input->stream.stream_lock );
952 input_ChangeProgram( p_input, (uint16_t)newval.i_int );
953 input_SetStatus( p_input, INPUT_STATUS_PLAY );
954 vlc_mutex_lock( &p_input->stream.stream_lock );
956 vlc_mutex_unlock( &p_input->stream.stream_lock );
958 val.b_bool = VLC_TRUE;
959 var_Set( p_input, "intf-change", val );
964 static int TitleCallback( vlc_object_t *p_this, char const *psz_cmd,
965 vlc_value_t oldval, vlc_value_t newval, void *p_data )
967 input_thread_t *p_input = (input_thread_t *)p_this;
968 input_area_t *p_area;
969 vlc_value_t val, val_list;
972 if( !strcmp( psz_cmd, "next-title" ) ) i_step++;
973 else if( !strcmp( psz_cmd, "prev-title" ) ) i_step--;
975 if( !i_step && oldval.i_int == newval.i_int ) return VLC_SUCCESS;
977 /* Sanity check should have already been done by var_Set(). */
978 vlc_mutex_lock( &p_input->stream.stream_lock );
982 var_Get( p_this, "title", &newval );
983 var_Change( p_this, "title", VLC_VAR_GETCHOICES, &val_list, NULL );
984 for( i = 0; i < val_list.p_list->i_count; i++ )
986 if( val_list.p_list->p_values[i].i_int == newval.i_int &&
987 i + i_step >= 0 && i + i_step < val_list.p_list->i_count )
989 newval.i_int = val_list.p_list->p_values[i + i_step].i_int;
993 var_Change( p_this, "title", VLC_VAR_FREELIST, &val_list, NULL );
996 p_area = p_input->stream.pp_areas[newval.i_int];
999 vlc_mutex_unlock( &p_input->stream.stream_lock );
1001 input_ChangeArea( p_input, p_area );
1002 input_SetStatus( p_input, INPUT_STATUS_PLAY );
1004 val.b_bool = VLC_TRUE;
1005 var_Set( p_input, "intf-change", val );
1010 static int ChapterCallback( vlc_object_t *p_this, char const *psz_cmd,
1011 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1013 input_thread_t *p_input = (input_thread_t *)p_this;
1014 input_area_t *p_area;
1015 vlc_value_t val, val_list;
1018 if( !strcmp( psz_cmd, "next-chapter" ) ) i_step++;
1019 else if( !strcmp( psz_cmd, "prev-chapter" ) ) i_step--;
1021 if( !i_step && oldval.i_int == newval.i_int ) return VLC_SUCCESS;
1023 /* Sanity check should have already been done by var_Set(). */
1024 vlc_mutex_lock( &p_input->stream.stream_lock );
1028 var_Get( p_this, "chapter", &newval );
1029 var_Change( p_this, "chapter", VLC_VAR_GETCHOICES, &val_list, NULL );
1030 for( i = 0; i < val_list.p_list->i_count; i++ )
1032 if( val_list.p_list->p_values[i].i_int == newval.i_int &&
1033 i + i_step >= 0 && i + i_step < val_list.p_list->i_count )
1035 newval.i_int = val_list.p_list->p_values[i + i_step].i_int;
1039 var_Change( p_this, "chapter", VLC_VAR_FREELIST, &val_list, NULL );
1042 p_area = p_input->stream.p_selected_area;
1043 p_input->stream.p_selected_area->i_part = newval.i_int;
1044 vlc_mutex_unlock( &p_input->stream.stream_lock );
1046 input_ChangeArea( p_input, p_area );
1047 input_SetStatus( p_input, INPUT_STATUS_PLAY );
1049 val.b_bool = VLC_TRUE;
1050 var_Set( p_input, "intf-change", val );
1055 static int NavigationCallback( vlc_object_t *p_this, char const *psz_cmd,
1056 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1058 input_thread_t *p_input = (input_thread_t *)p_this;
1059 uint16_t i_area_id = (int)p_data;
1062 vlc_mutex_lock( &p_input->stream.stream_lock );
1064 if( p_input->stream.p_selected_area->i_id == i_area_id &&
1065 oldval.i_int == newval.i_int )
1068 vlc_mutex_unlock( &p_input->stream.stream_lock );
1072 if( ( i_area_id < p_input->stream.i_area_nb ) && ( newval.i_int > 0 ) &&
1073 ( (uint16_t)newval.i_int <=
1074 p_input->stream.pp_areas[i_area_id]->i_part_nb ) )
1076 input_area_t *p_area = p_input->stream.pp_areas[i_area_id];
1077 p_area->i_part = newval.i_int;
1078 vlc_mutex_unlock( &p_input->stream.stream_lock );
1079 input_ChangeArea( p_input, p_area );
1080 input_SetStatus( p_input, INPUT_STATUS_PLAY );
1081 vlc_mutex_lock( &p_input->stream.stream_lock );
1083 vlc_mutex_unlock( &p_input->stream.stream_lock );
1085 val.b_bool = VLC_TRUE;
1086 var_Set( p_input, "intf-change", val );
1091 static int ESCallback( vlc_object_t *p_this, char const *psz_cmd,
1092 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1094 input_thread_t *p_input = (input_thread_t *)p_this;
1098 vlc_mutex_lock( &p_input->stream.stream_lock );
1100 /* Unselect old ES */
1101 for( i = 0 ; i < p_input->stream.i_es_number ; i++ )
1103 if( p_input->stream.pp_es[i]->i_id == oldval.i_int &&
1104 p_input->stream.pp_es[i]->p_decoder_fifo != NULL )
1106 input_UnselectES( p_input, p_input->stream.pp_es[i] );
1111 for( i = 0 ; i < p_input->stream.i_es_number ; i++ )
1113 if( p_input->stream.pp_es[i]->i_id == newval.i_int &&
1114 p_input->stream.pp_es[i]->p_decoder_fifo == NULL )
1116 input_SelectES( p_input, p_input->stream.pp_es[i] );
1120 vlc_mutex_unlock( &p_input->stream.stream_lock );
1122 val.b_bool = VLC_TRUE;
1123 var_Set( p_input, "intf-change", val );