Ticket #468: ticket468.patch
File ticket468.patch, 2.7 KB (added by nanang, 17 years ago) |
---|
-
pjmedia/include/pjmedia/mem_port.h
38 38 * situation where filesystems are not available in the target system. 39 39 */ 40 40 41 41 42 /** 43 * Memory player options. 44 */ 45 enum 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 /** 42 56 * Create the buffer based playback to play the media from the specified 43 57 * buffer. 44 58 * -
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->eof = PJ_FALSE; 151 164 } 152 165 153 166 size_needed = this_port->info.bytes_per_frame; … … 169 182 pj_assert(player->read_pos <= endpos); 170 183 171 184 if (player->read_pos == endpos) { 185 /* Set EOF flag */ 186 player->eof = PJ_TRUE; 187 /* Reset read pointer */ 172 188 player->read_pos = player->buffer; 173 189 174 /* Call callback, if any */175 if (player-> cb) {176 pj_s tatus_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; 177 193 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; 190 197 } 191 198 } 192 199 } … … 203 210 204 211 static pj_status_t mem_on_destroy(pjmedia_port *this_port) 205 212 { 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 208 219 return PJ_SUCCESS; 209 220 } 210 221