Changeset 08ece243befadb2eaf51ce28067829733eaab3ab
- Timestamp:
- 03/03/04 12:40:19 (5 years ago)
- git-parent:
- Files:
-
- modules/demux/a52.c (modified) (13 diffs)
- modules/demux/aac.c (modified) (15 diffs)
- modules/demux/au.c (modified) (2 diffs)
- modules/demux/dts.c (modified) (15 diffs)
- modules/demux/flac.c (modified) (14 diffs)
- modules/demux/wav.c (modified) (22 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
modules/demux/a52.c
rde81c25 r08ece24 3 3 ***************************************************************************** 4 4 * Copyright (C) 2001 VideoLAN 5 * $Id: a52.c,v 1. 6 2004/02/25 17:48:52fenrir Exp $5 * $Id: a52.c,v 1.7 2004/03/03 11:40:19 fenrir Exp $ 6 6 * 7 7 * Authors: Gildas Bazin <gbazin@netcourrier.com> … … 33 33 #endif 34 34 35 /***************************************************************************** 36 * Module descriptor 37 *****************************************************************************/ 38 static int Open ( vlc_object_t * ); 39 static void Close ( vlc_object_t * ); 40 41 vlc_module_begin(); 42 set_description( _("Raw A/52 demuxer") ); 43 set_capability( "demux2", 145 ); 44 set_callbacks( Open, Close ); 45 add_shortcut( "a52" ); 46 vlc_module_end(); 47 48 /***************************************************************************** 49 * Local prototypes 50 *****************************************************************************/ 51 static int Demux ( demux_t * ); 52 static int Control( demux_t *, int, va_list ); 53 54 struct demux_sys_t 55 { 56 vlc_bool_t b_start; 57 es_out_id_t *p_es; 58 59 /* Packetizer */ 60 decoder_t *p_packetizer; 61 62 int i_mux_rate; 63 vlc_bool_t b_big_endian; 64 }; 65 66 static int CheckSync( uint8_t *p_peek, vlc_bool_t *p_big_endian ); 67 35 68 #define PCM_FRAME_SIZE (1536 * 4) 36 69 #define A52_PACKET_SIZE (4 * PCM_FRAME_SIZE) 37 70 #define A52_MAX_HEADER_SIZE 10 38 71 39 /*****************************************************************************40 * Local prototypes41 *****************************************************************************/42 static int Open ( vlc_object_t * );43 static void Close ( vlc_object_t * );44 static int Demux ( input_thread_t * );45 46 static int Control( input_thread_t *, int, va_list );47 48 struct demux_sys_t49 {50 vlc_bool_t b_start;51 es_out_id_t *p_es;52 53 /* Packetizer */54 decoder_t *p_packetizer;55 56 int i_mux_rate;57 vlc_bool_t b_big_endian;58 };59 60 /*****************************************************************************61 * Module descriptor62 *****************************************************************************/63 vlc_module_begin();64 set_description( _("Raw A/52 demuxer") );65 set_capability( "demux", 145 );66 set_callbacks( Open, Close );67 add_shortcut( "a52" );68 vlc_module_end();69 70 /*****************************************************************************71 * CheckSync: Check if buffer starts with an A52 sync code72 *****************************************************************************/73 static int CheckSync( uint8_t *p_peek, vlc_bool_t *p_big_endian )74 {75 /* Little endian version of the bitstream */76 if( p_peek[0] == 0x77 && p_peek[1] == 0x0b &&77 p_peek[4] < 0x60 /* bsid < 12 */ )78 {79 *p_big_endian = VLC_FALSE;80 return VLC_SUCCESS;81 }82 /* Big endian version of the bitstream */83 else if( p_peek[0] == 0x0b && p_peek[1] == 0x77 &&84 p_peek[5] < 0x60 /* bsid < 12 */ )85 {86 *p_big_endian = VLC_TRUE;87 return VLC_SUCCESS;88 }89 90 return VLC_EGENERIC;91 }92 72 93 73 /***************************************************************************** … … 96 76 static int Open( vlc_object_t * p_this ) 97 77 { 98 input_thread_t *p_input = (input_thread_t *)p_this; 99 demux_sys_t *p_sys; 100 byte_t * p_peek; 101 int i_peek = 0; 102 vlc_bool_t b_big_endian; 103 104 p_input->pf_demux = Demux; 105 p_input->pf_demux_control = Control; 106 p_input->pf_rewind = NULL; 78 demux_t *p_demux = (demux_t*)p_this; 79 demux_sys_t *p_sys; 80 byte_t *p_peek; 81 int i_peek = 0; 82 vlc_bool_t b_big_endian; 107 83 108 84 /* Check if we are dealing with a WAV file */ 109 if( input_Peek( p_input, &p_peek, 12 ) == 12 &&85 if( stream_Peek( p_demux->s, &p_peek, 12 ) == 12 && 110 86 !strncmp( p_peek, "RIFF", 4 ) && !strncmp( &p_peek[8], "WAVE", 4 ) ) 111 87 { … … 114 90 /* Skip the wave header */ 115 91 i_peek = 12 + 8; 116 while( input_Peek( p_input, &p_peek, i_peek ) == i_peek &&92 while( stream_Peek( p_demux->s, &p_peek, i_peek ) == i_peek && 117 93 strncmp( p_peek + i_peek - 8, "data", 4 ) ) 118 94 { … … 124 100 /* Some A52 wav files don't begin with a sync code so we do a more 125 101 * extensive search */ 126 i_size = input_Peek( p_input, &p_peek, i_peek + A52_PACKET_SIZE * 2);102 i_size = stream_Peek( p_demux->s, &p_peek, i_peek + A52_PACKET_SIZE * 2); 127 103 i_size -= (PCM_FRAME_SIZE + A52_MAX_HEADER_SIZE); 128 104 … … 148 124 149 125 /* Have a peep at the show. */ 150 if( input_Peek( p_input, &p_peek, i_peek + A52_MAX_HEADER_SIZE * 2 ) <126 if( stream_Peek( p_demux->s, &p_peek, i_peek + A52_MAX_HEADER_SIZE * 2 ) < 151 127 i_peek + A52_MAX_HEADER_SIZE * 2 ) 152 128 { 153 129 /* Stream too short */ 154 msg_Warn( p_ input, "cannot peek()" );130 msg_Warn( p_demux, "cannot peek()" ); 155 131 return VLC_EGENERIC; 156 132 } … … 158 134 if( CheckSync( p_peek + i_peek, &b_big_endian ) != VLC_SUCCESS ) 159 135 { 160 if( p_input->psz_demux && !strncmp( p_input->psz_demux, "a52", 3 ) ) 161 { 162 /* User forced */ 163 msg_Err( p_input, "this doesn't look like a A52 audio stream, " 164 "continuing anyway" ); 165 } 166 else 136 if( strncmp( p_demux->psz_demux, "a52", 3 ) ) 167 137 { 168 138 return VLC_EGENERIC; 169 139 } 170 } 171 172 p_input->p_demux_data = p_sys = malloc( sizeof( demux_sys_t ) ); 140 141 /* User forced */ 142 msg_Err( p_demux, "this doesn't look like a A52 audio stream, " 143 "continuing anyway" ); 144 } 145 146 /* Fill p_demux fields */ 147 p_demux->pf_demux = Demux; 148 p_demux->pf_control = Control; 149 p_demux->p_sys = p_sys = malloc( sizeof( demux_sys_t ) ); 173 150 p_sys->b_start = VLC_TRUE; 174 151 p_sys->i_mux_rate = 0; … … 178 155 * Load the A52 packetizer 179 156 */ 180 p_sys->p_packetizer = vlc_object_create( p_ input, VLC_OBJECT_DECODER );157 p_sys->p_packetizer = vlc_object_create( p_demux, VLC_OBJECT_DECODER ); 181 158 p_sys->p_packetizer->pf_decode_audio = 0; 182 159 p_sys->p_packetizer->pf_decode_video = 0; … … 192 169 if( !p_sys->p_packetizer->p_module ) 193 170 { 194 msg_Err( p_ input, "cannot find A52 packetizer" );171 msg_Err( p_demux, "cannot find A52 packetizer" ); 195 172 return VLC_EGENERIC; 196 173 } 197 174 198 175 /* Create one program */ 199 vlc_mutex_lock( &p_input->stream.stream_lock ); 200 if( input_InitStream( p_input, 0 ) == -1 ) 201 { 202 vlc_mutex_unlock( &p_input->stream.stream_lock ); 203 msg_Err( p_input, "cannot init stream" ); 204 return VLC_EGENERIC; 205 } 206 p_input->stream.i_mux_rate = 0; 207 vlc_mutex_unlock( &p_input->stream.stream_lock ); 208 209 p_sys->p_es = 210 es_out_Add( p_input->p_es_out, &p_sys->p_packetizer->fmt_in ); 176 p_sys->p_es = es_out_Add( p_demux->out, &p_sys->p_packetizer->fmt_in ); 211 177 212 178 return VLC_SUCCESS; … … 218 184 static void Close( vlc_object_t * p_this ) 219 185 { 220 input_thread_t *p_input = (input_thread_t*)p_this;221 demux_sys_t *p_sys = p_ input->p_demux_data;186 demux_t *p_demux = (demux_t*)p_this; 187 demux_sys_t *p_sys = p_demux->p_sys; 222 188 223 189 /* Unneed module */ … … 235 201 * Returns -1 in case of error, 0 in case of EOF, 1 otherwise 236 202 *****************************************************************************/ 237 static int Demux( input_thread_t * p_input)238 { 239 demux_sys_t *p_sys = p_input->p_demux_data;240 block_t *p_block_in, *p_block_out;203 static int Demux( demux_t *p_demux ) 204 { 205 demux_sys_t *p_sys = p_demux->p_sys; 206 block_t *p_block_in, *p_block_out; 241 207 242 208 /* Align stream */ 243 int64_t i_pos = stream_Tell( p_ input->s );244 if( i_pos % 2 ) stream_Read( p_ input->s, NULL, 1 );245 246 if( !( p_block_in = stream_Block( p_ input->s, A52_PACKET_SIZE ) ) )209 int64_t i_pos = stream_Tell( p_demux->s ); 210 if( i_pos % 2 ) stream_Read( p_demux->s, NULL, 1 ); 211 212 if( !( p_block_in = stream_Block( p_demux->s, A52_PACKET_SIZE ) ) ) 247 213 { 248 214 return 0; … … 286 252 /* We assume a constant bitrate */ 287 253 if( p_block_out->i_length ) 288 p_sys->i_mux_rate = 289 p_block_out->i_buffer * I64C(1000000) / p_block_out->i_length; 290 p_input->stream.i_mux_rate = p_sys->i_mux_rate / 50; 291 292 input_ClockManageRef( p_input, 293 p_input->stream.p_selected_program, 294 p_block_out->i_pts * 9 / 100 ); 295 296 p_block_out->i_dts = p_block_out->i_pts = 297 input_ClockGetTS( p_input, p_input->stream.p_selected_program, 298 p_block_out->i_pts * 9 / 100 ); 299 300 es_out_Send( p_input->p_es_out, p_sys->p_es, p_block_out ); 254 { 255 p_sys->i_mux_rate = 256 p_block_out->i_buffer * I64C(1000000)/p_block_out->i_length; 257 } 258 259 /* set PCR */ 260 es_out_Control( p_demux->out, ES_OUT_SET_PCR, p_block_out->i_dts ); 261 262 es_out_Send( p_demux->out, p_sys->p_es, p_block_out ); 301 263 302 264 p_block_out = p_next; … … 310 272 * Control: 311 273 *****************************************************************************/ 312 static int Control( input_thread_t *p_input, int i_query, va_list args ) 313 { 314 demux_sys_t *p_sys = (demux_sys_t *)p_input->p_demux_data; 315 int64_t *pi64; 316 317 switch( i_query ) 318 { 319 case DEMUX_GET_TIME: 320 pi64 = (int64_t*)va_arg( args, int64_t * ); 321 if( p_sys->i_mux_rate > 0 ) 322 { 323 *pi64 = I64C(1000000) * stream_Tell( p_input->s ) / 324 p_sys->i_mux_rate; 325 return VLC_SUCCESS; 326 } 327 *pi64 = 0; 328 return VLC_EGENERIC; 329 330 case DEMUX_GET_LENGTH: 331 pi64 = (int64_t*)va_arg( args, int64_t * ); 332 if( p_sys->i_mux_rate > 0 ) 333 { 334 *pi64 = I64C(1000000) * stream_Size( p_input->s ) / 335 p_sys->i_mux_rate; 336 return VLC_SUCCESS; 337 } 338 *pi64 = 0; 339 return VLC_EGENERIC; 340 341 default: 342 return demux_vaControlDefault( p_input, i_query, args ); 343 } 344 } 274 static int Control( demux_t *p_demux, int i_query, va_list args ) 275 { 276 demux_sys_t *p_sys = p_demux->p_sys; 277 return demux2_vaControlHelper( p_demux->s, 278 0, -1, 279 8*p_sys->i_mux_rate, 1, i_query, args ); 280 } 281 282 /***************************************************************************** 283 * CheckSync: Check if buffer starts with an A52 sync code 284 *****************************************************************************/ 285 static int CheckSync( uint8_t *p_peek, vlc_bool_t *p_big_endian ) 286 { 287 /* Little endian version of the bitstream */ 288 if( p_peek[0] == 0x77 && p_peek[1] == 0x0b && 289 p_peek[4] < 0x60 /* bsid < 12 */ ) 290 { 291 *p_big_endian = VLC_FALSE; 292 return VLC_SUCCESS; 293 } 294 /* Big endian version of the bitstream */ 295 else if( p_peek[0] == 0x0b && p_peek[1] == 0x77 && 296 p_peek[5] < 0x60 /* bsid < 12 */ ) 297 { 298 *p_big_endian = VLC_TRUE; 299 return VLC_SUCCESS; 300 } 301 302 return VLC_EGENERIC; 303 } 304 305 modules/demux/aac.c
rffdca9a r08ece24 3 3 ***************************************************************************** 4 4 * Copyright (C) 2001-2003 VideoLAN 5 * $Id: aac.c,v 1. 9 2004/01/25 20:05:28 hartmanExp $5 * $Id: aac.c,v 1.10 2004/03/03 11:40:19 fenrir Exp $ 6 6 * 7 7 * Authors: Laurent Aimar <fenrir@via.ecp.fr> … … 38 38 vlc_module_begin(); 39 39 set_description( _("AAC demuxer" ) ); 40 set_capability( "demux ", 10 );40 set_capability( "demux2", 100 ); 41 41 set_callbacks( Open, Close ); 42 42 add_shortcut( "aac" ); … … 51 51 * Local prototypes 52 52 *****************************************************************************/ 53 static int Demux ( input_thread_t * );54 55 53 struct demux_sys_t 56 54 { … … 60 58 }; 61 59 60 static int Demux ( demux_t * ); 61 static int Control( demux_t *, int, va_list ); 62 62 63 static int i_aac_samplerate[16] = 63 64 { 64 96000, 88200, 64000, 48000, 44100, 32000, 65 96000, 88200, 64000, 48000, 44100, 32000, 65 66 24000, 22050, 16000, 12000, 11025, 8000, 66 67 7350, 0, 0, 0 … … 71 72 #define AAC_CHANNELS( p ) ( (((p)[2]&0x01)<<2) | (((p)[3]>>6)&0x03) ) 72 73 #define AAC_FRAME_SIZE( p ) ( (((p)[3]&0x03) << 11)|( (p)[4] << 3 )|( (((p)[5]) >>5)&0x7 ) ) 74 73 75 /* FIXME it's plain wrong */ 74 76 #define AAC_FRAME_SAMPLES( p ) 1024 … … 87 89 } 88 90 89 90 91 /***************************************************************************** 91 92 * Open: initializes AAC demux structures … … 93 94 static int Open( vlc_object_t * p_this ) 94 95 { 95 input_thread_t *p_input = (input_thread_t *)p_this; 96 demux_sys_t *p_sys; 97 int b_forced = VLC_FALSE; 98 99 uint8_t *p_peek; 100 101 module_t *p_id3; 102 103 es_format_t fmt; 104 105 106 if( p_input->psz_demux && !strncmp( p_input->psz_demux, "aac", 3 ) ) 96 demux_t *p_demux = (demux_t*)p_this; 97 demux_sys_t *p_sys; 98 int b_forced = VLC_FALSE; 99 100 uint8_t *p_peek; 101 module_t *p_id3; 102 es_format_t fmt; 103 104 if( !strncmp( p_demux->psz_demux, "aac", 3 ) ) 107 105 { 108 106 b_forced = VLC_TRUE; 109 107 } 110 108 111 if( p_ input->psz_name)112 { 113 int i_len = strlen( p_ input->psz_name);114 115 if( i_len > 4 && !strcasecmp( &p_ input->psz_name[i_len - 4], ".aac" ) )109 if( p_demux->psz_path ) 110 { 111 int i_len = strlen( p_demux->psz_path ); 112 113 if( i_len > 4 && !strcasecmp( &p_demux->psz_path[i_len - 4], ".aac" ) ) 116 114 { 117 115 b_forced = VLC_TRUE; … … 124 122 * extention check 125 123 */ 126 msg_Warn( p_ input, "AAC module discarded" );124 msg_Warn( p_demux, "AAC module discarded" ); 127 125 return VLC_EGENERIC; 128 126 } 129 127 130 128 /* skip possible id3 header */ 131 p_id3 = module_Need( p_input, "id3", NULL ); 132 if ( p_id3 ) 133 { 134 module_Unneed( p_input, p_id3 ); 135 } 136 137 p_input->pf_demux = Demux; 138 p_input->pf_demux_control = demux_vaControlDefault; 139 140 p_input->p_demux_data = p_sys = malloc( sizeof( demux_sys_t ) ); 129 if( ( p_id3 = module_Need( p_demux, "id3", NULL ) ) ) 130 { 131 module_Unneed( p_demux, p_id3 ); 132 } 133 134 p_demux->pf_demux = Demux; 135 p_demux->pf_control = Control; 136 p_demux->p_sys = p_sys = malloc( sizeof( demux_sys_t ) ); 137 141 138 p_sys->i_time = 0; 142 139 143 140 /* peek the begining (10 is for adts header) */ 144 if( stream_Peek( p_ input->s, &p_peek, 10 ) < 10 )145 { 146 msg_Err( p_ input, "cannot peek" );141 if( stream_Peek( p_demux->s, &p_peek, 10 ) < 10 ) 142 { 143 msg_Err( p_demux, "cannot peek" ); 147 144 goto error; 148 145 } 149 150 146 if( !strncmp( p_peek, "ADIF", 4 ) ) 151 147 { 152 msg_Err( p_ input, "ADIF file. Not yet supported. (Please report)" );148 msg_Err( p_demux, "ADIF file. Not yet supported. (Please report)" ); 153 149 goto error; 154 150 } … … 158 154 { 159 155 fmt.audio.i_channels = AAC_CHANNELS( p_peek ); 160 fmt.audio.i_rate = AAC_SAMPLE_RATE( p_peek );161 162 msg_Dbg( p_ input,156 fmt.audio.i_rate = AAC_SAMPLE_RATE( p_peek ); 157 158 msg_Dbg( p_demux, 163 159 "adts header: id=%d channels=%d sample_rate=%d", 164 160 AAC_ID( p_peek ), … … 167 163 } 168 164 169 vlc_mutex_lock( &p_input->stream.stream_lock ); 170 if( input_InitStream( p_input, 0 ) == -1) 171 { 172 vlc_mutex_unlock( &p_input->stream.stream_lock ); 173 msg_Err( p_input, "cannot init stream" ); 174 goto error; 175 } 176 p_input->stream.i_mux_rate = 0 / 50; 177 vlc_mutex_unlock( &p_input->stream.stream_lock ); 178 179 p_sys->p_es = es_out_Add( p_input->p_es_out, &fmt ); 180 165 p_sys->p_es = es_out_Add( p_demux->out, &fmt ); 181 166 return VLC_SUCCESS; 182 167 … … 192 177 * Returns -1 in case of error, 0 in case of EOF, 1 otherwise 193 178 *****************************************************************************/ 194 static int Demux( input_thread_t * p_input)195 { 196 demux_sys_t *p_sys = p_input->p_demux_data;197 block_t *p_block;198 199 uint8_t h[8];200 uint8_t *p_peek;201 202 if( stream_Peek( p_ input->s, &p_peek, 8 ) < 8 )203 { 204 msg_Warn( p_ input, "cannot peek" );179 static int Demux( demux_t *p_demux ) 180 { 181 demux_sys_t *p_sys = p_demux->p_sys; 182 block_t *p_block; 183 184 uint8_t h[8]; 185 uint8_t *p_peek; 186 187 if( stream_Peek( p_demux->s, &p_peek, 8 ) < 8 ) 188 { 189 msg_Warn( p_demux, "cannot peek" ); 205 190 return 0; 206 191 } … … 213 198 int i_peek; 214 199 215 i_peek = stream_Peek( p_ input->s, &p_peek, 8096 );200 i_peek = stream_Peek( p_demux->s, &p_peek, 8096 ); 216 201 if( i_peek < 8 ) 217 202 { 218 msg_Warn( p_ input, "cannot peek" );203 msg_Warn( p_demux, "cannot peek" ); 219 204 return 0; 220 205 } … … 233 218 } 234 219 235 msg_Warn( p_ input, "garbage=%d bytes", i_skip );236 stream_Read( p_ input->s, NULL, i_skip );220 msg_Warn( p_demux, "garbage=%d bytes", i_skip ); 221 stream_Read( p_demux->s, NULL, i_skip ); 237 222 return 1; 238 223 } … … 240 225 memcpy( h, p_peek, 8 ); /* can't use p_peek after stream_* */ 241 226 242 input_ClockManageRef( p_input, 243 p_input->stream.p_selected_program, 244 p_sys->i_time * 9 / 100 ); 245 246 if( ( p_block = stream_Block( p_input->s, AAC_FRAME_SIZE( h ) ) ) == NULL ) 247 { 248 msg_Warn( p_input, "cannot read data" ); 227 228 229 /* set PCR */ 230 es_out_Control( p_demux->out, ES_OUT_SET_PCR, p_sys->i_time ); 231 232 if( ( p_block = stream_Block( p_demux->s, AAC_FRAME_SIZE( h ) ) ) == NULL ) 233 { 234 msg_Warn( p_demux, "cannot read data" ); 249 235 return 0; 250 236 } 251 237 252 p_block->i_dts = 253 p_block->i_pts = input_ClockGetTS( p_input, 254 p_input->stream.p_selected_program, 255 p_sys->i_time * 9 / 100 ); 256 257 es_out_Send( p_input->p_es_out, p_sys->p_es, p_block ); 238 p_block->i_dts = p_block->i_pts = p_sys->i_time; 239 240 es_out_Send( p_demux->out, p_sys->p_es, p_block ); 258 241 259 242 p_sys->i_time += (mtime_t)1000000 * … … 268 251 static void Close( vlc_object_t * p_this ) 269 252 { 270 input_thread_t *p_input = (input_thread_t*)p_this;271 demux_sys_t *p_sys = p_input->p_demux_data;253 demux_t *p_demux = (demux_t*)p_this; 254 demux_sys_t *p_sys = p_demux->p_sys; 272 255 273 256 free( p_sys ); 274 257 } 275 258 259 /***************************************************************************** 260 * Control: 261 *****************************************************************************/ 262 static int Control( demux_t *p_demux, int i_query, va_list args ) 263 { 264 /* demux_sys_t *p_sys = p_demux->p_sys; */ 265 /* FIXME calculate the bitrate */ 266 return demux2_vaControlHelper( p_demux->s, 267 0, -1, 268 8*0, 1, i_query, args ); 269 } 270 modules/demux/au.c
r0b1ccd3 r08ece24 3 3 ***************************************************************************** 4 4 * Copyright (C) 2001-2003 VideoLAN 5 * $Id: au.c,v 1.1 3 2004/01/29 15:11:17fenrir Exp $5 * $Id: au.c,v 1.14 2004/03/03 11:40:19 fenrir Exp $ 6 6 * 7 7 * Authors: Laurent Aimar <fenrir@via.ecp.fr> … … 332 332 { 333 333 demux_sys_t *p_sys = p_demux->p_sys; 334 double f, *pf; 335 int64_t *pi64; 336 337 switch( i_query ) 338 { 339 case DEMUX_GET_POSITION: 340 { 341 int64_t i_tell = stream_Tell( p_demux->s ); 342 int64_t i_end = stream_Size( p_demux->s ); 343 344 pf = (double*) va_arg( args, double* ); 345 346 if( p_sys->i_header_size < i_end ) 347 { 348 *pf = (double)( i_tell - p_sys->i_header_size ) / 349 (double)(i_end - p_sys->i_header_size); 350 return VLC_SUCCESS; 351 } 352 return VLC_EGENERIC; 353 } 354 case DEMUX_SET_POSITION: 355 { 356 int64_t i_end = stream_Size( p_demux->s ); 357 358 f = (double) va_arg( args, double ); 359 360 if( p_sys->i_header_size < i_end ) 361 { 362 int64_t i_frame = (f * ( i_end - p_sys->i_header_size )) / 363 p_sys->fmt.audio.i_blockalign; 364 365 if( stream_Seek( p_demux->s, p_sys->i_header_size + 366 i_frame * p_sys->fmt.audio.i_blockalign ) ) 367 { 368 return VLC_EGENERIC; 369 } 370 p_sys->i_time = 1 + ( i_frame * p_sys->fmt.audio.i_blockalign / p_sys->i_frame_size ) * p_sys->i_frame_length; 371 return VLC_SUCCESS; 372 } 373 return VLC_EGENERIC; 374 } 375 376 case DEMUX_GET_TIME: 377 pi64 = (int64_t*)va_arg( args, int64_t * ); 378 *pi64 = p_sys->i_time; 379 return VLC_SUCCESS; 380 381 case DEMUX_GET_LENGTH: 382 { 383 int64_t i_size = stream_Size( p_demux->s ) - p_sys->i_header_size; 384 if( i_size > 0 ) 385 { 386 pi64 = (int64_t*)va_arg( args, int64_t * ); 387 *pi64 = i_size / p_sys->i_frame_size * p_sys->i_frame_length; 388 return VLC_SUCCESS; 389 } 390 return VLC_EGENERIC; 391 } 392 case DEMUX_SET_TIME: 393 case DEMUX_GET_FPS: 394 default: 395 return VLC_EGENERIC; 396 } 334 335 return demux2_vaControlHelper( p_demux->s, p_sys->i_header_size, -1, 336 p_sys->fmt.i_bitrate, p_sys->fmt.audio.i_blockalign, 337 i_query, args ); 397 338 } 398 339 399 400 401 402 403 404 405 modules/demux/dts.c
rde81c25 r08ece24 3 3 ***************************************************************************** 4 4 * Copyright (C) 2001 VideoLAN 5 * $Id: dts.c,v 1.1 0 2004/02/25 17:48:52fenrir Exp $5 * $Id: dts.c,v 1.11 2004/03/03 11:40:19 fenrir Exp $ 6 6 * 7 7 * Authors: Gildas Bazin <gbazin@netcourrier.com> … … 29 29 #include <vlc_codec.h> 30 30 31 /***************************************************************************** 32 * Module descriptor 33 *****************************************************************************/ 34 static int Open ( vlc_object_t * ); 35 static void Close ( vlc_object_t * ); 36 37 vlc_module_begin(); 38 set_description( _("Raw DTS demuxer") ); 39 set_capability( "demux2", 155 ); 40 set_callbacks( Open, Close ); 41 add_shortcut( "dts" ); 42 vlc_module_end(); 43 44 /***************************************************************************** 45 * Local prototypes 46 *****************************************************************************/ 47 static int Demux ( demux_t * ); 48 static int Control( demux_t *, int, va_list ); 49 50 struct demux_sys_t 51 { 52 vlc_bool_t b_start; 53 es_out_id_t *p_es; 54 55 /* Packetizer */ 56 decoder_t *p_packetizer; 57 58 int i_mux_rate; 59 }; 60 61 static int CheckSync( uint8_t *p_peek ); 62 31 63 #define DTS_PACKET_SIZE 16384 32 64 #define DTS_PROBE_SIZE (DTS_PACKET_SIZE * 4) … … 34 66 35 67 /***************************************************************************** 36 * Local prototypes37 *****************************************************************************/38 static int Open ( vlc_object_t * );39 static void Close ( vlc_object_t * );40 static int Demux ( input_thread_t * );41 42 static int Control( input_thread_t *, int, va_list );43 44 struct demux_sys_t45 {46 vlc_bool_t b_start;47 es_out_id_t *p_es;48 49 /* Packetizer */50 decoder_t *p_packetizer;51 52 int i_mux_rate;53 };54 55 /*****************************************************************************56 * Module descriptor57 *****************************************************************************/58 vlc_module_begin();59 set_description( _("Raw DTS demuxer") );60 set_capability( "demux", 155 );61 set_callbacks( Open, Close );62 add_shortcut( "dts" );63 vlc_module_end();64 65 /*****************************************************************************66 * CheckSync: Check if buffer starts with a DTS sync code67 *****************************************************************************/68 static int CheckSync( uint8_t *p_peek )69 {70 /* 14 bits, little endian version of the bitstream */71 if( p_peek[0] == 0xff && p_peek[1] == 0x1f &&72 p_peek[2] == 0x00 && p_peek[3] == 0xe8 &&73 (p_peek[4] & 0xf0) == 0xf0 && p_peek[5] == 0x07 )74 {75 return VLC_SUCCESS;76 }77 /* 14 bits, big endian version of the bitstream */78 else if( p_peek[0] == 0x1f && p_peek[1] == 0xff &&79 p_peek[2] == 0xe8 && p_peek[3] == 0x00 &&80 p_peek[4] == 0x07 && (p_peek[5] & 0xf0) == 0xf0)81 {82 return VLC_SUCCESS;83 }84 /* 16 bits, big endian version of the bitstream */85 else if( p_peek[0] == 0x7f && p_peek[1] == 0xfe &&86 p_peek[2] == 0x80 && p_peek[3] == 0x01 )87 {88 return VLC_SUCCESS;89 }90 /* 16 bits, little endian version of the bitstream */91 else if( p_peek[0] == 0xfe && p_peek[1] == 0x7f &&92 p_peek[2] == 0x01 && p_peek[3] == 0x80 )93 {94 return VLC_SUCCESS;95 }96 97 return VLC_EGENERIC;98 }99 100 /*****************************************************************************101 68 * Open: initializes ES structures 102 69 *****************************************************************************/ 103 70 static int Open( vlc_object_t * p_this ) 104 71 { 105 input_thread_t *p_input = (input_thread_t *)p_this; 106 demux_sys_t *p_sys; 107 byte_t * p_peek; 108 int i_peek = 0; 109 110 p_input->pf_demux = Demux; 111 p_input->pf_demux_control = Control; 112 p_input->pf_rewind = NULL; 72 demux_t *p_demux = (demux_t*)p_this; 73 demux_sys_t *p_sys; 74 byte_t * p_peek; 75 int i_peek = 0; 113 76 114 77 /* Check if we are dealing with a WAV file */ 115 if( input_Peek( p_input, &p_peek, 20 ) == 20 &&78 if( stream_Peek( p_demux->s, &p_peek, 20 ) == 20 && 116 79 !strncmp( p_peek, "RIFF", 4 ) && !strncmp( &p_peek[8], "WAVE", 4 ) ) 117 80 { … … 126 89 i_peek += i_size + 8; 127 90 128 if( input_Peek( p_input, &p_peek, i_peek ) != i_peek )91 if( stream_Peek( p_demux->s, &p_peek, i_peek ) != i_peek ) 129 92 return VLC_EGENERIC; 130 93 } … … 134 97 if( i_size + i_peek > DTS_PROBE_SIZE ) return VLC_EGENERIC; 135 98 i_peek += i_size + 8; 136 if( input_Peek( p_input, &p_peek, i_peek ) != i_peek )99 if( stream_Peek( p_demux->s, &p_peek, i_peek ) != i_peek ) 137 100 return VLC_EGENERIC; 138 101 if( GetWLE( p_peek + i_peek - i_size - 8 /* wFormatTag */ ) != … … 152 115 i_peek += i_size + 8; 153 116 154 if( input_Peek( p_input, &p_peek, i_peek ) != i_peek )117 if( stream_Peek( p_demux->s, &p_peek, i_peek ) != i_peek ) 155 118 return VLC_EGENERIC; 156 119 } … … 158 121 /* Some DTS wav files don't begin with a sync code so we do a more 159 122 * extensive search */ 160 i_size = input_Peek( p_input, &p_peek, DTS_PROBE_SIZE );123 i_size = stream_Peek( p_demux->s, &p_peek, DTS_PROBE_SIZE ); 161 124 i_size -= DTS_MAX_HEADER_SIZE; 162 125 … … 172 135 173 136 /* Have a peep at the show. */ 174 if( input_Peek( p_input, &p_peek, i_peek + DTS_MAX_HEADER_SIZE * 2 ) <137 if( stream_Peek( p_demux->s, &p_peek, i_peek + DTS_MAX_HEADER_SIZE * 2 ) < 175 138 i_peek + DTS_MAX_HEADER_SIZE * 2 ) 176 139 { 177 140 /* Stream too short */ 178 msg_Warn( p_ input, "cannot peek()" );141 msg_Warn( p_demux, "cannot peek()" ); 179 142 return VLC_EGENERIC; 180 143 } … … 182 145 if( CheckSync( p_peek + i_peek ) != VLC_SUCCESS ) 183 146 { 184 if( p_input->psz_demux && !strncmp( p_input->psz_demux, "dts", 3 ) ) 185 { 186 /* User forced */ 187 msg_Err( p_input, "this doesn't look like a DTS audio stream, " 188 "continuing anyway" ); 189 } 190 else 191 { 192 return VLC_EGENERIC; 193 } 194 } 195 196 p_input->p_demux_data = p_sys = malloc( sizeof( demux_sys_t ) ); 147 if( strncmp( p_demux->psz_demux, "dts", 3 ) ) 148 { 149 return VLC_EGENERIC; 150 } 151 /* User forced */ 152 msg_Err( p_demux, "this doesn't look like a DTS audio stream, " 153 "continuing anyway" ); 154 } 155 156 p_demux->pf_demux = Demux; 157 p_demux->pf_control = Control; 158 p_demux->p_sys = p_sys = malloc( sizeof( demux_sys_t ) ); 197 159 p_sys->b_start = VLC_TRUE; 198 160 p_sys->i_mux_rate = 0; … … 201 163 * Load the DTS packetizer 202 164 */ 203 p_sys->p_packetizer = vlc_object_create( p_ input, VLC_OBJECT_DECODER );165 p_sys->p_packetizer = vlc_object_create( p_demux, VLC_OBJECT_DECODER ); 204 166 p_sys->p_packetizer->pf_decode_audio = 0; 205 167 p_sys->p_packetizer->pf_decode_video = 0; … … 215 177 if( !p_sys->p_packetizer->p_module ) 216 178 { 217 msg_Err( p_ input, "cannot find DTS packetizer" );179 msg_Err( p_demux, "cannot find DTS packetizer" ); 218 180 return VLC_EGENERIC; 219 181 } 220 182 221 /* Create one program */ 222 vlc_mutex_lock( &p_input->stream.stream_lock ); 223 if( input_InitStream( p_input, 0 ) == -1 ) 224 { 225 vlc_mutex_unlock( &p_input->stream.stream_lock ); 226 msg_Err( p_input, "cannot init stream" ); 227 return VLC_EGENERIC; 228 } 229 p_input->stream.i_mux_rate = 0; 230 vlc_mutex_unlock( &p_input->stream.stream_lock ); 231 232 p_sys->p_es = 233 es_out_Add( p_input->p_es_out, &p_sys->p_packetizer->fmt_in ); 183 p_sys->p_es = es_out_Add( p_demux->out, &p_sys->p_packetizer->fmt_in ); 234 184 235 185 return VLC_SUCCESS; … … 239 189 * Close: frees unused data 240 190 *****************************************************************************/ 241 static void Close( vlc_object_t * p_this )242 { 243 input_thread_t *p_input = (input_thread_t*)p_this;244 demux_sys_t *p_sys = p_input->p_demux_data;191 static void Close( vlc_object_t *p_this ) 192 { 193 demux_t *p_demux = (demux_t*)p_this; 194 demux_sys_t *p_sys = p_demux->p_sys; 245 195 246 196 /* Unneed module */ … … 258 208 * Returns -1 in case of error, 0 in case of EOF, 1 otherwise 259 209 *****************************************************************************/ 260 static int Demux( input_thread_t * p_input)261 { 262 demux_sys_t *p_sys = p_input->p_demux_data;210 static int Demux( demux_t *p_demux ) 211 { 212 demux_sys_t *p_sys = p_demux->p_sys; 263 213 block_t *p_block_in, *p_block_out; 264 214 265 if( !( p_block_in = stream_Block( p_ input->s, DTS_PACKET_SIZE ) ) )215 if( !( p_block_in = stream_Block( p_demux->s, DTS_PACKET_SIZE ) ) ) 266 216 { 267 217 return 0; … … 284 234 /* We assume a constant bitrate */ 285 235 if( p_block_out->i_length ) 286 p_sys->i_mux_rate = 287 p_block_out->i_buffer * I64C(1000000) / p_block_out->i_length; 288 p_input->stream.i_mux_rate = p_sys->i_mux_rate / 50; 289 290 input_ClockManageRef( p_input, 291 p_input->stream.p_selected_program, 292 p_block_out->i_pts * 9 / 100 ); 293 294 p_block_out->i_dts = p_block_out->i_pts = 295 input_ClockGetTS( p_input, p_input->stream.p_selected_program, 296 p_block_out->i_pts * 9 / 100 ); 297 298 es_out_Send( p_input->p_es_out, p_sys->p_es, p_block_out ); 236 { 237 p_sys->i_mux_rate = 238 p_block_out->i_buffer * I64C(1000000) / p_block_out->i_length; 239 } 240 241 /* set PCR */ 242 es_out_Control( p_demux->out, ES_OUT_SET_PCR, p_block_out->i_dts ); 243 244 es_out_Send( p_demux->out, p_sys->p_es, p_block_out ); 299 245 300 246 p_block_out = p_next; … … 308 254 * Control: 309 255 *****************************************************************************/ 310 static int Control( input_thread_t *p_input, int i_query, va_list args ) 311 { 312 demux_sys_t *p_sys = (demux_sys_t *)p_input->p_demux_data; 313 int64_t *pi64; 314 315 switch( i_query ) 316 { 317
