G.711 with stereo hardware

DA
David Andrey
Wed, Jun 17, 2009 10:06 AM

Hi all,

I'm running PJSIP and PJMEDIA on a hardware that  have some problems
with mono sound. Stereo works fine.

I have to use G.711 as audio codec. Is there an "easy" way to add a
second channel (ideally a copy) to the existing one ?

Best regards

David

Hi all, I'm running PJSIP and PJMEDIA on a hardware that have some problems with mono sound. Stereo works fine. I have to use G.711 as audio codec. Is there an "easy" way to add a second channel (ideally a copy) to the existing one ? Best regards David
DA
David Andrey
Wed, Jun 17, 2009 3:21 PM

I'm trying to use pjmedia_stereo_port_create() resolve my problem. But I
ends at runtime with at this point:

g711_decode: Assertion `output_buf_len >= (input->size << 1)' failed.

The get_frame() function call the decoder with the following values:

outSize:0, frame->size:160, samples_count:80, BYTES_PER_SAMPLE:2

Is the stereo port a practicable way to solve my problem ?

From: pjsip-bounces@lists.pjsip.org
[mailto:pjsip-bounces@lists.pjsip.org] On Behalf Of David Andrey
Sent: Mittwoch, 17. Juni 2009 12:06
To: pjsip list
Subject: [pjsip] G.711 with stereo hardware

Hi all,

I'm running PJSIP and PJMEDIA on a hardware that  have some problems
with mono sound. Stereo works fine.

I have to use G.711 as audio codec. Is there an "easy" way to add a
second channel (ideally a copy) to the existing one ?

Best regards

David

I'm trying to use pjmedia_stereo_port_create() resolve my problem. But I ends at runtime with at this point: g711_decode: Assertion `output_buf_len >= (input->size << 1)' failed. The get_frame() function call the decoder with the following values: outSize:0, frame->size:160, samples_count:80, BYTES_PER_SAMPLE:2 Is the stereo port a practicable way to solve my problem ? From: pjsip-bounces@lists.pjsip.org [mailto:pjsip-bounces@lists.pjsip.org] On Behalf Of David Andrey Sent: Mittwoch, 17. Juni 2009 12:06 To: pjsip list Subject: [pjsip] G.711 with stereo hardware Hi all, I'm running PJSIP and PJMEDIA on a hardware that have some problems with mono sound. Stereo works fine. I have to use G.711 as audio codec. Is there an "easy" way to add a second channel (ideally a copy) to the existing one ? Best regards David
DA
David Andrey
Thu, Jul 2, 2009 1:46 PM

Maybe useful for someone J

I made the following changes in stereo_port.c:

static pj_status_t stereo_get_frame(pjmedia_port *this_port,

                        pjmedia_frame *frame)



//tmp_frame.buf = sport->get_buf? sport->get_buf : frame->buf;    //

allocate get buffer for stereo port ???

//tmp_frame.size = sport->dn_port->info.bytes_per_frame;

if (sport->get_buf)

{

  tmp_frame.buf = sport->get_buf;

  tmp_frame.size = sport->dn_port->info.bytes_per_frame;

}

else

{

  tmp_frame.buf = frame->buf;

  tmp_frame.size = frame->size;                               // da,

2009-06-30

}

static pj_status_t stereo_put_frame(pjmedia_port *this_port,

                        const pjmedia_frame *frame)



  //tmp_frame.size = sport->dn_port->info.bytes_per_frame;

  tmp_frame.size = sport->dn_port->info.samples_per_frame       //

da, 2009-06-30

                    * sport->base.info.bits_per_sample / 8;

Still have memory problems (heap) in relation with the stereo usage. But
stereo <-> G.711 seems ok now.

From: pjsip-bounces@lists.pjsip.org
[mailto:pjsip-bounces@lists.pjsip.org] On Behalf Of David Andrey
Sent: Mittwoch, 17. Juni 2009 17:21
To: pjsip list
Subject: Re: [pjsip] G.711 with stereo hardware

I'm trying to use pjmedia_stereo_port_create() resolve my problem. But I
ends at runtime with at this point:

g711_decode: Assertion `output_buf_len >= (input->size << 1)' failed.

The get_frame() function call the decoder with the following values:

outSize:0, frame->size:160, samples_count:80, BYTES_PER_SAMPLE:2

Is the stereo port a practicable way to solve my problem ?

From: pjsip-bounces@lists.pjsip.org
[mailto:pjsip-bounces@lists.pjsip.org] On Behalf Of David Andrey
Sent: Mittwoch, 17. Juni 2009 12:06
To: pjsip list
Subject: [pjsip] G.711 with stereo hardware

Hi all,

I'm running PJSIP and PJMEDIA on a hardware that  have some problems
with mono sound. Stereo works fine.

I have to use G.711 as audio codec. Is there an "easy" way to add a
second channel (ideally a copy) to the existing one ?

Best regards

David

Maybe useful for someone J I made the following changes in stereo_port.c: static pj_status_t stereo_get_frame(pjmedia_port *this_port, pjmedia_frame *frame) //tmp_frame.buf = sport->get_buf? sport->get_buf : frame->buf; // allocate get buffer for stereo port ??? //tmp_frame.size = sport->dn_port->info.bytes_per_frame; if (sport->get_buf) { tmp_frame.buf = sport->get_buf; tmp_frame.size = sport->dn_port->info.bytes_per_frame; } else { tmp_frame.buf = frame->buf; tmp_frame.size = frame->size; // da, 2009-06-30 } static pj_status_t stereo_put_frame(pjmedia_port *this_port, const pjmedia_frame *frame) //tmp_frame.size = sport->dn_port->info.bytes_per_frame; tmp_frame.size = sport->dn_port->info.samples_per_frame // da, 2009-06-30 * sport->base.info.bits_per_sample / 8; Still have memory problems (heap) in relation with the stereo usage. But stereo <-> G.711 seems ok now. From: pjsip-bounces@lists.pjsip.org [mailto:pjsip-bounces@lists.pjsip.org] On Behalf Of David Andrey Sent: Mittwoch, 17. Juni 2009 17:21 To: pjsip list Subject: Re: [pjsip] G.711 with stereo hardware I'm trying to use pjmedia_stereo_port_create() resolve my problem. But I ends at runtime with at this point: g711_decode: Assertion `output_buf_len >= (input->size << 1)' failed. The get_frame() function call the decoder with the following values: outSize:0, frame->size:160, samples_count:80, BYTES_PER_SAMPLE:2 Is the stereo port a practicable way to solve my problem ? From: pjsip-bounces@lists.pjsip.org [mailto:pjsip-bounces@lists.pjsip.org] On Behalf Of David Andrey Sent: Mittwoch, 17. Juni 2009 12:06 To: pjsip list Subject: [pjsip] G.711 with stereo hardware Hi all, I'm running PJSIP and PJMEDIA on a hardware that have some problems with mono sound. Stereo works fine. I have to use G.711 as audio codec. Is there an "easy" way to add a second channel (ideally a copy) to the existing one ? Best regards David
BP
Benny Prijono
Fri, Jul 3, 2009 7:45 AM

