1467
|
1
|
|
2 #include <stdio.h>
|
|
3 #include <stdlib.h>
|
|
4 #include <string.h>
|
|
5 #include <unistd.h>
|
|
6 #include <fcntl.h>
|
|
7
|
|
8 #include "config.h"
|
1567
|
9 #include "mp_msg.h"
|
1584
|
10 #include "help_mp.h"
|
1467
|
11
|
1468
|
12 #ifdef __FreeBSD__
|
|
13 #include <sys/cdrio.h>
|
|
14 #endif
|
|
15
|
1467
|
16 #include "stream.h"
|
1482
|
17 #include "demuxer.h"
|
1467
|
18
|
|
19 #ifdef STREAMING
|
|
20 #include "url.h"
|
|
21 #include "network.h"
|
|
22 static URL_t* url;
|
|
23 #endif
|
|
24
|
|
25 extern int vcd_get_track_end(int fd,int track);
|
|
26
|
|
27 // Open a new stream (stdin/file/vcd/url)
|
|
28
|
|
29 stream_t* open_stream(char* filename,int vcd_track,int* file_format){
|
|
30 stream_t* stream=NULL;
|
|
31 int f=-1;
|
|
32 off_t len;
|
|
33 #ifdef VCD_CACHE
|
|
34 int vcd_cache_size=128;
|
|
35 #endif
|
|
36 #ifdef __FreeBSD__
|
|
37 int bsize = VCD_SECTOR_SIZE;
|
|
38 #endif
|
|
39
|
|
40 //============ Open VideoCD track ==============
|
|
41 if(vcd_track){
|
|
42 int ret,ret2;
|
|
43 f=open(filename,O_RDONLY);
|
1584
|
44 if(f<0){ mp_msg(MSGT_OPEN,MSGL_ERR,MSGTR_CdDevNotfound,filename);return NULL; }
|
1467
|
45 vcd_read_toc(f);
|
|
46 ret2=vcd_get_track_end(f,vcd_track);
|
1584
|
47 if(ret2<0){ mp_msg(MSGT_OPEN,MSGL_ERR,MSGTR_ErrTrackSelect " (get)\n");return NULL;}
|
1467
|
48 ret=vcd_seek_to_track(f,vcd_track);
|
1584
|
49 if(ret<0){ mp_msg(MSGT_OPEN,MSGL_ERR,MSGTR_ErrTrackSelect " (seek)\n");return NULL;}
|
1467
|
50 // seek_to_byte+=ret;
|
1567
|
51 mp_msg(MSGT_OPEN,MSGL_V,"VCD start byte position: 0x%X end: 0x%X\n",ret,ret2);
|
1467
|
52 #ifdef VCD_CACHE
|
|
53 vcd_cache_init(vcd_cache_size);
|
|
54 #endif
|
|
55 #ifdef __FreeBSD__
|
|
56 if (ioctl (f, CDRIOCSETBLOCKSIZE, &bsize) == -1) {
|
|
57 perror ( "Error in CDRIOCSETBLOCKSIZE");
|
|
58 }
|
|
59 #endif
|
|
60 stream=new_stream(f,STREAMTYPE_VCD);
|
|
61 stream->start_pos=ret;
|
|
62 stream->end_pos=ret2;
|
|
63 return stream;
|
|
64 }
|
|
65
|
|
66 //============ Open STDIN ============
|
|
67 if(!strcmp(filename,"-")){
|
|
68 // read from stdin
|
1584
|
69 mp_msg(MSGT_OPEN,MSGL_INFO,MSGTR_ReadSTDIN);
|
1467
|
70 f=0; // 0=stdin
|
|
71 stream=new_stream(f,STREAMTYPE_STREAM);
|
|
72 return stream;
|
|
73 }
|
|
74
|
|
75 #ifdef STREAMING
|
|
76 url = url_new(filename);
|
|
77 if(url) {
|
|
78 (*file_format)=autodetectProtocol( url, &f );
|
|
79 if( (*file_format)==DEMUXER_TYPE_UNKNOWN ) {
|
1584
|
80 mp_msg(MSGT_OPEN,MSGL_ERR,MSGTR_UnableOpenURL, filename);
|
1467
|
81 url_free(url);
|
|
82 return NULL;
|
|
83 }
|
|
84 f=streaming_start( &url, f, file_format );
|
1584
|
85 if(f<0){ mp_msg(MSGT_OPEN,MSGL_ERR,MSGTR_UnableOpenURL, url->url); return NULL; }
|
|
86 mp_msg(MSGT_OPEN,MSGL_INFO,MSGTR_ConnToServer, url->hostname );
|
1467
|
87 stream=new_stream(f,STREAMTYPE_STREAM);
|
|
88 return NULL;
|
|
89 }
|
|
90 #endif
|
|
91
|
|
92 //============ Open plain FILE ============
|
|
93 f=open(filename,O_RDONLY);
|
1584
|
94 if(f<0){ mp_msg(MSGT_OPEN,MSGL_ERR,MSGTR_FileNotFound,filename);return NULL; }
|
1467
|
95 len=lseek(f,0,SEEK_END); lseek(f,0,SEEK_SET);
|
|
96 if (len == -1)
|
|
97 perror("Error: lseek failed to obtain video file size");
|
|
98 else
|
|
99 if(verbose)
|
|
100 #ifdef _LARGEFILE_SOURCE
|
1567
|
101 mp_msg(MSGT_OPEN,MSGL_V,"File size is %lld bytes\n", (long long)len);
|
1467
|
102 #else
|
1567
|
103 mp_msg(MSGT_OPEN,MSGL_V,"File size is %u bytes\n", (unsigned int)len);
|
1467
|
104 #endif
|
|
105 stream=new_stream(f,STREAMTYPE_FILE);
|
|
106 stream->end_pos=len;
|
|
107 return stream;
|
|
108
|
|
109 }
|