Changeset 704 for pjproject/trunk
- Timestamp:
- Sep 11, 2006 7:55:41 PM (18 years ago)
- Location:
- pjproject/trunk/pjmedia
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjmedia/include/pjmedia/mem_port.h
r532 r704 71 71 72 72 /** 73 * Register a callback to be called when the buffer reading has reached the 74 * end of buffer. If the player is set to play repeatedly, then the callback 75 * will be called multiple times. Note that only one callback can be 76 * registered for each player port. 77 * 78 * @param port The memory player port. 79 * @param user_data User data to be specified in the callback 80 * @param cb Callback to be called. If the callback returns non- 81 * PJ_SUCCESS, the playback will stop. Note that if 82 * application destroys the player port in the callback, 83 * it must return non-PJ_SUCCESS here. 84 * 85 * @return PJ_SUCCESS on success. 86 */ 87 PJ_DECL(pj_status_t) 88 pjmedia_mem_player_set_eof_cb( pjmedia_port *port, 89 void *user_data, 90 pj_status_t (*cb)(pjmedia_port *port, 91 void *usr_data)); 92 93 94 /** 73 95 * @} 74 96 */ -
pjproject/trunk/pjmedia/src/pjmedia/mem_player.c
r633 r704 38 38 pj_size_t buf_size; 39 39 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 40 46 }; 41 47 … … 95 101 96 102 103 104 /* 105 * Register a callback to be called when the file reading has reached the 106 * end of buffer. 107 */ 108 PJ_DEF(pj_status_t) 109 pjmedia_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 97 127 static pj_status_t mem_put_frame( pjmedia_port *this_port, 98 128 const pjmedia_frame *frame) … … 116 146 117 147 player = (struct mem_player*) this_port; 148 149 if (player->eof) { 150 frame->type = PJMEDIA_FRAME_TYPE_NONE; 151 return PJ_EEOF; 152 } 118 153 119 154 size_needed = this_port->info.bytes_per_frame; … … 135 170 pj_assert(player->read_pos <= endpos); 136 171 137 if (player->read_pos == endpos) 172 if (player->read_pos == endpos) { 138 173 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 } 139 193 } 140 141 player->timestamp.u64 += this_port->info.samples_per_frame;142 194 143 195 frame->size = this_port->info.bytes_per_frame; … … 145 197 frame->type = PJMEDIA_FRAME_TYPE_AUDIO; 146 198 199 player->timestamp.u64 += this_port->info.samples_per_frame; 200 147 201 return PJ_SUCCESS; 148 202 }
Note: See TracChangeset
for help on using the changeset viewer.