On Thu, Jul 2, 2009 at 2:46 PM, David Andrey David.Andrey@netmodule.comwrote:

Maybe useful for someone J

I made the following changes in stereo_port.c:

static pj_status_t stereo_get_frame(pjmedia_port *this_port,

                         pjmedia_frame *frame)



 //tmp_frame.*buf* = sport->get_buf? sport->get_buf : frame->*buf*;

// allocate get buffer for stereo port ???

 //tmp_frame.size = sport->dn_port->info.bytes_per_frame;

 *if* (sport->get_buf)

 {

   tmp_frame.buf = sport->get_buf;

   tmp_frame.size = sport->dn_port->info.bytes_per_frame;

 }

 *else*

 {

   tmp_frame.buf = frame->buf;

   tmp_frame.size = frame->size;                               // *da*,

2009-06-30

 }

static pj_status_t stereo_put_frame(pjmedia_port *this_port,

                         *const* pjmedia_frame *frame)



   //tmp_frame.size = sport->dn_port->info.bytes_per_frame;

   tmp_frame.size = sport->dn_port->info.samples_per_frame       // *da

*, 2009-06-30

                     * sport->base.info.bits_per_sample / 8;

Still have memory problems (heap) in relation with the stereo usage. But
stereo <-> G.711 seems ok now.

Sorry I don't understand your patch above. When calling get_frame() or
put_frame(), caller must supply frame size exactly as specified by
port_info.bytes_per_frame of the specified port. I have a felling that
somewhere your code does not do this hence the memory problem.

Also the stereo port was not supposed to support G.711 channel conversion
(i.e. only PCM), if this is what you're trying to do too.

cheers
Benny

On Thu, Jul 2, 2009 at 2:46 PM, David Andrey <David.Andrey@netmodule.com>wrote: > Maybe useful for someone J > > > > I made the following changes in stereo_port.c: > > > > *static* pj_status_t *stereo_get_frame*(pjmedia_port *this_port, > > pjmedia_frame *frame) > > > > //tmp_frame.*buf* = sport->get_buf? sport->get_buf : frame->*buf*; > // allocate get buffer for stereo port ??? > > //tmp_frame.size = sport->dn_port->info.bytes_per_frame; > > *if* (sport->get_buf) > > { > > tmp_frame.buf = sport->get_buf; > > tmp_frame.size = sport->dn_port->info.bytes_per_frame; > > } > > *else* > > { > > tmp_frame.buf = frame->buf; > > tmp_frame.size = frame->size; // *da*, > 2009-06-30 > > } > > > > > > *static* pj_status_t *stereo_put_frame*(pjmedia_port *this_port, > > *const* pjmedia_frame *frame) > > > > //tmp_frame.size = sport->dn_port->info.bytes_per_frame; > > tmp_frame.size = sport->dn_port->info.samples_per_frame // *da > *, 2009-06-30 > > * sport->base.info.bits_per_sample / 8; > > > > Still have memory problems (heap) in relation with the stereo usage. But > stereo <-> G.711 seems ok now. > Sorry I don't understand your patch above. When calling get_frame() or put_frame(), caller must supply frame size exactly as specified by port_info.bytes_per_frame of the specified port. I have a felling that somewhere your code does not do this hence the memory problem. Also the stereo port was not supposed to support G.711 channel conversion (i.e. only PCM), if this is what you're trying to do too. cheers Benny
DA
David Andrey
Fri, Jul 3, 2009 10:38 AM

Hi Benny,

Well, what I'm trying to do is as follow:

1.Get the audio port created by "pjmedia_session_create()"

  status = pjmedia_session_get_port (mediaSession, 0, &mediaPort);
  1. Open the sound device in full-duplex stereo (stereo is the only way
    at moment)

    pjmedia_aud_param audioParam;

    audioParam.dir = PJMEDIA_DIR_ENCODING_DECODING;

    audioParam.rec_id = -1;  // auto select for audio device

    audioParam.play_id = -1;

    audioParam.clock_rate =  mediaPort->info.clock_rate;

    audioParam.channel_count =  2; //mediaPort->info.channel_count;

    audioParam.samples_per_frame = 2*
    mediaPort->info.samples_per_frame;

    audioParam.bits_per_sample = mediaPort->info.bits_per_sample;

    PJ_LOG(3,(THIS_FILE, "create bidirectional audio ..."));

    status = pjmedia_snd_port_create2(inv->pool, &audioParam,
    &soundBidir);

3.Create a stereo-to-mono converter, which have the  the G.711 audio
port as downstream

  status = pjmedia_stereo_port_create(inv->pool,

          mediaPort,

          2,

          0,

          &stereoPort);
  1. Connect the stereo port to the sound device

    status = pjmedia_snd_port_connect(soundBidir, stereoPort);

All this is happening in the "on_media_update()" callback.

So the data path I think to have is like this:

In the capture direction (for 8kHz, 20 ms audio samples per frame):

1.sound device give a 320 samples / frame (2 channel, 160
samples/channel, 16 bit/sample)

2.stereo port convert this in 160 samples / frame (1 channel, 160
samples / channel, 16 bit/sample)  and give it to the downstream port.

3.the G.711 encoder convert the pcm  samples (1 channel, 160  samples, 8
bit/sample) and send it to the network

Has I could see, the G.711 encoder receives 160 samples / frames without
the "stereo-mono" conversion, but 80 by adding this one -> this
observation started my changes in the stereo_port.

Maybe I'm doing all this really wrong L But I'm sure there must be a way
to solve my stereo - mono problem in PJ J

Thanks for helping.

David

From: pjsip-bounces@lists.pjsip.org
[mailto:pjsip-bounces@lists.pjsip.org] On Behalf Of Benny Prijono
Sent: Freitag, 3. Juli 2009 09:46
To: pjsip list
Subject: Re: [pjsip] G.711 with stereo hardware

On Thu, Jul 2, 2009 at 2:46 PM, David Andrey
David.Andrey@netmodule.com wrote:

Maybe useful for someone J

 

I made the following changes in stereo_port.c:

 

static pj_status_t stereo_get_frame(pjmedia_port *this_port,

                            pjmedia_frame *frame)

 

    //tmp_frame.buf = sport->get_buf? sport->get_buf :

frame->buf;    // allocate get buffer for stereo port ???

    //tmp_frame.size = sport->dn_port->info.bytes_per_frame;

    if (sport->get_buf)

    {

      tmp_frame.buf = sport->get_buf;

      tmp_frame.size = sport->dn_port->info.bytes_per_frame;

    }

    else

    {

      tmp_frame.buf = frame->buf;

      tmp_frame.size = frame->size;

// da, 2009-06-30

    }

 

 

static pj_status_t stereo_put_frame(pjmedia_port *this_port,

                            const pjmedia_frame *frame)

 

      //tmp_frame.size = sport->dn_port->info.bytes_per_frame;

      tmp_frame.size = sport->dn_port->info.samples_per_frame

// da, 2009-06-30

                        * sport->base.info.bits_per_sample / 8;

 

Still have memory problems (heap) in relation with the stereo

usage. But stereo <-> G.711 seems ok now.

