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