PJSUA2 Development Documentation-sixth chapter media

Source: Internet
Author: User

6. Media

A media object is an object that can produce media or accept media.

The important subclass of media is Audiomedia, which represents audio media. PJSUA2 supports multiple types of audio media objects:

    • Capture the Audiomedia of a device for capturing audio from a sound device.
    • The audiomedia of the playback device can play audio to the sound device.
    • Call audio media for sending and receiving audio to remote people.
    • Audiomediaplayer, play WAV file.
    • Audiomediarecorder Audio is recorded to a WAV file.

More media objects may be added in the future.

6.1 Audio Conference Bridge

Conference Bridge provides a simple and powerful concept for managing audio streams between audio media. The simple principle is that the audio source is connected to the audio destination, and the bridge sends the audio stream from the source address to the destination, and so on. If multiple sources are being sent to the same destination, the audio from the source is mixed. If a signal source is sent to multiple destinations, the bridge is responsible for copying the audio from the source to multiple destinations. The bridge will even take care of the media for different clock frequencies and times.

In PJSUA2, all audio media objects are inserted into the Central Conference bridge for easy operation. First, the plug-in audio media will not connect to anything, so the media will not flow out/into any objects. Audio media source can use API?? Audiomedia.starttransmit ()/Audiomedia.stoptransmit ()) starts/stops the transfer to the destination.

The audio media object of the plug-in conferencing bridge is given a port ID number that identifies the bridge object. The application can use API Audiomedia.getportid () to retrieve the port ID. Typically, an application does not need to worry about the conferencing bridge and its port ID (all of which will be owned by the media Class) unless the application is creating its own custom audio media.

6.1.1 Play WAV files?

To play a WAV file to a sound device, simply transfer the WAV playback object to the playback media of the sound device:

Audiomediaplayer player; Audiomedia& play_med = endpoint::instance (). Auddevmanager (). Getplaybackdevmedia (); Try
{ Player.createplayer ("file.wav");
Catch (error&
{}

by default, WAV files are played in circular mode. to disable looping, when you create the player, you specify PJMEDIA_FILE_NO_LOOP :

Player.createplayer ("file.wav", Pjmedia_file_no_loop);

There is no loop, and once playback reaches the end of the WAV file, it will play mute.

When you're finished playing, just stop playing and stop playing:

Try {    player.stoptransmit (play_med);} Catch (error& err) {}

When the playback is stopped, playback resumes from the last playback location and the transfer is resumed. Use Player.setpos () to the playback position, set to the desired location.

6.1.2 Recording as WAV file

If you want to record an audio device to a WAV file, simply do the following:

Audiomediarecorder Recorder; Audiomedia& cap_med = endpoint::instance (). Auddevmanager (). Getcapturedevmedia (); Try {    Recorder.createrecorder ("file.wav");     Catch (error& err) {}

The media will flow from the sound device to the WAV video file. As before, to stop or pause a recording, simply stop the transfer:

Try {   catch(error& err) {}

Note that stopping the transfer to the WAV recorder as described above does not close the WAV file, and you can restart the recording by connecting the source to the WAV recorder. The recorded WAV file cannot be played before it is closed. To turn off the WAV recorder, simply delete it:

Delete recorder;

6.1.3 Local Audio loopback

Check whether the local sound device (capture and playback device) is working properly by sending audio from the capture device directly to the playback device (that is, local loopback). You can do this:

Cap_med.starttransmit (play_med);

6.1.4 Loop Audio

If necessary, you can loop audio from an audio media object to itself (that is, the audio received from the object will be transferred to itself). You can play back audio from any object as long as the object has two-way media. This means that the audio media can be looped back so that the audio received by the remote person will be transmitted to him/her. However, you cannot loop a WAV player or a sound recorder, because these objects can only be played or recorded, not simultaneously played and recorded.

6.1.5 Normal Call

A single call can have multiple media (such as audio and video). Application can use API?? Call.getmedia () retrieves the audio media. Then, for normal calls, we want to establish two-way audio with remote people, which can be done easily by connecting sound devices and calling audio media, and vice versa:

Callinfo ci =Call.getinfo (); Audiomedia*aud_med =NULL;//Find out which Media index is the audio for(Unsigned i=0; I<ci.media.size (); ++i) {if(Ci.media[i].type = =Pjmedia_type_audio) {aud_med= (Audiomedia *) Call.getmedia (i);  Break; }}if(aud_med) {//This would connect the sound device/mic to the call audio mediaCap_med.starttransmit (*aud_med); //And this would connect the call Audio media to the sound device/speakerAud_med->Starttransmit (play_med);}

6.1.6 Second Call

Let's say we want to talk to two partners at the same time. Since we have a two-way media connection with one side, we only need to add two-way connections to each other using the following code:

Audiomedia *aud_med2 = (Audiomedia *) Call2.getmedia (AUD_IDX); if (aud_med2) {    cap_med->starttransmit (*aud_med2);    Aud_med2-Starttransmit (play_med);}

Now we can talk to both of us and we will hear the voices of either side. But at this stage, the remote side cannot speak or hear each other (i.e. we are not in full-conference mode).

6.1.7 Conference Call

In order to communicate with each other, only two-way media should be established:

Aud_med->starttransmit (*aud_med2); Aud_med2->starttransmit (*aud_med);

Now the three parties (we and these two partners) are able to communicate with one another.

6.1.8 Recording Meeting

When you are meeting, it makes sense to record the meeting to a WAV file, and all we need to do is connect the microphone and two calls to a WAV recorder:

Cap_med.starttransmit (Recorder), aud_med-starttransmit (recorder), Aud_med2 Starttransmit (recorder);
6.2 Audio Device Management

See the next audio device framework.

Class 6.3 Reference 6.3.1 Media Framework class?
class pj:: Media

PJSUA2 Development Documentation-sixth chapter media

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.