Sorry I don't understand your patch above. When calling get_frame() or
put_frame(), caller must supply frame size exactly as specified by
port_info.bytes_per_frame of the specified port. I have a felling that
somewhere your code does not do this hence the memory problem.

Also the stereo port was not supposed to support G.711 channel
conversion (i.e. only PCM), if this is what you're trying to do too.

cheers
Benny

Hi Benny, Well, what I'm trying to do is as follow: 1.Get the audio port created by "pjmedia_session_create()" status = pjmedia_session_get_port (mediaSession, 0, &mediaPort); 2. Open the sound device in full-duplex stereo (stereo is the only way at moment) pjmedia_aud_param audioParam; audioParam.dir = PJMEDIA_DIR_ENCODING_DECODING; audioParam.rec_id = -1; // auto select for audio device audioParam.play_id = -1; audioParam.clock_rate = mediaPort->info.clock_rate; audioParam.channel_count = 2; //mediaPort->info.channel_count; audioParam.samples_per_frame = 2* mediaPort->info.samples_per_frame; audioParam.bits_per_sample = mediaPort->info.bits_per_sample; PJ_LOG(3,(THIS_FILE, "create bidirectional audio ...")); status = pjmedia_snd_port_create2(inv->pool, &audioParam, &soundBidir); 3.Create a stereo-to-mono converter, which have the the G.711 audio port as downstream status = pjmedia_stereo_port_create(inv->pool, mediaPort, 2, 0, &stereoPort); 4. Connect the stereo port to the sound device status = pjmedia_snd_port_connect(soundBidir, stereoPort); All this is happening in the "on_media_update()" callback. So the data path I think to have is like this: In the capture direction (for 8kHz, 20 ms audio samples per frame): 1.sound device give a 320 samples / frame (2 channel, 160 samples/channel, 16 bit/sample) 2.stereo port convert this in 160 samples / frame (1 channel, 160 samples / channel, 16 bit/sample) and give it to the downstream port. 3.the G.711 encoder convert the pcm samples (1 channel, 160 samples, 8 bit/sample) and send it to the network Has I could see, the G.711 encoder receives 160 samples / frames without the "stereo-mono" conversion, but 80 by adding this one -> this observation started my changes in the stereo_port. Maybe I'm doing all this really wrong L But I'm sure there must be a way to solve my stereo - mono problem in PJ J Thanks for helping. David From: pjsip-bounces@lists.pjsip.org [mailto:pjsip-bounces@lists.pjsip.org] On Behalf Of Benny Prijono Sent: Freitag, 3. Juli 2009 09:46 To: pjsip list Subject: Re: [pjsip] G.711 with stereo hardware On Thu, Jul 2, 2009 at 2:46 PM, David Andrey <David.Andrey@netmodule.com> wrote: Maybe useful for someone J I made the following changes in stereo_port.c: static pj_status_t stereo_get_frame(pjmedia_port *this_port, pjmedia_frame *frame) //tmp_frame.buf = sport->get_buf? sport->get_buf : frame->buf; // allocate get buffer for stereo port ??? //tmp_frame.size = sport->dn_port->info.bytes_per_frame; if (sport->get_buf) { tmp_frame.buf = sport->get_buf; tmp_frame.size = sport->dn_port->info.bytes_per_frame; } else { tmp_frame.buf = frame->buf; tmp_frame.size = frame->size; // da, 2009-06-30 } static pj_status_t stereo_put_frame(pjmedia_port *this_port, const pjmedia_frame *frame) //tmp_frame.size = sport->dn_port->info.bytes_per_frame; tmp_frame.size = sport->dn_port->info.samples_per_frame // da, 2009-06-30 * sport->base.info.bits_per_sample / 8; Still have memory problems (heap) in relation with the stereo usage. But stereo <-> G.711 seems ok now. Sorry I don't understand your patch above. When calling get_frame() or put_frame(), caller must supply frame size exactly as specified by port_info.bytes_per_frame of the specified port. I have a felling that somewhere your code does not do this hence the memory problem. Also the stereo port was not supposed to support G.711 channel conversion (i.e. only PCM), if this is what you're trying to do too. cheers Benny
BP
Benny Prijono
Fri, Jul 3, 2009 11:35 AM

On Fri, Jul 3, 2009 at 11:38 AM, David Andrey David.Andrey@netmodule.comwrote:

Hi Benny,

Well, what I’m trying to do is as follow:

1.Get the audio port created by “pjmedia_session_create()”

   status = pjmedia_session_get_port (mediaSession, 0, &mediaPort);
  1. Open the sound device in full-duplex stereo (stereo is the only way at
    moment)

    pjmedia_aud_param audioParam;

    audioParam.dir = PJMEDIA_DIR_ENCODING_DECODING;

    audioParam.rec_id = -1;  // auto select for audio device

    audioParam.play_id = -1;

    audioParam.clock_rate =  mediaPort->info.clock_rate;

    audioParam.channel_count =  2; //mediaPort->info.channel_count;

    audioParam.samples_per_frame = 2* mediaPort->info.samples_per_frame;

    audioParam.bits_per_sample = mediaPort->info.bits_per_sample;

    PJ_LOG(3,(THIS_FILE, "create bidirectional audio ..."));

    status = pjmedia_snd_port_create2(inv->pool, &audioParam,
    &soundBidir);

3.Create a stereo-to-mono converter, which have the  the G.711 audio port
as downstream

   status = pjmedia_stereo_port_create(inv->pool,

           mediaPort,

           2,

           0,

           &stereoPort);
  1. Connect the stereo port to the sound device

    status = pjmedia_snd_port_connect(soundBidir, stereoPort);

All this is happening in the “on_media_update()” callback.

So far so good actually. The above should work.

So the data path I think to have is like this:

In the capture direction (for 8kHz, 20 ms audio samples per frame):

1.sound device give a 320 samples / frame (2 channel, 160 samples/channel,
16 bit/sample)

2.stereo port convert this in 160 samples / frame (1 channel, 160 samples /
channel, 16 bit/sample)  and give it to the downstream port.

3.the G.711 encoder convert the pcm  samples (1 channel, 160  samples, 8
bit/sample) and send it to the network

Has I could see, the G.711 encoder receives 160 samples / frames without
the “stereo-mono” conversion, but 80 by adding this one -> this observation
started my changes in the stereo_port.

Something is not quite right there. With 20ms ptime, encoder should receive
160 samples after the frame is converted to mono, and not 80.

Can you check the contents of mediaPort->info? It should contain
clock_rate = 8000;
samples_per_frame  = 160
channel_count = 1;
bytes_per_frame = 320;

If samples_per_frame is 80 (=10ms), that means you set
stream_info->param.setting.frm_per_pkt to 1 instead of 2. FYI the
G.711codec uses 10ms framing, hence in the codec param we usually set
frm_per_pkt
to 2 to make it 20ms ptime. So then something is not right with the sound
device, since it's asked to return 10ms stereo frames in the aud_param
(equalling 160 samples per frame) but yet it gives 320 samples in the
capture callback. What sound device abstraction are you using?

If all is proper then I probably need to check elsewhere.

cheers
Benny

Maybe I’m doing all this really wrong L But I’m sure there must be a way to

solve my stereo – mono problem in PJ J

Thanks for helping.

