2 * implementation of VCD IO for OS/2
4 * Copyright (c) 2009 KO Myung-Hun (komh@chollian.net)
6 * This file is part of MPlayer.
8 * MPlayer is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * MPlayer is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 #ifndef MPLAYER_VCD_READ_OS2_H
24 #define MPLAYER_VCD_READ_OS2_H
28 struct __attribute__((packed
)) msf
{
37 struct msf msfCurrent
;
40 struct msf msfLeadOut
;
41 BYTE abVCDSector
[VCD_SECTOR_SIZE
];
44 static inline void vcd_set_msf(mp_vcd_priv_t
*vcd
, unsigned sect
)
47 vcd
->msfCurrent
.bFrame
= sect
% 75;
49 vcd
->msfCurrent
.bSecond
= sect
% 60;
51 vcd
->msfCurrent
.bMinute
= sect
;
54 static inline unsigned vcd_get_msf(mp_vcd_priv_t
*vcd
)
56 return vcd
->msfCurrent
.bFrame
+
57 (vcd
->msfCurrent
.bSecond
+ vcd
->msfCurrent
.bMinute
* 60) * 75 - 150;
60 int vcd_seek_to_track(mp_vcd_priv_t
*vcd
, int track
)
65 } __attribute__((packed
)) sParam
= {{'C', 'D', '0', '1'},};
70 } __attribute__((packed
)) sData
;
76 sParam
.bTrack
= track
;
77 rc
= DosDevIOCtl(vcd
->hcd
, IOCTL_CDROMAUDIO
, CDROMAUDIO_GETAUDIOTRACK
,
78 &sParam
, sizeof(sParam
), &ulParamLen
,
79 &sData
, sizeof(sData
), &ulDataLen
);
81 mp_msg(MSGT_STREAM
, MSGL_ERR
, "DosDevIOCtl(GETAUDIOTRACK) = 0x%lx\n", rc
);
85 vcd
->msfCurrent
= sData
.msfStart
;
87 return VCD_SECTOR_DATA
* vcd_get_msf(vcd
);
90 static int vcd_get_track_end(mp_vcd_priv_t
*vcd
, int track
)
92 if (track
< vcd
->iLastTrack
)
93 return vcd_seek_to_track(vcd
, track
+ 1);
95 vcd
->msfCurrent
= vcd
->msfLeadOut
;
97 return VCD_SECTOR_DATA
* vcd_get_msf(vcd
);
100 static mp_vcd_priv_t
*vcd_read_toc(int fd
)
104 UCHAR auchParamDisk
[4] = {'C', 'D', '0', '1'};
109 struct msf msfLeadOut
;
110 } __attribute__((packed
)) sDataDisk
;
115 } __attribute__((packed
)) sParamTrack
= {{'C', 'D', '0', '1'},};
120 } __attribute__((packed
)) sDataTrack
;
125 int i
, iMinute
= 0, iSecond
= 0, iFrame
= 0;
127 rc
= DosDevIOCtl(fd
, IOCTL_CDROMAUDIO
, CDROMAUDIO_GETAUDIODISK
,
128 auchParamDisk
, sizeof(auchParamDisk
), &ulParamLen
,
129 &sDataDisk
, sizeof(sDataDisk
), &ulDataLen
);
131 mp_msg(MSGT_OPEN
, MSGL_ERR
, "DosDevIOCtl(GETAUDIODISK) = 0x%lx\n", rc
);
135 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_VCD_START_TRACK=%d\n", sDataDisk
.bFirstTrack
);
136 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_VCD_END_TRACK=%d\n", sDataDisk
.bLastTrack
);
138 for (i
= sDataDisk
.bFirstTrack
; i
<= sDataDisk
.bLastTrack
+ 1; i
++) {
139 if (i
<= sDataDisk
.bLastTrack
) {
140 sParamTrack
.bTrack
= i
;
141 rc
= DosDevIOCtl(fd
, IOCTL_CDROMAUDIO
, CDROMAUDIO_GETAUDIOTRACK
,
142 &sParamTrack
, sizeof(sParamTrack
), &ulParamLen
,
143 &sDataTrack
, sizeof(sDataTrack
), &ulDataLen
);
145 mp_msg(MSGT_OPEN
, MSGL_ERR
, "DosDevIOCtl(GETAUDIOTRACK) = 0x%lx\n", rc
);
149 mp_msg(MSGT_OPEN
, MSGL_INFO
, "track %02d: adr=%d ctrl=%d %02d:%02d:%02d\n",
151 sDataTrack
.bControlInfo
& 0x0F,
152 sDataTrack
.bControlInfo
>> 4,
153 sDataTrack
.msfStart
.bMinute
,
154 sDataTrack
.msfStart
.bSecond
,
155 sDataTrack
.msfStart
.bFrame
);
157 sDataTrack
.msfStart
= sDataDisk
.msfLeadOut
;
159 if (mp_msg_test(MSGT_IDENTIFY
, MSGL_INFO
)) {
160 if (i
> sDataDisk
.bFirstTrack
) {
161 iMinute
= sDataTrack
.msfStart
.bMinute
- iMinute
;
162 iSecond
= sDataTrack
.msfStart
.bSecond
- iSecond
;
163 iFrame
= sDataTrack
.msfStart
.bFrame
- iFrame
;
172 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_VCD_TRACK_%d_MSF=%02d:%02d:%02d\n",
173 i
- 1, iMinute
, iSecond
, iFrame
);
176 iMinute
= sDataTrack
.msfStart
.bMinute
;
177 iSecond
= sDataTrack
.msfStart
.bSecond
;
178 iFrame
= sDataTrack
.msfStart
.bFrame
;
182 vcd
= calloc(1, sizeof(mp_vcd_priv_t
));
184 vcd
->iFirstTrack
= sDataDisk
.bFirstTrack
;
185 vcd
->iLastTrack
= sDataDisk
.bLastTrack
;
186 vcd
->msfLeadOut
= sDataDisk
.msfLeadOut
;
191 static int vcd_read(mp_vcd_priv_t
*vcd
, char *mem
)
199 BYTE bInterleavedSize
;
200 } __attribute__((packed
)) sParam
= {{'C', 'D', '0', '1'}, 1, 1,};
207 if (vcd
->msfCurrent
.bMinute
== vcd
->msfLeadOut
.bMinute
&&
208 vcd
->msfCurrent
.bSecond
== vcd
->msfLeadOut
.bSecond
&&
209 vcd
->msfCurrent
.bFrame
== vcd
->msfLeadOut
.bFrame
)
212 sParam
.msfStart
= vcd
->msfCurrent
;
213 rc
= DosDevIOCtl(vcd
->hcd
, IOCTL_CDROMDISK
, CDROMDISK_READLONG
,
214 &sParam
, sizeof(sParam
), &ulParamLen
,
215 vcd
->abVCDSector
, sizeof(vcd
->abVCDSector
), &ulDataLen
);
217 mp_msg(MSGT_STREAM
, MSGL_ERR
, "DosDevIOCtl(READLONG) = 0x%lx\n", rc
);
221 memcpy(mem
, &vcd
->abVCDSector
[VCD_SECTOR_OFFS
], VCD_SECTOR_DATA
);
223 vcd
->msfCurrent
.bFrame
++;
224 if (vcd
->msfCurrent
.bFrame
== 75) {
225 vcd
->msfCurrent
.bFrame
= 0;
226 vcd
->msfCurrent
.bSecond
++;
227 if (vcd
->msfCurrent
.bSecond
== 60) {
228 vcd
->msfCurrent
.bSecond
= 0;
229 vcd
->msfCurrent
.bMinute
++;
233 return VCD_SECTOR_DATA
;
236 #endif /* MPLAYER_VCD_READ_OS2_H */