1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
|
/* -*- c -*-
$Id: read.swg,v 1.7 2008/04/28 17:34:17 karl Exp $
Copyright (C) 2006, 2008 Rocky Bernstein <[email protected]>
This program 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 3 of the License, or
(at your option) any later version.
This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*/
/* See <cdio/read.h> for more extensive documentation. */
%constant long int READ_MODE_AUDIO = CDIO_READ_MODE_AUDIO;
%constant long int READ_MODE_M1F1 = CDIO_READ_MODE_M1F1;
%constant long int READ_MODE_M1F2 = CDIO_READ_MODE_M1F2;
%constant long int READ_MODE_M2F1 = CDIO_READ_MODE_M2F1;
%constant long int READ_MODE_M2F2 = CDIO_READ_MODE_M2F2;
typedef int cdio_read_mode_t;
%inline %{
typedef long int my_ssize_t;
%}
%apply my_ssize_t *OUTPUT { my_ssize_t *pi_size };
%rename cdio_lseek lseek;
off_t cdio_lseek(const CdIo_t *p_cdio, off_t offset, int whence=SEEK_SET);
%newobject read_cd; // free malloc'd return value
char *read_cd(const CdIo_t *p_cdio, my_ssize_t i_size,
/*out*/ my_ssize_t *pi_size);
%inline %{
char *
read_cd(const CdIo_t *p_cdio, my_ssize_t i_size,
/*out*/ my_ssize_t *pi_size) {
char *p_buf = calloc(1, i_size);
*pi_size = cdio_read(p_cdio, p_buf, i_size);
return p_buf;
}
%}
typedef char * buf_t;
%typemap(out) buf_t {
/* $1 is of type buf_t */
ST(argvi) = sv_newmortal();
if (result) {
/* I don't yet know how to pick up arg4 another way.
THIS MEANS ARG4 MUST ALWAYS BE THE SIZE. */
sv_setpvn((SV*)ST(argvi++), (char *) result, arg4);
/* Don't leak memory. return value was malloc'd by libcdio. */
free(result);
} else {
sv_setsv((SV*)ST(argvi++), &PL_sv_undef);
}
}
%apply long int *OUTPUT { long int *drc };
/* NOTE: arg 4 *must* be the size of the buf for the buf_t typemap. */
buf_t read_sectors(const CdIo_t *p_cdio, lsn_t i_lsn,
cdio_read_mode_t read_mode, my_ssize_t i_size,
/*out*/ my_ssize_t *pi_size,
/*out*/ long int *drc);
%inline %{
typedef char *buf_t;
/* NOTE: arg 4 *must* be the size of the buf for the buf_t typemap. */
buf_t
read_sectors(const CdIo_t *p_cdio, lsn_t i_lsn,
cdio_read_mode_t read_mode, my_ssize_t i_size,
/*out*/ my_ssize_t *pi_size,
/*out*/ long int *drc)
{
char *p_buf;
uint32_t i_blocks;
uint16_t i_blocksize;
switch (read_mode) {
case CDIO_READ_MODE_AUDIO:
i_blocksize = CDIO_CD_FRAMESIZE_RAW;
break;
case CDIO_READ_MODE_M1F1:
i_blocksize = M2RAW_SECTOR_SIZE;
break;
case CDIO_READ_MODE_M1F2:
i_blocksize = M2RAW_SECTOR_SIZE;
break;
case CDIO_READ_MODE_M2F1:
i_blocksize = CDIO_CD_FRAMESIZE;
break;
case CDIO_READ_MODE_M2F2:
i_blocksize = M2F2_SECTOR_SIZE;
break;
default:
pi_size = NULL;
*drc = DRIVER_OP_BAD_PARAMETER;
return NULL;
}
p_buf = calloc(1, i_size);
i_blocks = i_size / i_blocksize;
*drc = cdio_read_sectors(p_cdio, p_buf, i_lsn, read_mode, i_blocks);
if (*drc < 0) {
pi_size = NULL;
return NULL;
}
*pi_size = i_size;
return p_buf;
}
%}
/* NOTE: arg 4 *must* be the size of the buf for the buf_t typemap. */
buf_t
read_data_bytes(const CdIo_t *p_cdio, lsn_t i_lsn, int16_t i_blocksize,
my_ssize_t i_size,
/*out*/ my_ssize_t *pi_size,
long int *drc);
%inline %{
/* NOTE: arg 4 *must* be the size of the buf for the buf_t typemap. */
buf_t
read_data_bytes(const CdIo_t *p_cdio, lsn_t i_lsn,
int16_t i_blocksize, my_ssize_t i_size,
/*out*/ my_ssize_t *pi_size,
/*out*/ long int *drc) {
uint32_t i_blocks = i_size / i_blocksize;
char *p_buf;
switch (i_blocksize) {
case CDIO_CD_FRAMESIZE:
case CDIO_CD_FRAMESIZE_RAW:
case M2F2_SECTOR_SIZE:
case M2RAW_SECTOR_SIZE:
break;
default:
/* Don't know about these block sizes */
pi_size = NULL;
*drc = DRIVER_OP_BAD_PARAMETER;
return NULL;
}
p_buf = calloc(1, i_size);
#if DEBUGGING
printf("p_cdio: %x, i_size: %d, lsn: %d, blocksize %d, blocks %d\n",
p_cdio, i_size, i_lsn, i_blocksize, i_blocks);
#endif
*drc = cdio_read_data_sectors (p_cdio, p_buf, i_lsn,
i_blocksize, i_blocks);
#if DEBUGGING
printf("drc: %d\n", drc);
#endif
if (*drc < 0) {
pi_size = NULL;
return NULL;
}
*pi_size = i_size;
return p_buf;
}
%}
|