David

From: pjsip-bounces@lists.pjsip.org [mailto:
pjsip-bounces@lists.pjsip.org] *On Behalf Of *Benny Prijono
Sent: Freitag, 3. Juli 2009 09:46
To: pjsip list
Subject: Re: [pjsip] G.711 with stereo hardware

On Thu, Jul 2, 2009 at 2:46 PM, David Andrey David.Andrey@netmodule.com
wrote:

Maybe useful for someone J

I made the following changes in stereo_port.c:

static pj_status_t stereo_get_frame(pjmedia_port *this_port,

                         pjmedia_frame *frame)



 //tmp_frame.*buf* = sport->get_buf? sport->get_buf : frame->*buf*;

// allocate get buffer for stereo port ???

 //tmp_frame.size = sport->dn_port->info.bytes_per_frame;

 *if* (sport->get_buf)

 {

   tmp_frame.buf = sport->get_buf;

   tmp_frame.size = sport->dn_port->info.bytes_per_frame;

 }

 *else*

 {

   tmp_frame.buf = frame->buf;

   tmp_frame.size = frame->size;                               // *da*,

2009-06-30

 }

static pj_status_t stereo_put_frame(pjmedia_port *this_port,

                         *const* pjmedia_frame *frame)



   //tmp_frame.size = sport->dn_port->info.bytes_per_frame;

   tmp_frame.size = sport->dn_port->info.samples_per_frame       // *da

*, 2009-06-30

                     * sport->base.info.bits_per_sample / 8;

Still have memory problems (heap) in relation with the stereo usage. But
stereo <-> G.711 seems ok now.

Sorry I don't understand your patch above. When calling get_frame() or
put_frame(), caller must supply frame size exactly as specified by
port_info.bytes_per_frame of the specified port. I have a felling that
somewhere your code does not do this hence the memory problem.

Also the stereo port was not supposed to support G.711 channel conversion
(i.e. only PCM), if this is what you're trying to do too.

cheers
Benny


Visit our blog: http://blog.pjsip.org

pjsip mailing list
pjsip@lists.pjsip.org
http://lists.pjsip.org/mailman/listinfo/pjsip_lists.pjsip.org

On Fri, Jul 3, 2009 at 11:38 AM, David Andrey <David.Andrey@netmodule.com>wrote: > Hi Benny, > > > > Well, what I’m trying to do is as follow: > > > > 1.Get the audio port created by “pjmedia_session_create()” > > status = pjmedia_session_get_port (mediaSession, 0, &mediaPort); > > > > 2. Open the sound device in full-duplex stereo (stereo is the only way at > moment) > > pjmedia_aud_param audioParam; > > audioParam.dir = PJMEDIA_DIR_ENCODING_DECODING; > > audioParam.rec_id = -1; // auto select for audio device > > audioParam.play_id = -1; > > audioParam.clock_rate = mediaPort->info.clock_rate; > > audioParam.channel_count = 2; //mediaPort->info.channel_count; > > audioParam.samples_per_frame = 2* mediaPort->info.samples_per_frame; > > audioParam.bits_per_sample = mediaPort->info.bits_per_sample; > > > > PJ_LOG(3,(THIS_FILE, "create bidirectional audio ...")); > > status = pjmedia_snd_port_create2(inv->pool, &audioParam, > &soundBidir); > > > > 3.Create a stereo-to-mono converter, which have the the G.711 audio port > as downstream > > status = pjmedia_stereo_port_create(inv->pool, > > mediaPort, > > 2, > > 0, > > &stereoPort); > > > > 4. Connect the stereo port to the sound device > > status = pjmedia_snd_port_connect(soundBidir, stereoPort); > > > > All this is happening in the “on_media_update()” callback. > > So far so good actually. The above should work. > > > So the data path I think to have is like this: > > In the capture direction (for 8kHz, 20 ms audio samples per frame): > > 1.sound device give a 320 samples / frame (2 channel, 160 samples/channel, > 16 bit/sample) > > 2.stereo port convert this in 160 samples / frame (1 channel, 160 samples / > channel, 16 bit/sample) and give it to the downstream port. > > 3.the G.711 encoder convert the pcm samples (1 channel, 160 samples, 8 > bit/sample) and send it to the network > > > > Has I could see, the G.711 encoder receives 160 samples / frames without > the “stereo-mono” conversion, but 80 by adding this one -> this observation > started my changes in the stereo_port. > > > Something is not quite right there. With 20ms ptime, encoder should receive 160 samples after the frame is converted to mono, and not 80. Can you check the contents of mediaPort->info? It should contain clock_rate = 8000; samples_per_frame = 160 channel_count = 1; bytes_per_frame = 320; If samples_per_frame is 80 (=10ms), that means you set stream_info->param.setting.frm_per_pkt to 1 instead of 2. FYI the G.711codec uses 10ms framing, hence in the codec param we usually set frm_per_pkt to 2 to make it 20ms ptime. So then something is not right with the sound device, since it's asked to return 10ms stereo frames in the aud_param (equalling 160 samples per frame) but yet it gives 320 samples in the capture callback. What sound device abstraction are you using? If all is proper then I probably need to check elsewhere. cheers Benny Maybe I’m doing all this really wrong L But I’m sure there must be a way to > solve my stereo – mono problem in PJ J > > > > Thanks for helping. > > > > David > > > > *From:* pjsip-bounces@lists.pjsip.org [mailto: > pjsip-bounces@lists.pjsip.org] *On Behalf Of *Benny Prijono > *Sent:* Freitag, 3. Juli 2009 09:46 > *To:* pjsip list > *Subject:* Re: [pjsip] G.711 with stereo hardware > > > > On Thu, Jul 2, 2009 at 2:46 PM, David Andrey <David.Andrey@netmodule.com> > wrote: > > Maybe useful for someone J > > > > I made the following changes in stereo_port.c: > > > > *static* pj_status_t *stereo_get_frame*(pjmedia_port *this_port, > > pjmedia_frame *frame) > > > > //tmp_frame.*buf* = sport->get_buf? sport->get_buf : frame->*buf*; > // allocate get buffer for stereo port ??? > > //tmp_frame.size = sport->dn_port->info.bytes_per_frame; > > *if* (sport->get_buf) > > { > > tmp_frame.buf = sport->get_buf; > > tmp_frame.size = sport->dn_port->info.bytes_per_frame; > > } > > *else* > > { > > tmp_frame.buf = frame->buf; > > tmp_frame.size = frame->size; // *da*, > 2009-06-30 > > } > > > > > > *static* pj_status_t *stereo_put_frame*(pjmedia_port *this_port, > > *const* pjmedia_frame *frame) > > > > //tmp_frame.size = sport->dn_port->info.bytes_per_frame; > > tmp_frame.size = sport->dn_port->info.samples_per_frame // *da > *, 2009-06-30 > > * sport->base.info.bits_per_sample / 8; > > > > Still have memory problems (heap) in relation with the stereo usage. But > stereo <-> G.711 seems ok now. > > > Sorry I don't understand your patch above. When calling get_frame() or > put_frame(), caller must supply frame size exactly as specified by > port_info.bytes_per_frame of the specified port. I have a felling that > somewhere your code does not do this hence the memory problem. > > Also the stereo port was not supposed to support G.711 channel conversion > (i.e. only PCM), if this is what you're trying to do too. > > cheers > Benny > > _______________________________________________ > Visit our blog: http://blog.pjsip.org > > pjsip mailing list > pjsip@lists.pjsip.org > http://lists.pjsip.org/mailman/listinfo/pjsip_lists.pjsip.org > >
DA
David Andrey
Mon, Jul 6, 2009 7:30 AM

