1 /*
2 * Copyright (c) 2011 Intel Corporation. All Rights Reserved.
3 * Copyright (c) Imagination Technologies Limited, UK
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sub license, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
12 *
13 * The above copyright notice and this permission notice (including the
14 * next paragraph) shall be included in all copies or substantial portions
15 * of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
20 * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
21 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 *
25 */
26 
27 #ifndef _PTG_JPEG_H_
28 #define _PTG_JPEG_H_
29 
30 #include "img_types.h"
31 #include "tng_hostdefs.h"
32 #include "va/va_enc_jpeg.h"
33 
34 #define QUANT_TABLE_SIZE_BYTES  (64)
35 #define MTX_MAX_COMPONENTS  (3)
36 #define MAX_NUMBER_OF_MTX_UNITS 4 // Number of MTX units
37 
38 typedef enum {
39     IMG_ERR_OK                  = 0,    //!< OK
40     IMG_ERR_SURFACE_LOCKED      = 1,    //!< The requested surface was locked
41     IMG_ERR_MEMORY              = 2,    //!< A memory error occured
42     IMG_ERR_FILE                = 3,    //!< A file error occured
43     IMG_ERR_NOBUFFERAVAILABLE   = 4,    //!< No buffer was available
44     IMG_ERR_COMPLETE            = 5,    //!< Command is complete
45     IMG_ERR_INVALID_CONTEXT     = 6,    //!< An invalid context was given
46     IMG_ERR_INVALID_SIZE        = 7,    //!< An invalid size was given
47     IMG_ERR_TIMEOUT             = 8,    //!< Timeout
48     IMG_ERR_UNDEFINED           = -1
49 
50 } IMG_ERRORCODE;
51 
52 /*****************************************************************************/
53 /*  STREAMTYPEW                                                              */
54 /*  Container to store the stream context                                    */
55 /*****************************************************************************/
56 typedef struct {
57     IMG_UINT8 *Buffer; /*!< Ptr to the bitstream buffer */
58     IMG_UINT32 Offset;  /*!< Offset in the bitstream buffer */
59     IMG_UINT32 Limit;
60 } STREAMTYPEW;
61 
62 
63 typedef struct {
64     IMG_UINT8   aui8LumaQuantParams[QUANT_TABLE_SIZE_BYTES];    //!< Luma quant params
65     IMG_UINT8   aui8ChromaQuantParams[QUANT_TABLE_SIZE_BYTES];  //!< Chroma quant params
66 
67 } JPEG_MTX_QUANT_TABLE;
68 
69 typedef struct {
70     IMG_UINT32  ui32MCUPositionOfScanAndPipeNo; //!< Scan start position in MCUs
71     IMG_UINT32  ui32MCUCntAndResetFlag;     //!< [32:2] Number of MCU's to encode or decode, [1] Reset predictors (1=Reset, 0=No Reset)
72 
73 } MTX_ISSUE_BUFFERS;
74 
75 
76 typedef struct {
77     IMG_UINT32  ui32PhysAddr;   //!< Physical address Component plane in shared memory
78     IMG_UINT32  ui32Stride;     //!< Stride of source plane */
79     IMG_UINT32  ui32Height;     //!< Height of avaliable data in plane.  shall be a minumum of one MCU high
80 
81 } COMPONENTPLANE;
82 
83 typedef struct {
84     IMG_UINT32  ui32WidthBlocks;    //!< Width in pixels, shall be a multiple of 8
85     IMG_UINT32  ui32HeightBlocks;   //!< Height in pixels, shall be a multiple of 8
86     IMG_UINT32  ui32XLimit;         //!< Blocks will not be encoded beyond this
87     IMG_UINT32  ui32YLimit;         //!< Blocks will not be encoded beyond this
88 
89 } MCUCOMPONENT;
90 
91 
92 typedef struct {
93     COMPONENTPLANE  ComponentPlane[MTX_MAX_COMPONENTS]; //!< Array of component plane source information (detailing physical address, stride and height)
94     MCUCOMPONENT    MCUComponent[MTX_MAX_COMPONENTS];   //!< Array of Minimum Coded Unit information for each component plane
95     IMG_UINT32      ui32ComponentsInScan;               //!< Number of components
96     IMG_UINT32      ui32TableA;                         //!< Quantisation table for Luma component
97     IMG_UINT16      ui16DataInterleaveStatus;           //!< Source component interleave status (0, C_INTERLEAVE, LC_UVINTERLEAVE or LC_VUINTERLEAVE)
98     IMG_UINT16      ui16MaxPipes;                       //!< Maximum number of pipes to use in the encode
99 } JPEG_MTX_DMA_SETUP;
100 
101 typedef struct
102 {
103 	IMG_UINT32	apWritebackRegions[WB_FIFO_SIZE];       //!< Data section
104 } JPEG_MTX_WRITEBACK_MEMORY;
105 
106 typedef struct {
107     IMG_UINT32  ui32BytesUsed;      //!<
108     IMG_UINT32  ui32BytesEncoded;   //!<
109     IMG_UINT32  ui32BytesToEncode;  //!<
110     IMG_UINT32  ui32Reserved3;      //!<
111 
112 } BUFFER_HEADER;
113 
114 typedef enum {
115     BUFFER_FREE = 1,  //!< Buffer is not locked
116     HW_LOCK,          //!< Buffer is locked by hardware
117     SW_LOCK,          //!< Buffer is locked by software
118     NOTDEVICEMEMORY,  //!< Buffer is not a device memory buffer
119 
120 } LOCK_STATUS;
121 
122 typedef struct {
123     void* pMemInfo;   //!< Pointer to the memory handle for the buffer
124     LOCK_STATUS sLock;                  //!< Lock status for the buffer
125     IMG_UINT32  ui32Size;               //!< Size in bytes of the buffer
126     IMG_UINT32  ui32BytesWritten;       //!< Number of bytes written into buffer
127 
128 } IMG_BUFFER, IMG_CODED_BUFFER;
129 
130 typedef struct {
131     void *pMemInfo;
132     IMG_UINT16 ui16ScanNumber;
133     IMG_UINT32 ui32WriteBackVal;
134     IMG_INT8 i8PipeNumber; // Doubles as status indicator ( <0 = Awaiting output to CB, 0 = Idle, >0 = Being filled by MTX)
135     IMG_UINT32  MTXOpNum; // Handle returned from MTX issuebuff command, can be used to check for completion
136     IMG_UINT32 ui32DataBufferSizeBytes;
137     IMG_UINT32 ui32DataBufferUsedBytes;
138 } TOPAZHP_JPEG_BUFFER_INFO;
139 
140 typedef struct {
141     IMG_UINT16 ui16CScan;
142     IMG_UINT16 ui16SScan;
143     IMG_UINT16 ui16ScansInImage;
144     IMG_UINT8 ui8MTXIdleCnt;
145     IMG_UINT8 aui8MTXIdleTable[MAX_NUMBER_OF_MTX_UNITS];
146     TOPAZHP_JPEG_BUFFER_INFO *aBufferTable;
147     IMG_UINT32 ui32NumberMCUsX;
148     IMG_UINT32 ui32NumberMCUsY;
149     IMG_UINT32 ui32NumberMCUsToEncode;
150     IMG_UINT32 ui32NumberMCUsToEncodePerScan;
151     IMG_UINT8 ui8NumberOfCodedBuffers;
152 } TOPAZHP_SCAN_ENCODE_INFO;
153 
154 typedef struct {
155     IMG_UINT32 eFormat;
156     IMG_UINT16 ui16Quality;
157     IMG_UINT32 ui32OutputWidth;
158     IMG_UINT32 ui32OutputHeight;
159     IMG_UINT32 ui32InitialCBOffset;
160 
161     object_surface_p pSourceSurface;
162     void *pMemInfoMTXSetup;
163     JPEG_MTX_DMA_SETUP*    pMTXSetup;
164 
165     void *pMemInfoWritebackMemory;
166     JPEG_MTX_WRITEBACK_MEMORY *pMTXWritebackMemory;
167 
168     void *pMemInfoTableBlock;
169     JPEG_MTX_QUANT_TABLE   *psTablesBlock;
170 
171     IMG_UINT32 ui32Offsets[MTX_MAX_COMPONENTS];
172 
173     TOPAZHP_SCAN_ENCODE_INFO sScan_Encode_Info;
174 
175     /* New added elements after porting */
176     void *ctx;
177     IMG_INT32 NumCores;
178     IMG_CODED_BUFFER jpeg_coded_buf;
179     IMG_UINT32 ui32SizePerCodedBuffer;
180     MCUCOMPONENT MCUComponent[MTX_MAX_COMPONENTS];
181 } TOPAZHP_JPEG_ENCODER_CONTEXT;
182 
183 #define PTG_JPEG_MAX_SCAN_NUM 7
184 extern struct format_vtable_s tng_JPEGES_vtable;
185 extern VAStatus tng_jpeg_AppendMarkers(object_context_p obj_context, void *raw_coded_buf);
186 
187 #endif //_PTG_JPEG_H_
188