1 /*
2 * Copyright (c) 2020, 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     decode_avc_mv_buffers.cpp
24 //! \brief    Defines MV buffers related logic for avc decode
25 //!
26 
27 #include "decode_avc_basic_feature.h"
28 #include "decode_utils.h"
29 #include "decode_avc_mv_buffers.h"
30 #include "codec_def_decode_avc.h"
31 
32 namespace decode
33 {
34 
Init(void * hwInterface,DecodeAllocator & allocator,AvcBasicFeature & basicFeature)35 MOS_STATUS AvcMvBufferOpInf::Init(void* hwInterface, DecodeAllocator& allocator,
36                                    AvcBasicFeature& basicFeature)
37 {
38     DECODE_CHK_STATUS(BufferOpInf::Init(hwInterface, allocator, basicFeature));
39     return MOS_STATUS_SUCCESS;
40 }
41 
Allocate()42 MOS_BUFFER* AvcMvBufferOpInf::Allocate()
43 {
44     DECODE_FUNC_CALL();
45 
46     m_picWidthInMB =  (uint16_t)CODECHAL_GET_WIDTH_IN_MACROBLOCKS(m_basicFeature->m_width);
47     m_picHeightInMB = (uint16_t)CODECHAL_GET_WIDTH_IN_MACROBLOCKS(m_basicFeature->m_height);
48 
49     uint32_t avcDmvBufferSize = 64 * m_picWidthInMB * (uint32_t)(MOS_ALIGN_CEIL(m_picHeightInMB, 2));
50     return m_allocator->AllocateBuffer(avcDmvBufferSize, "AvcMvBuffer", resourceInternalReadWriteCache, notLockableVideoMem);
51 }
52 
Resize(MOS_BUFFER * & buffer)53 MOS_STATUS AvcMvBufferOpInf::Resize(MOS_BUFFER* &buffer)
54 {
55     DECODE_FUNC_CALL();
56 
57     if (buffer == nullptr)
58     {
59         DECODE_CHK_NULL(buffer = Allocate());
60         return MOS_STATUS_SUCCESS;
61     }
62 
63     m_picWidthInMB  = MOS_MAX(m_picWidthInMB, m_basicFeature->m_avcPicParams->pic_width_in_mbs_minus1 + 1);
64     m_picHeightInMB = MOS_MAX(m_picHeightInMB, m_basicFeature->m_avcPicParams->pic_height_in_mbs_minus1 + 1);
65 
66     uint32_t newDmvBufferSize = 64 * m_picWidthInMB * (uint32_t)(MOS_ALIGN_CEIL(m_picHeightInMB, 2));
67     return m_allocator->Resize(buffer, newDmvBufferSize, notLockableVideoMem, false);
68 }
69 
Destroy(MOS_BUFFER * & buffer)70 void AvcMvBufferOpInf::Destroy(MOS_BUFFER* &buffer)
71 {
72     DECODE_FUNC_CALL();
73 
74     if (m_allocator != nullptr)
75     {
76         m_allocator->Destroy(buffer);
77     }
78 }
79 
80 }  // namespace decode
81