2010-01-30 22:26:47 +00:00
|
|
|
/*
|
|
|
|
* This file is part of MPlayer.
|
|
|
|
*
|
|
|
|
* MPlayer is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* MPlayer is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with MPlayer; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
|
2008-02-22 09:09:46 +00:00
|
|
|
#ifndef MPLAYER_VCD_READ_WIN32_H
|
|
|
|
#define MPLAYER_VCD_READ_WIN32_H
|
2008-02-21 00:18:25 +00:00
|
|
|
|
2010-01-04 18:58:35 +00:00
|
|
|
#include <stddef.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2013-04-02 08:39:12 +00:00
|
|
|
#include <ntddcdrm.h>
|
2013-12-17 01:39:45 +00:00
|
|
|
#include "common/msg.h"
|
2007-03-12 15:57:01 +00:00
|
|
|
|
|
|
|
typedef struct mp_vcd_priv_st mp_vcd_priv_t;
|
|
|
|
|
|
|
|
/*
|
|
|
|
Unlike Unices, upon reading TOC, Windows will retrieve information for
|
|
|
|
all tracks, so we don't need to call DeviceIoControl() in functions
|
|
|
|
like vcd_seek_to_track() and vcd_get_track_end() for each track. Instead
|
|
|
|
we cache the information in mp_vcd_priv_st.
|
|
|
|
*/
|
|
|
|
struct mp_vcd_priv_st {
|
|
|
|
HANDLE hd;
|
|
|
|
CDROM_TOC toc;
|
|
|
|
unsigned sect;
|
|
|
|
char buf[VCD_SECTOR_SIZE];
|
|
|
|
};
|
|
|
|
|
|
|
|
static inline void vcd_set_msf(mp_vcd_priv_t* vcd, unsigned sect)
|
|
|
|
{
|
|
|
|
vcd->sect = sect;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline unsigned vcd_get_msf(mp_vcd_priv_t* vcd, int track){
|
2007-11-28 11:48:45 +00:00
|
|
|
int index = track - vcd->toc.FirstTrack;
|
2007-03-12 15:57:01 +00:00
|
|
|
/* -150 to compensate the 2-second pregap */
|
|
|
|
return vcd->toc.TrackData[index].Address[3] +
|
|
|
|
(vcd->toc.TrackData[index].Address[2] +
|
|
|
|
vcd->toc.TrackData[index].Address[1] * 60) * 75 - 150;
|
|
|
|
}
|
|
|
|
|
2011-05-07 21:32:50 +00:00
|
|
|
static int vcd_seek_to_track(mp_vcd_priv_t* vcd, int track)
|
2007-03-12 15:57:01 +00:00
|
|
|
{
|
|
|
|
unsigned sect;
|
|
|
|
if (track < vcd->toc.FirstTrack || track > vcd->toc.LastTrack)
|
|
|
|
return -1;
|
|
|
|
sect = vcd_get_msf(vcd, track);
|
|
|
|
vcd_set_msf(vcd, sect);
|
|
|
|
return VCD_SECTOR_DATA * (sect + 2);
|
|
|
|
}
|
|
|
|
|
2010-02-22 16:32:03 +00:00
|
|
|
static int vcd_get_track_end(mp_vcd_priv_t* vcd, int track)
|
2007-03-12 15:57:01 +00:00
|
|
|
{
|
|
|
|
if (track < vcd->toc.FirstTrack || track > vcd->toc.LastTrack)
|
|
|
|
return -1;
|
|
|
|
return VCD_SECTOR_DATA * (vcd_get_msf(vcd, track + 1));
|
|
|
|
}
|
|
|
|
|
2013-12-21 19:36:45 +00:00
|
|
|
static mp_vcd_priv_t* vcd_read_toc(stream_t *stream, int fd)
|
2007-03-12 15:57:01 +00:00
|
|
|
{
|
|
|
|
DWORD dwBytesReturned;
|
|
|
|
HANDLE hd;
|
2013-12-21 19:36:45 +00:00
|
|
|
int i;
|
2007-03-12 15:57:01 +00:00
|
|
|
mp_vcd_priv_t* vcd = malloc(sizeof(mp_vcd_priv_t));
|
|
|
|
if (!vcd)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
hd = (HANDLE)_get_osfhandle(fd);
|
|
|
|
if (!DeviceIoControl(hd, IOCTL_CDROM_READ_TOC, NULL, 0, &vcd->toc,
|
|
|
|
sizeof(CDROM_TOC), &dwBytesReturned, NULL)) {
|
2013-12-21 19:36:45 +00:00
|
|
|
MP_ERR(stream, "read CDROM toc header: %lu\n",
|
2007-03-12 15:57:01 +00:00
|
|
|
GetLastError());
|
|
|
|
free(vcd);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = vcd->toc.FirstTrack; i <= vcd->toc.LastTrack + 1; i++) {
|
|
|
|
int index = i - vcd->toc.FirstTrack;
|
|
|
|
if (i <= vcd->toc.LastTrack) {
|
2013-12-21 19:36:45 +00:00
|
|
|
MP_INFO(stream, "track %02d: adr=%d ctrl=%d"
|
2007-03-12 15:57:01 +00:00
|
|
|
" %02d:%02d:%02d\n",
|
|
|
|
vcd->toc.TrackData[index].TrackNumber,
|
|
|
|
vcd->toc.TrackData[index].Adr,
|
|
|
|
vcd->toc.TrackData[index].Control,
|
|
|
|
vcd->toc.TrackData[index].Address[1],
|
|
|
|
vcd->toc.TrackData[index].Address[2],
|
|
|
|
vcd->toc.TrackData[index].Address[3]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
vcd->hd = hd;
|
|
|
|
return vcd;
|
|
|
|
}
|
|
|
|
|
2013-07-21 19:54:58 +00:00
|
|
|
#define vcd_close(priv) (CloseHandle(((mp_vcd_priv_t*)priv)->hd))
|
|
|
|
|
2007-03-12 15:57:01 +00:00
|
|
|
static int vcd_read(mp_vcd_priv_t* vcd, char *mem)
|
|
|
|
{
|
|
|
|
DWORD dwBytesReturned;
|
|
|
|
RAW_READ_INFO cdrom_raw;
|
|
|
|
|
|
|
|
/* 2048 isn't a typo: it's the Windows way. */
|
|
|
|
cdrom_raw.DiskOffset.QuadPart = (long long)(2048 * vcd->sect);
|
|
|
|
cdrom_raw.SectorCount = 1;
|
|
|
|
cdrom_raw.TrackMode = XAForm2;
|
|
|
|
|
|
|
|
if (!DeviceIoControl(vcd->hd, IOCTL_CDROM_RAW_READ, &cdrom_raw,
|
|
|
|
sizeof(RAW_READ_INFO), vcd->buf, sizeof(vcd->buf),
|
|
|
|
&dwBytesReturned, NULL))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
vcd->sect++;
|
|
|
|
memcpy(mem, &vcd->buf[VCD_SECTOR_OFFS], VCD_SECTOR_DATA);
|
|
|
|
return VCD_SECTOR_DATA;
|
|
|
|
}
|
|
|
|
|
2008-02-22 09:09:46 +00:00
|
|
|
#endif /* MPLAYER_VCD_READ_WIN32_H */
|