Changeset 1808


Ignore:
Timestamp:
Feb 21, 2008 8:51:37 AM (12 years ago)
Author:
bennylp
Message:

Ticket #468: Added support for non looping playback in memory player

Location:
pjproject/trunk/pjmedia
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjmedia/include/pjmedia/mem_port.h

    r974 r1808  
    3939 */ 
    4040 
     41 
     42/** 
     43 * Memory player options. 
     44 */ 
     45enum pjmedia_mem_player_option 
     46{ 
     47    /** 
     48     * Tell the memory player to return NULL frame when the whole 
     49     * buffer has been played instead of rewinding the buffer back 
     50     * to start position. 
     51     */ 
     52    PJMEDIA_MEM_NO_LOOP = 1 
     53}; 
     54 
     55 
    4156/** 
    4257 * Create the buffer based playback to play the media from the specified 
     
    5368 * @param samples_per_frame Number of samples per frame. 
    5469 * @param bits_per_sample   Number of bits per sample. 
    55  * @param options           Option flags. 
     70 * @param options           Option flags, see #pjmedia_mem_player_option 
    5671 * @param p_port            Pointer to receive the port instance. 
    5772 * 
  • pjproject/trunk/pjmedia/src/pjmedia/mem_player.c

    r1417 r1808  
    147147 
    148148    if (player->eof) { 
    149         frame->type = PJMEDIA_FRAME_TYPE_NONE; 
    150         return PJ_EEOF; 
     149        pj_status_t status = PJ_SUCCESS; 
     150 
     151        /* Call callback, if any */ 
     152        if (player->cb) 
     153            status = (*player->cb)(this_port, player->user_data); 
     154 
     155        /* If callback returns non PJ_SUCCESS or 'no loop' is specified 
     156         * return immediately (and don't try to access player port since 
     157         * it might have been destroyed by the callback). 
     158         */ 
     159        if ((status != PJ_SUCCESS) || (player->options & PJMEDIA_MEM_NO_LOOP)) { 
     160            frame->type = PJMEDIA_FRAME_TYPE_NONE; 
     161            return PJ_EEOF; 
     162        } 
     163         
     164        player->eof = PJ_FALSE; 
    151165    } 
    152166 
     
    170184 
    171185        if (player->read_pos == endpos) { 
     186            /* Set EOF flag */ 
     187            player->eof = PJ_TRUE; 
     188            /* Reset read pointer */ 
    172189            player->read_pos = player->buffer; 
    173190 
    174             /* Call callback, if any */ 
    175             if (player->cb) { 
    176                 pj_status_t status; 
    177  
    178                 player->eof = PJ_TRUE; 
    179                 status = (*player->cb)(this_port, player->user_data); 
    180                 if (status != PJ_SUCCESS) { 
    181                     /* Must not access player from here on. It may be 
    182                      * destroyed by application. 
    183                      */ 
    184                     frame->size = size_written; 
    185                     frame->timestamp.u64 = player->timestamp.u64; 
    186                     frame->type = PJMEDIA_FRAME_TYPE_AUDIO; 
    187                     return status; 
    188                 } 
    189                 player->eof = PJ_FALSE; 
     191            /* Pad with zeroes then return for no looped play */ 
     192            if (player->options & PJMEDIA_MEM_NO_LOOP) { 
     193                pj_size_t null_len; 
     194 
     195                null_len = size_needed - size_written; 
     196                pj_bzero(dst + max, null_len); 
     197                break; 
    190198            } 
    191199        } 
     
    204212static pj_status_t mem_on_destroy(pjmedia_port *this_port) 
    205213{ 
    206     /* Nothing to do */ 
    207     PJ_UNUSED_ARG(this_port); 
    208     return PJ_SUCCESS; 
    209 } 
    210  
    211  
     214    PJ_ASSERT_RETURN(this_port->info.signature == SIGNATURE, 
     215                     PJ_EINVALIDOP); 
     216 
     217    /* Destroy signature */ 
     218    this_port->info.signature = 0; 
     219 
     220    return PJ_SUCCESS; 
     221} 
     222 
     223 
Note: See TracChangeset for help on using the changeset viewer.