Repository: ossrs/srs
File: trunk/src/protocol/srs_protocol_raw_avc.cpp (C++)

Code before:
    pps = string(frame, nb_frame);

    return err;
}

srs_error_t SrsRawHEVCStream::mux_sequence_header(std::string vps, std::string sps, std::vector<std::string> *pps, std::string &hvcC)
{
    srs_error_t err = srs_success;

    // hevc header information:
    // 23bytes header:
    //      configurationVersion, general_profile_space, general_tier_flag, general_profile_idc
    //      general_profile_compatibility_flags, general_constraint_indicator_flags,
    //      general_level_idc, min_spatial_segmentation_idc, parallelismType,
    //      chromaFormat, bitDepthLumaMinus8, bitDepthChromaMinus8,
    //      avgFrameRate, constantFrameRate, numTemporalLayers, temporalIdNested,
    //      lengthSizeMinusOne, numOfArrays
    // 5bytes size of vps/sps/pps:
    //      array_completeness, nal_unit_type, numNalus, nalUnitLength,
    // Nbytes of vps/sps/pps.
    //      sequenceParameterSetNALUnit

    // use simple mode: nalu size + nalu data
    /**/
	int nPPSSize = 0;
	for (auto stl_VectorIterator = pps->begin(); stl_VectorIterator != pps->end(); stl_VectorIterator++)
	{
		nPPSSize += stl_VectorIterator->length();
        nPPSSize += 2;
	}
    int nb_packet = 23 + 5 + (int)vps.length() + 5 + (int)sps.length() + 5 + (int)nPPSSize - 2;
    
    //int nb_packet = 23 + 5 + (int)vps.length() + 5 + (int)sps.length() + 5 + (int)pps->front().length();
    char *packet = new char[nb_packet];
    SrsAutoFreeA(char, packet);

    // use stream to generate the hevc packet.
    SrsBuffer stream(packet, nb_packet);

    SrsFormat format;
    if ((err = format.initialize()) != srs_success) {
        return srs_error_wrap(err, "format failed");
    }
    // hevc_dec_conf_record
    SrsHevcDecoderConfigurationRecord *hevc_info = &format.vcodec->hevc_dec_conf_record_;

    if (true) {
        // H265 VPS (video_parameter_set_rbsp()) NAL Unit.
        // @see Section 7.3.2.1 ("Video parameter set RBSP syntax") of the H.265
        // @doc ITU-T-H.265-2021.pdf, page 54.
        SrsBuffer vps_stream((char*)vps.data(), vps.length());

Review comment (suggestion):
We do not recommend using the "auto" syntax, as it is a new feature introduced in C++11. Currently, SRS is still using the C++98 standard. So, we should declare the iterator explicitly like this: `std::vector<string>::iterator it`.

Code after:
    pps = string(frame, nb_frame);

    return err;
}

srs_error_t SrsRawHEVCStream::mux_sequence_header(std::string vps, std::string sps, std::vector<std::string>& pps, std::string &hvcC)
{
    srs_error_t err = srs_success;

    // hevc header information:
    // 23bytes header:
    //      configurationVersion, general_profile_space, general_tier_flag, general_profile_idc
    //      general_profile_compatibility_flags, general_constraint_indicator_flags,
    //      general_level_idc, min_spatial_segmentation_idc, parallelismType,
    //      chromaFormat, bitDepthLumaMinus8, bitDepthChromaMinus8,
    //      avgFrameRate, constantFrameRate, numTemporalLayers, temporalIdNested,
    //      lengthSizeMinusOne, numOfArrays
    // 5bytes size of vps/sps/pps:
    //      array_completeness, nal_unit_type, numNalus, nalUnitLength,
    // Nbytes of vps/sps/pps.
    //      sequenceParameterSetNALUnit

    // use simple mode: nalu size + nalu data
    int pps_size = 0;
    for (std::vector<std::string>::iterator it = pps.begin(); it != pps.end(); it++) {
        pps_size += 2 + it->length();
    }

    int nb_packet = 23 + 5 + (int)vps.length() + 5 + (int)sps.length() + 5 + pps_size - 2;
    char* packet = new char[nb_packet];
    SrsAutoFreeA(char, packet);

    // use stream to generate the hevc packet.
    SrsBuffer stream(packet, nb_packet);

    SrsFormat format;
    if ((err = format.initialize()) != srs_success) {
        return srs_error_wrap(err, "format failed");
    }
    // hevc_dec_conf_record
    SrsHevcDecoderConfigurationRecord *hevc_info = &format.vcodec->hevc_dec_conf_record_;

    if (true) {
        // H265 VPS (video_parameter_set_rbsp()) NAL Unit.
        // @see Section 7.3.2.1 ("Video parameter set RBSP syntax") of the H.265
        // @doc ITU-T-H.265-2021.pdf, page 54.
        SrsBuffer vps_stream((char*)vps.data(), vps.length());
        if ((err = format.hevc_demux_vps(&vps_stream)) != srs_success) {
            return srs_error_wrap(err, "vps demux failed, len=%d", vps.length());
        }