Security video surveillance system video cloud solution EasyCVR voice forwarding function audio data packaging and sending process introduction

At present, our video cloud service platform EasyCVR can integrate the private protocol of Haikang EHome. In the previous article, I also told you about the configuration and calling process of the EHome protocol. If you are interested, you can read: Configuration and protocol introduction , Ehome protocol Introduction to the calling process .

EasyCVR1.png

EasyCVR voice forwarding function audio data package sending process

1. See the figure below for the overall data structure

202.png

2. ps file header

int gb28181_make_ps_header(char *pData, unsigned long long s64Scr)
{
    unsigned long long lScrExt = (s64Scr) % 100;
    s64Scr = s64Scr / 100;
    bits_buffer_t      bitsBuffer;
    bitsBuffer.i_size = PS_HDR_LEN;
    bitsBuffer.i_data = 0;
    bitsBuffer.i_mask = 0x80;
    bitsBuffer.p_data =    (unsigned char *)(pData);
    memset(bitsBuffer.p_data, 0, PS_HDR_LEN);
    bits_write(&bitsBuffer, 32, 0x000001BA);            /*start codes 起始码*/
    bits_write(&bitsBuffer, 2,     1);                        /*marker bits '01b'*/
    bits_write(&bitsBuffer, 3,     (s64Scr>>30)&0x07);     /*System clock [32..30]*/
    bits_write(&bitsBuffer, 1,     1);                               /*marker bit*/
    bits_write(&bitsBuffer, 15, (s64Scr>>15)&0x7FFF);   /*System clock [29..15]*/
    bits_write(&bitsBuffer, 1,     1);                            /*marker bit*/
    bits_write(&bitsBuffer, 15, s64Scr & 0x7fff);        /*System clock [14..0]*/
    bits_write(&bitsBuffer, 1,     1);                        /*marker bit*/
    bits_write(&bitsBuffer, 9,     0);                     /*SCR extension*/
    bits_write(&bitsBuffer, 1,     1);                        /*marker bit*/
    bits_write(&bitsBuffer, 22, (255)&0x3fffff);        /*bit rate(n units of 50 bytes per second.)*/
    bits_write(&bitsBuffer, 2,     3);                        /*marker bits '11'*/
    bits_write(&bitsBuffer, 5,     0x1f);                    /*reserved(reserved for future use)*/
    bits_write(&bitsBuffer, 3,     0);                        /*stuffing length*/
    return 0;
}

The packet start code field pack_start_code is a bit string of '0000 0000 0000 0000 0000 0001 1011 1010' (0x000001BA), which is used to mark the beginning of a packet

System clock reference fields system_clock_reference_base and system_clock_reference_extenstion

Marker bit field marker_bit 1-bit field, fixed value '1'

The program compound rate field program_mux_rate is a 22-bit integer that specifies the rate at which the P-STD receives the program stream during the packet containing this field. Its value is in units of 50 bytes/second, and a value of 0 is not allowed

The packet stuffing length field pack_stuffing_length is a 3-bit integer that specifies the number of stuffing bytes after the field

Stuffing_byte 8-bit field, the value is always '1111 1111'

3. PS system information

system_header_start_code is a 32-bit field of the system header start code field, which takes a bit string of '0000 0000 0000 0000 0000 0001 1011 1011' (0x000001BB), indicating the start of the system header

header_length The header length field is a 16-bit field. Point out the byte length of the system header after this field. This field may be extended in future expansions of this specification

marker_bit occupies 1 bit, the fixed value is 1

rate_bound: A 22-bit field of rate bound field. The value is not less than the maximum value of the program_mux_rate field encoded in any packet of the program stream. This field can be used by the decoder to estimate whether it is capable of decoding the entire stream

marker_bit occupies 1 bit, the fixed value is 1

audio_bound Audio bound field is a 6-bit field, the value is an integer in the closed interval from 0 to 32, and is not less than that of the GB/T XXXX.3 and GB/T AAAA.3 audio streams that are simultaneously active in the decoding process in the program stream Maximum number

fixed_flag The fixed flag field is a 1-bit flag. When set to '1', it means that the bit rate is constant; when set to '0', it means that the bit rate of the operation is variable

