G.711 with stereo hardware

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Benny,

 

Have you any additional information about this situation ?

 

Thanks

 

David

 

From: pjsip-bounces@xxxxxxxxxxxxxxx [mailto:pjsip-bounces at lists.pjsip.org] On Behalf Of David Andrey
Sent: Montag, 6. Juli 2009 09:31
To: pjsip list
Subject: Re: 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@xxxxxxxxxxxxxxx [mailto:pjsip-bounces at lists.pjsip.org] On Behalf Of Benny Prijono
Sent: Freitag, 3. Juli 2009 13:36
To: pjsip list
Subject: Re: G.711 with stereo hardware

 

On Fri, Jul 3, 2009 at 11:38 AM, David Andrey <David.Andrey at 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@xxxxxxxxxxxxxxx [mailto:pjsip-bounces at lists.pjsip.org] On Behalf Of Benny Prijono
	Sent: Freitag, 3. Juli 2009 09:46

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

	 

	On Thu, Jul 2, 2009 at 2:46 PM, David Andrey <David.Andrey at 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 at lists.pjsip.org
	http://lists.pjsip.org/mailman/listinfo/pjsip_lists.pjsip.org

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.pjsip.org/pipermail/pjsip_lists.pjsip.org/attachments/20090714/950442ad/attachment-0001.html>


[Index of Archives]     [Asterisk Users]     [Asterisk App Development]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [Linux API]
  Powered by Linux