1 /*
2 * Copyright (c) 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_hevc_packet_long.cpp
24 //! \brief    Defines the interface for hevc long format decode packet
25 //!
26 #include "decode_hevc_packet_long.h"
27 #include "decode_status_report_defs.h"
28 #include "decode_predication_packet.h"
29 #include "decode_marker_packet.h"
30 
31 namespace decode {
32 
~HevcDecodeLongPkt()33 HevcDecodeLongPkt::~HevcDecodeLongPkt()
34 {
35 }
36 
Init()37 MOS_STATUS HevcDecodeLongPkt::Init()
38 {
39     DECODE_FUNC_CALL();
40     DECODE_CHK_STATUS(HevcDecodePkt::Init());
41 
42     DECODE_CHK_STATUS(m_statusReport->RegistObserver(this));
43 
44     DecodeSubPacket* subPacket = m_hevcPipeline->GetSubPacket(DecodePacketId(m_hevcPipeline, hevcPictureSubPacketId));
45     m_picturePkt = dynamic_cast<HevcDecodePicPkt*>(subPacket);
46     DECODE_CHK_NULL(m_picturePkt);
47 
48     subPacket = m_hevcPipeline->GetSubPacket(DecodePacketId(m_hevcPipeline, hevcSliceSubPacketId));
49     m_slicePkt = dynamic_cast<HevcDecodeSlcPkt*>(subPacket);
50     DECODE_CHK_NULL(m_slicePkt);
51 
52     return MOS_STATUS_SUCCESS;
53 }
54 
Destroy()55 MOS_STATUS HevcDecodeLongPkt::Destroy()
56 {
57     m_statusReport->UnregistObserver(this);
58     return MOS_STATUS_SUCCESS;
59 }
60 
IsPrologRequired()61 bool HevcDecodeLongPkt::IsPrologRequired()
62 {
63     if (!m_hevcPipeline->IsShortFormat())
64     {
65         return true;
66     }
67 
68     if (!m_hevcPipeline->IsSingleTaskPhaseSupported())
69     {
70         return true;
71     }
72 
73     return false;
74 }
75 
CalculateCommandSize(uint32_t & commandBufferSize,uint32_t & requestedPatchListSize)76 MOS_STATUS HevcDecodeLongPkt::CalculateCommandSize(uint32_t &commandBufferSize, uint32_t &requestedPatchListSize)
77 {
78     DECODE_CHK_STATUS(CalculateCommandBufferSize(commandBufferSize));
79     DECODE_CHK_STATUS(CalculatePatchListSize(requestedPatchListSize));
80     return MOS_STATUS_SUCCESS;
81 }
82 
CalculateCommandBufferSize(uint32_t & commandBufferSize)83 MOS_STATUS HevcDecodeLongPkt::CalculateCommandBufferSize(uint32_t &commandBufferSize)
84 {
85     // Just need consider picture level cmds for first level command buffer size,
86     // since the slice level cmds are located 2nd lvl batch buffer which is
87     // allocated by pipeline.
88     DECODE_CHK_STATUS(m_picturePkt->CalculateCommandSize(m_pictureStatesSize, m_picturePatchListSize));
89     commandBufferSize = m_pictureStatesSize + COMMAND_BUFFER_RESERVED_SPACE;
90     return MOS_STATUS_SUCCESS;
91 }
92 
CalculatePatchListSize(uint32_t & requestedPatchListSize)93 MOS_STATUS HevcDecodeLongPkt::CalculatePatchListSize(uint32_t &requestedPatchListSize)
94 {
95     if (!m_osInterface->bUsesPatchList)
96     {
97         requestedPatchListSize = 0;
98         return MOS_STATUS_SUCCESS;
99     }
100 
101     DECODE_CHK_STATUS(m_slicePkt->CalculateCommandSize(m_sliceStatesSize, m_slicePatchListSize));
102 
103     if (m_hevcPipeline->GetDecodeMode() == HevcPipeline::separateTileDecodeMode)
104     {
105         uint32_t tileNum = (1 + m_hevcBasicFeature->m_hevcPicParams->num_tile_rows_minus1) *
106                            (1 + m_hevcBasicFeature->m_hevcPicParams->num_tile_columns_minus1);
107         requestedPatchListSize = m_picturePatchListSize +
108                                  m_slicePatchListSize * (m_hevcBasicFeature->m_numSlices + tileNum);
109     }
110     else
111     {
112         requestedPatchListSize = m_picturePatchListSize +
113                                  (m_slicePatchListSize * (m_hevcBasicFeature->m_numSlices + 1));
114     }
115 
116     return MOS_STATUS_SUCCESS;
117 }
118 
119 }
120