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