CSPS_flag CSPS flag field is a 1-bit field. When set to '1', the program stream conforms to the standard

system_audio_lock_flag The system audio lock flag field is a 1-bit field. Indicates that there is a specified ratio between the audio sampling rate of the system target decoder and system_clock_frequency

system_video_lock_flag The system video lock flag field is a 1-bit field. Indicates that there is a specified ratio between the video frame rate of the system target decoder and system_clock_frequency

marker_bit occupies 1 bit, the fixed value is 1

vedio_bound Video bound field 5-bit field, the value is an integer in the closed interval from 0 to 16 and not less than the maximum number of GB/T XXXX.2 and GB/T AAAA.2 streams that are simultaneously active during the decoding process in the program stream

packet_rate_restriction_flag A 1-bit flag in the packet rate restriction flag field. If the CSPS flag is '1', this field indicates which restriction specified in 2.7.9 applies to the packet rate. If the CSPS flag is '0', the meaning of this field is undefined.

reserved_bits reserved bit field, 7-bit field. The fixed value should be '111 1111'

The stream_id stream identification field is an 8-bit field. It indicates the encoding and elementary stream number of the stream involved in the P-STD_buffer_bound_scale and P-STD_buffer_size_bound fields that follow. If the value is '1011 1000', the following P-STD_buffer_bound_scale and P-STD_buffer_size_bound fields refer to all audio streams in the program stream; if the value is '1011 1001', the subsequent P-STD_buffer_bound_scale and P-STD_buffer_size_bound fields refer to All video streams in the program stream

P-STD_buffer_bound_scale The P-STD buffer bound scale field is a 1-bit field. Represents the scale factor used to interpret the subsequent P-STD_buffer_size_bound field. If the preceding stream_id represents an audio stream, the value of this field is '0'. If it represents a video stream, the value of this field is '1'. For all other stream types, the value of this field can be either '0' or '1'

P-STD_buffer_size_bound The P-STD buffer size bound field is a 13-bit unsigned integer, and the value is not less than the maximum value of the P-STD buffer size BSn of all packets of stream n in the program stream. If the value of P-STD_buffer_bound_scale is '0', then this field uses 128 bytes as a unit to measure the boundary of the buffer size

4. psm information

packet_start_code_prefix The 24-bit code of the packet start code prefix field. It and the map_stream_id that follow it together form a packet start code to mark the beginning of the packet. This field is a bit string whose value is '0000 0000 0000 0000 0000 0001' (0x000001)

map_stream_id is an 8-bit field of mapping stream identification field, with a value of 0xBC

program_stream_map_length Program stream map length field is a 16-bit field. Indicates the number of bytes in the program_stream_map immediately following this field

current_next_indicator The current next indicator field is a 1-bit field. When set to '1', it means that the transmitted program stream map is currently available. When set to '0', it means that the transmitted program stream mapping is not yet available, but it will be the next effective table

reserved reserved field 2 bits

program_stream_map_version The program stream map version field is a 5-bit field that represents the version number of the entire program stream map. Once the definition of the program stream mapping changes, this field will be incremented by 1, and modulo 32. When current_next_indicator is '1', this field should be the version number of the currently applicable program stream mapping; when current_next_indicator is '0', this field should be the version number of the next applicable program stream mapping

reserved reserved field 7 bits

marker_bit flag bit, a 1-bit field, the value is '1'

program_stream_info_length The program stream information length field is a 16-bit field, indicating the total length of the descriptor immediately following this field

elementary_stream_map_length The elementary stream map length field is a 16-bit field that indicates the byte length of all elementary stream information in the program stream map. It only includes stream_type, elementary_stream_id and elementary_stream_info_length fields

stream_type stream type field
MPEG-4 video stream: 0x10;
H.264 video stream: 0x1B;
SVAC video stream: 0x80;
G.711 audio stream: 0x90;
G.722.1 audio stream: 0x92;
G.723.1 audio stream: 0x93;
G.729 audio stream: 0x99;
SVAC audio stream: 0x9B.

