1 /* 2 * Copyright (c) 2020-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_vp8_entropy_state.cpp 25 //! \brief Defines entropy state list related logic for vp8 decode 26 //! 27 28 #include "decode_utils.h" 29 #include "decode_vp8_entropy_state.h" 30 #include "codec_def_decode_vp8.h" 31 32 namespace decode 33 { DecodeFill()34 void Vp8EntropyState::DecodeFill() 35 { 36 int32_t shift = m_bdValueSize - 8 - (m_count + 8); 37 uint32_t bytesLeft = (uint32_t)(m_bufferEnd - m_buffer); 38 uint32_t bitsLeft = bytesLeft * CHAR_BIT; 39 int32_t num = (int32_t)(shift + CHAR_BIT - bitsLeft); 40 int32_t loopEnd = 0; 41 42 if (num >= 0) 43 { 44 m_count += m_lotsOfBits; 45 loopEnd = num; 46 } 47 48 if (num < 0 || bitsLeft) 49 { 50 while (shift >= loopEnd) 51 { 52 m_count += CHAR_BIT; 53 m_value |= (uint32_t)*m_buffer << shift; 54 ++m_buffer; 55 shift -= CHAR_BIT; 56 } 57 } 58 } 59 DecodeBool(int32_t probability)60 uint32_t Vp8EntropyState::DecodeBool(int32_t probability) 61 { 62 uint32_t split = 1 + (((m_range - 1) * probability) >> 8); 63 uint32_t bigSplit = (uint32_t)split << (m_bdValueSize - 8); 64 uint32_t origRange = m_range; 65 m_range = split; 66 67 uint32_t bit = 0; 68 if (m_value >= bigSplit) 69 { 70 m_range = origRange - split; 71 m_value = m_value - bigSplit; 72 bit = 1; 73 } 74 75 int32_t shift = Norm[m_range]; 76 m_range <<= shift; 77 m_value <<= shift; 78 m_count -= shift; 79 80 if (m_count < 0) 81 { 82 DecodeFill(); 83 } 84 85 return bit; 86 } 87 DecodeValue(int32_t bits)88 int32_t Vp8EntropyState::DecodeValue(int32_t bits) 89 { 90 int32_t retValue = 0; 91 92 for (int32_t iBit = bits - 1; iBit >= 0; iBit--) 93 { 94 retValue |= (DecodeBool(0x80) << iBit); 95 } 96 97 return retValue; 98 } 99 ParseFrameHeadInit()100 void Vp8EntropyState::ParseFrameHeadInit() 101 { 102 if (m_frameHead->iFrameType == m_keyFrame) 103 { 104 MOS_SecureMemcpy(m_frameHead->FrameContext.MvContext, sizeof(DefaultMvContext), DefaultMvContext, sizeof(DefaultMvContext)); 105 MOS_SecureMemcpy(m_frameHead->FrameContext.YModeProb, sizeof(KfYModeProb), KfYModeProb, sizeof(KfYModeProb)); 106 MOS_SecureMemcpy(m_frameHead->FrameContext.UVModeProb, sizeof(KfUVModeProb), KfUVModeProb, sizeof(KfUVModeProb)); 107 MOS_SecureMemcpy(m_frameHead->FrameContext.CoefProbs, sizeof(DefaultCoefProbs), DefaultCoefProbs, sizeof(DefaultCoefProbs)); 108 109 MOS_SecureMemcpy(m_frameHead->YModeProbs, sizeof(KfYModeProb), KfYModeProb, sizeof(KfYModeProb)); 110 MOS_SecureMemcpy(m_frameHead->UVModeProbs, sizeof(KfUVModeProb), KfUVModeProb, sizeof(KfUVModeProb)); 111 MOS_SecureMemcpy(m_frameHead->YModeProbs, sizeof(YModeProb), YModeProb, sizeof(YModeProb)); 112 MOS_SecureMemcpy(m_frameHead->UVModeProbs, sizeof(UVModeProb), UVModeProb, sizeof(UVModeProb)); 113 114 memset(m_frameHead->SegmentFeatureData, 0, sizeof(m_frameHead->SegmentFeatureData)); 115 m_frameHead->u8MbSegementAbsDelta = 0; 116 117 memset(m_frameHead->RefLFDeltas, 0, sizeof(m_frameHead->RefLFDeltas)); 118 memset(m_frameHead->ModeLFDeltas, 0, sizeof(m_frameHead->ModeLFDeltas)); 119 120 m_frameHead->iRefreshGoldenFrame = 1; 121 m_frameHead->iRefreshAltFrame = 1; 122 m_frameHead->iCopyBufferToGolden = 0; 123 m_frameHead->iCopyBufferToAlt = 0; 124 125 m_frameHead->iLastFrameBufferCurrIdx = m_frameHead->iNewFrameBufferIdx; 126 m_frameHead->iGoldenFrameBufferCurrIdx = m_frameHead->iNewFrameBufferIdx; 127 m_frameHead->iAltFrameBufferCurrIdx = m_frameHead->iNewFrameBufferIdx; 128 129 m_frameHead->RefFrameSignBias[VP8_GOLDEN_FRAME] = 0; 130 m_frameHead->RefFrameSignBias[VP8_ALTREF_FRAME] = 0; 131 } 132 } 133 StartEntropyDecode()134 int32_t Vp8EntropyState::StartEntropyDecode() 135 { 136 m_bufferEnd = m_dataBufferEnd; 137 m_buffer = m_dataBuffer; 138 m_value = 0; 139 m_count = -8; 140 m_range = 255; 141 142 if ((m_bufferEnd - m_buffer) > 0 && m_buffer == nullptr) 143 { 144 return 1; 145 } 146 147 DecodeFill(); 148 149 return 0; 150 } 151 SegmentationEnabled()152 void Vp8EntropyState::SegmentationEnabled() 153 { 154 m_frameHead->u8SegmentationEnabled = (uint8_t)DecodeBool(m_probHalf); 155 156 if (m_frameHead->u8SegmentationEnabled) 157 { 158 m_frameHead->u8UpdateMbSegmentationMap = (uint8_t)DecodeBool(m_probHalf); 159 m_frameHead->u8UpdateMbSegmentationData = (uint8_t)DecodeBool(m_probHalf); 160 161 if (m_frameHead->u8UpdateMbSegmentationData) 162 { 163 m_frameHead->u8MbSegementAbsDelta = (uint8_t)DecodeBool(m_probHalf); 164 165 memset(m_frameHead->SegmentFeatureData, 0, sizeof(m_frameHead->SegmentFeatureData)); 166 167 for (int32_t i = 0; i < VP8_MB_LVL_MAX; i++) 168 { 169 for (int32_t j = 0; j < VP8_MAX_MB_SEGMENTS; j++) 170 { 171 if (DecodeBool(m_probHalf)) 172 { 173 m_frameHead->SegmentFeatureData[i][j] = (int8_t)DecodeValue(MbFeatureDataBits[i]); 174 175 if (DecodeBool(m_probHalf)) 176 { 177 m_frameHead->SegmentFeatureData[i][j] = -m_frameHead->SegmentFeatureData[i][j]; 178 } 179 } 180 else 181 { 182 m_frameHead->SegmentFeatureData[i][j] = 0; 183 } 184 } 185 } 186 } 187 188 if (m_frameHead->u8UpdateMbSegmentationMap) 189 { 190 memset(m_frameHead->MbSegmentTreeProbs, 255, sizeof(m_frameHead->MbSegmentTreeProbs)); 191 192 for (int32_t i = 0; i < VP8_MB_SEGMENT_TREE_PROBS; i++) 193 { 194 if (DecodeBool(m_probHalf)) 195 { 196 m_frameHead->MbSegmentTreeProbs[i] = (uint8_t)DecodeValue(8); 197 } 198 } 199 } 200 } 201 else 202 { 203 m_frameHead->u8UpdateMbSegmentationMap = 0; 204 m_frameHead->u8UpdateMbSegmentationData = 0; 205 } 206 } 207 LoopFilterInit(int32_t defaultFilterLvl)208 void Vp8EntropyState::LoopFilterInit(int32_t defaultFilterLvl) 209 { 210 for (int32_t segmentNum = 0; segmentNum < VP8_MAX_MB_SEGMENTS; segmentNum++) 211 { 212 int32_t segmentLvl = defaultFilterLvl; 213 214 if (m_frameHead->u8SegmentationEnabled) 215 { 216 if (m_frameHead->u8MbSegementAbsDelta == 1) 217 { 218 m_frameHead->LoopFilterLevel[segmentNum] = segmentLvl = m_frameHead->SegmentFeatureData[VP8_MB_LVL_ALT_LF][segmentNum]; 219 } 220 else 221 { 222 segmentLvl += m_frameHead->SegmentFeatureData[VP8_MB_LVL_ALT_LF][segmentNum]; 223 m_frameHead->LoopFilterLevel[segmentNum] = segmentLvl = (segmentLvl > 0) ? ((segmentLvl > 63) ? 63 : segmentLvl) : 0; 224 } 225 } 226 } 227 } 228 LoopFilterEnabled()229 void Vp8EntropyState::LoopFilterEnabled() 230 { 231 m_frameHead->FilterType = (VP8_LF_TYPE)DecodeBool(m_probHalf); 232 m_frameHead->iFilterLevel = DecodeValue(6); 233 m_frameHead->iSharpnessLevel = DecodeValue(3); 234 235 m_frameHead->u8ModeRefLfDeltaUpdate = 0; 236 m_frameHead->u8ModeRefLfDeltaEnabled = (uint8_t)DecodeBool(m_probHalf); 237 238 if (m_frameHead->u8ModeRefLfDeltaEnabled) 239 { 240 m_frameHead->u8ModeRefLfDeltaUpdate = (uint8_t)DecodeBool(m_probHalf); 241 242 if (m_frameHead->u8ModeRefLfDeltaUpdate) 243 { 244 for (int32_t i = 0; i < VP8_MAX_REF_LF_DELTAS; i++) 245 { 246 if (DecodeBool(m_probHalf)) 247 { 248 m_frameHead->RefLFDeltas[i] = (int8_t)DecodeValue(6); 249 250 if (DecodeBool(m_probHalf)) 251 { 252 m_frameHead->RefLFDeltas[i] = m_frameHead->RefLFDeltas[i] * (-1); 253 } 254 } 255 } 256 257 for (int32_t i = 0; i < VP8_MAX_MODE_LF_DELTAS; i++) 258 { 259 if (DecodeBool(m_probHalf)) 260 { 261 m_frameHead->ModeLFDeltas[i] = (int8_t)DecodeValue(6); 262 263 if (DecodeBool(m_probHalf)) 264 { 265 m_frameHead->ModeLFDeltas[i] = m_frameHead->ModeLFDeltas[i] * (-1); 266 } 267 } 268 } 269 } 270 } 271 272 if (m_frameHead->iFilterLevel) 273 { 274 LoopFilterInit(m_frameHead->iFilterLevel); 275 } 276 } 277 GetDeltaQ(int32_t prevVal,int32_t * qupdate)278 int32_t Vp8EntropyState::GetDeltaQ(int32_t prevVal, int32_t *qupdate) 279 { 280 int32_t retVal = 0; 281 282 if (DecodeBool(m_probHalf)) 283 { 284 retVal = DecodeValue(4); 285 286 if (DecodeBool(m_probHalf)) 287 { 288 retVal = -retVal; 289 } 290 } 291 292 if (retVal != prevVal) 293 { 294 *qupdate = 1; 295 } 296 297 return retVal; 298 } 299 DcQuant(int32_t qindex,int32_t delta)300 int32_t Vp8EntropyState::DcQuant(int32_t qindex, int32_t delta) 301 { 302 int32_t retVal; 303 304 qindex = qindex + delta; 305 306 if (qindex > 127) 307 { 308 qindex = 127; 309 } 310 else if (qindex < 0) 311 { 312 qindex = 0; 313 } 314 315 retVal = DcQLookup[qindex]; 316 return retVal; 317 } 318 Dc2Quant(int32_t qindex,int32_t delta)319 int32_t Vp8EntropyState::Dc2Quant(int32_t qindex, int32_t delta) 320 { 321 int32_t retVal; 322 323 qindex = qindex + delta; 324 325 if (qindex > 127) 326 { 327 qindex = 127; 328 } 329 else if (qindex < 0) 330 { 331 qindex = 0; 332 } 333 334 retVal = DcQLookup[qindex] * 2; 335 return retVal; 336 } 337 DcUVQuant(int32_t qindex,int32_t delta)338 int32_t Vp8EntropyState::DcUVQuant(int32_t qindex, int32_t delta) 339 { 340 int32_t retVal; 341 342 qindex = qindex + delta; 343 344 if (qindex > 127) 345 { 346 qindex = 127; 347 } 348 else if (qindex < 0) 349 { 350 qindex = 0; 351 } 352 353 retVal = DcQLookup[qindex]; 354 355 if (retVal > 132) 356 { 357 retVal = 132; 358 } 359 360 return retVal; 361 } 362 AcYQuant(int32_t qindex)363 int32_t Vp8EntropyState::AcYQuant(int32_t qindex) 364 { 365 int32_t retVal; 366 367 if (qindex > 127) 368 { 369 qindex = 127; 370 } 371 else if (qindex < 0) 372 { 373 qindex = 0; 374 } 375 376 retVal = AcQLookup[qindex]; 377 return retVal; 378 } 379 Ac2Quant(int32_t qindex,int32_t delta)380 int32_t Vp8EntropyState::Ac2Quant(int32_t qindex, int32_t delta) 381 { 382 int32_t retVal; 383 384 qindex = qindex + delta; 385 386 if (qindex > 127) 387 { 388 qindex = 127; 389 } 390 else if (qindex < 0) 391 { 392 qindex = 0; 393 } 394 395 retVal = (AcQLookup[qindex] * 101581) >> 16; 396 397 if (retVal < 8) 398 { 399 retVal = 8; 400 } 401 402 return retVal; 403 } AcUVQuant(int32_t qindex,int32_t delta)404 int32_t Vp8EntropyState::AcUVQuant(int32_t qindex, int32_t delta) 405 { 406 int32_t retVal; 407 408 qindex = qindex + delta; 409 410 if (qindex > 127) 411 { 412 qindex = 127; 413 } 414 else if (qindex < 0) 415 { 416 qindex = 0; 417 } 418 419 retVal = AcQLookup[qindex]; 420 return retVal; 421 } 422 QuantInit()423 void Vp8EntropyState::QuantInit() 424 { 425 for (int32_t i = 0; i < VP8_Q_INDEX_RANGE; i++) 426 { 427 m_frameHead->Y1DeQuant[i][0] = (int16_t)DcQuant(i, m_frameHead->iY1DcDeltaQ); 428 m_frameHead->Y2DeQuant[i][0] = (int16_t)Dc2Quant(i, m_frameHead->iY2DcDeltaQ); 429 m_frameHead->UVDeQuant[i][0] = (int16_t)DcUVQuant(i, m_frameHead->iUVDcDeltaQ); 430 431 m_frameHead->Y1DeQuant[i][1] = (int16_t)AcYQuant(i); 432 m_frameHead->Y2DeQuant[i][1] = (int16_t)Ac2Quant(i, m_frameHead->iY2AcDeltaQ); 433 m_frameHead->UVDeQuant[i][1] = (int16_t)AcUVQuant(i, m_frameHead->iUVAcDeltaQ); 434 } 435 } 436 QuantSetup()437 void Vp8EntropyState::QuantSetup() 438 { 439 int32_t qupdate = 0; 440 441 m_frameHead->iBaseQIndex = DecodeValue(7); 442 m_frameHead->iY1DcDeltaQ = GetDeltaQ(m_frameHead->iY1DcDeltaQ, &qupdate); 443 m_frameHead->iY2DcDeltaQ = GetDeltaQ(m_frameHead->iY2DcDeltaQ, &qupdate); 444 m_frameHead->iY2AcDeltaQ = GetDeltaQ(m_frameHead->iY2AcDeltaQ, &qupdate); 445 m_frameHead->iUVDcDeltaQ = GetDeltaQ(m_frameHead->iUVDcDeltaQ, &qupdate); 446 m_frameHead->iUVAcDeltaQ = GetDeltaQ(m_frameHead->iUVAcDeltaQ, &qupdate); 447 448 if (qupdate) 449 { 450 QuantInit(); 451 } 452 } 453 ReadMvContexts(MV_CONTEXT * mvContext)454 void Vp8EntropyState::ReadMvContexts(MV_CONTEXT *mvContext) 455 { 456 int32_t i = 0; 457 458 do 459 { 460 const uint8_t *upProb = MvUpdateProbs[i].MvProb; 461 uint8_t *prob = (uint8_t *)(mvContext + i); 462 uint8_t *const stopProb = prob + 19; 463 464 do 465 { 466 if (DecodeBool(*upProb++)) 467 { 468 const uint8_t x = (uint8_t)DecodeValue(7); 469 470 *prob = x ? x << 1 : 1; 471 } 472 } while (++prob < stopProb); 473 474 } while (++i < 2); 475 } 476 ParseFrameHead(PCODEC_VP8_PIC_PARAMS vp8PicParams)477 MOS_STATUS Vp8EntropyState::ParseFrameHead(PCODEC_VP8_PIC_PARAMS vp8PicParams) 478 { 479 MOS_STATUS eStatus = MOS_STATUS_SUCCESS; 480 481 ParseFrameHeadInit(); 482 483 StartEntropyDecode(); 484 485 if (m_frameHead->iFrameType == m_keyFrame) 486 { 487 DecodeBool(m_probHalf); // Color Space 488 DecodeBool(m_probHalf); // Clamp Type 489 } 490 491 SegmentationEnabled(); 492 493 LoopFilterEnabled(); 494 495 m_frameHead->MultiTokenPartition = (VP8_TOKEN_PARTITION)DecodeValue(2); 496 497 if (!m_frameHead->bNotFirstCall) 498 { 499 QuantInit(); 500 } 501 502 QuantSetup(); 503 504 if (m_frameHead->iFrameType != m_keyFrame) 505 { 506 m_frameHead->iRefreshGoldenFrame = DecodeBool(m_probHalf); 507 508 m_frameHead->iRefreshAltFrame = DecodeBool(m_probHalf); 509 510 m_frameHead->iCopyBufferToGolden = 0; 511 512 if (!m_frameHead->iRefreshGoldenFrame) 513 { 514 m_frameHead->iCopyBufferToGolden = DecodeValue(2); 515 } 516 517 m_frameHead->iCopyBufferToAlt = 0; 518 519 if (!m_frameHead->iRefreshAltFrame) 520 { 521 m_frameHead->iCopyBufferToAlt = DecodeValue(2); 522 } 523 524 m_frameHead->RefFrameSignBias[VP8_GOLDEN_FRAME] = DecodeBool(m_probHalf); 525 m_frameHead->RefFrameSignBias[VP8_ALTREF_FRAME] = DecodeBool(m_probHalf); 526 } 527 528 if (m_frameHead->bNotFirstCall && m_frameHead->iRefreshEntropyProbs == 0) 529 { 530 MOS_SecureMemcpy(&m_frameHead->FrameContext, sizeof(m_frameHead->FrameContext), &m_frameHead->LastFrameContext, sizeof(m_frameHead->LastFrameContext)); 531 } 532 533 m_frameHead->iRefreshEntropyProbs = DecodeBool(m_probHalf); 534 535 if (m_frameHead->iRefreshEntropyProbs == 0) 536 { 537 MOS_SecureMemcpy(&m_frameHead->LastFrameContext, sizeof(m_frameHead->LastFrameContext), &m_frameHead->FrameContext, sizeof(m_frameHead->FrameContext)); 538 } 539 540 if (m_frameHead->iFrameType == m_keyFrame || DecodeBool(m_probHalf)) 541 { 542 m_frameHead->iRefreshLastFrame = true; 543 } 544 else 545 { 546 m_frameHead->iRefreshLastFrame = false; 547 } 548 549 for (int32_t i = 0; i < VP8_BLOCK_TYPES; i++) 550 for (int32_t j = 0; j < VP8_COEF_BANDS; j++) 551 for (int32_t k = 0; k < VP8_PREV_COEF_CONTEXTS; k++) 552 for (int32_t l = 0; l < VP8_ENTROPY_NODES; l++) 553 { 554 uint8_t *const p = m_frameHead->FrameContext.CoefProbs[i][j][k] + l; 555 556 if (DecodeBool(CoefUpdateProbs[i][j][k][l])) 557 { 558 *p = (uint8_t)DecodeValue(8); 559 } 560 } 561 562 m_frameHead->iMbNoCoeffSkip = (int32_t)DecodeBool(m_probHalf); 563 m_frameHead->iProbSkipFalse = 0; 564 if (m_frameHead->iMbNoCoeffSkip) 565 { 566 m_frameHead->iProbSkipFalse = (uint8_t)DecodeValue(8); 567 } 568 569 if (m_frameHead->iFrameType != m_keyFrame) 570 { 571 m_frameHead->ProbIntra = (uint8_t)DecodeValue(8); 572 m_frameHead->ProbLast = (uint8_t)DecodeValue(8); 573 m_frameHead->ProbGf = (uint8_t)DecodeValue(8); 574 575 if (DecodeBool(m_probHalf)) 576 { 577 int32_t i = 0; 578 579 do 580 { 581 m_frameHead->YModeProbs[i] = m_frameHead->FrameContext.YModeProb[i] = 582 (uint8_t)DecodeValue(8); 583 } while (++i < 4); 584 } 585 586 if (DecodeBool(m_probHalf)) 587 { 588 int32_t i = 0; 589 590 do 591 { 592 m_frameHead->UVModeProbs[i] = m_frameHead->FrameContext.UVModeProb[i] = 593 (uint8_t)DecodeValue(8); 594 } while (++i < 3); 595 } 596 597 MV_CONTEXT MVContext[2]; 598 for (int32_t i = 0; i < 2; i++) 599 { 600 for (int32_t j = 0; j < 19; j++) 601 { 602 MVContext[i].MvProb[j] = vp8PicParams->ucMvUpdateProb[i][j]; 603 } 604 } 605 606 ReadMvContexts(MVContext); 607 } 608 609 vp8PicParams->ucP0EntropyCount = 8 - (m_count & 0x07); 610 vp8PicParams->ucP0EntropyValue = (uint8_t)(m_value >> 24); 611 vp8PicParams->uiP0EntropyRange = m_range; 612 613 uint32_t firstPartitionAndUncompSize; 614 if (m_frameHead->iFrameType == m_keyFrame) 615 { 616 firstPartitionAndUncompSize = vp8PicParams->uiFirstPartitionSize + 10; 617 } 618 else 619 { 620 firstPartitionAndUncompSize = vp8PicParams->uiFirstPartitionSize + 3; 621 } 622 623 // Partition Size 624 uint32_t partitionNum = 1 << m_frameHead->MultiTokenPartition; 625 uint32_t partitionSizeSum = 0; 626 m_dataBuffer = m_bitstreamBuffer + firstPartitionAndUncompSize; 627 if (partitionNum > 1) 628 { 629 for (int32_t i = 1; i < (int32_t)partitionNum; i++) 630 { 631 vp8PicParams->uiPartitionSize[i] = m_dataBuffer[0] + (m_dataBuffer[1] << 8) + (m_dataBuffer[2] << 16); 632 m_dataBuffer += 3; 633 partitionSizeSum += vp8PicParams->uiPartitionSize[i]; 634 } 635 } 636 637 uint32_t offsetCounter = ((m_count & 0x18) >> 3) + (((m_count & 0x07) != 0) ? 1 : 0); 638 vp8PicParams->uiFirstMbByteOffset = (uint32_t)(m_buffer - m_bitstreamBuffer) - offsetCounter; 639 vp8PicParams->uiPartitionSize[0] = firstPartitionAndUncompSize - (uint32_t)(m_buffer - m_bitstreamBuffer) + offsetCounter; 640 vp8PicParams->uiPartitionSize[partitionNum] = m_bitstreamBufferSize - firstPartitionAndUncompSize - (partitionNum - 1) * 3 - partitionSizeSum; 641 642 return eStatus; 643 } 644 FrameHeadQuantUpdate(PCODEC_VP8_PIC_PARAMS vp8PicParams)645 void Vp8EntropyState::FrameHeadQuantUpdate( 646 PCODEC_VP8_PIC_PARAMS vp8PicParams) 647 { 648 for (int32_t i = 0; i < VP8_Q_INDEX_RANGE; i++) 649 { 650 m_frameHead->Y1DeQuant[i][0] = (int16_t)DcQuant(i, vp8PicParams->cY1DcDeltaQ); 651 m_frameHead->Y2DeQuant[i][0] = (int16_t)Dc2Quant(i, vp8PicParams->cY2DcDeltaQ); 652 m_frameHead->UVDeQuant[i][0] = (int16_t)DcUVQuant(i, vp8PicParams->cUVDcDeltaQ); 653 654 m_frameHead->Y1DeQuant[i][1] = (int16_t)AcYQuant(i); 655 m_frameHead->Y2DeQuant[i][1] = (int16_t)Ac2Quant(i, vp8PicParams->cY2AcDeltaQ); 656 m_frameHead->UVDeQuant[i][1] = (int16_t)AcUVQuant(i, vp8PicParams->cUVAcDeltaQ); 657 } 658 } 659 Initialize(PCODECHAL_DECODE_VP8_FRAME_HEAD vp8FrameHeadIn,uint8_t * bitstreamBufferIn,uint32_t bitstreamBufferSizeIn)660 void Vp8EntropyState::Initialize( 661 PCODECHAL_DECODE_VP8_FRAME_HEAD vp8FrameHeadIn, 662 uint8_t* bitstreamBufferIn, 663 uint32_t bitstreamBufferSizeIn) 664 { 665 m_frameHead = vp8FrameHeadIn; 666 m_dataBuffer = bitstreamBufferIn; 667 m_dataBufferEnd = bitstreamBufferIn + bitstreamBufferSizeIn; 668 m_bitstreamBuffer = bitstreamBufferIn; 669 m_bitstreamBufferSize = bitstreamBufferSizeIn; 670 671 m_frameHead->iFrameType = m_dataBuffer[0] & 1; 672 m_frameHead->iVersion = (m_dataBuffer[0] >> 1) & 7; 673 m_frameHead->iShowframe = (m_dataBuffer[0] >> 4) & 1; 674 m_frameHead->uiFirstPartitionLengthInBytes = (m_dataBuffer[0] | (m_dataBuffer[1] << 8) | (m_dataBuffer[2] << 16)) >> 5; 675 676 m_dataBuffer += 3; 677 678 if (m_frameHead->iFrameType == m_keyFrame) 679 { 680 m_dataBuffer += 7; 681 } 682 } 683 } // namespace decode 684