| 1 |
/* |
| 2 |
* Copyright (c) 2017, Intel Corporation |
| 3 |
* |
| 4 |
* Permission is hereby granted, free of charge, to any person obtaining a |
| 5 |
* copy of this software and associated documentation files (the "Software"), |
| 6 |
* to deal in the Software without restriction, including without limitation |
| 7 |
* the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 8 |
* and/or sell copies of the Software, and to permit persons to whom the |
| 9 |
* Software is furnished to do so, subject to the following conditions: |
| 10 |
* |
| 11 |
* The above copyright notice and this permission notice shall be included |
| 12 |
* in all copies or substantial portions of the Software. |
| 13 |
* |
| 14 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 15 |
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 16 |
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 17 |
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR |
| 18 |
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
| 19 |
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
| 20 |
* OTHER DEALINGS IN THE SOFTWARE. |
| 21 |
*/ |
| 22 |
//! |
| 23 |
//! \file cm_vebox_data.cpp |
| 24 |
//! \brief Contains Class CmVeboxData definitions |
| 25 |
//! |
| 26 |
|
| 27 |
#include "cm_vebox_data.h" |
| 28 |
|
| 29 |
#include "cm_mem.h" |
| 30 |
|
| 31 |
namespace CMRT_UMD |
| 32 |
{ |
| 33 |
//*----------------------------------------------------------------------------- |
| 34 |
//| Purpose: Create Vebox Data |
| 35 |
//| Returns: Result of the operation. |
| 36 |
//*----------------------------------------------------------------------------- |
| 37 |
int32_t CmVeboxData::Create( uint8_t *stateData, uint8_t *surfaceData, CmVeboxData*& veboxData ) |
| 38 |
{ |
| 39 |
int32_t result = CM_SUCCESS; |
| 40 |
veboxData = new (std::nothrow) CmVeboxData( stateData, surfaceData ); |
| 41 |
if( veboxData ) |
| 42 |
{ |
| 43 |
veboxData->Acquire(); |
| 44 |
result = veboxData->Initialize(); |
| 45 |
if( result != CM_SUCCESS ) |
| 46 |
{ |
| 47 |
CmVeboxData::Destroy( veboxData ); |
| 48 |
} |
| 49 |
} |
| 50 |
else |
| 51 |
{ |
| 52 |
CM_ASSERTMESSAGE("Error: Failed to create CmVeboxData due to out of system memory."); |
| 53 |
result = CM_OUT_OF_HOST_MEMORY; |
| 54 |
} |
| 55 |
return result; |
| 56 |
|
| 57 |
} |
| 58 |
|
| 59 |
//*----------------------------------------------------------------------------- |
| 60 |
//| Purpose: Destroy CM Vebox Data |
| 61 |
//| Returns: Result of the operation. |
| 62 |
//*----------------------------------------------------------------------------- |
| 63 |
int32_t CmVeboxData::Destroy( CmVeboxData* &veboxData ) |
| 64 |
{ |
| 65 |
if (veboxData) |
| 66 |
{ |
| 67 |
veboxData->SafeRelease(); |
| 68 |
veboxData = nullptr; |
| 69 |
} |
| 70 |
|
| 71 |
return CM_SUCCESS; |
| 72 |
} |
| 73 |
|
| 74 |
//*----------------------------------------------------------------------------- |
| 75 |
//| Purpose: CM Vebox Data constructor |
| 76 |
//| Returns: Result of the operation. |
| 77 |
//*----------------------------------------------------------------------------- |
| 78 |
CmVeboxData::CmVeboxData( uint8_t *stateData, uint8_t *surfaceData ): |
| 79 |
m_stateDataSize( 0 ), |
| 80 |
m_stateData( stateData ), |
| 81 |
m_surfaceDataSize( 0 ), |
| 82 |
m_surfaceData( surfaceData ), |
| 83 |
m_refCount(0) |
| 84 |
{ |
| 85 |
} |
| 86 |
|
| 87 |
//*----------------------------------------------------------------------------- |
| 88 |
//| Purpose: CM Vebox Data Destructor |
| 89 |
//| Returns: Result of the operation. |
| 90 |
//*----------------------------------------------------------------------------- |
| 91 |
CmVeboxData::~CmVeboxData( void ) |
| 92 |
{ |
| 93 |
MosSafeDeleteArray( m_stateData ); |
| 94 |
MosSafeDeleteArray( m_surfaceData ); |
| 95 |
} |
| 96 |
|
| 97 |
//*----------------------------------------------------------------------------- |
| 98 |
//| Purpose: Do nothing in initialization |
| 99 |
//| Returns: CM_SUCCESS |
| 100 |
//*----------------------------------------------------------------------------- |
| 101 |
int32_t CmVeboxData::Initialize( void ) |
| 102 |
{ |
| 103 |
return CM_SUCCESS; |
| 104 |
} |
| 105 |
|
| 106 |
//*----------------------------------------------------------------------------- |
| 107 |
//| Purpose: Get Vebox Data pointer |
| 108 |
//| Returns: Result of the operation. |
| 109 |
//*----------------------------------------------------------------------------- |
| 110 |
int32_t CmVeboxData::GetData( uint8_t*& stateData, uint8_t*& surfaceData ) |
| 111 |
{ |
| 112 |
stateData = m_stateData; |
| 113 |
surfaceData = m_surfaceData; |
| 114 |
|
| 115 |
return CM_SUCCESS; |
| 116 |
} |
| 117 |
|
| 118 |
//*----------------------------------------------------------------------------- |
| 119 |
//| Purpose: SET Vebox Data size |
| 120 |
//| Returns: Result of the operation. |
| 121 |
//*----------------------------------------------------------------------------- |
| 122 |
int32_t CmVeboxData::SetVeboxDataSize(uint32_t stateDataSize, uint32_t surfaceDataSize) |
| 123 |
{ |
| 124 |
m_stateDataSize = stateDataSize; |
| 125 |
m_surfaceDataSize = surfaceDataSize; |
| 126 |
|
| 127 |
return CM_SUCCESS; |
| 128 |
} |
| 129 |
|
| 130 |
//*----------------------------------------------------------------------------- |
| 131 |
//| Purpose: Get Vebox Data size |
| 132 |
//| Returns: Result of the operation. |
| 133 |
//*----------------------------------------------------------------------------- |
| 134 |
int32_t CmVeboxData::GetVeboxDataSize(uint32_t& stateDataSize, uint32_t& surfaceDataSize) |
| 135 |
{ |
| 136 |
stateDataSize = m_stateDataSize; |
| 137 |
surfaceDataSize = m_surfaceDataSize; |
| 138 |
|
| 139 |
return CM_SUCCESS; |
| 140 |
} |
| 141 |
|
| 142 |
//*----------------------------------------------------------------------------- |
| 143 |
//| Purpose: Increase Reference count |
| 144 |
//| Returns: Result of the operation. |
| 145 |
//*----------------------------------------------------------------------------- |
| 146 |
int32_t CmVeboxData::Acquire( void ) |
| 147 |
{ |
| 148 |
++m_refCount; |
| 149 |
return m_refCount; |
| 150 |
} |
| 151 |
|
| 152 |
//*----------------------------------------------------------------------------- |
| 153 |
//| Purpose: De of Cm Event |
| 154 |
//| Returns: Result of the operation. |
| 155 |
//*----------------------------------------------------------------------------- |
| 156 |
int32_t CmVeboxData::SafeRelease( ) |
| 157 |
{ |
| 158 |
--m_refCount; |
| 159 |
if( m_refCount == 0 ) |
| 160 |
{ |
| 161 |
delete this; |
| 162 |
return 0; |
| 163 |
} |
| 164 |
else |
| 165 |
{ |
| 166 |
return m_refCount; |
| 167 |
} |
| 168 |
} |
| 169 |
} // namespace |