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