1/* ------------------------------------------------------------------
2 * Copyright (C) 1998-2009 PacketVideo
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
13 * express or implied.
14 * See the License for the specific language governing permissions
15 * and limitations under the License.
16 * -------------------------------------------------------------------
17 */
18#ifndef TI_M4V_CONFIG_PARSER_H_INCLUDED
19#define TI_M4V_CONFIG_PARSER_H_INCLUDED
20
21#include "oscl_base.h"
22#include "oscl_types.h"
23
24#include <utils/Log.h>
25#define LOG_TAG "TI_Parser_Utils"
26
27#define USE_LATER 0  // for some code that will be needed in the future
28
29#define MP4_INVALID_VOL_PARAM -1
30#define SHORT_HEADER_MODE -4
31
32#define WVGA_MAX_WIDTH 900
33#define WVGA_MAX_HEIGHT WVGA_MAX_WIDTH
34
35#define VISUAL_OBJECT_SEQUENCE_START_CODE 	0x01B0
36#define VISUAL_OBJECT_SEQUENCE_END_CODE 	0x01B1
37#define VISUAL_OBJECT_START_CODE   0x01B5
38#define VO_START_CODE 		    0x8
39#define VO_HEADER_LENGTH        32
40#define VOL_START_CODE 0x12
41#define VOL_START_CODE_LENGTH 28
42
43#define GROUP_START_CODE	0x01B3
44#define GROUP_START_CODE_LENGTH  32
45
46#define VOP_ID_CODE_LENGTH		5
47#define VOP_TEMP_REF_CODE_LENGTH	16
48
49#define USER_DATA_START_CODE	    0x01B2
50#define USER_DATA_START_CODE_LENGTH 32
51
52#define SHORT_VIDEO_START_MARKER		0x20
53#define SHORT_VIDEO_START_MARKER_LENGTH  22
54
55/*Some H264 profiles*/
56#define H264_PROFILE_IDC_BASELINE 66
57#define H264_PROFILE_IDC_MAIN 77
58#define H264_PROFILE_IDC_EXTENDED 88
59#define H264_PROFILE_IDC_HIGH 100
60
61typedef struct
62{
63    uint8 *data;
64    uint32 numBytes;
65    uint32 bytePos;
66    uint32 bitBuf;
67    uint32 dataBitPos;
68    uint32  bitPos;
69} mp4StreamType;
70
71
72int16 ShowBits(
73    mp4StreamType *pStream,
74    uint8 ucNBits,
75    uint32 *pulOutData
76);
77
78int16 FlushBits(
79    mp4StreamType *pStream,
80    uint8 ucNBits
81);
82
83int16 ReadBits(
84    mp4StreamType *pStream,
85    uint8 ucNBits,
86    uint32 *pulOutData
87);
88
89int16 ByteAlign(
90    mp4StreamType *pStream
91);
92
93	OSCL_IMPORT_REF int16 iDecodeVOLHeader(
94		mp4StreamType *psBits,
95		int32 *width,
96		int32 *height,
97		int32 *,
98		int32 *,
99		int32 *profilelevel);
100	OSCL_IMPORT_REF int16 iGetM4VConfigInfo(
101		uint8 *buffer,
102		int32 length,
103		int32 *width,
104		int32 *height,
105		int32 *,
106		int32 *);
107
108int16 DecodeUserData(mp4StreamType *pStream);
109
110	OSCL_IMPORT_REF int16 iDecodeShortHeader(
111		mp4StreamType *psBits,
112		int32 *width,
113		int32 *height,
114		int32 *,
115		int32 *);
116	OSCL_IMPORT_REF int16 iGetAVCConfigInfo(
117		uint8 *buffer,
118		int32 length,
119		int32 *width,
120		int32 *height,
121		int32 *,
122		int32 *,
123		int32 *profile,
124		int32 *level,
125		uint32 *entropy_coding_mode_flag);
126
127int32 FindNAL(uint8** nal_pnt, uint8* buffer, int32 length);
128int16 DecodeSPS(mp4StreamType *psBits, int32 *width, int32 *height, int32 *display_width, int32 *display_height, int32 *profile_idc, int32 *level_idc);
129#if USE_LATER
130int32 DecodeHRD(mp4StreamType *psBits);
131int32 DecodeVUI(mp4StreamType *psBits);
132#endif
133int32 DecodePPS(mp4StreamType *psBits, uint32 *entropy_coding_mode_flag);
134
135void ue_v(mp4StreamType *psBits, uint32 *codeNum);
136void se_v(mp4StreamType *psBits, int32 *value);
137void Parser_EBSPtoRBSP(uint8 *nal_unit, int32 *size);
138
139#endif //TI_M4V_CONFIG_PARSER_H_INCLUDED
140
141
142