1 /* 2 * Copyright © Microsoft 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 (including the next 12 * paragraph) shall be included in all copies or substantial portions of the 13 * Software. 14 * 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21 * IN THE SOFTWARE. 22 */ 23 24 #ifndef D3D12_VIDEO_ENCODE_FIFO_REFERENCES_MANAGER_HEVC_H 25 #define D3D12_VIDEO_ENCODE_FIFO_REFERENCES_MANAGER_HEVC_H 26 27 #include "d3d12_video_types.h" 28 #include "d3d12_video_encoder_references_manager.h" 29 #include "d3d12_video_dpb_storage_manager.h" 30 31 class d3d12_video_encoder_references_manager_hevc : public d3d12_video_encoder_references_manager_interface 32 { 33 public: 34 void end_frame(); 35 void begin_frame(D3D12_VIDEO_ENCODER_PICTURE_CONTROL_CODEC_DATA curFrameData, bool bUsedAsReference, struct pipe_picture_desc* picture); 36 D3D12_VIDEO_ENCODER_RECONSTRUCTED_PICTURE get_current_frame_recon_pic_output_allocation(); 37 bool get_current_frame_picture_control_data(D3D12_VIDEO_ENCODER_PICTURE_CONTROL_CODEC_DATA &codecAllocation); 38 bool is_current_frame_used_as_reference(); 39 D3D12_VIDEO_ENCODE_REFERENCE_FRAMES get_current_reference_frames(); 40 41 d3d12_video_encoder_references_manager_hevc(bool gopHasInterCodedFrames, 42 d3d12_video_dpb_storage_manager_interface &rDpbStorageManager, 43 uint32_t MaxDPBCapacity); 44 ~d3d12_video_encoder_references_manager_hevc()45 ~d3d12_video_encoder_references_manager_hevc() 46 { } 47 48 private: 49 // Class helpers 50 void prepare_current_frame_recon_pic_allocation(); 51 void reset_gop_tracking_and_dpb(); 52 void update_fifo_dpb_push_front_cur_recon_pic(); 53 void print_dpb(); 54 void print_l0_l1_lists(); 55 56 // Class members 57 58 uint32_t m_MaxDPBCapacity = 0; 59 60 struct D3D12_VIDEO_ENCODER_REFERENCE_PICTURE_DESCRIPTOR_HEVC_EX { 61 D3D12_VIDEO_ENCODER_REFERENCE_PICTURE_DESCRIPTOR_HEVC base; 62 /* the upper layer uses pipe_h265_enc_picture_desc.frame_num to identify frames 63 in the L0 and L1 reference lists. This frame_num is different than POC 64 so let's save it in this variable to be able to reverse-map the L0/L1 lists from 65 these indices into POCs */ 66 unsigned int reference_lists_frame_idx; 67 }; 68 69 struct current_frame_references_data 70 { 71 std::vector<D3D12_VIDEO_ENCODER_REFERENCE_PICTURE_DESCRIPTOR_HEVC_EX> pReferenceFramesReconPictureDescriptors; 72 D3D12_VIDEO_ENCODER_RECONSTRUCTED_PICTURE ReconstructedPicTexture; 73 }; 74 75 d3d12_video_dpb_storage_manager_interface &m_rDPBStorageManager; 76 77 current_frame_references_data m_CurrentFrameReferencesData; 78 79 bool m_gopHasInterFrames = false; 80 81 bool m_isCurrentFrameUsedAsReference = false; 82 D3D12_VIDEO_ENCODER_PICTURE_CONTROL_CODEC_DATA_HEVC m_curFrameState = {}; 83 std::vector<D3D12_VIDEO_ENCODER_REFERENCE_PICTURE_DESCRIPTOR_HEVC> m_curFrameStateDescriptorStorage; 84 unsigned int m_current_frame_idx = 0; 85 }; 86 87 #endif 88