Ticket #468: ticket468.patch

File ticket468.patch, 2.7 KB (added by nanang, 17 years ago)
  • pjmedia/include/pjmedia/mem_port.h

     
    3838 * situation where filesystems are not available in the target system. 
    3939 */ 
    4040 
     41 
    4142/** 
     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. 
     50     */ 
     51    PJMEDIA_MEM_NO_LOOP = 1 
     52}; 
     53 
     54 
     55/** 
    4256 * Create the buffer based playback to play the media from the specified 
    4357 * buffer. 
    4458 * 
  • pjmedia/src/pjmedia/mem_player.c

     
    146146    player = (struct mem_player*) this_port; 
    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. 
     157         */ 
     158        if ((status != PJ_SUCCESS) || (player->options & PJMEDIA_MEM_NO_LOOP)) { 
     159            frame->type = PJMEDIA_FRAME_TYPE_NONE; 
     160            return PJ_EEOF; 
     161        } 
     162         
     163        player->eof = PJ_FALSE; 
    151164    } 
    152165 
    153166    size_needed = this_port->info.bytes_per_frame; 
     
    169182        pj_assert(player->read_pos <= endpos); 
    170183 
    171184        if (player->read_pos == endpos) { 
     185            /* Set EOF flag */ 
     186            player->eof = PJ_TRUE; 
     187            /* Reset read pointer */ 
    172188            player->read_pos = player->buffer; 
    173189 
    174             /* Call callback, if any */ 
    175             if (player->cb) { 
    176                 pj_status_t status; 
     190            /* Pad with zeroes then return for no looped play */ 
     191            if (player->options & PJMEDIA_MEM_NO_LOOP) { 
     192                pj_size_t null_len; 
    177193 
    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; 
     194                null_len = size_needed - size_written; 
     195                pj_bzero(dst + max, null_len); 
     196                break; 
    190197            } 
    191198        } 
    192199    } 
     
    203210 
    204211static pj_status_t mem_on_destroy(pjmedia_port *this_port) 
    205212{ 
    206     /* Nothing to do */ 
    207     PJ_UNUSED_ARG(this_port); 
     213    PJ_ASSERT_RETURN(this_port->info.signature == SIGNATURE, 
     214                     PJ_EINVALIDOP); 
     215 
     216    /* Destroy signature */ 
     217    this_port->info.signature = 0; 
     218 
    208219    return PJ_SUCCESS; 
    209220} 
    210221