2 * Copyright (c) 1999-2000, Eric Moon.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions, and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions, and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * 3. The name of the author may not be used to endorse or promote products
17 * derived from this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 * OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
23 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
26 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
27 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 // eamoon@meadgroup.com
36 // A basic representation of a media buffer. RawBuffer
37 // instances may either allocate and maintain their own buffer or
38 // represent external data.
42 // realtime allocation support
47 #ifndef __RawBuffer_H__
48 #define __RawBuffer_H__
50 #include <SupportDefs.h>
55 public: // ctor/dtor/accessors
58 // allocate buffer (if frames > 0)
59 // [16jun99] if pFromPool is nonzero, uses realtime allocator
60 // w/ the provided pool; otherwise uses standard
66 rtm_pool
* pFromPool
=0);
68 // point to given data (does NOT take responsibility for
69 // deleting it; use adopt() for that.)
75 rtm_pool
* pFromPool
=0);
77 // generate reference to the given target buffer
78 RawBuffer(const RawBuffer
& clone
);
79 RawBuffer
& operator=(const RawBuffer
& clone
);
81 // returns pointer to start of buffer
83 // returns pointer to given frame
84 char* frame(uint32 frame
) const;
86 uint32
frameSize() const;
87 uint32
frames() const;
90 bool isCircular() const;
91 bool ownsBuffer() const;
93 rtm_pool
* pool() const;
95 // resize buffer, re-allocating if necessary to contain
96 // designated number of frames
97 // Does not preserve buffer contents.
99 void resize(uint32 frames
);
101 // take ownership of buffer from target
102 // (deletes current buffer data, if any owned)
111 // returns false if the target doesn't own the data, but references it
112 // one way or the other
113 bool adopt(RawBuffer
& target
);
115 // adopt currently ref'd data (if any; returns false if no buffer data or
119 public: // operations
121 // fill the buffer with zeroes
125 // raw copy to destination buffer, returning the number of
126 // frames written, and adjusting both offsets accordingly.
128 // no frames will be written if the buffers' frame sizes
131 // rawCopyTo() will repeat the source data as many times as
132 // necessary to fill the desired number of frames, but
133 // will write no more than the target buffer's size.
137 uint32
* pioFromFrame
,
138 uint32
* pioTargetFrame
,
139 uint32 frames
) const;
141 // more convenient version of above if you don't care
142 // how the offsets change.
148 uint32 frames
) const;
150 protected: // internal operations
151 // free owned data, if any
152 // [16jun99] uses proper rtm_free() call if needed
155 protected: // members
160 uint32 m_allocatedSize
;
166 #endif /* __RawBuffer_H__ */