Changeset 706 for pjproject/trunk
- Timestamp:
- Sep 12, 2006 11:33:22 AM (18 years ago)
- Location:
- pjproject/trunk/pjmedia
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjmedia/include/pjmedia/mem_port.h
r704 r706 135 135 136 136 /** 137 * Register a callback to be called when no space left in the buffer. 138 * Note that when a callback is registered, this callback will also be 139 * called when application destroys the port and the callback has not 140 * been called before. 141 * 142 * @param port The memory recorder port. 143 * @param user_data User data to be specified in the callback 144 * @param cb Callback to be called. If the callback returns non- 145 * PJ_SUCCESS, the recording will stop. In other cases 146 * recording will be restarted and the rest of the frame 147 * will be stored starting from the beginning of the 148 * buffer. Note that if application destroys the capture 149 * port in the callback, it must return non-PJ_SUCCESS 150 * here. 151 * 152 * @return PJ_SUCCESS on success. 153 */ 154 PJ_DECL(pj_status_t) 155 pjmedia_mem_capture_set_eof_cb(pjmedia_port *port, 156 void *user_data, 157 pj_status_t (*cb)(pjmedia_port *port, 158 void *usr_data)); 159 160 /** 161 * Return the current size of the recorded data in the buffer. 162 * 163 * @param port The memory recorder port. 164 * @return The size of buffer data.. 165 */ 166 PJ_DECL(pj_size_t) 167 pjmedia_mem_capture_get_size(pjmedia_port *port); 168 169 170 /** 137 171 * @} 138 172 */ -
pjproject/trunk/pjmedia/src/pjmedia/mem_capture.c
r633 r706 37 37 pj_size_t buf_size; 38 38 char *write_pos; 39 40 pj_bool_t eof; 41 void *user_data; 42 pj_status_t (*cb)(pjmedia_port *port, 43 void *user_data); 39 44 }; 40 45 … … 96 101 97 102 103 /* 104 * Register a callback to be called when the file reading has reached the 105 * end of buffer. 106 */ 107 PJ_DEF(pj_status_t) 108 pjmedia_mem_capture_set_eof_cb( pjmedia_port *port, 109 void *user_data, 110 pj_status_t (*cb)(pjmedia_port *port, 111 void *usr_data)) 112 { 113 struct mem_rec *rec; 114 115 PJ_ASSERT_RETURN(port->info.signature == SIGNATURE, 116 PJ_EINVALIDOP); 117 118 rec = (struct mem_rec*) port; 119 rec->user_data = user_data; 120 rec->cb = cb; 121 122 return PJ_SUCCESS; 123 } 124 125 126 /* Get current buffer size */ 127 PJ_DEF(pj_size_t) pjmedia_mem_capture_get_size(pjmedia_port *port) 128 { 129 struct mem_rec *rec; 130 131 PJ_ASSERT_RETURN(port->info.signature == SIGNATURE, 132 0); 133 134 rec = (struct mem_rec*) port; 135 if (rec->eof){ 136 return rec->buf_size; 137 } 138 return rec->write_pos - rec->buffer; 139 } 140 141 98 142 static pj_status_t rec_put_frame( pjmedia_port *this_port, 99 143 const pjmedia_frame *frame) … … 108 152 rec = (struct mem_rec*) this_port; 109 153 154 if (rec->eof) { 155 return PJ_EEOF; 156 } 157 110 158 size_written = 0; 111 159 endpos = rec->buffer + rec->buf_size; … … 113 161 while (size_written < frame->size) { 114 162 pj_size_t max; 115 163 116 164 max = frame->size - size_written; 117 165 if ((endpos - rec->write_pos) < (int)max) 118 166 max = endpos - rec->write_pos; 119 167 120 168 pj_memcpy(rec->write_pos, ((char*)frame->buf)+size_written, max); 121 169 size_written += max; 122 170 rec->write_pos += max; 123 171 124 172 pj_assert(rec->write_pos <= endpos); 125 126 if (rec->write_pos == endpos) 173 174 if (rec->write_pos == endpos) { 175 176 /* Rewind */ 127 177 rec->write_pos = rec->buffer; 128 } 178 179 /* Call callback, if any */ 180 if (rec->cb) { 181 pj_status_t status; 182 183 rec->eof = PJ_TRUE; 184 status = (*rec->cb)(this_port, rec->user_data); 185 if (status != PJ_SUCCESS) { 186 /* Must not access recorder from here on. It may be 187 * destroyed by application. 188 */ 189 return status; 190 } 191 rec->eof = PJ_FALSE; 192 } 193 } 194 } 195 129 196 return PJ_SUCCESS; 130 197 } … … 148 215 static pj_status_t rec_on_destroy(pjmedia_port *this_port) 149 216 { 150 /* Nothing to do */ 151 PJ_UNUSED_ARG(this_port); 152 return PJ_SUCCESS; 153 } 154 155 156 217 /* Call callback if data was captured 218 * and we're not in the callback already. 219 */ 220 struct mem_rec *rec; 221 222 PJ_ASSERT_RETURN(this_port->info.signature == SIGNATURE, 223 PJ_EINVALIDOP); 224 225 rec = (struct mem_rec*) this_port; 226 227 if(rec->cb && PJ_FALSE == rec->eof) { 228 rec->eof = PJ_TRUE; 229 (*rec->cb)(this_port, rec->user_data); 230 } 231 232 return PJ_SUCCESS; 233 } 234 235
Note: See TracChangeset
for help on using the changeset viewer.