Home | History | Annotate | Download | only in inc
      1 /*--------------------------------------------------------------------------
      2 Copyright (c) 2010-2012, Code Aurora Forum. All rights reserved.
      3 
      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
     14       permission.
     15 
     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 --------------------------------------------------------------------------*/
     28 #ifndef MP4_UTILS_H
     29 #define MP4_UTILS_H
     30 #include "OMX_Core.h"
     31 #include "OMX_QCOMExtns.h"
     32 typedef signed long long int64;
     33 typedef unsigned int uint32;   /* Unsigned 32 bit value */
     34 typedef unsigned short uint16;   /* Unsigned 16 bit value */
     35 typedef unsigned char uint8;   /* Unsigned 8  bit value */
     36 
     37 typedef int int32;   /* Signed 32 bit value */
     38 typedef signed short int16;   /* Signed 16 bit value */
     39 typedef signed char int8;   /* Signed 8  bit value */
     40 
     41 typedef 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 
    124 typedef 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 
    133 typedef enum VOPTYPE
    134 {
    135   NO_VOP = -1, // bitstream contains no VOP.
    136   MPEG4_I_VOP = 0,   // bitstream contains an MPEG4 I-VOP
    137   MPEG4_P_VOP = 1,   // bitstream contains an MPEG4 P-VOP
    138   MPEG4_B_VOP = 2,   // bitstream contains an MPEG4 B-VOP
    139   MPEG4_S_VOP = 3,   // bitstream contains an MPEG4 S-VOP
    140 } VOP_TYPE;
    141 
    142 typedef struct
    143 {
    144   uint32    timestamp_increment;
    145   uint32    offset;
    146   uint32    size;
    147   VOP_TYPE  vopType;
    148 } mp4_frame_info_type;
    149 
    150 void mp4_fill_aspect_ratio_info(struct vdec_aspectratioinfo *aspect_ratio_info,
    151                            OMX_QCOM_EXTRADATA_FRAMEINFO *frame_info);
    152 class MP4_Utils {
    153 private:
    154    struct posInfoType {
    155       uint8 *bytePtr;
    156       uint8 bitPos;
    157    };
    158 
    159    posInfoType m_posInfo;
    160    byte *m_dataBeginPtr;
    161    unsigned int vop_time_resolution;
    162    bool vop_time_found;
    163    uint16 m_SrcWidth, m_SrcHeight;   // Dimensions of the source clip
    164 public:
    165     MP4_Utils();
    166    ~MP4_Utils();
    167    int16 populateHeightNWidthFromShortHeader(mp4StreamType * psBits);
    168    bool parseHeader(mp4StreamType * psBits);
    169    static uint32 read_bit_field(posInfoType * posPtr, uint32 size);
    170    bool is_notcodec_vop(unsigned char *pbuffer, unsigned int len);
    171 };
    172 #endif
    173