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_ENC_BITSTREAM_BUILDER_HEVC_H 25 #define D3D12_VIDEO_ENC_BITSTREAM_BUILDER_HEVC_H 26 27 #include "d3d12_video_encoder_nalu_writer_hevc.h" 28 #include "d3d12_video_encoder_bitstream_builder.h" 29 30 class d3d12_video_bitstream_builder_hevc : public d3d12_video_bitstream_builder_interface 31 { 32 33 public: d3d12_video_bitstream_builder_hevc()34 d3d12_video_bitstream_builder_hevc() {}; ~d3d12_video_bitstream_builder_hevc()35 ~d3d12_video_bitstream_builder_hevc() {}; 36 37 HevcVideoParameterSet build_vps(const struct pipe_h265_enc_vid_param & vidData, 38 const D3D12_VIDEO_ENCODER_PROFILE_HEVC& profile, 39 const D3D12_VIDEO_ENCODER_LEVEL_TIER_CONSTRAINTS_HEVC& level, 40 const DXGI_FORMAT inputFmt, 41 bool gopHasBFrames, 42 uint8_t vps_video_parameter_set_id, 43 std::vector<BYTE> &headerBitstream, 44 std::vector<BYTE>::iterator placingPositionStart, 45 size_t &writtenBytes); 46 47 HevcSeqParameterSet build_sps(const HevcVideoParameterSet& parentVPS, 48 const struct pipe_h265_enc_seq_param & seqData, 49 uint8_t seq_parameter_set_id, 50 const D3D12_VIDEO_ENCODER_PICTURE_RESOLUTION_DESC& encodeResolution, 51 const D3D12_BOX& crop_window_upper_layer, 52 const UINT picDimensionMultipleRequirement, 53 const DXGI_FORMAT& inputFmt, 54 const D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_HEVC& codecConfig, 55 const D3D12_VIDEO_ENCODER_SEQUENCE_GOP_STRUCTURE_HEVC& hevcGOP, 56 std::vector<BYTE> &headerBitstream, 57 std::vector<BYTE>::iterator placingPositionStart, 58 size_t &writtenBytes); 59 60 HevcPicParameterSet build_pps(const struct pipe_h265_enc_pic_param & picData, 61 const HevcSeqParameterSet& parentSPS, 62 uint8_t pic_parameter_set_id, 63 const D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_HEVC& codecConfig, 64 const D3D12_VIDEO_ENCODER_PICTURE_CONTROL_CODEC_DATA_HEVC1& pictureControl, 65 std::vector<BYTE> &headerBitstream, 66 std::vector<BYTE>::iterator placingPositionStart, 67 size_t &writtenBytes); 68 69 void write_end_of_stream_nalu(std::vector<uint8_t> & headerBitstream, 70 std::vector<uint8_t>::iterator placingPositionStart, 71 size_t & writtenBytes); 72 void write_end_of_sequence_nalu(std::vector<uint8_t> & headerBitstream, 73 std::vector<uint8_t>::iterator placingPositionStart, 74 size_t & writtenBytes); 75 76 void write_aud(std::vector<uint8_t> & headerBitstream, 77 std::vector<uint8_t>::iterator placingPositionStart, 78 D3D12_VIDEO_ENCODER_FRAME_TYPE_HEVC frameType, 79 size_t & writtenBytes); 80 81 void print_vps(const HevcVideoParameterSet& vps); 82 void print_sps(const HevcSeqParameterSet& sps); 83 void print_pps(const HevcPicParameterSet& pps); 84 void print_rps(const HevcSeqParameterSet* sps, UINT stRpsIdx); 85 get_active_vps()86 const HevcVideoParameterSet& get_active_vps() 87 { 88 return m_active_vps; 89 } 90 get_active_sps()91 const HevcSeqParameterSet& get_active_sps() 92 { 93 return m_active_sps; 94 } 95 get_active_pps()96 const HevcPicParameterSet& get_active_pps() 97 { 98 return m_active_pps; 99 } 100 set_active_vps(HevcVideoParameterSet & active_vps)101 void set_active_vps(HevcVideoParameterSet &active_vps) 102 { 103 m_active_vps = active_vps; 104 } 105 set_active_sps(HevcSeqParameterSet & active_sps)106 void set_active_sps(HevcSeqParameterSet &active_sps) 107 { 108 m_active_sps = active_sps; 109 } 110 set_active_pps(HevcPicParameterSet & active_pps)111 void set_active_pps(HevcPicParameterSet &active_pps) 112 { 113 m_active_pps = active_pps; 114 } 115 116 private: 117 d3d12_video_nalu_writer_hevc m_hevcEncoder; 118 HevcVideoParameterSet m_active_vps = {}; 119 HevcSeqParameterSet m_active_sps = {}; 120 HevcPicParameterSet m_active_pps = {}; 121 122 void init_profile_tier_level(HEVCProfileTierLevel *ptl, uint8_t HEVCProfileIdc, uint8_t HEVCLevelIdc, bool isHighTier); 123 }; 124 125 #endif 126