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 (c) 1993-2001 by Sun Microsystems, Inc.
24 * All rights reserved.
27 #pragma ident "%Z%%M% %I% %E% SMI"
29 #include <AudioExtent.h>
32 // class AudioExtent methods
35 // class AudioExtent Constructor
38 Audio
* obj
, // audio object to point to
39 double s
, // start time
40 double e
): // end time
41 Audio("[extent]"), ref(obj
)
43 ref
->Reference(); // reference audio object
44 SetStart(s
); // set start/end times
48 // class AudioExtent Destructor
52 ref
->Dereference(); // clear audio object reference
55 // Get referenced object
62 // Set referenced object
65 Audio
* r
) // new audio object
67 if (ref
== r
) // object is not changing
69 ref
->Dereference(); // dereference previous object
72 ref
->Reference(); // reference new object
74 PrintMsg(_MGET_("AudioExtent:...NULL Audio object reference"),
89 Double s
) // start time, in seconds
91 if (Undefined(s
) || (s
< 0.))
101 // If determinate endpoint, return it
104 // Otherwise, return the endpoint of the underlying object
105 return (ref
->GetLength());
111 Double e
) // end time, in seconds
115 // If known endpoint and object has known size, do not exceed size
117 len
= ref
->GetLength();
118 if (!Undefined(len
) && (e
> len
))
124 // Get the length of an audio extent
130 // If extent end is indeterminate, use the end of the target object
132 // If the object length is indeterminate, then the length is
138 // Construct a name for the list
142 // XXX - construct a better name
143 return (ref
->GetName());
146 // Get the audio header for the current read position
147 AudioHdr
AudioExtent::
150 return (ref
->GetDHeader(ReadPosition() + start
));
153 // Get the audio header for the given position
154 AudioHdr
AudioExtent::
156 Double pos
) // position
158 return (ref
->GetDHeader(pos
+ start
));
161 // Copy data from extent into specified buffer.
162 // No data format translation takes place.
163 // The object's read position is not updated.
165 // Since the extent could refer to a list of extents of differing encodings,
166 // clients should always use GetHeader() in combination with ReadData()
167 AudioError
AudioExtent::
169 void* buf
, // destination buffer address
170 size_t& len
, // buffer size (updated)
171 Double
& pos
) // start position (updated)
179 // Save buffer size and zero transfer count
183 // Position must be valid
184 if (Undefined(pos
) || (pos
< 0.) || ((int)cnt
< 0))
185 return (RaiseError(AUDIO_ERR_BADARG
));
187 // If the end is determinate, check start position and length
190 if (!Undefined(newpos
)) {
191 // If starting beyond eof, give up now
194 err
.sys
= AUDIO_COPY_INPUT_EOF
;
198 // If the read would extend beyond end-of-extent, shorten it
199 buflen
= GetHeader(pos
).Time_to_Bytes((Double
)(newpos
- off
));
202 err
.sys
= AUDIO_COPY_INPUT_EOF
;
206 cnt
= (size_t)buflen
;
208 // Zero-length reads are easy
211 err
.sys
= AUDIO_COPY_ZERO_LIMIT
;
215 // Save the offset, read data, and update the returned position
218 err
= ref
->ReadData(buf
, len
, newpos
);
219 pos
= (newpos
- start
); // XXX - calculate bytes and convert?
223 // Write to AudioExtent is (currently) prohibited
224 AudioError
AudioExtent::
226 void*, // destination buffer address
227 size_t& len
, // buffer size (updated)
228 Double
&) // start position (updated)
231 return (RaiseError(AUDIO_ERR_NOEFFECT
));