2 Copyright (c) 2004-2006, John Hurst
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions
8 1. Redistributions of source code must retain the above copyright
9 notice, this list of conditions and the following disclaimer.
10 2. Redistributions in binary form must reproduce the above copyright
11 notice, this list of conditions and the following disclaimer in the
12 documentation and/or other materials provided with the distribution.
13 3. The name of the author may not be used to endorse or promote products
14 derived from this software without specific prior written permission.
16 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 \brief AS-DCP library, misc classes and subroutines
32 #include "AS_DCP_internal.h"
39 snprintf(ver, 16, "%u.%u.%u", VERSION_MAJOR, VERSION_APIMINOR, VERSION_IMPMINOR);
44 //------------------------------------------------------------------------------------------
46 // frame buffer base class implementation
48 ASDCP::FrameBuffer::FrameBuffer() :
49 m_Data(0), m_Capacity(0), m_OwnMem(false), m_Size(0),
50 m_FrameNumber(0), m_SourceLength(0), m_PlaintextOffset(0)
54 ASDCP::FrameBuffer::~FrameBuffer()
56 if ( m_OwnMem && m_Data != 0 )
60 // Instructs the object to use an externally allocated buffer. The external
61 // buffer will not be cleaned up by the frame buffer when it is destroyed.
62 // Call with (0,0) to revert to internally allocated buffer.
63 // Returns error if the buf_addr argument is NULL and either buf_size is
64 // non-zero or internally allocated memory is in use.
66 ASDCP::FrameBuffer::SetData(byte_t* buf_addr, ui32_t buf_size)
68 // if buf_addr is null and we have an external memory reference,
69 // drop the reference and place the object in the initialized-
70 // but-no-buffer-allocated state
73 if ( buf_size > 0 || m_OwnMem )
77 m_Capacity = m_Size = 0;
82 if ( m_OwnMem && m_Data != 0 )
86 m_Capacity = buf_size;
93 // Sets the size of the internally allocate buffer. Returns RESULT_CAPEXTMEM
94 // if the object is using an externally allocated buffer via SetData();
95 // Resets content size to zero.
97 ASDCP::FrameBuffer::Capacity(ui32_t cap_size)
99 if ( ! m_OwnMem && m_Data != 0 )
100 return RESULT_CAPEXTMEM; // cannot resize external memory
102 if ( m_Capacity < cap_size )
110 m_Data = (byte_t*)malloc(cap_size);
115 m_Capacity = cap_size;