Changes between Initial Version and Version 1 of pjsip-doc/media


Ignore:
Timestamp:
Dec 4, 2013 1:55:12 AM (10 years ago)
Author:
bennylp
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • pjsip-doc/media

    v1 v1  
     1{{{ 
     2#!rst 
     3 
     4Media 
     5===== 
     6Media 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). 
     7 
     8An important subclass of Media is AudioMedia which represents audio media. There are several type of audio media objects supported in PJSUA2: 
     9 
     10- CallAudioMedia, to transmit and receive audio to/from remote person. 
     11- AudioMediaPlayer, to play WAV file(s). 
     12- AudioMediaRecorder, to record audio to a WAV file. 
     13 
     14More media objects may be added in the future. 
     15 
     16The Audio Conference Bridge 
     17--------------------------------------------------------- 
     18The 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. 
     19 
     20In ​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 
     22An 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. 
     23 
     24Playing a WAV File 
     25++++++++++++++++++ 
     26To playback the WAV file to the speaker, just start the transmission of the WAV playback object to the sound device:: 
     27 
     28    AudioMediaPlayer player; 
     29    try { 
     30        player.createPlayer(“file.wav”); 
     31        player.startTransmit(); 
     32    } catch(Error& err) { 
     33    } 
     34 
     35Once you're done with the playback, just stop the transmission n to stop the playback:: 
     36 
     37    try { 
     38        player.stopTransmit(); 
     39    } catch(Error& err) { 
     40    } 
     41 
     42Recording to WAV File 
     43+++++++++++++++++++++ 
     44Or if you want to record the microphone to the WAV file, simply do this:: 
     45 
     46    AudioMediaRecorder recorder; 
     47    try { 
     48        recorder.createRecorder(“file.wav”); 
     49        .startTransmit(recorder); 
     50    } catch(Error& err) { 
     51    } 
     52 
     53And the media will flow from the sound device to the WAV record file. As usual, to stop or pause recording, just stop the transmission:: 
     54 
     55    try { 
     56       .stopTransmit(recorder); 
     57    } catch(Error& err) { 
     58    } 
     59 
     60(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 
     62Looping Audio 
     63+++++++++++++ 
     64If 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 
     68With 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 
     70You 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 
     72Normal Call 
     73+++++++++++ 
     74 
     75A single call can has several audio medias. Application can retrieve the audio media by using the API Call.getMedia():: 
     76 
     77    AudioMedia *aud_med = (AudioMedia *)call.getMedia(0); 
     78 
     79In 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:: 
     80 
     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(); 
     86 
     87Second Call 
     88+++++++++++ 
     89Suppose 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:: 
     90 
     91    AudioMedia *aud_med2 = (AudioMedia *)call2.getMedia(0); 
     92    ->startTransmit(*aud_med2); 
     93    aud_med2->startTransmit(); 
     94 
     95Now 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). 
     96 
     97Conference Call 
     98+++++++++++++++ 
     99To enable both parties talk to each other, just establish bidirectional media between them:: 
     100 
     101    aud_med->startTransmit(*aud_med2); 
     102    aud_med2->startTransmit(*aud_med); 
     103 
     104Now the three parties (us and both remote parties) will be able to talk to each other. 
     105 
     106Recording the Conference 
     107++++++++++++++++++++++++ 
     108 
     109While 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 
     111    ->startTransmit(recorder); 
     112    aud_med->startTransmit(recorder); 
     113    aud_med2->startTransmit(recorder); 
     114 
     115We only need to care about what the audio routings we want to achieve and the bridge will take care of making it happen. 
     116 
     117}}}