Ignore:
Timestamp:
Jul 19, 2011 3:42:28 AM (13 years ago)
Author:
nanang
Message:

Re #1326: Initial code integration from branch 2.0-dev to trunk as "2.0-pre-alpha-svn".

Location:
pjproject/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk

  • pjproject/trunk/pjmedia/src/pjmedia/resample_port.c

    r3553 r3664  
    2626 
    2727#define BYTES_PER_SAMPLE        2 
    28 #define SIGNATURE               PJMEDIA_PORT_SIGNATURE('R','S','M','P') 
     28#define SIGNATURE               PJMEDIA_SIG_PORT_RESAMPLE 
    2929 
    3030 
     
    4343 
    4444static pj_status_t resample_put_frame(pjmedia_port *this_port, 
    45                                       const pjmedia_frame *frame); 
     45                                      pjmedia_frame *frame); 
    4646static pj_status_t resample_get_frame(pjmedia_port *this_port,  
    4747                                      pjmedia_frame *frame); 
     
    5858    const pj_str_t name = pj_str("resample"); 
    5959    struct resample_port *rport; 
    60     unsigned ptime; 
     60    pjmedia_audio_format_detail *d_afd, *r_afd; 
    6161    pj_status_t status; 
    6262 
     
    6565 
    6666    /* Only supports 16bit samples per frame */ 
    67     PJ_ASSERT_RETURN(dn_port->info.bits_per_sample == 16, PJMEDIA_ENCBITS); 
    68  
    69     ptime = dn_port->info.samples_per_frame * 1000 /  
    70             dn_port->info.clock_rate; 
    71      
     67    PJ_ASSERT_RETURN(PJMEDIA_PIA_BITS(&dn_port->info) == 16, PJMEDIA_ENCBITS); 
     68 
     69    d_afd = pjmedia_format_get_audio_format_detail(&dn_port->info.fmt, 1); 
     70 
    7271    /* Create and initialize port. */ 
    7372    rport = PJ_POOL_ZALLOC_T(pool, struct resample_port); 
     
    7574 
    7675    pjmedia_port_info_init(&rport->base.info, &name, SIGNATURE, clock_rate, 
    77                            dn_port->info.channel_count, BYTES_PER_SAMPLE * 8,  
    78                            clock_rate * ptime / 1000); 
     76                           d_afd->channel_count, BYTES_PER_SAMPLE * 8, 
     77                           clock_rate * d_afd->frame_time_usec / 1000000); 
    7978 
    8079    rport->dn_port = dn_port; 
    8180    rport->options = opt; 
    8281 
     82    r_afd = pjmedia_format_get_audio_format_detail(&rport->base.info.fmt, 1); 
    8383 
    8484    /* Create buffers.  
     
    8787     */ 
    8888    rport->get_buf = (pj_int16_t*) 
    89                      pj_pool_alloc(pool, dn_port->info.bytes_per_frame); 
     89                     pj_pool_alloc(pool, PJMEDIA_PIA_AVG_FSZ(&dn_port->info)); 
    9090    PJ_ASSERT_RETURN(rport->get_buf != NULL, PJ_ENOMEM); 
    9191 
    9292    rport->put_buf = (pj_int16_t*) 
    93                      pj_pool_alloc(pool, dn_port->info.bytes_per_frame); 
     93                     pj_pool_alloc(pool, PJMEDIA_PIA_AVG_FSZ(&dn_port->info)); 
    9494    PJ_ASSERT_RETURN(rport->put_buf != NULL, PJ_ENOMEM); 
    9595 
     
    9999                                     (opt&PJMEDIA_RESAMPLE_USE_LINEAR)==0, 
    100100                                     (opt&PJMEDIA_RESAMPLE_USE_SMALL_FILTER)==0, 
    101                                      dn_port->info.channel_count, 
    102                                      dn_port->info.clock_rate,  
    103                                      rport->base.info.clock_rate, 
    104                                      dn_port->info.samples_per_frame,  
     101                                     d_afd->channel_count, 
     102                                     d_afd->clock_rate, 
     103                                     r_afd->clock_rate, 
     104                                     PJMEDIA_PIA_SPF(&dn_port->info), 
    105105                                     &rport->resample_get); 
    106106    if (status != PJ_SUCCESS) 
     
    111111                                     (opt&PJMEDIA_RESAMPLE_USE_LINEAR)==0,  
    112112                                     (opt&PJMEDIA_RESAMPLE_USE_SMALL_FILTER)==0, 
    113                                      dn_port->info.channel_count, 
    114                                      rport->base.info.clock_rate,  
    115                                      dn_port->info.clock_rate, 
    116                                      rport->base.info.samples_per_frame, 
     113                                     d_afd->channel_count, 
     114                                     r_afd->clock_rate, 
     115                                     d_afd->clock_rate, 
     116                                     PJMEDIA_PIA_SPF(&rport->base.info), 
    117117                                     &rport->resample_put); 
    118118 
     
    132132 
    133133static pj_status_t resample_put_frame(pjmedia_port *this_port, 
    134                                       const pjmedia_frame *frame) 
     134                                      pjmedia_frame *frame) 
    135135{ 
    136136    struct resample_port *rport = (struct resample_port*) this_port; 
     
    148148 
    149149        downstream_frame.buf = rport->put_buf; 
    150         downstream_frame.size = rport->dn_port->info.bytes_per_frame; 
     150        downstream_frame.size = PJMEDIA_PIA_AVG_FSZ(&rport->dn_port->info); 
    151151    } else { 
    152152        downstream_frame.buf = frame->buf; 
     
    176176 
    177177    tmp_frame.buf = rport->get_buf; 
    178     tmp_frame.size = rport->dn_port->info.bytes_per_frame; 
     178    tmp_frame.size = PJMEDIA_PIA_AVG_FSZ(&rport->dn_port->info); 
    179179    tmp_frame.timestamp.u64 = frame->timestamp.u64; 
    180180    tmp_frame.type = PJMEDIA_FRAME_TYPE_AUDIO; 
     
    188188        frame->timestamp = tmp_frame.timestamp; 
    189189        /* Copy whatever returned as long as the buffer size is enough */ 
    190         frame->size = tmp_frame.size < rport->base.info.bytes_per_frame ? 
    191                       tmp_frame.size : rport->base.info.bytes_per_frame; 
     190        frame->size = tmp_frame.size < PJMEDIA_PIA_AVG_FSZ(&rport->base.info) ? 
     191                      tmp_frame.size : PJMEDIA_PIA_AVG_FSZ(&rport->base.info); 
    192192        if (tmp_frame.size) { 
    193193            pjmedia_copy_samples((pj_int16_t*)frame->buf,  
     
    202202                          (pj_int16_t*) frame->buf); 
    203203 
    204     frame->size = rport->base.info.bytes_per_frame; 
     204    frame->size = PJMEDIA_PIA_AVG_FSZ(&rport->base.info); 
    205205    frame->type = PJMEDIA_FRAME_TYPE_AUDIO; 
    206206 
Note: See TracChangeset for help on using the changeset viewer.