1*09537850SAkhilesh Sanikop /* 2*09537850SAkhilesh Sanikop * Copyright 2020 The libgav1 Authors 3*09537850SAkhilesh Sanikop * 4*09537850SAkhilesh Sanikop * Licensed under the Apache License, Version 2.0 (the "License"); 5*09537850SAkhilesh Sanikop * you may not use this file except in compliance with the License. 6*09537850SAkhilesh Sanikop * You may obtain a copy of the License at 7*09537850SAkhilesh Sanikop * 8*09537850SAkhilesh Sanikop * http://www.apache.org/licenses/LICENSE-2.0 9*09537850SAkhilesh Sanikop * 10*09537850SAkhilesh Sanikop * Unless required by applicable law or agreed to in writing, software 11*09537850SAkhilesh Sanikop * distributed under the License is distributed on an "AS IS" BASIS, 12*09537850SAkhilesh Sanikop * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13*09537850SAkhilesh Sanikop * See the License for the specific language governing permissions and 14*09537850SAkhilesh Sanikop * limitations under the License. 15*09537850SAkhilesh Sanikop */ 16*09537850SAkhilesh Sanikop 17*09537850SAkhilesh Sanikop #ifndef LIBGAV1_SRC_UTILS_REFERENCE_INFO_H_ 18*09537850SAkhilesh Sanikop #define LIBGAV1_SRC_UTILS_REFERENCE_INFO_H_ 19*09537850SAkhilesh Sanikop 20*09537850SAkhilesh Sanikop #include <array> 21*09537850SAkhilesh Sanikop #include <cstdint> 22*09537850SAkhilesh Sanikop 23*09537850SAkhilesh Sanikop #include "src/utils/array_2d.h" 24*09537850SAkhilesh Sanikop #include "src/utils/compiler_attributes.h" 25*09537850SAkhilesh Sanikop #include "src/utils/constants.h" 26*09537850SAkhilesh Sanikop #include "src/utils/types.h" 27*09537850SAkhilesh Sanikop 28*09537850SAkhilesh Sanikop namespace libgav1 { 29*09537850SAkhilesh Sanikop 30*09537850SAkhilesh Sanikop // This struct collects some members related to reference frames in one place to 31*09537850SAkhilesh Sanikop // make it easier to pass them as parameters to some dsp functions. 32*09537850SAkhilesh Sanikop struct ReferenceInfo { 33*09537850SAkhilesh Sanikop // Initialize |motion_field_reference_frame| so that 34*09537850SAkhilesh Sanikop // Tile::StoreMotionFieldMvsIntoCurrentFrame() can skip some updates when 35*09537850SAkhilesh Sanikop // the updates are the same as the initialized value. 36*09537850SAkhilesh Sanikop // Set to kReferenceFrameIntra instead of kReferenceFrameNone to simplify 37*09537850SAkhilesh Sanikop // branch conditions in motion field projection. 38*09537850SAkhilesh Sanikop // The following memory initialization of contiguous memory is very fast. It 39*09537850SAkhilesh Sanikop // is not recommended to make the initialization multi-threaded, unless the 40*09537850SAkhilesh Sanikop // memory which needs to be initialized in each thread is still contiguous. ResetReferenceInfo41*09537850SAkhilesh Sanikop LIBGAV1_MUST_USE_RESULT bool Reset(int rows, int columns) { 42*09537850SAkhilesh Sanikop return motion_field_reference_frame.Reset(rows, columns, 43*09537850SAkhilesh Sanikop /*zero_initialize=*/true) && 44*09537850SAkhilesh Sanikop motion_field_mv.Reset( 45*09537850SAkhilesh Sanikop rows, columns, 46*09537850SAkhilesh Sanikop #if LIBGAV1_MSAN 47*09537850SAkhilesh Sanikop // It is set in Tile::StoreMotionFieldMvsIntoCurrentFrame() only 48*09537850SAkhilesh Sanikop // for qualified blocks. In MotionFieldProjectionKernel() dsp 49*09537850SAkhilesh Sanikop // optimizations, it is read no matter it was set or not. 50*09537850SAkhilesh Sanikop /*zero_initialize=*/true 51*09537850SAkhilesh Sanikop #else 52*09537850SAkhilesh Sanikop /*zero_initialize=*/false 53*09537850SAkhilesh Sanikop #endif 54*09537850SAkhilesh Sanikop ); 55*09537850SAkhilesh Sanikop } 56*09537850SAkhilesh Sanikop 57*09537850SAkhilesh Sanikop // All members are used by inter frames only. 58*09537850SAkhilesh Sanikop // For intra frames, they are not initialized. 59*09537850SAkhilesh Sanikop 60*09537850SAkhilesh Sanikop std::array<uint8_t, kNumReferenceFrameTypes> order_hint; 61*09537850SAkhilesh Sanikop 62*09537850SAkhilesh Sanikop // An example when |relative_distance_from| does not equal 63*09537850SAkhilesh Sanikop // -|relative_distance_to|: 64*09537850SAkhilesh Sanikop // |relative_distance_from| = GetRelativeDistance(7, 71, 25) = -64 65*09537850SAkhilesh Sanikop // -|relative_distance_to| = -GetRelativeDistance(71, 7, 25) = 64 66*09537850SAkhilesh Sanikop // This is why we need both |relative_distance_from| and 67*09537850SAkhilesh Sanikop // |relative_distance_to|. 68*09537850SAkhilesh Sanikop // |relative_distance_from|: Relative distances from reference frames to this 69*09537850SAkhilesh Sanikop // frame. 70*09537850SAkhilesh Sanikop std::array<int8_t, kNumReferenceFrameTypes> relative_distance_from; 71*09537850SAkhilesh Sanikop // |relative_distance_to|: Relative distances to reference frames. 72*09537850SAkhilesh Sanikop std::array<int8_t, kNumReferenceFrameTypes> relative_distance_to; 73*09537850SAkhilesh Sanikop 74*09537850SAkhilesh Sanikop // Skip motion field projection of specific types of frames if their 75*09537850SAkhilesh Sanikop // |relative_distance_to| is negative or too large. 76*09537850SAkhilesh Sanikop std::array<bool, kNumReferenceFrameTypes> skip_references; 77*09537850SAkhilesh Sanikop // Lookup table to get motion field projection division multiplier of specific 78*09537850SAkhilesh Sanikop // types of frames. Derived from kProjectionMvDivisionLookup. 79*09537850SAkhilesh Sanikop std::array<int16_t, kNumReferenceFrameTypes> projection_divisions; 80*09537850SAkhilesh Sanikop 81*09537850SAkhilesh Sanikop // The current frame's |motion_field_reference_frame| and |motion_field_mv_| 82*09537850SAkhilesh Sanikop // are guaranteed to be allocated only when refresh_frame_flags is not 0. 83*09537850SAkhilesh Sanikop // Array of size (rows4x4 / 2) x (columns4x4 / 2). Entry at i, j corresponds 84*09537850SAkhilesh Sanikop // to MfRefFrames[i * 2 + 1][j * 2 + 1] in the spec. 85*09537850SAkhilesh Sanikop Array2D<ReferenceFrameType> motion_field_reference_frame; 86*09537850SAkhilesh Sanikop // Array of size (rows4x4 / 2) x (columns4x4 / 2). Entry at i, j corresponds 87*09537850SAkhilesh Sanikop // to MfMvs[i * 2 + 1][j * 2 + 1] in the spec. 88*09537850SAkhilesh Sanikop Array2D<MotionVector> motion_field_mv; 89*09537850SAkhilesh Sanikop }; 90*09537850SAkhilesh Sanikop 91*09537850SAkhilesh Sanikop } // namespace libgav1 92*09537850SAkhilesh Sanikop 93*09537850SAkhilesh Sanikop #endif // LIBGAV1_SRC_UTILS_REFERENCE_INFO_H_ 94