xref: /aosp_15_r20/external/mesa3d/src/gallium/drivers/d3d12/d3d12_video_encoder_bitstream_builder_h264.h (revision 6104692788411f58d303aa86923a9ff6ecaded22)
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 print_pps(const H264_PPS &pps);
71    void print_sps(const H264_SPS &sps);
72 
get_active_sps()73    const H264_SPS& get_active_sps()
74    {
75       return m_activeSPSStructure;
76    };
get_active_pps()77    const H264_PPS& get_active_pps()
78    {
79       return m_activePPSStructure;
80    };
81 
set_active_sps(H264_SPS & active_sps)82    void set_active_sps(H264_SPS &active_sps)
83    {
84       m_activeSPSStructure = active_sps;
85    };
set_active_pps(H264_PPS & active_pps)86    void set_active_pps(H264_PPS &active_pps)
87    {
88       m_activePPSStructure = active_pps;
89    };
90 
91  private:
92    d3d12_video_nalu_writer_h264 m_h264Encoder;
93    H264_SPS m_activeSPSStructure = {};
94    H264_PPS m_activePPSStructure = {};
95 };
96 
97 #endif
98