Ticket #468: mem_player.patch
File mem_player.patch, 2.5 KB (added by nanang, 17 years ago) |
---|
-
pjmedia/include/pjmedia/mem_port.h
39 39 */ 40 40 41 41 /** 42 * Memory player options. 43 */ 44 enum pjmedia_mem_player_option 45 { 46 /** 47 * Tell the memory player to return NULL frame when the whole 48 * buffer has been played. 49 */ 50 PJMEDIA_MEM_NO_LOOP = 1 51 }; 52 53 /** 42 54 * Create the buffer based playback to play the media from the specified 43 55 * buffer. 44 56 * -
pjmedia/src/pjmedia/mem_player.c
146 146 player = (struct mem_player*) this_port; 147 147 148 148 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->read_pos = player->buffer; 164 player->eof = PJ_FALSE; 151 165 } 152 166 153 167 size_needed = this_port->info.bytes_per_frame; … … 169 183 pj_assert(player->read_pos <= endpos); 170 184 171 185 if (player->read_pos == endpos) { 172 p layer->read_pos = player->buffer;186 pj_size_t null_len; 173 187 174 /* Call callback, if any */ 175 if (player->cb) { 176 pj_status_t status; 188 player->eof = PJ_TRUE; 177 189 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; 190 } 190 null_len = size_needed - size_written; 191 pj_bzero(dst + max, null_len); 192 break; 191 193 } 192 194 } 193 195 … … 203 205 204 206 static pj_status_t mem_on_destroy(pjmedia_port *this_port) 205 207 { 206 /* Nothing to do */ 207 PJ_UNUSED_ARG(this_port); 208 PJ_ASSERT_RETURN(this_port->info.signature == SIGNATURE, 209 PJ_EINVALIDOP); 210 211 this_port->info.signature = 0; 212 208 213 return PJ_SUCCESS; 209 214 } 210 215