Changes between Version 2 and Version 3 of pjsip-doc/media
- Timestamp:
- Dec 4, 2013 8:01:20 AM (11 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
pjsip-doc/media
v2 v3 4 4 Media 5 5 ===== 6 Media objects are objects that are capable to either produce media or takes media. In PJMEDIA terms, these objects are implemented as media ports (pjmedia_port).6 Media objects are objects that are capable to either produce media or takes media. 7 7 8 8 An important subclass of Media is AudioMedia which represents audio media. There are several type of audio media objects supported in PJSUA2: 9 9 10 - CallAudioMedia, to transmit and receive audio to/from remote person. 10 - Capture device's AudioMedia, to capture audio from the sound device. 11 - Playback device's AudioMedia, to play audio to the sound device. 12 - Call's AudioMedia, to transmit and receive audio to/from remote person. 11 13 - AudioMediaPlayer, to play WAV file(s). 12 14 - AudioMediaRecorder, to record audio to a WAV file. … … 20 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(). 21 23 22 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 port ID (as all will be taken care of by the bridge) unless application want to create its own custom audio media.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. 23 25 24 26 Playing a WAV File 25 27 ++++++++++++++++++ 26 To playback the WAV file to the s peaker, just start the transmission of the WAV playback object to the sound device::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:: 27 29 28 30 AudioMediaPlayer player; 31 AudioMedia& play_med = Endpoint::instance().audDevManager().getPlaybackDevMedia(); 29 32 try { 30 player.createPlayer( “file.wav”);31 player.startTransmit( );33 player.createPlayer("file.wav"); 34 player.startTransmit(play_med); 32 35 } catch(Error& err) { 33 36 } 34 37 35 Once you're done with the playback, just stop the transmission nto stop the playback::38 Once you're done with the playback, just stop the transmission to stop the playback:: 36 39 37 40 try { 38 player.stopTransmit( );41 player.stopTransmit(play_med); 39 42 } catch(Error& err) { 40 43 } … … 42 45 Recording to WAV File 43 46 +++++++++++++++++++++ 44 Or if you want to record the microphone to the WAV file, simply do this::47 Or if you want to record the audio from the sound device to the WAV file, simply do this:: 45 48 46 49 AudioMediaRecorder recorder; 50 AudioMedia& cap_med = Endpoint::instance().audDevManager().getCaptureDevMedia(); 47 51 try { 48 recorder.createRecorder( “file.wav”);49 .startTransmit(recorder);52 recorder.createRecorder("file.wav"); 53 cap_med.startTransmit(recorder); 50 54 } catch(Error& err) { 51 55 } … … 54 58 55 59 try { 56 .stopTransmit(recorder);60 cap_med.stopTransmit(recorder); 57 61 } catch(Error& err) { 58 62 } … … 60 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.) 61 65 66 Local Audio Loopback 67 ++++++++++++++++++++ 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:: 69 70 cap_med.startTransmit(play_med); 71 62 72 Looping Audio 63 73 +++++++++++++ 64 If you want, you can loop the audio of a media object to itself (i.e. the audio received from the object will be transmitted to itself). For example, you can loop the audio of the sound device with:: 65 66 .startTransmit(); 67 68 With the above connection, audio received from the microphone will be played back to the speaker. This is useful to test whether the microphone and speaker are working properly. 69 70 You can loop-back audio from any objects, as long as the object has bidirectional media. That means you can loop the call's audio media, so that audio received from the remote person will be transmitted back to her/him. But you can't loop the WAV player or recorder since these objects can only play or record and not both. 74 If you want, you can loop the audio of an audio media object to itself (i.e. the audio received from the object will be transmitted to itself). You can loop-back audio from any objects, as long as the object has bidirectional media. That means you can loop the call's audio media, so that audio received from the remote person will be transmitted back to her/him. But you can't loop the WAV player or recorder since these objects can only play or record and not both. 71 75 72 76 Normal Call 73 77 +++++++++++ 74 78 75 A single call can has several audio medias. Application can retrieve the audio media by using the API Call.getMedia() ::79 A single call can has 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:: 76 80 77 81 AudioMedia *aud_med = (AudioMedia *)call.getMedia(0); 82 if (aud_med) { 83 // This will connect the sound device/mic to the call audio media 84 cap_med.startTransmit(*aud_med); 78 85 79 In the above, 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. 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:: 86 // And this will connect the call audio media to the sound device/speaker 87 aud_med->startTransmit(play_med); 88 } 80 89 81 // This will connect the sound device/mic to the call audio media 82 ->startTransmit(*aud_med); 83 84 // And this will connect the call audio media to the sound device/speaker 85 aud_med->startTransmit(); 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. 86 91 87 92 Second Call … … 90 95 91 96 AudioMedia *aud_med2 = (AudioMedia *)call2.getMedia(0); 92 ->startTransmit(*aud_med2); 93 aud_med2->startTransmit(); 97 if (aud_med2) { 98 cap_med->startTransmit(*aud_med2); 99 aud_med2->startTransmit(play_med); 100 } 94 101 95 102 Now we can talk to both parties at the same time, and we will hear audio from either party. But at this stage, the remote parties can't talk or hear each other (i.e. we're not in full conference mode yet). … … 109 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:: 110 117 111 ->startTransmit(recorder);118 cap_med->startTransmit(recorder); 112 119 aud_med->startTransmit(recorder); 113 120 aud_med2->startTransmit(recorder);