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
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.
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]
23 * Copyright 1991-2003 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
33 #include <AudioRawPipe.h>
35 #include <audio_hdr.h>
37 // class AudioPipe methods
39 // Constructor with file descriptor, mode, and optional name
42 const int desc
, // file descriptor
43 const FileAccess acc
, // access mode
44 const AudioHdr
& hdr_local
, // header
45 const char *name_local
, // name
46 const off_t off
// offset
47 ):AudioPipe(desc
, acc
, name_local
), offset(off
)
54 // The create routine for pipes writes a file header
55 AudioError
AudioRawPipe::
60 // Was the header properly set?
61 err
= GetHeader().Validate();
62 if (err
!= AUDIO_SUCCESS
)
63 return (RaiseError(err
));
65 // Open fd supplied by constructor
66 if (!isfdset() || opened()) {
67 return (RaiseError(AUDIO_ERR_NOEFFECT
, Warning
));
70 // set flag for opened() test
73 // Set the actual output length to zero
76 return (AUDIO_SUCCESS
);
79 // The open routine for raw pipes validates the header and
80 // init's the read pos to offset and sets the opened flag.
81 AudioError
AudioRawPipe::
87 // The constructor should have supplied a valid fd
88 // If fd is not open, or file header already decoded, skip it
89 if (!isfdset() || opened())
90 return (RaiseError(AUDIO_ERR_NOEFFECT
, Warning
));
92 // Stat the file, to see if it is a regular file
93 if (fstat(getfd(), &st
) < 0)
94 return (RaiseError(AUDIO_UNIXERROR
));
96 // check validity of file header
97 err
= GetHeader().Validate();
98 if (err
!= AUDIO_SUCCESS
) {
99 (void) close(getfd());
104 // Only trust the file size for regular files
105 if (S_ISREG(st
.st_mode
)) {
106 // for raw files - no hdr, so it's the whole file minus
108 setlength(GetHeader().Bytes_to_Time(st
.st_size
- offset
));
111 setlength(AUDIO_UNKNOWN_TIME
);
114 // set flag for opened() test
117 err
= SetOffset(offset
);
119 // reset logical position to 0.0, since this is, in effect,
120 // the beginning of the file.
121 SetReadPosition(0.0, Absolute
);
126 Boolean
AudioRawPipe::
132 AudioError
AudioRawPipe::
138 // only read only files for now
139 if (GetAccess().Writeable()) {
140 return (AUDIO_ERR_NOEFFECT
);
143 // only allow this if we haven't read anything yet (i.e. current
145 if (ReadPosition() != 0.) {
146 return (AUDIO_ERR_NOEFFECT
);
149 if ((err
= seekread(GetHeader().Bytes_to_Time(val
), setting
))
154 // this should *never* happen 'cause seekread just sets setting
155 // to GetHeader().Time_to_Bytes....
156 if (setting
!= val
) {
157 // don't really know what error is apropos for this.
158 return (AUDIO_ERR_BADFRAME
);
162 return (AUDIO_SUCCESS
);