• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #ifndef _VIDDEC_MPEG2_H
2 #define _VIDDEC_MPEG2_H
3 
4 /**
5  * viddec_mpeg2.h
6  * --------------
7  * This header file contains all the necessary state information and function
8  * prototypes for the MPEG2 parser. This header also defines the debug macros
9  * used by the MPEG2 parser to emit debug messages in host mode.
10  */
11 
12 #include "viddec_fw_debug.h"
13 #include "viddec_parser_ops.h"
14 #include "mpeg2.h"
15 
16 /* Debug Print Macros */
17 #define MPEG2_DEB(x...)        DEB("MPEG2_Parser: "x)
18 #define MPEG2_FA_DEB(x...)     DEB("MPEG2_Frame_attribute: "x)
19 
20 /* Bit masks */
21 #define MPEG2_BIT_MASK_11      0x7ff /* Used for masking Height and Width */
22 #define MPEG2_BIT_MASK_8       0xff  /* Used fro masking start code byte */
23 #define MPEG2_BIT_MASK_4       0xf   /* Used for masking Level */
24 #define MPEG2_BIT_MASK_3       0x7   /* Used for masking Profile */
25 
26 /* MPEG2 Start code and prefix size */
27 #define MPEG2_SC_AND_PREFIX_SIZE 32
28 
29 /* Number of DMEM Workload Items */
30 #define MPEG2_NUM_DMEM_WL_ITEMS 2
31 
32 /* Number of Quantization Matrix Workload Items */
33 #define MPEG2_NUM_QMAT_WL_ITEMS 32
34 
35 /* Maximum supported content size */
36 #define MPEG2_MAX_CONTENT_WIDTH  2048
37 #define MPEG2_MAX_CONTENT_HEIGHT 2048
38 
39 /* Others */
40 #define MPEG2_BITS_EIGHT        8
41 
42 
43 /* MPEG2 Stream Levels */
44 typedef enum {
45     MPEG2_LEVEL_SEQ = 0,
46     MPEG2_LEVEL_GOP,
47     MPEG2_LEVEL_PIC
48 } mpeg2_stream_levels;
49 
50 /* MPEG2 Headers and Extensions */
51 typedef enum {
52     MPEG2_HEADER_NONE           = 0,
53     MPEG2_HEADER_SEQ            = 1 << 0,
54     MPEG2_HEADER_SEQ_EXT        = 1 << 1,
55     MPEG2_HEADER_SEQ_DISP_EXT   = 1 << 2,
56     MPEG2_HEADER_GOP            = 1 << 3,
57     MPEG2_HEADER_PIC            = 1 << 4,
58     MPEG2_HEADER_PIC_COD_EXT    = 1 << 5,
59     MPEG2_HEADER_PIC_DISP_EXT   = 1 << 6,
60     MPEG2_HEADER_SEQ_SCAL_EXT   = 1 << 7
61 } mpeg2_headers;
62 
63 /* MPEG2 Parser Status Codes */
64 typedef enum {
65     MPEG2_SUCCESS            = 0, /* No error */
66     MPEG2_FRAME_COMPLETE     = 1, /* Frame parsing complete found */
67     MPEG2_PARSE_ERROR        = 2, /* Failure in parsing */
68 } mpeg2_status;
69 
70 /* MPEG2 Current Workload Status Codes */
71 typedef enum {
72     MPEG2_WL_EMPTY          = 0,
73     MPEG2_WL_DMEM_DATA      = (1 << 0),
74     MPEG2_WL_REF_INFO       = (1 << 1),
75     MPEG2_WL_PARTIAL_SLICE  = (1 << 2),
76     MPEG2_WL_DANGLING_FIELD = (1 << 3),
77     MPEG2_WL_COMPLETE       = (1 << 4),
78     MPEG2_WL_MISSING_TF     = (1 << 5),
79     MPEG2_WL_MISSING_BF     = (1 << 6),
80     MPEG2_WL_UNSUPPORTED    = (1 << 7),
81     /* Error codes */
82     MPEG2_WL_CORRUPTED_SEQ_HDR      = (1 << 8),
83     MPEG2_WL_CORRUPTED_SEQ_EXT      = (1 << 9),
84     MPEG2_WL_CORRUPTED_SEQ_DISP_EXT = (1 << 10),
85     MPEG2_WL_CORRUPTED_GOP_HDR      = (1 << 11),
86     MPEG2_WL_CORRUPTED_PIC_HDR      = (1 << 12),
87     MPEG2_WL_CORRUPTED_PIC_COD_EXT  = (1 << 13),
88     MPEG2_WL_CORRUPTED_PIC_DISP_EXT = (1 << 14),
89     MPEG2_WL_CORRUPTED_QMAT_EXT     = (1 << 15),
90     /* Error concealment codes */
91     MPEG2_WL_CONCEALED_PIC_COD_TYPE = (1 << 16),
92     MPEG2_WL_CONCEALED_PIC_STRUCT   = (1 << 17),
93     MPEG2_WL_CONCEALED_CHROMA_FMT   = (1 << 18),
94     /* Type of dangling field */
95     MPEG2_WL_DANGLING_FIELD_TOP     = (1 << 24),
96     MPEG2_WL_DANGLING_FIELD_BOTTOM  = (1 << 25),
97     MPEG2_WL_REPEAT_FIELD           = (1 << 26),
98 } mpeg2_wl_status_codes;
99 
100 /* MPEG2 Parser Workload types */
101 typedef enum
102 {
103     /* MPEG2 Decoder Specific data */
104     VIDDEC_WORKLOAD_MPEG2_DMEM = VIDDEC_WORKLOAD_DECODER_SPECIFIC,
105 
106     /* MPEG2 Quantization Matrix data */
107     VIDDEC_WORKLOAD_MPEG2_QMAT,
108 
109     /* Past reference frame */
110     VIDDEC_WORKLOAD_MPEG2_REF_PAST = VIDDEC_WORKLOAD_REF_FRAME_SOURCE_0,
111 
112     /* Future reference frame */
113     VIDDEC_WORKLOAD_MPEG2_REF_FUTURE,
114 
115     /* Use current frame as reference */
116     VIDDEC_WORKLOAD_MPEG2_REF_CURRENT_FRAME,
117 
118     /* User Data */
119     VIDDEC_WORKLOAD_MPEG2_USERDATA = VIDDEC_WORKLOAD_USERDATA
120 } viddec_mpeg2_workloads;
121 
122 /* MPEG2 Decoder Specific Workitems */
123 struct mpeg2_workitems
124 {
125     /* Core Sequence Info 1 */
126     uint32_t csi1;
127 
128     /* Core Sequence Info 2 */
129     uint32_t csi2;
130 
131     /* Core Picture Info 1 */
132     uint32_t cpi1;
133 
134     /* Core Picture Coding Extension Info 1 */
135     uint32_t cpce1;
136 
137     /* Quantization Matrices */
138     /*  0-15: Intra Quantization Matrix */
139     /* 16-31: Non-Intra Quantization Matrix */
140     /* 32-47: Chroma Intra Quantization Matrix */
141     /* 48-63: Chroma Non-Intra Quantization Matrix */
142     uint32_t qmat[MPEG2_QUANT_MAT_SIZE];
143 };
144 
145 /* MPEG2 Video Parser Context */
146 struct viddec_mpeg2_parser
147 {
148     /* MPEG2 Metadata Structure */
149     struct mpeg2_info info;
150 
151     /* MPEG2 Workitems */
152     struct mpeg2_workitems wi;
153 
154     /* Workload Status */
155     uint32_t  mpeg2_wl_status;
156 
157     /* Last parsed start code */
158     int32_t   mpeg2_last_parsed_sc;
159 
160     /* Last parsed slice start code. Used to start emitting workload items. */
161     int32_t   mpeg2_last_parsed_slice_sc;
162 
163     /* Current sequence headers parsed */
164     uint8_t   mpeg2_curr_seq_headers;
165 
166     /* Current frame headers parsed */
167     uint8_t   mpeg2_curr_frame_headers;
168 
169     /* Flag to indicate a valid sequence header was successfully parsed for */
170     /* the current stream. */
171     uint8_t   mpeg2_valid_seq_hdr_parsed;
172 
173     /* Flag to indicate if quantization matrices are updated */
174     uint8_t   mpeg2_custom_qmat_parsed;
175 
176     /* Flag to indicate if reference table is updated with an entry */
177     uint8_t   mpeg2_ref_table_updated;
178 
179     /* Flag to indicate if the stream is MPEG2 */
180     uint8_t   mpeg2_stream;
181 
182     /* Flag to indicate if the previous picture metadata is parsed */
183     uint8_t   mpeg2_pic_metadata_complete;
184 
185     /* Number of active pan scan offsets */
186     uint8_t   mpeg2_num_pan_scan_offsets;
187 
188     /* Indicates the current stream level (Sequence/GOP/Picture) */
189     /* Used for identifying the level for User Data */
190     uint8_t   mpeg2_stream_level;
191 
192     /* Flag to indicate if the current picture is interlaced or not */
193     uint8_t   mpeg2_picture_interlaced;
194 
195     /* Flag to indicate if the current field for interlaced picture is first */
196     /* field or not. This flag is used only when mpeg2_picture_interlaced is */
197     /* set to 1. */
198     uint8_t   mpeg2_first_field;
199 
200     /* Flag to indicate if the current parsed data has start of a frame */
201     uint8_t   mpeg2_frame_start;
202 
203     /* Temporal reference of the previous picture - Used to detect dangling fields */
204     uint32_t  mpeg2_prev_temp_ref;
205 
206     /* Previous picture structure - Used to identify the type of missing field */
207     uint8_t   mpeg2_prev_picture_structure;
208 
209     /* Flag to decide whether to use the current or next workload to dump workitems */
210     uint8_t   mpeg2_use_next_workload;
211     uint8_t   mpeg2_first_slice_flag;
212 };
213 
214 /* External Function Declarations */
215 extern void *memset(void *s, int32_t c, uint32_t n);
216 
217 /* MPEG2 Parser Function Prototypes */
218 void     viddec_mpeg2_translate_attr            (void *parent, void *ctxt);
219 void     viddec_mpeg2_emit_workload             (void *parent, void *ctxt);
220 void     viddec_mpeg2_parse_seq_hdr             (void *parent, void *ctxt);
221 void     viddec_mpeg2_parse_gop_hdr             (void *parent, void *ctxt);
222 void     viddec_mpeg2_parse_pic_hdr             (void *parent, void *ctxt);
223 void     viddec_mpeg2_parse_and_append_user_data(void *parent, void *ctxt);
224 void     viddec_mpeg2_parse_and_append_slice_data(void *parent, void *ctxt);
225 void     viddec_mpeg2_parse_ext                 (void *parent, void *ctxt);
226 
227 /* MPEG2 wrapper functions for workload operations */
228 void    viddec_mpeg2_append_workitem        (void *parent, viddec_workload_item_t *wi, uint8_t flag);
229 void    viddec_mpeg2_append_pixeldata       (void *parent, uint8_t flag);
230 viddec_workload_t*  viddec_mpeg2_get_header (void *parent, uint8_t flag);
231 #endif
232