Changes between Version 4 and Version 5 of Python_SIP/Media
- Timestamp:
- Jul 23, 2008 6:35:50 PM (16 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Python_SIP/Media
v4 v5 1 = Working with Media=1 = Media Concept = 2 2 3 3 [[TracNav(Python_SIP/TOC)]] 4 4 5 5 6 == The Concept==6 == Media Objects == 7 7 8 Media objects are objects that are capable to process media. There are several type of media objects supported in pjsua: 8 Media objects are objects that are capable to process media. In [http://www.pjsip.org/pjmedia/docs/html/index.htm PJMEDIA] terms, these objects re implemented as media ports (or [http://www.pjsip.org/pjmedia/docs/html/group__PJMEDIA__PORT.htm pjmedia_port]). 9 10 There are several type of media objects supported in pjsua: 9 11 * call, obviously, to transmit and receive media from remote person. 10 12 * WAV file player to play WAV file … … 14 16 More media objects may be added in the future. 15 17 18 == The Conference Bridge == 19 16 20 In pjsua Python module and in [http://www.pjsip.org/pjsip/docs/html/group__PJSUA__LIB.htm 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. 21 22 Each object provides different API to fetch the slot number associated with it: 23 * for [http://www.pjsip.org/python/pjsua.htm#Call Call] object, the slot number is in the [http://www.pjsip.org/python/pjsua.htm#CallInfo CallInfo] structure, so it can be fetch with {{{call.info().conf_slot}}} (once the media is active of course). 24 * for WAV file player, use [http://www.pjsip.org/python/pjsua.htm#Lib-player_get_slot lib.player_get_slot()] 25 * for WAV playlist, use [http://www.pjsip.org/python/pjsua.htm#Lib-playlist_get_slot lib.playlist_get_slot()] 26 * for WAV file recorder, use [http://www.pjsip.org/python/pjsua.htm#Lib-recorder_get_slot lib.recorder_get_slot()] 27 17 28 18 29 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. … … 33 44 === Sample: WAV File Playback === 34 45 35 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!46 To playback the WAV file to the speaker, just connect the WAV playback object to the sound device, with the snippet below: 36 47 37 48 [[Image(conference-bridge-wav-playback.jpg)]] 38 49 39 The diagram above shows the media flow from the WAV playback object to the sound device (see the red arrow).50 The red line in the diagram above shows the media flow from the WAV playback object to the sound device. 40 51 41 52 Here's the code to connect the WAV playback object to the speaker: … … 67 78 }}} 68 79 69 And the media will flow from the sound device to the WAV record file, as shown in the diagram below:80 And the media will flow from the sound device to the WAV record file, as shown as brown line in the diagram below: 70 81 71 82 [[Image(conference-bridge-snd-rec.jpg)]] … … 78 89 }}} 79 90 80 (Note that disconnecting the WAV recorder as above does not close the WAV file, and you can resume recording by connecting a source to the WAV recorder again. )91 (Note that disconnecting the WAV recorder as above does not close the WAV file, and you can resume recording by connecting a source to the WAV recorder again. You cannot playback the recorded WAV file before you close it.) 81 92 82 93 83 94 === Sample: Normal Call === 84 95 85 For a normal call, we 'd want to establish bidirectional audio with the remote person, which can be done easily by establishing bidirectional connection between the call (with Alice, in this case) and the sound device:96 For a normal call, we would want to establish bidirectional audio with the remote person (with Alice, in this case), which can be done easily by connecting the sound device and the call and vice versa: 86 97 87 98 {{{ 88 99 #!python 89 100 101 # This will connect the sound device/mic to the call 90 102 lib.conf_connect(0, 3) 103 104 # And this will connect the call to the sound device/speaker 91 105 lib.conf_connect(3, 0) 92 106 }}} … … 101 115 === Sample: Second Call === 102 116 103 Suppose we want to talk with Alice and Bob at the same time. Since we already have bidirectional media connection with Alice, we just need to add the code below to establish bidirectional connection with Bob.117 Suppose we want to talk with Alice and Bob at the same time. Since we already have bidirectional media connection with Alice, we just need to add bidirectional connection with Bob using the code below. 104 118 105 119 {{{ … … 110 124 }}} 111 125 112 Now we can talk to Alice and Bob at the same time, and we will hear audio from either party. The interconnection diagram in the bridge will be like this:126 The interconnection diagram in the bridge will be like this, with the code above adds the blue lines below: 113 127 114 128 [[Image(conference-bridge-2-calls.jpg)]] 115 129 116 At this stage, we can talk to both Alice and Bob, but Alice and Bob can't talk or hear each other.130 Now we can talk to Alice and Bob at the same time, and we will hear audio from either party. But at this stage, Alice and Bob can't talk or hear each other (i.e. we're not in full conference mode yet). 117 131 118 132 === Sample: Conference Call === … … 127 141 }}} 128 142 129 The snippet above will add the new connections as shown as lines with black colorbelow:143 The snippet above will add the new connections as shown as black lines below: 130 144 131 145 [[Image(conference-bridge-conf-call.jpg)]] 132 146 147 Now the three parties (us, Alice, and Bob) will be able to talk to each other. 133 148 134 149 === Sample: Recording the Conference === … … 148 163 [[Image(conference-bridge-conf-call-record.jpg)]] 149 164 165 That looks like a pretty intricate connections indeed, but the good thing is we don't need to worry about it as all will be taken care of by the bridge. We only need to care about what the audio routings that we want to achieve.