xref: /titanic_52/usr/src/cmd/audio/include/AudioUnixfile.h (revision 25cf1a301a396c38e8adf52c15f537b80d2483f7)
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_AUDIOUNIXFILE_H
28 #define	_MULTIMEDIA_AUDIOUNIXFILE_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #include <AudioStream.h>
33 
34 #ifdef __cplusplus
35 extern "C" {
36 #endif
37 
38 // This is the abstract base class for all file descriptor based audio i/o.
39 // It is invalid to create an object of type AudioUnixfile.
40 
41 class AudioUnixfile : public AudioStream {
42 private:
43 	FileAccess	mode;			// access mode
44 	Boolean		block;			// FALSE if fd set non-blocking
45 	Boolean		filehdrset;		// TRUE if file hdr read/written
46 	int		fd;			// file descriptor
47 	char		*infostring;		// Info string from header
48 	unsigned int	infolength;		// Info string length
49 
50 	AudioUnixfile() {}			// Constructor w/no args
51 
52 protected:
53 	// Constructor
54 	AudioUnixfile(
55 	    const char *path,		// pathname
56 	    const FileAccess acc);	// access mode
57 
58 	int getfd() const;			// Return descriptor
59 	void setfd(int d);			// Set descriptor
60 
61 	virtual AudioError decode_filehdr();	// Get header from file
62 	virtual AudioError encode_filehdr();	// Write file header
63 
64 	// Seek in input stream
65 	virtual AudioError seekread(
66 	    Double pos,				// position to seek to
67 	    off_t& offset);			// returned byte offset
68 
69 	// Seek in output stream
70 	virtual AudioError seekwrite(
71 	    Double pos,				// position to seek to
72 	    off_t& offset);			// returned byte offset
73 
74 	virtual Boolean isfdset() const;		// TRUE if fd is valid
75 	virtual Boolean isfilehdrset() const;		// TRUE if file hdr r/w
76 
77 	// class AudioStream methods specialized here
78 	virtual Boolean opened() const;			// TRUE, if open
79 
80 public:
81 	virtual ~AudioUnixfile();			// Destructor
82 
83 	virtual FileAccess GetAccess() const;		// Get mode
84 	virtual Boolean GetBlocking() const;		// TRUE, if blocking i/o
85 	virtual void SetBlocking(Boolean b);		// Set block/non-block
86 
87 	virtual AudioError Create() = 0;		// Create file
88 	virtual AudioError Open() = 0;			// Open file
89 
90 	// ... with search path
91 	virtual AudioError OpenPath(
92 	    const char *path = 0);
93 	virtual AudioError Close();			// Close file
94 
95 	// Methods specific to the audio file format
96 	// Get info string
97 	virtual char *const GetInfostring(
98 	    int& len) const;			// return length
99 
100 	// Set info string
101 	virtual void SetInfostring(
102 	    const char	*str,			// ptr to info data
103 	    int		len = -1);		// optional length
104 
105 	// class Audio methods specialized here
106 	// Read from position
107 	virtual AudioError ReadData(
108 	    void* buf,				// buffer to fill
109 	    size_t& len,			// buffer length (updated)
110 	    Double& pos);			// start position (updated)
111 
112 	// Write at position
113 	virtual AudioError WriteData(
114 	    void* buf,				// buffer to copy
115 	    size_t& len,			// buffer length (updated)
116 	    Double& pos);			// start position (updated)
117 };
118 
119 #include <AudioUnixfile_inline.h>
120 
121 #ifdef __cplusplus
122 }
123 #endif
124 
125 #endif /* !_MULTIMEDIA_AUDIOUNIXFILE_H */
126