Ignore:
Timestamp:
Sep 11, 2006 7:55:41 PM (18 years ago)
Author:
bennylp
Message:

Added EOF callback in memory playback port.

File:
1 edited

Legend:

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

    r633 r704  
    3838    pj_size_t        buf_size; 
    3939    char            *read_pos; 
     40 
     41    pj_bool_t        eof; 
     42    void            *user_data; 
     43    pj_status_t    (*cb)(pjmedia_port *port, 
     44                         void *user_data); 
     45 
    4046}; 
    4147 
     
    95101 
    96102 
     103 
     104/* 
     105 * Register a callback to be called when the file reading has reached the 
     106 * end of buffer. 
     107 */ 
     108PJ_DEF(pj_status_t)  
     109pjmedia_mem_player_set_eof_cb( pjmedia_port *port, 
     110                               void *user_data, 
     111                               pj_status_t (*cb)(pjmedia_port *port, 
     112                                                 void *usr_data)) 
     113{ 
     114    struct mem_player *player; 
     115 
     116    PJ_ASSERT_RETURN(port->info.signature == SIGNATURE, 
     117                     PJ_EINVALIDOP); 
     118 
     119    player = (struct mem_player*) port; 
     120    player->user_data = user_data; 
     121    player->cb = cb; 
     122 
     123    return PJ_SUCCESS; 
     124} 
     125 
     126 
    97127static pj_status_t mem_put_frame( pjmedia_port *this_port,  
    98128                                  const pjmedia_frame *frame) 
     
    116146 
    117147    player = (struct mem_player*) this_port; 
     148 
     149    if (player->eof) { 
     150        frame->type = PJMEDIA_FRAME_TYPE_NONE; 
     151        return PJ_EEOF; 
     152    } 
    118153 
    119154    size_needed = this_port->info.bytes_per_frame; 
     
    135170        pj_assert(player->read_pos <= endpos); 
    136171 
    137         if (player->read_pos == endpos) 
     172        if (player->read_pos == endpos) { 
    138173            player->read_pos = player->buffer; 
     174 
     175            /* Call callback, if any */ 
     176            if (player->cb) { 
     177                pj_status_t status; 
     178 
     179                player->eof = PJ_TRUE; 
     180                status = (*player->cb)(this_port, player->user_data); 
     181                if (status != PJ_SUCCESS) { 
     182                    /* Must not access player from here on. It may be 
     183                     * destroyed by application. 
     184                     */ 
     185                    frame->size = size_written; 
     186                    frame->timestamp.u64 = player->timestamp.u64; 
     187                    frame->type = PJMEDIA_FRAME_TYPE_AUDIO; 
     188                    return status; 
     189                } 
     190                player->eof = PJ_FALSE; 
     191            } 
     192        } 
    139193    } 
    140  
    141     player->timestamp.u64 += this_port->info.samples_per_frame; 
    142194 
    143195    frame->size = this_port->info.bytes_per_frame; 
     
    145197    frame->type = PJMEDIA_FRAME_TYPE_AUDIO; 
    146198 
     199    player->timestamp.u64 += this_port->info.samples_per_frame; 
     200 
    147201    return PJ_SUCCESS; 
    148202} 
Note: See TracChangeset for help on using the changeset viewer.