1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate  * Copyright (c) 1993-2001 by Sun Microsystems, Inc.
24*7c478bd9Sstevel@tonic-gate  * All rights reserved.
25*7c478bd9Sstevel@tonic-gate  */
26*7c478bd9Sstevel@tonic-gate 
27*7c478bd9Sstevel@tonic-gate #include <AudioExtent.h>
28*7c478bd9Sstevel@tonic-gate #include <AudioList.h>
29*7c478bd9Sstevel@tonic-gate #include <AudioDebug.h>
30*7c478bd9Sstevel@tonic-gate 
31*7c478bd9Sstevel@tonic-gate // class AudioList methods
32*7c478bd9Sstevel@tonic-gate 
33*7c478bd9Sstevel@tonic-gate 
34*7c478bd9Sstevel@tonic-gate // class AudioListEntry Constructor
35*7c478bd9Sstevel@tonic-gate AudioList::AudioListEntry::
AudioListEntry(Audio * obj)36*7c478bd9Sstevel@tonic-gate AudioListEntry(
37*7c478bd9Sstevel@tonic-gate 	Audio*		obj):			// audio object to point to
38*7c478bd9Sstevel@tonic-gate 	aptr(0), next(0), prev(0)
39*7c478bd9Sstevel@tonic-gate {
40*7c478bd9Sstevel@tonic-gate 	// A NULL object is only valid in dummy entries, such as list heads
41*7c478bd9Sstevel@tonic-gate 	newptr(obj);
42*7c478bd9Sstevel@tonic-gate }
43*7c478bd9Sstevel@tonic-gate 
44*7c478bd9Sstevel@tonic-gate // class AudioListEntry Destructor
45*7c478bd9Sstevel@tonic-gate AudioList::AudioListEntry::
~AudioListEntry()46*7c478bd9Sstevel@tonic-gate ~AudioListEntry()
47*7c478bd9Sstevel@tonic-gate {
48*7c478bd9Sstevel@tonic-gate 	newptr(0);
49*7c478bd9Sstevel@tonic-gate 	if (next != 0) {
50*7c478bd9Sstevel@tonic-gate 		next->prev = prev;
51*7c478bd9Sstevel@tonic-gate 	}
52*7c478bd9Sstevel@tonic-gate 	if (prev != 0) {
53*7c478bd9Sstevel@tonic-gate 		prev->next = next;
54*7c478bd9Sstevel@tonic-gate 	}
55*7c478bd9Sstevel@tonic-gate }
56*7c478bd9Sstevel@tonic-gate 
57*7c478bd9Sstevel@tonic-gate // Set a new extent pointer in an AudioListEntry
58*7c478bd9Sstevel@tonic-gate void AudioList::AudioListEntry::
newptr(Audio * newa)59*7c478bd9Sstevel@tonic-gate newptr(
60*7c478bd9Sstevel@tonic-gate 	Audio*		newa)		// new object
61*7c478bd9Sstevel@tonic-gate {
62*7c478bd9Sstevel@tonic-gate 	if (aptr != 0)
63*7c478bd9Sstevel@tonic-gate 		aptr->Dereference();
64*7c478bd9Sstevel@tonic-gate 	aptr = newa;
65*7c478bd9Sstevel@tonic-gate 	if (aptr != 0)
66*7c478bd9Sstevel@tonic-gate 		aptr->Reference();
67*7c478bd9Sstevel@tonic-gate }
68*7c478bd9Sstevel@tonic-gate 
69*7c478bd9Sstevel@tonic-gate 	// Link object into list
70*7c478bd9Sstevel@tonic-gate // Link in a new AudioListEntry
71*7c478bd9Sstevel@tonic-gate void AudioList::AudioListEntry::
link(AudioListEntry * after)72*7c478bd9Sstevel@tonic-gate link(
73*7c478bd9Sstevel@tonic-gate 	AudioListEntry*	after)		// link after this one
74*7c478bd9Sstevel@tonic-gate {
75*7c478bd9Sstevel@tonic-gate 	// Link object into list
76*7c478bd9Sstevel@tonic-gate 	prev = after;
77*7c478bd9Sstevel@tonic-gate 	next = after->next;
78*7c478bd9Sstevel@tonic-gate 	after->next = this;
79*7c478bd9Sstevel@tonic-gate 	if (next != 0)
80*7c478bd9Sstevel@tonic-gate 		next->prev = this;
81*7c478bd9Sstevel@tonic-gate }
82*7c478bd9Sstevel@tonic-gate 
83*7c478bd9Sstevel@tonic-gate // Split an AudioListEntry at the specified offset
84*7c478bd9Sstevel@tonic-gate void AudioList::AudioListEntry::
split(Double pos)85*7c478bd9Sstevel@tonic-gate split(
86*7c478bd9Sstevel@tonic-gate 	Double		pos)		// split offset
87*7c478bd9Sstevel@tonic-gate {
88*7c478bd9Sstevel@tonic-gate 	AudioExtent*	e1;
89*7c478bd9Sstevel@tonic-gate 	AudioExtent*	e2;
90*7c478bd9Sstevel@tonic-gate 	AudioListEntry*	newp;
91*7c478bd9Sstevel@tonic-gate 
92*7c478bd9Sstevel@tonic-gate 	// Create two extents referencing this object
93*7c478bd9Sstevel@tonic-gate 	e1 = new AudioExtent(aptr, 0., pos);
94*7c478bd9Sstevel@tonic-gate 	e2 = new AudioExtent(aptr, pos, AUDIO_UNKNOWN_TIME);
95*7c478bd9Sstevel@tonic-gate 
96*7c478bd9Sstevel@tonic-gate 	// Set the current entry to the first extent and append the second
97*7c478bd9Sstevel@tonic-gate 	newptr(e1);
98*7c478bd9Sstevel@tonic-gate 	newp = new AudioListEntry(e2);
99*7c478bd9Sstevel@tonic-gate 	newp->link(this);
100*7c478bd9Sstevel@tonic-gate }
101*7c478bd9Sstevel@tonic-gate 
102*7c478bd9Sstevel@tonic-gate 
103*7c478bd9Sstevel@tonic-gate // class AudioList Constructor
104*7c478bd9Sstevel@tonic-gate AudioList::
AudioList(const char * local_name)105*7c478bd9Sstevel@tonic-gate AudioList(
106*7c478bd9Sstevel@tonic-gate 	const char  *local_name):		// name string
107*7c478bd9Sstevel@tonic-gate 	Audio(local_name), head(0)
108*7c478bd9Sstevel@tonic-gate {
109*7c478bd9Sstevel@tonic-gate }
110*7c478bd9Sstevel@tonic-gate 
111*7c478bd9Sstevel@tonic-gate // class AudioList Destructor
112*7c478bd9Sstevel@tonic-gate AudioList::
~AudioList()113*7c478bd9Sstevel@tonic-gate ~AudioList()
114*7c478bd9Sstevel@tonic-gate {
115*7c478bd9Sstevel@tonic-gate 	// Delete all entries in the list
116*7c478bd9Sstevel@tonic-gate 	while (first() != 0)
117*7c478bd9Sstevel@tonic-gate 		delete first();
118*7c478bd9Sstevel@tonic-gate }
119*7c478bd9Sstevel@tonic-gate 
120*7c478bd9Sstevel@tonic-gate // Get the first entry in the list
121*7c478bd9Sstevel@tonic-gate AudioList::AudioListEntry* AudioList::
first() const122*7c478bd9Sstevel@tonic-gate first() const
123*7c478bd9Sstevel@tonic-gate {
124*7c478bd9Sstevel@tonic-gate 	return (head.next);
125*7c478bd9Sstevel@tonic-gate }
126*7c478bd9Sstevel@tonic-gate 
127*7c478bd9Sstevel@tonic-gate // Get the extent and offset corresponding to a given position
128*7c478bd9Sstevel@tonic-gate // Return FALSE if no extents in list or position is beyond eof
129*7c478bd9Sstevel@tonic-gate Boolean AudioList::
getposition(Double & pos,AudioListEntry * & ep) const130*7c478bd9Sstevel@tonic-gate getposition(
131*7c478bd9Sstevel@tonic-gate 	Double&			pos,		// target position (updated)
132*7c478bd9Sstevel@tonic-gate 	AudioListEntry*&	ep) const	// returned extent pointer
133*7c478bd9Sstevel@tonic-gate {
134*7c478bd9Sstevel@tonic-gate 	Double			length;
135*7c478bd9Sstevel@tonic-gate 
136*7c478bd9Sstevel@tonic-gate 	// Position must be specified
137*7c478bd9Sstevel@tonic-gate 	if (Undefined(pos))
138*7c478bd9Sstevel@tonic-gate 		return (FALSE);
139*7c478bd9Sstevel@tonic-gate 
140*7c478bd9Sstevel@tonic-gate 	// Get the first extent in the list
141*7c478bd9Sstevel@tonic-gate 	ep = first();
142*7c478bd9Sstevel@tonic-gate 	while (ep != 0) {
143*7c478bd9Sstevel@tonic-gate 		// Get length of extent
144*7c478bd9Sstevel@tonic-gate 		length = ep->aptr->GetLength();
145*7c478bd9Sstevel@tonic-gate 		if (Undefined(length)) {
146*7c478bd9Sstevel@tonic-gate 			// Can't determine sizes beyond this
147*7c478bd9Sstevel@tonic-gate 			return (TRUE);
148*7c478bd9Sstevel@tonic-gate 		}
149*7c478bd9Sstevel@tonic-gate 		// If the remaining offset is inside the current extent
150*7c478bd9Sstevel@tonic-gate 		if (length > pos)
151*7c478bd9Sstevel@tonic-gate 			return (TRUE);
152*7c478bd9Sstevel@tonic-gate 
153*7c478bd9Sstevel@tonic-gate 		// Move on to the next extent
154*7c478bd9Sstevel@tonic-gate 		pos -= length;
155*7c478bd9Sstevel@tonic-gate 		ep = ep->next;
156*7c478bd9Sstevel@tonic-gate 	}
157*7c478bd9Sstevel@tonic-gate 	return (FALSE);
158*7c478bd9Sstevel@tonic-gate }
159*7c478bd9Sstevel@tonic-gate 
160*7c478bd9Sstevel@tonic-gate // Get the total length of the audio list
161*7c478bd9Sstevel@tonic-gate Double AudioList::
GetLength() const162*7c478bd9Sstevel@tonic-gate GetLength() const
163*7c478bd9Sstevel@tonic-gate {
164*7c478bd9Sstevel@tonic-gate 	AudioListEntry*	ep;
165*7c478bd9Sstevel@tonic-gate 	Double		sum;
166*7c478bd9Sstevel@tonic-gate 	Double		x;
167*7c478bd9Sstevel@tonic-gate 
168*7c478bd9Sstevel@tonic-gate 	for (sum = 0., ep = first(); ep != 0; ep = ep->next) {
169*7c478bd9Sstevel@tonic-gate 		// Accumulate times for each extent
170*7c478bd9Sstevel@tonic-gate 		// Indeterminate extents screw up the calculation
171*7c478bd9Sstevel@tonic-gate 		x = ep->aptr->GetLength();
172*7c478bd9Sstevel@tonic-gate 		if (Undefined(x))
173*7c478bd9Sstevel@tonic-gate 			return (x);
174*7c478bd9Sstevel@tonic-gate 		sum += x;
175*7c478bd9Sstevel@tonic-gate 	}
176*7c478bd9Sstevel@tonic-gate 	return (sum);
177*7c478bd9Sstevel@tonic-gate }
178*7c478bd9Sstevel@tonic-gate 
179*7c478bd9Sstevel@tonic-gate // Construct a name for the list
180*7c478bd9Sstevel@tonic-gate char *AudioList::
GetName() const181*7c478bd9Sstevel@tonic-gate GetName() const
182*7c478bd9Sstevel@tonic-gate {
183*7c478bd9Sstevel@tonic-gate 	// XXX - construct a better name
184*7c478bd9Sstevel@tonic-gate 	return (Audio::GetName());
185*7c478bd9Sstevel@tonic-gate }
186*7c478bd9Sstevel@tonic-gate 
187*7c478bd9Sstevel@tonic-gate // Get the audio header for the current read position
188*7c478bd9Sstevel@tonic-gate AudioHdr AudioList::
GetHeader()189*7c478bd9Sstevel@tonic-gate GetHeader()
190*7c478bd9Sstevel@tonic-gate {
191*7c478bd9Sstevel@tonic-gate 	return (GetHeader(ReadPosition()));
192*7c478bd9Sstevel@tonic-gate }
193*7c478bd9Sstevel@tonic-gate 
194*7c478bd9Sstevel@tonic-gate // Get the audio header for the given position
195*7c478bd9Sstevel@tonic-gate AudioHdr AudioList::
GetHeader(Double pos)196*7c478bd9Sstevel@tonic-gate GetHeader(
197*7c478bd9Sstevel@tonic-gate 	Double		pos)		// position
198*7c478bd9Sstevel@tonic-gate {
199*7c478bd9Sstevel@tonic-gate 	AudioListEntry*	ep;
200*7c478bd9Sstevel@tonic-gate 
201*7c478bd9Sstevel@tonic-gate 	// Get the extent pointer for the given position
202*7c478bd9Sstevel@tonic-gate 	if (!getposition(pos, ep)) {
203*7c478bd9Sstevel@tonic-gate 		AudioHdr	h;
204*7c478bd9Sstevel@tonic-gate 
205*7c478bd9Sstevel@tonic-gate 		if (pos != 0.) {
206*7c478bd9Sstevel@tonic-gate 			PrintMsg(_MGET_(
207*7c478bd9Sstevel@tonic-gate 			    "AudioHdr:GetHeader()...position is beyond eof"),
208*7c478bd9Sstevel@tonic-gate 			    Warning);
209*7c478bd9Sstevel@tonic-gate 			return (h);
210*7c478bd9Sstevel@tonic-gate 		}
211*7c478bd9Sstevel@tonic-gate 		if ((ep = first()) != 0)
212*7c478bd9Sstevel@tonic-gate 			return (ep->aptr->GetHeader());
213*7c478bd9Sstevel@tonic-gate 		return (h);
214*7c478bd9Sstevel@tonic-gate 	}
215*7c478bd9Sstevel@tonic-gate 	// Get the header for the proper offset in the extent
216*7c478bd9Sstevel@tonic-gate 	return (ep->aptr->GetDHeader(pos));
217*7c478bd9Sstevel@tonic-gate }
218*7c478bd9Sstevel@tonic-gate 
219*7c478bd9Sstevel@tonic-gate // Copy data from list into specified buffer.
220*7c478bd9Sstevel@tonic-gate // No data format translation takes place.
221*7c478bd9Sstevel@tonic-gate // The object's read position is not updated.
222*7c478bd9Sstevel@tonic-gate //
223*7c478bd9Sstevel@tonic-gate // Since list could contain extents of differing encodings,
224*7c478bd9Sstevel@tonic-gate // clients should always use GetHeader() in combination with ReadData()
225*7c478bd9Sstevel@tonic-gate AudioError AudioList::
ReadData(void * buf,size_t & len,Double & pos)226*7c478bd9Sstevel@tonic-gate ReadData(
227*7c478bd9Sstevel@tonic-gate 	void*		buf,		// destination buffer address
228*7c478bd9Sstevel@tonic-gate 	size_t&		len,		// buffer size (updated)
229*7c478bd9Sstevel@tonic-gate 	Double&		pos)		// start position (updated)
230*7c478bd9Sstevel@tonic-gate {
231*7c478bd9Sstevel@tonic-gate 	AudioListEntry*	ep;
232*7c478bd9Sstevel@tonic-gate 	size_t		cnt;
233*7c478bd9Sstevel@tonic-gate 	Double		off;
234*7c478bd9Sstevel@tonic-gate 	Double		newpos;
235*7c478bd9Sstevel@tonic-gate 	AudioError	err;
236*7c478bd9Sstevel@tonic-gate 
237*7c478bd9Sstevel@tonic-gate 	// Save buffer size
238*7c478bd9Sstevel@tonic-gate 	cnt = len;
239*7c478bd9Sstevel@tonic-gate 
240*7c478bd9Sstevel@tonic-gate 	// Position must be valid
241*7c478bd9Sstevel@tonic-gate 	if (Undefined(pos) || (pos < 0.) || ((int)cnt < 0))
242*7c478bd9Sstevel@tonic-gate 		return (RaiseError(AUDIO_ERR_BADARG));
243*7c478bd9Sstevel@tonic-gate 
244*7c478bd9Sstevel@tonic-gate 	// Loop until data is returned or error
245*7c478bd9Sstevel@tonic-gate 	// XXX - THIS IS WRONG!  THE HEADER COULD CHANGE!
246*7c478bd9Sstevel@tonic-gate 	do {
247*7c478bd9Sstevel@tonic-gate 		// Get the extent/offset for read position; clear return count
248*7c478bd9Sstevel@tonic-gate 		len = 0;
249*7c478bd9Sstevel@tonic-gate 		off = pos;
250*7c478bd9Sstevel@tonic-gate 		if (!getposition(off, ep)) {
251*7c478bd9Sstevel@tonic-gate 			err = AUDIO_EOF;
252*7c478bd9Sstevel@tonic-gate 			err.sys = AUDIO_COPY_INPUT_EOF;
253*7c478bd9Sstevel@tonic-gate 			return (err);
254*7c478bd9Sstevel@tonic-gate 		}
255*7c478bd9Sstevel@tonic-gate 
256*7c478bd9Sstevel@tonic-gate 		// Save the offset and read some data
257*7c478bd9Sstevel@tonic-gate 		newpos = off;
258*7c478bd9Sstevel@tonic-gate 		len = cnt;
259*7c478bd9Sstevel@tonic-gate 		err = ep->aptr->ReadData(buf, len, newpos);
260*7c478bd9Sstevel@tonic-gate 
261*7c478bd9Sstevel@tonic-gate 		// If no eof on this list entry, or no more data, we're done
262*7c478bd9Sstevel@tonic-gate 		if ((err != AUDIO_EOF) || (err.sys != AUDIO_COPY_INPUT_EOF) ||
263*7c478bd9Sstevel@tonic-gate 		    (ep->next == 0)) {
264*7c478bd9Sstevel@tonic-gate 			break;
265*7c478bd9Sstevel@tonic-gate 		}
266*7c478bd9Sstevel@tonic-gate 
267*7c478bd9Sstevel@tonic-gate 		// Advance to next list entry
268*7c478bd9Sstevel@tonic-gate 		// XXX - Is this problemmatic, too?
269*7c478bd9Sstevel@tonic-gate 		pos += ep->aptr->GetLength() - off;
270*7c478bd9Sstevel@tonic-gate 	} while (TRUE);
271*7c478bd9Sstevel@tonic-gate 
272*7c478bd9Sstevel@tonic-gate 	// Update the byte count and position
273*7c478bd9Sstevel@tonic-gate 	pos += (newpos - off);		// XXX - recalculate?
274*7c478bd9Sstevel@tonic-gate 	return (err);
275*7c478bd9Sstevel@tonic-gate }
276*7c478bd9Sstevel@tonic-gate 
277*7c478bd9Sstevel@tonic-gate // Write to AudioList is (currently) prohibited
278*7c478bd9Sstevel@tonic-gate AudioError AudioList::
WriteData(void *,size_t & len,Double &)279*7c478bd9Sstevel@tonic-gate WriteData(
280*7c478bd9Sstevel@tonic-gate 	void*,				// destination buffer address
281*7c478bd9Sstevel@tonic-gate 	size_t&		len,		// buffer size (updated)
282*7c478bd9Sstevel@tonic-gate 	Double&)			// start position (updated)
283*7c478bd9Sstevel@tonic-gate {
284*7c478bd9Sstevel@tonic-gate 	len = 0;
285*7c478bd9Sstevel@tonic-gate 	return (RaiseError(AUDIO_ERR_NOEFFECT));
286*7c478bd9Sstevel@tonic-gate }
287*7c478bd9Sstevel@tonic-gate 
288*7c478bd9Sstevel@tonic-gate // Insert an entry at the start
289*7c478bd9Sstevel@tonic-gate AudioError AudioList::
Insert(Audio * obj)290*7c478bd9Sstevel@tonic-gate Insert(
291*7c478bd9Sstevel@tonic-gate 	Audio*		obj)		// object to insert
292*7c478bd9Sstevel@tonic-gate {
293*7c478bd9Sstevel@tonic-gate 	Double		pos;		// insertion offset, in seconds
294*7c478bd9Sstevel@tonic-gate 
295*7c478bd9Sstevel@tonic-gate 	return (Insert(obj, pos = 0.));
296*7c478bd9Sstevel@tonic-gate }
297*7c478bd9Sstevel@tonic-gate 
298*7c478bd9Sstevel@tonic-gate // Insert an entry at a specified position
299*7c478bd9Sstevel@tonic-gate AudioError AudioList::
Insert(Audio * obj,Double pos)300*7c478bd9Sstevel@tonic-gate Insert(
301*7c478bd9Sstevel@tonic-gate 	Audio*		obj,		// object to insert
302*7c478bd9Sstevel@tonic-gate 	Double		pos)		// insertion offset, in seconds
303*7c478bd9Sstevel@tonic-gate {
304*7c478bd9Sstevel@tonic-gate 	AudioListEntry	*ep;
305*7c478bd9Sstevel@tonic-gate 	AudioListEntry	*prev;
306*7c478bd9Sstevel@tonic-gate 
307*7c478bd9Sstevel@tonic-gate 	// Find the insertion point
308*7c478bd9Sstevel@tonic-gate 	if (first() == 0) {
309*7c478bd9Sstevel@tonic-gate 		prev = &head;		// this is the first extent
310*7c478bd9Sstevel@tonic-gate 	} else {
311*7c478bd9Sstevel@tonic-gate 		if (!getposition(pos, prev)) {
312*7c478bd9Sstevel@tonic-gate 			if (pos == 0.) {
313*7c478bd9Sstevel@tonic-gate 				// Append extent to end of list
314*7c478bd9Sstevel@tonic-gate 				return (Append(obj));
315*7c478bd9Sstevel@tonic-gate 			} else {
316*7c478bd9Sstevel@tonic-gate 				return (RaiseError(AUDIO_ERR_BADARG));
317*7c478bd9Sstevel@tonic-gate 			}
318*7c478bd9Sstevel@tonic-gate 		} else if (pos != 0.) {
319*7c478bd9Sstevel@tonic-gate 			// The insertion is in an extent, split it in two
320*7c478bd9Sstevel@tonic-gate 			prev->split(pos);
321*7c478bd9Sstevel@tonic-gate 		} else {
322*7c478bd9Sstevel@tonic-gate 			// Insert before the current position
323*7c478bd9Sstevel@tonic-gate 			prev = prev->prev;
324*7c478bd9Sstevel@tonic-gate 		}
325*7c478bd9Sstevel@tonic-gate 	}
326*7c478bd9Sstevel@tonic-gate 	// Create object and link into list
327*7c478bd9Sstevel@tonic-gate 	ep = new AudioListEntry(obj);
328*7c478bd9Sstevel@tonic-gate 	ep->link(prev);
329*7c478bd9Sstevel@tonic-gate 
330*7c478bd9Sstevel@tonic-gate 	return (AUDIO_SUCCESS);
331*7c478bd9Sstevel@tonic-gate }
332*7c478bd9Sstevel@tonic-gate 
333*7c478bd9Sstevel@tonic-gate // Append an entry to a list
334*7c478bd9Sstevel@tonic-gate AudioError AudioList::
Append(Audio * obj)335*7c478bd9Sstevel@tonic-gate Append(
336*7c478bd9Sstevel@tonic-gate 	Audio*		obj)		// object to append
337*7c478bd9Sstevel@tonic-gate {
338*7c478bd9Sstevel@tonic-gate 	AudioListEntry	*ep;
339*7c478bd9Sstevel@tonic-gate 	AudioListEntry	*prev;
340*7c478bd9Sstevel@tonic-gate 
341*7c478bd9Sstevel@tonic-gate 	// Find the last extent in the list
342*7c478bd9Sstevel@tonic-gate 	for (prev = &head; prev->next != 0; prev = prev->next)
343*7c478bd9Sstevel@tonic-gate 		continue;
344*7c478bd9Sstevel@tonic-gate 
345*7c478bd9Sstevel@tonic-gate 	// Create object and link into list
346*7c478bd9Sstevel@tonic-gate 	ep = new AudioListEntry(obj);
347*7c478bd9Sstevel@tonic-gate 	ep->link(prev);
348*7c478bd9Sstevel@tonic-gate 	return (AUDIO_SUCCESS);
349*7c478bd9Sstevel@tonic-gate }
350*7c478bd9Sstevel@tonic-gate 
351*7c478bd9Sstevel@tonic-gate // Copy routine for lists
352*7c478bd9Sstevel@tonic-gate AudioError AudioList::
AsyncCopy(Audio * to,Double & frompos,Double & topos,Double & limit)353*7c478bd9Sstevel@tonic-gate AsyncCopy(
354*7c478bd9Sstevel@tonic-gate 	Audio*		to,			// audio object to copy to
355*7c478bd9Sstevel@tonic-gate 	Double&		frompos,		// input pos (updated)
356*7c478bd9Sstevel@tonic-gate 	Double&		topos,			// output pos (updated)
357*7c478bd9Sstevel@tonic-gate 	Double&		limit)			// amt to copy (updated)
358*7c478bd9Sstevel@tonic-gate {
359*7c478bd9Sstevel@tonic-gate 	AudioListEntry*	ep;
360*7c478bd9Sstevel@tonic-gate 	Double		svlim;
361*7c478bd9Sstevel@tonic-gate 	Double		newpos;
362*7c478bd9Sstevel@tonic-gate 	Double		off;
363*7c478bd9Sstevel@tonic-gate 	AudioError	err;
364*7c478bd9Sstevel@tonic-gate 
365*7c478bd9Sstevel@tonic-gate 	svlim = limit;
366*7c478bd9Sstevel@tonic-gate 	// Loop until data is returned or error
367*7c478bd9Sstevel@tonic-gate 	// XXX - THIS IS WRONG!  THE HEADER COULD CHANGE!
368*7c478bd9Sstevel@tonic-gate 	do {
369*7c478bd9Sstevel@tonic-gate 		// Get the extent and offset for the read position
370*7c478bd9Sstevel@tonic-gate 		off = frompos;
371*7c478bd9Sstevel@tonic-gate 		if (!getposition(off, ep)) {
372*7c478bd9Sstevel@tonic-gate 			// nothing written, limit should reflect this
373*7c478bd9Sstevel@tonic-gate 			limit = 0.0;
374*7c478bd9Sstevel@tonic-gate 			err = AUDIO_EOF;
375*7c478bd9Sstevel@tonic-gate 			err.sys = AUDIO_COPY_INPUT_EOF;
376*7c478bd9Sstevel@tonic-gate 			return (err);
377*7c478bd9Sstevel@tonic-gate 		}
378*7c478bd9Sstevel@tonic-gate 
379*7c478bd9Sstevel@tonic-gate 		// Save the offset and do a copy
380*7c478bd9Sstevel@tonic-gate 		newpos = off;
381*7c478bd9Sstevel@tonic-gate 		limit = svlim;
382*7c478bd9Sstevel@tonic-gate 		err = ep->aptr->AsyncCopy(to, newpos, topos, limit);
383*7c478bd9Sstevel@tonic-gate 
384*7c478bd9Sstevel@tonic-gate 		// If no eof on this list entry, or no more data, we're done
385*7c478bd9Sstevel@tonic-gate 		if ((err != AUDIO_EOF) || (err.sys != AUDIO_COPY_INPUT_EOF) ||
386*7c478bd9Sstevel@tonic-gate 		    (ep->next == 0)) {
387*7c478bd9Sstevel@tonic-gate 			break;
388*7c478bd9Sstevel@tonic-gate 		}
389*7c478bd9Sstevel@tonic-gate 
390*7c478bd9Sstevel@tonic-gate 		// Advance to next list entry
391*7c478bd9Sstevel@tonic-gate 		// XXX - Is this problemmatic, too?
392*7c478bd9Sstevel@tonic-gate 		frompos += ep->aptr->GetLength() - off;
393*7c478bd9Sstevel@tonic-gate 	} while (TRUE);
394*7c478bd9Sstevel@tonic-gate 
395*7c478bd9Sstevel@tonic-gate 	// Update the byte count and  position
396*7c478bd9Sstevel@tonic-gate 	frompos += (newpos - off); // XXX - recalculate?
397*7c478bd9Sstevel@tonic-gate 	return (err);
398*7c478bd9Sstevel@tonic-gate }
399