Ignore:
Timestamp:
Sep 20, 2007 1:19:03 PM (17 years ago)
Author:
bennylp
Message:

Ticket #13: Send RTCP RR if stream is not transmitting any RTP packets

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/branches/pjproject-0.5-stable/pjmedia/src/pjmedia/stream.c

    r1047 r1447  
    6363{ 
    6464    int             event; 
    65     pj_uint32_t     start_ts; 
     65    pj_uint32_t     duration; 
    6666}; 
    6767 
     
    167167static pj_status_t get_frame( pjmedia_port *port, pjmedia_frame *frame) 
    168168{ 
    169     pjmedia_stream *stream = port->port_data.pdata; 
     169    pjmedia_stream *stream = (pjmedia_stream*) port->port_data.pdata; 
    170170    pjmedia_channel *channel = stream->dec; 
    171171    unsigned samples_count, samples_per_frame, samples_required; 
     
    192192                        stream->codec_param.info.channel_cnt /  
    193193                        1000; 
    194     p_out_samp = frame->buf; 
     194    p_out_samp = (pj_int16_t*) frame->buf; 
    195195 
    196196    for (samples_count=0; samples_count < samples_required;  
     
    374374 */ 
    375375static void create_dtmf_payload(pjmedia_stream *stream,  
    376                           struct pjmedia_frame *frame_out) 
     376                                struct pjmedia_frame *frame_out, 
     377                                int *first, int *last) 
    377378{ 
    378379    pjmedia_rtp_dtmf_event *event; 
    379380    struct dtmf *digit = &stream->tx_dtmf_buf[0]; 
    380     unsigned duration; 
    381381    pj_uint32_t cur_ts; 
    382382 
    383383    pj_assert(sizeof(pjmedia_rtp_dtmf_event) == 4); 
    384384 
    385     event = frame_out->buf; 
     385    *first = *last = 0; 
     386 
     387    event = (pjmedia_rtp_dtmf_event*) frame_out->buf; 
    386388    cur_ts = pj_ntohl(stream->enc->rtp.out_hdr.ts); 
    387     duration = cur_ts - digit->start_ts; 
     389 
     390    if (digit->duration == 0) { 
     391        PJ_LOG(5,(stream->port.info.name.ptr, "Sending DTMF digit id %c",  
     392                  digitmap[digit->event])); 
     393        *first = 1; 
     394    } 
     395 
     396    digit->duration += stream->port.info.samples_per_frame; 
    388397 
    389398    event->event = (pj_uint8_t)digit->event; 
    390399    event->e_vol = 10; 
    391     event->duration = pj_htons((pj_uint16_t)duration); 
    392  
    393     if (duration >= PJMEDIA_DTMF_DURATION) { 
     400    event->duration = pj_htons((pj_uint16_t)digit->duration); 
     401 
     402 
     403    if (digit->duration >= PJMEDIA_DTMF_DURATION) { 
     404 
    394405        event->e_vol |= 0x80; 
     406        *last = 1; 
    395407 
    396408        /* Prepare next digit. */ 
    397409        pj_mutex_lock(stream->jb_mutex); 
     410 
    398411        pj_array_erase(stream->tx_dtmf_buf, sizeof(stream->tx_dtmf_buf[0]), 
    399412                       stream->tx_dtmf_count, 0); 
    400413        --stream->tx_dtmf_count; 
    401414 
    402         stream->tx_dtmf_buf[0].start_ts = cur_ts; 
    403415        pj_mutex_unlock(stream->jb_mutex); 
    404  
    405         if (stream->tx_dtmf_count) { 
    406             PJ_LOG(5,(stream->port.info.name.ptr, 
    407                       "Sending DTMF digit id %c",  
    408                       digitmap[stream->tx_dtmf_buf[0].event])); 
    409         } 
    410  
    411     } else if (duration == 0) { 
    412         PJ_LOG(5,(stream->port.info.name.ptr, "Sending DTMF digit id %c",  
    413                   digitmap[digit->event])); 
    414     } 
    415  
     416    } 
    416417 
    417418    frame_out->size = 4; 
     
    439440    } else if (timestamp - stream->rtcp_last_tx >= stream->rtcp_interval) { 
    440441         
    441         pjmedia_rtcp_pkt *rtcp_pkt; 
     442        void *rtcp_pkt; 
    442443        int len; 
    443444 
     
    515516                                  const pjmedia_frame *frame ) 
    516517{ 
    517     pjmedia_stream *stream = port->port_data.pdata; 
     518    pjmedia_stream *stream = (pjmedia_stream*) port->port_data.pdata; 
    518519    pjmedia_channel *channel = stream->enc; 
    519520    pj_status_t status = 0; 
     
    522523    void *rtphdr; 
    523524    int rtphdrlen; 
    524  
     525    int inc_timestamp = 0; 
    525526 
    526527    /* Don't do anything if stream is paused */ 
     
    551552     */ 
    552553    if (stream->tx_dtmf_count) { 
    553  
    554         create_dtmf_payload(stream, &frame_out); 
    555  
    556         /* Encapsulate. */ 
     554        int first=0, last=0; 
     555 
     556        create_dtmf_payload(stream, &frame_out, &first, &last); 
     557 
     558        /* Encapsulate into RTP packet. Note that: 
     559         *  - RTP marker should be set on the beginning of a new event 
     560         *  - RTP timestamp is constant for the same packet.  
     561         */ 
    557562        status = pjmedia_rtp_encode_rtp( &channel->rtp,  
    558                                          stream->tx_event_pt, 0,  
    559                                          frame_out.size, ts_len,  
     563                                         stream->tx_event_pt, first,  
     564                                         frame_out.size, (first?ts_len:0),  
    560565                                         (const void**)&rtphdr,  
    561566                                         &rtphdrlen); 
     567 
     568        if (last) { 
     569            /* This is the last packet for the event.  
     570             * Increment the RTP timestamp of the RTP session, for next 
     571             * RTP packets. 
     572             */ 
     573            inc_timestamp = PJMEDIA_DTMF_DURATION - ts_len; 
     574        } 
    562575 
    563576    } else if (frame->type != PJMEDIA_FRAME_TYPE_NONE) { 
     
    663676    pj_memcpy(channel->out_pkt, rtphdr, sizeof(pjmedia_rtp_hdr)); 
    664677 
     678    /* Special case for DTMF: timestamp remains constant for 
     679     * the same event, and is only updated after a complete event 
     680     * has been transmitted. 
     681     */ 
     682    if (inc_timestamp) { 
     683        pjmedia_rtp_encode_rtp( &channel->rtp, stream->tx_event_pt, 0, 
     684                                0, inc_timestamp, NULL, NULL); 
     685    } 
    665686 
    666687    /* Set RTP marker bit if currently not streaming */ 
    667688    if (stream->is_streaming == PJ_FALSE) { 
    668         pjmedia_rtp_hdr *rtp = channel->out_pkt; 
     689        pjmedia_rtp_hdr *rtp = (pjmedia_rtp_hdr*) channel->out_pkt; 
    669690 
    670691        rtp->m = 1; 
     
    698719                              const pjmedia_frame *frame ) 
    699720{ 
    700     pjmedia_stream *stream = port->port_data.pdata; 
     721    pjmedia_stream *stream = (pjmedia_stream*) port->port_data.pdata; 
    701722    pjmedia_frame tmp_zero_frame; 
    702723    unsigned samples_per_frame; 
     
    831852                                  const void *payload, unsigned payloadlen) 
    832853{ 
    833     const pjmedia_rtp_dtmf_event *event = payload; 
     854    pjmedia_rtp_dtmf_event *event = (pjmedia_rtp_dtmf_event*) payload; 
    834855 
    835856    /* Check compiler packing. */ 
     
    903924 
    904925{ 
    905     pjmedia_stream *stream = data; 
     926    pjmedia_stream *stream = (pjmedia_stream*) data; 
    906927    pjmedia_channel *channel = stream->dec; 
    907928    const pjmedia_rtp_hdr *hdr; 
     
    919940 
    920941    /* Ignore keep-alive packets */ 
    921     if (bytes_read < sizeof(pjmedia_rtp_hdr)) 
     942    if (bytes_read < (pj_ssize_t) sizeof(pjmedia_rtp_hdr)) 
    922943        return; 
    923944 
     
    10531074                        pj_ssize_t bytes_read) 
    10541075{ 
    1055     pjmedia_stream *stream = data; 
     1076    pjmedia_stream *stream = (pjmedia_stream*) data; 
    10561077 
    10571078    /* Check for errors */ 
     
    10811102    /* Allocate memory for channel descriptor */ 
    10821103 
    1083     channel = pj_pool_zalloc(pool, sizeof(pjmedia_channel)); 
     1104    channel = (pjmedia_channel*) pj_pool_zalloc(pool, sizeof(pjmedia_channel)); 
    10841105    PJ_ASSERT_RETURN(channel != NULL, PJ_ENOMEM); 
    10851106 
     
    11471168    /* Allocate the media stream: */ 
    11481169 
    1149     stream = pj_pool_zalloc(pool, sizeof(pjmedia_stream)); 
     1170    stream = (pjmedia_stream*) pj_pool_zalloc(pool, sizeof(pjmedia_stream)); 
    11501171    PJ_ASSERT_RETURN(stream != NULL, PJ_ENOMEM); 
    11511172 
    11521173    /* Init stream/port name */ 
    1153     name.ptr = pj_pool_alloc(pool, M); 
     1174    name.ptr = (char*) pj_pool_alloc(pool, M); 
    11541175    name.slen = pj_ansi_snprintf(name.ptr, M, "strm%p", stream); 
    11551176 
     
    12631284        /* Allocate buffer */ 
    12641285        stream->enc_buf_size = stream->port.info.clock_rate * ptime / 1000; 
    1265         stream->enc_buf = pj_pool_alloc(pool, stream->enc_buf_size * 2); 
     1286        stream->enc_buf = (pj_int16_t*) 
     1287                          pj_pool_alloc(pool, stream->enc_buf_size * 2); 
    12661288 
    12671289    } else { 
     
    15361558     
    15371559    if (stream->tx_dtmf_count+digit_char->slen >= 
    1538         PJ_ARRAY_SIZE(stream->tx_dtmf_buf)) 
     1560        (long)PJ_ARRAY_SIZE(stream->tx_dtmf_buf)) 
    15391561    { 
    15401562        status = PJ_ETOOMANY; 
     
    15721594 
    15731595            stream->tx_dtmf_buf[stream->tx_dtmf_count+i].event = pt; 
     1596            stream->tx_dtmf_buf[stream->tx_dtmf_count+i].duration = 0; 
    15741597        } 
    15751598 
     
    15771600            goto on_return; 
    15781601 
    1579         /* Init start_ts and end_ts only for the first digit. 
    1580          * Subsequent digits are initialized on the fly. 
    1581          */ 
    1582         if (stream->tx_dtmf_count ==0) { 
    1583             pj_uint32_t start_ts; 
    1584  
    1585             start_ts = pj_ntohl(stream->enc->rtp.out_hdr.ts); 
    1586             stream->tx_dtmf_buf[0].start_ts = start_ts; 
    1587         } 
    1588  
    15891602        /* Increment digit count only if all digits are valid. */ 
    15901603        stream->tx_dtmf_count += digit_char->slen; 
    1591  
    15921604    } 
    15931605 
     
    16461658 * Set callback to be called upon receiving DTMF digits. 
    16471659 */ 
    1648 PJ_DEF(pj_status_t) 
    1649 pjmedia_stream_set_dtmf_callback(pjmedia_stream *stream, 
     1660PJ_DEF(pj_status_t) pjmedia_stream_set_dtmf_callback(pjmedia_stream *stream, 
    16501661                                 void (*cb)(pjmedia_stream*,  
    16511662                                            void *user_data,  
Note: See TracChangeset for help on using the changeset viewer.