elementary_stream_id The elementary stream identifier field is an 8-bit field that indicates the value of the stream_id field in the PES packet header of the PES packet where the elementary stream is located. (The definition of this field, where 0x (C0DF) refers to audio and 0x (E0EF) refers to video)

elementary_stream_info_length The elementary stream information length field is a 16-bit field, indicating the byte length of the descriptor immediately following this field. (That is, the length of the stream description of this type. The specified length after this field is not in the range class specified by elementary_stream_map_length.)

CRC_32 CRC 32 characters

A 32-bit field, which contains the CRC value to generate a 0 output value in the decoder register defined in Appendix A after processing the complete program stream mapping

5. pes data

int gb28181_make_pes_header(char *pData, int stream_id, int payload_len, unsigned long long pts, unsigned long long dts)
{

    bits_buffer_t      bitsBuffer;
    bitsBuffer.i_size = PES_HDR_LEN;
    bitsBuffer.i_data = 0;
    bitsBuffer.i_mask = 0x80;
    bitsBuffer.p_data =    (unsigned char *)(pData);
    memset(bitsBuffer.p_data, 0, PES_HDR_LEN);
    /*system header*/
    bits_write( &bitsBuffer, 24,0x000001);    /*start code*/
    bits_write( &bitsBuffer, 8, (stream_id));    /*streamID*/
    bits_write( &bitsBuffer, 16,(payload_len)+13);    /*packet_len pes剩余头部以及后面的es长度之和,比如SPS长度+13*/
    bits_write( &bitsBuffer, 2, 2 );        /*'10'*/
    bits_write( &bitsBuffer, 2, 0 );        /*scrambling_control*/
    bits_write( &bitsBuffer, 1, 1 );        /*priority*/
    bits_write( &bitsBuffer, 1, 1 );        /*data_alignment_indicator*/
    bits_write( &bitsBuffer, 1, 0 );        /*copyright*/
    bits_write( &bitsBuffer, 1, 0 );        /*original_or_copy*/
    bits_write( &bitsBuffer, 1, 1 );        /*PTS_flag 是否有PTS*/
    bits_write( &bitsBuffer, 1, 1 );        /*DTS_flag 是否有DTS信息*/
    bits_write( &bitsBuffer, 1, 0 );        /*ESCR_flag*/
    bits_write( &bitsBuffer, 1, 0 );        /*ES_rate_flag*/
    bits_write( &bitsBuffer, 1, 0 );        /*DSM_trick_mode_flag*/
    bits_write( &bitsBuffer, 1, 0 );        /*additional_copy_info_flag*/
    bits_write( &bitsBuffer, 1, 0 );        /*PES_CRC_flag*/
    bits_write( &bitsBuffer, 1, 0 );        /*PES_extension_flag*/
    bits_write( &bitsBuffer, 8, 10);        /*header_data_length*/

    /*PTS,DTS*/
    bits_write( &bitsBuffer, 4, 3 );                    /*'0011'*/
    bits_write( &bitsBuffer, 3, ((pts)>>30)&0x07 );     /*PTS[32..30]*/
    bits_write( &bitsBuffer, 1, 1 );
    bits_write( &bitsBuffer, 15,((pts)>>15)&0x7FFF);    /*PTS[29..15]*/
    bits_write( &bitsBuffer, 1, 1 );
    bits_write( &bitsBuffer, 15,(pts)&0x7FFF);          /*PTS[14..0]*/
    bits_write( &bitsBuffer, 1, 1 );
    bits_write( &bitsBuffer, 4, 1 );                    /*'0001'*/
    bits_write( &bitsBuffer, 3, ((dts)>>30)&0x07 );     /*DTS[32..30]*/
    bits_write( &bitsBuffer, 1, 1 );
    bits_write( &bitsBuffer, 15,((dts)>>15)&0x7FFF);    /*DTS[29..15]*/
    bits_write( &bitsBuffer, 1, 1 );
    bits_write( &bitsBuffer, 15,(dts)&0x7FFF);          /*DTS[14..0]*/
    bits_write( &bitsBuffer, 1, 1 );
    return 0;
}

Guess you like

Origin blog.csdn.net/EasyNVS/article/details/108635518