Mercurial > mplayer.hg
annotate libmpdemux/open.c @ 5755:4593e6189c20
more infos
author | jaf |
---|---|
date | Sun, 21 Apr 2002 02:44:25 +0000 |
parents | 4bd766a5632b |
children | 194bca17117b |
rev | line source |
---|---|
1467 | 1 |
4343
b0c8eed7473c
Extended DVD chapter specification. Remove -last-chapter option.
kmkaplan
parents:
4291
diff
changeset
|
2 #include <ctype.h> |
1467 | 3 #include <stdio.h> |
4 #include <stdlib.h> | |
5 #include <string.h> | |
6 #include <unistd.h> | |
7 #include <fcntl.h> | |
8 | |
9 #include "config.h" | |
1567 | 10 #include "mp_msg.h" |
1584 | 11 #include "help_mp.h" |
1467 | 12 |
1468 | 13 #ifdef __FreeBSD__ |
14 #include <sys/cdrio.h> | |
15 #endif | |
16 | |
4343
b0c8eed7473c
Extended DVD chapter specification. Remove -last-chapter option.
kmkaplan
parents:
4291
diff
changeset
|
17 #include "../cfgparser.h" |
1467 | 18 #include "stream.h" |
1482 | 19 #include "demuxer.h" |
4551 | 20 #include "mf.h" |
1467 | 21 |
22 #ifdef STREAMING | |
23 #include "url.h" | |
24 #include "network.h" | |
25 static URL_t* url; | |
26 #endif | |
27 | |
1596 | 28 int dvd_title=0; |
29 int dvd_chapter=1; | |
4291
e889d37f25b2
Add option -last-chapter for DVD playing/encoding
kmkaplan
parents:
4251
diff
changeset
|
30 int dvd_last_chapter=0; |
1596 | 31 int dvd_angle=1; |
4222
de7eddb3fd70
Change to use cdrom-device and dvd-device options needed for DVD/TV/VCD
albeu
parents:
4146
diff
changeset
|
32 char* dvd_device=NULL; |
de7eddb3fd70
Change to use cdrom-device and dvd-device options needed for DVD/TV/VCD
albeu
parents:
4146
diff
changeset
|
33 char* cdrom_device=NULL; |
5472 | 34 int dvd_nav=0; /* use libdvdnav? */ |
5380
8a01cde9cf39
DVDnav support patch by David Holm and Kees Cook <mplayer@outflux.net>
arpi
parents:
4729
diff
changeset
|
35 |
5381 | 36 #ifdef USE_DVDNAV |
5472 | 37 #include "dvdnav_stream.h" |
5380
8a01cde9cf39
DVDnav support patch by David Holm and Kees Cook <mplayer@outflux.net>
arpi
parents:
4729
diff
changeset
|
38 #endif |
1596 | 39 |
40 #ifdef USE_DVDREAD | |
41 | |
42 #include <dvdread/dvd_reader.h> | |
43 #include <dvdread/ifo_types.h> | |
44 #include <dvdread/ifo_read.h> | |
45 #include <dvdread/nav_read.h> | |
1875 | 46 |
47 #define DVDREAD_VERSION(maj,min,micro) ((maj)*10000 + (min)*100 + (micro)) | |
48 | |
49 /* | |
50 * Try to autodetect the libdvd-0.9.0 library | |
51 * (0.9.0 removed the <dvdread/dvd_udf.h> header, and moved the two defines | |
52 * DVD_VIDEO_LB_LEN and MAX_UDF_FILE_NAME_LEN from it to | |
53 * <dvdread/dvd_reader.h>) | |
54 */ | |
55 #if defined(DVD_VIDEO_LB_LEN) && defined(MAX_UDF_FILE_NAME_LEN) | |
56 #define LIBDVDREAD_VERSION DVDREAD_VERSION(0,9,0) | |
57 #else | |
58 #define LIBDVDREAD_VERSION DVDREAD_VERSION(0,8,0) | |
59 #endif | |
60 | |
2935 | 61 char * dvd_audio_stream_types[8] = |
62 { "ac3","unknown","mpeg1","mpeg2ext","lpcm","unknown","dts" }; | |
1596 | 63 |
64 #endif | |
65 | |
1467 | 66 extern int vcd_get_track_end(int fd,int track); |
67 | |
2790 | 68 #ifdef USE_TV |
69 #include "tv.h" | |
2802 | 70 tvi_handle_t *tv_handler; |
2931 | 71 |
72 extern int stream_open_tv(stream_t *stream, tvi_handle_t *tvh); | |
2790 | 73 #endif |
74 | |
1467 | 75 // Open a new stream (stdin/file/vcd/url) |
76 | |
77 stream_t* open_stream(char* filename,int vcd_track,int* file_format){ | |
78 stream_t* stream=NULL; | |
79 int f=-1; | |
80 off_t len; | |
81 #ifdef VCD_CACHE | |
82 int vcd_cache_size=128; | |
83 #endif | |
84 #ifdef __FreeBSD__ | |
85 int bsize = VCD_SECTOR_SIZE; | |
86 #endif | |
87 | |
88 //============ Open VideoCD track ============== | |
3261 | 89 #ifdef HAVE_VCD |
1467 | 90 if(vcd_track){ |
91 int ret,ret2; | |
4222
de7eddb3fd70
Change to use cdrom-device and dvd-device options needed for DVD/TV/VCD
albeu
parents:
4146
diff
changeset
|
92 if(!cdrom_device) cdrom_device=DEFAULT_CDROM_DEVICE; |
de7eddb3fd70
Change to use cdrom-device and dvd-device options needed for DVD/TV/VCD
albeu
parents:
4146
diff
changeset
|
93 f=open(cdrom_device,O_RDONLY); |
de7eddb3fd70
Change to use cdrom-device and dvd-device options needed for DVD/TV/VCD
albeu
parents:
4146
diff
changeset
|
94 if(f<0){ mp_msg(MSGT_OPEN,MSGL_ERR,MSGTR_CdDevNotfound,cdrom_device);return NULL; } |
1467 | 95 vcd_read_toc(f); |
96 ret2=vcd_get_track_end(f,vcd_track); | |
1584 | 97 if(ret2<0){ mp_msg(MSGT_OPEN,MSGL_ERR,MSGTR_ErrTrackSelect " (get)\n");return NULL;} |
1467 | 98 ret=vcd_seek_to_track(f,vcd_track); |
1584 | 99 if(ret<0){ mp_msg(MSGT_OPEN,MSGL_ERR,MSGTR_ErrTrackSelect " (seek)\n");return NULL;} |
1467 | 100 // seek_to_byte+=ret; |
1567 | 101 mp_msg(MSGT_OPEN,MSGL_V,"VCD start byte position: 0x%X end: 0x%X\n",ret,ret2); |
1467 | 102 #ifdef VCD_CACHE |
103 vcd_cache_init(vcd_cache_size); | |
104 #endif | |
105 #ifdef __FreeBSD__ | |
106 if (ioctl (f, CDRIOCSETBLOCKSIZE, &bsize) == -1) { | |
107 perror ( "Error in CDRIOCSETBLOCKSIZE"); | |
108 } | |
109 #endif | |
110 stream=new_stream(f,STREAMTYPE_VCD); | |
111 stream->start_pos=ret; | |
112 stream->end_pos=ret2; | |
113 return stream; | |
114 } | |
3261 | 115 #endif |
1467 | 116 |
1596 | 117 //============ Open DVD title ============== |
5380
8a01cde9cf39
DVDnav support patch by David Holm and Kees Cook <mplayer@outflux.net>
arpi
parents:
4729
diff
changeset
|
118 #ifdef USE_DVDNAV |
8a01cde9cf39
DVDnav support patch by David Holm and Kees Cook <mplayer@outflux.net>
arpi
parents:
4729
diff
changeset
|
119 if(dvd_nav){ |
5472 | 120 dvdnav_priv_t *dvdnav_priv; |
5380
8a01cde9cf39
DVDnav support patch by David Holm and Kees Cook <mplayer@outflux.net>
arpi
parents:
4729
diff
changeset
|
121 int event,len,tmplen=0; |
8a01cde9cf39
DVDnav support patch by David Holm and Kees Cook <mplayer@outflux.net>
arpi
parents:
4729
diff
changeset
|
122 |
8a01cde9cf39
DVDnav support patch by David Holm and Kees Cook <mplayer@outflux.net>
arpi
parents:
4729
diff
changeset
|
123 stream=new_stream(-1,STREAMTYPE_DVDNAV); |
8a01cde9cf39
DVDnav support patch by David Holm and Kees Cook <mplayer@outflux.net>
arpi
parents:
4729
diff
changeset
|
124 if (!stream) { |
8a01cde9cf39
DVDnav support patch by David Holm and Kees Cook <mplayer@outflux.net>
arpi
parents:
4729
diff
changeset
|
125 mp_msg(MSGT_OPEN,MSGL_ERR,MSGTR_Exit_error); |
8a01cde9cf39
DVDnav support patch by David Holm and Kees Cook <mplayer@outflux.net>
arpi
parents:
4729
diff
changeset
|
126 return NULL; |
8a01cde9cf39
DVDnav support patch by David Holm and Kees Cook <mplayer@outflux.net>
arpi
parents:
4729
diff
changeset
|
127 } |
5472 | 128 |
129 if(!filename) filename=DEFAULT_DVD_DEVICE; | |
130 if (!(dvdnav_priv=new_dvdnav_stream(filename))) { | |
131 mp_msg(MSGT_OPEN,MSGL_ERR,MSGTR_CantOpenDVD,filename); | |
132 return NULL; | |
133 } | |
134 | |
135 stream->priv=(void*)dvdnav_priv; | |
5380
8a01cde9cf39
DVDnav support patch by David Holm and Kees Cook <mplayer@outflux.net>
arpi
parents:
4729
diff
changeset
|
136 return stream; |
8a01cde9cf39
DVDnav support patch by David Holm and Kees Cook <mplayer@outflux.net>
arpi
parents:
4729
diff
changeset
|
137 } |
8a01cde9cf39
DVDnav support patch by David Holm and Kees Cook <mplayer@outflux.net>
arpi
parents:
4729
diff
changeset
|
138 #endif |
1596 | 139 #ifdef USE_DVDREAD |
140 if(dvd_title){ | |
2050 | 141 // int ret,ret2; |
5380
8a01cde9cf39
DVDnav support patch by David Holm and Kees Cook <mplayer@outflux.net>
arpi
parents:
4729
diff
changeset
|
142 dvd_priv_t *d; |
1596 | 143 int ttn,pgc_id,pgn; |
144 dvd_reader_t *dvd; | |
145 dvd_file_t *title; | |
146 ifo_handle_t *vmg_file; | |
147 tt_srpt_t *tt_srpt; | |
148 ifo_handle_t *vts_file; | |
149 /** | |
150 * Open the disc. | |
151 */ | |
4222
de7eddb3fd70
Change to use cdrom-device and dvd-device options needed for DVD/TV/VCD
albeu
parents:
4146
diff
changeset
|
152 if(!dvd_device) dvd_device=DEFAULT_DVD_DEVICE; |
de7eddb3fd70
Change to use cdrom-device and dvd-device options needed for DVD/TV/VCD
albeu
parents:
4146
diff
changeset
|
153 dvd = DVDOpen(dvd_device); |
1596 | 154 if( !dvd ) { |
4222
de7eddb3fd70
Change to use cdrom-device and dvd-device options needed for DVD/TV/VCD
albeu
parents:
4146
diff
changeset
|
155 mp_msg(MSGT_OPEN,MSGL_ERR,MSGTR_CantOpenDVD,dvd_device); |
1596 | 156 return NULL; |
157 } | |
158 | |
1973
5216f108cb4f
all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents:
1899
diff
changeset
|
159 mp_msg(MSGT_OPEN,MSGL_INFO,MSGTR_DVDwait); |
1596 | 160 |
161 /** | |
162 * Load the video manager to find out the information about the titles on | |
163 * this disc. | |
164 */ | |
165 vmg_file = ifoOpen( dvd, 0 ); | |
166 if( !vmg_file ) { | |
167 mp_msg(MSGT_OPEN,MSGL_ERR, "Can't open VMG info!\n"); | |
168 DVDClose( dvd ); | |
169 return NULL; | |
170 } | |
171 tt_srpt = vmg_file->tt_srpt; | |
172 /** | |
173 * Make sure our title number is valid. | |
174 */ | |
1973
5216f108cb4f
all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents:
1899
diff
changeset
|
175 mp_msg(MSGT_OPEN,MSGL_INFO, MSGTR_DVDnumTitles, |
1596 | 176 tt_srpt->nr_of_srpts ); |
177 if( dvd_title < 1 || dvd_title > tt_srpt->nr_of_srpts ) { | |
1973
5216f108cb4f
all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents:
1899
diff
changeset
|
178 mp_msg(MSGT_OPEN,MSGL_ERR, MSGTR_DVDinvalidTitle, dvd_title); |
1596 | 179 ifoClose( vmg_file ); |
180 DVDClose( dvd ); | |
181 return NULL; | |
182 } | |
183 --dvd_title; // remap 1.. -> 0.. | |
184 /** | |
185 * Make sure the chapter number is valid for this title. | |
186 */ | |
1973
5216f108cb4f
all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents:
1899
diff
changeset
|
187 mp_msg(MSGT_OPEN,MSGL_INFO, MSGTR_DVDnumChapters, |
1596 | 188 tt_srpt->title[dvd_title].nr_of_ptts ); |
189 if( dvd_chapter<1 || dvd_chapter>tt_srpt->title[dvd_title].nr_of_ptts ) { | |
1973
5216f108cb4f
all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents:
1899
diff
changeset
|
190 mp_msg(MSGT_OPEN,MSGL_ERR, MSGTR_DVDinvalidChapter, dvd_chapter); |
1596 | 191 ifoClose( vmg_file ); |
192 DVDClose( dvd ); | |
193 return NULL; | |
194 } | |
4291
e889d37f25b2
Add option -last-chapter for DVD playing/encoding
kmkaplan
parents:
4251
diff
changeset
|
195 if( dvd_last_chapter>0 ) { |
e889d37f25b2
Add option -last-chapter for DVD playing/encoding
kmkaplan
parents:
4251
diff
changeset
|
196 if ( dvd_last_chapter<dvd_chapter || dvd_last_chapter>tt_srpt->title[dvd_title].nr_of_ptts ) { |
e889d37f25b2
Add option -last-chapter for DVD playing/encoding
kmkaplan
parents:
4251
diff
changeset
|
197 mp_msg(MSGT_OPEN,MSGL_ERR, "Invalid DVD last chapter number: %d\n", dvd_last_chapter); |
e889d37f25b2
Add option -last-chapter for DVD playing/encoding
kmkaplan
parents:
4251
diff
changeset
|
198 ifoClose( vmg_file ); |
e889d37f25b2
Add option -last-chapter for DVD playing/encoding
kmkaplan
parents:
4251
diff
changeset
|
199 DVDClose( dvd ); |
e889d37f25b2
Add option -last-chapter for DVD playing/encoding
kmkaplan
parents:
4251
diff
changeset
|
200 return NULL; |
e889d37f25b2
Add option -last-chapter for DVD playing/encoding
kmkaplan
parents:
4251
diff
changeset
|
201 } |
e889d37f25b2
Add option -last-chapter for DVD playing/encoding
kmkaplan
parents:
4251
diff
changeset
|
202 } |
1596 | 203 --dvd_chapter; // remap 1.. -> 0.. |
4291
e889d37f25b2
Add option -last-chapter for DVD playing/encoding
kmkaplan
parents:
4251
diff
changeset
|
204 /* XXX No need to remap dvd_last_chapter */ |
1596 | 205 /** |
206 * Make sure the angle number is valid for this title. | |
207 */ | |
1973
5216f108cb4f
all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents:
1899
diff
changeset
|
208 mp_msg(MSGT_OPEN,MSGL_INFO, MSGTR_DVDnumAngles, |
1596 | 209 tt_srpt->title[dvd_title].nr_of_angles ); |
210 if( dvd_angle<1 || dvd_angle>tt_srpt->title[dvd_title].nr_of_angles ) { | |
1977 | 211 mp_msg(MSGT_OPEN,MSGL_ERR, MSGTR_DVDinvalidAngle, dvd_angle); |
1596 | 212 ifoClose( vmg_file ); |
213 DVDClose( dvd ); | |
214 return NULL; | |
215 } | |
1617 | 216 --dvd_angle; // remap 1.. -> 0.. |
1596 | 217 /** |
218 * Load the VTS information for the title set our title is in. | |
219 */ | |
220 vts_file = ifoOpen( dvd, tt_srpt->title[dvd_title].title_set_nr ); | |
221 if( !vts_file ) { | |
1973
5216f108cb4f
all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents:
1899
diff
changeset
|
222 mp_msg(MSGT_OPEN,MSGL_ERR, MSGTR_DVDnoIFO, |
1596 | 223 tt_srpt->title[dvd_title].title_set_nr ); |
224 ifoClose( vmg_file ); | |
225 DVDClose( dvd ); | |
226 return NULL; | |
227 } | |
228 /** | |
229 * We've got enough info, time to open the title set data. | |
230 */ | |
231 title = DVDOpenFile( dvd, tt_srpt->title[dvd_title].title_set_nr, | |
232 DVD_READ_TITLE_VOBS ); | |
233 if( !title ) { | |
1973
5216f108cb4f
all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents:
1899
diff
changeset
|
234 mp_msg(MSGT_OPEN,MSGL_ERR, MSGTR_DVDnoVOBs, |
1596 | 235 tt_srpt->title[dvd_title].title_set_nr ); |
236 ifoClose( vts_file ); | |
237 ifoClose( vmg_file ); | |
238 DVDClose( dvd ); | |
239 return NULL; | |
240 } | |
241 | |
1973
5216f108cb4f
all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents:
1899
diff
changeset
|
242 mp_msg(MSGT_OPEN,MSGL_INFO, MSGTR_DVDopenOk); |
1596 | 243 // store data |
244 d=malloc(sizeof(dvd_priv_t)); memset(d,0,sizeof(dvd_priv_t)); | |
245 d->dvd=dvd; | |
246 d->title=title; | |
247 d->vmg_file=vmg_file; | |
248 d->tt_srpt=tt_srpt; | |
249 d->vts_file=vts_file; | |
250 | |
251 /** | |
2935 | 252 * Check number of audio channels and types |
253 */ | |
254 { | |
255 int ac3aid = 128; | |
256 int mpegaid = 0; | |
257 int pcmaid = 160; | |
258 | |
259 d->nr_of_channels=0; | |
260 | |
261 if ( vts_file->vts_pgcit ) | |
262 { | |
263 int i; | |
264 for ( i=0;i<8;i++ ) | |
265 if ( vts_file->vts_pgcit->pgci_srp[0].pgc->audio_control[i] & 0x8000 ) | |
266 { | |
267 audio_attr_t * audio = &vts_file->vtsi_mat->vts_audio_attr[i]; | |
268 int language = 0; | |
269 char tmp[] = "unknown"; | |
270 | |
271 if ( audio->lang_type == 1 ) | |
272 { | |
273 language=audio->lang_code; | |
274 tmp[0]=language>>8; | |
275 tmp[1]=language&0xff; | |
276 tmp[2]=0; | |
277 } | |
278 | |
279 d->audio_streams[d->nr_of_channels].language=language; | |
280 d->audio_streams[d->nr_of_channels].id=0; | |
281 switch ( audio->audio_format ) | |
282 { | |
283 case 0: // ac3 | |
284 case 6: // dts | |
285 d->audio_streams[d->nr_of_channels].id=ac3aid; | |
286 ac3aid++; | |
287 break; | |
288 case 2: // mpeg layer 1/2/3 | |
289 case 3: // mpeg2 ext | |
290 d->audio_streams[d->nr_of_channels].id=mpegaid; | |
291 mpegaid++; | |
292 break; | |
293 case 4: // lpcm | |
294 d->audio_streams[d->nr_of_channels].id=pcmaid; | |
295 pcmaid++; | |
296 break; | |
297 } | |
298 | |
299 mp_msg(MSGT_OPEN,MSGL_V,"[open] audio stream: %d audio format: %s language: %s aid: %d\n", | |
300 d->nr_of_channels, | |
301 dvd_audio_stream_types[ audio->audio_format ], | |
302 tmp, | |
303 d->audio_streams[d->nr_of_channels].id | |
304 ); | |
3753 | 305 |
2935 | 306 d->nr_of_channels++; |
307 } | |
308 } | |
3048 | 309 mp_msg(MSGT_OPEN,MSGL_V,"[open] number of audio channels on disk: %d.\n",d->nr_of_channels ); |
310 } | |
311 | |
312 /** | |
313 * Check number of subtitles and language | |
314 */ | |
315 { | |
316 int i; | |
317 | |
318 d->nr_of_subtitles=0; | |
319 for ( i=0;i<32;i++ ) | |
320 if ( vts_file->vts_pgcit->pgci_srp[0].pgc->subp_control[i] & 0x80000000 ) | |
321 { | |
322 subp_attr_t * subtitle = &vts_file->vtsi_mat->vts_subp_attr[i]; | |
323 int language = 0; | |
324 char tmp[] = "unknown"; | |
325 | |
326 if ( subtitle->type == 1 ) | |
327 { | |
328 language=subtitle->lang_code; | |
329 tmp[0]=language>>8; | |
330 tmp[1]=language&0xff; | |
331 tmp[2]=0; | |
332 } | |
333 | |
334 d->subtitles[ d->nr_of_subtitles ].language=language; | |
335 d->subtitles[ d->nr_of_subtitles ].id=d->nr_of_subtitles; | |
336 | |
337 mp_msg(MSGT_OPEN,MSGL_V,"[open] subtitle ( sid ): %d language: %s\n", | |
338 d->nr_of_subtitles, | |
339 tmp | |
340 ); | |
341 d->nr_of_subtitles++; | |
342 } | |
343 mp_msg(MSGT_OPEN,MSGL_V,"[open] number of subtitles on disk: %d\n",d->nr_of_subtitles ); | |
2935 | 344 } |
345 | |
346 /** | |
1596 | 347 * Determine which program chain we want to watch. This is based on the |
348 * chapter number. | |
349 */ | |
350 ttn = tt_srpt->title[ dvd_title ].vts_ttn; // local | |
351 pgc_id = vts_file->vts_ptt_srpt->title[ttn-1].ptt[dvd_chapter].pgcn; // local | |
352 pgn = vts_file->vts_ptt_srpt->title[ttn-1].ptt[dvd_chapter].pgn; // local | |
353 d->cur_pgc = vts_file->vts_pgcit->pgci_srp[pgc_id-1].pgc; | |
354 d->cur_cell = d->cur_pgc->program_map[pgn-1] - 1; // start playback here | |
355 d->packs_left=-1; // for Navi stuff | |
1609
84199d075839
ugly seeking bug fixed, correct multiangle seek implemented
arpi
parents:
1596
diff
changeset
|
356 d->angle_seek=0; |
4291
e889d37f25b2
Add option -last-chapter for DVD playing/encoding
kmkaplan
parents:
4251
diff
changeset
|
357 /* XXX dvd_last_chapter is in the range 1..nr_of_ptts */ |
e889d37f25b2
Add option -last-chapter for DVD playing/encoding
kmkaplan
parents:
4251
diff
changeset
|
358 if ( dvd_last_chapter > 0 && dvd_last_chapter < tt_srpt->title[ttn-1].nr_of_ptts ) { |
e889d37f25b2
Add option -last-chapter for DVD playing/encoding
kmkaplan
parents:
4251
diff
changeset
|
359 pgn=vts_file->vts_ptt_srpt->title[ttn-1].ptt[dvd_last_chapter].pgn; |
e889d37f25b2
Add option -last-chapter for DVD playing/encoding
kmkaplan
parents:
4251
diff
changeset
|
360 d->last_cell=d->cur_pgc->program_map[pgn-1] - 1; |
e889d37f25b2
Add option -last-chapter for DVD playing/encoding
kmkaplan
parents:
4251
diff
changeset
|
361 } |
e889d37f25b2
Add option -last-chapter for DVD playing/encoding
kmkaplan
parents:
4251
diff
changeset
|
362 else |
e889d37f25b2
Add option -last-chapter for DVD playing/encoding
kmkaplan
parents:
4251
diff
changeset
|
363 d->last_cell=d->cur_pgc->nr_of_cells; |
1596 | 364 |
365 if( d->cur_pgc->cell_playback[d->cur_cell].block_type | |
366 == BLOCK_TYPE_ANGLE_BLOCK ) d->cur_cell+=dvd_angle; | |
367 d->cur_pack = d->cur_pgc->cell_playback[ d->cur_cell ].first_sector; | |
368 d->cell_last_pack=d->cur_pgc->cell_playback[ d->cur_cell ].last_sector; | |
369 mp_msg(MSGT_DVD,MSGL_V, "DVD start cell: %d pack: 0x%X-0x%X \n",d->cur_cell,d->cur_pack,d->cell_last_pack); | |
370 | |
371 // ... (unimplemented) | |
372 // return NULL; | |
373 stream=new_stream(-1,STREAMTYPE_DVD); | |
374 stream->start_pos=(off_t)d->cur_pack*2048; | |
4390 | 375 stream->end_pos=(off_t)(d->cur_pgc->cell_playback[d->last_cell-1].last_sector)*2048; |
376 printf("DVD start=%d end=%d \n",d->cur_pack,d->cur_pgc->cell_playback[d->last_cell-1].last_sector); | |
1596 | 377 stream->priv=(void*)d; |
378 return stream; | |
379 } | |
380 #endif | |
381 | |
2790 | 382 #ifdef USE_TV |
383 //============ Check for TV-input ==== | |
2931 | 384 if (tv_param_on == 1) |
2790 | 385 { |
2931 | 386 /* create stream */ |
387 stream = new_stream(-1, STREAMTYPE_TV); | |
388 if (!stream) | |
389 return(NULL); | |
390 | |
391 /* create tvi handler */ | |
2790 | 392 tv_handler = tv_begin(); |
393 if (!tv_handler) | |
394 return(NULL); | |
2931 | 395 |
396 /* preinit */ | |
397 if (!tv_init(tv_handler)) | |
398 goto tv_err; | |
399 | |
400 if (!stream_open_tv(stream, tv_handler)) | |
401 goto tv_err; | |
402 | |
403 return(stream); | |
404 | |
405 /* something went wrong - uninit */ | |
406 tv_err: | |
2837 | 407 tv_uninit(tv_handler); |
2802 | 408 return(NULL); |
2790 | 409 } |
410 #endif | |
411 | |
4551 | 412 //============ Check for multi file-input ==== |
413 if (mf_support == 1) | |
414 { | |
415 /* create stream */ | |
416 stream = new_stream(-1, STREAMTYPE_MF); | |
417 if (!stream) | |
418 return(NULL); | |
419 | |
420 if (!stream_open_mf(filename, stream)) | |
421 return(NULL); | |
422 | |
423 return(stream); | |
424 } | |
425 | |
1467 | 426 //============ Open STDIN ============ |
427 if(!strcmp(filename,"-")){ | |
428 // read from stdin | |
1584 | 429 mp_msg(MSGT_OPEN,MSGL_INFO,MSGTR_ReadSTDIN); |
1467 | 430 f=0; // 0=stdin |
431 stream=new_stream(f,STREAMTYPE_STREAM); | |
432 return stream; | |
433 } | |
434 | |
435 #ifdef STREAMING | |
436 url = url_new(filename); | |
437 if(url) { | |
4251
05affdf4bdcd
Moved network related code from open.c to network.c
bertrand
parents:
4222
diff
changeset
|
438 stream=new_stream(f,STREAMTYPE_STREAM); |
4729
f51bd827ed1c
fixed MP3 ICY detection, return detected file format for open_stream
alex
parents:
4551
diff
changeset
|
439 if( streaming_start( stream, file_format, url )<0){ |
4251
05affdf4bdcd
Moved network related code from open.c to network.c
bertrand
parents:
4222
diff
changeset
|
440 mp_msg(MSGT_OPEN,MSGL_ERR,MSGTR_UnableOpenURL, filename); |
05affdf4bdcd
Moved network related code from open.c to network.c
bertrand
parents:
4222
diff
changeset
|
441 url_free(url); |
05affdf4bdcd
Moved network related code from open.c to network.c
bertrand
parents:
4222
diff
changeset
|
442 return NULL; |
4046
f732854e3d16
Kept the HTTP connection open after autodetect, so
bertrand
parents:
3753
diff
changeset
|
443 } |
1584 | 444 mp_msg(MSGT_OPEN,MSGL_INFO,MSGTR_ConnToServer, url->hostname ); |
3045
6c14fd789ba5
Changed the order of processing the network opening.
bertrand
parents:
2935
diff
changeset
|
445 url_free(url); |
2315 | 446 return stream; |
1467 | 447 } |
448 #endif | |
449 | |
450 //============ Open plain FILE ============ | |
451 f=open(filename,O_RDONLY); | |
1584 | 452 if(f<0){ mp_msg(MSGT_OPEN,MSGL_ERR,MSGTR_FileNotFound,filename);return NULL; } |
1467 | 453 len=lseek(f,0,SEEK_END); lseek(f,0,SEEK_SET); |
454 if (len == -1) | |
455 perror("Error: lseek failed to obtain video file size"); | |
456 else | |
457 #ifdef _LARGEFILE_SOURCE | |
1567 | 458 mp_msg(MSGT_OPEN,MSGL_V,"File size is %lld bytes\n", (long long)len); |
1467 | 459 #else |
1567 | 460 mp_msg(MSGT_OPEN,MSGL_V,"File size is %u bytes\n", (unsigned int)len); |
1467 | 461 #endif |
462 stream=new_stream(f,STREAMTYPE_FILE); | |
463 stream->end_pos=len; | |
464 return stream; | |
465 | |
466 } | |
1596 | 467 |
4343
b0c8eed7473c
Extended DVD chapter specification. Remove -last-chapter option.
kmkaplan
parents:
4291
diff
changeset
|
468 int dvd_parse_chapter_range(struct config *conf, const char *range){ |
b0c8eed7473c
Extended DVD chapter specification. Remove -last-chapter option.
kmkaplan
parents:
4291
diff
changeset
|
469 char *s, *t; |
4344 | 470 conf; /* prevent warning from GCC */ |
471 s = range; | |
4343
b0c8eed7473c
Extended DVD chapter specification. Remove -last-chapter option.
kmkaplan
parents:
4291
diff
changeset
|
472 dvd_chapter = 1; |
b0c8eed7473c
Extended DVD chapter specification. Remove -last-chapter option.
kmkaplan
parents:
4291
diff
changeset
|
473 dvd_last_chapter = 0; |
b0c8eed7473c
Extended DVD chapter specification. Remove -last-chapter option.
kmkaplan
parents:
4291
diff
changeset
|
474 if (*range && isdigit(*range)) { |
b0c8eed7473c
Extended DVD chapter specification. Remove -last-chapter option.
kmkaplan
parents:
4291
diff
changeset
|
475 dvd_chapter = strtol(range, &s, 10); |
b0c8eed7473c
Extended DVD chapter specification. Remove -last-chapter option.
kmkaplan
parents:
4291
diff
changeset
|
476 if (range == s) { |
b0c8eed7473c
Extended DVD chapter specification. Remove -last-chapter option.
kmkaplan
parents:
4291
diff
changeset
|
477 mp_msg(MSGT_OPEN, MSGL_ERR, "Invalid chapter range specification %s\n", range); |
b0c8eed7473c
Extended DVD chapter specification. Remove -last-chapter option.
kmkaplan
parents:
4291
diff
changeset
|
478 return -1; |
b0c8eed7473c
Extended DVD chapter specification. Remove -last-chapter option.
kmkaplan
parents:
4291
diff
changeset
|
479 } |
b0c8eed7473c
Extended DVD chapter specification. Remove -last-chapter option.
kmkaplan
parents:
4291
diff
changeset
|
480 } |
b0c8eed7473c
Extended DVD chapter specification. Remove -last-chapter option.
kmkaplan
parents:
4291
diff
changeset
|
481 if (*s == 0) |
b0c8eed7473c
Extended DVD chapter specification. Remove -last-chapter option.
kmkaplan
parents:
4291
diff
changeset
|
482 return 0; |
b0c8eed7473c
Extended DVD chapter specification. Remove -last-chapter option.
kmkaplan
parents:
4291
diff
changeset
|
483 else if (*s != '-') { |
b0c8eed7473c
Extended DVD chapter specification. Remove -last-chapter option.
kmkaplan
parents:
4291
diff
changeset
|
484 mp_msg(MSGT_OPEN, MSGL_ERR, "Invalid chapter range specification %s\n", range); |
b0c8eed7473c
Extended DVD chapter specification. Remove -last-chapter option.
kmkaplan
parents:
4291
diff
changeset
|
485 return -1; |
b0c8eed7473c
Extended DVD chapter specification. Remove -last-chapter option.
kmkaplan
parents:
4291
diff
changeset
|
486 } |
b0c8eed7473c
Extended DVD chapter specification. Remove -last-chapter option.
kmkaplan
parents:
4291
diff
changeset
|
487 ++s; |
b0c8eed7473c
Extended DVD chapter specification. Remove -last-chapter option.
kmkaplan
parents:
4291
diff
changeset
|
488 if (*s == 0) |
b0c8eed7473c
Extended DVD chapter specification. Remove -last-chapter option.
kmkaplan
parents:
4291
diff
changeset
|
489 return 0; |
b0c8eed7473c
Extended DVD chapter specification. Remove -last-chapter option.
kmkaplan
parents:
4291
diff
changeset
|
490 if (! isdigit(*s)) { |
b0c8eed7473c
Extended DVD chapter specification. Remove -last-chapter option.
kmkaplan
parents:
4291
diff
changeset
|
491 mp_msg(MSGT_OPEN, MSGL_ERR, "Invalid chapter range specification %s\n", range); |
b0c8eed7473c
Extended DVD chapter specification. Remove -last-chapter option.
kmkaplan
parents:
4291
diff
changeset
|
492 return -1; |
b0c8eed7473c
Extended DVD chapter specification. Remove -last-chapter option.
kmkaplan
parents:
4291
diff
changeset
|
493 } |
b0c8eed7473c
Extended DVD chapter specification. Remove -last-chapter option.
kmkaplan
parents:
4291
diff
changeset
|
494 dvd_last_chapter = strtol(s, &t, 10); |
b0c8eed7473c
Extended DVD chapter specification. Remove -last-chapter option.
kmkaplan
parents:
4291
diff
changeset
|
495 if (s == t || *t) { |
b0c8eed7473c
Extended DVD chapter specification. Remove -last-chapter option.
kmkaplan
parents:
4291
diff
changeset
|
496 mp_msg(MSGT_OPEN, MSGL_ERR, "Invalid chapter range specification %s\n", range); |
b0c8eed7473c
Extended DVD chapter specification. Remove -last-chapter option.
kmkaplan
parents:
4291
diff
changeset
|
497 return -1; |
b0c8eed7473c
Extended DVD chapter specification. Remove -last-chapter option.
kmkaplan
parents:
4291
diff
changeset
|
498 } |
b0c8eed7473c
Extended DVD chapter specification. Remove -last-chapter option.
kmkaplan
parents:
4291
diff
changeset
|
499 return 0; |
b0c8eed7473c
Extended DVD chapter specification. Remove -last-chapter option.
kmkaplan
parents:
4291
diff
changeset
|
500 } |
b0c8eed7473c
Extended DVD chapter specification. Remove -last-chapter option.
kmkaplan
parents:
4291
diff
changeset
|
501 |
3753 | 502 #ifdef USE_DVDREAD |
1596 | 503 |
3753 | 504 int dvd_aid_from_lang(stream_t *stream, unsigned char* lang){ |
505 dvd_priv_t *d=stream->priv; | |
506 int code,i; | |
507 while(lang && strlen(lang)>=2){ | |
508 code=lang[1]|(lang[0]<<8); | |
509 for(i=0;i<d->nr_of_channels;i++){ | |
510 if(d->audio_streams[i].language==code){ | |
511 mp_msg(MSGT_OPEN,MSGL_INFO,"Selected DVD audio channel: %d language: %c%c\n", | |
512 d->audio_streams[i].id, lang[0],lang[1]); | |
513 return d->audio_streams[i].id; | |
514 } | |
515 // printf("%X != %X (%c%c)\n",code,d->audio_streams[i].language,lang[0],lang[1]); | |
516 } | |
517 lang+=2; while (lang[0]==',' || lang[0]==' ') ++lang; | |
518 } | |
519 mp_msg(MSGT_OPEN,MSGL_INFO,"No matching DVD audio language found!\n"); | |
520 return -1; | |
521 } | |
522 | |
523 int dvd_sid_from_lang(stream_t *stream, unsigned char* lang){ | |
524 dvd_priv_t *d=stream->priv; | |
525 int code,i; | |
526 while(lang && strlen(lang)>=2){ | |
527 code=lang[1]|(lang[0]<<8); | |
528 for(i=0;i<d->nr_of_subtitles;i++){ | |
529 if(d->subtitles[i].language==code){ | |
530 mp_msg(MSGT_OPEN,MSGL_INFO,"Selected DVD subtitle channel: %d language: %c%c\n", | |
531 d->subtitles[i].id, lang[0],lang[1]); | |
532 return d->subtitles[i].id; | |
533 } | |
534 } | |
535 lang+=2; while (lang[0]==',' || lang[0]==' ') ++lang; | |
536 } | |
537 mp_msg(MSGT_OPEN,MSGL_INFO,"No matching DVD subtitle language found!\n"); | |
538 return -1; | |
539 } | |
1596 | 540 |
541 static int dvd_next_cell(dvd_priv_t *d){ | |
542 int next_cell=d->cur_cell; | |
1616 | 543 |
544 mp_msg(MSGT_DVD,MSGL_V, "dvd_next_cell: next1=0x%X \n",next_cell); | |
1596 | 545 |
546 if( d->cur_pgc->cell_playback[ next_cell ].block_type | |
547 == BLOCK_TYPE_ANGLE_BLOCK ) { | |
4291
e889d37f25b2
Add option -last-chapter for DVD playing/encoding
kmkaplan
parents:
4251
diff
changeset
|
548 while(next_cell<d->last_cell){ |
1596 | 549 if( d->cur_pgc->cell_playback[next_cell].block_mode |
550 == BLOCK_MODE_LAST_CELL ) break; | |
551 ++next_cell; | |
552 } | |
553 } | |
1616 | 554 mp_msg(MSGT_DVD,MSGL_V, "dvd_next_cell: next2=0x%X \n",next_cell); |
1596 | 555 |
556 ++next_cell; | |
4291
e889d37f25b2
Add option -last-chapter for DVD playing/encoding
kmkaplan
parents:
4251
diff
changeset
|
557 if(next_cell>=d->last_cell) return -1; // EOF |
1596 | 558 if( d->cur_pgc->cell_playback[next_cell].block_type == BLOCK_TYPE_ANGLE_BLOCK ){ |
559 next_cell+=dvd_angle; | |
4291
e889d37f25b2
Add option -last-chapter for DVD playing/encoding
kmkaplan
parents:
4251
diff
changeset
|
560 if(next_cell>=d->last_cell) return -1; // EOF |
1596 | 561 } |
1616 | 562 mp_msg(MSGT_DVD,MSGL_V, "dvd_next_cell: next3=0x%X \n",next_cell); |
1596 | 563 return next_cell; |
564 } | |
565 | |
566 int dvd_read_sector(dvd_priv_t *d,unsigned char* data){ | |
567 int len; | |
568 | |
569 if(d->packs_left==0){ | |
570 /** | |
571 * If we're not at the end of this cell, we can determine the next | |
572 * VOBU to display using the VOBU_SRI information section of the | |
573 * DSI. Using this value correctly follows the current angle, | |
574 * avoiding the doubled scenes in The Matrix, and makes our life | |
575 * really happy. | |
576 * | |
577 * Otherwise, we set our next address past the end of this cell to | |
578 * force the code above to go to the next cell in the program. | |
579 */ | |
580 if( d->dsi_pack.vobu_sri.next_vobu != SRI_END_OF_CELL ) { | |
581 d->cur_pack= d->dsi_pack.dsi_gi.nv_pck_lbn + | |
582 ( d->dsi_pack.vobu_sri.next_vobu & 0x7fffffff ); | |
583 mp_msg(MSGT_DVD,MSGL_DBG2, "Navi new pos=0x%X \n",d->cur_pack); | |
584 } else { | |
585 // end of cell! find next cell! | |
586 mp_msg(MSGT_DVD,MSGL_V, "--- END OF CELL !!! ---\n"); | |
587 d->cur_pack=d->cell_last_pack+1; | |
588 } | |
589 } | |
590 | |
591 read_next: | |
592 | |
593 if(d->cur_pack>d->cell_last_pack){ | |
594 // end of cell! | |
595 int next=dvd_next_cell(d); | |
596 if(next>=0){ | |
597 d->cur_cell=next; | |
598 | |
1615 | 599 // if( d->cur_pgc->cell_playback[d->cur_cell].block_type |
600 // == BLOCK_TYPE_ANGLE_BLOCK ) d->cur_cell+=dvd_angle; | |
1596 | 601 d->cur_pack = d->cur_pgc->cell_playback[ d->cur_cell ].first_sector; |
602 d->cell_last_pack=d->cur_pgc->cell_playback[ d->cur_cell ].last_sector; | |
603 mp_msg(MSGT_DVD,MSGL_V, "DVD next cell: %d pack: 0x%X-0x%X \n",d->cur_cell,d->cur_pack,d->cell_last_pack); | |
604 | |
605 } else return -1; // EOF | |
606 } | |
607 | |
608 len = DVDReadBlocks( d->title, d->cur_pack, 1, data ); | |
609 if(!len) return -1; //error | |
610 | |
611 if(data[38]==0 && data[39]==0 && data[40]==1 && data[41]==0xBF && | |
612 data[1024]==0 && data[1025]==0 && data[1026]==1 && data[1027]==0xBF){ | |
613 // found a Navi packet!!! | |
1875 | 614 #if LIBDVDREAD_VERSION >= DVDREAD_VERSION(0,9,0) |
615 navRead_DSI( &d->dsi_pack, &(data[ DSI_START_BYTE ]) ); | |
616 #else | |
1596 | 617 navRead_DSI( &d->dsi_pack, &(data[ DSI_START_BYTE ]), sizeof(dsi_t) ); |
1875 | 618 #endif |
1596 | 619 if(d->cur_pack != d->dsi_pack.dsi_gi.nv_pck_lbn ){ |
620 mp_msg(MSGT_DVD,MSGL_V, "Invalid NAVI packet! lba=0x%X navi=0x%X \n", | |
621 d->cur_pack,d->dsi_pack.dsi_gi.nv_pck_lbn); | |
622 } else { | |
623 // process! | |
624 d->packs_left = d->dsi_pack.dsi_gi.vobu_ea; | |
625 mp_msg(MSGT_DVD,MSGL_DBG2, "Found NAVI packet! lba=0x%X len=%d \n",d->cur_pack,d->packs_left); | |
1609
84199d075839
ugly seeking bug fixed, correct multiangle seek implemented
arpi
parents:
1596
diff
changeset
|
626 if(d->angle_seek){ |
84199d075839
ugly seeking bug fixed, correct multiangle seek implemented
arpi
parents:
1596
diff
changeset
|
627 int skip=d->dsi_pack.sml_agli.data[dvd_angle].address; |
84199d075839
ugly seeking bug fixed, correct multiangle seek implemented
arpi
parents:
1596
diff
changeset
|
628 if(skip) d->cur_pack=d->dsi_pack.dsi_gi.nv_pck_lbn+skip; |
84199d075839
ugly seeking bug fixed, correct multiangle seek implemented
arpi
parents:
1596
diff
changeset
|
629 d->angle_seek=0; |
84199d075839
ugly seeking bug fixed, correct multiangle seek implemented
arpi
parents:
1596
diff
changeset
|
630 mp_msg(MSGT_DVD,MSGL_V, "Angle-seek synced! skip=%d new_lba=0x%X \n",skip,d->cur_pack); |
84199d075839
ugly seeking bug fixed, correct multiangle seek implemented
arpi
parents:
1596
diff
changeset
|
631 } |
1596 | 632 } |
633 ++d->cur_pack; | |
634 goto read_next; | |
635 } | |
636 | |
637 ++d->cur_pack; | |
638 if(d->packs_left>=0) --d->packs_left; | |
1609
84199d075839
ugly seeking bug fixed, correct multiangle seek implemented
arpi
parents:
1596
diff
changeset
|
639 |
84199d075839
ugly seeking bug fixed, correct multiangle seek implemented
arpi
parents:
1596
diff
changeset
|
640 if(d->angle_seek) goto read_next; // searching for Navi packet |
1596 | 641 |
642 return d->cur_pack-1; | |
643 } | |
644 | |
645 void dvd_seek(dvd_priv_t *d,int pos){ | |
646 d->packs_left=-1; | |
647 d->cur_pack=pos; | |
648 | |
649 // check if we stay in current cell (speedup things, and avoid angle skip) | |
1609
84199d075839
ugly seeking bug fixed, correct multiangle seek implemented
arpi
parents:
1596
diff
changeset
|
650 if(d->cur_pack>d->cell_last_pack || |
1596 | 651 d->cur_pack<d->cur_pgc->cell_playback[ d->cur_cell ].first_sector){ |
652 | |
653 // ok, cell change, find the right cell! | |
654 d->cur_cell=0; | |
655 if( d->cur_pgc->cell_playback[d->cur_cell].block_type | |
656 == BLOCK_TYPE_ANGLE_BLOCK ) d->cur_cell+=dvd_angle; | |
657 | |
658 while(1){ | |
659 int next; | |
660 d->cell_last_pack=d->cur_pgc->cell_playback[ d->cur_cell ].last_sector; | |
661 if(d->cur_pack<d->cur_pgc->cell_playback[ d->cur_cell ].first_sector){ | |
662 d->cur_pack=d->cur_pgc->cell_playback[ d->cur_cell ].first_sector; | |
663 break; | |
664 } | |
665 if(d->cur_pack<=d->cell_last_pack) break; // ok, we find it! :) | |
666 next=dvd_next_cell(d); | |
667 if(next<0){ | |
668 // d->cur_pack=d->cell_last_pack+1; | |
669 break; // we're after the last cell | |
670 } | |
671 d->cur_cell=next; | |
672 } | |
1609
84199d075839
ugly seeking bug fixed, correct multiangle seek implemented
arpi
parents:
1596
diff
changeset
|
673 |
1596 | 674 } |
675 | |
676 mp_msg(MSGT_DVD,MSGL_V, "DVD Seek! lba=0x%X cell=%d packs: 0x%X-0x%X \n", | |
677 d->cur_pack,d->cur_cell,d->cur_pgc->cell_playback[ d->cur_cell ].first_sector,d->cell_last_pack); | |
678 | |
1609
84199d075839
ugly seeking bug fixed, correct multiangle seek implemented
arpi
parents:
1596
diff
changeset
|
679 // if we're in interleaved multi-angle cell, find the right angle chain! |
1596 | 680 // (read Navi block, and use the seamless angle jump table) |
1609
84199d075839
ugly seeking bug fixed, correct multiangle seek implemented
arpi
parents:
1596
diff
changeset
|
681 d->angle_seek=1; |
1596 | 682 |
683 } | |
684 | |
685 #endif |