h264_nal.h 4.64 KB
Newer Older
1
/*****************************************************************************
2
 * Copyright © 2010-2014 VideoLAN
3 4 5
 *
 * Authors: Jean-Baptiste Kempf <jb@videolan.org>
 *
6 7
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published by
8 9 10 11 12
 * the Free Software Foundation; either version 2.1 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Jean-Baptiste Kempf's avatar
LGPL  
Jean-Baptiste Kempf committed
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
 * GNU Lesser General Public License for more details.
15 16 17 18 19 20
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
 *****************************************************************************/

Felix Abecassis's avatar
Felix Abecassis committed
21 22 23
#ifndef H264_NAL_H
# define H264_NAL_H

24 25 26
# ifdef HAVE_CONFIG_H
#  include "config.h"
# endif
27

28 29
# include <vlc_common.h>
# include <vlc_codec.h>
30

31 32
# include "../demux/mpeg/mpeg_parser_helpers.h"

33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
#define PROFILE_H264_BASELINE             66
#define PROFILE_H264_MAIN                 77
#define PROFILE_H264_EXTENDED             88
#define PROFILE_H264_HIGH                 100
#define PROFILE_H264_HIGH_10              110
#define PROFILE_H264_HIGH_422             122
#define PROFILE_H264_HIGH_444             144
#define PROFILE_H264_HIGH_444_PREDICTIVE  244

#define PROFILE_H264_CAVLC_INTRA          44
#define PROFILE_H264_SVC_BASELINE         83
#define PROFILE_H264_SVC_HIGH             86
#define PROFILE_H264_MVC_STEREO_HIGH      128
#define PROFILE_H264_MVC_MULTIVIEW_HIGH   118

48 49 50
#define SPS_MAX (32)
#define PPS_MAX (256)

51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
enum nal_unit_type_e
{
    NAL_UNKNOWN = 0,
    NAL_SLICE   = 1,
    NAL_SLICE_DPA   = 2,
    NAL_SLICE_DPB   = 3,
    NAL_SLICE_DPC   = 4,
    NAL_SLICE_IDR   = 5,    /* ref_idc != 0 */
    NAL_SEI         = 6,    /* ref_idc == 0 */
    NAL_SPS         = 7,
    NAL_PPS         = 8,
    NAL_AU_DELIMITER= 9
    /* ref_idc == 0 for 6,9,10,11,12 */
};

/* Defined in H.264 annex D */
enum sei_type_e
{
    SEI_PIC_TIMING = 1,
    SEI_USER_DATA_REGISTERED = 4,
    SEI_RECOVERY_POINT = 6
};

74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
struct nal_sps
{
    int i_id;
    int i_profile, i_level;
    int i_width, i_height;
    int i_log2_max_frame_num;
    int b_frame_mbs_only;
    int i_pic_order_cnt_type;
    int i_delta_pic_order_always_zero_flag;
    int i_log2_max_pic_order_cnt_lsb;

    struct {
        bool b_valid;
        int i_sar_num, i_sar_den;
        bool b_timing_info_present_flag;
        uint32_t i_num_units_in_tick;
        uint32_t i_time_scale;
        bool b_fixed_frame_rate;
        bool b_pic_struct_present_flag;
        bool b_cpb_dpb_delays_present_flag;
        uint8_t i_cpb_removal_delay_length_minus1;
        uint8_t i_dpb_output_delay_length_minus1;
    } vui;
};

struct nal_pps
{
    int i_id;
    int i_sps_id;
    int i_pic_order_present_flag;
};

static inline void CreateDecodedNAL( uint8_t **pp_ret, int *pi_ret,
                                     const uint8_t *src, int i_src )
{
    uint8_t *dst = malloc( i_src );

    *pp_ret = dst;

    if( dst )
        *pi_ret = nal_decode(src, dst, i_src);
}

117 118 119 120 121
/* Parse the SPS/PPS Metadata and convert it to annex b format */
int convert_sps_pps( decoder_t *p_dec, const uint8_t *p_buf,
                     uint32_t i_buf_size, uint8_t *p_out_buf,
                     uint32_t i_out_buf_size, uint32_t *p_sps_pps_size,
                     uint32_t *p_nal_size);
122

123
/* Convert H.264 NAL format to annex b in-place */
124 125 126 127 128
struct H264ConvertState {
    uint32_t nal_len;
    uint32_t nal_pos;
};

129 130 131
void convert_h264_to_annexb( uint8_t *p_buf, uint32_t i_len,
                             size_t i_nal_size,
                             struct H264ConvertState *state );
132

133 134 135 136 137 138
/* Get the SPS/PPS pointers from an Annex B buffer
 * Returns 0 if a SPS and/or a PPS is found */
int h264_get_spspps( uint8_t *p_buf, size_t i_buf,
                     uint8_t **pp_sps, size_t *p_sps_size,
                     uint8_t **pp_pps, size_t *p_pps_size );

139 140 141 142 143 144 145 146 147 148
/* Parse a SPS into the struct nal_sps
 * Returns 0 in case of success */
int h264_parse_sps( const uint8_t *p_sps_buf, int i_sps_size,
                    struct nal_sps *p_sps );

/* Parse a PPS into the struct nal_pps
 * Returns 0 in case of success */
int h264_parse_pps( const uint8_t *p_pps_buf, int i_pps_size,
                    struct nal_pps *p_pps );

149
/* Get level and Profile */
150 151
bool h264_get_profile_level(const es_format_t *p_fmt, size_t *p_profile,
                            size_t *p_level, size_t *p_nal_size);
Felix Abecassis's avatar
Felix Abecassis committed
152 153

#endif /* H264_NAL_H */