Hi,

Here are the values of the mediaPort:

CALL.CPP  mediaPort -> clock_rate=8000  -  channel_count=1  -  samples_per_frame=160  -  bits_per_sample=16  -  bytes_per_frame=160

Seems I have a mismatch between "samples_per_frame" and "bytes_per_frame" ???

This gives the following output by the stereo - mono conversion (without my change)

stereo_put_frame source: nto1, samples per frames:320, bits per sample:16, bytes:640,  channel count:2

stereo_put_frame down: samples_per_frames=160  -  bits_per_sample=1  -  frame size=160

I checked the number of frames per packet during the "on_media_update()" callback.

audioStreamInfo = &sessionInfo.stream_info [0];

audioStreamInfo->param->setting.vad = PJ_SILENCE_DETECT;      // Voice Activity Detection (Silence)

PJ_LOG(3,(THIS_FILE, "audio frame per packet:%d", audioStreamInfo->param->setting.frm_per_pkt));

è CALL.CPP  audio frame per packet:2

Some additional infos that could help ...The memory problems becomes apparent by ending the call.

The code in "on_state_changed()" for the "PJSIP_INV_STATE_DISCONNECTED" state

  1. status = pjmedia_snd_port_disconnect        (soundBidir);

  2. status = pjmedia_snd_port_destroy (soundBidir);

  3. status = pjmedia_port_destroy (stereoPort);

  4. status = pjmedia_port_destroy (mediaPort);

  5. status = pjmedia_session_destroy  (mediaSession);

David

From: pjsip-bounces@lists.pjsip.org [mailto:pjsip-bounces@lists.pjsip.org] On Behalf Of Benny Prijono
Sent: Freitag, 3. Juli 2009 13:36
To: pjsip list
Subject: Re: [pjsip] G.711 with stereo hardware

On Fri, Jul 3, 2009 at 11:38 AM, David Andrey David.Andrey@netmodule.com wrote:

Hi Benny,

 

Well, what I'm trying to do is as follow:

 

1.Get the audio port created by "pjmedia_session_create()"

      status = pjmedia_session_get_port (mediaSession, 0, &mediaPort);

 

2. Open the sound device in full-duplex stereo (stereo is the only way at moment)

      pjmedia_aud_param audioParam;

      audioParam.dir = PJMEDIA_DIR_ENCODING_DECODING;

      audioParam.rec_id = -1;   // auto select for audio device

      audioParam.play_id = -1;

      audioParam.clock_rate =  mediaPort->info.clock_rate;

      audioParam.channel_count =  2; //mediaPort->info.channel_count;

      audioParam.samples_per_frame = 2* mediaPort->info.samples_per_frame;

      audioParam.bits_per_sample = mediaPort->info.bits_per_sample;

 

      PJ_LOG(3,(THIS_FILE, "create bidirectional audio ..."));

      status = pjmedia_snd_port_create2(inv->pool, &audioParam, &soundBidir);

 

3.Create a stereo-to-mono converter, which have the  the G.711 audio port as downstream

      status = pjmedia_stereo_port_create(inv->pool,

              mediaPort,

              2,

              0,

              &stereoPort);

 

4. Connect the stereo port to the sound device

    status = pjmedia_snd_port_connect(soundBidir, stereoPort);

 

All this is happening in the "on_media_update()" callback.

So far so good actually. The above should work.

So the data path I think to have is like this:

In the capture direction (for 8kHz, 20 ms audio samples per frame):

1.sound device give a 320 samples / frame (2 channel, 160 samples/channel, 16 bit/sample) 

2.stereo port convert this in 160 samples / frame (1 channel, 160 samples / channel, 16 bit/sample)  and give it to the downstream port.

3.the G.711 encoder convert the pcm  samples (1 channel, 160  samples, 8 bit/sample) and send it to the network

 

Has I could see, the G.711 encoder receives 160 samples / frames without the "stereo-mono" conversion, but 80 by adding this one -> this observation started my changes in the stereo_port.

 

Something is not quite right there. With 20ms ptime, encoder should receive 160 samples after the frame is converted to mono, and not 80.

Can you check the contents of mediaPort->info? It should contain
clock_rate = 8000;
samples_per_frame  = 160
channel_count = 1;
bytes_per_frame = 320;

If samples_per_frame is 80 (=10ms), that means you set stream_info->param.setting.frm_per_pkt to 1 instead of 2. FYI the G.711 codec uses 10ms framing, hence in the codec param we usually set frm_per_pkt to 2 to make it 20ms ptime. So then something is not right with the sound device, since it's asked to return 10ms stereo frames in the aud_param (equalling 160 samples per frame) but yet it gives 320 samples in the capture callback. What sound device abstraction are you using?

If all is proper then I probably need to check elsewhere.

cheers
Benny

Maybe I'm doing all this really wrong L But I'm sure there must be a way to solve my stereo - mono problem in PJ J

 

Thanks for helping.

 

David

 

From: pjsip-bounces@lists.pjsip.org [mailto:pjsip-bounces@lists.pjsip.org] On Behalf Of Benny Prijono
Sent: Freitag, 3. Juli 2009 09:46


To: pjsip list
Subject: Re: [pjsip] G.711 with stereo hardware

 

On Thu, Jul 2, 2009 at 2:46 PM, David Andrey <David.Andrey@netmodule.com> wrote:

	Maybe useful for someone J

	 

	I made the following changes in stereo_port.c:

	 

	static pj_status_t stereo_get_frame(pjmedia_port *this_port,

	                            pjmedia_frame *frame)

	 

	    //tmp_frame.buf = sport->get_buf? sport->get_buf : frame->buf;    // allocate get buffer for stereo port ???

	    //tmp_frame.size = sport->dn_port->info.bytes_per_frame;

	    if (sport->get_buf)

	    {

	      tmp_frame.buf = sport->get_buf;

	      tmp_frame.size = sport->dn_port->info.bytes_per_frame;

	    }

	    else

	    {

	      tmp_frame.buf = frame->buf;

	      tmp_frame.size = frame->size;                               // da, 2009-06-30

	    }

	 

	 

	static pj_status_t stereo_put_frame(pjmedia_port *this_port,

	                            const pjmedia_frame *frame)

	 

	      //tmp_frame.size = sport->dn_port->info.bytes_per_frame;

	      tmp_frame.size = sport->dn_port->info.samples_per_frame       // da, 2009-06-30

	                        * sport->base.info.bits_per_sample / 8;

	 

	Still have memory problems (heap) in relation with the stereo usage. But stereo <-> G.711 seems ok now.


Sorry I don't understand your patch above. When calling get_frame() or put_frame(), caller must supply frame size exactly as specified by port_info.bytes_per_frame of the specified port. I have a felling that somewhere your code does not do this hence the memory problem.

