title: pjsip capture and play pcm data
body: <p>I have some embedded Devices that have no audio device by default. They communicate with each other via a FPGA. So my question is, how do I capture/play back audio from pjsip in pcm in order to send/receive it with the FPGA?</p>
  <p>I know that there is <em>pjmedia_mem_player_create()</em> and <em>pjmedia_mem_capture_create()</em> but I can't seem to find any good info towards using these functions.</p>
  <p>I tried the following piece of code, but an assertion failed cause one of the function's parameter is &quot;empty&quot;.</p>
  <p>Error:</p>
  <blockquote>
  <p>pjmedia_mem_capture_create: Assertion `pool &amp;&amp; buffer &amp;&amp; size &amp;&amp;  clock_rate &amp;&amp; channel_count &amp;&amp; samples_per_frame &amp;&amp; bits_per_sample &amp;&amp; p_port' failed.</p>
  </blockquote>
  <p><strong>Note</strong>: I'm mainly using pjsua2 for everything else like registrations, transports etc. Also the default audio is set to null with <em>ep.audDevManager().setNullDev();</em> as without this, making/receiving a call would simply fail?!</p>
  <pre><code>void MyCall::onCallMediaState(OnCallMediaStateParam &amp;prm){
  CallInfo ci = getInfo();
  
  pj_caching_pool_init(&amp;cp, &amp;pj_pool_factory_default_policy, 0);
  pj_pool_t *pool = pj_pool_create(&amp;cp.factory, &quot;POOLNAME&quot;, 2000, 2000, NULL);
  
  void *buffer;
  pjmedia_port *prt;
  
  #define CLOCK_RATE 8000
  #define CHANELS 1
  #define SAMPLES_PER_FRAME 480
  #define BITS_PER_SAMPLE 16
  
  pjmedia_mem_capture_create( pool, //Pool
                              buffer, //Buffer
                              2000, //Buffer Size
                              CLOCK_RATE, 
                              CHANELS, 
                              SAMPLES_PER_FRAME, 
                              BITS_PER_SAMPLE, 
                              0, //Options
                              &amp;prt); //The return port}
  </code></pre>
  <p><strong>UPDATE</strong></p>
  <p>The assertion failed cause the buffer variable doesn't have any memory allocated to it. Allocate with twice the amount of samples per frame to have sufficient memory.</p>
  <pre><code> buffer = pj_pool_zalloc(pool, 960);
  </code></pre>
  <p>Also a callback needs to be registered with <code>pjmedia_mem_capture_set_eof_cb2()</code> (The two at the end is necessary for PJSIP 2.10 or later) Apparently from there the buffer can be used. Just that my implementation atm doesn't execute the callback.</p>