xref: /titanic_51/usr/src/cmd/audio/include/Audio.h (revision 37714ae43602c675f9dc59b070bfdf9fa702872c)
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 1992-2002 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef _MULTIMEDIA_AUDIO_H
28 #define	_MULTIMEDIA_AUDIO_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #include <AudioTypes.h>
33 #include <AudioError.h>
34 #include <AudioHdr.h>
35 
36 #ifdef __cplusplus
37 extern "C" {
38 #endif
39 
40 // Error-handling function declaration
41 class Audio;
42 typedef Boolean	(*AudioErrfunc)(const Audio*, AudioError, AudioSeverity,
43 		    char *);
44 
45 
46 // Data transfer subcodes.
47 // Returned from ReadData(), WriteData(), AsyncCopy(), Copy() in err.sys
48 enum AudioCopyFlag {
49     AUDIO_COPY_SHORT_INPUT = 100,	// AUDIO_SUCCESS: input would block
50     AUDIO_COPY_ZERO_LIMIT = 101,	// AUDIO_SUCCESS: length was zero
51     AUDIO_COPY_SHORT_OUTPUT = 102,	// AUDIO_SUCCESS: only partial output
52     AUDIO_COPY_INPUT_EOF = 103,		// AUDIO_EOF: eof on input
53     AUDIO_COPY_OUTPUT_EOF = 104		// AUDIO_EOF: eof on output
54 };
55 
56 
57 
58 // This is the abstract base class from which all audio data types derive.
59 // It is invalid to create an object of type Audio.
60 
61 class Audio {
62 private:
63 	static int	idctr;			// id seed value
64 
65 	int		id;			// object id number
66 	int		refcnt;			// reference count
67 	char		*name;			// name
68 	Double		readpos;		// current read position ptr
69 	Double		writepos;		// current write position ptr
70 	AudioErrfunc	errorfunc;		// address of error function
71 
72 protected:
73 	void SetName(const char *str);		// Set name string
74 
75 	// Set position
76 	Double setpos(
77 	    Double& pos,			// position field to update
78 	    Double newpos,			// new position
79 	    Whence w = Absolute);		// Absolute || Relative
80 
81 // XXX - should these be protected?
82 public:
83 	int getid() const;			// Get id value
84 
85 	// Raise error code
86 	virtual AudioError RaiseError(
87 	    AudioError code,			// error code
88 	    AudioSeverity sev = Error,		// error severity
89 	    char *msg = '\0') const;		// error message
90 
91 	// Raise error msg
92 	virtual void PrintMsg(
93 	    char *msg,				// error code
94 	    AudioSeverity sev = Message) const;	// error severity
95 
96 public:
97 	Audio(const char *str = "");		// Constructor
98 	virtual ~Audio();			// Destructor
99 
100 	void Reference();			// Increment ref count
101 	void Dereference();			// Decrement ref count
102 	Boolean isReferenced() const;		// TRUE if referenced
103 
104 	virtual char *GetName() const;		// Get name string
105 
106 	// Set user error func
107 	virtual void SetErrorFunction(
108 	    AudioErrfunc func);			// return TRUE if non-fatal
109 
110 	virtual Double ReadPosition() const;	// Get read position
111 	virtual Double WritePosition() const;	// Get write position
112 
113 	// Set read position
114 	virtual Double SetReadPosition(
115 	    Double pos,				// new position
116 	    Whence w = Absolute);		// Absolute || Relative
117 
118 	// Set write position
119 	virtual Double SetWritePosition(
120 	    Double pos,				// new position
121 	    Whence w = Absolute);		// Absolute || Relative
122 
123 	// Read from current pos
124 	virtual AudioError Read(
125 	    void* buf,				// buffer to fill
126 	    size_t& len);			// buffer length (updated)
127 
128 	// Write to current pos
129 	virtual AudioError Write(
130 	    void* buf,				// buffer to copy
131 	    size_t& len);			// buffer length (updated)
132 
133 	// XXX - no Append() method for now because of name clashes
134 
135 	// methods specialized by inherited classes
136 	virtual AudioHdr GetHeader() = 0;	// Get header
137 	virtual AudioHdr GetDHeader(Double);	// Get header at pos
138 	virtual Double GetLength() const = 0;	// Get length, in secs
139 
140 	// Read from position
141 	virtual AudioError ReadData(
142 	    void* buf,				// buffer to fill
143 	    size_t& len,			// buffer length (updated)
144 	    Double& pos) = 0;			// start position (updated)
145 
146 	// Write at position
147 	virtual AudioError WriteData(
148 	    void* buf,				// buffer to copy
149 	    size_t& len,			// buffer length (updated)
150 	    Double& pos) = 0;			// start position (updated)
151 
152 	// Write and extend
153 	virtual AudioError AppendData(
154 	    void* buf,				// buffer to copy
155 	    size_t& len,			// buffer length (updated)
156 	    Double& pos);			// start position (updated)
157 
158 	// copy to another audio obj.
159 	virtual AudioError Copy(
160 	    Audio* ap);				// dest audio object
161 
162 	// copy to another audio obj.
163 	virtual AudioError Copy(
164 	    Audio* ap,				// dest audio object
165 	    Double& frompos,
166 	    Double& topos,
167 	    Double& limit);
168 
169 	// copy to another audio obj.
170 	virtual AudioError AsyncCopy(
171 	    Audio* ap,				// dest audio object
172 	    Double& frompos,
173 	    Double& topos,
174 	    Double& limit);
175 
176 	// Define default classification routines
177 	// The appropriate routine should be specialized by each leaf class.
178 	virtual Boolean isFile() const { return (FALSE); }
179 	virtual Boolean isDevice() const { return (FALSE); }
180 	virtual Boolean isDevicectl() const { return (FALSE); }
181 	virtual Boolean isPipe() const { return (FALSE); }
182 	virtual Boolean isBuffer() const { return (FALSE); }
183 	virtual Boolean isExtent() const { return (FALSE); }
184 	virtual Boolean isList() const { return (FALSE); }
185 };
186 
187 #include <Audio_inline.h>
188 
189 #ifdef __cplusplus
190 }
191 #endif
192 
193 #endif /* !_MULTIMEDIA_AUDIO_H */
194