PJMEDIA之录音器的使用(capture sound to avi file)
為了熟悉pjmedia的相關函數以及使用方法,這里練習了官網上的一個錄音器的例子。
核心函數:
| pj_status_t pjmedia_wav_writer_port_create | ( | pj_pool_t *? | pool, |
| ? | ? | const char *? | filename, |
| ? | ? | unsigned? | clock_rate, |
| ? | ? | unsigned? | channel_count, |
| ? | ? | unsigned? | samples_per_frame, |
| ? | ? | unsigned? | bits_per_sample, |
| ? | ? | unsigned? | flags, |
| ? | ? | pj_ssize_t? | buff_size, |
| ? | ? | pjmedia_port **? | p_port? |
| ? | ) | ? | ? |
Create a media port to record streams to a WAV file. Note that the port must be closed properly (with pjmedia_port_destroy()) so that the WAV header can be filled with correct values (such as the file length). WAV writer port supports for writing audio in uncompressed 16 bit PCM format or compressed G.711 U-law/A-law format, this needs to be specified in flags param.
Parameters| pool | Pool to create memory buffers for this port. |
| filename | File name. |
| clock_rate | The sampling rate. |
| channel_count | Number of channels. |
| samples_per_frame | Number of samples per frame. |
| bits_per_sample | Number of bits per sample (eg 16). |
| flags | Port creation flags, see pjmedia_file_writer_option. |
| buff_size | Buffer size to be allocated. If the value is zero or negative, the port will use default buffer size (which is about 4KB). |
| p_port | Pointer to receive the file port instance. |
| pj_status_t pjmedia_snd_port_create_rec | ( | pj_pool_t *? | pool, |
| ? | ? | int? | index, |
| ? | ? | unsigned? | clock_rate, |
| ? | ? | unsigned? | channel_count, |
| ? | ? | unsigned? | samples_per_frame, |
| ? | ? | unsigned? | bits_per_sample, |
| ? | ? | unsigned? | options, |
| ? | ? | pjmedia_snd_port **? | p_port? |
| ? | ) | ? | ? |
Create unidirectional sound device port for capturing audio streams from the sound device with the specified parameters.
Parameters| pool | Pool to allocate sound port structure. |
| index | Device index, or -1 to let the library choose the first available device. |
| clock_rate | Sound device's clock rate to set. |
| channel_count | Set number of channels, 1 for mono, or 2 for stereo. The channel count determines the format of the frame. |
| samples_per_frame | Number of samples per frame. |
| bits_per_sample | Set the number of bits per sample. The normal value for this parameter is 16 bits per sample. |
| options | Options flag. |
| p_port | Pointer to receive the sound device port instance. |
| pj_status_t pjmedia_endpt_create | ( | pj_pool_factory *? | pf, |
| ? | ? | pj_ioqueue_t *? | ioqueue, |
| ? | ? | unsigned? | worker_cnt, |
| ? | ? | pjmedia_endpt **? | p_endpt? |
| ? | ) | ? | ? |
Create an instance of media endpoint.
Parameters| pf | Pool factory, which will be used by the media endpoint throughout its lifetime. |
| ioqueue | Optional ioqueue instance to be registered to the endpoint. The ioqueue instance is used to poll all RTP and RTCP sockets. If this argument is NULL, the endpoint will create an internal ioqueue instance. |
| worker_cnt | Specify the number of worker threads to be created to poll the ioqueue. |
| p_endpt | Pointer to receive the endpoint instance. |
| pj_status_t pjmedia_snd_port_connect | ( | pjmedia_snd_port *? | snd_port, |
| ? | ? | pjmedia_port *? | port? |
| ? | ) | ? | ? |
Connect a port to the sound device port. If the sound device port has a sound recorder device, then this will start periodic function call to the port's put_frame() function. If the sound device has a sound player device, then this will start periodic function call to the port's get_frame() function.
For this version of PJMEDIA, the media port MUST have the same audio settings as the sound device port, or otherwise the connection will fail. This means the port MUST have the same clock_rate, channel count, samples per frame, and bits per sample as the sound device port.
Parameters| snd_port | The sound device port. |
| port | The media port to be connected. |
?
轉載于:https://www.cnblogs.com/heat-man/p/3664558.html
總結
以上是生活随笔為你收集整理的PJMEDIA之录音器的使用(capture sound to avi file)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 《Effective Java》读书笔记
- 下一篇: 阴影及定位