mediastream2说明文档-2(2.7.3)

Howto 1: build a sample audio graph.

Initialize mediastreamer2

When using mediastreamer2, your first task is to initialize the library:

##include <mediastreamer2/mscommon.h>
int i;
i=ms_init();
if (i!=0)
return -1;
Mediastreamer2 provides internal components which are called filters. Those filters must be linked together so that OUTPUT from one filter is sent to INPUT of the other filters.

Usually, filters are used for processing audio or video data. They could capture data, play/draw data, encode/decode data, mix data (conference), transform data (echo canceller). One of the most important filter is the RTP filters that are able to send and receive RTP data.

Graph sample

If you are using mediastreamer2, you probably want to do Voice Over IP and get a graph providing a 2 way communication. This 2 graphs are very simple:

This first graph shows the filters needed to capture data from a sound card, encode them and send it through an RTP session.

AUDIO -> ENCODER -> RTP
CAPTURE -> -> SENDER
This second graph shows the filters needed to receive data from an RTP session decode it and send it to the playback device.

RTP -> DECODER -> DTMF -> AUDIO
RECEIVER -> -> GENERATION -> PLAYBACK
Code to initiate the filters of the Graph sample

Note that the NULL/error checks are not done for better reading. To build the graph, you‘ll need some information: you need to select the sound card and of course have an RTP session created with oRTP.

MSSndCard *sndcard;
sndcard=ms_snd_card_manager_get_default_card(ms_snd_card_manager_get());
/* audio capture filter */
MSFilter *soundread=ms_snd_card_create_reader(captcard);
MSFilter *soundwrite=ms_snd_card_create_writer(playcard);
MSFilter *encoder=ms_filter_create_encoder("PCMU");
MSFilter *decoder=ms_filter_create_decoder("PCMU");
MSFilter *rtpsend=ms_filter_new(MS_RTP_SEND_ID);
MSFilter *rtprecv=ms_filter_new(MS_RTP_RECV_ID);
RtpSession *rtp_session = *** your_ortp_session *** ;
ms_filter_call_method(rtpsend,MS_RTP_SEND_SET_SESSION,rtp_session);
ms_filter_call_method(rtprecv,MS_RTP_RECV_SET_SESSION,rtp_session);
MSFilter *dtmfgen=ms_filter_new(MS_DTMF_GEN_ID);
In most cases, the above graph is not enough: you‘ll need to configure filter‘s options. As an example, you need to set sampling rate of sound cards‘ filters:

int sr = 8000;
int chan=1;
ms_filter_call_method(soundread,MS_FILTER_SET_SAMPLE_RATE,&sr);
ms_filter_call_method(soundwrite,MS_FILTER_SET_SAMPLE_RATE,&sr);
ms_filter_call_method(stream->encoder,MS_FILTER_SET_SAMPLE_RATE,&sr);
ms_filter_call_method(stream->decoder,MS_FILTER_SET_SAMPLE_RATE,&sr);
ms_filter_call_method(soundwrite,MS_FILTER_SET_NCHANNELS, &chan);
/* if you have some fmtp parameters (from SDP for example!)
char *fmtp1 = ** get your fmtp line **;
char *fmtp2 = ** get your fmtp line **;
ms_filter_call_method(stream->encoder,MS_FILTER_ADD_FMTP, (void*)fmtp1);
ms_filter_call_method(stream->decoder,MS_FILTER_ADD_FMTP,(void*)fmtp2);
Code to link the filters and run the graph sample

ms_filter_link(stream->soundread,0,stream->encoder,0);
ms_filter_link(stream->encoder,0,stream->rtpsend,0);
ms_filter_link(stream->rtprecv,0,stream->decoder,0);
ms_filter_link(stream->decoder,0,stream->dtmfgen,0);
ms_filter_link(stream->dtmfgen,0,stream->soundwrite,0);
Then you need to ‘attach‘ the filters to a ticker. A ticker is a graph manager responsible for running filters.

In the above case, there is 2 independant graph within the ticker: you need to attach the first element of each graph (the one that does not contains any INPUT pins)

/* create ticker */
MSTicker *ticker=ms_ticker_new();
ms_ticker_attach(ticker,soundread);
ms_ticker_attach(ticker,rtprecv);
Code to unlink the filters and stop the graph sample

ms_ticker_detach(ticker,soundread);
ms_ticker_detach(ticker,rtprecv);
ms_filter_unlink(stream->soundread,0,stream->encoder,0);
ms_filter_unlink(stream->encoder,0,stream->rtpsend,0);
ms_filter_unlink(stream->rtprecv,0,stream->decoder,0);
ms_filter_unlink(stream->decoder,0,stream->dtmfgen,0);
ms_filter_unlink(stream->dtmfgen,0,stream->soundwrite,0);
if (rtp_session!=NULL) rtp_session_destroy(rtp_session);
if (rtpsend!=NULL) ms_filter_destroy(rtpsend);
if (rtprecv!=NULL) ms_filter_destroy(rtprecv);
if (soundread!=NULL) ms_filter_destroy(soundread);
if (soundwrite!=NULL) ms_filter_destroy(soundwrite);
if (encoder!=NULL) ms_filter_destroy(encoder);
if (decoder!=NULL) ms_filter_destroy(decoder);
if (dtmfgen!=NULL) ms_filter_destroy(dtmfgen);
if (ticker!=NULL) ms_ticker_destroy(ticker);

