Changeset e695e7d80ebe2420542e14dfd7894222e449d88b
- Timestamp:
- 02/04/04 15:18:32
(5 years ago)
- Author:
- Laurent Aimar <fenrir@videolan.org>
- git-committer:
- Laurent Aimar <fenrir@videolan.org> 1080911912 +0000
- git-parent:
[d9259f2f2e86a0338c91c31d35fc0ad6983ca724]
- git-author:
- Laurent Aimar <fenrir@videolan.org> 1080911912 +0000
- Message:
- rawdv.c: demux -> demux2. (Untested so may be broken)
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| r070b6a3 |
re695e7d |
|
| 2 | 2 | * rawdv.c : raw dv input module for vlc |
|---|
| 3 | 3 | ***************************************************************************** |
|---|
| 4 | | * Copyright (C) 2001-2003 VideoLAN |
|---|
| 5 | | * $Id: rawdv.c,v 1.15 2004/02/29 19:01:22 gbazin Exp $ |
|---|
| | 4 | * Copyright (C) 2001-2004 VideoLAN |
|---|
| | 5 | * $Id$ |
|---|
| 6 | 6 | * |
|---|
| 7 | 7 | * Authors: Gildas Bazin <gbazin@netcourrier.com> |
|---|
| … | … | |
| 36 | 36 | static void Close( vlc_object_t * ); |
|---|
| 37 | 37 | |
|---|
| 38 | | static block_t *dv_extract_audio( input_thread_t * p_input, |
|---|
| 39 | | block_t* p_frame_block ); |
|---|
| 40 | | |
|---|
| 41 | 38 | vlc_module_begin(); |
|---|
| 42 | 39 | set_description( _("raw dv demuxer") ); |
|---|
| 43 | | set_capability( "demux", 2 ); |
|---|
| | 40 | set_capability( "demux2", 2 ); |
|---|
| 44 | 41 | set_callbacks( Open, Close ); |
|---|
| 45 | 42 | add_shortcut( "rawdv" ); |
|---|
| … | … | |
| 110 | 107 | * Local prototypes |
|---|
| 111 | 108 | *****************************************************************************/ |
|---|
| 112 | | static int Demux ( input_thread_t * ); |
|---|
| | 109 | static int Demux( demux_t * ); |
|---|
| | 110 | static int Control( demux_t *, int i_query, va_list args ); |
|---|
| | 111 | |
|---|
| | 112 | static block_t *dv_extract_audio( demux_t *p_demux, |
|---|
| | 113 | block_t* p_frame_block ); |
|---|
| 113 | 114 | |
|---|
| 114 | 115 | /***************************************************************************** |
|---|
| … | … | |
| 117 | 118 | static int Open( vlc_object_t * p_this ) |
|---|
| 118 | 119 | { |
|---|
| 119 | | input_thread_t *p_input = (input_thread_t *)p_this; |
|---|
| 120 | | demux_sys_t *p_sys; |
|---|
| 121 | | |
|---|
| 122 | | byte_t *p_peek, *p_peek_backup; |
|---|
| 123 | | |
|---|
| 124 | | uint32_t i_dword; |
|---|
| 125 | | dv_header_t dv_header; |
|---|
| 126 | | dv_id_t dv_id; |
|---|
| 127 | | char *psz_ext; |
|---|
| | 120 | demux_t *p_demux = (demux_t*)p_this; |
|---|
| | 121 | demux_sys_t *p_sys; |
|---|
| | 122 | |
|---|
| | 123 | byte_t *p_peek, *p_peek_backup; |
|---|
| | 124 | |
|---|
| | 125 | uint32_t i_dword; |
|---|
| | 126 | dv_header_t dv_header; |
|---|
| | 127 | dv_id_t dv_id; |
|---|
| | 128 | char *psz_ext; |
|---|
| 128 | 129 | |
|---|
| 129 | 130 | /* It isn't easy to recognize a raw dv stream. The chances that we'll |
|---|
| … | … | |
| 133 | 134 | |
|---|
| 134 | 135 | /* Check for dv file extension */ |
|---|
| 135 | | psz_ext = strrchr ( p_input->psz_name, '.' ); |
|---|
| 136 | | if( ( !psz_ext || strcasecmp( psz_ext, ".dv") )&& |
|---|
| 137 | | ( !p_input->psz_demux || strcmp(p_input->psz_demux, "rawdv") ) ) |
|---|
| | 136 | psz_ext = strrchr( p_demux->psz_path, '.' ); |
|---|
| | 137 | if( ( !psz_ext || strcasecmp( psz_ext, ".dv") ) && |
|---|
| | 138 | strcmp(p_demux->psz_demux, "rawdv") ) |
|---|
| 138 | 139 | { |
|---|
| 139 | 140 | return VLC_EGENERIC; |
|---|
| 140 | 141 | } |
|---|
| 141 | 142 | |
|---|
| 142 | | if( stream_Peek( p_input->s, &p_peek, DV_PAL_FRAME_SIZE ) < |
|---|
| | 143 | if( stream_Peek( p_demux->s, &p_peek, DV_PAL_FRAME_SIZE ) < |
|---|
| 143 | 144 | DV_NTSC_FRAME_SIZE ) |
|---|
| 144 | 145 | { |
|---|
| 145 | 146 | /* Stream too short ... */ |
|---|
| 146 | | msg_Err( p_input, "cannot peek()" ); |
|---|
| | 147 | msg_Err( p_demux, "cannot peek()" ); |
|---|
| 147 | 148 | return VLC_EGENERIC; |
|---|
| 148 | 149 | } |
|---|
| … | … | |
| 162 | 163 | if( dv_id.sct != 0 ) |
|---|
| 163 | 164 | { |
|---|
| 164 | | msg_Warn( p_input, "not a raw dv stream header" ); |
|---|
| | 165 | msg_Warn( p_demux, "not a raw dv stream header" ); |
|---|
| 165 | 166 | return VLC_EGENERIC; |
|---|
| 166 | 167 | } |
|---|
| … | … | |
| 171 | 172 | if( i_dword >> (32 - 1) ) /* incorrect bit */ |
|---|
| 172 | 173 | { |
|---|
| 173 | | msg_Warn( p_input, "incorrect bit" ); |
|---|
| | 174 | msg_Warn( p_demux, "incorrect bit" ); |
|---|
| 174 | 175 | return VLC_EGENERIC; |
|---|
| 175 | 176 | } |
|---|
| … | … | |
| 195 | 196 | |
|---|
| 196 | 197 | /* Set p_input field */ |
|---|
| 197 | | p_input->pf_demux = Demux; |
|---|
| 198 | | p_input->pf_demux_control = demux_vaControlDefault; |
|---|
| 199 | | p_input->p_demux_data = p_sys = malloc( sizeof( demux_sys_t ) ); |
|---|
| | 198 | p_demux->pf_demux = Demux; |
|---|
| | 199 | p_demux->pf_control = Control; |
|---|
| | 200 | p_demux->p_sys = p_sys = malloc( sizeof( demux_sys_t ) ); |
|---|
| 200 | 201 | |
|---|
| 201 | 202 | p_sys->i_dsf = dv_header.dsf; |
|---|
| … | … | |
| 213 | 214 | p_sys->fmt_video.video.i_height= dv_header.dsf ? 576 : 480;; |
|---|
| 214 | 215 | |
|---|
| | 216 | /* FIXME FIXME */ |
|---|
| | 217 | #if 0 |
|---|
| 215 | 218 | /* necessary because input_SplitBuffer() will only get |
|---|
| 216 | 219 | * INPUT_DEFAULT_BUFSIZE bytes at a time. */ |
|---|
| 217 | 220 | p_input->i_bufsize = p_sys->frame_size; |
|---|
| 218 | | |
|---|
| 219 | | vlc_mutex_lock( &p_input->stream.stream_lock ); |
|---|
| 220 | | if( input_InitStream( p_input, 0 ) == -1) |
|---|
| 221 | | { |
|---|
| 222 | | vlc_mutex_unlock( &p_input->stream.stream_lock ); |
|---|
| 223 | | msg_Err( p_input, "cannot init stream" ); |
|---|
| 224 | | free( p_sys ); |
|---|
| 225 | | return VLC_EGENERIC; |
|---|
| 226 | | } |
|---|
| 227 | | p_input->stream.i_mux_rate = p_sys->frame_size * p_sys->f_rate; |
|---|
| 228 | | vlc_mutex_unlock( &p_input->stream.stream_lock ); |
|---|
| 229 | | |
|---|
| 230 | | p_sys->p_es_video = es_out_Add( p_input->p_es_out, &p_sys->fmt_video ); |
|---|
| | 221 | #endif |
|---|
| | 222 | |
|---|
| | 223 | p_sys->p_es_video = es_out_Add( p_demux->out, &p_sys->fmt_video ); |
|---|
| 231 | 224 | |
|---|
| 232 | 225 | /* Audio stuff */ |
|---|
| … | … | |
| 255 | 248 | p_sys->fmt_audio.audio.i_bitspersample = 16; |
|---|
| 256 | 249 | |
|---|
| 257 | | p_sys->p_es_audio = es_out_Add( p_input->p_es_out, &p_sys->fmt_audio ); |
|---|
| | 250 | p_sys->p_es_audio = es_out_Add( p_demux->out, &p_sys->fmt_audio ); |
|---|
| 258 | 251 | } |
|---|
| 259 | 252 | |
|---|
| … | … | |
| 266 | 259 | static void Close( vlc_object_t *p_this ) |
|---|
| 267 | 260 | { |
|---|
| 268 | | input_thread_t *p_input = (input_thread_t *)p_this; |
|---|
| 269 | | demux_sys_t *p_sys = p_input->p_demux_data; |
|---|
| | 261 | demux_t *p_demux = (demux_t*)p_this; |
|---|
| | 262 | demux_sys_t *p_sys = p_demux->p_sys; |
|---|
| 270 | 263 | |
|---|
| 271 | 264 | free( p_sys ); |
|---|
| … | … | |
| 277 | 270 | * Returns -1 in case of error, 0 in case of EOF, 1 otherwise |
|---|
| 278 | 271 | *****************************************************************************/ |
|---|
| 279 | | static int Demux( input_thread_t * p_input ) |
|---|
| 280 | | { |
|---|
| 281 | | demux_sys_t *p_sys = p_input->p_demux_data; |
|---|
| 282 | | block_t *p_block; |
|---|
| 283 | | vlc_bool_t b_audio = VLC_FALSE, b_video = VLC_FALSE; |
|---|
| 284 | | |
|---|
| 285 | | if( p_input->stream.p_selected_program->i_synchro_state == SYNCHRO_REINIT ) |
|---|
| 286 | | { |
|---|
| 287 | | off_t i_pos = stream_Tell( p_input->s ); |
|---|
| 288 | | |
|---|
| 289 | | msg_Warn( p_input, "synchro reinit" ); |
|---|
| 290 | | |
|---|
| 291 | | /* If the user tried to seek in the stream, we need to make sure |
|---|
| 292 | | * the new position is at a DIF block boundary. */ |
|---|
| 293 | | if( i_pos % p_sys->frame_size > 0 ) |
|---|
| 294 | | { |
|---|
| 295 | | i_pos += p_sys->frame_size - i_pos % p_sys->frame_size; |
|---|
| 296 | | |
|---|
| 297 | | if( stream_Seek( p_input->s, i_pos ) ) |
|---|
| 298 | | { |
|---|
| 299 | | msg_Warn( p_input, "cannot resynch after seek (EOF?)" ); |
|---|
| 300 | | return -1; |
|---|
| 301 | | } |
|---|
| 302 | | } |
|---|
| 303 | | } |
|---|
| | 272 | static int Demux( demux_t *p_demux ) |
|---|
| | 273 | { |
|---|
| | 274 | demux_sys_t *p_sys = p_demux->p_sys; |
|---|
| | 275 | block_t *p_block; |
|---|
| | 276 | vlc_bool_t b_audio = VLC_FALSE; |
|---|
| 304 | 277 | |
|---|
| 305 | 278 | /* Call the pace control */ |
|---|
| 306 | | input_ClockManageRef( p_input, p_input->stream.p_selected_program, |
|---|
| 307 | | p_sys->i_pcr ); |
|---|
| 308 | | |
|---|
| 309 | | if( ( p_block = stream_Block( p_input->s, p_sys->frame_size ) ) == NULL ) |
|---|
| | 279 | es_out_Control( p_demux->out, ES_OUT_SET_PCR, p_sys->i_pcr ); |
|---|
| | 280 | |
|---|
| | 281 | if( ( p_block = stream_Block( p_demux->s, p_sys->frame_size ) ) == NULL ) |
|---|
| 310 | 282 | { |
|---|
| 311 | 283 | /* EOF */ |
|---|
| … | … | |
| 313 | 285 | } |
|---|
| 314 | 286 | |
|---|
| 315 | | es_out_Control( p_input->p_es_out, ES_OUT_GET_ES_STATE, |
|---|
| 316 | | p_sys->p_es_video, &b_video ); |
|---|
| 317 | | |
|---|
| 318 | 287 | if( p_sys->p_es_audio ) |
|---|
| 319 | 288 | { |
|---|
| 320 | | es_out_Control( p_input->p_es_out, ES_OUT_GET_ES_STATE, |
|---|
| | 289 | es_out_Control( p_demux->out, ES_OUT_GET_ES_STATE, |
|---|
| 321 | 290 | p_sys->p_es_audio, &b_audio ); |
|---|
| 322 | 291 | } |
|---|
| 323 | 292 | |
|---|
| 324 | 293 | p_block->i_dts = |
|---|
| 325 | | p_block->i_pts = input_ClockGetTS( p_input, |
|---|
| 326 | | p_input->stream.p_selected_program, |
|---|
| 327 | | p_sys->i_pcr ); |
|---|
| | 294 | p_block->i_pts = p_sys->i_pcr; |
|---|
| | 295 | |
|---|
| 328 | 296 | if( b_audio ) |
|---|
| 329 | 297 | { |
|---|
| 330 | | block_t *p_audio_block = dv_extract_audio( p_input, p_block ); |
|---|
| | 298 | block_t *p_audio_block = dv_extract_audio( p_demux, p_block ); |
|---|
| 331 | 299 | if( p_audio_block ) |
|---|
| 332 | 300 | { |
|---|
| 333 | | p_audio_block->i_pts = p_audio_block->i_dts = p_block->i_dts; |
|---|
| 334 | | es_out_Send( p_input->p_es_out, p_sys->p_es_audio, p_audio_block ); |
|---|
| | 301 | p_audio_block->i_pts = |
|---|
| | 302 | p_audio_block->i_dts = p_sys->i_pcr; |
|---|
| | 303 | es_out_Send( p_demux->out, p_sys->p_es_audio, p_audio_block ); |
|---|
| 335 | 304 | } |
|---|
| 336 | 305 | } |
|---|
| 337 | 306 | |
|---|
| 338 | | if( b_video ) |
|---|
| 339 | | es_out_Send( p_input->p_es_out, p_sys->p_es_video, p_block ); |
|---|
| 340 | | else |
|---|
| 341 | | block_Release( p_block ); |
|---|
| 342 | | |
|---|
| 343 | | p_sys->i_pcr += ( 90000 / p_sys->f_rate ); |
|---|
| | 307 | es_out_Send( p_demux->out, p_sys->p_es_video, p_block ); |
|---|
| | 308 | |
|---|
| | 309 | p_sys->i_pcr += ( I64C(1000000) / p_sys->f_rate ); |
|---|
| 344 | 310 | |
|---|
| 345 | 311 | return 1; |
|---|
| | 312 | } |
|---|
| | 313 | |
|---|
| | 314 | /***************************************************************************** |
|---|
| | 315 | * Control: |
|---|
| | 316 | *****************************************************************************/ |
|---|
| | 317 | static int Control( demux_t *p_demux, int i_query, va_list args ) |
|---|
| | 318 | { |
|---|
| | 319 | demux_sys_t *p_sys = p_demux->p_sys; |
|---|
| | 320 | |
|---|
| | 321 | /* XXX: DEMUX_SET_TIME is precise here */ |
|---|
| | 322 | return demux2_vaControlHelper( p_demux->s, |
|---|
| | 323 | 0, -1, |
|---|
| | 324 | p_sys->frame_size * p_sys->f_rate * 8, |
|---|
| | 325 | p_sys->frame_size, i_query, args ); |
|---|
| 346 | 326 | } |
|---|
| 347 | 327 | |
|---|
| … | … | |
| 352 | 332 | { 18, 48, 78, 8, 38, 68, 28, 58, 88 }, |
|---|
| 353 | 333 | { 24, 54, 84, 14, 44, 74, 4, 34, 64 }, |
|---|
| 354 | | |
|---|
| | 334 | |
|---|
| 355 | 335 | { 1, 31, 61, 21, 51, 81, 11, 41, 71 }, /* 2nd channel */ |
|---|
| 356 | 336 | { 7, 37, 67, 27, 57, 87, 17, 47, 77 }, |
|---|
| … | … | |
| 365 | 345 | { 12, 48, 84, 2, 38, 74, 28, 64, 100}, |
|---|
| 366 | 346 | { 18, 54, 90, 8, 44, 80, 34, 70, 106}, |
|---|
| 367 | | { 24, 60, 96, 14, 50, 86, 4, 40, 76}, |
|---|
| | 347 | { 24, 60, 96, 14, 50, 86, 4, 40, 76}, |
|---|
| 368 | 348 | { 30, 66, 102, 20, 56, 92, 10, 46, 82}, |
|---|
| 369 | | |
|---|
| | 349 | |
|---|
| 370 | 350 | { 1, 37, 73, 27, 63, 99, 17, 53, 89}, /* 2nd channel */ |
|---|
| 371 | 351 | { 7, 43, 79, 33, 69, 105, 23, 59, 95}, |
|---|
| 372 | 352 | { 13, 49, 85, 3, 39, 75, 29, 65, 101}, |
|---|
| 373 | 353 | { 19, 55, 91, 9, 45, 81, 35, 71, 107}, |
|---|
| 374 | | { 25, 61, 97, 15, 51, 87, 5, 41, 77}, |
|---|
| | 354 | { 25, 61, 97, 15, 51, 87, 5, 41, 77}, |
|---|
| 375 | 355 | { 31, 67, 103, 21, 57, 93, 11, 47, 83}, |
|---|
| 376 | 356 | }; |
|---|
| … | … | |
| 379 | 359 | { |
|---|
| 380 | 360 | uint16_t shift, result; |
|---|
| 381 | | |
|---|
| | 361 | |
|---|
| 382 | 362 | sample = (sample < 0x800) ? sample : sample | 0xf000; |
|---|
| 383 | 363 | shift = (sample & 0xf00) >> 8; |
|---|
| … | … | |
| 396 | 376 | } |
|---|
| 397 | 377 | |
|---|
| 398 | | static block_t *dv_extract_audio( input_thread_t * p_input, |
|---|
| | 378 | static block_t *dv_extract_audio( demux_t *p_demux, |
|---|
| 399 | 379 | block_t* p_frame_block ) |
|---|
| 400 | 380 | { |
|---|
| 401 | | demux_sys_t *p_sys = p_input->p_demux_data; |
|---|
| | 381 | demux_sys_t *p_sys = p_demux->p_sys; |
|---|
| 402 | 382 | block_t *p_block; |
|---|
| 403 | 383 | uint8_t *p_frame, *p_buf; |
|---|
| … | … | |
| 414 | 394 | if( i_audio_quant > 1 ) |
|---|
| 415 | 395 | { |
|---|
| 416 | | msg_Dbg( p_input, "Unsupported quantization for DV audio"); |
|---|
| | 396 | msg_Dbg( p_demux, "Unsupported quantization for DV audio"); |
|---|
| 417 | 397 | return NULL; |
|---|
| 418 | 398 | } |
|---|
| … | … | |
| 434 | 414 | i_size = (i_size + i_samples) * 4; /* 2ch, 2bytes */ |
|---|
| 435 | 415 | |
|---|
| 436 | | p_block = block_New( p_input, i_size ); |
|---|
| | 416 | p_block = block_New( p_demux, i_size ); |
|---|
| 437 | 417 | |
|---|
| 438 | 418 | /* for each DIF segment */ |
|---|
| … | … | |
| 490 | 470 | return p_block; |
|---|
| 491 | 471 | } |
|---|
| | 472 | |
|---|
| | 473 | |
|---|