How to decode (codec encoded) audio frames using pjmedia + pjmedia-codec?

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

 



Hi all,
I'm attempting to decode "codec" encoded packets but I'm having trouble understanding how to properly decode the frames (subframes, etc). I understand that I must iterate the frames and look for subframes but my attempts have failed and the code removed. If I disable the codec this code works fine on both sides.

Here is my callback code:

static pj_status_t play_cb(void * user_data, pjmedia_frame * frame)
{
    audio_stream * s = static_cast<audio_stream *> (user_data);
    
    if (s)
    {
    	char pkt[160];
    	struct pjmedia_frame in, out;

    	unsigned samples_per_frame = 
    		g_codec_param.info.clock_rate * g_codec_param.info.frm_ptime / 1000
    	;

		for (;;)
		{
			// decode frame, subframe and frames?
			
			// Inform the handler.
			s->on_output(static_cast<const char *> (out.buf), out.size);
		}
    }
    
    return PJ_SUCCESS;
}

static pj_status_t rec_cb(void * user_data, pjmedia_frame * frame)
{
    audio_stream * s = static_cast<audio_stream *> (user_data);
    
    if (s)
    {
        char pkt[160];
        struct pjmedia_frame in, out;

        unsigned samples_per_frame = 
        	g_codec_param.info.clock_rate * g_codec_param.info.frm_ptime / 1000
        ;
 
        in.type = PJMEDIA_FRAME_TYPE_AUDIO;
        in.buf = frame->buf;
        in.size = samples_per_frame * 2;
        out.buf = pkt;

        pj_status_t status = s->codec()->op->encode(
        	s->codec(), &in, sizeof(pkt), &out
        );
        
        assert(status == PJ_SUCCESS);
		
		// Inform the handler.
        s->on_input(pkt, out.size);
    }
    
    return PJ_SUCCESS;
}


Thanks for any help on this problem.

junglecat




[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