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.25 2001/03/03 07:07:01 stef 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 #define MODULE_NAME dvd
33 #include "modules_inner.h"
35 /*****************************************************************************
37 *****************************************************************************/
43 #include <netinet/in.h>
46 #include <sys/types.h>
63 #include "stream_control.h"
64 #include "input_ext-intf.h"
65 #include "input_ext-dec.h"
69 #include "dvd_netlist.h"
72 #include "input_dvd.h"
73 #include "mpeg_system.h"
79 /*****************************************************************************
81 *****************************************************************************/
90 /* The ISO 639 language codes.
91 * Language names with * prefix are not spelled in their own language
93 { " ", "Not Specified" },
95 { "ab", "*Abkhazian" },
96 { "af", "*Afrikaans" },
99 { "as", "*Assamese" },
101 { "az", "*Azerbaijani" },
102 { "ba", "*Bashkir" },
103 { "be", "*Byelorussian" },
104 { "bg", "*Bulgarian" },
106 { "bi", "*Bislama" },
107 { "bn", "*Bengali; Bangla" },
108 { "bo", "*Tibetan" },
110 { "ca", "*Catalan" },
111 { "co", "*Corsican" },
112 { "cs", "*Czech(Ceske)" },
116 { "dz", "*Bhutani" },
119 { "eo", "*Esperanto" },
121 { "et", "*Estonian" },
123 { "fa", "*Persian" },
126 { "fo", "*Faroese" },
127 { "fr", "Francais" },
128 { "fy", "*Frisian" },
130 { "gd", "*Scots Gaelic" },
131 { "gl", "*Galician" },
132 { "gn", "*Guarani" },
133 { "gu", "*Gujarati" },
135 { "he", "*Hebrew" }, /* formerly iw */
137 { "hr", "Hrvatski" }, /* Croatian */
139 { "hy", "*Armenian" },
140 { "ia", "*Interlingua" },
141 { "id", "*Indonesian" }, /* formerly in */
142 { "ie", "*Interlingue" },
143 { "ik", "*Inupiak" },
144 { "in", "*Indonesian" }, /* replaced by id */
145 { "is", "Islenska" },
146 { "it", "Italiano" },
147 { "iu", "*Inuktitut" },
148 { "iw", "*Hebrew" }, /* replaced by he */
149 { "ja", "*Japanese" },
150 { "ji", "*Yiddish" }, /* replaced by yi */
151 { "jw", "*Javanese" },
152 { "ka", "*Georgian" },
154 { "kl", "*Greenlandic" },
155 { "km", "*Cambodian" },
156 { "kn", "*Kannada" },
158 { "ks", "*Kashmiri" },
159 { "ku", "*Kurdish" },
160 { "ky", "*Kirghiz" },
162 { "ln", "*Lingala" },
163 { "lo", "*Laothian" },
164 { "lt", "*Lithuanian" },
165 { "lv", "*Latvian, Lettish" },
166 { "mg", "*Malagasy" },
168 { "mk", "*Macedonian" },
169 { "ml", "*Malayalam" },
170 { "mn", "*Mongolian" },
171 { "mo", "*Moldavian" },
172 { "mr", "*Marathi" },
174 { "mt", "*Maltese" },
175 { "my", "*Burmese" },
178 { "nl", "Nederlands" },
180 { "oc", "*Occitan" },
181 { "om", "*(Afan) Oromo" },
183 { "pa", "*Punjabi" },
185 { "ps", "*Pashto, Pushto" },
186 { "pt", "Portugues" },
187 { "qu", "*Quechua" },
188 { "rm", "*Rhaeto-Romance" },
189 { "rn", "*Kirundi" },
190 { "ro", "*Romanian" },
191 { "ru", "*Russian" },
192 { "rw", "*Kinyarwanda" },
193 { "sa", "*Sanskrit" },
196 { "sh", "*Serbo-Croatian" },
197 { "si", "*Sinhalese" },
199 { "sl", "*Slovenian" },
203 { "sq", "*Albanian" },
204 { "sr", "*Serbian" },
205 { "ss", "*Siswati" },
206 { "st", "*Sesotho" },
207 { "su", "*Sundanese" },
209 { "sw", "*Swahili" },
214 { "ti", "*Tigrinya" },
215 { "tk", "*Turkmen" },
216 { "tl", "*Tagalog" },
217 { "tn", "*Setswana" },
219 { "tr", "*Turkish" },
224 { "uk", "*Ukrainian" },
227 { "vi", "*Vietnamese" },
228 { "vo", "*Volapuk" },
231 { "yi", "*Yiddish" }, /* formerly ji */
234 { "zh", "*Chinese" },
239 /*****************************************************************************
241 *****************************************************************************/
242 static int DVDProbe ( probedata_t *p_data );
243 static int DVDCheckCSS ( struct input_thread_s * );
244 static int DVDRead ( struct input_thread_s *, data_packet_t ** );
245 static void DVDInit ( struct input_thread_s * );
246 static void DVDEnd ( struct input_thread_s * );
247 static void DVDSeek ( struct input_thread_s *, off_t );
248 static int DVDSetArea ( struct input_thread_s *, int, int, int, int );
249 static int DVDRewind ( struct input_thread_s * );
251 /*****************************************************************************
252 * Functions exported as capabilities. They are declared as static so that
253 * we don't pollute the namespace too much.
254 *****************************************************************************/
255 void _M( input_getfunctions )( function_list_t * p_function_list )
257 #define input p_function_list->functions.input
258 p_function_list->pf_probe = DVDProbe;
259 input.pf_init = DVDInit;
260 input.pf_open = input_FileOpen;
261 input.pf_close = input_FileClose;
262 input.pf_end = DVDEnd;
263 input.pf_read = DVDRead;
264 input.pf_set_area = DVDSetArea;
265 input.pf_demux = input_DemuxPS;
266 input.pf_new_packet = DVDNewPacket;
267 input.pf_new_pes = DVDNewPES;
268 input.pf_delete_packet = DVDDeletePacket;
269 input.pf_delete_pes = DVDDeletePES;
270 input.pf_rewind = DVDRewind;
271 input.pf_seek = DVDSeek;
276 * Local tools to decode some data in ifo
279 /*****************************************************************************
280 * Language: gives the long language name from the two-letters ISO-639 code
281 *****************************************************************************/
282 static char * Language( u16 i_code )
286 while( memcmp( lang_tbl[i].p_code, &i_code, 2 ) &&
287 lang_tbl[i].p_lang_long[0] )
292 return lang_tbl[i].p_lang_long;
296 * Data reading functions
299 /*****************************************************************************
300 * DVDProbe: verifies that the stream is a PS stream
301 *****************************************************************************/
302 static int DVDProbe( probedata_t *p_data )
304 input_thread_t * p_input = (input_thread_t *)p_data;
306 char * psz_name = p_input->p_source;
310 if( TestMethod( INPUT_METHOD_VAR, "dvd" ) )
315 if( ( strlen(psz_name) > 4 ) && !strncasecmp( psz_name, "dvd:", 4 ) )
317 /* If the user specified "dvd:" then it's probably a DVD */
322 i_handle = open( psz_name, 0 );
332 /*****************************************************************************
333 * DVDCheckCSS: check the stream
334 *****************************************************************************/
335 static int DVDCheckCSS( input_thread_t * p_input )
337 return CSSTest( p_input->i_handle );
340 /*****************************************************************************
341 * DVDCellToOff: synchronize navigation maps with current offset
342 *****************************************************************************/
343 static int DVDCellToOff( thread_dvd_data_t * p_dvd )
350 /*****************************************************************************
351 * DVDFindCell: from cell index in adress map from index in information table.
352 *****************************************************************************/
353 static int DVDFindCell( thread_dvd_data_t * p_dvd, int i_index )
358 p_pgc = &p_dvd->ifo.vts.pgci_ti.p_srp[p_dvd->i_vts_title-1].pgc;
361 while( ( p_pgc->p_cell_pos_inf[i_index].i_vob_id >
362 p_dvd->ifo.vts.c_adt.p_cell_inf[i_cell].i_vob_id ) &&
363 p_dvd->ifo.vts.c_adt.i_cell_nb > i_cell )
365 //if( p_dvd->ifo.vts.c_adt.p_cell_inf[i_cell+1].i_esector*DVD_LB_SIZE >
371 while( ( p_pgc->p_cell_pos_inf[i_index].i_cell_id >
372 p_dvd->ifo.vts.c_adt.p_cell_inf[i_cell].i_cell_id ) &&
373 p_dvd->ifo.vts.c_adt.i_cell_nb > i_cell )
375 //if( p_dvd->ifo.vts.c_adt.p_cell_inf[i_cell+1].i_esector*DVD_LB_SIZE >
385 /*****************************************************************************
386 * DVDChapterSelect: find the cell corresponding to requested chapter
387 * When called to find chapter 1, also sets title size and end.
388 *****************************************************************************/
389 static int DVDChapterSelect( thread_dvd_data_t * p_dvd, int i_chapter )
397 p_pgc = &p_dvd->ifo.vts.pgci_ti.p_srp[p_dvd->i_vts_title-1].pgc;
399 /* Find cell index in Program chain for current chapter */
400 i_index = p_pgc->prg_map.pi_entry_cell[i_chapter-1] - 1;
402 /* Search for cell_index in cell adress_table */
403 i_start_cell = DVDFindCell( p_dvd, i_index );
405 /* 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 );*/
407 /* start is : beginning of vts + offset to vobs + offset to vob x */
408 p_dvd->i_start = p_dvd->ifo.vts.i_pos + DVD_LB_SIZE *
409 (off_t)( p_dvd->ifo.vts.mat.i_tt_vobs_ssector +
410 p_dvd->ifo.vts.c_adt.p_cell_inf[i_start_cell].i_ssector );
412 /* compute size of the stream */
416 p_dvd->ifo.vmg.ptt_srpt.p_tts[p_dvd->i_title-1].i_ptt_nb;
417 i_index = p_pgc->prg_map.pi_entry_cell[i_last_chapter - 1] - 1;
419 /* intf_WarnMsg( 3, "last: %d index: %d", i_last_chapter, i_index );*/
421 i_end_cell = DVDFindCell( p_dvd, i_index );
423 /* 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 );*/
425 p_dvd->i_size = (off_t)DVD_LB_SIZE *
426 ( p_dvd->ifo.vts.c_adt.p_cell_inf[i_end_cell].i_esector -
427 p_dvd->ifo.vts.c_adt.p_cell_inf[i_start_cell].i_ssector + 1 );
428 intf_WarnMsg( 3, "DVD: Start cell: %d End Cell: %d",
429 i_start_cell, i_end_cell );
435 /*****************************************************************************
436 * DVDSetArea: initialize input data for title x, chapter y.
437 * It should be called for each user navigation request, and to change
438 * audio or sub-picture streams.
440 * Take care that i_title starts from 0 (vmg) and i_chapter start from 1.
441 * i_audio, i_spu start from 1 ; 0 means off.
442 * A negative value for an argument means it does not change
443 *****************************************************************************/
444 static int DVDSetArea( input_thread_t * p_input,
445 int i_title, int i_chapter,
446 int i_audio, int i_spu )
448 thread_dvd_data_t * p_method;
449 es_descriptor_t * p_es;
459 p_method = (thread_dvd_data_t*)p_input->p_plugin_data;
461 vlc_mutex_lock( &p_input->stream.stream_lock );
467 * We have to load all title information
470 /* Change the default area */
471 p_input->stream.p_selected_area = p_input->stream.pp_areas[i_title];
473 p_method->i_title = i_title;
475 /* title position inside the selected vts */
476 p_method->i_vts_title =
477 p_method->ifo.vmg.ptt_srpt.p_tts[i_title-1].i_vts_ttn;
480 p_method->ifo.i_title =
481 p_method->ifo.vmg.ptt_srpt.p_tts[i_title-1].i_tts_nb;
484 IfoReadVTS( &(p_method->ifo) );
485 intf_WarnMsg( 2, "ifo info: vts initialized" );
487 /* css title key for current vts */
488 if( p_method->b_encrypted )
490 p_method->p_css->i_title =
491 p_method->ifo.vmg.ptt_srpt.p_tts[i_title-1].i_tts_nb;
492 p_method->p_css->i_title_pos =
493 p_method->ifo.vts.i_pos +
494 p_method->ifo.vts.mat.i_tt_vobs_ssector * DVD_LB_SIZE;
495 CSSGetKey( p_method->p_css );
496 intf_WarnMsg( 2, "css info: vts key initialized" );
500 * Set selected title start and size
502 DVDChapterSelect( p_method, 1 );
505 lseek( p_input->i_handle, p_method->i_start, SEEK_SET );
507 intf_WarnMsg( 2, "dvd info: title: %d", i_title );
508 intf_WarnMsg( 2, "dvd info: vobstart at: %lld", p_method->i_start );
509 intf_WarnMsg( 2, "dvd info: stream size: %lld", p_method->i_size );
510 intf_WarnMsg( 2, "dvd info: number of chapters: %d",
511 p_input->stream.p_selected_area->i_part_nb );
513 /* Area definition */
514 p_input->stream.p_selected_area->i_start = p_method->i_start;
515 p_input->stream.p_selected_area->i_size = p_method->i_size;
518 * Destroy obsolete ES by reinitializing program 0
519 * and find all ES in title with ifo data
521 if( p_input->stream.pp_programs != NULL )
523 input_DelProgram( p_input, p_input->stream.pp_programs[0] );
526 input_AddProgram( p_input, 0, sizeof( stream_ps_data_t ) );
530 /* ES 0 -> video MPEG2 */
531 p_es = input_AddES( p_input, p_input->stream.pp_programs[0], 0xe0, 0 );
532 p_es->i_stream_id = 0xe0;
533 p_es->i_type = MPEG2_VIDEO_ES;
534 input_SelectES( p_input, p_es );
535 intf_WarnMsg( 1, "dvd info: video MPEG2 stream" );
537 /* Audio ES, in the order they appear in .ifo */
538 i_nb = p_method->ifo.vts.mat.i_audio_nb;
543 for( i = 1 ; i <= i_nb ; i++ )
547 fprintf( stderr, "Audio %d: %x %x %x %x %x %x %x\n", i,
548 p_method->ifo.vts.mat.p_audio_atrt[i].i_num_channels,
549 p_method->ifo.vts.mat.p_audio_atrt[i].i_coding_mode,
550 p_method->ifo.vts.mat.p_audio_atrt[i].i_multichannel_extension,
551 p_method->ifo.vts.mat.p_audio_atrt[i].i_type,
552 p_method->ifo.vts.mat.p_audio_atrt[i].i_appl_mode,
553 p_method->ifo.vts.mat.p_audio_atrt[i].i_foo,
554 p_method->ifo.vts.mat.p_audio_atrt[i].i_bar );
557 switch( p_method->ifo.vts.mat.p_audio_atrt[i].i_coding_mode )
560 i_id = ( ( 0x7f + i ) << 8 ) | 0xbd;
561 p_es = input_AddES( p_input,
562 p_input->stream.pp_programs[0], i_id, 0 );
563 p_es->i_stream_id = 0xbd;
564 p_es->i_type = AC3_AUDIO_ES;
566 strcpy( p_es->psz_desc, Language( hton16(
567 p_method->ifo.vts.mat.p_audio_atrt[i-1].i_lang_code ) ) );
571 case 0x03: /* MPEG audio */
573 p_es = input_AddES( p_input,
574 p_input->stream.pp_programs[0], i_id, 0 );
575 p_es->i_stream_id = i_id;
576 p_es->i_type = MPEG2_AUDIO_ES;
578 strcpy( p_es->psz_desc, Language( hton16(
579 p_method->ifo.vts.mat.p_audio_atrt[i-1].i_lang_code ) ) );
582 case 0x04: /* LPCM */
584 intf_ErrMsg( "dvd error: LPCM audio not handled yet" );
588 intf_ErrMsg( "dvd error: DTS audio not handled yet" );
592 intf_ErrMsg( "dvd error: unkown audio" );
595 intf_WarnMsg( 1, "dvd info: audio stream %d %s\t(0x%x)",
596 i, p_es->psz_desc, i_id );
600 i_nb = p_method->ifo.vts.mat.i_subpic_nb;
604 for( i = 1 ; i <= i_nb ; i++ )
608 i_id = ( i_sub_pic++ << 8 ) | 0xbd;
609 p_es = input_AddES( p_input,
610 p_input->stream.pp_programs[0], i_id, 0 );
611 p_es->i_stream_id = 0xbd;
612 p_es->i_type = DVD_SPU_ES;
613 strcpy( p_es->psz_desc, Language( hton16(
614 p_method->ifo.vts.mat.p_subpic_atrt[i-1].i_lang_code ) ) );
615 intf_WarnMsg( 1, "dvd info: spu stream %d %s\t(0x%x)",
616 i, p_es->psz_desc, i_id );
618 /* The before the last spu has a 0x0 prefix */
620 ( p_method->ifo.vts.mat.p_subpic_atrt[i].i_prefix == 0 );
627 * Select requested ES
629 if( ( i_audio >= 0 ) || ( i_title >= 0 ) )
632 /* Audio: we check it is in the range and
633 * default it to the first if not */
634 if( i_audio > p_method->ifo.vts.mat.i_audio_nb )
639 p_es = p_input->stream.pp_programs[0]->pp_es[i_audio];
641 /* We can only have one audio channel */
642 /* Look for a preselected one */
644 for( i = 0 ; i < p_input->stream.i_selected_es_number ; i++ )
646 if( p_input->stream.pp_selected_es[i]->b_audio )
656 if( p_input->stream.pp_selected_es[i_index] != p_es )
658 input_UnselectES( p_input,
659 p_input->stream.pp_selected_es[i_index] );
660 input_SelectES( p_input, p_es );
661 intf_WarnMsg( 1, "dvd info: audio %d selected -> %s (0x%x)",
662 i_audio, p_es->psz_desc, p_es->i_id );
667 input_SelectES( p_input, p_es );
668 intf_WarnMsg( 1, "dvd info: audio %d selected -> %s (0x%x)",
669 i_audio, p_es->psz_desc, p_es->i_id );
673 if( ( i_spu >= 0 ) || ( i_title >= 0 ) )
675 /* For spu: no one if none or a not existed one requested */
676 if( ( i_spu <= p_method->ifo.vts.mat.i_subpic_nb ) && ( i_spu > 0 ) )
678 input_SelectES( p_input, ( p_es = p_input->stream.pp_programs[0]->
679 pp_es[ i_spu + p_method->ifo.vts.mat.i_audio_nb ] ) );
681 intf_WarnMsg( 1, "dvd info: spu %d selected -> %s (0x%x)",
682 i_spu, p_es->psz_desc, p_es->i_id );
690 if( ( i_chapter > 0 ) &&
691 ( i_chapter <= p_input->stream.p_selected_area->i_part_nb ) )
693 DVDChapterSelect( p_method, i_chapter );
695 p_input->stream.p_selected_area->i_part = i_chapter;
697 DVDSeek( p_input, p_method->i_start -
698 p_input->stream.p_selected_area->i_start );
700 intf_WarnMsg( 2, "dvd info: chapter %d start at: %lld", i_chapter,
701 p_input->stream.p_selected_area->i_tell );
704 /* No PSM to read in DVD mode, we already have all information */
705 p_input->stream.pp_programs[0]->b_is_ok = 1;
707 vlc_mutex_unlock( &p_input->stream.stream_lock );
712 /*****************************************************************************
713 * DVDInit: initializes DVD structures
714 *****************************************************************************/
715 static void DVDInit( input_thread_t * p_input )
717 thread_dvd_data_t * p_method;
724 if( (p_method = malloc( sizeof(thread_dvd_data_t) )) == NULL )
726 intf_ErrMsg( "Out of memory" );
727 p_input->b_error = 1;
731 p_input->p_plugin_data = (void *)p_method;
732 p_input->p_method_data = NULL;
734 p_method->i_fd = p_input->i_handle;
736 p_method->i_block_once = 32;
737 p_input->i_read_once = 128;
739 p_method->b_encrypted = DVDCheckCSS( p_input );
741 lseek( p_input->i_handle, 0, SEEK_SET );
743 /* Reading structures initialisation */
744 p_input->p_method_data =
745 DVDNetlistInit( 4096, 16384, 4096, DVD_LB_SIZE, p_method->i_block_once );
746 intf_WarnMsg( 2, "dvd info: netlist initialized" );
748 /* Ifo initialisation */
749 p_method->ifo = IfoInit( p_input->i_handle );
750 intf_WarnMsg( 2, "ifo info: vmg initialized" );
752 /* CSS initialisation */
753 if( p_method->b_encrypted )
755 p_method->p_css = CSSInit( p_input->i_handle );
757 if( p_method->p_css == NULL )
759 intf_ErrMsg( "css error: fatal failure" );
760 p_input->b_error = 1;
764 intf_WarnMsg( 2, "css info: initialized" );
767 /* Initialize ES structures */
768 input_InitStream( p_input, sizeof( stream_ps_data_t ) );
770 /* Set stream and area data */
771 vlc_mutex_lock( &p_input->stream.stream_lock );
773 #define srpt p_method->ifo.vmg.ptt_srpt
774 intf_WarnMsg( 2, "dvd info: number of titles: %d", srpt.i_ttu_nb );
776 #define area p_input->stream.pp_areas
777 /* We start from 1 here since area 0 is reserved for video_ts.vob */
778 for( i = 1 ; i <= srpt.i_ttu_nb ; i++ )
780 input_AddArea( p_input );
782 /* Should not be so simple eventually :
783 * are title Program Chains, or still something else ? */
786 /* Absolute start offset and size
787 * We can only set that with vts ifo, so we do it during the
788 * first call to DVDSetArea */
789 area[i]->i_start = 0;
792 /* Number of chapter */
793 area[i]->i_part_nb = srpt.p_tts[i-1].i_ptt_nb;
796 /* Offset to vts_i_0.ifo */
797 area[i]->i_plugin_data = p_method->ifo.i_off +
798 ( srpt.p_tts[i-1].i_ssector * DVD_LB_SIZE );
802 vlc_mutex_unlock( &p_input->stream.stream_lock );
804 /* Get requested title - if none try to find one where is the movie */
805 i_title = main_GetIntVariable( INPUT_TITLE_VAR, 1 );
806 if( i_title <= 0 || i_title > srpt.i_ttu_nb )
812 /* Get requested chapter - if none defaults to first one */
813 i_chapter = main_GetIntVariable( INPUT_CHAPTER_VAR, 1 );
819 /* For audio: first one if none or a not existing one specified */
820 i_audio = main_GetIntVariable( INPUT_CHANNEL_VAR, 1 );
823 main_PutIntVariable( INPUT_CHANNEL_VAR, 1 );
827 i_spu = main_GetIntVariable( INPUT_SUBTITLE_VAR, 0 );
829 DVDSetArea( p_input, i_title, i_chapter, i_audio, i_spu );
834 /*****************************************************************************
835 * DVDEnd: frees unused data
836 *****************************************************************************/
837 static void DVDEnd( input_thread_t * p_input )
839 thread_dvd_data_t * p_method;
840 dvd_netlist_t * p_netlist;
842 p_method = (thread_dvd_data_t*)p_input->p_plugin_data;
843 p_netlist = (dvd_netlist_t *)p_input->p_method_data;
845 CSSEnd( p_method->p_css );
846 // IfoEnd( p_method->p_ifo ) );
848 DVDNetlistEnd( p_netlist );
851 /*****************************************************************************
852 * DVDRead: reads data packets into the netlist.
853 *****************************************************************************
854 * Returns -1 in case of error, 0 if everything went well, and 1 in case of
856 *****************************************************************************/
857 static int DVDRead( input_thread_t * p_input,
858 data_packet_t ** pp_packets )
860 thread_dvd_data_t * p_method;
861 dvd_netlist_t * p_netlist;
862 struct iovec * p_vec;
863 struct data_packet_s * pp_data[p_input->i_read_once];
870 p_method = (thread_dvd_data_t *)p_input->p_plugin_data;
871 p_netlist = (dvd_netlist_t *)p_input->p_method_data;
873 /* Get an iovec pointer */
874 if( ( p_vec = DVDGetiovec( p_netlist ) ) == NULL )
876 intf_ErrMsg( "DVD: read error" );
881 readv( p_input->i_handle, p_vec, p_method->i_block_once );
883 /* Update netlist indexes */
884 DVDMviovec( p_netlist, p_method->i_block_once, pp_data );
887 /* Read headers to compute payload length */
888 for( i_iovec = 0 ; i_iovec < p_method->i_block_once ; i_iovec++ )
890 if( p_method->b_encrypted )
892 CSSDescrambleSector( p_method->p_css->pi_title_key,
893 p_vec[i_iovec].iov_base );
894 ((u8*)(p_vec[i_iovec].iov_base))[0x14] &= 0x8F;
899 while( i_pos < p_netlist->i_buffer_size )
901 pi_cur = (u8*)(p_vec[i_iovec].iov_base + i_pos);
904 if( U32_AT( pi_cur ) != 0x1BA )
906 /* That's the case for all packets, except pack header. */
907 i_packet_size = U16_AT( pi_cur + 4 );
908 pp_packets[i_packet] = DVDNewPtr( p_netlist );
913 if( ( pi_cur[4] & 0xC0 ) == 0x40 )
918 else if( ( pi_cur[4] & 0xF0 ) == 0x20 )
925 intf_ErrMsg( "Unable to determine stream type" );
929 pp_packets[i_packet] = pp_data[i_iovec];
933 (*pp_data[i_iovec]->pi_refcount)++;
935 pp_packets[i_packet]->pi_refcount = pp_data[i_iovec]->pi_refcount;
937 pp_packets[i_packet]->p_buffer = pp_data[i_iovec]->p_buffer;
939 pp_packets[i_packet]->p_payload_start =
940 pp_packets[i_packet]->p_buffer + i_pos;
942 pp_packets[i_packet]->p_payload_end =
943 pp_packets[i_packet]->p_payload_start + i_packet_size + 6;
946 i_pos += i_packet_size + 6;
950 pp_packets[i_packet] = NULL;
952 vlc_mutex_lock( &p_input->stream.stream_lock );
953 p_input->stream.p_selected_area->i_tell +=
954 p_method->i_block_once *DVD_LB_SIZE;
955 vlc_mutex_unlock( &p_input->stream.stream_lock );
961 /*****************************************************************************
962 * DVDRewind : reads a stream backward
963 *****************************************************************************/
964 static int DVDRewind( input_thread_t * p_input )
969 /*****************************************************************************
970 * DVDSeek : Goes to a given position on the stream ; this one is used by the
971 * input and translate chronological position from input to logical postion
973 *****************************************************************************/
974 static void DVDSeek( input_thread_t * p_input, off_t i_off )
976 thread_dvd_data_t * p_method;
979 p_method = ( thread_dvd_data_t * )p_input->p_plugin_data;
981 /* We have to take care of offset of beginning of title */
982 i_pos = i_off + p_input->stream.p_selected_area->i_start;
984 /* With DVD, we have to be on a sector boundary */
985 i_pos = i_pos & (~0x7ff);
987 i_pos = lseek( p_input->i_handle, i_pos, SEEK_SET );
989 p_input->stream.p_selected_area->i_tell = i_pos -
990 p_input->stream.p_selected_area->i_start;