1 /*---------------------------------------------------------------------------*
2 
3   Copyright (C) 2011-2012 Nintendo.  All rights reserved.
4 
5   These coded instructions, statements, and computer programs contain
6   proprietary information of Nintendo of America Inc. and/or Nintendo
7   Company Ltd., and are protected by Federal copyright law.  They may
8   not be disclosed to third parties or copied or duplicated in any form,
9   in whole or in part, without the prior written consent of Nintendo.
10 
11  *---------------------------------------------------------------------------*/
12 #ifndef _H264DECAPI_H
13 #define _H264DECAPI_H
14 
15 #ifdef __cplusplus
16 extern "C" {
17 #endif
18 /*
19     set parameters
20 */
21 #define H264DEC_PARAM_ID_FPTR_OUTPUT        (0x00000001)
22 #define H264DEC_PARAM_ID_OUTPUT_PER_FRAME   (0x20000002)
23 #define H264DEC_PARAM_ID_USER_MEMORY        (0x70000001)
24 
25 #define BUFFERING_OUTPUT_PER_FRAME          (0x00000000)
26 #define UNBUFFERING_OUTPUT_PER_FRAME        (0x00000001)
27 
28 /*
29     alignment
30 */
31 #define H264DEC_ALIGN_PITCH_IN_PIXELS(PitchInPixels)    ((PitchInPixels + 0xFF) & ~0xFF)
32 #define H264DEC_BUFFER_ALIGNMENT                        (256)
33 
34 /*
35     Profile
36 */
37 #define H264_BASELINE_PROFILE               ( 66)
38 #define H264_MAIN_PROFILE                   ( 77)
39 #define H264_HIGH_PROFILE                   (100)
40 
41 /*
42     0x(01 XX 00 00) : stream error
43         XX -> xxxx x000 (stream error ID[5bit])
44 
45         00000 : general
46         00001 : profile error (not supported)
47         00010 : no slice which can be decoded
48         00011 : not supported (ex. required resolution)
49         ------------------------
50         00100 - 11111 : reserved
51 */
52 #define H264DEC_ERR_STREAM           (0x01000000)
53 #define H264DEC_ERR_PROFILE          (0x01080000)
54 #define H264DEC_ERR_NODATA           (0x01100000)
55 #define H264DEC_ERR_NOTSUPPORTED     (0x01180000)
56 #define H264DEC_ERR_PARAM            (0x01010000)
57 #define H264DEC_ERR_OUTOFMEMORY      (0x01020000)
58 #define H264DEC_ERR_INTERNAL         (0x01030000)
59 #define H264DEC_ERR_SEQUENCE         (0x01050000)
60 #define H264DEC_ERR_MEMSEGMENT       (0x01060000)
61 #define H264DEC_ERR_MAX_SIZE         (0x01070000)
62 #define H264DEC_ERR_BUFFEREMPTY      (0x00080000)
63 #define H264DEC_ERR_USE_FM           (0x00000080)
64 #define H264DEC_ERR_FM_STAT          (0x000000FF)
65 
66 // VUI Parameters
67 typedef struct __VUI_PARAMETERS__
68 {
69     u8 aspect_ratio_info_present_flag;
70     u8 aspect_ratio_idc;
71     s16 sar_width;
72     s16 sar_height;
73     u8 overscan_info_present_flag;
74     u8 overscan_appropriate_flag;
75     u8 video_signal_type_present_flag;
76     u8 video_format;
77     u8 video_full_range_flag;
78     u8 colour_description_present_flag;
79     u8 colour_primaries;
80     u8 transfer_characteristics;
81     u8 matrix_coefficients;
82     u8 chroma_loc_info_present_flag;
83     u8 chroma_sample_loc_type_top_field;
84     u8 chroma_sample_loc_type_bottom_field;
85     u8 timing_info_present_flag;
86     u32 num_units_in_tick;
87     u32 time_scale;
88     u8 fixed_frame_rate_flag;
89     u8 nal_hrd_parameters_present_flag;
90     u8 vcl_hrd_parameters_present_flag;
91     u8 low_delay_hrd_flag;
92     u8 pic_struct_present_flag;
93     u8 bitstream_restriction_flag;
94     u8 motion_vectors_over_pic_boundaries_flag;
95     s16 max_bytes_per_pic_denom;
96     s16 max_bits_per_mb_denom;
97     s16 log2_max_mv_length_horizontal;
98     s16 log2_max_mv_length_vertical;
99     s16 num_reorder_frames;
100     s16 max_dec_frame_buffering;
101 } VUIParameters;
102 
103 typedef struct __H264DEC_RESULT__
104 {
105     s32 DecStatus;
106     f64 TimeStamp;
107     s32 ResultWidth;
108     s32 ResultHeight;
109     s32 NextLine;
110     u8 CropEnableFlag;
111     s32 TopCrop;
112     s32 BottomCrop;
113     s32 LeftCrop;
114     s32 RightCrop;
115     u8 PanScanEnableFlag;
116     s32 TopPanScan;
117     s32 BottomPanScan;
118     s32 LeftPanScan;
119     s32 RightPanScan;
120     void    *Result;
121     u8 vui_parameters_present_flag;
122     VUIParameters *VUIparameters;
123     s32 reserved[10];
124 } H264DECResult;
125 
126 typedef struct __H264DEC_OUTPUT__
127 {
128     s32 FmCnt;
129     H264DECResult **DecResPtr;
130     void *UserMemory;
131 } H264DECOutput;
132 
133 /*
134     API
135 */
136 s32     H264DECInitParam(s32 memSize, void *memPtr);
137 s32     H264DECSetParam(void *memPtr, s32 paramid, void *param);
138 s32     H264DECOpen(void *memPtr);
139 s32     H264DECBegin(void *memPtr);
140 s32     H264DECSetBitstream(void *memPtr, const u8 *bitstream, const s32 length, const f64 timeStamp);
141 s32     H264DECExecute(void *memPtr, void *StrFmPtr );
142 s32     H264DECFlush(void *memPtr);
143 s32     H264DECEnd(void *memPtr);
144 s32     H264DECClose(void *memPtr);
145 s32     H264DECMemoryRequirement(s32 Profile, s32 Level, s32 MaxWidth, s32 MaxHeight, s32 *CodecMemSize);
146 s32     H264DECGetImageSize(const u8 *buf, s32 TotalBytes, s32 streamOffset, s32 *Width, s32 *Height);
147 s32     H264DECFindDecstartpoint(const u8 *buf, s32 totalBytes, s32 *streamOffset);
148 s32     H264DECFindIdrpoint(const u8 *buf, s32 totalBytes, s32 *streamOffset);
149 s32     H264DECCheckDecunitLength(void *memPtr, const u8 *buf, s32 totalBytes, s32 streamOffset, s32 *length);
150 s32     H264DECCheckMemSegmentation(void *memPtr, u32 Size);
151 s32     H264DECCheckSkipableFrame(const u8 *buf, s32 Length, s32 *SkipFlag);
152 /*
153     not supported
154 */
155 s32     H264DECSetParam_FPTR_OUTPUT(void *memPtr, int (*func)(void *));
156 s32     H264DECSetParam_OUTPUT_PER_FRAME(void  *memPtr, int outputPerFrameFlag);
157 s32     H264DECSetParam_USER_MEMORY(void *memPtr, void **usermem );
158 
159 #ifdef __cplusplus
160 }
161 #endif
162 #endif  /* _H264API__H */
163