1 /*****************************************************************************
2 * input_programs.c: es_descriptor_t, pgrm_descriptor_t management
3 *****************************************************************************
4 * Copyright (C) 1999, 2000 VideoLAN
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
21 *****************************************************************************/
23 /*****************************************************************************
25 *****************************************************************************/
27 /*****************************************************************************
28 * input_InitStream: init the stream descriptor of the given input
29 *****************************************************************************/
30 void input_InitStream( input_thread_t * p_input )
32 p_input->stream->i_pgrm_number = 0;
33 p_input->stream->pp_programs = NULL;
36 /*****************************************************************************
37 * input_AddProgram: add and init a program descriptor
38 *****************************************************************************
39 * This program descriptor will be referenced in the given stream descriptor
40 *****************************************************************************/
41 pgrm_descriptor_t * input_AddProgram( input_thread_t * p_input,
44 int i_pgrm_index = p_stream->i_pgrm_number; /* Where to add the pgrm */
46 intf_DbgMsg("Adding description for pgrm %d", i_pgrm_id);
48 /* Add an entry to the list of program associated with the stream */
49 p_input->stream.i_pgrm_number++;
50 p_input->stream.pp_programs = realloc( p_input->stream.pp_programs,
51 p_input->stream.i_pgrm_number
52 * sizeof(pgrm_descriptor_t *) );
54 /* Allocate the structure to store this description */
55 p_input->stream.pp_programs[i_pgrm_index] =
56 malloc( sizeof(pgrm_descriptor_t) );
59 p_input->stream.pp_programs[i_pgrm_index]->i_number = i_pgrm_id;
60 p_input->stream.pp_programs[i_pgrm_index]->b_is_ok = 0;
62 p_input->stream.pp_programs[i_pgrm_index]->i_es_number = 0;
63 p_input->stream.pp_programs[i_pgrm_index]->pp_es = NULL;
65 p_input->stream.pp_programs[i_pgrm_index]->delta_cr = 0;
66 p_input->stream.pp_programs[i_pgrm_index]->delta_absolute = 0;
67 p_input->stream.pp_programs[i_pgrm_index]->last_cr = 0;
68 p_input->stream.pp_programs[i_pgrm_index]->c_average_count = 0;
69 p_input->stream.pp_programs[i_pgrm_index]->i_synchro_state
70 = SYNCHRO_NOT_STARTED;
72 p_input->stream.pp_programs[i_pgrm_index]->p_vout
73 = p_input->p_default_vout;
74 p_input->stream.pp_programs[i_pgrm_index]->p_aout
75 = p_input->p_default_aout;
77 return p_input->stream.pp_programs[i_pgrm_index];
80 /*****************************************************************************
81 * input_DelProgram: destroy a program descriptor
82 *****************************************************************************
83 * All ES descriptions referenced in the descriptor will be deleted.
84 *****************************************************************************/
85 void input_DelProgram( input_thread_t * p_input, u16 i_pgrm_id )
87 int i_index, i_pgrm_index = -1;
88 pgrm_descriptor_t * p_pgrm = NULL;
90 intf_DbgMsg("Deleting description for pgrm %d", i_pgrm_id);
92 /* Find where this program is described */
93 for( i_index = 0; i_index < p_input->stream.i_pgrm_number; i_index++ )
95 if( p_input->stream.pp_programs[i_index]->i_number == i_pgrm_id )
97 i_pgrm_index = i_index;
98 p_pgrm = p_input->stream.pp_programs[ i_pgrm_index ];
103 /* Make sure that the pgrm exists */
104 ASSERT(i_pgrm_index >= 0);
107 /* Free the structures that describe the es that belongs to that program */
108 for( i_index = 0; i_index < p_pgrm->i_es_number; i_index++ )
110 DestroyESDescr( p_input, p_pgrm, p_pgrm->pp_es[i_index]->i_id );
113 /* Free the table of es descriptors */
114 free( p_pgrm->pp_es );
116 /* Free the description of this stream */
119 /* Remove this program from the stream's list of programs */
120 p_input->stream.i_pgrm_number--;
121 p_input->stream.pp_programs[i_pgrm_index] =
122 p_input->stream.pp_programs[p_input->stream.i_pgrm_number];
123 p_input->stream.pp_programs = realloc( p_input->stream.pp_programs,
124 p_input->stream.i_pgrm_number
125 * sizeof(pgrm_descriptor_t *) );
128 /*****************************************************************************
130 *****************************************************************************
131 * Reserve a slot in the table of ES descriptors for the ES and add it to the
132 * list of ES of p_pgrm. If p_pgrm if NULL, then the ES is considered as stand
134 *****************************************************************************/
135 es_descriptor_t * input_AddES( input_thread_t * p_input,
136 pgrm_descriptor_t * p_pgrm, u16 i_es_id)
139 es_descriptor_t * p_es = NULL;
141 intf_DbgMsg("Adding description for ES %d", i_es_id);
143 /* Find an empty slot to store the description of that es */
144 for( i_index = 0; i_index < INPUT_MAX_ES &&
145 p_input->p_es[i_index].i_id != EMPTY_ID; i_index++ );
147 if( i_index >= INPUT_MAX_ES )
149 /* No slot is empty */
150 intf_ErrMsg("Stream carries too many ES for our decoder");
154 /* Reserve the slot for that ES */
155 p_es = &p_input->p_es[i_index];
156 p_es->i_id = i_es_id;
157 intf_DbgMsg("Slot %d in p_es table assigned to ES %d",
160 /* Init its values */
161 p_es->b_discontinuity = 0;
162 p_es->p_pes_packet = NULL;
163 p_es->p_decoder_fifo = NULL;
165 /* Add this ES to the program definition if one is given */
168 p_pgrm->i_es_number++;
169 p_pgrm->pp_es = realloc( p_pgrm->pp_es,
171 * sizeof(es_descriptor_t *) );
172 p_pgrm->pp_es[p_pgrm->i_es_number - 1] = p_es;
173 p_es->p_pgrm = p_pgrm;
184 /*****************************************************************************
186 *****************************************************************************/
187 void input_DelES( input_thread_t * p_input, u16 i_id)
190 program_descriptor_t * p_pgrm;
191 es_descriptor_t * p_es;
193 /* Look for the description of the ES */
194 for( i_index = 0; i_index < INPUT_MAX_ES; i_index++ )
196 if( p_input->p_es[i_index].i_id == i_id )
198 p_es = &p_input->p_es[i_index];
199 p_pgrm = p_input->p_es[i_index].p_pgrm;
206 /* Remove this ES from the description of the program if it is associated to
210 for( i_index = 0; ; i_index++ )
212 if( p_pgrm->p_es[i_index].i_id == i_id )
214 p_pgrm->i_es_number--;
215 p_pgrm->pp_es[i_index] = p_pgrm->p_es[p_pgrm->i_es_number];
216 p_pgrm->pp_es = realloc( p_pgrm->pp_es,
218 * sizeof(es_decriptor_t *));
224 /* The table of stream descriptors is static, so don't free memory
225 * but just mark the slot as unused */
226 p_es->i_id = EMPTY_ID;