Ignore:
Timestamp:
May 19, 2006 3:58:13 PM (18 years ago)
Author:
bennylp
Message:

Install VAD in g711, gsm, and speex, and add the DTX support in stream.c. Also changed the way the silence detector works, and changed default speex quality/complexity to 10

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjmedia/src/pjmedia/stream.c

    r452 r457  
    5757    void                   *out_pkt;        /**< Output buffer.             */ 
    5858    pjmedia_rtp_session     rtp;            /**< RTP session.               */ 
    59     char                    last_frm_type;  /**< Last frame type from jb    */ 
    6059}; 
    6160 
     
    9190    pjmedia_codec_param      codec_param;   /**< Codec param.               */ 
    9291    unsigned                 frame_size;    /**< Size of encoded base frame.*/ 
     92    pj_bool_t                is_streaming;  /**< Currently streaming?. This 
     93                                                 is used to put RTP marker 
     94                                                 bit.                       */ 
     95 
    9396    pj_mutex_t              *jb_mutex; 
    9497    pjmedia_jbuf            *jb;            /**< Jitter buffer.             */ 
     98    char                     jb_last_frm;   /**< Last frame type from jb    */ 
    9599 
    96100    pjmedia_rtcp_session     rtcp;          /**< RTCP for incoming RTP.     */ 
     
    210214             * the frame.  
    211215             */ 
    212             if (frame_type != channel->last_frm_type) { 
     216            if (frame_type != stream->jb_last_frm) { 
    213217                pjmedia_jb_state jb_state; 
    214218 
     
    244248                pjmedia_zero_samples(p_out_samp + samples_count, 
    245249                                     samples_required - samples_count); 
     250                samples_count = samples_required; 
    246251            } 
    247252 
    248             channel->last_frm_type = frame_type; 
     253            stream->jb_last_frm = frame_type; 
    249254            break; 
    250255 
     
    277282                } while (samples_count < samples_required); 
    278283 
    279                 if (channel->last_frm_type != frame_type) { 
     284                if (stream->jb_last_frm != frame_type) { 
    280285                    PJ_LOG(5,(stream->port.info.name.ptr,  
    281286                              "Jitter buffer is bufferring with plc (prefetch=%d)", 
     
    288293                pjmedia_zero_samples(p_out_samp + samples_count, 
    289294                                     samples_required - samples_count); 
     295                samples_count = samples_required; 
    290296                PJ_LOG(5,(stream->port.info.name.ptr,  
    291297                          "Jitter buffer is bufferring (prefetch=%d)..",  
     
    293299            } 
    294300 
    295             channel->last_frm_type = frame_type; 
     301            stream->jb_last_frm = frame_type; 
    296302            break; 
    297303 
     
    318324        } 
    319325 
    320         channel->last_frm_type = frame_type; 
     326        stream->jb_last_frm = frame_type; 
    321327    } 
    322328 
     
    438444    struct pjmedia_frame frame_out; 
    439445    unsigned ts_len; 
    440     pj_bool_t has_tx; 
    441446    void *rtphdr; 
    442447    int rtphdrlen; 
    443     pj_ssize_t sent; 
    444448 
    445449 
     
    454458    /* Init frame_out buffer. */ 
    455459    frame_out.buf = ((char*)channel->out_pkt) + sizeof(pjmedia_rtp_hdr); 
    456  
    457     /* Make compiler happy */ 
    458460    frame_out.size = 0; 
     461 
    459462 
    460463    /* If we have DTMF digits in the queue, transmit the digits.  
     
    463466    if (stream->tx_dtmf_count) { 
    464467 
    465         has_tx = PJ_TRUE; 
    466468        create_dtmf_payload(stream, &frame_out); 
    467469 
     
    475477    } else if (frame->type != PJMEDIA_FRAME_TYPE_NONE) { 
    476478        unsigned ts, samples_per_frame; 
    477  
    478         has_tx = PJ_TRUE; 
    479479 
    480480        /* Repeatedly call encode if there are multiple frames to be 
     
    490490            unsigned bytes_per_sample, max_size; 
    491491 
     492            /* Nb of bytes in PCM sample */ 
    492493            bytes_per_sample = stream->codec_param.info.pcm_bits_per_sample/8; 
    493494 
     495            /* Split original PCM input frame into base frame size */ 
    494496            tmp_in_frame.buf = ((char*)frame->buf) + ts * bytes_per_sample; 
    495497            tmp_in_frame.size = samples_per_frame * bytes_per_sample; 
    496498            tmp_in_frame.type = PJMEDIA_FRAME_TYPE_AUDIO; 
    497499 
     500            /* Set output frame position */ 
    498501            tmp_out_frame.buf = ((char*)frame_out.buf) + frame_out.size; 
    499502 
     
    501504                       frame_out.size; 
    502505 
     506            /* Encode! */ 
    503507            status = stream->codec->op->encode( stream->codec, &tmp_in_frame,  
    504508                                                max_size, &tmp_out_frame); 
     
    509513            } 
    510514 
     515            /* tmp_out_frame.size may be zero for silence frame. */ 
    511516            frame_out.size += tmp_out_frame.size; 
     517 
     518            /* Stop processing next PCM frame when encode() returns either  
     519             * CNG frame or NULL frame. 
     520             */ 
     521            if (tmp_out_frame.type!=PJMEDIA_FRAME_TYPE_AUDIO ||  
     522                tmp_out_frame.size==0)  
     523            { 
     524                break; 
     525            } 
     526 
    512527        } 
    513  
    514         //printf("p"); fflush(stdout); 
    515528 
    516529        /* Encapsulate. */ 
     
    523536 
    524537        /* Just update RTP session's timestamp. */ 
    525         has_tx = PJ_FALSE; 
    526538        status = pjmedia_rtp_encode_rtp( &channel->rtp,  
    527539                                         0, 0,  
     
    547559 
    548560    /* Do nothing if we have nothing to transmit */ 
    549     if (!has_tx) 
     561    if (frame_out.size == 0) { 
     562        if (stream->is_streaming) { 
     563            PJ_LOG(5,(stream->port.info.name.ptr,"Starting silence")); 
     564            stream->is_streaming = PJ_FALSE; 
     565        } 
    550566        return PJ_SUCCESS; 
    551  
    552     if (rtphdrlen != sizeof(pjmedia_rtp_hdr)) { 
    553         /* We don't support RTP with extended header yet. */ 
    554         PJ_TODO(SUPPORT_SENDING_RTP_WITH_EXTENDED_HEADER); 
    555         return PJ_SUCCESS; 
    556     } 
    557  
     567    } 
     568 
     569 
     570    /* Copy RTP header to the beginning of packet */ 
    558571    pj_memcpy(channel->out_pkt, rtphdr, sizeof(pjmedia_rtp_hdr)); 
    559572 
    560573 
    561     /* Send. */ 
    562     sent = frame_out.size+sizeof(pjmedia_rtp_hdr); 
    563  
     574    /* Set RTP marker bit if currently not streaming */ 
     575    if (stream->is_streaming == PJ_FALSE) { 
     576        pjmedia_rtp_hdr *rtp = channel->out_pkt; 
     577 
     578        rtp->m = 1; 
     579        PJ_LOG(5,(stream->port.info.name.ptr,"Start talksprut..")); 
     580    } 
     581 
     582    stream->is_streaming = PJ_TRUE; 
     583 
     584    /* Send the RTP packet to the transport. */ 
    564585    (*stream->transport->op->send_rtp)(stream->transport, 
    565                                        channel->out_pkt, sent); 
     586                                       channel->out_pkt,  
     587                                       frame_out.size +  
     588                                            sizeof(pjmedia_rtp_hdr)); 
    566589 
    567590 
Note: See TracChangeset for help on using the changeset viewer.