1/* ///////////////////////////////////////////////////////////////////////
2//
3//               INTEL CORPORATION PROPRIETARY INFORMATION
4//  This software is supplied under the terms of a license agreement or
5//  nondisclosure agreement with Intel Corporation and may not be copied
6//  or disclosed except in accordance with the terms of that agreement.
7//        Copyright (c) 2001-2006 Intel Corporation. All Rights Reserved.
8//
9//  Description:    VC1 header.
10//
11*/
12
13#ifndef _VC1_H_
14#define _VC1_H_
15
16#ifdef MFD_FIRMWARE
17   typedef unsigned int size_t;
18   #define LOG(...)
19#else
20   #include <stdio.h>
21   #include <unistd.h>
22   #include <stdint.h>
23   enum {
24      NONE = 0,
25      CRITICAL,
26      WARNING,
27      INFO,
28      DEBUG,
29   } log_level;
30
31   #define vc1_log_level DEBUG
32
33   #define LOG( log_lev, format, args ... ) \
34      if (vc1_log_level >= log_lev) { OS_INFO("%s[%d]:: " format "\n", __FUNCTION__ , __LINE__ ,  ## args ); }
35#endif
36
37#include "viddec_fw_workload.h"
38#include "vc1parse_common_defs.h"
39#include "vc1common.h"
40
41#ifdef __cplusplus
42extern "C" {
43#endif
44
45#define LOG_CRIT(format, args ... )  LOG( CRITICAL, format, ## args)
46#define LOG_WARN(format, args ... )  LOG( WARNING,  format, ## args)
47#define LOG_INFO(format, args ... )  LOG( INFO,     format, ## args)
48#define LOG_DEBUG(format, args ... ) LOG( DEBUG,    format, ## args)
49
50// Seems to be hardware bug: DO NOT TRY TO SWAP BITPLANE0 and BITPLANE2
51// Block Control Register at offset 222C uses Bitplane_raw_ID0 to indicate directmb/fieldtx while
52// and Bitplane_raw_ID2 for acpred/mvtypemb/forwardmb
53// but when we send bitplane index 0 for directmb/fieldtx and bitplane index 2 for acpred/mvtypemb/forwardmb
54// md5 mismatches are seen
55typedef enum
56{
57   BPP_FORWARDMB  =  VIDDEC_WORKLOAD_VC1_BITPLANE0,
58   BPP_ACPRED     =  VIDDEC_WORKLOAD_VC1_BITPLANE0,
59   BPP_MVTYPEMB   =  VIDDEC_WORKLOAD_VC1_BITPLANE0,
60   BPP_OVERFLAGS  =  VIDDEC_WORKLOAD_VC1_BITPLANE1,
61   BPP_SKIPMB     =  VIDDEC_WORKLOAD_VC1_BITPLANE1,
62   BPP_DIRECTMB   =  VIDDEC_WORKLOAD_VC1_BITPLANE2,
63   BPP_FIELDTX    =  VIDDEC_WORKLOAD_VC1_BITPLANE2,
64} vc1_bpp_type_t;
65
66/* status codes */
67typedef enum {
68   VC1_STATUS_EOF          =  1,   // end of file
69   VC1_STATUS_OK           =  0,   // no error
70   VC1_STATUS_NO_MEM       =  2,   // out of memory
71   VC1_STATUS_FILE_ERROR   =  2,   // file error
72   VC1_STATUS_NOTSUPPORT   =  2,   // not supported mode
73   VC1_STATUS_PARSE_ERROR  =  2,   // fail in parse MPEG-4 stream
74   VC1_STATUS_ERROR        =  2    // unknown/unspecified error
75} vc1_Status;
76
77/* VC1 start code values */
78typedef enum {
79   vc1_Forbidden           = 0x80,/*0x80-0xFF*/
80   vc1_Reserved1           = 0x09,/*0x00-0x09*/
81   vc1_Reserved2           = 0x10,
82   vc1_Reserved3           = 0x1A,
83   vc1_Reserved4           = 0x20,/*0x20-0x7F*/
84   vc1_SCEndOfSequence     = 0x0A,
85   vc1_SCSlice             = 0x0B,
86   vc1_SCField             = 0x0C,
87   vc1_SCFrameHeader       = 0x0D,
88   vc1_SCEntryPointHeader  = 0x0E,
89   vc1_SCSequenceHeader    = 0x0F,
90   vc1_SCSliceUser         = 0x1B,
91   vc1_SCFieldUser         = 0x1C,
92   vc1_SCFrameUser         = 0x1D,
93   vc1_SCEntryPointUser    = 0x1E,
94   vc1_SCSequenceUser      = 0x1F
95} vc1_sc;
96
97#if 0
98typedef enum
99{
100   vc1_ProfileSimple = 0,  /** Simple profile */
101   vc1_ProfileMain,        /** Main profile */
102   vc1_ProfileReserved,    /** Reserved */
103   vc1_ProfileAdvanced     /** Advanced profile */
104} vc1_Profile;
105#endif
106
107typedef enum
108{
109   vc1_PtypeI  = 1,
110   vc1_PtypeP  = 2,
111   vc1_PtypeB  = 4,
112   vc1_PtypeBI = 5,
113   vc1_PtypeSkipped = 8|2,
114} vc1_ptype;
115
116typedef enum
117{
118   vc1_PtypeII = 0,
119   vc1_PtypeIP = 1,
120   vc1_PtypePI = 2,
121   vc1_PtypePP = 3,
122   vc1_PtypeBB = 4,
123   vc1_PtypeBBI = 5,
124   vc1_PtypeBIB = 6,
125   vc1_PtypeBIBI = 7
126} vc1_fptype;
127
128typedef enum
129{
130   vc1_Imode_Raw  = 0,         //0x0000
131   vc1_Imode_Norm2,        //0x10
132   vc1_Imode_Diff2,        //0x001
133   vc1_Imode_Norm6,        //0x11
134   vc1_Imode_Diff6,        //0x0001
135   vc1_Imode_Rowskip,      //0x010
136   vc1_Imode_Colskip,      //0x011
137} vc1_Imode;
138
139/* calculation of MAX_BITPLANE_SZ 2048/16x1088/16 pel= 128x68 bit used for bitplane
140 * as rows are packed in DWORDS
141 * we have (128)/32 * 68 Dwords needed for bitplane storage
142 */
143#define MAX_BITPLANE_SZ 272
144
145/* Full Info */
146typedef struct {
147   unsigned char*       bufptr;         /* current frame, point to header or data */
148   int                  bitoff;         /* mostly point to next frame header or PSC */
149   int                  picture_info_has_changed;
150   vc1_metadata_t       metadata;
151   vc1_PictureLayerHeader picLayerHeader;
152   uint32_t             bitplane[MAX_BITPLANE_SZ];
153} vc1_Info;
154
155#ifdef __cplusplus
156}
157#endif
158
159enum {
160   VC1_REF_FRAME_T_MINUS_1 = 0,
161   VC1_REF_FRAME_T_MINUS_2,
162   VC1_REF_FRAME_T_MINUS_0,
163   VC1_NUM_REFERENCE_FRAMES,
164};
165
166enum vc1_sc_seen_flags
167{
168    VC1_SC_INVALID = 0 << 0,
169    VC1_SC_SEQ     = 1 << 0,
170    VC1_SC_EP      = 1 << 1,
171    VC1_SC_FRM     = 1 << 2,
172    VC1_SC_FLD     = 1 << 3,
173    VC1_SC_SLC     = 1 << 4,
174    VC1_SC_UD      = 1 << 5,
175};
176#define VC1_SEQ_MASK VC1_SC_SEQ
177#define VC1_EP_MASK VC1_SC_SEQ | VC1_SC_EP
178#define VC1_FRM_MASK VC1_SC_SEQ | VC1_SC_EP | VC1_SC_FRM
179#define VC1_FLD_MASK VC1_SC_SEQ | VC1_SC_EP | VC1_SC_FRM | VC1_SC_FLD
180
181typedef struct {
182   int id;
183   uint32_t intcomp_top;
184   uint32_t intcomp_bot;
185   int fcm;         /* frame coding mode */
186   int type;
187   int anchor[2];   /* one per field */
188   int rr_en;       /* range reduction enable flag at sequence layer */
189   int rr_frm;      /* range reduction flag at picture layer */
190} ref_frame_t;
191
192typedef struct
193{
194    uint32_t      sc_seen_since_last_wkld;
195    uint32_t      sc_seen;
196    uint32_t      is_frame_start;
197	uint8_t is_reference_picture;
198    uint32_t      intcomp_last[4]; /* for B frames */
199    uint32_t      intcomp_top[2];
200    uint32_t      intcomp_bot[2];
201    vc1_Info      info;
202    VC1D_SPR_REGS spr;
203    ref_frame_t   ref_frame[VC1_NUM_REFERENCE_FRAMES];
204#ifdef VBP
205    /* A storage area is provided for each type of bit plane.  Only one of */
206    /* each type will ever be used for a picture and never more than three */
207    /* bit-planes per picture, and often only one is used.  We never clear */
208    /* this data and writes into it when we need to.  vc1parse_bitplane.c  */
209    /* makes use of these set them to one of the bitplane types included   */
210    /* in the picture header structure.  Those sturctures are set every    */
211    /* time a picture parse begins. */
212    uint32_t      bp_forwardmb[4096];
213    uint32_t      bp_acpred[4096];
214    uint32_t      bp_mvtypemb[4096];
215    uint32_t      bp_overflags[4096];
216    uint32_t      bp_skipmb[4096];
217    uint32_t      bp_directmb[4096];
218    uint32_t      bp_fieldtx[4096];
219    uint32_t	  start_code;
220#endif
221} vc1_viddec_parser_t;
222
223#endif  //_VC1_H_
224
225