Also the stereo port was not supposed to support G.711 channel conversion (i.e. only PCM), if this is what you're trying to do too.

cheers
 Benny


_______________________________________________
Visit our blog: http://blog.pjsip.org

pjsip mailing list
pjsip@lists.pjsip.org
http://lists.pjsip.org/mailman/listinfo/pjsip_lists.pjsip.org
Hi, Here are the values of the mediaPort: CALL.CPP mediaPort -> clock_rate=8000 - channel_count=1 - samples_per_frame=160 - bits_per_sample=16 - bytes_per_frame=160 Seems I have a mismatch between "samples_per_frame" and "bytes_per_frame" ??? This gives the following output by the stereo - mono conversion (without my change) stereo_put_frame source: nto1, samples per frames:320, bits per sample:16, bytes:640, channel count:2 stereo_put_frame down: samples_per_frames=160 - bits_per_sample=1 - frame size=160 I checked the number of frames per packet during the "on_media_update()" callback. audioStreamInfo = &sessionInfo.stream_info [0]; audioStreamInfo->param->setting.vad = PJ_SILENCE_DETECT; // Voice Activity Detection (Silence) PJ_LOG(3,(THIS_FILE, "audio frame per packet:%d", audioStreamInfo->param->setting.frm_per_pkt)); è CALL.CPP audio frame per packet:2 Some additional infos that could help ...The memory problems becomes apparent by ending the call. The code in "on_state_changed()" for the "PJSIP_INV_STATE_DISCONNECTED" state 1. status = pjmedia_snd_port_disconnect (soundBidir); 2. status = pjmedia_snd_port_destroy (soundBidir); 3. status = pjmedia_port_destroy (stereoPort); 4. status = pjmedia_port_destroy (mediaPort); 5. status = pjmedia_session_destroy (mediaSession); David From: pjsip-bounces@lists.pjsip.org [mailto:pjsip-bounces@lists.pjsip.org] On Behalf Of Benny Prijono Sent: Freitag, 3. Juli 2009 13:36 To: pjsip list Subject: Re: [pjsip] G.711 with stereo hardware On Fri, Jul 3, 2009 at 11:38 AM, David Andrey <David.Andrey@netmodule.com> wrote: Hi Benny, Well, what I'm trying to do is as follow: 1.Get the audio port created by "pjmedia_session_create()" status = pjmedia_session_get_port (mediaSession, 0, &mediaPort); 2. Open the sound device in full-duplex stereo (stereo is the only way at moment) pjmedia_aud_param audioParam; audioParam.dir = PJMEDIA_DIR_ENCODING_DECODING; audioParam.rec_id = -1; // auto select for audio device audioParam.play_id = -1; audioParam.clock_rate = mediaPort->info.clock_rate; audioParam.channel_count = 2; //mediaPort->info.channel_count; audioParam.samples_per_frame = 2* mediaPort->info.samples_per_frame; audioParam.bits_per_sample = mediaPort->info.bits_per_sample; PJ_LOG(3,(THIS_FILE, "create bidirectional audio ...")); status = pjmedia_snd_port_create2(inv->pool, &audioParam, &soundBidir); 3.Create a stereo-to-mono converter, which have the the G.711 audio port as downstream status = pjmedia_stereo_port_create(inv->pool, mediaPort, 2, 0, &stereoPort); 4. Connect the stereo port to the sound device status = pjmedia_snd_port_connect(soundBidir, stereoPort); All this is happening in the "on_media_update()" callback. So far so good actually. The above should work. So the data path I think to have is like this: In the capture direction (for 8kHz, 20 ms audio samples per frame): 1.sound device give a 320 samples / frame (2 channel, 160 samples/channel, 16 bit/sample) 2.stereo port convert this in 160 samples / frame (1 channel, 160 samples / channel, 16 bit/sample) and give it to the downstream port. 3.the G.711 encoder convert the pcm samples (1 channel, 160 samples, 8 bit/sample) and send it to the network Has I could see, the G.711 encoder receives 160 samples / frames without the "stereo-mono" conversion, but 80 by adding this one -> this observation started my changes in the stereo_port. Something is not quite right there. With 20ms ptime, encoder should receive 160 samples after the frame is converted to mono, and not 80. Can you check the contents of mediaPort->info? It should contain clock_rate = 8000; samples_per_frame = 160 channel_count = 1; bytes_per_frame = 320; If samples_per_frame is 80 (=10ms), that means you set stream_info->param.setting.frm_per_pkt to 1 instead of 2. FYI the G.711 codec uses 10ms framing, hence in the codec param we usually set frm_per_pkt to 2 to make it 20ms ptime. So then something is not right with the sound device, since it's asked to return 10ms stereo frames in the aud_param (equalling 160 samples per frame) but yet it gives 320 samples in the capture callback. What sound device abstraction are you using? If all is proper then I probably need to check elsewhere. cheers Benny Maybe I'm doing all this really wrong L But I'm sure there must be a way to solve my stereo - mono problem in PJ J Thanks for helping. David From: pjsip-bounces@lists.pjsip.org [mailto:pjsip-bounces@lists.pjsip.org] On Behalf Of Benny Prijono Sent: Freitag, 3. Juli 2009 09:46 To: pjsip list Subject: Re: [pjsip] G.711 with stereo hardware On Thu, Jul 2, 2009 at 2:46 PM, David Andrey <David.Andrey@netmodule.com> wrote: Maybe useful for someone J I made the following changes in stereo_port.c: static pj_status_t stereo_get_frame(pjmedia_port *this_port, pjmedia_frame *frame) //tmp_frame.buf = sport->get_buf? sport->get_buf : frame->buf; // allocate get buffer for stereo port ??? //tmp_frame.size = sport->dn_port->info.bytes_per_frame; if (sport->get_buf) { tmp_frame.buf = sport->get_buf; tmp_frame.size = sport->dn_port->info.bytes_per_frame; } else { tmp_frame.buf = frame->buf; tmp_frame.size = frame->size; // da, 2009-06-30 } static pj_status_t stereo_put_frame(pjmedia_port *this_port, const pjmedia_frame *frame) //tmp_frame.size = sport->dn_port->info.bytes_per_frame; tmp_frame.size = sport->dn_port->info.samples_per_frame // da, 2009-06-30 * sport->base.info.bits_per_sample / 8; Still have memory problems (heap) in relation with the stereo usage. But stereo <-> G.711 seems ok now. Sorry I don't understand your patch above. When calling get_frame() or put_frame(), caller must supply frame size exactly as specified by port_info.bytes_per_frame of the specified port. I have a felling that somewhere your code does not do this hence the memory problem. Also the stereo port was not supposed to support G.711 channel conversion (i.e. only PCM), if this is what you're trying to do too. cheers Benny _______________________________________________ Visit our blog: http://blog.pjsip.org pjsip mailing list pjsip@lists.pjsip.org http://lists.pjsip.org/mailman/listinfo/pjsip_lists.pjsip.org
DA
David Andrey
Tue, Jul 14, 2009 8:15 AM

Hi Benny,

Have you any additional information about this situation ?

