1 /*
2 * Copyright (c) 2019, Intel 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 shall be included
12 * in all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
21 */
22 //!
23 //! \file     encode_back_annotation_packet.h
24 //! \brief    Defines the implementation of AV1 back annotation packet
25 //!
26 
27 #ifndef __CODECHAL_BACK_ANNOTATION_PACKET_H__
28 #define __CODECHAL_BACK_ANNOTATION_PACKET_H__
29 
30 #include "media_cmd_packet.h"
31 #include "encode_huc.h"
32 #include "media_pipeline.h"
33 #include "codec_hw_next.h"
34 #include "encode_utils.h"
35 #include "encode_av1_basic_feature.h"
36 
37 namespace encode
38 {
39     enum AnnotationTypes
40     {
41         frame_header_obu = 0,
42         TileGroupOBU = 1
43     };
44 
45     // // 64-byte alignment
46     struct VdencAv1HucBackAnnotationDmem
47     {
48         uint32_t     firstTileGroupByteOffset;  // Tile Size Records, start offset  in byte, 0xffffffff means unavailable
49         uint32_t     reserved_32[31];           // reserved mbz
50         uint16_t     reserved_16[64];          // reserved mbz
51 
52         uint8_t      tileGroupNumber;
53         uint8_t      backAnnotationType;       // 0: frame_header_obu, 1:TileGroupOBU
54         uint8_t      reserved_8[62];           // reserved mbz
55     };
56 
57     struct VdencAv1HucCtrlBigData
58     {
59         uint32_t      OBUSizeByteOffset[ENCODE_VDENC_AV1_MAX_TILE_GROUP_NUM];        // the obu_size location
60         uint8_t      tileNumberPerGroup[ENCODE_VDENC_AV1_MAX_TILE_GROUP_NUM];
61     };
62 
63     class Av1BackAnnotationPkt : public EncodeHucPkt
64     {
65     public:
Av1BackAnnotationPkt(MediaPipeline * pipeline,MediaTask * task,CodechalHwInterfaceNext * hwInterface)66         Av1BackAnnotationPkt(MediaPipeline *pipeline, MediaTask *task, CodechalHwInterfaceNext *hwInterface) :
67             EncodeHucPkt(pipeline, task, hwInterface)
68         {
69         }
70 
~Av1BackAnnotationPkt()71         virtual ~Av1BackAnnotationPkt() {}
72 
73         virtual MOS_STATUS Init() override;
74 
75         //!
76         //! \brief  Prepare interal parameters, should be invoked for each frame
77         //! \param  [in] params
78         //!         Pointer to the input parameters
79         //! \return MOS_STATUS
80         //!         MOS_STATUS_SUCCESS if success, else fail reason
81         //!
82         virtual MOS_STATUS Prepare() override;
83 
84         MOS_STATUS Submit(MOS_COMMAND_BUFFER *commandBuffer, uint8_t packetPhase = otherPacket) override;
85 
86         //!
87         //! \brief  Calculate Command Size
88         //!
89         //! \param  [in, out] commandBufferSize
90         //!         requested size
91         //! \param  [in, out] requestedPatchListSize
92         //!         requested size
93         //! \return MOS_STATUS
94         //!         status
95         //!
96         virtual MOS_STATUS CalculateCommandSize(
97             uint32_t &commandBufferSize,
98             uint32_t &requestedPatchListSize) override;
99 
100         //!
101         //! \brief  Get Packet Name
102         //! \return std::string
103         //!
GetPacketName()104         virtual std::string GetPacketName() override
105         {
106             return "BACK_ANNOTATION";
107         }
108 
109         //!
110         //! \brief  One frame is completed
111         //! \param  [in] mfxStatus
112         //!         pointer to status buffer which for MFX
113         //! \param  [in] rcsStatus
114         //!         pointer to status buffer which for RCS
115         //! \param  [in, out] statusReport
116         //!         pointer of EncoderStatusReport
117         //! \return MOS_STATUS
118         //!         MOS_STATUS_SUCCESS if success, else fail reason
119         //!
120         virtual MOS_STATUS Completed(void *mfxStatus, void *rcsStatus, void *statusReport) override;
121 
122     protected:
123         virtual MOS_STATUS AllocateResources() override;
124 
125         virtual MOS_STATUS SetDmemBuffer();
126 
127         virtual MOS_STATUS SetHucCtrlBuffer();
128 
129 #if USE_CODECHAL_DEBUG_TOOL
130         virtual MOS_STATUS DumpBackAnnotation();
131         virtual MOS_STATUS DumpOutput() override;
132 #endif
133         static constexpr uint32_t               m_vdboxHucBackAnnonationKernelDescriptor = 17;   //!< Huc AV1 back annotation kernel descriptor
134         static constexpr uint32_t               m_numBytesOfOBUSize = 4;   //!< byte number for OBU size
135 
136         uint32_t m_vdencbackAnnotationDmemBufferSize = sizeof(VdencAv1HucBackAnnotationDmem);
137         PMOS_RESOURCE m_vdencBackAnnotationDmemBuffer[CODECHAL_ENCODE_RECYCLED_BUFFER_NUM][VDENC_BRC_NUM_OF_PASSES] = {}; //!< Huc AV1 back annotation DMEM buffer
138 
139         uint32_t m_vdencAv1HucCtrlBufferSize = sizeof(VdencAv1HucCtrlBigData);
140         PMOS_RESOURCE m_vdencAv1HucCtrlBuffer[CODECHAL_ENCODE_RECYCLED_BUFFER_NUM][VDENC_BRC_NUM_OF_PASSES] = {}; //!< Huc AV1 back annotation DMEM buffer
141 
142         Av1BasicFeature    *m_basicFeature = nullptr;  //!< AV1 Basic Feature used in each frame
143 
144     MEDIA_CLASS_DEFINE_END(encode__Av1BackAnnotationPkt)
145     };
146 
147 }  // namespace encode
148 #endif
149