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
|
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright (c) 1992-2001 by Sun Microsystems, Inc.
* All rights reserved.
*/
#ifndef _MULTIMEDIA_AUDIOFILE_H
#define _MULTIMEDIA_AUDIOFILE_H
#ifdef NO_EXTERN_C
#ifdef __cplusplus
extern "C" {
#endif
#endif /* NO_EXTERN_C */
#include <AudioUnixfile.h>
#include <sys/types.h>
#include <sys/mman.h>
// A 'primitive type' for memory mapped file access types
enum vmaccess_t {
NormalAccess = 0, RandomAccess = 1, SequentialAccess = 2
};
class VMAccess {
private:
vmaccess_t type; // combined mode
public:
VMAccess(vmaccess_t x = NormalAccess): type(x) { } // Constructor
inline operator vmaccess_t() // Cast to enum
{ return (type); }
inline operator int() { // Cast to integer
switch (type) {
case RandomAccess: return (MADV_RANDOM);
case SequentialAccess: return (MADV_SEQUENTIAL);
case NormalAccess:
default:
return (MADV_NORMAL);
}
}
};
// This is the 'base' class for regular files containing audio data
class AudioFile : public AudioUnixfile {
private:
static const FileAccess defmode; // Default access mode
static const char *AUDIO_PATH; // Default path env name
off_t hdrsize; // length of file header
off_t seekpos; // current system file pointer
Double origlen; // initial length of file
caddr_t mapaddr; // for mmaping RO files
off_t maplen; // length of mmaped region
VMAccess vmaccess; // vm (mmap) access type
AudioFile operator=(AudioFile); // Assignment is illegal
protected:
// Open named file
virtual AudioError tryopen(
const char *, int);
// Create named file
virtual AudioError createfile(
const char *path); // filename
// class AudioUnixfile methods specialized here
// Seek in input stream
virtual AudioError seekread(
Double pos, // position to seek to
off_t& offset); // returned byte offset
// Seek in output stream
virtual AudioError seekwrite(
Double pos, // position to seek to
off_t& offset); // returned byte offset
public:
AudioFile(); // Constructor w/no args
// Constructor with path
AudioFile(
const char *path, // filename
const FileAccess acc = defmode); // access mode
virtual ~AudioFile(); // Destructor
// Set tmpfile location
static AudioError SetTempPath(
const char *path); // directory path
// class AudioUnixfile methods specialized here
virtual void SetBlocking(Boolean) { } // No-op for files
// front end to madvise
AudioError SetAccessType(
VMAccess vmacc); // (normal, random, seq access)
inline VMAccess GetAccessType() const { // get vm access type
return (vmaccess);
}
virtual AudioError Create(); // Create file
virtual AudioError Open(); // Open file
// ... with search path
virtual AudioError OpenPath(
const char *path = AUDIO_PATH);
virtual AudioError Close(); // Close file
// Read from position
virtual AudioError ReadData(
void* buf, // buffer to fill
size_t& len, // buffer length (updated)
Double& pos); // start position (updated)
// Write at position
virtual AudioError WriteData(
void* buf, // buffer to copy
size_t& len, // buffer length (updated)
Double& pos); // start position (updated)
// copy to another audio obj.
virtual AudioError AsyncCopy(
Audio* ap, // dest audio object
Double& frompos,
Double& topos,
Double& limit);
// class Audio methods specialized here
virtual Boolean isFile() const { return (TRUE); }
};
#ifdef NO_EXTERN_C
#ifdef __cplusplus
}
#endif
#endif /* NO_EXTERN_C */
#endif /* !_MULTIMEDIA_AUDIOFILE_H */
|