Thanks

David

From: pjsip-bounces@lists.pjsip.org [mailto:pjsip-bounces@lists.pjsip.org] On Behalf Of David Andrey
Sent: Montag, 6. Juli 2009 09:31
To: pjsip list
Subject: Re: [pjsip] G.711 with stereo hardware

Hi,

Here are the values of the mediaPort:

CALL.CPP  mediaPort -> clock_rate=8000  -  channel_count=1  -  samples_per_frame=160  -  bits_per_sample=16  -  bytes_per_frame=160

Seems I have a mismatch between "samples_per_frame" and "bytes_per_frame" ???

This gives the following output by the stereo - mono conversion (without my change)

stereo_put_frame source: nto1, samples per frames:320, bits per sample:16, bytes:640,  channel count:2

stereo_put_frame down: samples_per_frames=160  -  bits_per_sample=1  -  frame size=160

I checked the number of frames per packet during the "on_media_update()" callback.

audioStreamInfo = &sessionInfo.stream_info [0];

audioStreamInfo->param->setting.vad = PJ_SILENCE_DETECT;      // Voice Activity Detection (Silence)

PJ_LOG(3,(THIS_FILE, "audio frame per packet:%d", audioStreamInfo->param->setting.frm_per_pkt));

è CALL.CPP  audio frame per packet:2

Some additional infos that could help ...The memory problems becomes apparent by ending the call.

The code in "on_state_changed()" for the "PJSIP_INV_STATE_DISCONNECTED" state

  1. status = pjmedia_snd_port_disconnect        (soundBidir);

  2. status = pjmedia_snd_port_destroy (soundBidir);

  3. status = pjmedia_port_destroy (stereoPort);

  4. status = pjmedia_port_destroy (mediaPort);

  5. status = pjmedia_session_destroy  (mediaSession);

David

From: pjsip-bounces@lists.pjsip.org [mailto:pjsip-bounces@lists.pjsip.org] On Behalf Of Benny Prijono
Sent: Freitag, 3. Juli 2009 13:36
To: pjsip list
Subject: Re: [pjsip] G.711 with stereo hardware

On Fri, Jul 3, 2009 at 11:38 AM, David Andrey David.Andrey@netmodule.com wrote:

Hi Benny,

 

Well, what I'm trying to do is as follow:

 

1.Get the audio port created by "pjmedia_session_create()"

      status = pjmedia_session_get_port (mediaSession, 0, &mediaPort);

 

2. Open the sound device in full-duplex stereo (stereo is the only way at moment)

      pjmedia_aud_param audioParam;

      audioParam.dir = PJMEDIA_DIR_ENCODING_DECODING;

      audioParam.rec_id = -1;   // auto select for audio device

      audioParam.play_id = -1;

      audioParam.clock_rate =  mediaPort->info.clock_rate;

      audioParam.channel_count =  2; //mediaPort->info.channel_count;

      audioParam.samples_per_frame = 2* mediaPort->info.samples_per_frame;

      audioParam.bits_per_sample = mediaPort->info.bits_per_sample;

 

      PJ_LOG(3,(THIS_FILE, "create bidirectional audio ..."));

      status = pjmedia_snd_port_create2(inv->pool, &audioParam, &soundBidir);

 

3.Create a stereo-to-mono converter, which have the  the G.711 audio port as downstream

      status = pjmedia_stereo_port_create(inv->pool,

              mediaPort,

              2,

              0,

              &stereoPort);

 

4. Connect the stereo port to the sound device

    status = pjmedia_snd_port_connect(soundBidir, stereoPort);

 

All this is happening in the "on_media_update()" callback.

So far so good actually. The above should work.

So the data path I think to have is like this:

In the capture direction (for 8kHz, 20 ms audio samples per frame):

1.sound device give a 320 samples / frame (2 channel, 160 samples/channel, 16 bit/sample) 

2.stereo port convert this in 160 samples / frame (1 channel, 160 samples / channel, 16 bit/sample)  and give it to the downstream port.

3.the G.711 encoder convert the pcm  samples (1 channel, 160  samples, 8 bit/sample) and send it to the network

 

Has I could see, the G.711 encoder receives 160 samples / frames without the "stereo-mono" conversion, but 80 by adding this one -> this observation started my changes in the stereo_port.

 

Something is not quite right there. With 20ms ptime, encoder should receive 160 samples after the frame is converted to mono, and not 80.

Can you check the contents of mediaPort->info? It should contain
clock_rate = 8000;
samples_per_frame  = 160
channel_count = 1;
bytes_per_frame = 320;

If samples_per_frame is 80 (=10ms), that means you set stream_info->param.setting.frm_per_pkt to 1 instead of 2. FYI the G.711 codec uses 10ms framing, hence in the codec param we usually set frm_per_pkt to 2 to make it 20ms ptime. So then something is not right with the sound device, since it's asked to return 10ms stereo frames in the aud_param (equalling 160 samples per frame) but yet it gives 320 samples in the capture callback. What sound device abstraction are you using?

If all is proper then I probably need to check elsewhere.

cheers
Benny

Maybe I'm doing all this really wrong L But I'm sure there must be a way to solve my stereo - mono problem in PJ J

 

Thanks for helping.

 

David

 

From: pjsip-bounces@lists.pjsip.org [mailto:pjsip-bounces@lists.pjsip.org] On Behalf Of Benny Prijono
Sent: Freitag, 3. Juli 2009 09:46


To: pjsip list
Subject: Re: [pjsip] G.711 with stereo hardware

 

On Thu, Jul 2, 2009 at 2:46 PM, David Andrey <David.Andrey@netmodule.com> wrote:

	Maybe useful for someone J

	 

	I made the following changes in stereo_port.c:

	 

	static pj_status_t stereo_get_frame(pjmedia_port *this_port,

	                            pjmedia_frame *frame)

	 

	    //tmp_frame.buf = sport->get_buf? sport->get_buf : frame->buf;    // allocate get buffer for stereo port ???

	    //tmp_frame.size = sport->dn_port->info.bytes_per_frame;

	    if (sport->get_buf)

	    {

	      tmp_frame.buf = sport->get_buf;

	      tmp_frame.size = sport->dn_port->info.bytes_per_frame;

	    }

	    else

	    {

	      tmp_frame.buf = frame->buf;

	      tmp_frame.size = frame->size;                               // da, 2009-06-30

	    }

	 

	 

	static pj_status_t stereo_put_frame(pjmedia_port *this_port,

	                            const pjmedia_frame *frame)

	 

	      //tmp_frame.size = sport->dn_port->info.bytes_per_frame;

	      tmp_frame.size = sport->dn_port->info.samples_per_frame       // da, 2009-06-30

	                        * sport->base.info.bits_per_sample / 8;

	 

	Still have memory problems (heap) in relation with the stereo usage. But stereo <-> G.711 seems ok now.


Sorry I don't understand your patch above. When calling get_frame() or put_frame(), caller must supply frame size exactly as specified by port_info.bytes_per_frame of the specified port. I have a felling that somewhere your code does not do this hence the memory problem.

Also the stereo port was not supposed to support G.711 channel conversion (i.e. only PCM), if this is what you're trying to do too.