时间: 2024-11-09 03:04:47

mediastream2说明文档-2(2.7.3)的相关文章

mediastream2说明文档-3(2.7.3)

Starting mediastreamer2 library. Functions void  ms_init (void) int  ms_load_plugins (const char *directory) void  ms_exit (void) int  ms_get_payload_max_size () int  ms_discover_mtu (const char *destination_host) void  ms_set_mtu (int mtu) void  ms_

原创SQlServer数据库生成简单的说明文档小工具(附源码)

这是一款简单的数据库文档生成工具,主要实现了SQlServer生成说明文档的小工具,目前不够完善,主要可以把数据库的表以及表的详细字段信息,导出到 Word中,可以方便开发人员了解数据库的信息或写技术说明文档. 技术上主要采用的 C#+Dapper+Npod ,开发工具为Vs2015,基于Net4.5框架. 实现思路: 1.首先获取数据库的字符串,测试链接是否成功, 2.通过脚本获取该服务器的数据库列表. 3.根据数据库找到该数据库的所有数据表 4.通过脚本找到该数据表所有的字段信息 5.使用N

ICE中间件说明文档

1       ICE中间件简介 2       平台核心功能 2.1        接口描述语言(Slice) 2.2        ICE运行时 2.2.1         通信器 2.2.2         对象适配器 2.2.3         位置透明性 2.3        异步编程模型 2.3.1         异步方法调用 2.3.2         异步方法分派 2.4        订阅/发布编程模型 2.5        动态服务管理(IceBox) 2.6       

艾恩ASP无组件上传类(上传组件)说明文档(from www.sysoft.cc)

艾恩ASP无组件上传类(上传组件)说明文档2010-1-18 By Anlige一.简介自从接触ASP就开始接触上传,看过一些上传类,但是总感觉封装的还是不够简单,因此自己尝试写一个能够用最少最简单的代码实现各种上传方式的上传类.在学校期间就开始写,一点点的完善.优化,到现在的版本,现在的版本能适应各种上传方式.上传类的主要的功能如下:1.自由设置最大上传大小.单文件最大上传大小2.自由设置允许上传的文件类型3.可设置文本的编码,以适应各种上传环境4.内置进度条,a用户可选择开启和关闭5.多种错

详细设计说明文档

1引言 1.1编写目的 本文档为软件<自习任我行>的详细设计说明书,向阅读人员介绍本软件的整体框架和详细设计. 1.2背景 说明: 项目名称:自习任我行 开发人员:杨波.崔海营.周亚豪.闵芮.高琪.张丹丹.蔡容玉 用户:铁道大学全体学生 运行:安卓手机 系统描述:自习任我行软件为铁道大学的学生提供了一个方便查询自习室上自习的快速平台.该软件分为查询自习室模块和安排自习室模块.自习任我行软件是一套功能简单实用的的专门用于学生自习的软件,具有操作方便高效迅速等特点.该软件采用eclipse开发工具

weiapi2.2 HelpPage自动生成接口说明文档和接口测试功能

在开发Webapi项目时每写完一个方法时,是不是需要添加相应的功能说明和测试案例呢?为了更简单方便的写说明接口文档和接口测试HelpPage提供了一个方便的途径. 她的大致原理是:在编译时会生成.dll程序集和.xml程序集说明文件,通过xml文件获取Controller名称.action名称.参数信息和备注信息等.这样接口说明文档就可以放到备注信息了,个人觉得确实粗暴简单 .那接口测试在哪呢?这里用到nuget第三方程序包:webapitestclient 先上效果图吧! 案例是用VS2013

Eclipse4.7使用基础 制作说明文档

os :windows7 x64    jdk:jdk-8u131-windows-x64    ide:Eclipse Oxygen Release (4.7.0) 三个代码 父类.接口类.子类 父类 package jizuiku.test01; /** * 人抽象类 * * @author 给最苦 * @version 17.08.29 */ public abstract class Person { /** * 吃饭功能 */ public abstract void eat(); /

【腾讯GAD暑期训练营游戏程序班】游戏场景管理作业说明文档

场景管理作业说明文档                              用了八叉树的算法,测出三层时最快,区域范围内物体数量为21块,控制台打印出的结果如图所示: 场景物体:游戏中,所有具有空间属性的物体游戏场景:<围棋>二维表<进击的围棋><围棋世界>基于空间分组的场景管理的进一步优化进一步分组四叉树视锥范围剔除非可见区域当前必要场景区域 动态加载谷歌 可感知即存在 不可感知即不存在 场景加载

文件上传到百度云盘说明文档

图1 图2 图3 图4 1. 上传百度云盘功能,由于百度开发者中还没有开放对.net 操作的SDK,所以我们现在只能使用原生的REST API   我们的做法就是如何用C# 语言调用 调用curl 命令. 2. curl是利用URL语法在命令行方式下工作的开源文件传输工具.它被广泛应用在Unix.多种Linux发行版中,并且有DOS和Win32.Win64下的移植版本. 要操作curl 我们需要引入LibCurlNet.dll   3.百度上传我们需要有百度账号,而且需要申请开发者功能进入主页后