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