wiki:Python_SIP/Media

Version 2 (modified by bennylp, 16 years ago) (diff)

--

Working with Media

The Concept

Media objects are objects that are capable to process media. There are several type of media objects supported in pjsua:

  • call, obviously, to transmit and receive media from remote person.
  • WAV file player to play WAV file
  • WAV file recorder to record audio to a WAV file
  • WAV playlist, to playback multiple WAV files sequentially.

More media objects may be added in the future.

In pjsua Python module and in PJSUA API in general, all media objects are terminated in the central conference bridge so that they are easier to manipulate. When objects are plugged-in to the conference bridge, they will be given a slot number that identifies the objects in the bridge.

The conference bridge provides a simple but yet powerful API to manage audio routing between the audio objects. The principle is very simple, that is you connect audio source to audio destination, and the bridge will make the audio flows from the source to destination, and that's it. If more than one sources are transmitting to the same destination, then the audio will be mixed. If one source is transmitting to more than one destinations, the bridge will take care of duplicating the audio from the source to the multiple destinations.

Lets see a diagram of a conference bridge with several media objects.

The diagram above shows the conference bridge with the following objects:

  • sound device, which by convention is always attached at slot number 0
  • a WAV file to be played back at slot 1
  • a WAV file for recording at slot 2
  • an active call to Alice at slot 3
  • an active call to Bob at slot 4

When a media object is plugged-in to the bridge, it will not be connected to anything, so media will not flow from/to the object. When no connections are made in the bridge (like the diagram above), then no media will be flowing in the bridge at all.

Sample: WAV File Playback

To playback the WAV file to the speaker, just connect the WAV playback object to the sound device, and that's it. Simple isn't it!

Here's the code to connect the WAV playback object to the speaker:

  lib.conf_connect(1, 0)

The conf_connect() method takes two arguments:

  • the first argument is the slot number of the source media object, in this case one (1) for the WAV file playback, and
  • the second argument is the slot number of the destination media object, in this case zero for the sound device

Once you're done with the playback, just disconnect the connection to stop the playback:

  lib.conf_disconnect(1, 0)

Attachments (8)

Download all attachments as: .zip