1/*-------------------------------------------------------------------------- 2Copyright (c) 2010 - 2013, The Linux Foundation. All rights reserved. 3 4Redistribution and use in source and binary forms, with or without 5modification, 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 The Linux Foundation nor 12 the names of its contributors may be used to endorse or promote 13 products derived from this software without specific prior written 14 permission. 15 16THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 20CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 21EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 22PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 23OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 24WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 25OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 26ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27--------------------------------------------------------------------------*/ 28#ifndef MP4_UTILS_H 29#define MP4_UTILS_H 30#include "OMX_Core.h" 31#include "OMX_QCOMExtns.h" 32typedef signed long long int64; 33typedef unsigned int uint32; /* Unsigned 32 bit value */ 34typedef unsigned short uint16; /* Unsigned 16 bit value */ 35typedef unsigned char uint8; /* Unsigned 8 bit value */ 36 37typedef int int32; /* Signed 32 bit value */ 38typedef signed short int16; /* Signed 16 bit value */ 39typedef signed char int8; /* Signed 8 bit value */ 40 41typedef unsigned char byte; /* Unsigned 8 bit value type. */ 42#define SIMPLE_PROFILE_LEVEL0 0x08 43#define SIMPLE_PROFILE_LEVEL1 0x01 44#define SIMPLE_PROFILE_LEVEL2 0x02 45#define SIMPLE_PROFILE_LEVEL3 0x03 46#define SIMPLE_PROFILE_LEVEL4A 0x04 47#define SIMPLE_PROFILE_LEVEL5 0x05 48#define SIMPLE_PROFILE_LEVEL6 0x06 49#define SIMPLE_PROFILE_LEVEL0B 0x09 50 51#define SIMPLE_SCALABLE_PROFILE_LEVEL0 0x10 52#define SIMPLE_SCALABLE_PROFILE_LEVEL1 0x11 53#define SIMPLE_SCALABLE_PROFILE_LEVEL2 0x12 54 55#define SIMPLE_SCALABLE_PROFILE_LEVEL0 0x10 56#define SIMPLE_SCALABLE_PROFILE_LEVEL1 0x11 57#define SIMPLE_SCALABLE_PROFILE_LEVEL2 0x12 58#define ADVANCED_SIMPLE_PROFILE_LEVEL0 0xF0 59#define ADVANCED_SIMPLE_PROFILE_LEVEL1 0xF1 60#define ADVANCED_SIMPLE_PROFILE_LEVEL2 0xF2 61#define ADVANCED_SIMPLE_PROFILE_LEVEL3 0xF3 62#define ADVANCED_SIMPLE_PROFILE_LEVEL4 0xF4 63#define ADVANCED_SIMPLE_PROFILE_LEVEL5 0xF5 64 65#define VISUAL_OBJECT_SEQUENCE_START_CODE 0x000001B0 66#define MP4ERROR_SUCCESS 0 67 68#define VIDEO_OBJECT_LAYER_START_CODE_MASK 0xFFFFFFF0 69#define VIDEO_OBJECT_LAYER_START_CODE 0x00000120 70#define VOP_START_CODE_MASK 0xFFFFFFFF 71#define VOP_START_CODE 0x000001B6 72#define GOV_START_CODE 0x000001B3 73#define SHORT_HEADER_MASK 0xFFFFFC00 74#define SHORT_HEADER_START_MARKER 0x00008000 75#define SHORT_HEADER_START_CODE 0x00008000 76#define SPARK1_START_CODE 0x00008400 77#define MPEG4_SHAPE_RECTANGULAR 0x00 78#define EXTENDED_PAR 0xF 79#define SHORT_VIDEO_START_MARKER 0x20 80#define MP4_INVALID_VOL_PARAM (0x0001) // unsupported VOL parameter 81#define MP4ERROR_UNSUPPORTED_UFEP -1068 82#define MP4ERROR_UNSUPPORTED_SOURCE_FORMAT -1069 83#define MASK(x) (0xFFFFFFFF >> (32 - (x))) 84#define VISUAL_OBJECT_TYPE_VIDEO_ID 0x1 85#define VISUAL_OBJECT_START_CODE 0x000001B5 86#define VIDEO_OBJECT_START_CODE_MASK 0xFFFFFFE0 87#define VIDEO_OBJECT_START_CODE 0x00000100 88 89#define RESERVED_OBJECT_TYPE 0x0 90#define SIMPLE_OBJECT_TYPE 0x1 91#define SIMPLE_SCALABLE_OBJECT_TYPE 0x2 92#define CORE_OBJECT_TYPE 0x3 93#define MAIN_OBJECT_TYPE 0x4 94#define N_BIT_OBJECT_TYPE 0x5 95#define BASIC_ANIMATED_2D_TEXTURE 0x6 96#define ANIMATED_2D_MESH 0x7 97#define ADVANCED_SIMPLE 0x11 98 99 100#define SIMPLE_L1_MAX_VBVBUFFERSIZE 10 /* VBV Max Buffer size=10 (p. 498) */ 101#define SIMPLE_L1_MAX_BITRATE 160 /* is is 64kpbs or 160 400bits/sec units */ 102#define SIMPLE_L2_MAX_VBVBUFFERSIZE 40 /* VBV Max Buffer size = 40 */ 103#define SIMPLE_L2_MAX_BITRATE 320 /* 320 400bps units = 128kpbs */ 104#define SIMPLE_L3_MAX_VBVBUFFERSIZE 40 /* VBV Max Buffer size = 40 */ 105#define SIMPLE_L3_MAX_BITRATE 960 /* 960 400bps units = 384kpbs */ 106 107/* The MP4 decoder currently supports Simple Profile@L3 */ 108#define MAX_VBVBUFFERSIZE (SIMPLE_L3_MAX_VBVBUFFERSIZE) 109#define MAX_BITRATE (SIMPLE_L3_MAX_BITRATE) 110 111#define MAX_QUANTPRECISION 9 112#define MIN_QUANTPRECISION 3 113 114#define MP4_VGA_WIDTH 640 115#define MP4_VGA_HEIGHT 480 116#define MP4_WVGA_WIDTH 800 117#define MP4_WVGA_HEIGHT 480 118#define MP4_720P_WIDTH 1280 119#define MP4_720P_HEIGHT 720 120 121#define MP4_MAX_DECODE_WIDTH MP4_720P_WIDTH 122#define MP4_MAX_DECODE_HEIGHT MP4_720P_HEIGHT 123 124typedef struct { 125 unsigned char *data; 126 unsigned long int numBytes; 127} mp4StreamType; 128 129#define MAX_FRAMES_IN_CHUNK 10 130#define VOP_START_CODE 0x000001B6 131#define VOL_START_CODE 0x000001B0 132 133typedef enum VOPTYPE { 134 NO_VOP = -1, // bitstream contains no VOP. 135 MPEG4_I_VOP = 0, // bitstream contains an MPEG4 I-VOP 136 MPEG4_P_VOP = 1, // bitstream contains an MPEG4 P-VOP 137 MPEG4_B_VOP = 2, // bitstream contains an MPEG4 B-VOP 138 MPEG4_S_VOP = 3, // bitstream contains an MPEG4 S-VOP 139} VOP_TYPE; 140 141typedef struct { 142 uint32 timestamp_increment; 143 uint32 offset; 144 uint32 size; 145 VOP_TYPE vopType; 146} mp4_frame_info_type; 147 148class MP4_Utils 149{ 150 private: 151 struct posInfoType { 152 uint8 *bytePtr; 153 uint8 bitPos; 154 }; 155 156 posInfoType m_posInfo; 157 byte *m_dataBeginPtr; 158 unsigned int vop_time_resolution; 159 bool vop_time_found; 160 uint16 m_SrcWidth, m_SrcHeight; // Dimensions of the source clip 161 public: 162 MP4_Utils(); 163 ~MP4_Utils(); 164 int16 populateHeightNWidthFromShortHeader(mp4StreamType * psBits); 165 bool parseHeader(mp4StreamType * psBits); 166 static uint32 read_bit_field(posInfoType * posPtr, uint32 size); 167 bool is_notcodec_vop(unsigned char *pbuffer, unsigned int len); 168}; 169#endif 170