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(); ~d3d12_video_bitstream_builder_h264()35 ~d3d12_video_bitstream_builder_h264() {}; 36 37 H264_SPS 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 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 H264_PPS build_pps(const enum pipe_video_profile & 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 write_aud(std::vector<uint8_t> & headerBitstream, 67 std::vector<uint8_t>::iterator placingPositionStart, 68 size_t & writtenBytes); 69 70 void write_sei_messages(const std::vector<H264_SEI_MESSAGE>& sei_messages, 71 std::vector<uint8_t> & headerBitstream, 72 std::vector<uint8_t>::iterator placingPositionStart, 73 size_t & writtenBytes); 74 75 void write_slice_svc_prefix(const H264_SLICE_PREFIX_SVC & nal_svc_prefix, 76 std::vector<uint8_t> & headerBitstream, 77 std::vector<uint8_t>::iterator placingPositionStart, 78 size_t & writtenBytes); 79 80 void print_pps(const H264_PPS &pps); 81 void print_sps(const H264_SPS &sps); 82 get_active_sps()83 const H264_SPS& get_active_sps() 84 { 85 return m_activeSPSStructure; 86 }; get_active_pps()87 const H264_PPS& get_active_pps() 88 { 89 return m_activePPSStructure; 90 }; 91 set_active_sps(H264_SPS & active_sps)92 void set_active_sps(H264_SPS &active_sps) 93 { 94 m_activeSPSStructure = active_sps; 95 }; set_active_pps(H264_PPS & active_pps)96 void set_active_pps(H264_PPS &active_pps) 97 { 98 m_activePPSStructure = active_pps; 99 }; 100 101 private: 102 d3d12_video_nalu_writer_h264 m_h264Encoder; 103 H264_SPS m_activeSPSStructure = {}; 104 H264_PPS m_activePPSStructure = {}; 105 }; 106 107 #endif 108