Repository: ossrs/srs
File: trunk/src/kernel/srs_kernel_codec.cpp (C++)

Code before:
    // for NALU, ITU-T H.265 7.3.2.3 Picture parameter set RBSP syntax
    // @see 7.3.2.3 Picture parameter set RBSP syntax
    // @doc ITU-T-H.265-2021.pdf, page 57.
    if (!stream->require(1)) {
        return srs_error_new(ERROR_HEVC_DECODE_ERROR, "decode hevc pps requires 1 only %d bytes", stream->left());
    }
    int8_t nutv = stream->read_1bytes();

    // forbidden_zero_bit shall be equal to 0.
    int8_t forbidden_zero_bit = (nutv >> 7) & 0x01;
    if (forbidden_zero_bit) {
        return srs_error_new(ERROR_HEVC_DECODE_ERROR, "hevc forbidden_zero_bit=%d shall be equal to 0", forbidden_zero_bit);
    }

    // nal_unit_type specifies the type of RBSP data structure contained in the NAL unit as specified in Table 7-1.
    // @see 7.4.2.2 NAL unit header semantics
    // @doc ITU-T-H.265-2021.pdf, page 86.
    SrsHevcNaluType nal_unit_type = (SrsHevcNaluType)((nutv >> 1) & 0x3f);
    if (nal_unit_type != SrsHevcNaluType_PPS) {
        return srs_error_new(ERROR_HEVC_DECODE_ERROR, "hevc pps nal_unit_type=%d shall be equal to 33", nal_unit_type);
    }

    // nuh_layer_id + nuh_temporal_id_plus1
    stream->skip(1);

    // decode the rbsp from sps.
    // rbsp[ i ] a raw byte sequence payload is specified as an ordered sequence of bytes.
    std::vector<uint8_t> rbsp(stream->size());

    int nb_rbsp = remove_emulation_bytes(rbsp, stream);

    return hevc_demux_pps_rbsp((char*)&rbsp[0], nb_rbsp);
}

srs_error_t SrsFormat::hevc_demux_pps_rbsp(char* rbsp, int nb_rbsp)
{
    srs_error_t err = srs_success;

    // reparse the rbsp.
    SrsBuffer stream(rbsp, nb_rbsp);

    // H265 PPS NAL Unit (pic_parameter_set_rbsp()) parser.
    // Section 7.3.2.3 ("Picture parameter set RBSP syntax") of the H.265
    // ITU-T-H.265-2021.pdf, page 57.
    SrsBitBuffer bs(&stream);

    // pps_pic_parameter_set_id  ue(v)
    uint32_t pps_pic_parameter_set_id = 0;
    if ((err = bs.read_bits_ue(pps_pic_parameter_set_id)) != srs_success) {
        return srs_error_wrap(err, "pps_pic_parameter_set_id");
    }

Review comment (bug):
1. Should this annotation be uniformly modified?
2. The annotation here is written incorrectly `// decode the rbsp from pps.`

`TRANS_BY_GPT4`

Code after:
    // ITU-T-H.265-2021.pdf, page 55 ~ page 57.

    // 7.3.2.11 RBSP trailing bits syntax
    // ITU-T-H.265-2021.pdf, page 61.
    // rbsp_trailing_bits()

    return err;
}

srs_error_t SrsFormat::hevc_demux_pps(SrsBuffer *stream)
{
    // for NALU, ITU-T H.265 7.3.2.3 Picture parameter set RBSP syntax
    // @see 7.3.2.3 Picture parameter set RBSP syntax
    // @doc ITU-T-H.265-2021.pdf, page 57.
    if (!stream->require(1)) {
        return srs_error_new(ERROR_HEVC_DECODE_ERROR, "decode hevc pps requires 1 only %d bytes", stream->left());
    }
    int8_t nutv = stream->read_1bytes();

    // forbidden_zero_bit shall be equal to 0.
    int8_t forbidden_zero_bit = (nutv >> 7) & 0x01;
    if (forbidden_zero_bit) {
        return srs_error_new(ERROR_HEVC_DECODE_ERROR, "hevc forbidden_zero_bit=%d shall be equal to 0", forbidden_zero_bit);
    }

    // nal_unit_type specifies the type of RBSP data structure contained in the NAL unit as specified in Table 7-1.
    // @see 7.4.2.2 NAL unit header semantics
    // @doc ITU-T-H.265-2021.pdf, page 86.
    SrsHevcNaluType nal_unit_type = (SrsHevcNaluType)((nutv >> 1) & 0x3f);
    if (nal_unit_type != SrsHevcNaluType_PPS) {
        return srs_error_new(ERROR_HEVC_DECODE_ERROR, "hevc pps nal_unit_type=%d shall be equal to 33", nal_unit_type);
    }

    // nuh_layer_id + nuh_temporal_id_plus1
    stream->skip(1);

    // decode the rbsp from pps.
    // rbsp[ i ] a raw byte sequence payload is specified as an ordered sequence of bytes.
    std::vector<uint8_t> rbsp(stream->size());

    int nb_rbsp = srs_rbsp_remove_emulation_bytes(stream, rbsp);

    return hevc_demux_pps_rbsp((char*)&rbsp[0], nb_rbsp);
}

srs_error_t SrsFormat::hevc_demux_pps_rbsp(char* rbsp, int nb_rbsp)
{
    srs_error_t err = srs_success;

    // reparse the rbsp.
    SrsBuffer stream(rbsp, nb_rbsp);