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
poolPool to create memory buffers for this port.
filenameFile name.
clock_rateThe sampling rate.
channel_countNumber of channels.
samples_per_frameNumber of samples per frame.
bits_per_sampleNumber of bits per sample (eg 16).
flagsPort creation flags, see pjmedia_file_writer_option.
buff_sizeBuffer size to be allocated. If the value is zero or negative, the port will use default buffer size (which is about 4KB).
p_portPointer to receive the file port instance.
Returns
PJ_SUCCESS on success.
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
poolPool to allocate sound port structure.
indexDevice index, or -1 to let the library choose the first available device.
clock_rateSound device's clock rate to set.
channel_countSet number of channels, 1 for mono, or 2 for stereo. The channel count determines the format of the frame.
samples_per_frameNumber of samples per frame.
bits_per_sampleSet the number of bits per sample. The normal value for this parameter is 16 bits per sample.
optionsOptions flag.
p_portPointer to receive the sound device port instance.
Returns
PJ_SUCCESS on success, or the appropriate error code.
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
pfPool factory, which will be used by the media endpoint throughout its lifetime.
ioqueueOptional 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_cntSpecify the number of worker threads to be created to poll the ioqueue.
p_endptPointer to receive the endpoint instance.
Returns
PJ_SUCCESS on success.
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_portThe sound device port.
portThe media port to be connected.
Returns
PJ_SUCCESS on success, or the appropriate error code.
//capture sound to wav file
//heat nan -test
#include<pjmedia.h>
#include<pjlib.h>
#include<stdio.h>
#include<stdlib.h>#define CLOCK_RATE 44100 //采样率
#define NCHANNELS 2  //通道数
#define SAMPLES_PER_FRAME (NCHANNELS *(CLOCK_RATE*10/1000)) //每帧包含的采样数
#define BITS_PER_SAMPLE 16  //每个抽样的字节数int main()
{pj_caching_pool cp;pjmedia_endpt *med_endpt;pj_pool_t *pool;pjmedia_port *file_port;  pjmedia_snd_port *snd_port;pj_status_t status;char tmp[10];char filename[20];status=pj_init();if(status!=PJ_SUCCESS){PJ_LOG(3,("failed","pj_init"));}pj_caching_pool_init(&cp,&pj_pool_factory_default_policy,0);
//创建endpointstatus=pjmedia_endpt_create(&cp.factory,NULL,1,&med_endpt);if(status!=PJ_SUCCESS){PJ_LOG(3,("failed","pjmedia_endpt_create"));}pool=pj_pool_create(&cp.factory,"wav_recoder",4000,4000,NULL);
//输入要保存录音的文件名    PJ_LOG(3,("wav_recorder","please input the file name!"));gets(filename);
//创建录音端口  把音频流写成wav文件status=pjmedia_wav_writer_port_create(pool,filename,CLOCK_RATE,NCHANNELS,SAMPLES_PER_FRAME,BITS_PER_SAMPLE,0,0,&file_port  //指向接收该实例的pjmedia_port);if(status!=PJ_SUCCESS){PJ_LOG(3,("failed","pjmedia_wav_write_port_create"));}
//创建单向的音频设备端口用来捕获音频status=pjmedia_snd_port_create_rec(pool,-1,PJMEDIA_PIA_SRATE(&file_port->info),PJMEDIA_PIA_CCNT(&file_port->info),PJMEDIA_PIA_SPF(&file_port->info),PJMEDIA_PIA_BITS(&file_port->info),0,&snd_port);if(status!=PJ_SUCCESS){PJ_LOG(3,("failed","pjmedia_snd_port_create_rec"));}
//连接两个端口开始录音status=pjmedia_snd_port_connect(snd_port,file_port);if(status!=PJ_SUCCESS){PJ_LOG(3,("failed","pjmedia_snd_port_connect"));}pj_thread_sleep(10);//显示终止信息  puts("PRESS <ENTER> to stop recording and quit");if(fgets(tmp,sizeof(tmp),stdin)==NULL){puts("EOF while reading stdin,will quit now..");}//养成良好习惯,吃完饭总要刷刷碗吧! pjmedia_snd_port_destroy(snd_port);pjmedia_port_destroy(file_port);pj_pool_release(pool);pjmedia_endpt_destroy(med_endpt);pj_caching_pool_destroy(&cp);pj_shutdown();return 0;
//	pj_thread_sleep(10);}

 

转载于:https://www.cnblogs.com/heat-man/p/3664558.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/363918.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

2007年暑期总结

又是一个没有回家的假期&#xff0c;一个月的鸡蛋炒拉面&#xff0c;一个月沉浸在编程的世界里……收获早已超越了技术本身&#xff0c;项目的实践&#xff0c;系统的架构&#xff0c;……更多的&#xff0c;是朋友们在一起的乐趣。A5闹鬼记&#xff0c;回去洗洗就睡了&#xf…

Linux下用户组、文件权限详解=------转载文

转载自-----原文地址&#xff1a; https://www.cnblogs.com/123-/p/4189072.html Linux下用户组、文件权限详解 用户组 在linux中的每个用户必须属于一个组&#xff0c;不能独立于组外。在linux中每个文件有所有者、所在组、其它组的概念 - 所有者 - 所在组 - 其它组 - 改变用…

风暴事件处理器–每个工作者的GC日志文件

在过去的三个月中&#xff0c;我正在与一个新团队合作&#xff0c;为电信领域的大数据分析构建产品。 Storm事件处理器是我们使用的主要框架之一&#xff0c;而且确实很棒。 您可以阅读其官方文档&#xff08;已改进&#xff09;中的更多详细信息。 Storm使用Workers来完成您…

JS实现逼真的雪花飘落特效

逼真的雪花飘落特效 效果图&#xff1a; 图片素材 &#xff1a; --> ParticleSmoke.png 代码如下&#xff0c;复制即可使用&#xff1a; <!doctype html> <html> <head> <meta charset"UTF-8"> <meta name"renderer" conte…

本地执行php查看内存占用,查看页面执行php占用内存情况

今天头脑一热&#xff0c;想看一下页面在执行的过程中占用了多少内存&#xff0c;我也不知道这样做的目的是什么&#xff0c;可能是出于我的惯性思维吧。不过这样做也不是完全没用&#xff0c;你可以清楚的知道哪些页面占用的内存比较多&#xff0c;特别是对于使用共用主机的网…

阴影及定位

阴影及定位 隐藏及阴影 标签隐藏 1、显示方式 display display: none; /*表示在页面中隐藏&#xff0c;并且不占位&#xff0c;但是重新显示出来又会占位*/ 2、透明度 opacity opacity: 0; /* 0 代表完全透明 1 代表完全显示 但是即使是透明了也会在页面中占位*/ /* 显示方式透…

ABAP--关于ABAP流程处理的一些命令的说明(stop,exit,return,check,reject)

Stop 命令使用该命令的程序位置INITIALIZATION, AT SELECTION-SCREEN, START-OF-SELECTION和GET 事件中处理说明1、 当在INITIALIZATION事件执行该命令&#xff0c;系统将直接触发应用服务器和客户端屏幕元素的发送&#xff1b;2、 在其他事件中将直接触发END-OF-SELECTION事件…

[Code+#3]寻找车位

[Code#3]寻找车位 挺厉害的线段树题 m<n&#xff0c;所以n<2000,并且只有1000次修改询问&#xff0c;mqlogn的复杂度可以接受&#xff01; 求全局&#xff1f; 对行(n)建一个线段树。 线段树中维护的东西&#xff0c;一定可以包含所有“完全包含在”这个横条中的最大正方…

ActiveMQ –经纪人网络解释–第2部分

在此博客中&#xff0c;我们将看到双工网络连接器如何工作。 在上一部分中&#xff0c;我们从broker-1和broker-2创建了一个网络连接器。 我们能够看到当代理2上有一个使用者使用队列“ foo.bar”时&#xff0c;代理1上的队列“ foo.bar”的消息如何转发到代理2上的队列“ foo…

JQ实现情人节表白程序

JQ实现情人节表白页面 效果图&#xff1a; 表白利页&#xff0c;你值得拥有哦&#xff01; 代码如下&#xff0c;复制即可使用&#xff1a; <!doctype html> <html> <head> <meta charset"utf-8"> <title>JQ实现情人节表白程序<…

php 内部异步执行顺序,event_loop中不同异步操作的执行顺序

关于js的单线程、怎么创建一个异步任务都是老生常谈的话题了&#xff0c;我们今天就总结一下js不同的异步操作到底执行顺序如何。首先我们要明白js两种任务类型&#xff0c;一个是macrotask(宏任务)&#xff0c;一个是 microtask(微任务)。一个宏任务就是一个事件循环&#xff…

OpenGPU.org域名已经被劫持

这个域名被指向了上海黄浦区某地。 此时此刻&#xff0c;我的心情无比激动&#xff0c;“这年头&#xff0c;你要是不被‘墙’了&#xff0c;都不好意思出门”。 This domain name had been redirected to Shanghai, PRC. At this moment, I’m really excited that it’s my h…

Java 8日期时间API教程:LocalDateTime

该博文是Java 8中引入的有关Date Time API的系列教程的一部分。在本博文中&#xff0c;我将介绍LocalDateTime类中可用的一些方法。 LocalDateTime是一个不可更改的线程安全对象&#xff0c;它表示ISO-8601日历系统中没有时区的日期时间&#xff0c;例如2014-03-30T02&#xf…

消息队列使用的四种场景介绍(转)

消息队列中间件是分布式系统中重要的组件&#xff0c;主要解决应用耦合&#xff0c;异步消息&#xff0c;流量削锋等问题 实现高性能&#xff0c;高可用&#xff0c;可伸缩和最终一致性架构 使用较多的消息队列有ActiveMQ&#xff0c;RabbitMQ&#xff0c;ZeroMQ&#xff0c;Ka…

一步一步SharePoint 2007之三十一:实现文档Event Handler(3)——附加Handler程序

摘要  本篇文章将介绍实现文档Event Handler的第三部分——附加Handler程序。正文  下面将记录每一步的操作过程。  1、首先打开我的网站&#xff0c;依次点击Document Center、Documents&#xff0c;进入Documents列表页面。  2、在Documents列表界面中点击Settings&a…

oracle数据库swap占用率高,物理内存空余很多,swap被持续占用的问题

本帖最后由 wyanghu 于 2012-8-18 10:21 编辑这套生产环境跑在vmware esx虚拟机上&#xff0c;现在遇到的问题是&#xff1a;操作系统内存空余很大&#xff0c;但swap被持续占用&#xff0c;直到swap被占完&#xff0c;估计系统就崩溃了。下面是我的操作系统参数及oracle参数&a…

Day2 HTML基本标签元素

Day2 HTML基本标签元素 HTML: 超文本标记语言(HyperText Mark-up Language ) 1.作用&#xff1a;写网页结构    2.HTML不区分大小写&#xff0c;建议小写   3.文件后缀 .html 或者 .htm   4.html由浏览器解析执行. 由上往下&#xff0c;由左往右 1) HTML标…

C# 如何跨平台调用C++的函数指针!

函数指针搞C的人应该都知道&#xff0c;效率高&#xff0c;易用性强&#xff0c;隐蔽代码等。在C里面调用C写的dll的函数指针那是在容易不过了。使用C#就稍微麻烦点了&#xff01;那怎么掉呢&#xff1f;通过上面的第一篇文章我们知道应该使用委托 delegate。如果再高级点&…

Java hashCode() 和 equals()的若干问题解答

本章的内容主要解决下面几个问题&#xff1a; 1 equals() 的作用是什么&#xff1f; 2 equals() 与 的区别是什么&#xff1f; 3 hashCode() 的作用是什么&#xff1f; 4 hashCode() 和 equals() 之间有什么联系&#xff1f; https://www.cnblogs.com/skywang12345/p/3324958.…

Builder模式和Spring框架

介绍 每当对象同时具有强制属性和可选属性时&#xff0c;我都喜欢使用构建器模式 。 但是构建对象通常是Spring框架的责任&#xff0c;因此让我们看看如何同时使用基于Java和XML的Spring配置来使用它。 建造者的例子 让我们从下面的Builder类开始。 public final class Confi…