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 //!
24 //! \file decode_input_bitstream_m12.cpp
25 //! \brief Defines the common interface for decode input bitstream
26 //! \details Defines the interface to handle the decode input bitstream in
27 //! both single execution call mode and multiple excution call mode.
28 //!
29 #include "decode_input_bitstream_m12.h"
30 #include "decode_basic_feature.h"
31 #include "decode_pipeline.h"
32 #include "decode_huc_packet_creator_g12.h"
33
34 namespace decode {
35
DecodeInputBitstreamM12(DecodePipeline * pipeline,MediaTask * task,uint8_t numVdbox,CodechalHwInterface * hwInterface)36 DecodeInputBitstreamM12::DecodeInputBitstreamM12(DecodePipeline *pipeline, MediaTask *task, uint8_t numVdbox, CodechalHwInterface *hwInterface)
37 : DecodeInputBitstream(pipeline, task, numVdbox)
38 {
39 m_hwInterface = hwInterface;
40 }
41
Init(CodechalSetting & settings)42 MOS_STATUS DecodeInputBitstreamM12::Init(CodechalSetting& settings)
43 {
44 DECODE_CHK_NULL(m_pipeline);
45
46 DECODE_CHK_NULL(m_hwInterface);
47 PMOS_INTERFACE osInterface = m_hwInterface->GetOsInterface();
48 DECODE_CHK_NULL(osInterface);
49 InitScalabilityPars(osInterface);
50
51 m_allocator = m_pipeline->GetDecodeAllocator();
52 DECODE_CHK_NULL(m_allocator);
53
54 MediaFeatureManager* featureManager = m_pipeline->GetFeatureManager();
55 DECODE_CHK_NULL(featureManager);
56 m_basicFeature = dynamic_cast<DecodeBasicFeature*>(featureManager->GetFeature(FeatureIDs::basicFeature));
57 DECODE_CHK_NULL(m_basicFeature);
58
59 HucPacketCreatorG12 *hucPktCreator = dynamic_cast<HucPacketCreatorG12 *>(m_pipeline);
60 DECODE_CHK_NULL(hucPktCreator);
61 m_concatPkt = hucPktCreator->CreateHucCopyPkt(m_pipeline, m_task, m_hwInterface);
62 DECODE_CHK_NULL(m_concatPkt);
63 MediaPacket *packet = dynamic_cast<MediaPacket *>(m_concatPkt);
64 DECODE_CHK_NULL(packet);
65 DECODE_CHK_STATUS(RegisterPacket(DecodePacketId(m_pipeline, hucCopyPacketId), *packet));
66 DECODE_CHK_STATUS(packet->Init());
67
68 return MOS_STATUS_SUCCESS;
69 }
70
DecodeJpegInputBitstreamM12(DecodePipeline * pipeline,MediaTask * task,uint8_t numVdbox,CodechalHwInterface * hwInterface)71 DecodeJpegInputBitstreamM12::DecodeJpegInputBitstreamM12(DecodePipeline *pipeline, MediaTask *task, uint8_t numVdbox, CodechalHwInterface *hwInterface)
72 : DecodeInputBitstreamM12(pipeline, task, numVdbox, hwInterface)
73 {
74 }
75
Init(CodechalSetting & settings)76 MOS_STATUS DecodeJpegInputBitstreamM12::Init(CodechalSetting &settings)
77 {
78 DecodeInputBitstreamM12::Init(settings);
79
80 m_jpegBasicFeature = dynamic_cast<JpegBasicFeature *>(m_basicFeature);
81 DECODE_CHK_NULL(m_jpegBasicFeature);
82 return MOS_STATUS_SUCCESS;
83 }
84
85
IsComplete()86 bool DecodeJpegInputBitstreamM12::IsComplete()
87 {
88 return m_completeBitStream && m_completeJpegScan;
89 }
90
Append(const CodechalDecodeParams & decodeParams)91 MOS_STATUS DecodeJpegInputBitstreamM12::Append(const CodechalDecodeParams &decodeParams)
92 {
93 bool firstExecuteCall = (decodeParams.m_executeCallIndex == 0);
94 auto numScans = m_jpegBasicFeature->m_jpegScanParams->NumScans;
95 auto totalScans = m_jpegBasicFeature->m_jpegPicParams->m_totalScans;
96 uint32_t maxBufferSize = MOS_ALIGN_CEIL(m_jpegBasicFeature->m_jpegPicParams->m_frameWidth * m_jpegBasicFeature->m_jpegPicParams->m_frameHeight * 3, 64);
97 uint32_t segmentSize = decodeParams.m_dataSize;
98 if (firstExecuteCall)
99 {
100 auto headerSize = m_jpegBasicFeature->m_jpegScanParams->ScanHeader[numScans - 1].DataOffset +
101 m_jpegBasicFeature->m_jpegScanParams->ScanHeader[numScans - 1].DataLength;
102
103 if (numScans >= totalScans && segmentSize >= headerSize) // Bitstream complete and scan complete
104 {
105 m_completeBitStream = true;
106 m_completeJpegScan = true;
107 }
108 else if (numScans < totalScans && segmentSize > headerSize) // Bitstream complete and scan incomplete
109 {
110 m_completeBitStream = true;
111 m_completeJpegScan = false;
112 }
113 else if (numScans >= totalScans && segmentSize < headerSize) //Bitstream incomplete and scan complete, should catenate bitstream
114 {
115 m_completeBitStream = false;
116 m_completeJpegScan = true;
117 m_requiredSize = maxBufferSize;
118
119 //Allocate Buffer
120 DECODE_CHK_STATUS(AllocateCatenatedBuffer());
121 m_basicFeature->m_resDataBuffer = *m_catenatedBuffer;
122 m_basicFeature->m_dataOffset = 0;
123 DECODE_CHK_STATUS(ActivatePacket(DecodePacketId(m_pipeline, hucCopyPacketId), true, 0, 0));
124 AddNewSegment(*(decodeParams.m_dataBuffer), decodeParams.m_dataOffset, decodeParams.m_dataSize);
125 }
126 else
127 {
128 return MOS_STATUS_INVALID_PARAMETER;
129 }
130 }
131 else
132 {
133 if (m_completeBitStream) // Bitstream complete and scan incomplete, wait scan complete
134 {
135 m_completeJpegScan = (numScans >= totalScans);
136 }
137 else //Bitstream incomplete and scan complete, should catenate bitstream
138 {
139 if (m_segmentsTotalSize + segmentSize > m_requiredSize)
140 {
141 DECODE_ASSERTMESSAGE("Bitstream size exceeds allocated buffer size!");
142 return MOS_STATUS_INVALID_PARAMETER;
143 }
144 DECODE_CHK_STATUS(ActivatePacket(DecodePacketId(m_pipeline, hucCopyPacketId), true, 0, 0));
145 AddNewSegment(*(decodeParams.m_dataBuffer), decodeParams.m_dataOffset, decodeParams.m_dataSize);
146
147 uint32_t totalSize = m_jpegBasicFeature->m_jpegScanParams->ScanHeader[totalScans - 1].DataOffset +
148 m_jpegBasicFeature->m_jpegScanParams->ScanHeader[totalScans - 1].DataLength;
149 if (m_segmentsTotalSize + segmentSize >= totalSize)
150 {
151 m_completeBitStream = true;
152 }
153 }
154 }
155 m_segmentsTotalSize += MOS_ALIGN_CEIL(segmentSize, MHW_CACHELINE_SIZE);
156 return MOS_STATUS_SUCCESS;
157 }
158
159 }
160