annotate open.c @ 1590:e49685127514

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