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