1 /*
2 * Copyright (c) 2019, 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_hevc_mv_buffers.cpp
24 //! \brief Defines MV buffers related logic for hevc decode
25 //!
26
27 #include "decode_hevc_basic_feature.h"
28 #include "decode_utils.h"
29 #include "decode_hevc_mv_buffers.h"
30 #include "codec_def_decode_hevc.h"
31
32 namespace decode
33 {
34
Init(void * hwInterface,DecodeAllocator & allocator,HevcBasicFeature & basicFeature)35 MOS_STATUS HevcMvBufferOpInf::Init(void* hwInterface, DecodeAllocator& allocator,
36 HevcBasicFeature& basicFeature)
37 {
38 DECODE_CHK_STATUS(BufferOpInf::Init(hwInterface, allocator, basicFeature));
39
40 return MOS_STATUS_SUCCESS;
41 }
42
Allocate()43 MOS_BUFFER* HevcMvBufferOpInf::Allocate()
44 {
45 DECODE_FUNC_CALL();
46
47 uint32_t mvtSize = ((((m_basicFeature->m_width + 63) >> 6) * (((m_basicFeature->m_height + 15) >> 4)) + 1)&(-2));
48 uint32_t mvtbSize = ((((m_basicFeature->m_width + 31) >> 5) * (((m_basicFeature->m_height + 31) >> 5)) + 1)&(-2));
49 uint32_t bufferSize = MOS_MAX(mvtSize, mvtbSize) * MHW_CACHELINE_SIZE;
50
51 auto buffer = m_allocator->AllocateBuffer(bufferSize, "MvTemporalBuffer",
52 resourceInternalReadWriteCache, notLockableVideoMem);
53
54 return buffer;
55 }
56
Resize(MOS_BUFFER * & buffer)57 MOS_STATUS HevcMvBufferOpInf::Resize(MOS_BUFFER* &buffer)
58 {
59 DECODE_FUNC_CALL();
60
61 if (buffer == nullptr)
62 {
63 DECODE_CHK_NULL(buffer = Allocate());
64 return MOS_STATUS_SUCCESS;
65 }
66
67 uint32_t mvtSize = ((((m_basicFeature->m_width + 63) >> 6) * (((m_basicFeature->m_height + 15) >> 4)) + 1)&(-2));
68 uint32_t mvtbSize = ((((m_basicFeature->m_width + 31) >> 5) * (((m_basicFeature->m_height + 31) >> 5)) + 1)&(-2));
69 uint32_t bufferSize = MOS_MAX(mvtSize, mvtbSize) * MHW_CACHELINE_SIZE;
70
71 auto status = m_allocator->Resize(buffer, bufferSize, notLockableVideoMem, false);
72 return status;
73 }
74
Destroy(MOS_BUFFER * & buffer)75 void HevcMvBufferOpInf::Destroy(MOS_BUFFER* &buffer)
76 {
77 DECODE_FUNC_CALL();
78
79 if (m_allocator != nullptr)
80 {
81 m_allocator->Destroy(buffer);
82 }
83 }
84
85 } // namespace decode
86