- Timestamp:
- Jun 12, 2006 10:13:31 AM (18 years ago)
- Location:
- pjproject/trunk/pjmedia
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjmedia/include/pjmedia/master_port.h
r404 r498 53 53 * @param u_port Upstream port. 54 54 * @param d_port Downstream port. 55 * @param options Options flags .55 * @param options Options flags, bitmask from #pjmedia_master_port_flag. 56 56 * @param p_m Pointer to receive the master port instance. 57 57 * … … 65 65 66 66 67 68 67 /** 69 68 * Start the media flow. … … 74 73 */ 75 74 PJ_DECL(pj_status_t) pjmedia_master_port_start(pjmedia_master_port *m); 76 77 75 78 76 … … 88 86 89 87 /** 88 * Change the upstream port. Note that application is responsible to destroy 89 * current upstream port (the one that is going to be replaced with the 90 * new port). 91 * 92 * @param m The master port. 93 * @param port Port to be used for upstream port. 94 * 95 * @return PJ_SUCCESS on success. 96 */ 97 PJ_DECL(pj_status_t) pjmedia_master_port_set_uport(pjmedia_master_port *m, 98 pjmedia_port *port); 99 100 101 /** 102 * Get the upstream port. 103 * 104 * @param m The master port. 105 * 106 * @return The upstream port. 107 */ 108 PJ_DECL(pjmedia_port*) pjmedia_master_port_get_uport(pjmedia_master_port*m); 109 110 111 /** 112 * Change the downstream port. Note that application is responsible to destroy 113 * current downstream port (the one that is going to be replaced with the 114 * new port). 115 * 116 * @param m The master port. 117 * @param port Port to be used for downstream port. 118 * 119 * @return PJ_SUCCESS on success. 120 */ 121 PJ_DECL(pj_status_t) pjmedia_master_port_set_dport(pjmedia_master_port *m, 122 pjmedia_port *port); 123 124 125 /** 126 * Get the downstream port. 127 * 128 * @param m The master port. 129 * 130 * @return The downstream port. 131 */ 132 PJ_DECL(pjmedia_port*) pjmedia_master_port_get_dport(pjmedia_master_port*m); 133 134 135 /** 90 136 * Destroy the master port, and optionally destroy the upstream and 91 137 * downstream ports. 92 138 * 93 139 * @param m The master port. 140 * @param destroy_ports If non-zero, the function will destroy both 141 * upstream and downstream ports too. 94 142 * 95 143 * @return PJ_SUCCESS on success. 96 144 */ 97 PJ_DECL(pj_status_t) pjmedia_master_port_destroy(pjmedia_master_port *m); 145 PJ_DECL(pj_status_t) pjmedia_master_port_destroy(pjmedia_master_port *m, 146 pj_bool_t destroy_ports); 98 147 99 148 -
pjproject/trunk/pjmedia/src/pjmedia/clock_thread.c
r404 r498 20 20 #include <pjmedia/errno.h> 21 21 #include <pj/assert.h> 22 #include <pj/lock.h> 22 23 #include <pj/os.h> 23 24 #include <pj/pool.h> … … 42 43 pj_bool_t running; 43 44 pj_bool_t quitting; 45 pj_lock_t *lock; 44 46 }; 45 47 … … 83 85 clock->quitting = PJ_FALSE; 84 86 87 /* I don't think we need a mutex, so we'll use null. */ 88 status = pj_lock_create_null_mutex(pool, "clock", &clock->lock); 89 if (status != PJ_SUCCESS) 90 return status; 91 85 92 status = pj_thread_create(pool, "clock", &clock_thread, clock, 86 93 0, 0, &clock->thread); 87 if (status != PJ_SUCCESS) 88 return status; 94 if (status != PJ_SUCCESS) { 95 pj_lock_destroy(clock->lock); 96 return status; 97 } 89 98 90 99 … … 105 114 PJ_ASSERT_RETURN(clock != NULL, PJ_EINVAL); 106 115 116 if (clock->running) 117 return PJ_SUCCESS; 118 107 119 status = pj_get_timestamp(&now); 108 120 if (status != PJ_SUCCESS) 109 121 return status; 110 122 123 pj_lock_acquire(clock->lock); 111 124 clock->next_tick.u64 = now.u64 + clock->interval.u64; 112 125 clock->running = PJ_TRUE; 126 pj_lock_release(clock->lock); 113 127 114 128 return status; … … 206 220 continue; 207 221 222 pj_lock_acquire(clock->lock); 223 208 224 /* Call callback, if any */ 209 225 if (clock->cb) … … 216 232 clock->next_tick.u64 += clock->interval.u64; 217 233 218 234 pj_lock_release(clock->lock); 219 235 } 220 236 … … 239 255 } 240 256 257 if (clock->lock) { 258 pj_lock_destroy(clock->lock); 259 clock->lock = NULL; 260 } 261 241 262 return PJ_SUCCESS; 242 263 } 243 264 244 265 245 246 247 -
pjproject/trunk/pjmedia/src/pjmedia/master_port.c
r411 r498 21 21 #include <pjmedia/errno.h> 22 22 #include <pj/assert.h> 23 #include <pj/lock.h> 23 24 #include <pj/pool.h> 24 25 #include <pj/string.h> … … 33 34 unsigned buff_size; 34 35 void *buff; 36 pj_lock_t *lock; 35 37 }; 36 38 … … 91 93 return PJ_ENOMEM; 92 94 95 /* Create lock object */ 96 status = pj_lock_create_simple_mutex(pool, "mport", &m->lock); 97 if (status != PJ_SUCCESS) 98 return status; 93 99 94 100 /* Create media clock */ 95 101 status = pjmedia_clock_create(pool, clock_rate, samples_per_frame, 0, 96 102 &clock_callback, m, &m->clock); 97 if (status != PJ_SUCCESS) 103 if (status != PJ_SUCCESS) { 104 pj_lock_destroy(m->lock); 98 105 return status; 99 106 } 100 107 101 108 /* Done */ … … 116 123 return pjmedia_clock_start(m->clock); 117 124 } 118 119 125 120 126 … … 139 145 pj_status_t status; 140 146 147 148 /* Lock access to ports. */ 149 pj_lock_acquire(m->lock); 141 150 142 151 /* Get frame from upstream port and pass it to downstream port */ … … 163 172 164 173 status = pjmedia_port_put_frame(m->u_port, &frame); 174 175 /* Release lock */ 176 pj_lock_release(m->lock); 177 } 178 179 180 /* 181 * Change the upstream port. 182 */ 183 PJ_DEF(pj_status_t) pjmedia_master_port_set_uport(pjmedia_master_port *m, 184 pjmedia_port *port) 185 { 186 PJ_ASSERT_RETURN(m && port, PJ_EINVAL); 187 188 /* If we have downstream port, make sure they have matching samples per 189 * frame. 190 */ 191 if (m->d_port) { 192 PJ_ASSERT_RETURN( 193 port->info.clock_rate/port->info.samples_per_frame== 194 m->d_port->info.clock_rate/m->d_port->info.samples_per_frame, 195 PJMEDIA_ENCSAMPLESPFRAME 196 ); 197 } 198 199 pj_lock_acquire(m->lock); 200 201 m->u_port = port; 202 203 pj_lock_release(m->lock); 204 205 return PJ_SUCCESS; 206 } 207 208 209 /* 210 * Get the upstream port. 211 */ 212 PJ_DEF(pjmedia_port*) pjmedia_master_port_get_uport(pjmedia_master_port*m) 213 { 214 PJ_ASSERT_RETURN(m, NULL); 215 return m->u_port; 216 } 217 218 219 /* 220 * Change the downstream port. 221 */ 222 PJ_DEF(pj_status_t) pjmedia_master_port_set_dport(pjmedia_master_port *m, 223 pjmedia_port *port) 224 { 225 PJ_ASSERT_RETURN(m && port, PJ_EINVAL); 226 227 /* If we have upstream port, make sure they have matching samples per 228 * frame. 229 */ 230 if (m->u_port) { 231 PJ_ASSERT_RETURN( 232 port->info.clock_rate/port->info.samples_per_frame== 233 m->u_port->info.clock_rate/m->u_port->info.samples_per_frame, 234 PJMEDIA_ENCSAMPLESPFRAME 235 ); 236 } 237 238 pj_lock_acquire(m->lock); 239 240 m->d_port = port; 241 242 pj_lock_release(m->lock); 243 244 return PJ_SUCCESS; 245 } 246 247 248 /* 249 * Get the downstream port. 250 */ 251 PJ_DEF(pjmedia_port*) pjmedia_master_port_get_dport(pjmedia_master_port*m) 252 { 253 PJ_ASSERT_RETURN(m, NULL); 254 return m->d_port; 165 255 } 166 256 … … 170 260 * d_port ports. 171 261 */ 172 PJ_DEF(pj_status_t) pjmedia_master_port_destroy(pjmedia_master_port *m) 262 PJ_DEF(pj_status_t) pjmedia_master_port_destroy(pjmedia_master_port *m, 263 pj_bool_t destroy_ports) 173 264 { 174 265 PJ_ASSERT_RETURN(m, PJ_EINVAL); … … 179 270 } 180 271 181 if (m->u_port ) {272 if (m->u_port && destroy_ports) { 182 273 pjmedia_port_destroy(m->u_port); 183 274 m->u_port = NULL; 184 275 } 185 276 186 if (m->d_port ) {277 if (m->d_port && destroy_ports) { 187 278 pjmedia_port_destroy(m->d_port); 188 279 m->d_port = NULL; 189 280 } 190 281 191 return PJ_SUCCESS; 192 } 193 194 282 if (m->lock) { 283 pj_lock_destroy(m->lock); 284 m->lock = NULL; 285 } 286 287 return PJ_SUCCESS; 288 } 289 290
Note: See TracChangeset
for help on using the changeset viewer.