hxxx_helper.h 4.15 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
/*****************************************************************************
 * hxxx_helper.h: AnnexB / avcC helper for dumb decoders
 *****************************************************************************
 * Copyright (C) 2017 VLC authors and VideoLAN
 *
 * 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
 * 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
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Lesser General Public License for more details.
 *
 * 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.
 *****************************************************************************/

#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

#include <vlc_block.h>
#include <vlc_fourcc.h>

#include "../packetizer/h264_nal.h"
#include "../packetizer/hevc_nal.h"

struct hxxx_helper_nal
{
    block_t *b;
    union {
35
        void                            *xps;
36 37
        h264_sequence_parameter_set_t   *h264_sps;
        h264_picture_parameter_set_t    *h264_pps;
38 39 40
        hevc_sequence_parameter_set_t   *hevc_sps;
        hevc_picture_parameter_set_t    *hevc_pps;
        hevc_video_parameter_set_t      *hevc_vps;
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
    };
};

struct hxxx_helper
{
    vlc_object_t *p_obj; /* for logs */
    vlc_fourcc_t i_codec;
    bool b_need_xvcC; /* Need avcC or hvcC */

    bool b_is_xvcC;
    uint8_t i_nal_length_size;
    union {
        struct {
            struct hxxx_helper_nal sps_list[H264_SPS_ID_MAX + 1];
            struct hxxx_helper_nal pps_list[H264_PPS_ID_MAX + 1];
            uint8_t i_current_sps;
            uint8_t i_sps_count;
            uint8_t i_pps_count;
        } h264;
        struct {
61 62 63 64 65 66 67 68
            struct hxxx_helper_nal sps_list[HEVC_SPS_ID_MAX + 1];
            struct hxxx_helper_nal pps_list[HEVC_PPS_ID_MAX + 1];
            struct hxxx_helper_nal vps_list[HEVC_VPS_ID_MAX + 1];
            uint8_t i_current_sps;
            uint8_t i_current_vps;
            uint8_t i_sps_count;
            uint8_t i_pps_count;
            uint8_t i_vps_count;
69 70 71 72
            void *p_annexb_config_nal;
            size_t i_annexb_config_nal;
        } hevc;
    };
73 74 75 76

    /* Process the block: do the AnnexB <-> xvcC conversion if needed. If
     * p_config_changed is not NULL, parse nals to detect a SPS/PPS or a video
     * size change. */
77 78 79 80 81 82 83 84 85 86 87
    block_t * (*pf_process_block)(struct hxxx_helper *hh, block_t *p_block,
                                  bool *p_config_changed);
};

void hxxx_helper_init(struct hxxx_helper *hh, vlc_object_t *p_obj,
                      vlc_fourcc_t i_codec, bool b_need_xvcC);
void hxxx_helper_clean(struct hxxx_helper *hh);

int hxxx_helper_set_extra(struct hxxx_helper *hh, const void *p_extra,
                          size_t i_extra);

88
block_t *h264_helper_get_annexb_config(const struct hxxx_helper *hh);
89

90
block_t *h264_helper_get_avcc_config(const struct hxxx_helper *hh);
91

92
int hxxx_helper_get_current_picture_size(const struct hxxx_helper *hh,
93 94 95
                                         unsigned *p_w, unsigned *p_h,
                                         unsigned *p_vw, unsigned *p_vh);

96
int hxxx_helper_get_current_sar(const struct hxxx_helper *hh, int *p_num, int *p_den);
97

98
int h264_helper_get_current_dpb_values(const struct hxxx_helper *hh,
99
                                       uint8_t *p_depth, unsigned *pi_delay);
100

101
int hxxx_helper_get_current_profile_level(const struct hxxx_helper *hh,
102 103
                                          uint8_t *p_profile, uint8_t *p_level);

104 105 106 107 108
int hxxx_helper_get_colorimetry(const struct hxxx_helper *hh,
                                video_color_primaries_t *p_primaries,
                                video_transfer_func_t *p_transfer,
                                video_color_space_t *p_colorspace,
                                bool *p_full_range);