cheers
 Benny


_______________________________________________
Visit our blog: http://blog.pjsip.org

pjsip mailing list
pjsip@lists.pjsip.org
http://lists.pjsip.org/mailman/listinfo/pjsip_lists.pjsip.org
Hi Benny, Have you any additional information about this situation ? Thanks David From: pjsip-bounces@lists.pjsip.org [mailto:pjsip-bounces@lists.pjsip.org] On Behalf Of David Andrey Sent: Montag, 6. Juli 2009 09:31 To: pjsip list Subject: Re: [pjsip] G.711 with stereo hardware Hi, Here are the values of the mediaPort: CALL.CPP mediaPort -> clock_rate=8000 - channel_count=1 - samples_per_frame=160 - bits_per_sample=16 - bytes_per_frame=160 Seems I have a mismatch between "samples_per_frame" and "bytes_per_frame" ??? This gives the following output by the stereo - mono conversion (without my change) stereo_put_frame source: nto1, samples per frames:320, bits per sample:16, bytes:640, channel count:2 stereo_put_frame down: samples_per_frames=160 - bits_per_sample=1 - frame size=160 I checked the number of frames per packet during the "on_media_update()" callback. audioStreamInfo = &sessionInfo.stream_info [0]; audioStreamInfo->param->setting.vad = PJ_SILENCE_DETECT; // Voice Activity Detection (Silence) PJ_LOG(3,(THIS_FILE, "audio frame per packet:%d", audioStreamInfo->param->setting.frm_per_pkt)); è CALL.CPP audio frame per packet:2 Some additional infos that could help ...The memory problems becomes apparent by ending the call. The code in "on_state_changed()" for the "PJSIP_INV_STATE_DISCONNECTED" state 1. status = pjmedia_snd_port_disconnect (soundBidir); 2. status = pjmedia_snd_port_destroy (soundBidir); 3. status = pjmedia_port_destroy (stereoPort); 4. status = pjmedia_port_destroy (mediaPort); 5. status = pjmedia_session_destroy (mediaSession); David From: pjsip-bounces@lists.pjsip.org [mailto:pjsip-bounces@lists.pjsip.org] On Behalf Of Benny Prijono Sent: Freitag, 3. Juli 2009 13:36 To: pjsip list Subject: Re: [pjsip] G.711 with stereo hardware On Fri, Jul 3, 2009 at 11:38 AM, David Andrey <David.Andrey@netmodule.com> wrote: Hi Benny, Well, what I'm trying to do is as follow: 1.Get the audio port created by "pjmedia_session_create()" status = pjmedia_session_get_port (mediaSession, 0, &mediaPort); 2. Open the sound device in full-duplex stereo (stereo is the only way at moment) pjmedia_aud_param audioParam; audioParam.dir = PJMEDIA_DIR_ENCODING_DECODING; audioParam.rec_id = -1; // auto select for audio device audioParam.play_id = -1; audioParam.clock_rate = mediaPort->info.clock_rate; audioParam.channel_count = 2; //mediaPort->info.channel_count; audioParam.samples_per_frame = 2* mediaPort->info.samples_per_frame; audioParam.bits_per_sample = mediaPort->info.bits_per_sample; PJ_LOG(3,(THIS_FILE, "create bidirectional audio ...")); status = pjmedia_snd_port_create2(inv->pool, &audioParam, &soundBidir); 3.Create a stereo-to-mono converter, which have the the G.711 audio port as downstream status = pjmedia_stereo_port_create(inv->pool, mediaPort, 2, 0, &stereoPort); 4. Connect the stereo port to the sound device status = pjmedia_snd_port_connect(soundBidir, stereoPort); All this is happening in the "on_media_update()" callback. So far so good actually. The above should work. So the data path I think to have is like this: In the capture direction (for 8kHz, 20 ms audio samples per frame): 1.sound device give a 320 samples / frame (2 channel, 160 samples/channel, 16 bit/sample) 2.stereo port convert this in 160 samples / frame (1 channel, 160 samples / channel, 16 bit/sample) and give it to the downstream port. 3.the G.711 encoder convert the pcm samples (1 channel, 160 samples, 8 bit/sample) and send it to the network Has I could see, the G.711 encoder receives 160 samples / frames without the "stereo-mono" conversion, but 80 by adding this one -> this observation started my changes in the stereo_port. Something is not quite right there. With 20ms ptime, encoder should receive 160 samples after the frame is converted to mono, and not 80. Can you check the contents of mediaPort->info? It should contain clock_rate = 8000; samples_per_frame = 160 channel_count = 1; bytes_per_frame = 320; If samples_per_frame is 80 (=10ms), that means you set stream_info->param.setting.frm_per_pkt to 1 instead of 2. FYI the G.711 codec uses 10ms framing, hence in the codec param we usually set frm_per_pkt to 2 to make it 20ms ptime. So then something is not right with the sound device, since it's asked to return 10ms stereo frames in the aud_param (equalling 160 samples per frame) but yet it gives 320 samples in the capture callback. What sound device abstraction are you using? If all is proper then I probably need to check elsewhere. cheers Benny Maybe I'm doing all this really wrong L But I'm sure there must be a way to solve my stereo - mono problem in PJ J Thanks for helping. David From: pjsip-bounces@lists.pjsip.org [mailto:pjsip-bounces@lists.pjsip.org] On Behalf Of Benny Prijono Sent: Freitag, 3. Juli 2009 09:46 To: pjsip list Subject: Re: [pjsip] G.711 with stereo hardware On Thu, Jul 2, 2009 at 2:46 PM, David Andrey <David.Andrey@netmodule.com> wrote: Maybe useful for someone J I made the following changes in stereo_port.c: static pj_status_t stereo_get_frame(pjmedia_port *this_port, pjmedia_frame *frame) //tmp_frame.buf = sport->get_buf? sport->get_buf : frame->buf; // allocate get buffer for stereo port ??? //tmp_frame.size = sport->dn_port->info.bytes_per_frame; if (sport->get_buf) { tmp_frame.buf = sport->get_buf; tmp_frame.size = sport->dn_port->info.bytes_per_frame; } else { tmp_frame.buf = frame->buf; tmp_frame.size = frame->size; // da, 2009-06-30 } static pj_status_t stereo_put_frame(pjmedia_port *this_port, const pjmedia_frame *frame) //tmp_frame.size = sport->dn_port->info.bytes_per_frame; tmp_frame.size = sport->dn_port->info.samples_per_frame // da, 2009-06-30 * sport->base.info.bits_per_sample / 8; Still have memory problems (heap) in relation with the stereo usage. But stereo <-> G.711 seems ok now. Sorry I don't understand your patch above. When calling get_frame() or put_frame(), caller must supply frame size exactly as specified by port_info.bytes_per_frame of the specified port. I have a felling that somewhere your code does not do this hence the memory problem. Also the stereo port was not supposed to support G.711 channel conversion (i.e. only PCM), if this is what you're trying to do too. cheers Benny _______________________________________________ Visit our blog: http://blog.pjsip.org pjsip mailing list pjsip@lists.pjsip.org http://lists.pjsip.org/mailman/listinfo/pjsip_lists.pjsip.org