rocprofiler-sdk/rocdecode/details/rocparser.h Source File

rocprofiler-sdk/rocdecode/details/rocparser.h Source File#

Rocprofiler SDK Developer API: rocprofiler-sdk/rocdecode/details/rocparser.h Source File
Rocprofiler SDK Developer API 0.6.0
ROCm Profiling API and tools
rocparser.h
Go to the documentation of this file.
1/*
2Copyright (c) 2024 - 2025 Advanced Micro Devices, Inc. All rights reserved.
3
4Permission is hereby granted, free of charge, to any person obtaining a copy
5of this software and associated documentation files (the "Software"), to deal
6in the Software without restriction, including without limitation the rights
7to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8copies of the Software, and to permit persons to whom the Software is
9furnished to do so, subject to the following conditions:
10
11The above copyright notice and this permission notice shall be included in
12all copies or substantial portions of the Software.
13
14THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20THE SOFTWARE.
21*/
22
23#pragma once
24
25#if !defined(ROCPROFILER_SDK_USE_SYSTEM_ROCDECODE)
26# if defined __has_include
27# if __has_include(<rocdecode/rocdecode.h>)
28# define ROCPROFILER_SDK_USE_SYSTEM_ROCDECODE 1
29# else
30# define ROCPROFILER_SDK_USE_SYSTEM_ROCDECODE 0
31# endif
32# else
33# define ROCPROFILER_SDK_USE_SYSTEM_ROCDECODE 0
34# endif
35#endif
36
37#if ROCPROFILER_SDK_USE_SYSTEM_ROCDECODE > 0
38# include <rocdecode/rocdecode.h>
39#else
41#endif
42
43/*!
44 * \file
45 * \brief The AMD rocParser Library.
46 *
47 * \defgroup group_rocparser rocDecode Parser: AMD ROCm Video Parser API
48 * \brief AMD The rocDecode video parser for AMD’s GPUs.
49 * \defgroup group_rocdec_struct rocDecode Parser Structs: AMD ROCm Video Parser Structs
50 * \brief AMD The rocDecode video parser struct
51 */
52
53#if defined(__cplusplus)
54extern "C" {
55#endif /* __cplusplus */
56
57/*********************************************************************************/
58//! HANDLE pf rocDecDecoder
59//! Used in subsequent API calls after rocDecCreateDecoder
60/*********************************************************************************/
61
62typedef void* RocdecVideoParser;
63typedef uint64_t RocdecTimeStamp;
64
65/**
66 * @brief ROCDEC_VIDEO_FORMAT struct
67 * @ingroup group_rocdec_struct
68 * Used in Parser callback API
69 */
70typedef struct
71{
72 rocDecVideoCodec codec; /**< OUT: Compression format */
73 /**
74 * OUT: frame rate = numerator / denominator (for example: 30000/1001)
75 */
76 struct
77 {
78 /**< OUT: frame rate numerator (0 = unspecified or variable frame rate) */
79 uint32_t numerator;
80 /**< OUT: frame rate denominator (0 = unspecified or variable frame rate) */
81 uint32_t denominator;
82 } frame_rate;
83 uint8_t progressive_sequence; /**< OUT: 0=interlaced, 1=progressive */
84 uint8_t bit_depth_luma_minus8; /**< OUT: high bit depth luma. E.g, 2 for 10-bitdepth, 4 for
85 12-bitdepth */
86 uint8_t bit_depth_chroma_minus8; /**< OUT: high bit depth chroma. E.g, 2 for 10-bitdepth, 4 for
87 12-bitdepth */
88 uint8_t min_num_decode_surfaces; /**< OUT: Minimum number of decode surfaces to be allocated for
89 correct decoding. The client can send this value in
90 num_decode_surfaces. This guarantees correct functionality
91 and optimal video memory usage but not necessarily the best
92 performance, which depends on the design of the overall
93 application. The optimal number of decode surfaces (in terms
94 of performance and memory utilization) should be decided by
95 experimentation for each application, but it cannot go below
96 min_num_decode_surfaces. If this value is used for
97 num_decode_surfaces then it must be returned to parser
98 during sequence callback. */
99 uint32_t coded_width; /**< OUT: coded frame width in pixels */
100 uint32_t coded_height; /**< OUT: coded frame height in pixels */
101 /**
102 * area of the frame that should be displayed
103 * typical example:
104 * coded_width = 1920, coded_height = 1088
105 * display_area = { 0,0,1920,1080 }
106 */
107 struct
108 {
109 int left; /**< OUT: left position of display rect */
110 int top; /**< OUT: top position of display rect */
111 int right; /**< OUT: right position of display rect */
112 int bottom; /**< OUT: bottom position of display rect */
113 } display_area;
114
115 rocDecVideoChromaFormat chroma_format; /**< OUT: Chroma format */
116 uint32_t bitrate; /**< OUT: video bitrate (bps, 0=unknown) */
117 /**
118 * OUT: Display Aspect Ratio = x:y (4:3, 16:9, etc)
119 */
120 struct
121 {
122 int x;
123 int y;
124 } display_aspect_ratio;
125 /**
126 * Video Signal Description
127 * Refer section E.2.1 (VUI parameters semantics) of H264 spec file
128 */
129 struct
130 {
131 uint8_t video_format : 3; /**< OUT: 0-Component, 1-PAL, 2-NTSC, 3-SECAM, 4-MAC,
132 5-Unspecified */
133 uint8_t video_full_range_flag : 1; /**< OUT: indicates the black level and luma and chroma
134 range */
135 uint8_t reserved_zero_bits : 4; /**< Reserved bits */
136 uint8_t color_primaries; /**< OUT: chromaticity coordinates of source primaries */
137 uint8_t transfer_characteristics; /**< OUT: opto-electronic transfer characteristic of the
138 source picture */
139 uint8_t matrix_coefficients; /**< OUT: used in deriving luma and chroma signals from RGB
140 primaries */
141 } video_signal_description;
142 uint32_t seqhdr_data_length; /**< OUT: Additional bytes following (RocdecVideoFormatEx) */
144
145/****************************************************************/
146//! \ingroup group_rocdec_struct
147//! \struct RocdecVideoFormat
148//! Video format including raw sequence header information
149//! Used in rocDecCreateVideoParser API
150/****************************************************************/
151typedef struct
152{
153 RocdecVideoFormat format; /**< OUT: RocdecVideoFormat structure */
154 uint32_t max_width;
155 uint32_t max_height;
156 uint8_t raw_seqhdr_data[1024]; /**< OUT: Sequence header data */
158
159/***************************************************************/
160//! \enum RocdecVideoPacketFlags
161//! Data packet flags
162//! Used in RocdecSourceDataPacket structure
163/***************************************************************/
164typedef enum
165{
166 ROCDEC_PKT_ENDOFSTREAM = 0x01, /**< Set when this is the last packet for this stream */
167 ROCDEC_PKT_TIMESTAMP = 0x02, /**< Timestamp is valid */
168 ROCDEC_PKT_DISCONTINUITY = 0x04, /**< Set when a discontinuity has to be signalled */
170 0x08, /**< Set when the packet contains exactly one frame or one field */
172 0x10, /**< If this flag is set along with ROCDEC_PKT_ENDOFSTREAM, an additional (dummy)
173 display callback will be invoked with null value of ROCDECPARSERDISPINFO which
174 should be interpreted as end of the stream. */
176
177/*****************************************************************************/
178//! \ingroup group_rocdec_struct
179//! \struct RocdecSourceDataPacket
180//! Data Packet
181//! Used in rocDecParseVideoData API
182//! IN for rocDecParseVideoData
183/*****************************************************************************/
184typedef struct _RocdecSourceDataPacket
185{
186 uint32_t flags; /**< IN: Combination of ROCDEC_PKT_XXX flags */
187 uint32_t
188 payload_size; /**< IN: number of bytes in the payload (may be zero if EOS flag is set) */
189 const uint8_t*
190 payload; /**< IN: Pointer to packet payload data (may be NULL if EOS flag is set) */
191 RocdecTimeStamp pts; /**< IN: Presentation time stamp (10MHz clock), only valid if
192 ROCDEC_PKT_TIMESTAMP flag is set */
194
195/**********************************************************************************/
196/*! \brief Timing Info struct
197 * \ingroup group_rocdec_struct
198 * \struct RocdecParserDispInfo
199 * \Used in rocdecParseVideoData API with PFNVIDDISPLAYCALLBACK pfn_display_picture
200 */
201/**********************************************************************************/
202typedef struct _RocdecParserDispInfo
203{
204 int picture_index; /**< OUT: Index of the current picture */
205 int progressive_frame; /**< OUT: 1 if progressive frame; 0 otherwise */
206 int top_field_first; /**< OUT: 1 if top field is displayed first; 0 otherwise */
207 int repeat_first_field; /**< OUT: Number of additional fields (1=ivtc, 2=frame doubling, 4=frame
208 tripling, -1=unpaired field) */
209 RocdecTimeStamp pts; /**< OUT: Presentation time stamp */
211
212/**
213 * @brief RocdecOperatingPointInfo struct
214 * @ingroup group_rocdec_struct
215 * Operating point information of scalable bitstream
216 */
217typedef struct _RocdecOperatingPointInfo
218{
220 union
221 {
222 struct
223 {
224 uint8_t operating_points_cnt;
225 uint8_t reserved24_bits[3];
226 uint16_t operating_points_idc[32];
227 } av1;
228 uint8_t codec_reserved[1024];
229 };
231
232/**********************************************************************************/
233//! \ingroup group_rocdec_struct
234//! \struct RocdecSeiMessage;
235//! Used in RocdecSeiMessageInfo structure
236/**********************************************************************************/
237typedef struct _RocdecSeiMessage
238{
239 uint8_t sei_message_type; /**< OUT: SEI Message Type */
240 uint8_t reserved[3];
241 uint32_t sei_message_size; /**< OUT: SEI Message Size */
243
244/**********************************************************************************/
245//! \ingroup group_rocdec_struct
246//! \struct RocdecSeiMessageInfo
247//! Used in rocDecParseVideoData API with PFNVIDSEIMSGCALLBACK pfn_get_sei_msg
248/**********************************************************************************/
249typedef struct _RocdecSeiMessageInfo
250{
251 void* sei_data; /**< OUT: SEI Message Data */
252 RocdecSeiMessage* sei_message; /**< OUT: SEI Message Info */
253 uint32_t sei_message_count; /**< OUT: SEI Message Count */
254 uint32_t picIdx; /**< OUT: SEI Message Pic Index */
256
257/**
258 * @brief Parser callbacks
259 * \ The parser will call these synchronously from within rocDecParseVideoData(), whenever there is
260 * sequence change or a picture \ is ready to be decoded and/or displayed. \ Return values from
261 * these callbacks are interpreted as below. If the callbacks return failure, it will be propagated
262 * by \ rocDecParseVideoData() to the application. \ Parser picks default operating point as 0 and
263 * outputAllLayers flag as 0 if PFNVIDOPPOINTCALLBACK is not set or return value is \ -1 or invalid
264 * operating point. \ PFNVIDSEQUENCECALLBACK : 0: fail, 1: succeeded, > 1: override dpb size of
265 * parser (set by RocdecParserParams::max_num_decode_surfaces \ while creating parser) \
266 * PFNVIDDECODECALLBACK : 0: fail, >=1: succeeded \ PFNVIDDISPLAYCALLBACK : 0: fail, >=1:
267 * succeeded \ PFNVIDOPPOINTCALLBACK : <0: fail, >=0: succeeded (bit 0-9: OperatingPoint, bit
268 * 10-10: outputAllLayers, bit 11-30: reserved) \ PFNVIDSEIMSGCALLBACK : 0: fail, >=1: succeeded
269 */
273// typedef int (ROCDECAPI *PFNVIDOPPOINTCALLBACK)(void *, RocdecOperatingPointInfo*); //
274// reserved for future (AV1 specific)
276
277/**
278 * \brief The AMD rocDecode library.
279 * \ingroup group_rocdec_struct
280 * \Used in rocDecCreateVideoParser API
281 */
282typedef struct _RocdecParserParams
283{
284 rocDecVideoCodec codec_type; /**< IN: rocDecVideoCodec_XXX */
285 uint32_t max_num_decode_surfaces; /**< IN: Max # of decode surfaces (parser will cycle through
286 these) */
287 uint32_t clock_rate; /**< IN: Timestamp units in Hz (0=default=10000000Hz) */
288 uint32_t error_threshold; /**< IN: % Error threshold (0-100) for calling pfn_decode_picture
289 (100=always IN: call pfn_decode_picture even if picture bitstream
290 is fully corrupted) */
291 uint32_t max_display_delay; /**< IN: Max display queue delay (improves pipelining of decode with
292 display) 0 = no delay (recommended values: 2..4) */
293 uint32_t annex_b : 1; /**< IN: AV1 annexB stream */
294 uint32_t reserved : 31; /**< Reserved for future use - set to zero */
295 uint32_t reserved_1[4]; /**< IN: Reserved for future use - set to 0 */
296 void* user_data; /**< IN: User data for callbacks */
297 PFNVIDSEQUENCECALLBACK pfn_sequence_callback; /**< IN: Called before decoding frames and/or
298 whenever there is a fmt change */
299 PFNVIDDECODECALLBACK pfn_decode_picture; /**< IN: Called when a picture is ready to be decoded
300 (decode order) */
301 PFNVIDDISPLAYCALLBACK pfn_display_picture; /**< IN: Called whenever a picture is ready to be
302 displayed (display order) */
304 pfn_get_sei_msg; /**< IN: Called when all SEI messages are parsed for particular frame */
305 void* reserved_2[5]; /**< Reserved for future use - set to NULL */
307 ext_video_info; /**< IN: [Optional] sequence header data from system layer */
309
310/************************************************************************************************/
311//! \ingroup group_rocparser
312//! \fn rocDecodeStatus ROCDECAPI rocDecCreateVideoParser(RocdecVideoParser *parser_handle,
313//! RocdecParserParams *params) Create video parser object and initialize
314/************************************************************************************************/
317
318/************************************************************************************************/
319//! \ingroup group_rocparser
320//! \fn rocDecodeStatus ROCDECAPI rocDecParseVideoData(RocdecVideoParser parser_handle,
321//! RocdecSourceDataPacket *packet) Parse the video data from source data packet in pPacket Extracts
322//! parameter sets like SPS, PPS, bitstream etc. from pPacket and calls back pfn_decode_picture with
323//! RocdecPicParams data for kicking of HW decoding calls back pfn_sequence_callback with
324//! RocdecVideoFormat data for initial sequence header or when the decoder encounters a video format
325//! change calls back pfn_display_picture with RocdecParserDispInfo data to display a video frame
326/************************************************************************************************/
329
330/************************************************************************************************/
331//! \ingroup group_rocparser
332//! \fn rocDecStatus ROCDECAPI rocDecParserMarkFrameForReuse(RocdecVideoParser parser_handle, int
333//! pic_idx) Mark frame with index pic_idx in parser's buffer pool for reuse (means the frame has
334//! been consumed)
335/************************************************************************************************/
338
339/************************************************************************************************/
340//! \ingroup group_rocparser
341//! \fn rocDecStatus ROCDECAPI rocDecDestroyVideoParser(RocdecVideoParser parser_handle)
342//! Destroy the video parser object
343/************************************************************************************************/
346
347#if defined(__cplusplus)
348}
349#endif /* __cplusplus */
uint32_t coded_height
Definition rocparser.h:100
rocDecVideoChromaFormat chroma_format
Definition rocparser.h:115
uint8_t bit_depth_luma_minus8
Definition rocparser.h:84
uint8_t sei_message_type
Definition rocparser.h:239
const uint8_t * payload
Definition rocparser.h:190
RocdecTimeStamp pts
Definition rocparser.h:191
RocdecSeiMessage * sei_message
Definition rocparser.h:252
uint32_t seqhdr_data_length
Definition rocparser.h:142
rocDecVideoCodec codec_type
Definition rocparser.h:284
uint32_t sei_message_count
Definition rocparser.h:253
RocdecVideoFormatEx * ext_video_info
Definition rocparser.h:307
PFNVIDDISPLAYCALLBACK pfn_display_picture
Definition rocparser.h:301
uint32_t clock_rate
Definition rocparser.h:287
uint32_t coded_width
Definition rocparser.h:99
uint32_t max_display_delay
Definition rocparser.h:291
PFNVIDSEIMSGCALLBACK pfn_get_sei_msg
Definition rocparser.h:304
PFNVIDSEQUENCECALLBACK pfn_sequence_callback
Definition rocparser.h:297
rocDecVideoCodec codec
Definition rocparser.h:219
RocdecTimeStamp pts
Definition rocparser.h:209
uint32_t sei_message_size
Definition rocparser.h:241
PFNVIDDECODECALLBACK pfn_decode_picture
Definition rocparser.h:299
uint8_t bit_depth_chroma_minus8
Definition rocparser.h:86
uint8_t min_num_decode_surfaces
Definition rocparser.h:88
uint32_t max_num_decode_surfaces
Definition rocparser.h:285
uint32_t error_threshold
Definition rocparser.h:288
rocDecVideoCodec codec
Definition rocparser.h:72
uint8_t progressive_sequence
Definition rocparser.h:83
RocdecOperatingPointInfo structOperating point information of scalable bitstream.
Definition rocparser.h:218
Timing Info struct\Used in rocdecParseVideoData API with PFNVIDDISPLAYCALLBACK pfn_display_picture.
Definition rocparser.h:203
The AMD rocDecode library.\Used in rocDecCreateVideoParser API.
Definition rocparser.h:283
Used in RocdecSeiMessageInfo structure.
Definition rocparser.h:238
Used in rocDecParseVideoData API with PFNVIDSEIMSGCALLBACK pfn_get_sei_msg.
Definition rocparser.h:250
Data Packet Used in rocDecParseVideoData API IN for rocDecParseVideoData.
Definition rocparser.h:185
ROCDEC_VIDEO_FORMAT structUsed in Parser callback API.
Definition rocparser.h:71
The AMD rocDecode Library.
rocDecStatus
Definition rocdecode.h:78
rocDecVideoCodec
Definition rocdecode.h:97
rocDecVideoChromaFormat
Definition rocdecode.h:151
#define ROCDECAPI
Definition rocdecode.h:29
RocdecVideoFormat format
Definition rocparser.h:153
RocdecVideoPacketFlags
Data packet flags Used in RocdecSourceDataPacket structure.
Definition rocparser.h:165
@ ROCDEC_PKT_TIMESTAMP
Definition rocparser.h:167
@ ROCDEC_PKT_ENDOFPICTURE
Definition rocparser.h:169
@ ROCDEC_PKT_DISCONTINUITY
Definition rocparser.h:168
@ ROCDEC_PKT_NOTIFY_EOS
Definition rocparser.h:171
@ ROCDEC_PKT_ENDOFSTREAM
Definition rocparser.h:166
void * RocdecVideoParser
HANDLE pf rocDecDecoder Used in subsequent API calls after rocDecCreateDecoder.
Definition rocparser.h:62
int(ROCDECAPI * PFNVIDDISPLAYCALLBACK)(void *, RocdecParserDispInfo *)
Definition rocparser.h:272
rocDecStatus ROCDECAPI rocDecParserMarkFrameForReuse(RocdecVideoParser parser_handle, int pic_idx)
int(ROCDECAPI * PFNVIDDECODECALLBACK)(void *, RocdecPicParams *)
Definition rocparser.h:271
int(ROCDECAPI * PFNVIDSEIMSGCALLBACK)(void *, RocdecSeiMessageInfo *)
Definition rocparser.h:275
uint64_t RocdecTimeStamp
Definition rocparser.h:63
rocDecStatus ROCDECAPI rocDecDestroyVideoParser(RocdecVideoParser parser_handle)
rocDecStatus ROCDECAPI rocDecParseVideoData(RocdecVideoParser parser_handle, RocdecSourceDataPacket *packet)
rocDecStatus ROCDECAPI rocDecCreateVideoParser(RocdecVideoParser *parser_handle, RocdecParserParams *params)
int(ROCDECAPI * PFNVIDSEQUENCECALLBACK)(void *, RocdecVideoFormat *)
Parser callbacks \ The parser will call these synchronously from within rocDecParseVideoData(),...
Definition rocparser.h:270