xref: /illumos-gate/usr/src/cmd/audio/include/AudioFile.h (revision e5803b76927480e8f9b67b22201c484ccf4c2bcf)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright (c) 1992-2001 by Sun Microsystems, Inc.
24  * All rights reserved.
25  */
26 
27 #ifndef _MULTIMEDIA_AUDIOFILE_H
28 #define	_MULTIMEDIA_AUDIOFILE_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #ifdef NO_EXTERN_C
33 
34 #ifdef __cplusplus
35 extern "C" {
36 #endif
37 
38 #endif /* NO_EXTERN_C */
39 
40 #include <AudioUnixfile.h>
41 #include <sys/types.h>
42 #include <sys/mman.h>
43 
44 // A 'primitive type' for memory mapped file access types
45 enum vmaccess_t {
46     NormalAccess = 0, RandomAccess = 1, SequentialAccess = 2
47 };
48 
49 class VMAccess {
50 private:
51 	vmaccess_t	type;		// combined mode
52 public:
53 	VMAccess(vmaccess_t x = NormalAccess): type(x) { }	// Constructor
54 	inline operator vmaccess_t()			// Cast to enum
55 	    { return (type); }
56 	inline operator int() {				// Cast to integer
57 	    switch (type) {
58 	    case NormalAccess: return (MADV_NORMAL);
59 	    case RandomAccess: return (MADV_RANDOM);
60 	    case SequentialAccess: return (MADV_SEQUENTIAL);
61 	    }
62 	}
63 };
64 
65 
66 // This is the 'base' class for regular files containing audio data
67 class AudioFile : public AudioUnixfile {
68 private:
69 	static const FileAccess	defmode;	// Default access mode
70 	static const char	*AUDIO_PATH;	// Default path env name
71 
72 	off_t			hdrsize;	// length of file header
73 	off_t			seekpos;	// current system file pointer
74 	Double			origlen;	// initial length of file
75 
76 	caddr_t			mapaddr;	// for mmaping RO files
77 	off_t			maplen;		// length of mmaped region
78 	VMAccess		vmaccess;	// vm (mmap) access type
79 
80 	AudioFile operator=(AudioFile);			// Assignment is illegal
81 
82 protected:
83 	// Open named file
84 	virtual AudioError tryopen(
85 	    const char *, int);
86 	// Create named file
87 	virtual AudioError createfile(
88 	    const char *path);			// filename
89 
90 	// class AudioUnixfile methods specialized here
91 	// Seek in input stream
92 	virtual AudioError seekread(
93 	    Double pos,				// position to seek to
94 	    off_t& offset);			// returned byte offset
95 	// Seek in output stream
96 	virtual AudioError seekwrite(
97 	    Double pos,				// position to seek to
98 	    off_t& offset);			// returned byte offset
99 
100 public:
101 	AudioFile();				// Constructor w/no args
102 
103 	// Constructor with path
104 	AudioFile(
105 	    const char *path,			// filename
106 	    const FileAccess acc = defmode);	// access mode
107 	virtual ~AudioFile();			// Destructor
108 
109 	// Set tmpfile location
110 	static AudioError SetTempPath(
111 	    const char *path);			// directory path
112 
113 	// class AudioUnixfile methods specialized here
114 	virtual void SetBlocking(Boolean) { }	// No-op for files
115 
116 	// front end to madvise
117 	AudioError SetAccessType(
118 	    VMAccess vmacc);			// (normal, random, seq access)
119 
120 	inline VMAccess GetAccessType()	const {	// get vm access type
121 		return (vmaccess);
122 	}
123 
124 	virtual AudioError Create();		// Create file
125 	virtual AudioError Open();		// Open file
126 
127 	// ... with search path
128 	virtual AudioError OpenPath(
129 	    const char *path = AUDIO_PATH);
130 	virtual AudioError Close();		// Close file
131 
132 	// Read from position
133 	virtual AudioError ReadData(
134 	    void* buf,				// buffer to fill
135 	    size_t& len,			// buffer length (updated)
136 	    Double& pos);			// start position (updated)
137 
138 	// Write at position
139 	virtual AudioError WriteData(
140 	    void* buf,				// buffer to copy
141 	    size_t& len,			// buffer length (updated)
142 	    Double& pos);			// start position (updated)
143 
144 	// copy to another audio obj.
145 	virtual AudioError AsyncCopy(
146 	    Audio* ap,				// dest audio object
147 	    Double& frompos,
148 	    Double& topos,
149 	    Double& limit);
150 
151 	// class Audio methods specialized here
152 	virtual Boolean isFile() const { return (TRUE); }
153 };
154 
155 #ifdef NO_EXTERN_C
156 
157 #ifdef __cplusplus
158 }
159 #endif
160 
161 #endif /* NO_EXTERN_C */
162 
163 #endif /* !_MULTIMEDIA_AUDIOFILE_H */
164