1 /* 2 * Copyright (c) 2020-2021, 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_vp8_reference_frames.cpp 24 //! \brief Defines reference list related logic for vp8 decode 25 //! 26 27 #include "decode_vp8_basic_feature.h" 28 #include "decode_utils.h" 29 #include "decode_vp8_reference_frames.h" 30 #include "codec_def_decode_vp8.h" 31 32 namespace decode 33 { Vp8ReferenceFrames()34 Vp8ReferenceFrames::Vp8ReferenceFrames() 35 { 36 memset(m_vp8RefList, 0, sizeof(m_vp8RefList)); 37 } 38 Init(Vp8BasicFeature * basicFeature,DecodeAllocator & allocator)39 MOS_STATUS Vp8ReferenceFrames::Init(Vp8BasicFeature *basicFeature, DecodeAllocator& allocator) 40 { 41 DECODE_FUNC_CALL(); 42 43 DECODE_CHK_NULL(basicFeature); 44 m_basicFeature = basicFeature; 45 m_allocator = &allocator; 46 DECODE_CHK_NULL(m_allocator); 47 DECODE_CHK_STATUS(AllocateDataList(m_vp8RefList, CODECHAL_NUM_UNCOMPRESSED_SURFACE_VP8)); // CODECHAL_NUM_UNCOMPRESSED_SURFACE_VP8 128 48 49 return MOS_STATUS_SUCCESS; 50 } 51 ~Vp8ReferenceFrames()52 Vp8ReferenceFrames::~Vp8ReferenceFrames() 53 { 54 DECODE_FUNC_CALL(); 55 56 FreeDataList(m_vp8RefList, CODECHAL_NUM_UNCOMPRESSED_SURFACE_VP8); 57 m_activeReferenceList.clear(); 58 } 59 UpdatePicture(CODEC_VP8_PIC_PARAMS & picParams)60 MOS_STATUS Vp8ReferenceFrames::UpdatePicture(CODEC_VP8_PIC_PARAMS &picParams) 61 { 62 DECODE_FUNC_CALL(); 63 64 DECODE_CHK_STATUS(UpdateCurFrame(picParams)); 65 66 // Override reference list with ref surface passed from DDI if needed 67 uint8_t surfCount = 0; 68 uint8_t surfIndex = 0; 69 while (surfCount < m_basicFeature->m_refSurfaceNum && surfIndex < CODECHAL_NUM_UNCOMPRESSED_SURFACE_VP8) 70 { 71 if (!m_allocator->ResourceIsNull(&m_basicFeature->m_refFrameSurface[surfIndex].OsResource)) 72 { 73 m_vp8RefList[surfIndex]->resRefPic = m_basicFeature->m_refFrameSurface[surfIndex].OsResource; 74 surfCount++; 75 } 76 surfIndex++; 77 } 78 79 if (picParams.key_frame) // reference surface should be nullptr when key_frame == true 80 { 81 m_basicFeature->m_LastRefSurface = nullptr; 82 m_basicFeature->m_GoldenRefSurface = nullptr; 83 m_basicFeature->m_AltRefSurface = nullptr; 84 } 85 else 86 { 87 if((Mos_ResourceIsNull(&m_vp8RefList[picParams.ucLastRefPicIndex]->resRefPic)) && (m_basicFeature->m_LastRefSurface)) 88 { 89 m_vp8RefList[picParams.ucLastRefPicIndex]->resRefPic = *(m_basicFeature->m_LastRefSurface); 90 } 91 else 92 { 93 m_basicFeature->m_LastRefSurface = &(m_vp8RefList[picParams.ucLastRefPicIndex]->resRefPic); 94 } 95 if((Mos_ResourceIsNull(&m_vp8RefList[picParams.ucGoldenRefPicIndex]->resRefPic)) && (m_basicFeature->m_GoldenRefSurface)) 96 { 97 m_vp8RefList[picParams.ucGoldenRefPicIndex]->resRefPic = *(m_basicFeature->m_GoldenRefSurface); 98 } 99 else 100 { 101 m_basicFeature->m_GoldenRefSurface = &(m_vp8RefList[picParams.ucGoldenRefPicIndex]->resRefPic); 102 } 103 if((Mos_ResourceIsNull(&m_vp8RefList[picParams.ucAltRefPicIndex]->resRefPic)) && (m_basicFeature->m_AltRefSurface)) 104 { 105 m_vp8RefList[picParams.ucAltRefPicIndex]->resRefPic = *(m_basicFeature->m_AltRefSurface); 106 } 107 else 108 { 109 m_basicFeature->m_AltRefSurface = &(m_vp8RefList[picParams.ucAltRefPicIndex]->resRefPic); 110 } 111 } 112 return MOS_STATUS_SUCCESS; 113 } 114 UpdateCurFrame(const CODEC_VP8_PIC_PARAMS & picParams)115 MOS_STATUS Vp8ReferenceFrames::UpdateCurFrame(const CODEC_VP8_PIC_PARAMS &picParams) 116 { 117 DECODE_FUNC_CALL(); 118 119 DECODE_CHK_COND(picParams.CurrPic.FrameIdx >= CODECHAL_NUM_UNCOMPRESSED_SURFACE_VP8, 120 "Invalid frame index of current frame"); 121 122 m_currRefList = m_vp8RefList[picParams.CurrPic.FrameIdx]; 123 124 m_currRefList->RefPic = picParams.CurrPic; 125 m_currRefList->resRefPic = m_basicFeature->m_destSurface.OsResource; 126 127 return MOS_STATUS_SUCCESS; 128 } 129 130 } // namespace decode 131