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