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