18 #include <sys/ioctl.h>
22 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) || defined(__NetBSD__) || defined(__OpenBSD__)
23 #include "vcd_read_fbsd.h"
24 #elif defined(__APPLE__)
25 #include "vcd_read_darwin.h"
27 #include "vcd_read_win32.h"
32 #include "libmpdemux/demuxer.h"
34 extern char *cdrom_device
;
36 static struct stream_priv_s
{
39 } stream_priv_dflts
= {
44 #define ST_OFF(f) M_ST_OFF(struct stream_priv_s,f)
46 static const m_option_t stream_opts_fields
[] = {
47 { "track", ST_OFF(track
), CONF_TYPE_INT
, M_OPT_MIN
, 1, 0, NULL
},
48 { "device", ST_OFF(device
), CONF_TYPE_STRING
, 0, 0 ,0, NULL
},
50 { "hostname", ST_OFF(track
), CONF_TYPE_INT
, M_OPT_MIN
, 1, 0, NULL
},
51 { "filename", ST_OFF(device
), CONF_TYPE_STRING
, 0, 0 ,0, NULL
},
52 { NULL
, NULL
, 0, 0, 0, 0, NULL
}
54 static struct m_struct_st stream_opts
= {
56 sizeof(struct stream_priv_s
),
61 static int fill_buffer(stream_t
*s
, char* buffer
, int max_len
){
62 if(s
->pos
> s
->end_pos
) /// don't past end of current track
64 return vcd_read(s
->priv
,buffer
);
67 static int seek(stream_t
*s
,off_t newpos
) {
69 vcd_set_msf(s
->priv
,s
->pos
/VCD_SECTOR_DATA
);
73 static void close_s(stream_t
*stream
) {
77 static int open_s(stream_t
*stream
,int mode
, void* opts
, int* file_format
) {
78 struct stream_priv_s
* p
= (struct stream_priv_s
*)opts
;
79 int ret
,ret2
,f
,sect
,tmp
;
81 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
82 int bsize
= VCD_SECTOR_SIZE
;
86 char device
[] = "\\\\.\\?:";
89 if(mode
!= STREAM_READ
91 || GetVersion() > 0x80000000 // Win9x
94 m_struct_free(&stream_opts
,opts
);
95 return STREAM_UNSUPPORTED
;
100 p
->device
= strdup(cdrom_device
);
102 p
->device
= strdup(DEFAULT_CDROM_DEVICE
);
106 device
[4] = p
->device
[0];
107 /* open() can't be used for devices so do it the complicated way */
108 hd
= CreateFile(device
, GENERIC_READ
, FILE_SHARE_READ
, NULL
,
109 OPEN_EXISTING
, FILE_FLAG_SEQUENTIAL_SCAN
, NULL
);
110 f
= _open_osfhandle((long)hd
, _O_RDONLY
);
112 f
=open(p
->device
,O_RDONLY
);
115 mp_msg(MSGT_OPEN
,MSGL_ERR
,MSGTR_CdDevNotfound
,p
->device
);
116 m_struct_free(&stream_opts
,opts
);
120 vcd
= vcd_read_toc(f
);
122 mp_msg(MSGT_OPEN
,MSGL_ERR
,"Failed to get cd toc\n");
124 m_struct_free(&stream_opts
,opts
);
127 ret2
=vcd_get_track_end(vcd
,p
->track
);
129 mp_msg(MSGT_OPEN
,MSGL_ERR
,MSGTR_ErrTrackSelect
" (get)\n");
132 m_struct_free(&stream_opts
,opts
);
135 ret
=vcd_seek_to_track(vcd
,p
->track
);
137 mp_msg(MSGT_OPEN
,MSGL_ERR
,MSGTR_ErrTrackSelect
" (seek)\n");
140 m_struct_free(&stream_opts
,opts
);
143 /* search forward up to at most 3 seconds to skip leading margin */
144 sect
= ret
/ VCD_SECTOR_DATA
;
145 for (tmp
= sect
; tmp
< sect
+ 3 * 75; tmp
++) {
146 char mem
[VCD_SECTOR_DATA
];
147 //since MPEG packs are block-aligned we stop discarding sectors if they are non-null
148 if (vcd_read(vcd
, mem
) != VCD_SECTOR_DATA
|| mem
[2] || mem
[3])
151 mp_msg(MSGT_OPEN
, MSGL_DBG2
, "%d leading sectors skipped\n", tmp
- sect
);
152 vcd_set_msf(vcd
, tmp
);
153 ret
= tmp
* VCD_SECTOR_DATA
;
155 mp_msg(MSGT_OPEN
,MSGL_V
,"VCD start byte position: 0x%X end: 0x%X\n",ret
,ret2
);
157 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
158 if (ioctl (f
, CDRIOCSETBLOCKSIZE
, &bsize
) == -1) {
159 mp_msg(MSGT_OPEN
,MSGL_WARN
,"Error in CDRIOCSETBLOCKSIZE");
164 stream
->type
= STREAMTYPE_VCD
;
165 stream
->sector_size
= VCD_SECTOR_DATA
;
166 stream
->start_pos
=ret
;
167 stream
->end_pos
=ret2
;
170 stream
->fill_buffer
= fill_buffer
;
172 stream
->close
= close_s
;
173 *file_format
= DEMUXER_TYPE_MPEG_PS
;
175 m_struct_free(&stream_opts
,opts
);
179 const stream_info_t stream_info_vcd
= {
183 "based on the code from ???",
187 1 // Urls are an option string