annotate open.c @ 1505:842c29861e25

upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
author arpi
date Mon, 13 Aug 2001 18:37:10 +0000
parents 4800d1c58dab
children 5c7760aa4f94
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1467
f352e1e951ba stream opening -> open.c, initialframes ignored
arpi
parents:
diff changeset
1
f352e1e951ba stream opening -> open.c, initialframes ignored
arpi
parents:
diff changeset
2 #include <stdio.h>
f352e1e951ba stream opening -> open.c, initialframes ignored
arpi
parents:
diff changeset
3 #include <stdlib.h>
f352e1e951ba stream opening -> open.c, initialframes ignored
arpi
parents:
diff changeset
4 #include <string.h>
f352e1e951ba stream opening -> open.c, initialframes ignored
arpi
parents:
diff changeset
5 #include <unistd.h>
f352e1e951ba stream opening -> open.c, initialframes ignored
arpi
parents:
diff changeset
6 #include <fcntl.h>
f352e1e951ba stream opening -> open.c, initialframes ignored
arpi
parents:
diff changeset
7
f352e1e951ba stream opening -> open.c, initialframes ignored
arpi
parents:
diff changeset
8 #include "config.h"
f352e1e951ba stream opening -> open.c, initialframes ignored
arpi
parents:
diff changeset
9
1468
fbed9c34069c freebsd fix
arpi
parents: 1467
diff changeset
10 #ifdef __FreeBSD__
fbed9c34069c freebsd fix
arpi
parents: 1467
diff changeset
11 #include <sys/cdrio.h>
fbed9c34069c freebsd fix
arpi
parents: 1467
diff changeset
12 #endif
fbed9c34069c freebsd fix
arpi
parents: 1467
diff changeset
13
1467
f352e1e951ba stream opening -> open.c, initialframes ignored
arpi
parents:
diff changeset
14 #include "stream.h"
1482
4800d1c58dab --enable-streaming fix
arpi
parents: 1468
diff changeset
15 #include "demuxer.h"
1467
f352e1e951ba stream opening -> open.c, initialframes ignored
arpi
parents:
diff changeset
16
f352e1e951ba stream opening -> open.c, initialframes ignored
arpi
parents:
diff changeset
17 #ifdef STREAMING
f352e1e951ba stream opening -> open.c, initialframes ignored
arpi
parents:
diff changeset
18 #include "url.h"
f352e1e951ba stream opening -> open.c, initialframes ignored
arpi
parents:
diff changeset
19 #include "network.h"
f352e1e951ba stream opening -> open.c, initialframes ignored
arpi
parents:
diff changeset
20 static URL_t* url;
f352e1e951ba stream opening -> open.c, initialframes ignored
arpi
parents:
diff changeset
21 #endif
f352e1e951ba stream opening -> open.c, initialframes ignored
arpi
parents:
diff changeset
22
f352e1e951ba stream opening -> open.c, initialframes ignored
arpi
parents:
diff changeset
23 extern int verbose;
f352e1e951ba stream opening -> open.c, initialframes ignored
arpi
parents:
diff changeset
24 extern int vcd_get_track_end(int fd,int track);
f352e1e951ba stream opening -> open.c, initialframes ignored
arpi
parents:
diff changeset
25
f352e1e951ba stream opening -> open.c, initialframes ignored
arpi
parents:
diff changeset
26 // Open a new stream (stdin/file/vcd/url)
f352e1e951ba stream opening -> open.c, initialframes ignored
arpi
parents:
diff changeset
27
f352e1e951ba stream opening -> open.c, initialframes ignored
arpi
parents:
diff changeset
28 stream_t* open_stream(char* filename,int vcd_track,int* file_format){
f352e1e951ba stream opening -> open.c, initialframes ignored
arpi
parents:
diff changeset
29 stream_t* stream=NULL;
f352e1e951ba stream opening -> open.c, initialframes ignored
arpi
parents:
diff changeset
30 int f=-1;
f352e1e951ba stream opening -> open.c, initialframes ignored
arpi
parents:
diff changeset
31 off_t len;
f352e1e951ba stream opening -> open.c, initialframes ignored
arpi
parents:
diff changeset
32 #ifdef VCD_CACHE
f352e1e951ba stream opening -> open.c, initialframes ignored
arpi
parents:
diff changeset
33 int vcd_cache_size=128;
f352e1e951ba stream opening -> open.c, initialframes ignored
arpi
parents:
diff changeset
34 #endif
f352e1e951ba stream opening -> open.c, initialframes ignored
arpi
parents:
diff changeset
35 #ifdef __FreeBSD__
f352e1e951ba stream opening -> open.c, initialframes ignored
arpi
parents:
diff changeset
36 int bsize = VCD_SECTOR_SIZE;
f352e1e951ba stream opening -> open.c, initialframes ignored
arpi
parents:
diff changeset
37 #endif
f352e1e951ba stream opening -> open.c, initialframes ignored
arpi
parents:
diff changeset
38
f352e1e951ba stream opening -> open.c, initialframes ignored
arpi
parents:
diff changeset
39 //============ Open VideoCD track ==============
f352e1e951ba stream opening -> open.c, initialframes ignored
arpi
parents:
diff changeset
40 if(vcd_track){
f352e1e951ba stream opening -> open.c, initialframes ignored
arpi
parents:
diff changeset
41 int ret,ret2;
f352e1e951ba stream opening -> open.c, initialframes ignored
arpi
parents:
diff changeset
42 f=open(filename,O_RDONLY);
f352e1e951ba stream opening -> open.c, initialframes ignored
arpi
parents:
diff changeset
43 if(f<0){ fprintf(stderr,"CD-ROM Device '%s' not found!\n",filename);return NULL; }
f352e1e951ba stream opening -> open.c, initialframes ignored
arpi
parents:
diff changeset
44 vcd_read_toc(f);
f352e1e951ba stream opening -> open.c, initialframes ignored
arpi
parents:
diff changeset
45 ret2=vcd_get_track_end(f,vcd_track);
f352e1e951ba stream opening -> open.c, initialframes ignored
arpi
parents:
diff changeset
46 if(ret2<0){ fprintf(stderr,"Error selecting VCD track! (get)\n");return NULL;}
f352e1e951ba stream opening -> open.c, initialframes ignored
arpi
parents:
diff changeset
47 ret=vcd_seek_to_track(f,vcd_track);
f352e1e951ba stream opening -> open.c, initialframes ignored
arpi
parents:
diff changeset
48 if(ret<0){ fprintf(stderr,"Error selecting VCD track! (seek)\n");return NULL;}
f352e1e951ba stream opening -> open.c, initialframes ignored
arpi
parents:
diff changeset
49 // seek_to_byte+=ret;
f352e1e951ba stream opening -> open.c, initialframes ignored
arpi
parents:
diff changeset
50 if(verbose) printf("VCD start byte position: 0x%X end: 0x%X\n",ret,ret2);
f352e1e951ba stream opening -> open.c, initialframes ignored
arpi
parents:
diff changeset
51 #ifdef VCD_CACHE
f352e1e951ba stream opening -> open.c, initialframes ignored
arpi
parents:
diff changeset
52 vcd_cache_init(vcd_cache_size);
f352e1e951ba stream opening -> open.c, initialframes ignored
arpi
parents:
diff changeset
53 #endif
f352e1e951ba stream opening -> open.c, initialframes ignored
arpi
parents:
diff changeset
54 #ifdef __FreeBSD__
f352e1e951ba stream opening -> open.c, initialframes ignored
arpi
parents:
diff changeset
55 if (ioctl (f, CDRIOCSETBLOCKSIZE, &bsize) == -1) {
f352e1e951ba stream opening -> open.c, initialframes ignored
arpi
parents:
diff changeset
56 perror ( "Error in CDRIOCSETBLOCKSIZE");
f352e1e951ba stream opening -> open.c, initialframes ignored
arpi
parents:
diff changeset
57 }
f352e1e951ba stream opening -> open.c, initialframes ignored
arpi
parents:
diff changeset
58 #endif
f352e1e951ba stream opening -> open.c, initialframes ignored
arpi
parents:
diff changeset
59 stream=new_stream(f,STREAMTYPE_VCD);
f352e1e951ba stream opening -> open.c, initialframes ignored
arpi
parents:
diff changeset
60 stream->start_pos=ret;
f352e1e951ba stream opening -> open.c, initialframes ignored
arpi
parents:
diff changeset
61 stream->end_pos=ret2;
f352e1e951ba stream opening -> open.c, initialframes ignored
arpi
parents:
diff changeset
62 return stream;
f352e1e951ba stream opening -> open.c, initialframes ignored
arpi
parents:
diff changeset
63 }
f352e1e951ba stream opening -> open.c, initialframes ignored
arpi
parents:
diff changeset
64
f352e1e951ba stream opening -> open.c, initialframes ignored
arpi
parents:
diff changeset
65 //============ Open STDIN ============
f352e1e951ba stream opening -> open.c, initialframes ignored
arpi
parents:
diff changeset
66 if(!strcmp(filename,"-")){
f352e1e951ba stream opening -> open.c, initialframes ignored
arpi
parents:
diff changeset
67 // read from stdin
f352e1e951ba stream opening -> open.c, initialframes ignored
arpi
parents:
diff changeset
68 printf("Reading from stdin...\n");
f352e1e951ba stream opening -> open.c, initialframes ignored
arpi
parents:
diff changeset
69 f=0; // 0=stdin
f352e1e951ba stream opening -> open.c, initialframes ignored
arpi
parents:
diff changeset
70 stream=new_stream(f,STREAMTYPE_STREAM);
f352e1e951ba stream opening -> open.c, initialframes ignored
arpi
parents:
diff changeset
71 return stream;
f352e1e951ba stream opening -> open.c, initialframes ignored
arpi
parents:
diff changeset
72 }
f352e1e951ba stream opening -> open.c, initialframes ignored
arpi
parents:
diff changeset
73
f352e1e951ba stream opening -> open.c, initialframes ignored
arpi
parents:
diff changeset
74 #ifdef STREAMING
f352e1e951ba stream opening -> open.c, initialframes ignored
arpi
parents:
diff changeset
75 url = url_new(filename);
f352e1e951ba stream opening -> open.c, initialframes ignored
arpi
parents:
diff changeset
76 if(url) {
f352e1e951ba stream opening -> open.c, initialframes ignored
arpi
parents:
diff changeset
77 (*file_format)=autodetectProtocol( url, &f );
f352e1e951ba stream opening -> open.c, initialframes ignored
arpi
parents:
diff changeset
78 if( (*file_format)==DEMUXER_TYPE_UNKNOWN ) {
f352e1e951ba stream opening -> open.c, initialframes ignored
arpi
parents:
diff changeset
79 fprintf(stderr,"Unable to open URL: %s\n", filename);
f352e1e951ba stream opening -> open.c, initialframes ignored
arpi
parents:
diff changeset
80 url_free(url);
f352e1e951ba stream opening -> open.c, initialframes ignored
arpi
parents:
diff changeset
81 return NULL;
f352e1e951ba stream opening -> open.c, initialframes ignored
arpi
parents:
diff changeset
82 }
f352e1e951ba stream opening -> open.c, initialframes ignored
arpi
parents:
diff changeset
83 f=streaming_start( &url, f, file_format );
f352e1e951ba stream opening -> open.c, initialframes ignored
arpi
parents:
diff changeset
84 if(f<0){ fprintf(stderr,"Unable to open URL: %s\n", url->url); return NULL; }
f352e1e951ba stream opening -> open.c, initialframes ignored
arpi
parents:
diff changeset
85 printf("Connected to server: %s\n", url->hostname );
f352e1e951ba stream opening -> open.c, initialframes ignored
arpi
parents:
diff changeset
86 stream=new_stream(f,STREAMTYPE_STREAM);
f352e1e951ba stream opening -> open.c, initialframes ignored
arpi
parents:
diff changeset
87 return NULL;
f352e1e951ba stream opening -> open.c, initialframes ignored
arpi
parents:
diff changeset
88 }
f352e1e951ba stream opening -> open.c, initialframes ignored
arpi
parents:
diff changeset
89 #endif
f352e1e951ba stream opening -> open.c, initialframes ignored
arpi
parents:
diff changeset
90
f352e1e951ba stream opening -> open.c, initialframes ignored
arpi
parents:
diff changeset
91 //============ Open plain FILE ============
f352e1e951ba stream opening -> open.c, initialframes ignored
arpi
parents:
diff changeset
92 f=open(filename,O_RDONLY);
f352e1e951ba stream opening -> open.c, initialframes ignored
arpi
parents:
diff changeset
93 if(f<0){ fprintf(stderr,"File not found: '%s'\n",filename);return NULL; }
f352e1e951ba stream opening -> open.c, initialframes ignored
arpi
parents:
diff changeset
94 len=lseek(f,0,SEEK_END); lseek(f,0,SEEK_SET);
f352e1e951ba stream opening -> open.c, initialframes ignored
arpi
parents:
diff changeset
95 if (len == -1)
f352e1e951ba stream opening -> open.c, initialframes ignored
arpi
parents:
diff changeset
96 perror("Error: lseek failed to obtain video file size");
f352e1e951ba stream opening -> open.c, initialframes ignored
arpi
parents:
diff changeset
97 else
f352e1e951ba stream opening -> open.c, initialframes ignored
arpi
parents:
diff changeset
98 if(verbose)
f352e1e951ba stream opening -> open.c, initialframes ignored
arpi
parents:
diff changeset
99 #ifdef _LARGEFILE_SOURCE
f352e1e951ba stream opening -> open.c, initialframes ignored
arpi
parents:
diff changeset
100 printf("File size is %lld bytes\n", (long long)len);
f352e1e951ba stream opening -> open.c, initialframes ignored
arpi
parents:
diff changeset
101 #else
f352e1e951ba stream opening -> open.c, initialframes ignored
arpi
parents:
diff changeset
102 printf("File size is %u bytes\n", (unsigned int)len);
f352e1e951ba stream opening -> open.c, initialframes ignored
arpi
parents:
diff changeset
103 #endif
f352e1e951ba stream opening -> open.c, initialframes ignored
arpi
parents:
diff changeset
104 stream=new_stream(f,STREAMTYPE_FILE);
f352e1e951ba stream opening -> open.c, initialframes ignored
arpi
parents:
diff changeset
105 stream->end_pos=len;
f352e1e951ba stream opening -> open.c, initialframes ignored
arpi
parents:
diff changeset
106 return stream;
f352e1e951ba stream opening -> open.c, initialframes ignored
arpi
parents:
diff changeset
107
f352e1e951ba stream opening -> open.c, initialframes ignored
arpi
parents:
diff changeset
108 }