]> git.sesse.net Git - vlc/blob - modules/access/vcd/cdrom_internals.h
Do not call EnsureUTF8 on NULL string (cdtext).
[vlc] / modules / access / vcd / cdrom_internals.h
1 /****************************************************************************
2  * cdrom_internals.h: cdrom tools private header
3  *****************************************************************************
4  * Copyright (C) 1998-2001 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Johan Bilien <jobi@via.ecp.fr>
8  *          Gildas Bazin <gbazin@netcourrier.com>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23  *****************************************************************************/
24
25 /*****************************************************************************
26  * The vcddev structure
27  *****************************************************************************/
28 struct vcddev_s
29 {
30     char   *psz_dev;                                      /* vcd device name */
31
32     /* Section used in vcd image mode */
33     int    i_vcdimage_handle;                   /* vcd image file descriptor */
34     int    i_tracks;                          /* number of tracks of the vcd */
35     int    *p_sectors;                           /* tracks layout on the vcd */
36
37     /* Section used in vcd device mode */
38
39 #ifdef WIN32
40     HANDLE h_device_handle;                         /* vcd device descriptor */
41     long  hASPI;
42     short i_sid;
43     long  (*lpSendCommand)( void* );
44
45 #else
46     int    i_device_handle;                         /* vcd device descriptor */
47 #endif
48
49 };
50
51
52 /*****************************************************************************
53  * Misc. Macros
54  *****************************************************************************/
55 /* LBA = msf.frame + 75 * ( msf.second + 60 * msf.minute ) */
56 #define MSF_TO_LBA(min, sec, frame) ((int)frame + 75 * (sec + 60 * min))
57 /* LBA = msf.frame + 75 * ( msf.second - 2 + 60 * msf.minute ) */
58 #define MSF_TO_LBA2(min, sec, frame) ((int)frame + 75 * (sec -2 + 60 * min))
59
60 #ifndef O_BINARY
61 #   define O_BINARY 0
62 #endif
63
64 #define VCDDEV_T 1
65
66 /*****************************************************************************
67  * Platform specifics
68  *****************************************************************************/
69 #if defined( __APPLE__ )
70 #define darwin_freeTOC( p ) free( (void*)p )
71 #define CD_MIN_TRACK_NO 01
72 #define CD_MAX_TRACK_NO 99
73 #endif
74
75 #if defined( WIN32 )
76
77 /* Win32 DeviceIoControl specifics */
78 #ifndef MAXIMUM_NUMBER_TRACKS
79 #    define MAXIMUM_NUMBER_TRACKS 100
80 #endif
81 typedef struct _TRACK_DATA {
82     UCHAR Reserved;
83     UCHAR Control : 4;
84     UCHAR Adr : 4;
85     UCHAR TrackNumber;
86     UCHAR Reserved1;
87     UCHAR Address[4];
88 } TRACK_DATA, *PTRACK_DATA;
89 typedef struct _CDROM_TOC {
90     UCHAR Length[2];
91     UCHAR FirstTrack;
92     UCHAR LastTrack;
93     TRACK_DATA TrackData[MAXIMUM_NUMBER_TRACKS];
94 } CDROM_TOC, *PCDROM_TOC;
95 typedef enum _TRACK_MODE_TYPE {
96     YellowMode2,
97     XAForm2,
98     CDDA
99 } TRACK_MODE_TYPE, *PTRACK_MODE_TYPE;
100 typedef struct __RAW_READ_INFO {
101     LARGE_INTEGER DiskOffset;
102     ULONG SectorCount;
103     TRACK_MODE_TYPE TrackMode;
104 } RAW_READ_INFO, *PRAW_READ_INFO;
105 typedef struct _CDROM_READ_TOC_EX {
106   UCHAR  Format : 4;
107   UCHAR  Reserved1 : 3;
108   UCHAR  Msf : 1;
109   UCHAR  SessionTrack;
110   UCHAR  Reserved2;
111   UCHAR  Reserved3;
112 } CDROM_READ_TOC_EX, *PCDROM_READ_TOC_EX;
113
114 #ifndef IOCTL_CDROM_BASE
115 #    define IOCTL_CDROM_BASE FILE_DEVICE_CD_ROM
116 #endif
117 #ifndef IOCTL_CDROM_READ_TOC
118 #    define IOCTL_CDROM_READ_TOC CTL_CODE(IOCTL_CDROM_BASE, 0x0000, \
119                                           METHOD_BUFFERED, FILE_READ_ACCESS)
120 #endif
121 #ifndef IOCTL_CDROM_RAW_READ
122 #define IOCTL_CDROM_RAW_READ CTL_CODE(IOCTL_CDROM_BASE, 0x000F, \
123                                       METHOD_OUT_DIRECT, FILE_READ_ACCESS)
124 #endif
125 #define IOCTL_CDROM_READ_TOC_EX CTL_CODE(IOCTL_CDROM_BASE, 0x0015, \
126                                          METHOD_BUFFERED, FILE_READ_ACCESS)
127
128
129 #define MINIMUM_CDROM_READ_TOC_EX_SIZE    2
130 #define CDROM_READ_TOC_EX_FORMAT_CDTEXT   0x05
131
132 /* Win32 aspi specific */
133 #define WIN_NT               ( GetVersion() < 0x80000000 )
134 #define ASPI_HAID           0
135 #define ASPI_TARGET         0
136 #define DTYPE_CDROM         0x05
137
138 #define SENSE_LEN           0x0E
139 #define SC_GET_DEV_TYPE     0x01
140 #define SC_EXEC_SCSI_CMD    0x02
141 #define SC_GET_DISK_INFO    0x06
142 #define SS_COMP             0x01
143 #define SS_PENDING          0x00
144 #define SS_NO_ADAPTERS      0xE8
145 #define SRB_DIR_IN          0x08
146 #define SRB_DIR_OUT         0x10
147 #define SRB_EVENT_NOTIFY    0x40
148
149 #define READ_CD 0xbe
150
151 #define READ_TOC 0x43
152 #define READ_TOC_FORMAT_TOC 0x0
153
154 #pragma pack(1)
155
156 struct SRB_GetDiskInfo
157 {
158     unsigned char   SRB_Cmd;
159     unsigned char   SRB_Status;
160     unsigned char   SRB_HaId;
161     unsigned char   SRB_Flags;
162     unsigned long   SRB_Hdr_Rsvd;
163     unsigned char   SRB_Target;
164     unsigned char   SRB_Lun;
165     unsigned char   SRB_DriveFlags;
166     unsigned char   SRB_Int13HDriveInfo;
167     unsigned char   SRB_Heads;
168     unsigned char   SRB_Sectors;
169     unsigned char   SRB_Rsvd1[22];
170 };
171
172 struct SRB_GDEVBlock
173 {
174     unsigned char SRB_Cmd;
175     unsigned char SRB_Status;
176     unsigned char SRB_HaId;
177     unsigned char SRB_Flags;
178     unsigned long SRB_Hdr_Rsvd;
179     unsigned char SRB_Target;
180     unsigned char SRB_Lun;
181     unsigned char SRB_DeviceType;
182     unsigned char SRB_Rsvd1;
183 };
184
185 struct SRB_ExecSCSICmd
186 {
187     unsigned char   SRB_Cmd;
188     unsigned char   SRB_Status;
189     unsigned char   SRB_HaId;
190     unsigned char   SRB_Flags;
191     unsigned long   SRB_Hdr_Rsvd;
192     unsigned char   SRB_Target;
193     unsigned char   SRB_Lun;
194     unsigned short  SRB_Rsvd1;
195     unsigned long   SRB_BufLen;
196     unsigned char   *SRB_BufPointer;
197     unsigned char   SRB_SenseLen;
198     unsigned char   SRB_CDBLen;
199     unsigned char   SRB_HaStat;
200     unsigned char   SRB_TargStat;
201     unsigned long   *SRB_PostProc;
202     unsigned char   SRB_Rsvd2[20];
203     unsigned char   CDBByte[16];
204     unsigned char   SenseArea[SENSE_LEN+2];
205 };
206
207 #pragma pack()
208 #endif /* WIN32 */
209
210 #define SECTOR_TYPE_MODE2_FORM2 0x14
211 #define SECTOR_TYPE_CDDA 0x04
212 #define READ_CD_RAW_MODE2 0xF0
213 #define READ_CD_USERDATA 0x10
214
215 /*****************************************************************************
216  * Local Prototypes
217  *****************************************************************************/
218 static int    OpenVCDImage( vlc_object_t *, const char *, struct vcddev_s * );
219 static void   CloseVCDImage( vlc_object_t *, struct vcddev_s * );
220
221 #if defined( __APPLE__ )
222 static CDTOC *darwin_getTOC( vlc_object_t *, const struct vcddev_s * );
223 static int    darwin_getNumberOfTracks( CDTOC *, int );
224
225 #elif defined( WIN32 )
226 static int    win32_vcd_open( vlc_object_t *, const char *, struct vcddev_s *);
227 #endif