Ignore:
Timestamp:
Jun 20, 2006 3:39:07 PM (18 years ago)
Author:
bennylp
Message:

Yet again large diffs because of documentation/doxygen update

File:
1 edited

Legend:

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

    r518 r531  
    3131 
    3232 
    33 #define SIGNATURE           ('F'<<24|'P'<<16|'L'<<8|'Y') 
     33#define SIGNATURE           PJMEDIA_PORT_SIGNATURE('F', 'P', 'l', 'y') 
    3434#define BYTES_PER_SAMPLE    2 
    3535 
     
    6666    pj_oshandle_t    fd; 
    6767 
     68    pj_status_t    (*cb)(pjmedia_port*, void*); 
    6869}; 
    6970 
     
    117118    pj_status_t status; 
    118119 
    119     if (fport->eof) { 
     120    /* Can't read file if EOF and loop flag is disabled */ 
     121    if (fport->eof) 
    120122        return PJ_EEOF; 
    121     } 
    122123 
    123124    while (size_left > 0) { 
     
    142143         */ 
    143144        if (size < (pj_ssize_t)size_to_read) { 
     145            /* Call callback, if any. */ 
     146            if (fport->cb) { 
     147                PJ_LOG(5,(THIS_FILE,  
     148                          "File port %.*s EOF, calling callback", 
     149                          (int)fport->base.info.name.slen, 
     150                          fport->base.info.name.ptr)); 
     151 
     152                fport->eof = PJ_TRUE; 
     153                status = (*fport->cb)(&fport->base, fport->base.user_data); 
     154                if (status != PJ_SUCCESS) { 
     155                    /* This will crash if file port is destroyed in the  
     156                     * callback, that's why we set the eof flag before 
     157                     * calling the callback: 
     158                     fport->eof = PJ_TRUE; 
     159                    */ 
     160                    return status; 
     161                } 
     162                 
     163                fport->eof = PJ_FALSE; 
     164            } 
     165 
    144166            if (fport->options & PJMEDIA_FILE_NO_LOOP) { 
    145167                PJ_LOG(5,(THIS_FILE, "File port %.*s EOF, stopping..", 
     
    336358 */ 
    337359PJ_DEF(pj_status_t) pjmedia_wav_player_port_set_pos(pjmedia_port *port, 
    338                                                     pj_uint32_t samples ) 
     360                                                    pj_uint32_t bytes ) 
    339361{ 
    340362    struct file_port *fport; 
    341363 
    342     PJ_ASSERT_RETURN(port, PJ_EINVAL); 
     364    /* Sanity check */ 
     365    PJ_ASSERT_RETURN(port, -PJ_EINVAL); 
     366 
     367    /* Check that this is really a player port */ 
     368    PJ_ASSERT_RETURN(port->info.signature == SIGNATURE, -PJ_EINVALIDOP); 
     369 
    343370 
    344371    fport = (struct file_port*) port; 
    345372 
    346     PJ_ASSERT_RETURN(samples*BYTES_PER_SAMPLE < fport->fsize - 
    347                       sizeof(pjmedia_wave_hdr), PJ_EINVAL); 
    348  
    349     fport->fpos = sizeof(struct pjmedia_wave_hdr) +  
    350                     samples * BYTES_PER_SAMPLE; 
     373    PJ_ASSERT_RETURN(bytes < fport->fsize - sizeof(pjmedia_wave_hdr),  
     374                     PJ_EINVAL); 
     375 
     376    fport->fpos = sizeof(struct pjmedia_wave_hdr) + bytes; 
    351377    pj_file_setpos( fport->fd, fport->fpos, PJ_SEEK_SET); 
    352378 
    353379    fport->eof = PJ_FALSE; 
    354380    return fill_buffer(fport); 
     381} 
     382 
     383 
     384/* 
     385 * Get the file play position of WAV player. 
     386 */ 
     387PJ_DEF(pj_ssize_t) pjmedia_wav_player_port_get_pos( pjmedia_port *port ) 
     388{ 
     389    struct file_port *fport; 
     390    pj_size_t payload_pos; 
     391 
     392    /* Sanity check */ 
     393    PJ_ASSERT_RETURN(port, -PJ_EINVAL); 
     394 
     395    /* Check that this is really a player port */ 
     396    PJ_ASSERT_RETURN(port->info.signature == SIGNATURE, -PJ_EINVALIDOP); 
     397 
     398    fport = (struct file_port*) port; 
     399 
     400    payload_pos = (pj_size_t)(fport->fpos - sizeof(pjmedia_wave_hdr)); 
     401    if (payload_pos >= fport->bufsize) 
     402        return payload_pos - fport->bufsize + (fport->readpos - fport->buf); 
     403    else 
     404        return (fport->readpos - fport->buf) % payload_pos; 
     405} 
     406 
     407 
     408 
     409/* 
     410 * Register a callback to be called when the file reading has reached the 
     411 * end of file. 
     412 */ 
     413PJ_DEF(pj_status_t)  
     414pjmedia_wav_player_set_eof_cb( pjmedia_port *port, 
     415                               void *user_data, 
     416                               pj_status_t (*cb)(pjmedia_port *port, 
     417                                                 void *usr_data)) 
     418{ 
     419    struct file_port *fport; 
     420 
     421    /* Sanity check */ 
     422    PJ_ASSERT_RETURN(port, -PJ_EINVAL); 
     423 
     424    /* Check that this is really a player port */ 
     425    PJ_ASSERT_RETURN(port->info.signature == SIGNATURE, -PJ_EINVALIDOP); 
     426 
     427    fport = (struct file_port*) port; 
     428 
     429    fport->base.user_data = user_data; 
     430    fport->cb = cb; 
     431 
     432    return PJ_SUCCESS; 
    355433} 
    356434 
Note: See TracChangeset for help on using the changeset viewer.