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_H264_H 25 #define D3D12_VIDEO_ENC_BITSTREAM_BUILDER_H264_H 26 27 #include "d3d12_video_encoder_nalu_writer_h264.h" 28 #include "d3d12_video_encoder_bitstream_builder.h" 29 30 class d3d12_video_bitstream_builder_h264 : public d3d12_video_bitstream_builder_interface 31 { 32 33 public: 34 d3d12_video_bitstream_builder_h264(bool insert_aud_nalu = false); ~d3d12_video_bitstream_builder_h264()35 ~d3d12_video_bitstream_builder_h264() {}; 36 37 void build_sps(const struct pipe_h264_enc_seq_param & seqData, 38 const enum pipe_video_profile & profile, 39 const D3D12_VIDEO_ENCODER_LEVELS_H264 & level, 40 const DXGI_FORMAT & inputFmt, 41 const D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_H264 & codecConfig, 42 const D3D12_VIDEO_ENCODER_SEQUENCE_GOP_STRUCTURE_H264 &gopConfig, 43 uint32_t seq_parameter_set_id, 44 uint32_t max_num_ref_frames, 45 D3D12_VIDEO_ENCODER_PICTURE_RESOLUTION_DESC sequenceTargetResolution, 46 D3D12_BOX frame_cropping_codec_config, 47 std::vector<uint8_t> & headerBitstream, 48 std::vector<uint8_t>::iterator placingPositionStart, 49 size_t & writtenBytes); 50 51 void build_pps(const enum pipe_video_profile & profile, 52 const D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_H264 & codecConfig, 53 const D3D12_VIDEO_ENCODER_PICTURE_CONTROL_CODEC_DATA_H264 &pictureControl, 54 uint32_t pic_parameter_set_id, 55 uint32_t seq_parameter_set_id, 56 std::vector<uint8_t> & headerBitstream, 57 std::vector<uint8_t>::iterator placingPositionStart, 58 size_t & writtenBytes); 59 60 void write_end_of_stream_nalu(std::vector<uint8_t> & headerBitstream, 61 std::vector<uint8_t>::iterator placingPositionStart, 62 size_t & writtenBytes); 63 void write_end_of_sequence_nalu(std::vector<uint8_t> & headerBitstream, 64 std::vector<uint8_t>::iterator placingPositionStart, 65 size_t & writtenBytes); 66 67 void write_aud(std::vector<uint8_t> & headerBitstream, 68 std::vector<uint8_t>::iterator placingPositionStart, 69 size_t & writtenBytes); 70 71 void print_pps(const H264_PPS &pps); 72 void print_sps(const H264_SPS &sps); 73 get_active_sps_id()74 uint32_t get_active_sps_id() 75 { 76 return m_activeSPSIndex; 77 }; get_active_pps_id()78 uint32_t get_active_pps_id() 79 { 80 return m_activePPSIndex; 81 }; 82 get_active_pps()83 std::vector<uint8_t>& get_active_pps() 84 { 85 return m_activePPS; 86 }; 87 set_active_sps_id(uint32_t active_sps_id)88 void set_active_sps_id(uint32_t active_sps_id) 89 { 90 m_activeSPSIndex = active_sps_id; 91 debug_printf("[d3d12_video_bitstream_builder_h264] Setting new active SPS ID: %d ", m_activeSPSIndex); 92 }; set_active_pps_id(uint32_t active_pps_id)93 void set_active_pps_id(uint32_t active_pps_id) 94 { 95 m_activePPSIndex = active_pps_id; 96 debug_printf("[d3d12_video_bitstream_builder_h264] Setting new active PPS ID: %d ", m_activePPSIndex); 97 }; 98 insert_aud_nalu_requested()99 bool insert_aud_nalu_requested() { return m_insert_aud_nalu; } 100 101 private: 102 d3d12_video_nalu_writer_h264 m_h264Encoder; 103 std::vector<uint8_t> m_activePPS; 104 uint32_t m_activeSPSIndex = 0; 105 uint32_t m_activePPSIndex = 0; 106 bool m_insert_aud_nalu = false; 107 }; 108 109 #endif 110