1 // Copyright (c) 2020 Intel Corporation 2 // 3 // Permission is hereby granted, free of charge, to any person obtaining a copy 4 // of this software and associated documentation files (the "Software"), to deal 5 // in the Software without restriction, including without limitation the rights 6 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 // copies of the Software, and to permit persons to whom the Software is 8 // furnished to do so, subject to the following conditions: 9 // 10 // The above copyright notice and this permission notice shall be included in all 11 // copies or substantial portions of the Software. 12 // 13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 // SOFTWARE. 20 21 #pragma once 22 23 #include <vector> 24 #include "mfx_common.h" 25 26 #ifndef MFX_ENABLE_MCTF_EXT 27 // all internal logic is based on these constants 28 // if they are not defined, the logic of all checks, 29 // switches & branches gets too complicated (as modes are 30 // exist in MCTF and it is needed to somehow introduce them. 31 enum { 32 MCTF_TEMPORAL_MODE_UNKNOWN = 0, 33 MCTF_TEMPORAL_MODE_SPATIAL = 1, 34 MCTF_TEMPORAL_MODE_1REF = 2, 35 MCTF_TEMPORAL_MODE_2REF = 3, 36 MCTF_TEMPORAL_MODE_4REF = 4 37 }; 38 #else 39 enum { 40 MCTF_TEMPORAL_MODE_UNKNOWN = MFX_MCTF_TEMPORAL_MODE_UNKNOWN, 41 MCTF_TEMPORAL_MODE_SPATIAL = MFX_MCTF_TEMPORAL_MODE_SPATIAL, 42 MCTF_TEMPORAL_MODE_1REF = MFX_MCTF_TEMPORAL_MODE_1REF, 43 MCTF_TEMPORAL_MODE_2REF = MFX_MCTF_TEMPORAL_MODE_2REF, 44 MCTF_TEMPORAL_MODE_4REF = MFX_MCTF_TEMPORAL_MODE_4REF 45 }; 46 #endif 47 48 // this is an internal structure to represent MCTF controls; 49 // is not exposed outside; 50 typedef struct { 51 mfxU16 Overlap; 52 mfxU16 Deblocking; 53 mfxU16 TemporalMode; 54 mfxU16 subPelPrecision; 55 mfxU16 FilterStrength; // [0...20] 56 mfxU32 BitsPerPixelx100k; 57 mfxU16 reserved[6]; 58 } IntMctfParams; 59 60 // multiplier to translate float bpp -->fixed-integer 61 enum { MCTF_BITRATE_MULTIPLIER = 100000 }; 62 63 // this macro enables updates of runtime params at each frame 64 #undef MCTF_UPDATE_RTPARAMS_ON_EACH_FRAME 65 66 // MCTF models adopts for x264 or h265 following by MCTF 67 //#define MCTF_MODEL_FOR_x264_OR_x265 68 69 // MCTF models adopts for MSDK following by MCTF 70 #define MCTF_MODEL_FOR_MSDK 71 72 //#define MFX_MCTF_DEBUG_PRINT 73 #include <memory> 74 #include "cmrt_cross_platform.h" 75 #include "../../../vpp/include/mfx_vpp_defs.h" 76 #include "libmfx_core_interface.h" 77 #include "asc.h" 78 79 #include <cassert> 80 #define CHROMABASE 80 81 #define MAXCHROMA 100 82 #define MCTFSTRENGTH 3 83 #define MCTFNOFILTER 0 84 #define MCTFADAPTIVE 21 85 #define MCTFADAPTIVEVAL 1050 86 #define MCTF_CHROMAOFF 0 87 88 #ifndef __MFXDEFS_H__ 89 typedef char mfxI8; 90 typedef char int8_t; 91 typedef unsigned char mfxU8; 92 typedef unsigned char uint8_t; 93 typedef short mfxI16; 94 typedef short int16_t; 95 typedef unsigned short mfxU16; 96 typedef unsigned short uint16_t; 97 typedef int mfxI32; 98 typedef int int32_t; 99 typedef unsigned int mfxU32; 100 typedef unsigned int uint32_t; 101 typedef __int64 mfxI64; 102 typedef __int64 long long; 103 typedef unsigned __int64 mfxU64; 104 typedef unsigned __int64 unsigned long long; 105 typedef double mfx64F; 106 typedef double double; 107 typedef float mfx32F; 108 typedef float float; 109 110 typedef struct { 111 mfxI16 112 x, 113 y; 114 } mfxI16Pair; 115 #endif //__MFXDEFS_H__ 116 117 typedef struct { 118 mfxU16 119 x, 120 y; 121 } mfxU16Pair; 122 typedef struct { 123 mfxU8 124 scn1, 125 scn2, 126 scn3, 127 scn4; 128 } mfxU8quad; 129 130 131 #define MAX(a, b) (((a) > (b)) ? (a) : (b)) 132 #define MIN(a, b) (((a) < (b)) ? (a) : (b)) 133 #define ABS(a) (((a) < 0) ? (-(a)) : (a)) 134 135 #define MCTF_CHECK_CM_ERR(STS, ERR) if ((STS) != CM_SUCCESS) { ASC_PRINTF("FAILED at file: %s, line: %d, cmerr: %d\n", __FILE__, __LINE__, STS); return ERR; } 136 137 #define CHECK_ERR(ERR) if ((ERR) != PASSED) { ASC_PRINTF("FAILED at file: %s, line: %d\n", __FILE__, __LINE__); return (ERR); } 138 #define DIVUP(a, b) ((a+b-1)/b) 139 #define ROUNDUP(a, b) DIVUP(a,b)*b 140 141 #define BORDER 4 142 #define SUBMREDIM 4 143 #define WIDTHB (WIDTH + BORDER*2) 144 #define HEIGHTB (HEIGHT + BORDER*2) 145 146 #define CROP_BLOCK_ALIGNMENT 16 147 #define VMEBLSIZE 16 148 #define TEST_MAIN 1 149 #define MINHEIGHT 120 //it determines which picture size will use 8x8 or 16x16 blocks, smaller than this 8x8, bigger 16x16. 150 151 enum 152 { 153 PASSED, 154 FAILED 155 }; 156 enum 157 { 158 AMCTF_NOT_READY, 159 AMCTF_READY 160 }; 161 typedef enum AMCTF_OP_MODE 162 { 163 SEPARATE_REG_OP, 164 OVERLAP_REG_OP, 165 SEPARATE_ADA_OP, 166 OVERLAP_ADA_OP 167 }AMCTF_OMODE; 168 169 typedef enum _OFFSET_OV_MODE 170 { 171 NO_OVERLAP_OFFSET = 0, 172 OVERLAP_OFFSET = 2 173 }OFFSET_OV_MODE; 174 175 typedef enum _DENOISER_RUN_TYPE 176 { 177 DEN_CLOSE_RUN, 178 DEN_FAR_RUN 179 }DRT; 180 181 typedef enum _NUMBER_OF_REFERENCES 182 { 183 NO_REFERENCES, 184 ONE_REFERENCE, 185 TWO_REFERENCES, 186 THREE_REFERENCES, 187 FOUR_REFERENCES 188 }NUOR; 189 190 enum class MCTF_MODE 191 { 192 MCTF_MANUAL_MODE, // MCTF operates based on filter-strength passed by application 193 MCTF_AUTO_MODE, // MCTF automatically ajusts filter-strength and uses noise-estimations 194 MCTF_NOT_INITIALIZED_MODE 195 }; 196 197 enum class MCTF_CONFIGURATION 198 { 199 MCTF_MAN_NCA_NBA, // Manual, not Content-adaptive, not bitrate-adaptive 200 MCTF_AUT_CA_NBA, // Auto (noise-estimator is used), content-adaptive, not bitrate-adaptive 201 MCTF_AUT_NCA_NBA, // Auto (noise-estimator is used), not Content - adaptive, not bitrate - adaptive 202 MCTF_AUT_CA_BA, // Auto (noise-estimator is used), Content - adaptive, bitrate - adaptive 203 MCTF_NOT_CONFIGURED // not configured yet 204 }; 205 206 typedef enum _SUBPELPRECISION 207 { 208 INTEGER_PEL, 209 QUARTER_PEL 210 }SPP; 211 212 struct VmeSearchPath // sizeof=58 213 { 214 mfxU8 sp[56]; 215 mfxU8 maxNumSu; 216 mfxU8 lenSp; 217 }; 218 219 struct spatialNoiseAnalysis 220 { 221 mfxF32 222 var; 223 mfxF32 224 SCpp; 225 }; 226 227 struct MeControlSmall // sizeof=96 228 { 229 VmeSearchPath searchPath; 230 mfxU8 reserved[2]; 231 mfxU16 width; 232 mfxU16 height; 233 mfxU16 th; 234 mfxU16 mre_width; 235 mfxU16 mre_height; 236 mfxU16 sTh; 237 mfxU16 subPrecision; 238 mfxU16 CropX; 239 mfxU16 CropY; 240 mfxU16 CropW; 241 mfxU16 CropH; 242 mfxU8 reserved2[14]; 243 }; 244 static_assert(sizeof(MeControlSmall) == 96,"size of MeControlSmall != 96"); 245 struct frameData 246 { 247 std::vector<mfxU8> 248 *frame; 249 mfxU8 250 scene_number; 251 }; 252 253 struct gpuFrameData 254 { 255 CmSurface2D 256 * frameData, 257 *fOut; 258 SurfaceIndex 259 * fIdx, 260 * fIdxOut; 261 mfxFrameSurface1 262 * mfxFrame; 263 CmSurface2D 264 * magData; 265 SurfaceIndex 266 * idxMag; 267 mfxU8 268 sc, 269 tc, 270 stc; 271 mfxU32 272 scene_idx, 273 frame_number, 274 frame_relative_position, 275 noise_count; 276 mfxU16 277 filterStrength; 278 mfxF64 279 noise_var, 280 noise_sad, 281 noise_sc, 282 frame_sad, 283 frame_sc, 284 frame_Rs, 285 frame_Cs; 286 bool 287 frame_added, 288 isSceneChange, 289 isIntra; 290 IntMctfParams 291 mfxMctfControl; gpuFrameDatagpuFrameData292 gpuFrameData() : 293 frameData(0) 294 , fOut(0) 295 , fIdx(0) 296 , fIdxOut(0) 297 , mfxFrame(0) 298 , magData(0) 299 , idxMag(0) 300 , sc(0) 301 , tc(0) 302 , stc(0) 303 , scene_idx(0xffffffff) 304 , frame_number(0) 305 , frame_relative_position(0) 306 , noise_count(0) 307 , filterStrength(MCTFNOFILTER) 308 , noise_var(0.0) 309 , noise_sad(0.0) 310 , noise_sc(0.0) 311 , frame_sad(0.0) 312 , frame_sc(0.0) 313 , frame_Rs(0.0) 314 , frame_Cs(0.0) 315 , frame_added(false) 316 , isSceneChange(false) 317 , isIntra(false) 318 , mfxMctfControl(IntMctfParams{}) 319 { 320 } 321 }; 322 323 ////////////////////////////////////////////////////////// 324 // Defines and Constants 325 ////////////////////////////////////////////////////////// 326 #define MCTFSEARCHPATHSIZE 56 327 328 typedef struct _MulSurfIdx 329 { 330 SurfaceIndex 331 * p_ppIndex, 332 * p_pIndex, 333 * p_curIndex, 334 * p_fIndex, 335 * p_ffIndex; 336 } MulSurfIdx; 337 338 class CMCRuntimeError : public std::exception 339 { 340 public: CMCRuntimeError()341 CMCRuntimeError() : std::exception() { assert(!"CmRuntimeError"); } 342 }; 343 344 // forward declarations 345 using ns_asc::ASC; 346 //class Time; 347 348 //Cm based Motion estimation and compensation 349 class CMC 350 { 351 352 public: 353 static const mfxU16 AUTO_FILTER_STRENGTH; 354 static const mfxU16 DEFAULT_FILTER_STRENGTH; 355 static const mfxU16 INPIPE_FILTER_STRENGTH; 356 static const mfxU32 DEFAULT_BPP; 357 static const mfxU16 DEFAULT_DEBLOCKING; 358 static const mfxU16 DEFAULT_OVERLAP; 359 static const mfxU16 DEFAULT_ME; 360 static const mfxU16 DEFAULT_REFS; 361 362 // this function fills IntMctfParams structure which is used 363 // to store MCTF params; internal structure. 364 static void QueryDefaultParams(IntMctfParams*); 365 366 //this is for API 367 static void QueryDefaultParams(mfxExtVppMctf*); 368 369 static mfxStatus CheckAndFixParams(mfxExtVppMctf*); 370 371 // this function fills MCTF params based on extended buffer 372 static void FillParamControl(IntMctfParams*, const mfxExtVppMctf*); 373 374 private: 375 typedef mfxI32(CMC::*t_MCTF_ME)(); 376 typedef mfxI32(CMC::*t_MCTF_NOA)(bool adaptControl); 377 typedef mfxI32(CMC::*t_MCTF_MERGE)(); 378 typedef mfxI32(CMC::*t_RUN_MCTF)(bool notInPipeline); 379 typedef mfxI32(CMC::*t_MCTF_LOAD)(); 380 typedef mfxI32(CMC::*t_MCTF_SPDEN)(); 381 382 t_MCTF_ME pMCTF_ME_func; 383 t_MCTF_MERGE pMCTF_MERGE_func; 384 t_MCTF_NOA pMCTF_NOA_func; 385 t_RUN_MCTF pMCTF_func; 386 t_MCTF_LOAD pMCTF_LOAD_func; 387 t_MCTF_SPDEN pMCTF_SpDen_func; 388 389 eMFXHWType 390 mctf_HWType; 391 CmDevice 392 * device; 393 CmQueue 394 * queue; 395 CmTask 396 * task; 397 CmEvent 398 * e, 399 * copyEv; 400 CmThreadSpace 401 * threadSpace, 402 * threadSpace2, 403 * threadSpaceMC, 404 * threadSpaceMC2; 405 size_t 406 hwSize; 407 mfxU32 408 hwType; 409 mfxU64 410 exeTime, 411 exeTimeT; 412 //Common elements 413 mfxU32 414 version, 415 surfPitch, 416 surfSize, 417 surfNoisePitch, 418 surfNoiseSize, 419 sceneNum, 420 countFrames; 421 size_t 422 bufferCount; 423 mfxU16 424 firstFrame, 425 lastFrame, 426 number_of_References, 427 // an index to a "slot" within QfIn which corresponds 428 // to a frame being an output at this moment; this is 429 // for the normal MCTF operation (not at the begining) 430 DefaultIdx2Out, 431 432 // current index in QfIn to out; it might differ 433 // from DefaultIdx2Out in the beginning and end; 434 CurrentIdx2Out, 435 deblocking_Control, 436 gopBasedFilterStrength, 437 overlap_Motion; 438 bool 439 bitrate_Adaptation; 440 MCTF_MODE 441 m_AutoMode; 442 MCTF_CONFIGURATION 443 ConfigMode; 444 445 // current state of MCTF: is it ready to output data or not 446 mfxU16 447 MctfState; 448 449 IntMctfParams 450 m_RTParams, 451 m_InitRTParams; 452 mfxI8 453 backward_distance, 454 forward_distance; 455 mfxU16 456 bth; 457 std::unique_ptr<MeControlSmall> 458 p_ctrl; 459 CmBuffer 460 * ctrlBuf; 461 CmSurface2D 462 * qpel1, 463 * qpel2; 464 CmSurface2DUP 465 * mv_1, 466 * mv_2, 467 * mv_3, 468 * mv_4, 469 * noiseAnalysisSurf, 470 * distSurf; 471 SurfaceIndex 472 * idxCtrl, 473 * idxSrc, 474 * idxRef1, 475 * idxRef2, 476 * idxRef3, 477 * idxRef4, 478 * idxMv_1, 479 * idxMv_2, 480 * idxMv_3, 481 * idxMv_4, 482 * idxNoiseAnalysis, 483 * idxDist; 484 mfxI32 485 argIdx, 486 ov_width_bl, 487 ov_height_bl; 488 mfxU16 489 blsize, 490 tsWidthFull, 491 tsWidth, 492 tsHeight, 493 tsWidthFullMC, 494 tsWidthMC, 495 tsHeightMC; 496 void 497 * mvSys1, 498 * mvSys2, 499 * mvSys3, 500 * mvSys4, 501 * noiseAnalysisSys, 502 * distSys; 503 mfxF64 504 bpp; 505 mfxU32 506 m_FrameRateExtN, 507 m_FrameRateExtD; 508 mfxU32 509 scene_numbers[5]; 510 mfxU64 511 time; 512 513 mfxI32 res; 514 515 std::vector<mfxU32> 516 distRef; 517 std::vector<spatialNoiseAnalysis> 518 var_sc; 519 520 SurfaceIndex 521 * genxRefs1, 522 * genxRefs2, 523 * genxRefs3, 524 * genxRefs4; 525 526 //MC elements 527 CmProgram 528 * programMc, 529 * programDe; 530 CmKernel 531 * kernelNoise, 532 * kernelMcDen, 533 * kernelMc1r, 534 * kernelMc2r, 535 * kernelMc4r; 536 537 CmSurface2D 538 * mco, 539 * mco2; 540 SurfaceIndex 541 * idxMco, 542 * idxMco2; 543 bool 544 m_externalSCD, 545 m_adaptControl, //Based on sequence stats indicates if denoising should be performed or not 546 m_doFilterFrame; 547 std::unique_ptr<ASC> 548 pSCD; 549 // a queue MCTF of frames MCTF operates on 550 std::vector<gpuFrameData> 551 QfIn; 552 553 // ----------- MSDK binds------------------ 554 VideoCORE 555 * m_pCore; 556 557 protected: 558 //ME elements 559 CmProgram 560 * programMe; 561 CmKernel 562 * kernelMe, 563 * kernelMeB2, 564 * kernelMeB; 565 566 private: 567 inline mfxStatus SetupMeControl( 568 const mfxFrameInfo & FrameInfo, 569 mfxU16 th, 570 mfxU16 subPelPre 571 ); 572 mfxStatus DIM_SET( 573 mfxU16 overlap 574 ); 575 mfxStatus MCTF_InitQueue( 576 mfxU16 refNum 577 ); 578 579 void RotateBuffer(); 580 void RotateBufferA(); 581 void RotateBufferB(); 582 583 mfxStatus IM_SURF_SET_Int(); 584 mfxStatus IM_SURF_SET(); 585 mfxStatus IM_SURF_SET( 586 CmSurface2D ** p_surface, 587 SurfaceIndex ** p_idxSurf 588 ); 589 mfxStatus IM_SURF_SET( 590 AbstractSurfaceHandle pD3DSurf, 591 CmSurface2D ** p_surface, 592 SurfaceIndex ** p_idxSurf 593 ); 594 mfxStatus IM_MRE_SURF_SET( 595 CmSurface2D ** p_Surface, 596 SurfaceIndex ** p_idxSurf 597 ); 598 mfxStatus GEN_NoiseSURF_SET( 599 CmSurface2DUP ** p_Surface, 600 void ** p_Sys, 601 SurfaceIndex ** p_idxSurf 602 ); 603 mfxStatus GEN_SURF_SET( 604 CmSurface2DUP ** p_Surface, 605 void ** p_Sys, 606 SurfaceIndex ** p_idxSurf 607 ); 608 mfxI32 MCTF_SET_KERNELMe( 609 SurfaceIndex * GenxRefs, 610 SurfaceIndex * idxMV, 611 mfxU16 start_x, 612 mfxU16 start_y, 613 mfxU8 blSize 614 ); 615 mfxI32 MCTF_SET_KERNELMeBi( 616 SurfaceIndex * GenxRefs, 617 SurfaceIndex * GenxRefs2, 618 SurfaceIndex * idxMV, 619 SurfaceIndex * idxMV2, 620 mfxU16 start_x, 621 mfxU16 start_y, 622 mfxU8 blSize, 623 mfxI8 forwardRefDist, 624 mfxI8 backwardRefDist 625 ); 626 mfxU32 MCTF_SET_KERNELMeBiMRE( 627 SurfaceIndex* GenxRefs, 628 SurfaceIndex* GenxRefs2, 629 SurfaceIndex* idxMV, 630 SurfaceIndex* idxMV2, 631 mfxU16 start_x, 632 mfxU16 start_y, 633 mfxU8 blSize, 634 mfxI8 forwardRefDist, 635 mfxI8 backwardRefDist 636 ); 637 mfxU32 MCTF_SET_KERNELMeBiMRE2( 638 SurfaceIndex* GenxRefs, 639 SurfaceIndex* GenxRefs2, 640 SurfaceIndex* idxMV, 641 SurfaceIndex* idxMV2, 642 mfxU16 start_x, 643 mfxU16 start_y, 644 mfxU8 blSize, 645 mfxI8 forwardRefDist, 646 mfxI8 backwardRefDist 647 ); 648 mfxI32 MCTF_SET_KERNELMc( 649 mfxU16 start_x, 650 mfxU16 start_y, 651 mfxU8 srcNum, 652 mfxU8 refNum 653 ); 654 mfxI32 MCTF_SET_KERNELMc2r( 655 mfxU16 start_x, 656 mfxU16 start_y 657 ); 658 mfxI32 MCTF_SET_KERNELMc2rDen( 659 mfxU16 start_x, 660 mfxU16 start_y 661 ); 662 mfxI32 MCTF_SET_KERNELMc4r( 663 mfxU16 start_x, 664 mfxU16 start_y 665 ); 666 mfxI32 MCTF_SET_KERNELMc4r( 667 mfxU16 start_x, 668 mfxU16 start_y, 669 SurfaceIndex * multiIndex 670 ); 671 mfxI32 MCTF_SET_KERNELMc4r( 672 mfxU16 start_x, 673 mfxU16 start_y, 674 mfxU8 runType 675 ); 676 mfxI32 MCTF_SET_KERNELMcMerge( 677 mfxU16 start_x, 678 mfxU16 start_y 679 ); 680 mfxU8 SetOverlapOp(); 681 mfxU8 SetOverlapOp_half(); 682 mfxI32 MCTF_Enqueue( 683 CmTask* taskInt, 684 CmEvent* & eInt, 685 const CmThreadSpace* tSInt = 0 686 ); 687 mfxI32 MCTF_RUN_TASK_NA( 688 CmKernel * kernel, 689 bool reset, 690 mfxU16 widthTs, 691 mfxU16 heightTs 692 ); 693 mfxI32 MCTF_RUN_TASK( 694 CmKernel * kernel, 695 bool reset 696 ); 697 mfxI32 MCTF_RUN_DOUBLE_TASK( 698 CmKernel * meKernel, 699 CmKernel * mcKernel, 700 bool reset 701 ); 702 mfxI32 MCTF_RUN_MCTASK( 703 CmKernel * kernel, 704 bool reset 705 ); 706 mfxI32 MCTF_RUN_TASK( 707 CmKernel * kernel, 708 bool reset, 709 CmThreadSpace * tS 710 ); 711 mfxI32 MCTF_RUN_ME( 712 SurfaceIndex * GenxRefs, 713 SurfaceIndex * idxMV 714 ); 715 mfxI32 MCTF_RUN_ME( 716 SurfaceIndex * GenxRefs, 717 SurfaceIndex * GenxRefs2, 718 SurfaceIndex * idxMV, 719 SurfaceIndex * idxMV2, 720 char forwardRefDist, 721 char backwardRefDist 722 ); 723 mfxI32 MCTF_RUN_ME_MC_HE( 724 SurfaceIndex * GenxRefs, 725 SurfaceIndex * GenxRefs2, 726 SurfaceIndex * idxMV, 727 SurfaceIndex * idxMV2, 728 mfxI8 forwardRefDist, 729 mfxI8 backwardRefDist, 730 mfxU8 mcSufIndex 731 ); 732 mfxI32 MCTF_RUN_ME_MC_H( 733 SurfaceIndex * GenxRefs, 734 SurfaceIndex * GenxRefs2, 735 SurfaceIndex * idxMV, 736 SurfaceIndex * idxMV2, 737 mfxI8 forwardRefDist, 738 mfxI8 backwardRefDist, 739 mfxU8 mcSufIndex 740 ); 741 mfxI32 MCTF_RUN_ME_1REF(); 742 mfxI32 MCTF_RUN_ME_2REF(); 743 mfxI32 MCTF_RUN_ME_4REF(); 744 745 mfxI32 MCTF_RUN_ME_2REF_HE(); 746 747 void GET_DISTDATA(); 748 void GET_DISTDATA_H(); 749 void GET_NOISEDATA(); 750 mfxF64 GET_TOTAL_SAD(); 751 mfxI32 MCTF_RUN_Noise_Analysis( 752 mfxU8 srcNum 753 ); 754 void GetSpatioTemporalComplexityFrame( 755 mfxU8 currentFrame 756 ); 757 mfxU32 computeQpClassFromBitRate( 758 mfxU8 currentFrame 759 ); 760 bool FilterEnable( 761 gpuFrameData frame 762 ); 763 mfxI32 noise_estimator( 764 bool adaptControl 765 ); 766 mfxI32 MCTF_RUN_BLEND(); 767 mfxI32 MCTF_RUN_BLEND( 768 mfxU8 srcNum, 769 mfxU8 refNum 770 ); 771 mfxI32 MCTF_RUN_BLEND2R(); 772 mfxI32 MCTF_RUN_BLEND2R_DEN(); 773 mfxI32 MCTF_RUN_BLEND4R( 774 DRT typeRun 775 ); 776 mfxI32 MCTF_RUN_BLEND4R( 777 SurfaceIndex * multiIndex 778 ); 779 mfxI32 MCTF_BLEND4R(); 780 mfxI32 MCTF_RUN_MERGE(); 781 mfxI32 MCTF_LOAD_1REF(); 782 mfxI32 MCTF_LOAD_2REF(); 783 mfxI32 MCTF_LOAD_4REF(); 784 void AssignSceneNumber(); 785 mfxI32 MCTF_RUN_MCTF_DEN_1REF( 786 bool 787 ); 788 mfxI32 MCTF_RUN_MCTF_DEN( 789 bool notInPipeline 790 ); 791 mfxI32 MCTF_RUN_MCTF_DEN_4REF( 792 bool 793 ); 794 mfxI32 MCTF_RUN_AMCTF_DEN(); 795 796 mfxStatus MCTF_SET_ENV( 797 VideoCORE * core, 798 const mfxFrameInfo & FrameInfo, 799 const IntMctfParams * pMctfParam, 800 bool isCmUsed, 801 bool isNCActive 802 ); 803 mfxI32 MCTF_SET_KERNEL_Noise( 804 mfxU16 srcNum, 805 mfxU16 start_x, 806 mfxU16 start_y 807 ); 808 mfxI32 MCTF_SET_KERNELDe( 809 mfxU16 srcNum, 810 mfxU16 start_x, 811 mfxU16 start_y 812 ); 813 mfxI32 MCTF_SET_KERNELDe( 814 mfxU16 start_x, 815 mfxU16 start_y 816 ); 817 mfxI32 MCTF_RUN_AMCTF(); 818 mfxI32 MCTF_RUN_AMCTF( 819 mfxU16 srcNum 820 ); 821 mfxI32 MCTF_RUN_Denoise( 822 mfxU16 srcNum 823 ); 824 mfxI32 MCTF_RUN_Denoise(); 825 826 // it will update strength/deblock/bitrate depending on the current mode MCTF operates & parameters 827 // stored in QfIn, in a position srcNum; it will also update the current parameters (if for next frame 828 // no information was passed) 829 mfxStatus MCTF_UpdateRTParams( 830 IntMctfParams * pMctfParam 831 ); 832 mfxStatus MCTF_CheckRTParams( 833 const IntMctfParams * pMctfParam 834 ); 835 mfxStatus MCTF_UpdateANDApplyRTParams( 836 mfxU8 srcNum 837 ); 838 public: 839 mfxU16 MCTF_QUERY_NUMBER_OF_REFERENCES(); 840 // sets filter-strength 841 mfxStatus SetFilterStrenght( 842 unsigned short tFs,//Temporal filter strength 843 unsigned short sFs //Spatial filter strength 844 ); 845 inline mfxStatus SetFilterStrenght( 846 unsigned short fs 847 ); 848 // returns number of referencies MCTF operates on MCTF_GetReferenceNumber()849 mfxU16 MCTF_GetReferenceNumber() { return MCTF_QUERY_NUMBER_OF_REFERENCES(); }; 850 // Initialize MCTF 851 mfxStatus MCTF_INIT( 852 VideoCORE * core, 853 CmDevice * pCmDevice, 854 const mfxFrameInfo & FrameInfo, 855 const IntMctfParams * pMctfParam 856 ); 857 mfxStatus MCTF_INIT(//When external App is using SCD, no need to initilize internal scd. 858 VideoCORE * core, 859 CmDevice * pCmDevice, 860 const mfxFrameInfo & FrameInfo, 861 const IntMctfParams * pMctfParam, 862 const bool externalSCD, 863 const bool isNCActive 864 ); 865 mfxStatus MCTF_INIT( 866 VideoCORE * core, 867 CmDevice * pCmDevice, 868 const mfxFrameInfo & FrameInfo, 869 const IntMctfParams * pMctfParam, 870 bool isCmUsed, 871 const bool externalSCD, 872 const bool useFilterAdaptControl, 873 const bool isNCActive 874 ); 875 // returns how many frames are needed to work; 876 mfxU32 MCTF_GetQueueDepth(); 877 mfxStatus MCTF_SetMemory( 878 const std::vector<mfxFrameSurface1*> &); 879 mfxStatus MCTF_SetMemory( 880 bool isCmUsed 881 ); 882 void MCTF_CLOSE(); MCTF_QueryMode()883 MCTF_CONFIGURATION MCTF_QueryMode() { return ConfigMode; }; 884 mfxStatus MCTF_UpdateBitrateInfo( 885 mfxU32 886 ); 887 //returns a pointer to internally allocated surface, and locks it using core method 888 mfxStatus MCTF_GetEmptySurface( 889 mfxFrameSurface1 ** ppSurface 890 ); 891 // submits a surface to MCTF & set appropriate filter-strength; 892 mfxU32 IM_SURF_PUT( 893 CmSurface2D *p_surface, 894 mfxU8 *p_data 895 ); 896 897 void IntBufferUpdate( 898 bool isSceneChange, 899 bool isIntraFrame, 900 bool doIntraFiltering 901 ); 902 void BufferFilterAssignment( 903 mfxU16 * filterStrength, 904 bool doIntraFiltering, 905 bool isAnchorFrame, 906 bool isSceneChange 907 ); 908 bool MCTF_Check_Use(); 909 mfxStatus MCTF_PUT_FRAME( 910 void * frameInData, 911 mfxHDLPair frameOutHandle, 912 CmSurface2D ** frameOutData, 913 bool isCmSurface, 914 mfxU16 * filterStrength, 915 bool needsOutput, 916 bool doIntraFiltering 917 ); 918 mfxStatus MCTF_PUT_FRAME( 919 IntMctfParams * pMctfControl, 920 CmSurface2D * InSurf, 921 CmSurface2D * OutSurf 922 ); 923 mfxStatus MCTF_PUT_FRAME( 924 IntMctfParams * pMctfControl, 925 CmSurface2D * OutSurf, 926 mfxU32 schgDesicion 927 ); 928 mfxStatus MCTF_PUT_FRAME( 929 mfxU32 sceneNumber, 930 CmSurface2D * OutSurf 931 ); 932 mfxStatus MCTF_UpdateBufferCount(); 933 mfxStatus MCTF_DO_FILTERING_IN_AVC(); 934 mfxU16 MCTF_QUERY_FILTER_STRENGTH(); 935 mfxStatus MCTF_DO_FILTERING(); 936 // returns (query) result of filtering to outFrame 937 mfxStatus MCTF_GET_FRAME( 938 CmSurface2D* outFrame 939 ); 940 mfxStatus MCTF_GET_FRAME( 941 mfxU8 * outFrame 942 ); 943 bool MCTF_CHECK_FILTER_USE(); 944 mfxStatus MCTF_RELEASE_FRAME( 945 bool isCmUsed 946 ); 947 // after MCTF_GET_FRAME is invoked, we need to update TimeStamp & FrameOrder 948 // To cal this function with a surface that needs to be updated 949 mfxStatus MCTF_TrackTimeStamp( 950 mfxFrameSurface1 * outFrame 951 ); MCTF_ReadyToOutput()952 bool MCTF_ReadyToOutput() { return (AMCTF_READY == MctfState); }; 953 }; 954