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) 2008 Intel Corporation. All Rights Reserved.
8 //
9 //  Description: Common functions for parsing VC-1 bitstreams.
10 //
11 */
12 
13 #ifndef _VC1PARSE_H_
14 #define _VC1PARSE_H_
15 
16 #include "viddec_parser_ops.h"
17 #include "vc1.h"
18 
19 /** @weakgroup vc1parse_defs VC-1 Parse Definitions */
20 /** @ingroup vc1parse_defs */
21 /*@{*/
22 
23 /* This macro gets the next less-than-nine bits from the bitstream.  It is
24 assumed that numBits is less than ten. */
25 #ifdef VC1_VERBOSE
26 #include <stdio.h>
27 #define AUTO_TRACE OS_INFO("trace: %s\n", __FUNCTION__)
28 #define DEBUGBITS(arg1, args ...) OS_INFO( arg1, ## args)
29 #else
30 #define AUTO_TRACE
31 #define DEBUGBITS(...)
32 #endif
33 
34 extern void *memset(void *s, int32_t c, uint32_t n);
35 
36 /* This macro gets the next numBits from the bitstream. */
37 #define VC1_GET_BITS VC1_GET_BITS9
38 #define VC1_GET_BITS9(numBits, value) \
39 {   uint32_t __tmp__; \
40     viddec_pm_get_bits(ctxt, (uint32_t*)&__tmp__, numBits ); \
41     value = __tmp__;\
42     DEBUGBITS("BIT:%40s= 0x%x\tNo. of bits=%d\tbyte = %02x\t%s[%d]\n", #value, value, numBits, 0, __FILE__, __LINE__); \
43 }
44 
45 #define VC1_PEEK_BITS(numBits, value) \
46 {   uint32_t __tmp__; \
47     viddec_pm_peek_bits(ctxt, (uint32_t*)&__tmp__, numBits ); \
48     value = __tmp__;\
49     DEBUGBITS("PEEK%40s= 0x%x\tNo. of bits=%d\tbyte = %02x\t%s[%d]\n", #value, value, numBits, 0, __FILE__, __LINE__); \
50 }
51 
52 /* This macro asserts if the condition is not true. */
53 #ifdef VC1_VERBOSE
54 #define VC1_ASSERT(condition) \
55 { \
56     if (! (condition)) \
57         OS_INFO("Failed " #condition "!\n"); \
58 }
59 #else
60 #define VC1_ASSERT(condition)
61 #endif
62 
63 /*@}*/
64 
65 /** @weakgroup vc1parse VC-1 Parse Functions */
66 /** @ingroup vc1parse */
67 /*@{*/
68 
69 extern const uint8_t VC1_MVMODE_LOW_TBL[];
70 extern const uint8_t VC1_MVMODE_HIGH_TBL[];
71 extern const int32_t VC1_BITPLANE_IMODE_TBL[];
72 extern const int32_t VC1_BITPLANE_K_TBL[];
73 extern const int32_t VC1_BFRACTION_TBL[];
74 extern const int32_t VC1_REFDIST_TBL[];
75 
76 void vc1_end_frame(vc1_viddec_parser_t *parser);
77 
78 /* Top-level functions to parse bitstream layers for rcv format. */
79 vc1_Status vc1_ParseRCVSequenceLayer (void* ctxt, vc1_Info *pInfo);
80 
81 /* Top-level functions to parse bitstream layers for the various profiles. */
82 vc1_Status vc1_ParseSequenceLayer(void* ctxt, vc1_Info *pInfo);
83 vc1_Status vc1_ParseEntryPointLayer(void* ctxt, vc1_Info *pInfo);
84 vc1_Status vc1_ParseSliceLayer(void* ctxt, vc1_Info *pInfo);
85 vc1_Status vc1_ParsePictureLayer(void* ctxt, vc1_Info *pInfo);
86 vc1_Status vc1_ParseFieldLayer(void* ctxt, vc1_Info *pInfo);
87 
88 /* Top-level functions to parse headers for various picture layers for the
89 simple and main profiles. */
90 vc1_Status vc1_ParsePictureHeader(void* ctxt, vc1_Info *pInfo);
91 vc1_Status vc1_ParsePictureHeader_ProgressiveIpicture(void* ctxt, vc1_Info *pInfo);
92 vc1_Status vc1_ParsePictureHeader_ProgressivePpicture(void* ctxt, vc1_Info *pInfo);
93 vc1_Status vc1_ParsePictureHeader_ProgressiveBpicture(void* ctxt, vc1_Info *pInfo);
94 
95 /* Top-level functions to parse common part of the headers for various picture
96 layers for the advanced profile. */
97 vc1_Status vc1_ParsePictureHeader_Adv(void* ctxt, vc1_Info *pInfo);
98 vc1_Status vc1_ParseFieldHeader_Adv (void* ctxt, vc1_Info *pInfo);
99 vc1_Status vc1_ParsePictureFieldHeader_Adv(void* ctxt, vc1_Info *pInfo);
100 
101 /* Functions to parse remainder part of the headers for various progressive
102 picture layers for the advanced profile. */
103 vc1_Status vc1_ParsePictureHeader_ProgressiveIpicture_Adv(void* ctxt, vc1_Info *pInfo);
104 vc1_Status vc1_ParsePictureHeader_ProgressivePpicture_Adv(void* ctxt, vc1_Info *pInfo);
105 vc1_Status vc1_ParsePictureHeader_ProgressiveBpicture_Adv(void* ctxt, vc1_Info *pInfo);
106 
107 /* Functions to parse remainder part of the headers for various interlace frame
108 layers for the advanced profile. */
109 vc1_Status vc1_ParsePictureHeader_InterlaceIpicture_Adv(void* ctxt, vc1_Info *pInfo);
110 vc1_Status vc1_ParsePictureHeader_InterlacePpicture_Adv(void* ctxt, vc1_Info *pInfo);
111 vc1_Status vc1_ParsePictureHeader_InterlaceBpicture_Adv(void* ctxt, vc1_Info *pInfo);
112 
113 /* Functions to parse remainder part of the headers for various interlace frame
114 layers for the advanced profile. */
115 vc1_Status vc1_ParseFieldHeader_InterlaceIpicture_Adv(void* ctxt, vc1_Info *pInfo);
116 vc1_Status vc1_ParseFieldHeader_InterlacePpicture_Adv(void* ctxt, vc1_Info *pInfo);
117 vc1_Status vc1_ParseFieldHeader_InterlaceBpicture_Adv(void* ctxt, vc1_Info *pInfo);
118 
119 /* Functions to parse syntax element in bitstream. */
120 vc1_Status vc1_MVRangeDecode(void* ctxt, vc1_Info *pInfo);
121 vc1_Status vc1_DMVRangeDecode(void* ctxt, vc1_Info *pInfo);
122 vc1_Status vc1_CalculatePQuant(vc1_Info *pInfo);
123 vc1_Status vc1_VOPDQuant(void* ctxt, vc1_Info *pInfo);
124 vc1_Status vc1_DecodeBitplane(void* ctxt, vc1_Info *pInfo, uint32_t width, uint32_t height, vc1_bpp_type_t bptype);
125 vc1_Status vc1_DecodeHuffmanOne(void* ctxt, int32_t *pDst, const int32_t *pDecodeTable);
126 vc1_Status vc1_DecodeHuffmanPair(void* ctxt, const int32_t *pDecodeTable, int8_t *pFirst, int16_t *pSecond);
127 
128 void vc1_start_new_frame(void *parent, vc1_viddec_parser_t *parser);
129 int32_t vc1_parse_emit_current_frame(void *parent, vc1_viddec_parser_t *parser);
130 
131 /* function to handle user data */
132 vc1_Status vc1_ParseAndAppendUserData(void* ctxt, uint32_t sc);
133 
134 /*@}*/
135 
136 #endif /* _VC1PARSE_H_. */
137