1 /*--------------------------------------------------------------------------
2 Copyright (c) 2010, Code Aurora Forum. All rights reserved.
4 Redistribution and use in source and binary forms, with or without
5 modification, are permitted provided that the following conditions are met:
6 * Redistributions of source code must retain the above copyright
7 notice, this list of conditions and the following disclaimer.
8 * Redistributions in binary form must reproduce the above copyright
9 notice, this list of conditions and the following disclaimer in the
10 documentation and/or other materials provided with the distribution.
11 * Neither the name of Code Aurora nor
12 the names of its contributors may be used to endorse or promote
13 products derived from this software without specific prior written
16 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
20 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
23 OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24 WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
25 OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
26 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 --------------------------------------------------------------------------*/
31 /*========================================================================
34 U t i l i t i e s a n d H e l p e r R o u t i n e s
36 *//** @file H264_Utils.h
37 This module contains H264 video decoder utilities and helper routines.
39 *//*====================================================================== */
41 /* =======================================================================
43 INCLUDE FILES FOR MODULE
45 ========================================================================== */
51 #define STD_MIN(x,y) (((x) < (y)) ? (x) : (y))
53 #define OMX_CORE_720P_HEIGHT 720
54 #define OMX_CORE_720P_WIDTH 1280
56 /* =======================================================================
60 ========================================================================== */
62 /* -----------------------------------------------------------------------
63 ** Constant / Define Declarations
64 ** ----------------------------------------------------------------------- */
65 // Common format block header definitions
66 #define MT_VIDEO_META_STREAM_HEADER 0x00
67 #define MT_VIDEO_MEDIA_STREAM_HEADER 0x01
68 #define MT_VIDEO_META_MEDIA_STREAM_HEADER 0x02
70 // H.264 format block header definitions
71 #define MT_VIDEO_H264_ACCESS_UNIT_FORMAT 0x00
72 #define MT_VIDEO_H264_NAL_FORMT 0x01
73 #define MT_VIDEO_H264_BYTE_FORMAT 0x02
74 #define MT_VIDEO_H264_BYTE_STREAM_FORMAT 0x00
75 #define MT_VIDEO_H264_NAL_UNIT_STREAM_FORMAT 0x01
76 #define MT_VIDEO_H264_FORMAT_BLOCK_HEADER_SIZE 18
78 // MPEG-4 format block header definitions
79 #define MT_VIDEO_MPEG4_VOP_FORMAT 0x00
80 #define MT_VIDEO_MPEG4_SLICE_FORMAT 0x01
81 #define MT_VIDEO_MPEG4_BYTE_FORMAT 0x02
82 #define MT_VIDEO_MPEG4_FORMAT_BLOCK_HEADER_SIZE 15
84 // H.263 format block header definitions
85 #define MT_VIDEO_H263_PICTURE_FORMAT 0x00
86 #define MT_VIDEO_H263_GOB_FORMAT 0x01
87 #define MT_VIDEO_H263_SLICE_STRUCTURED_FORMAT 0x02
88 #define MT_VIDEO_H263_BYTE_FORMAT 0x03
89 #define MT_VIDEO_H263_FORMAT_BLOCK_HEADER_SIZE 16
91 /* =======================================================================
92 ** Function Declarations
93 ** ======================================================================= */
95 /* -----------------------------------------------------------------------
97 ** ----------------------------------------------------------------------- */
99 // This type is used when parsing an H.264 bitstream to collect H.264 NAL
100 // units that need to go in the meta data.
101 struct H264ParamNalu {
104 uint32 picOrderCntType;
105 bool frameMbsOnlyFlag;
106 bool picOrderPresentFlag;
107 uint32 picWidthInMbsMinus1;
108 uint32 picHeightInMapUnitsMinus1;
109 uint32 log2MaxFrameNumMinus4;
110 uint32 log2MaxPicOrderCntLsbMinus4;
111 bool deltaPicOrderAlwaysZeroFlag;
112 //std::vector<uint8> nalu;
119 //typedef map<uint32, H264ParamNalu> H264ParamNaluSet;
120 typedef Map<uint32, H264ParamNalu *> H264ParamNaluSet;
123 NALU_TYPE_UNSPECIFIED = 0,
125 NALU_TYPE_PARTITION_A,
126 NALU_TYPE_PARTITION_B,
127 NALU_TYPE_PARTITION_C,
132 NALU_TYPE_ACCESS_DELIM,
135 NALU_TYPE_FILLER_DATA,
139 // NAL header information
143 uint32 forbidden_zero_bit;
146 // This structure contains persistent information about an H.264 stream as it
148 //struct H264StreamInfo {
149 // H264ParamNaluSet pic;
150 // H264ParamNaluSet seq;
154 /******************************************************************************
155 ** This class is used to convert an H.264 NALU (network abstraction layer
156 ** unit) into RBSP (raw byte sequence payload) and extract bits from it.
157 *****************************************************************************/
160 RbspParser (const uint8 *begin, const uint8 *end);
162 virtual ~RbspParser ();
171 const uint8 *begin, *end;
183 void initialize_frame_checking_environment();
184 void allocate_rbsp_buffer(uint32 inputBufferSize);
185 bool isNewFrame(OMX_IN OMX_U8 *bitstream,
186 OMX_IN OMX_U32 bitstream_length,
187 OMX_IN OMX_U32 size_of_nal_length_field,
188 OMX_OUT OMX_BOOL &isNewFrame);
191 boolean extract_rbsp(OMX_IN OMX_U8 *buffer,
192 OMX_IN OMX_U32 buffer_length,
193 OMX_IN OMX_U32 size_of_nal_length_field,
194 OMX_OUT OMX_U8 *rbsp_bistream,
195 OMX_OUT OMX_U32 *rbsp_length,
196 OMX_OUT NALU *nal_unit);
200 H264ParamNaluSet pic;
201 H264ParamNaluSet seq;
204 bool m_forceToStichNextNAL;
209 #endif /* H264_UTILS_H */