1 /*
2 * Copyright (c) 2021-2022, 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_vvc_mv_buffers.cpp
24 //! \brief Defines MV buffers related logic for vvc decode
25 //!
26
27 #include "decode_vvc_basic_feature.h"
28 #include "decode_utils.h"
29 #include "decode_vvc_mv_buffers.h"
30 #include "codec_def_decode_vvc.h"
31
32 namespace decode
33 {
34
Init(void * hwInterface,DecodeAllocator & allocator,VvcBasicFeature & basicFeature)35 MOS_STATUS VvcMvBufferOpInf::Init(void* hwInterface, DecodeAllocator& allocator,
36 VvcBasicFeature& basicFeature)
37 {
38 DECODE_CHK_STATUS(BufferOpInf::Init(hwInterface, allocator, basicFeature));
39 if (m_hwInterface != nullptr)
40 {
41 auto itf = static_cast<CodechalHwInterfaceNext *>(m_hwInterface);
42 m_vvcpItf = std::static_pointer_cast<mhw::vdbox::vvcp::Itf>(itf->GetVvcpInterfaceNext());
43 }
44 DECODE_CHK_NULL(m_vvcpItf);
45
46 return MOS_STATUS_SUCCESS;
47 }
48
Allocate()49 MOS_BUFFER* VvcMvBufferOpInf::Allocate()
50 {
51 DECODE_FUNC_CALL();
52
53 mhw::vdbox::vvcp::VvcpBufferSizePar vvcpBufSizeParam;
54 MOS_ZeroMemory(&vvcpBufSizeParam, sizeof(vvcpBufSizeParam));
55 vvcpBufSizeParam.m_picWidth = m_basicFeature->m_width;
56 vvcpBufSizeParam.m_picHeight = m_basicFeature->m_height;
57 if (m_vvcpItf->GetVvcpBufSize(mhw::vdbox::vvcp::vcMvTemporalBuffer, &vvcpBufSizeParam) != MOS_STATUS_SUCCESS)
58 {
59 return nullptr;
60 }
61
62 return m_allocator->AllocateBuffer(
63 vvcpBufSizeParam.m_bufferSize,
64 "MvTemporalBuffer",
65 resourceInternalReadWriteCache,
66 notLockableVideoMem);
67 }
68
Resize(MOS_BUFFER * & buffer)69 MOS_STATUS VvcMvBufferOpInf::Resize(MOS_BUFFER* &buffer)
70 {
71 DECODE_FUNC_CALL();
72
73 if (buffer == nullptr)
74 {
75 DECODE_CHK_NULL(buffer = Allocate());
76 return MOS_STATUS_SUCCESS;
77 }
78
79 mhw::vdbox::vvcp::VvcpBufferSizePar vvcpBufSizeParam;
80 MOS_ZeroMemory(&vvcpBufSizeParam, sizeof(vvcpBufSizeParam));
81 vvcpBufSizeParam.m_picWidth = m_basicFeature->m_width;
82 vvcpBufSizeParam.m_picHeight = m_basicFeature->m_height;
83 DECODE_CHK_STATUS(m_vvcpItf->GetVvcpBufSize(
84 mhw::vdbox::vvcp::vcMvTemporalBuffer,
85 &vvcpBufSizeParam));
86
87 return m_allocator->Resize(buffer, vvcpBufSizeParam.m_bufferSize, notLockableVideoMem, false);
88 }
89
Destroy(MOS_BUFFER * & buffer)90 void VvcMvBufferOpInf::Destroy(MOS_BUFFER* &buffer)
91 {
92 DECODE_FUNC_CALL();
93 if (m_allocator != nullptr)
94 {
95 m_allocator->Destroy(buffer);
96 }
97 }
98
99 } // namespace decode
100