Changeset 6112 for pjproject/trunk/pjmedia/src/pjmedia/mem_capture.c
- Timestamp:
- Nov 29, 2019 4:21:17 AM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjmedia/src/pjmedia/mem_capture.c
r3664 r6112 21 21 #include <pj/assert.h> 22 22 #include <pj/errno.h> 23 #include <pj/log.h> 23 24 #include <pj/pool.h> 24 25 … … 43 44 pj_status_t (*cb)(pjmedia_port *port, 44 45 void *user_data); 46 pj_bool_t subscribed; 47 void (*cb2)(pjmedia_port*, void*); 45 48 }; 46 49 … … 102 105 103 106 107 #if !DEPRECATED_FOR_TICKET_2251 104 108 /* 105 109 * Register a callback to be called when the file reading has reached the … … 116 120 PJ_EINVALIDOP); 117 121 122 PJ_LOG(1, (THIS_FILE, "pjmedia_mem_capture_set_eof_cb() is deprecated. " 123 "Use pjmedia_mem_capture_set_eof_cb2() instead.")); 124 118 125 rec = (struct mem_rec*) port; 119 126 rec->user_data = user_data; … … 121 128 122 129 return PJ_SUCCESS; 130 } 131 #endif 132 133 134 /* 135 * Register a callback to be called when the file reading has reached the 136 * end of buffer. 137 */ 138 PJ_DEF(pj_status_t) pjmedia_mem_capture_set_eof_cb2( pjmedia_port *port, 139 void *user_data, 140 void (*cb)(pjmedia_port *port, 141 void *usr_data)) 142 { 143 struct mem_rec *rec; 144 145 PJ_ASSERT_RETURN(port->info.signature == SIGNATURE, 146 PJ_EINVALIDOP); 147 148 rec = (struct mem_rec*) port; 149 rec->user_data = user_data; 150 rec->cb2 = cb; 151 152 return PJ_SUCCESS; 123 153 } 124 154 … … 137 167 } 138 168 return rec->write_pos - rec->buffer; 169 } 170 171 172 static pj_status_t rec_on_event(pjmedia_event *event, 173 void *user_data) 174 { 175 struct mem_rec *rec = (struct mem_rec *)user_data; 176 177 if (event->type == PJMEDIA_EVENT_CALLBACK) { 178 if (rec->cb2) 179 (*rec->cb2)(&rec->base, rec->base.port_data.pdata); 180 } 181 182 return PJ_SUCCESS; 139 183 } 140 184 … … 178 222 179 223 /* Call callback, if any */ 180 if (rec->cb) { 224 if (rec->cb2) { 225 if (!rec->subscribed) { 226 pj_status_t status; 227 228 status = pjmedia_event_subscribe(NULL, rec_on_event, 229 rec, rec); 230 rec->subscribed = (status == PJ_SUCCESS)? PJ_TRUE: 231 PJ_FALSE; 232 } 233 234 if (rec->subscribed) { 235 pjmedia_event event; 236 237 pjmedia_event_init(&event, PJMEDIA_EVENT_CALLBACK, 238 NULL, rec); 239 pjmedia_event_publish(NULL, rec, &event, 240 PJMEDIA_EVENT_PUBLISH_POST_EVENT); 241 } 242 243 return PJ_SUCCESS; 244 245 } else if (rec->cb) { 181 246 pj_status_t status; 182 247 … … 225 290 rec = (struct mem_rec*) this_port; 226 291 292 if (rec->subscribed) { 293 pjmedia_event_unsubscribe(NULL, &rec_on_event, rec, rec); 294 rec->subscribed = PJ_FALSE; 295 } 296 227 297 if(rec->cb && PJ_FALSE == rec->eof) { 228 298 rec->eof = PJ_TRUE;
Note: See TracChangeset
for help on using the changeset viewer.