int speex_jitter_get(SpeexJitter *jitter, spx_int16_t *out, int *current_timestamp, void** userData)
{
   int i;
   int jbRet;	/* results returned by the JB */
   int ourRet;	/* result that we will return */
   spx_int32_t activity;
   char data[2048];
   JitterBufferPacket packet;
   packet.data = data;
   packet.len = 2048;  /* AAAAARGH: it took a week to find and add this missing line */
   
   if (jitter->valid_bits)
   {
      /* Try decoding last received packet */
      jbRet = speex_decode_int(jitter->dec, &jitter->current_packet, out);
      if (jbRet == 0)
      {
         jitter_buffer_tick(jitter->packets);
         return 1;
      } else {
         jitter->valid_bits = 0;
      }
   }

   jbRet = jitter_buffer_get(jitter->packets, &packet, jitter->frame_size, NULL);
   
   if (jbRet != JITTER_BUFFER_OK)
   {
	  /* no packet found, so no corresponding user-data */
      *userData = NULL;

      /* No packet found... extrapolate one */

      /*fprintf (stderr, "lost/late frame\n");*/
      /*Packet is late or lost*/
      speex_decode_int(jitter->dec, NULL, out);
	  
	  ourRet = 2;
   } else {
	  /* found a packet, so there is corresponding user-data */
	  *userData = (void*)(packet.user_data);
   
      speex_bits_read_from(&jitter->current_packet, packet.data, packet.len);
      /* Decode packet */
      jbRet = speex_decode_int(jitter->dec, &jitter->current_packet, out);
      if (jbRet == 0) {
         ourRet = 0;		
         jitter->valid_bits = 1;
      } else {
         /* Error while decoding */
         ourRet = 3;
         for (i=0;i<jitter->frame_size;i++) out[i]=0;
      }
   }
   speex_decoder_ctl(jitter->dec, SPEEX_GET_ACTIVITY, &activity);
   if (activity < jitter->activity_threshold) 
      jitter_buffer_update_delay(jitter->packets, &packet, NULL); 
   jitter_buffer_tick(jitter->packets);
   return ourRet;
}
Exemplo n.º 2
0
static tsk_size_t tdav_speex_jitterbuffer_get(tmedia_jitterbuffer_t* self, void* out_data, tsk_size_t out_size)
{
	tdav_speex_jitterbuffer_t *jb = (tdav_speex_jitterbuffer_t *)self;
    JitterBufferPacket jb_packet;
    int ret;

    if(!out_data || !out_size){
        TSK_DEBUG_ERROR("Invalid parameter");
        return 0;
    }
    if(!jb->state){
        TSK_DEBUG_ERROR("Invalid state");
        return 0;
    }
	if(jb->x_data_size != out_size){ // consumer must request PTIME data
		TSK_DEBUG_WARN("%d not expected as frame size. %u<>%u", out_size, jb->frame_duration, (out_size * 500)/jb->rate);
		return 0;
	}

    jb_packet.data = out_data;
    jb_packet.len = out_size;

	if ((ret = jitter_buffer_get(jb->state, &jb_packet, jb->frame_duration/*(out_size * 500)/jb->rate*/, tsk_null)) != JITTER_BUFFER_OK) {
        switch(ret){
            case JITTER_BUFFER_MISSING: /*TSK_DEBUG_INFO("JITTER_BUFFER_MISSING - %d", ret);*/ break;
            case JITTER_BUFFER_INSERTION: /*TSK_DEBUG_INFO("JITTER_BUFFER_INSERTION - %d", ret);*/ break;
            default: TSK_DEBUG_INFO("jitter_buffer_get() failed - %d", ret); break;
        }
        jitter_buffer_update_delay(jb->state, &jb_packet, NULL);
        return 0;
    }
    // jitter_buffer_update_delay(jitterbuffer->state, &jb_packet, NULL);

    return out_size;
}
Exemplo n.º 3
0
JNIEXPORT jint JNICALL Native_NATIVE(jitter_1buffer_1update_1delay)
	(JNIEnv *env, jclass that, jlong arg0, jobject arg1, jintArray arg2)
{
	JitterBufferPacket _arg1, *lparg1=NULL;
	jint *lparg2=NULL;
	jint rc = 0;
	Native_NATIVE_ENTER(env, that, Native_jitter_1buffer_1update_1delay_FUNC);
	if (arg1) if ((lparg1 = getJitterBufferPacketFields(env, arg1, &_arg1)) == NULL) goto fail;
	if (arg2) if ((lparg2 = (*env)->GetIntArrayElements(env, arg2, NULL)) == NULL) goto fail;
	rc = jitter_buffer_update_delay((JitterBuffer *)(intptr_t)arg0, lparg1, lparg2);
fail:
	if (arg2 && lparg2) (*env)->ReleaseIntArrayElements(env, arg2, lparg2, 0);
	Native_NATIVE_EXIT(env, that, Native_jitter_1buffer_1update_1delay_FUNC);
	return rc;
}