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: d3d12_video_bitstream_builder_h264()34 d3d12_video_bitstream_builder_h264() {}; ~d3d12_video_bitstream_builder_h264()35 ~d3d12_video_bitstream_builder_h264() {}; 36 37 void build_sps(const D3D12_VIDEO_ENCODER_PROFILE_H264 & profile, 38 const D3D12_VIDEO_ENCODER_LEVELS_H264 & level, 39 const DXGI_FORMAT & inputFmt, 40 const D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_H264 & codecConfig, 41 const D3D12_VIDEO_ENCODER_SEQUENCE_GOP_STRUCTURE_H264 &gopConfig, 42 uint32_t seq_parameter_set_id, 43 uint32_t max_num_ref_frames, 44 D3D12_VIDEO_ENCODER_PICTURE_RESOLUTION_DESC sequenceTargetResolution, 45 D3D12_BOX frame_cropping_codec_config, 46 std::vector<uint8_t> & headerBitstream, 47 std::vector<uint8_t>::iterator placingPositionStart, 48 size_t & writtenBytes); 49 50 void build_pps(const D3D12_VIDEO_ENCODER_PROFILE_H264 & profile, 51 const D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_H264 & codecConfig, 52 const D3D12_VIDEO_ENCODER_PICTURE_CONTROL_CODEC_DATA_H264 &pictureControl, 53 uint32_t pic_parameter_set_id, 54 uint32_t seq_parameter_set_id, 55 std::vector<uint8_t> & headerBitstream, 56 std::vector<uint8_t>::iterator placingPositionStart, 57 size_t & writtenBytes); 58 59 void write_end_of_stream_nalu(std::vector<uint8_t> & headerBitstream, 60 std::vector<uint8_t>::iterator placingPositionStart, 61 size_t & writtenBytes); 62 void write_end_of_sequence_nalu(std::vector<uint8_t> & headerBitstream, 63 std::vector<uint8_t>::iterator placingPositionStart, 64 size_t & writtenBytes); 65 66 void print_pps(const H264_PPS &pps); 67 void print_sps(const H264_SPS &sps); 68 69 uint32_t m_activeSPSIndex = 0; 70 uint32_t m_activePPSIndex = 0; 71 get_active_sps_id()72 uint32_t get_active_sps_id() 73 { 74 return m_activeSPSIndex; 75 }; get_active_pps_id()76 uint32_t get_active_pps_id() 77 { 78 return m_activePPSIndex; 79 }; 80 set_active_sps_id(uint32_t active_sps_id)81 void set_active_sps_id(uint32_t active_sps_id) 82 { 83 m_activeSPSIndex = active_sps_id; 84 debug_printf("[d3d12_video_bitstream_builder_h264] Setting new active SPS ID: %d ", m_activeSPSIndex); 85 }; set_active_pps_id(uint32_t active_pps_id)86 void set_active_pps_id(uint32_t active_pps_id) 87 { 88 m_activePPSIndex = active_pps_id; 89 debug_printf("[d3d12_video_bitstream_builder_h264] Setting new active PPS ID: %d ", m_activePPSIndex); 90 }; 91 92 private: 93 d3d12_video_nalu_writer_h264 m_h264Encoder; 94 }; 95 96 #endif 97