Changes between Version 4 and Version 5 of pjsip-doc/media
- Timestamp:
- Feb 10, 2014 10:19:56 AM (11 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
pjsip-doc/media
v4 v5 18 18 The Audio Conference Bridge 19 19 ---------------------------- 20 The conference bridge provides a simple but yet powerful concept to manage audio flow between the audio medias. 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 from the sources 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. 20 The conference bridge provides a simple but yet powerful concept to manage audio flow between the audio medias. 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 from the sources 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. The bridge will even take care medias with different clock rates and ptime. 21 21 22 In PJSUA2, all audio media objects are plugged-in to the central conference bridge for easier manipulation. A plugged-in audio media will not be connected to anything, so media will not flow from/to any objects. An audio media source can start/stop the transmission to a destination by using the API AudioMedia.startTransmit() / AudioMedia.stopTransmit().22 In PJSUA2, all audio media objects are plugged-in to the central conference bridge for easier manipulation. At first, a plugged-in audio media will not be connected to anything, so media will not flow from/to any objects. An audio media source can start/stop the transmission to a destination by using the API AudioMedia.startTransmit() / AudioMedia.stopTransmit(). 23 23 24 24 An audio media object plugged-in to the conference bridge will be given a port ID number that identifies the object in the bridge. Application can use the API AudioMedia.getPortId() to retrieve the port ID. Normally, application should not need to worry about the conference bridge and its port ID (as all will be taken care of by the Media class) unless application want to create its own custom audio media. … … 26 26 Playing a WAV File 27 27 ++++++++++++++++++ 28 To playback the WAV file to the sound device, just start the transmission of the WAV playback object to the sound device's playback media:: 28 To playback the WAV file to the sound device, just start the transmission of the WAV playback object to the sound device's playback media: 29 30 .. code-block:: c++ 29 31 30 32 AudioMediaPlayer player; … … 36 38 } 37 39 38 Once you're done with the playback, just stop the transmission to stop the playback:: 40 By default, the WAV file will be played in a loop. To disable the loop, specify ``PJMEDIA_FILE_NO_LOOP`` when creating the player: 41 42 .. code-block:: c++ 43 44 player.createPlayer("file.wav", PJMEDIA_FILE_NO_LOOP); 45 46 Without looping, silence will be played once the playback has reached the end of the WAV file. 47 48 Once you're done with the playback, just stop the transmission to stop the playback: 49 50 .. code-block:: c++ 39 51 40 52 try { … … 43 55 } 44 56 57 Resuming the transmission after the playback is stopped will resume playback from the last play position. Use ``player.setPos()`` to set playback position to a desired location. 58 59 45 60 Recording to WAV File 46 61 +++++++++++++++++++++ 47 Or if you want to record the audio from the sound device to the WAV file, simply do this:: 62 Or if you want to record the audio from the sound device to the WAV file, simply do this: 63 64 .. code-block:: c++ 48 65 49 66 AudioMediaRecorder recorder; … … 55 72 } 56 73 57 And the media will flow from the sound device to the WAV record file. As usual, to stop or pause recording, just stop the transmission:: 74 And the media will flow from the sound device to the WAV record file. As usual, to stop or pause recording, just stop the transmission: 75 76 .. code-block:: c++ 58 77 59 78 try { … … 62 81 } 63 82 64 (Note that stopping the transmission to 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.) 83 Note that stopping the transmission to 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. To close the WAV recorder, simply delete it: 84 85 .. code-block:: c++ 86 87 delete recorder; 88 65 89 66 90 Local Audio Loopback 67 91 ++++++++++++++++++++ 68 A useful test to check whether the local sound device (capture and playback device) is working properly is by transmitting the audio from the capture device directly to the playback device (i.e. local loopback). You can do this by:: 92 A useful test to check whether the local sound device (capture and playback device) is working properly is by transmitting the audio from the capture device directly to the playback device (i.e. local loopback). You can do this by: 93 94 .. code-block:: c++ 69 95 70 96 cap_med.startTransmit(play_med); 97 71 98 72 99 Looping Audio … … 77 104 +++++++++++ 78 105 79 A single call can ha s several audio medias. Application can retrieve the audio media by using the API Call.getMedia(). Then for a normal call, we would want to establish bidirectional audio with the remote person, which can be done easily by connecting the sound device and the call audio media and vice versa::106 A single call can have more than one media (for example, audio and video). Application can retrieve the audio media by using the API Call.getMedia(). Then for a normal call, we would want to establish bidirectional audio with the remote person, which can be done easily by connecting the sound device and the call audio media and vice versa: 80 107 81 AudioMedia *aud_med = (AudioMedia *)call.getMedia(0); 108 .. code-block:: c++ 109 110 CallInfo ci = call.getInfo(); 111 AudioMedia *aud_med = NULL; 112 113 // Find out which media index is the audio 114 for (unsigned i=0; i<ci.media.size(); ++i) { 115 if (ci.media[i].type == PJMEDIA_TYPE_AUDIO) { 116 aud_med = (AudioMedia *)call.getMedia(i); 117 break; 118 } 119 } 120 82 121 if (aud_med) { 83 122 // This will connect the sound device/mic to the call audio media … … 88 127 } 89 128 90 In the above snippet, we assume that the audio media is located in index 0. Of course on a real application, we should iterate the medias to find the correct media index by checking whether the media returned by getMedia() is valid. More on this will be explained later in the Call section. 129 91 130 92 131 Second Call 93 132 +++++++++++ 94 Suppose we want to talk with two remote parties at the same time. Since we already have bidirectional media connection with one party, we just need to add bidirectional connection with the other party using the code below: :133 Suppose we want to talk with two remote parties at the same time. Since we already have bidirectional media connection with one party, we just need to add bidirectional connection with the other party using the code below: 95 134 96 AudioMedia *aud_med2 = (AudioMedia *)call2.getMedia(0); 135 .. code-block:: c++ 136 137 AudioMedia *aud_med2 = (AudioMedia *)call2.getMedia(aud_idx); 97 138 if (aud_med2) { 98 139 cap_med->startTransmit(*aud_med2); … … 104 145 Conference Call 105 146 +++++++++++++++ 106 To enable both parties talk to each other, just establish bidirectional media between them:: 147 To enable both parties talk to each other, just establish bidirectional media between them: 148 149 .. code-block:: c++ 107 150 108 151 aud_med->startTransmit(*aud_med2); … … 114 157 ++++++++++++++++++++++++ 115 158 116 While doing the conference, it perfectly makes sense to want to record the conference to a WAV file, and all we need to do is to connect the microphone and both calls to the WAV recorder:: 159 While doing the conference, it perfectly makes sense to want to record the conference to a WAV file, and all we need to do is to connect the microphone and both calls to the WAV recorder: 160 161 .. code-block:: c++ 117 162 118 163 cap_med.startTransmit(recorder);