安防音頻

音頻編碼相關的調研:

1、 默認情況下將使用PCMU (G711u)。PCMU和PCMA能給你帶來比較好的音質效果但同時也將佔用比較大的帶寬。
如果你的網絡情況不是很好,你可以選擇G723或者G729編碼,這兩個編碼可以提供比較好的音質的情況下佔
用比較少的帶寬資源。如果你的帶寬充足的情況下,你也可以選擇G722寬帶編碼,它將帶給你逼真的音質效果。

G711 實際佔用帶寬 每線90.4kbit/s 100線併發佔用 9Mbps
G729 實際佔用帶寬 每線34.4kbit/s 100線併發佔用 3.4Mbps
G723 實際佔用帶寬 每線22.9kbit/s 100線併發佔用 2.2Mbps

帶寬=包長度×每秒包數
=包長度×(1/打包週期)
=(Ethernet頭+IP頭+UDP頭+RTP頭+有效載荷)×(1/打包週期)
=(208bit +160bit+64bit+96bit +有效載荷)×(1/打包週期)
=(528bit+(打包週期(秒)×每秒的比特數))×(1/打包週期)
=( 528 / 打包週期 ) + 每秒比特數

SRS發佈音頻raw的API定義:
/**
* write an audio raw frame to srs.
* not similar to h.264 video, the audio never aggregated, always
* encoded one frame by one, so this api is used to write a frame.
*
* @param sound_format Format of SoundData. The following values are defined:
* 0 = Linear PCM, platform endian
* 1 = ADPCM
* 2 = MP3
* 3 = Linear PCM, little endian
* 4 = Nellymoser 16 kHz mono
* 5 = Nellymoser 8 kHz mono
* 6 = Nellymoser
* 7 = G.711 A-law logarithmic PCM
* 8 = G.711 mu-law logarithmic PCM
* 9 = reserved
* 10 = AAC
* 11 = Speex
* 14 = MP3 8 kHz
* 15 = Device-specific sound
* Formats 7, 8, 14, and 15 are reserved.
* AAC is supported in Flash Player 9,0,115,0 and higher.
* Speex is supported in Flash Player 10 and higher.
* @param sound_rate Sampling rate. The following values are defined:
* 0 = 5.5 kHz
* 1 = 11 kHz
* 2 = 22 kHz
* 3 = 44 kHz
* @param sound_size Size of each audio sample. This parameter only pertains to
* uncompressed formats. Compressed formats always decode
* to 16 bits internally.
* 0 = 8-bit samples
* 1 = 16-bit samples
* @param sound_type Mono or stereo sound
* 0 = Mono sound
* 1 = Stereo sound
* @param timestamp The timestamp of audio.
*
* @example /trunk/research/librtmp/srs_aac_raw_publish.c
* @example /trunk/research/librtmp/srs_audio_raw_publish.c
*
* @remark for aac, the frame must be in ADTS format.
* @see aac-mp4a-format-ISO_IEC_14496-3+2001.pdf, page 75, 1.A.2.2 ADTS
* @remark for aac, only support profile 1-4, AAC main/LC/SSR/LTP,
* @see aac-mp4a-format-ISO_IEC_14496-3+2001.pdf, page 23, 1.5.1.1 Audio object type
*
* @see https://github.com/simple-rtmp-server/srs/issues/212
* @see E.4.2.1 AUDIODATA of video_file_format_spec_v10_1.pdf
*
* @return 0, success; otherswise, failed.
*/
extern int srs_audio_write_raw_frame(srs_rtmp_t rtmp,
char sound_format, char sound_rate, char sound_size, char sound_type,
char* frame, int frame_size, u_int32_t timestamp
);

    /**
    * whether aac raw data is in adts format,
    * which bytes sequence matches '1111 1111 1111'B, that is 0xFFF.
    * @param aac_raw_data the input aac raw data, a encoded aac frame data.
    * @param ac_raw_size the size of aac raw data.
    *
    * @reamrk used to check whether current frame is in adts format.
    *       @see aac-mp4a-format-ISO_IEC_14496-3+2001.pdf, page 75, 1.A.2.2 ADTS
    * @example /trunk/research/librtmp/srs_aac_raw_publish.c
    *
    * @return 0 false; otherwise, true.
    */
    extern srs_bool srs_aac_is_adts(char* aac_raw_data, int ac_raw_size);

    /**
    * parse the adts header to get the frame size,
    * which bytes sequence matches '1111 1111 1111'B, that is 0xFFF.
    * @param aac_raw_data the input aac raw data, a encoded aac frame data.
    * @param ac_raw_size the size of aac raw data.
    *
    * @return failed when <=0 failed; otherwise, ok.
    */
    extern int srs_aac_adts_frame_size(char* aac_raw_data, int ac_raw_size);   
發佈了50 篇原創文章 · 獲贊 3 · 訪問量 6萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章