MEDIASTREAM2 Description Document-2 (2.7.3)

Source: Internet
Author: User

HOWTO 1:build a sample audio graph.

Initialize Mediastreamer2

When using Mediastreamer2, your first task was to initialize the library:

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

Usually, filters is 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 was the RTP filters that was able to send and receive RTP data.

Graph sample

If you are using the Mediastreamer2, you probably want-to-do Voice over IP and get a graph providing a 2-in-a-do communication. This 2 graphs is very simple:

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

RTP, AUDIO-ENCODER
SENDER, CAPTURE
This second graph shows the filters needed to receive data from a RTP session decode it and send it to the playback Devic E.

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

Note that the null/error checks is not do for better reading. To build the graph, you'll need some information:you need to select the sound card and of course has an RTP session CREA Ted 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 was 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 are 2 independant graph within the ticker:you need to attach the first element of each graph (the One, 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);

MEDIASTREAM2 Description Document-2 (2.7.3)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.