Mercurial > mplayer.hg
annotate stream/stream_vcd.c @ 20267:b0c44d5b9d6c
sync up to r20265 + some li'l fix
author | ptt |
---|---|
date | Mon, 16 Oct 2006 16:11:04 +0000 |
parents | 64d82a45a05d |
children | 3ff1eade91f9 |
rev | line source |
---|---|
9886 | 1 |
2 #include "config.h" | |
3 | |
4 #include "mp_msg.h" | |
5 #include "stream.h" | |
6 #include "help_mp.h" | |
17012 | 7 #include "m_option.h" |
8 #include "m_struct.h" | |
9886 | 9 |
10121
d42177a0da2a
Changed the STREAMING defines to MPLAYER_NETWORK to avoid name definition clash.
bertrand
parents:
9886
diff
changeset
|
10 #include <fcntl.h> |
9886 | 11 #include <stdlib.h> |
12 #include <unistd.h> | |
13 #include <sys/ioctl.h> | |
14 #include <errno.h> | |
15 | |
15566 | 16 #if defined(__FreeBSD__) || defined(__DragonFly__) |
9886 | 17 #include <sys/cdrio.h> |
18 #include "vcd_read_fbsd.h" | |
12797
b2419eef04da
OpenBSD portability patches from the OpenBSD ports tree
diego
parents:
10591
diff
changeset
|
19 #elif defined(__NetBSD__) || defined (__OpenBSD__) |
13678 | 20 #include "vcd_read_nbsd.h" |
13681
e52daf7f3bcc
enable vcd for all darwin based sys not only mac osx
nplourde
parents:
13678
diff
changeset
|
21 #elif defined(SYS_DARWIN) |
e52daf7f3bcc
enable vcd for all darwin based sys not only mac osx
nplourde
parents:
13678
diff
changeset
|
22 #include "vcd_read_darwin.h" |
9886 | 23 #else |
24 #include "vcd_read.h" | |
25 #endif | |
26 | |
10591 | 27 extern char *cdrom_device; |
28 | |
9886 | 29 static struct stream_priv_s { |
30 int track; | |
31 char* device; | |
32 } stream_priv_dflts = { | |
33 1, | |
10591 | 34 NULL |
9886 | 35 }; |
36 | |
37 #define ST_OFF(f) M_ST_OFF(struct stream_priv_s,f) | |
38 /// URL definition | |
39 static m_option_t stream_opts_fields[] = { | |
40 { "track", ST_OFF(track), CONF_TYPE_INT, M_OPT_MIN, 1, 0, NULL }, | |
41 { "device", ST_OFF(device), CONF_TYPE_STRING, 0, 0 ,0, NULL}, | |
42 /// For url parsing | |
43 { "hostname", ST_OFF(track), CONF_TYPE_INT, M_OPT_MIN, 1, 0, NULL }, | |
44 { "filename", ST_OFF(device), CONF_TYPE_STRING, 0, 0 ,0, NULL}, | |
45 { NULL, NULL, 0, 0, 0, 0, NULL } | |
46 }; | |
47 static struct m_struct_st stream_opts = { | |
48 "vcd", | |
49 sizeof(struct stream_priv_s), | |
50 &stream_priv_dflts, | |
51 stream_opts_fields | |
52 }; | |
53 | |
54 static int fill_buffer(stream_t *s, char* buffer, int max_len){ | |
15912 | 55 if(s->pos > s->end_pos) /// don't past end of current track |
56 return 0; | |
9886 | 57 return vcd_read(s->priv,buffer); |
58 } | |
59 | |
60 static int seek(stream_t *s,off_t newpos) { | |
61 s->pos = newpos; | |
62 vcd_set_msf(s->priv,s->pos/VCD_SECTOR_DATA); | |
63 return 1; | |
64 } | |
65 | |
66 static void close_s(stream_t *stream) { | |
67 free(stream->priv); | |
68 } | |
69 | |
70 static int open_s(stream_t *stream,int mode, void* opts, int* file_format) { | |
71 struct stream_priv_s* p = (struct stream_priv_s*)opts; | |
72 int ret,ret2,f; | |
73 mp_vcd_priv_t* vcd; | |
74 #ifdef __FreeBSD__ | |
75 int bsize = VCD_SECTOR_SIZE; | |
76 #endif | |
77 | |
78 if(mode != STREAM_READ) { | |
79 m_struct_free(&stream_opts,opts); | |
80 return STREAM_UNSUPORTED; | |
81 } | |
82 | |
10591 | 83 if (!p->device) { |
84 if(cdrom_device) | |
85 p->device = strdup(cdrom_device); | |
86 else | |
87 p->device = strdup(DEFAULT_CDROM_DEVICE); | |
88 } | |
89 | |
9886 | 90 f=open(p->device,O_RDONLY); |
91 if(f<0){ | |
92 mp_msg(MSGT_OPEN,MSGL_ERR,MSGTR_CdDevNotfound,p->device); | |
93 m_struct_free(&stream_opts,opts); | |
94 return STREAM_ERROR; | |
95 } | |
96 | |
97 vcd = vcd_read_toc(f); | |
98 if(!vcd) { | |
99 mp_msg(MSGT_OPEN,MSGL_ERR,"Failed to get cd toc\n"); | |
100 close(f); | |
101 m_struct_free(&stream_opts,opts); | |
102 return STREAM_ERROR; | |
103 } | |
104 ret2=vcd_get_track_end(vcd,p->track); | |
105 if(ret2<0){ | |
106 mp_msg(MSGT_OPEN,MSGL_ERR,MSGTR_ErrTrackSelect " (get)\n"); | |
107 close(f); | |
108 free(vcd); | |
109 m_struct_free(&stream_opts,opts); | |
110 return STREAM_ERROR; | |
111 } | |
112 ret=vcd_seek_to_track(vcd,p->track); | |
113 if(ret<0){ | |
114 mp_msg(MSGT_OPEN,MSGL_ERR,MSGTR_ErrTrackSelect " (seek)\n"); | |
115 close(f); | |
116 free(vcd); | |
117 m_struct_free(&stream_opts,opts); | |
118 return STREAM_ERROR; | |
119 } | |
120 mp_msg(MSGT_OPEN,MSGL_V,"VCD start byte position: 0x%X end: 0x%X\n",ret,ret2); | |
121 | |
122 #ifdef __FreeBSD__ | |
123 if (ioctl (f, CDRIOCSETBLOCKSIZE, &bsize) == -1) { | |
124 mp_msg(MSGT_OPEN,MSGL_WARN,"Error in CDRIOCSETBLOCKSIZE"); | |
125 } | |
126 #endif | |
127 | |
128 stream->fd = f; | |
129 stream->type = STREAMTYPE_VCD; | |
130 stream->sector_size = VCD_SECTOR_DATA; | |
131 stream->start_pos=ret; | |
132 stream->end_pos=ret2; | |
133 stream->priv = vcd; | |
134 | |
135 stream->fill_buffer = fill_buffer; | |
136 stream->seek = seek; | |
137 stream->close = close_s; | |
138 | |
139 m_struct_free(&stream_opts,opts); | |
140 return STREAM_OK; | |
141 } | |
142 | |
143 stream_info_t stream_info_vcd = { | |
144 "Video CD", | |
145 "vcd", | |
146 "Albeu", | |
147 "based on the code from ???", | |
148 open_s, | |
149 { "vcd", NULL }, | |
150 &stream_opts, | |
151 1 // Urls are an option string | |
152 }; |