1 /*****************************************************************************
2 * input_dvd.c: DVD raw reading plugin.
4 * This plugins should handle all the known specificities of the DVD format,
5 * especially the 2048 bytes logical block size.
7 * -input_netlist used to read packets
8 * -dvd_ifo for ifo parsing and analyse
9 * -dvd_css for unscrambling
10 * -dvd_udf to find files
11 *****************************************************************************
12 * Copyright (C) 1998-2001 VideoLAN
13 * $Id: input_dvd.c,v 1.27 2001/03/04 03:12:00 sam Exp $
15 * Author: Stéphane Borel <stef@via.ecp.fr>
17 * This program is free software; you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by
19 * the Free Software Foundation; either version 2 of the License, or
20 * (at your option) any later version.
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
27 * You should have received a copy of the GNU General Public License
28 * along with this program; if not, write to the Free Software
29 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
30 *****************************************************************************/
32 /*****************************************************************************
34 *****************************************************************************/
38 #define MODULE_NAME dvd-css
40 #define MODULE_NAME dvd-nocss
42 #include "modules_inner.h"
47 #include <netinet/in.h>
50 #include <sys/types.h>
67 #include "stream_control.h"
68 #include "input_ext-intf.h"
69 #include "input_ext-dec.h"
73 #include "dvd_netlist.h"
76 #include "input_dvd.h"
77 #include "mpeg_system.h"
83 /*****************************************************************************
85 *****************************************************************************/
94 /* The ISO 639 language codes.
95 * Language names with * prefix are not spelled in their own language
97 { " ", "Not Specified" },
99 { "ab", "*Abkhazian" },
100 { "af", "*Afrikaans" },
101 { "am", "*Amharic" },
103 { "as", "*Assamese" },
105 { "az", "*Azerbaijani" },
106 { "ba", "*Bashkir" },
107 { "be", "*Byelorussian" },
108 { "bg", "*Bulgarian" },
110 { "bi", "*Bislama" },
111 { "bn", "*Bengali; Bangla" },
112 { "bo", "*Tibetan" },
114 { "ca", "*Catalan" },
115 { "co", "*Corsican" },
116 { "cs", "*Czech(Ceske)" },
120 { "dz", "*Bhutani" },
123 { "eo", "*Esperanto" },
125 { "et", "*Estonian" },
127 { "fa", "*Persian" },
130 { "fo", "*Faroese" },
131 { "fr", "Francais" },
132 { "fy", "*Frisian" },
134 { "gd", "*Scots Gaelic" },
135 { "gl", "*Galician" },
136 { "gn", "*Guarani" },
137 { "gu", "*Gujarati" },
139 { "he", "*Hebrew" }, /* formerly iw */
141 { "hr", "Hrvatski" }, /* Croatian */
143 { "hy", "*Armenian" },
144 { "ia", "*Interlingua" },
145 { "id", "*Indonesian" }, /* formerly in */
146 { "ie", "*Interlingue" },
147 { "ik", "*Inupiak" },
148 { "in", "*Indonesian" }, /* replaced by id */
149 { "is", "Islenska" },
150 { "it", "Italiano" },
151 { "iu", "*Inuktitut" },
152 { "iw", "*Hebrew" }, /* replaced by he */
153 { "ja", "*Japanese" },
154 { "ji", "*Yiddish" }, /* replaced by yi */
155 { "jw", "*Javanese" },
156 { "ka", "*Georgian" },
158 { "kl", "*Greenlandic" },
159 { "km", "*Cambodian" },
160 { "kn", "*Kannada" },
162 { "ks", "*Kashmiri" },
163 { "ku", "*Kurdish" },
164 { "ky", "*Kirghiz" },
166 { "ln", "*Lingala" },
167 { "lo", "*Laothian" },
168 { "lt", "*Lithuanian" },
169 { "lv", "*Latvian, Lettish" },
170 { "mg", "*Malagasy" },
172 { "mk", "*Macedonian" },
173 { "ml", "*Malayalam" },
174 { "mn", "*Mongolian" },
175 { "mo", "*Moldavian" },
176 { "mr", "*Marathi" },
178 { "mt", "*Maltese" },
179 { "my", "*Burmese" },
182 { "nl", "Nederlands" },
184 { "oc", "*Occitan" },
185 { "om", "*(Afan) Oromo" },
187 { "pa", "*Punjabi" },
189 { "ps", "*Pashto, Pushto" },
190 { "pt", "Portugues" },
191 { "qu", "*Quechua" },
192 { "rm", "*Rhaeto-Romance" },
193 { "rn", "*Kirundi" },
194 { "ro", "*Romanian" },
195 { "ru", "*Russian" },
196 { "rw", "*Kinyarwanda" },
197 { "sa", "*Sanskrit" },
200 { "sh", "*Serbo-Croatian" },
201 { "si", "*Sinhalese" },
203 { "sl", "*Slovenian" },
207 { "sq", "*Albanian" },
208 { "sr", "*Serbian" },
209 { "ss", "*Siswati" },
210 { "st", "*Sesotho" },
211 { "su", "*Sundanese" },
213 { "sw", "*Swahili" },
218 { "ti", "*Tigrinya" },
219 { "tk", "*Turkmen" },
220 { "tl", "*Tagalog" },
221 { "tn", "*Setswana" },
223 { "tr", "*Turkish" },
228 { "uk", "*Ukrainian" },
231 { "vi", "*Vietnamese" },
232 { "vo", "*Volapuk" },
235 { "yi", "*Yiddish" }, /* formerly ji */
238 { "zh", "*Chinese" },
243 /*****************************************************************************
245 *****************************************************************************/
246 static int DVDProbe ( probedata_t *p_data );
247 static int DVDCheckCSS ( struct input_thread_s * );
248 static int DVDRead ( struct input_thread_s *, data_packet_t ** );
249 static void DVDInit ( struct input_thread_s * );
250 static void DVDEnd ( struct input_thread_s * );
251 static void DVDSeek ( struct input_thread_s *, off_t );
252 static int DVDSetArea ( struct input_thread_s *, int, int, int, int );
253 static int DVDRewind ( struct input_thread_s * );
255 /*****************************************************************************
256 * Functions exported as capabilities. They are declared as static so that
257 * we don't pollute the namespace too much.
258 *****************************************************************************/
259 void _M( input_getfunctions )( function_list_t * p_function_list )
261 #define input p_function_list->functions.input
262 p_function_list->pf_probe = DVDProbe;
263 input.pf_init = DVDInit;
264 input.pf_open = input_FileOpen;
265 input.pf_close = input_FileClose;
266 input.pf_end = DVDEnd;
267 input.pf_read = DVDRead;
268 input.pf_set_area = DVDSetArea;
269 input.pf_demux = input_DemuxPS;
270 input.pf_new_packet = DVDNewPacket;
271 input.pf_new_pes = DVDNewPES;
272 input.pf_delete_packet = DVDDeletePacket;
273 input.pf_delete_pes = DVDDeletePES;
274 input.pf_rewind = DVDRewind;
275 input.pf_seek = DVDSeek;
280 * Local tools to decode some data in ifo
283 /*****************************************************************************
284 * Language: gives the long language name from the two-letters ISO-639 code
285 *****************************************************************************/
286 static char * Language( u16 i_code )
290 while( memcmp( lang_tbl[i].p_code, &i_code, 2 ) &&
291 lang_tbl[i].p_lang_long[0] )
296 return lang_tbl[i].p_lang_long;
300 * Data reading functions
303 /*****************************************************************************
304 * DVDProbe: verifies that the stream is a PS stream
305 *****************************************************************************/
306 static int DVDProbe( probedata_t *p_data )
308 input_thread_t * p_input = (input_thread_t *)p_data;
310 char * psz_name = p_input->p_source;
314 if( TestMethod( INPUT_METHOD_VAR, "dvd" ) )
320 #endif /* HAVE_CSS */
323 if( ( strlen(psz_name) > 4 ) && !strncasecmp( psz_name, "dvd:", 4 ) )
325 /* If the user specified "dvd:" then it's probably a DVD */
330 #endif /* HAVE_CSS */
334 i_handle = open( psz_name, 0 );
344 /*****************************************************************************
345 * DVDCheckCSS: check the stream
346 *****************************************************************************/
347 static int DVDCheckCSS( input_thread_t * p_input )
349 return CSSTest( p_input->i_handle );
352 /*****************************************************************************
353 * DVDCellToOff: synchronize navigation maps with current offset
354 *****************************************************************************/
355 static int DVDCellToOff( thread_dvd_data_t * p_dvd )
362 /*****************************************************************************
363 * DVDFindCell: from cell index in adress map from index in information table.
364 *****************************************************************************/
365 static int DVDFindCell( thread_dvd_data_t * p_dvd, int i_index )
370 p_pgc = &p_dvd->ifo.vts.pgci_ti.p_srp[p_dvd->i_vts_title-1].pgc;
373 while( ( p_pgc->p_cell_pos_inf[i_index].i_vob_id >
374 p_dvd->ifo.vts.c_adt.p_cell_inf[i_cell].i_vob_id ) &&
375 p_dvd->ifo.vts.c_adt.i_cell_nb > i_cell )
377 //if( p_dvd->ifo.vts.c_adt.p_cell_inf[i_cell+1].i_esector*DVD_LB_SIZE >
383 while( ( p_pgc->p_cell_pos_inf[i_index].i_cell_id >
384 p_dvd->ifo.vts.c_adt.p_cell_inf[i_cell].i_cell_id ) &&
385 p_dvd->ifo.vts.c_adt.i_cell_nb > i_cell )
387 //if( p_dvd->ifo.vts.c_adt.p_cell_inf[i_cell+1].i_esector*DVD_LB_SIZE >
397 /*****************************************************************************
398 * DVDChapterSelect: find the cell corresponding to requested chapter
399 * When called to find chapter 1, also sets title size and end.
400 *****************************************************************************/
401 static int DVDChapterSelect( thread_dvd_data_t * p_dvd, int i_chapter )
409 p_pgc = &p_dvd->ifo.vts.pgci_ti.p_srp[p_dvd->i_vts_title-1].pgc;
411 /* Find cell index in Program chain for current chapter */
412 i_index = p_pgc->prg_map.pi_entry_cell[i_chapter-1] - 1;
414 /* Search for cell_index in cell adress_table */
415 i_start_cell = DVDFindCell( p_dvd, i_index );
417 /* intf_WarnMsg( 3, "DVD: Cell: %d vob id: %d cell id: %d", i_start_cell, p_dvd->ifo.vts.c_adt.p_cell_inf[i_start_cell].i_vob_id, p_dvd->ifo.vts.c_adt.p_cell_inf[i_start_cell].i_cell_id );*/
419 /* start is : beginning of vts + offset to vobs + offset to vob x */
420 p_dvd->i_start = p_dvd->ifo.vts.i_pos + DVD_LB_SIZE *
421 (off_t)( p_dvd->ifo.vts.mat.i_tt_vobs_ssector +
422 p_dvd->ifo.vts.c_adt.p_cell_inf[i_start_cell].i_ssector );
424 /* compute size of the stream */
428 p_dvd->ifo.vmg.ptt_srpt.p_tts[p_dvd->i_title-1].i_ptt_nb;
429 i_index = p_pgc->prg_map.pi_entry_cell[i_last_chapter - 1] - 1;
431 /* intf_WarnMsg( 3, "last: %d index: %d", i_last_chapter, i_index );*/
433 i_end_cell = DVDFindCell( p_dvd, i_index );
435 /* intf_WarnMsg( 3, "DVD: Cell: %d vob id: %d cell id: %d", i_end_cell, p_dvd->ifo.vts.c_adt.p_cell_inf[i_end_cell].i_vob_id, p_dvd->ifo.vts.c_adt.p_cell_inf[i_end_cell].i_cell_id );*/
437 p_dvd->i_size = (off_t)DVD_LB_SIZE *
438 ( p_dvd->ifo.vts.c_adt.p_cell_inf[i_end_cell].i_esector -
439 p_dvd->ifo.vts.c_adt.p_cell_inf[i_start_cell].i_ssector + 1 );
440 intf_WarnMsg( 3, "DVD: Start cell: %d End Cell: %d",
441 i_start_cell, i_end_cell );
447 /*****************************************************************************
448 * DVDSetArea: initialize input data for title x, chapter y.
449 * It should be called for each user navigation request, and to change
450 * audio or sub-picture streams.
452 * Take care that i_title starts from 0 (vmg) and i_chapter start from 1.
453 * i_audio, i_spu start from 1 ; 0 means off.
454 * A negative value for an argument means it does not change
455 *****************************************************************************/
456 static int DVDSetArea( input_thread_t * p_input,
457 int i_title, int i_chapter,
458 int i_audio, int i_spu )
460 thread_dvd_data_t * p_method;
461 es_descriptor_t * p_es;
471 p_method = (thread_dvd_data_t*)p_input->p_plugin_data;
473 vlc_mutex_lock( &p_input->stream.stream_lock );
479 * We have to load all title information
482 /* Change the default area */
483 p_input->stream.p_selected_area = p_input->stream.pp_areas[i_title];
485 p_method->i_title = i_title;
487 /* title position inside the selected vts */
488 p_method->i_vts_title =
489 p_method->ifo.vmg.ptt_srpt.p_tts[i_title-1].i_vts_ttn;
492 p_method->ifo.i_title =
493 p_method->ifo.vmg.ptt_srpt.p_tts[i_title-1].i_tts_nb;
496 IfoReadVTS( &(p_method->ifo) );
497 intf_WarnMsg( 2, "ifo info: vts initialized" );
499 /* css title key for current vts */
500 if( p_method->b_encrypted )
502 p_method->p_css->i_title =
503 p_method->ifo.vmg.ptt_srpt.p_tts[i_title-1].i_tts_nb;
504 p_method->p_css->i_title_pos =
505 p_method->ifo.vts.i_pos +
506 p_method->ifo.vts.mat.i_tt_vobs_ssector * DVD_LB_SIZE;
507 CSSGetKey( p_method->p_css );
508 intf_WarnMsg( 2, "css info: vts key initialized" );
512 * Set selected title start and size
514 DVDChapterSelect( p_method, 1 );
517 lseek( p_input->i_handle, p_method->i_start, SEEK_SET );
519 intf_WarnMsg( 2, "dvd info: title: %d", i_title );
520 intf_WarnMsg( 2, "dvd info: vobstart at: %lld", p_method->i_start );
521 intf_WarnMsg( 2, "dvd info: stream size: %lld", p_method->i_size );
522 intf_WarnMsg( 2, "dvd info: number of chapters: %d",
523 p_input->stream.p_selected_area->i_part_nb );
525 /* Area definition */
526 p_input->stream.p_selected_area->i_start = p_method->i_start;
527 p_input->stream.p_selected_area->i_size = p_method->i_size;
530 * Destroy obsolete ES by reinitializing program 0
531 * and find all ES in title with ifo data
533 if( p_input->stream.pp_programs != NULL )
535 input_DelProgram( p_input, p_input->stream.pp_programs[0] );
538 input_AddProgram( p_input, 0, sizeof( stream_ps_data_t ) );
542 /* ES 0 -> video MPEG2 */
543 p_es = input_AddES( p_input, p_input->stream.pp_programs[0], 0xe0, 0 );
544 p_es->i_stream_id = 0xe0;
545 p_es->i_type = MPEG2_VIDEO_ES;
546 input_SelectES( p_input, p_es );
547 intf_WarnMsg( 1, "dvd info: video MPEG2 stream" );
549 /* Audio ES, in the order they appear in .ifo */
550 i_nb = p_method->ifo.vts.mat.i_audio_nb;
555 for( i = 1 ; i <= i_nb ; i++ )
559 fprintf( stderr, "Audio %d: %x %x %x %x %x %x %x\n", i,
560 p_method->ifo.vts.mat.p_audio_atrt[i].i_num_channels,
561 p_method->ifo.vts.mat.p_audio_atrt[i].i_coding_mode,
562 p_method->ifo.vts.mat.p_audio_atrt[i].i_multichannel_extension,
563 p_method->ifo.vts.mat.p_audio_atrt[i].i_type,
564 p_method->ifo.vts.mat.p_audio_atrt[i].i_appl_mode,
565 p_method->ifo.vts.mat.p_audio_atrt[i].i_foo,
566 p_method->ifo.vts.mat.p_audio_atrt[i].i_bar );
569 switch( p_method->ifo.vts.mat.p_audio_atrt[i].i_coding_mode )
572 i_id = ( ( 0x7f + i ) << 8 ) | 0xbd;
573 p_es = input_AddES( p_input,
574 p_input->stream.pp_programs[0], i_id, 0 );
575 p_es->i_stream_id = 0xbd;
576 p_es->i_type = AC3_AUDIO_ES;
578 strcpy( p_es->psz_desc, Language( hton16(
579 p_method->ifo.vts.mat.p_audio_atrt[i-1].i_lang_code ) ) );
583 case 0x03: /* MPEG audio */
585 p_es = input_AddES( p_input,
586 p_input->stream.pp_programs[0], i_id, 0 );
587 p_es->i_stream_id = i_id;
588 p_es->i_type = MPEG2_AUDIO_ES;
590 strcpy( p_es->psz_desc, Language( hton16(
591 p_method->ifo.vts.mat.p_audio_atrt[i-1].i_lang_code ) ) );
594 case 0x04: /* LPCM */
596 intf_ErrMsg( "dvd error: LPCM audio not handled yet" );
600 intf_ErrMsg( "dvd error: DTS audio not handled yet" );
604 intf_ErrMsg( "dvd error: unknown audio type %.2x",
605 p_method->ifo.vts.mat.p_audio_atrt[i].i_coding_mode );
608 intf_WarnMsg( 1, "dvd info: audio stream %d %s\t(0x%x)",
609 i, p_es->psz_desc, i_id );
613 i_nb = p_method->ifo.vts.mat.i_subpic_nb;
617 for( i = 1 ; i <= i_nb ; i++ )
621 i_id = ( i_sub_pic++ << 8 ) | 0xbd;
622 p_es = input_AddES( p_input,
623 p_input->stream.pp_programs[0], i_id, 0 );
624 p_es->i_stream_id = 0xbd;
625 p_es->i_type = DVD_SPU_ES;
626 strcpy( p_es->psz_desc, Language( hton16(
627 p_method->ifo.vts.mat.p_subpic_atrt[i-1].i_lang_code ) ) );
628 intf_WarnMsg( 1, "dvd info: spu stream %d %s\t(0x%x)",
629 i, p_es->psz_desc, i_id );
631 /* The before the last spu has a 0x0 prefix */
633 ( p_method->ifo.vts.mat.p_subpic_atrt[i].i_prefix == 0 );
640 * Select requested ES
642 if( ( i_audio >= 0 ) || ( i_title >= 0 ) )
645 /* Audio: we check it is in the range and
646 * default it to the first if not */
647 if( i_audio > p_method->ifo.vts.mat.i_audio_nb )
652 p_es = p_input->stream.pp_programs[0]->pp_es[i_audio];
654 /* We can only have one audio channel */
655 /* Look for a preselected one */
657 for( i = 0 ; i < p_input->stream.i_selected_es_number ; i++ )
659 if( p_input->stream.pp_selected_es[i]->b_audio )
669 if( p_input->stream.pp_selected_es[i_index] != p_es )
671 input_UnselectES( p_input,
672 p_input->stream.pp_selected_es[i_index] );
673 input_SelectES( p_input, p_es );
674 intf_WarnMsg( 1, "dvd info: audio %d selected -> %s (0x%x)",
675 i_audio, p_es->psz_desc, p_es->i_id );
680 input_SelectES( p_input, p_es );
681 intf_WarnMsg( 1, "dvd info: audio %d selected -> %s (0x%x)",
682 i_audio, p_es->psz_desc, p_es->i_id );
686 if( ( i_spu >= 0 ) || ( i_title >= 0 ) )
688 /* For spu: no one if none or a not existed one requested */
689 if( ( i_spu <= p_method->ifo.vts.mat.i_subpic_nb ) && ( i_spu > 0 ) )
691 input_SelectES( p_input, ( p_es = p_input->stream.pp_programs[0]->
692 pp_es[ i_spu + p_method->ifo.vts.mat.i_audio_nb ] ) );
694 intf_WarnMsg( 1, "dvd info: spu %d selected -> %s (0x%x)",
695 i_spu, p_es->psz_desc, p_es->i_id );
703 if( ( i_chapter > 0 ) &&
704 ( i_chapter <= p_input->stream.p_selected_area->i_part_nb ) )
706 DVDChapterSelect( p_method, i_chapter );
708 p_input->stream.p_selected_area->i_part = i_chapter;
710 DVDSeek( p_input, p_method->i_start -
711 p_input->stream.p_selected_area->i_start );
713 intf_WarnMsg( 2, "dvd info: chapter %d start at: %lld", i_chapter,
714 p_input->stream.p_selected_area->i_tell );
717 /* No PSM to read in DVD mode, we already have all information */
718 p_input->stream.pp_programs[0]->b_is_ok = 1;
720 vlc_mutex_unlock( &p_input->stream.stream_lock );
725 /*****************************************************************************
726 * DVDInit: initializes DVD structures
727 *****************************************************************************/
728 static void DVDInit( input_thread_t * p_input )
730 thread_dvd_data_t * p_method;
737 if( (p_method = malloc( sizeof(thread_dvd_data_t) )) == NULL )
739 intf_ErrMsg( "Out of memory" );
740 p_input->b_error = 1;
744 p_input->p_plugin_data = (void *)p_method;
745 p_input->p_method_data = NULL;
747 p_method->i_fd = p_input->i_handle;
749 p_method->i_block_once = 32;
750 p_input->i_read_once = 128;
752 p_method->b_encrypted = DVDCheckCSS( p_input );
754 lseek( p_input->i_handle, 0, SEEK_SET );
756 /* Reading structures initialisation */
757 p_input->p_method_data =
758 DVDNetlistInit( 4096, 16384, 4096, DVD_LB_SIZE, p_method->i_block_once );
759 intf_WarnMsg( 2, "dvd info: netlist initialized" );
761 /* Ifo initialisation */
762 p_method->ifo = IfoInit( p_input->i_handle );
763 intf_WarnMsg( 2, "ifo info: vmg initialized" );
765 /* CSS initialisation */
766 if( p_method->b_encrypted )
768 p_method->p_css = CSSInit( p_input->i_handle );
770 if( p_method->p_css == NULL )
772 intf_ErrMsg( "css error: fatal failure" );
773 p_input->b_error = 1;
777 intf_WarnMsg( 2, "css info: initialized" );
780 /* Initialize ES structures */
781 input_InitStream( p_input, sizeof( stream_ps_data_t ) );
783 /* Set stream and area data */
784 vlc_mutex_lock( &p_input->stream.stream_lock );
786 #define srpt p_method->ifo.vmg.ptt_srpt
787 intf_WarnMsg( 2, "dvd info: number of titles: %d", srpt.i_ttu_nb );
789 #define area p_input->stream.pp_areas
790 /* We start from 1 here since area 0 is reserved for video_ts.vob */
791 for( i = 1 ; i <= srpt.i_ttu_nb ; i++ )
793 input_AddArea( p_input );
795 /* Should not be so simple eventually :
796 * are title Program Chains, or still something else ? */
799 /* Absolute start offset and size
800 * We can only set that with vts ifo, so we do it during the
801 * first call to DVDSetArea */
802 area[i]->i_start = 0;
805 /* Number of chapter */
806 area[i]->i_part_nb = srpt.p_tts[i-1].i_ptt_nb;
809 /* Offset to vts_i_0.ifo */
810 area[i]->i_plugin_data = p_method->ifo.i_off +
811 ( srpt.p_tts[i-1].i_ssector * DVD_LB_SIZE );
815 vlc_mutex_unlock( &p_input->stream.stream_lock );
817 /* Get requested title - if none try to find one where is the movie */
818 i_title = main_GetIntVariable( INPUT_TITLE_VAR, 1 );
819 if( i_title <= 0 || i_title > srpt.i_ttu_nb )
825 /* Get requested chapter - if none defaults to first one */
826 i_chapter = main_GetIntVariable( INPUT_CHAPTER_VAR, 1 );
832 /* For audio: first one if none or a not existing one specified */
833 i_audio = main_GetIntVariable( INPUT_CHANNEL_VAR, 1 );
836 main_PutIntVariable( INPUT_CHANNEL_VAR, 1 );
840 i_spu = main_GetIntVariable( INPUT_SUBTITLE_VAR, 0 );
842 DVDSetArea( p_input, i_title, i_chapter, i_audio, i_spu );
847 /*****************************************************************************
848 * DVDEnd: frees unused data
849 *****************************************************************************/
850 static void DVDEnd( input_thread_t * p_input )
852 thread_dvd_data_t * p_method;
853 dvd_netlist_t * p_netlist;
855 p_method = (thread_dvd_data_t*)p_input->p_plugin_data;
856 p_netlist = (dvd_netlist_t *)p_input->p_method_data;
858 CSSEnd( p_method->p_css );
859 // IfoEnd( p_method->p_ifo ) );
861 DVDNetlistEnd( p_netlist );
864 /*****************************************************************************
865 * DVDRead: reads data packets into the netlist.
866 *****************************************************************************
867 * Returns -1 in case of error, 0 if everything went well, and 1 in case of
869 *****************************************************************************/
870 static int DVDRead( input_thread_t * p_input,
871 data_packet_t ** pp_packets )
873 thread_dvd_data_t * p_method;
874 dvd_netlist_t * p_netlist;
875 struct iovec * p_vec;
876 struct data_packet_s * pp_data[p_input->i_read_once];
883 p_method = (thread_dvd_data_t *)p_input->p_plugin_data;
884 p_netlist = (dvd_netlist_t *)p_input->p_method_data;
886 /* Get an iovec pointer */
887 if( ( p_vec = DVDGetiovec( p_netlist ) ) == NULL )
889 intf_ErrMsg( "DVD: read error" );
894 readv( p_input->i_handle, p_vec, p_method->i_block_once );
896 /* Update netlist indexes */
897 DVDMviovec( p_netlist, p_method->i_block_once, pp_data );
900 /* Read headers to compute payload length */
901 for( i_iovec = 0 ; i_iovec < p_method->i_block_once ; i_iovec++ )
903 if( p_method->b_encrypted )
905 CSSDescrambleSector( p_method->p_css->pi_title_key,
906 p_vec[i_iovec].iov_base );
907 ((u8*)(p_vec[i_iovec].iov_base))[0x14] &= 0x8F;
912 while( i_pos < p_netlist->i_buffer_size )
914 pi_cur = (u8*)(p_vec[i_iovec].iov_base + i_pos);
917 if( U32_AT( pi_cur ) != 0x1BA )
919 /* That's the case for all packets, except pack header. */
920 i_packet_size = U16_AT( pi_cur + 4 );
921 pp_packets[i_packet] = DVDNewPtr( p_netlist );
926 if( ( pi_cur[4] & 0xC0 ) == 0x40 )
931 else if( ( pi_cur[4] & 0xF0 ) == 0x20 )
938 intf_ErrMsg( "Unable to determine stream type" );
942 pp_packets[i_packet] = pp_data[i_iovec];
946 (*pp_data[i_iovec]->pi_refcount)++;
948 pp_packets[i_packet]->pi_refcount = pp_data[i_iovec]->pi_refcount;
950 pp_packets[i_packet]->p_buffer = pp_data[i_iovec]->p_buffer;
952 pp_packets[i_packet]->p_payload_start =
953 pp_packets[i_packet]->p_buffer + i_pos;
955 pp_packets[i_packet]->p_payload_end =
956 pp_packets[i_packet]->p_payload_start + i_packet_size + 6;
959 i_pos += i_packet_size + 6;
963 pp_packets[i_packet] = NULL;
965 vlc_mutex_lock( &p_input->stream.stream_lock );
966 p_input->stream.p_selected_area->i_tell +=
967 p_method->i_block_once *DVD_LB_SIZE;
968 vlc_mutex_unlock( &p_input->stream.stream_lock );
974 /*****************************************************************************
975 * DVDRewind : reads a stream backward
976 *****************************************************************************/
977 static int DVDRewind( input_thread_t * p_input )
982 /*****************************************************************************
983 * DVDSeek : Goes to a given position on the stream ; this one is used by the
984 * input and translate chronological position from input to logical postion
986 *****************************************************************************/
987 static void DVDSeek( input_thread_t * p_input, off_t i_off )
989 thread_dvd_data_t * p_method;
992 p_method = ( thread_dvd_data_t * )p_input->p_plugin_data;
994 /* We have to take care of offset of beginning of title */
995 i_pos = i_off + p_input->stream.p_selected_area->i_start;
997 /* With DVD, we have to be on a sector boundary */
998 i_pos = i_pos & (~0x7ff);
1000 i_pos = lseek( p_input->i_handle, i_pos, SEEK_SET );
1002 p_input->stream.p_selected_area->i_tell = i_pos -
1003 p_input->stream.p_selected_area->i_start;