Changeset 3615
- Timestamp:
- Jul 11, 2011 9:36:08 AM (13 years ago)
- Location:
- pjproject/branches/projects/2.0-dev/pjmedia
- Files:
-
- 1 edited
- 2 moved
Legend:
- Unmodified
- Added
- Removed
-
pjproject/branches/projects/2.0-dev/pjmedia/include/pjmedia.h
r3420 r3615 68 68 #include <pjmedia/transport_srtp.h> 69 69 #include <pjmedia/transport_udp.h> 70 #include <pjmedia/vid eoport.h>70 #include <pjmedia/vid_port.h> 71 71 #include <pjmedia/vid_codec.h> 72 72 #include <pjmedia/vid_stream.h> -
pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia/vid_port.c
r3614 r3615 17 17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 18 */ 19 #include <pjmedia/vid eoport.h>19 #include <pjmedia/vid_port.h> 20 20 #include <pjmedia/clock.h> 21 21 #include <pjmedia/converter.h> … … 25 25 #include <pj/pool.h> 26 26 27 #define THIS_FILE "vid eoport.c"27 #define THIS_FILE "vid_port.c" 28 28 29 29 typedef struct vid_pasv_port vid_pasv_port; … … 38 38 struct pjmedia_vid_port 39 39 { 40 pj_pool_t *pool; 41 pj_str_t dev_name; 42 pjmedia_dir dir; 43 pjmedia_rect_size cap_size; 44 pjmedia_vid_dev_stream *strm; 45 pjmedia_vid_cb strm_cb; 46 void *strm_cb_data; 47 enum role role, 48 stream_role; 49 vid_pasv_port *pasv_port; 50 pjmedia_port *client_port; 51 pj_bool_t destroy_client_port; 52 53 pjmedia_converter *cap_conv; 54 void *cap_conv_buf; 55 pj_size_t cap_conv_buf_size; 56 pjmedia_conversion_param cap_conv_param; 57 58 pjmedia_clock *enc_clock, 59 *dec_clock; 60 61 pjmedia_clock_src cap_clocksrc, 62 rend_clocksrc; 40 pj_pool_t *pool; 41 pj_str_t dev_name; 42 pjmedia_dir dir; 43 // pjmedia_rect_size cap_size; 44 pjmedia_vid_dev_stream *strm; 45 pjmedia_vid_cb strm_cb; 46 void *strm_cb_data; 47 enum role role, 48 stream_role; 49 vid_pasv_port *pasv_port; 50 pjmedia_port *client_port; 51 pj_bool_t destroy_client_port; 52 53 pjmedia_converter *conv; 54 void *conv_buf; 55 pj_size_t conv_buf_size; 56 pjmedia_conversion_param conv_param; 57 58 pjmedia_clock *clock; 59 60 pjmedia_clock_src clocksrc; 63 61 64 62 struct sync_clock_src_t … … 69 67 unsigned nsync_frame; 70 68 unsigned nsync_progress; 71 } cap_sync_clocksrc, rend_sync_clocksrc; 72 73 pjmedia_frame *enc_frm_buf, 74 *dec_frm_buf; 75 pj_size_t enc_frm_buf_size, 76 dec_frm_buf_size; 77 78 pj_mutex_t *enc_frm_mutex, 79 *dec_frm_mutex; 69 } sync_clocksrc; 70 71 pjmedia_frame *frm_buf; 72 pj_size_t frm_buf_size; 73 pj_mutex_t *frm_mutex; 80 74 }; 81 75 … … 119 113 case PJMEDIA_DIR_RENDER: 120 114 return "render"; 121 case PJMEDIA_DIR_CAPTURE_RENDER:122 return "capture and render";123 115 default: 124 116 return "??"; … … 132 124 pjmedia_vid_port *vp; 133 125 const pjmedia_video_format_detail *vfd; 134 char cap_dev_name[64], rend_dev_name[64];126 char dev_name[64]; 135 127 pjmedia_vid_cb vid_cb; 136 128 pj_bool_t need_frame_buf = PJ_FALSE; … … 138 130 unsigned ptime_usec; 139 131 pjmedia_vid_param vparam; 132 pjmedia_vid_dev_info di; 133 unsigned i; 140 134 141 135 PJ_ASSERT_RETURN(pool && prm && p_vid_port, PJ_EINVAL); … … 157 151 vp->role = prm->active ? ROLE_ACTIVE : ROLE_PASSIVE; 158 152 vp->dir = prm->vidparam.dir; 159 vp->cap_size = vfd->size;153 // vp->cap_size = vfd->size; 160 154 161 155 vparam = prm->vidparam; 162 cap_dev_name[0] = rend_dev_name[0] = '\0'; 163 164 if (vp->dir & PJMEDIA_DIR_CAPTURE) { 165 pjmedia_vid_dev_info di; 166 unsigned i; 167 168 /* Get device info */ 169 status = pjmedia_vid_dev_get_info(prm->vidparam.cap_id, &di); 170 if (status != PJ_SUCCESS) 171 return status; 172 173 pj_ansi_snprintf(cap_dev_name, sizeof(cap_dev_name), "%s [%s]", 174 di.name, di.driver); 175 176 for (i = 0; i < di.fmt_cnt; ++i) { 177 if (prm->vidparam.fmt.id == di.fmt[i].id) 178 break; 179 } 180 181 if (i == di.fmt_cnt) { 182 /* The device has no no matching format. Pick one from 183 * the supported formats, and later use converter to 184 * convert it to the required format. 185 */ 186 pj_assert(di.fmt_cnt != 0); 187 vparam.fmt.id = di.fmt[0].id; 188 } 189 190 pj_strdup2_with_null(pool, &vp->dev_name, di.name); 191 vp->stream_role = di.has_callback ? ROLE_ACTIVE : ROLE_PASSIVE; 192 } 193 194 if (vp->dir & PJMEDIA_DIR_RENDER) { 195 pjmedia_vid_dev_info di; 196 unsigned i; 197 198 /* Get device info */ 199 status = pjmedia_vid_dev_get_info(prm->vidparam.rend_id, &di); 200 if (status != PJ_SUCCESS) 201 return status; 202 203 pj_ansi_snprintf(rend_dev_name, sizeof(rend_dev_name), "and %s [%s]", 204 di.name, di.driver); 205 206 for (i = 0; i < di.fmt_cnt; ++i) { 207 if (prm->vidparam.fmt.id == di.fmt[i].id) 208 break; 209 } 210 211 if (i == di.fmt_cnt) { 212 /* The device has no no matching format. Pick one from 213 * the supported formats, and later use converter to 214 * convert it to the required format. 215 */ 216 pj_assert(di.fmt_cnt != 0); 217 vparam.fmt.id = di.fmt[0].id; 218 } 219 220 pj_strdup2_with_null(pool, &vp->dev_name, di.name); 221 vp->stream_role = di.has_callback ? ROLE_ACTIVE : ROLE_PASSIVE; 222 } 156 dev_name[0] = '\0'; 157 158 /* Get device info */ 159 if (vp->dir & PJMEDIA_DIR_CAPTURE) 160 status = pjmedia_vid_dev_get_info(prm->vidparam.cap_id, &di); 161 else 162 status = pjmedia_vid_dev_get_info(prm->vidparam.rend_id, &di); 163 if (status != PJ_SUCCESS) 164 return status; 165 166 pj_ansi_snprintf(dev_name, sizeof(dev_name), "%s [%s]", 167 di.name, di.driver); 168 169 for (i = 0; i < di.fmt_cnt; ++i) { 170 if (prm->vidparam.fmt.id == di.fmt[i].id) 171 break; 172 } 173 174 if (i == di.fmt_cnt) { 175 /* The device has no no matching format. Pick one from 176 * the supported formats, and later use converter to 177 * convert it to the required format. 178 */ 179 pj_assert(di.fmt_cnt != 0); 180 vparam.fmt.id = di.fmt[0].id; 181 } 182 183 pj_strdup2_with_null(pool, &vp->dev_name, di.name); 184 vp->stream_role = di.has_callback ? ROLE_ACTIVE : ROLE_PASSIVE; 223 185 224 186 PJ_LOG(4,(THIS_FILE, 225 "Opening device %s %sfor %s: format=%s, size=%dx%d @%d:%d fps",226 cap_dev_name, rend_dev_name,187 "Opening device %s for %s: format=%s, size=%dx%d @%d:%d fps", 188 dev_name, 227 189 vid_dir_name(prm->vidparam.dir), 228 190 pjmedia_get_video_format_info(NULL, vparam.fmt.id)->name, … … 231 193 232 194 ptime_usec = PJMEDIA_PTIME(&vfd->fps); 233 pjmedia_clock_src_init(&vp->c ap_clocksrc, PJMEDIA_TYPE_VIDEO,195 pjmedia_clock_src_init(&vp->clocksrc, PJMEDIA_TYPE_VIDEO, 234 196 prm->vidparam.clock_rate, ptime_usec); 235 pjmedia_clock_src_init(&vp->rend_clocksrc, PJMEDIA_TYPE_VIDEO, 236 prm->vidparam.clock_rate, ptime_usec); 237 vp->cap_sync_clocksrc.max_sync_ticks = 197 vp->sync_clocksrc.max_sync_ticks = 238 198 PJMEDIA_CLOCK_SYNC_MAX_RESYNC_DURATION * 239 1000 / vp->cap_clocksrc.ptime_usec; 240 vp->rend_sync_clocksrc.max_sync_ticks = 241 PJMEDIA_CLOCK_SYNC_MAX_RESYNC_DURATION * 242 1000 / vp->rend_clocksrc.ptime_usec; 199 1000 / vp->clocksrc.ptime_usec; 243 200 244 201 /* Create the video stream */ … … 254 211 255 212 PJ_LOG(4,(THIS_FILE, 256 "Device %s %sopened: format=%s, size=%dx%d @%d:%d fps",257 cap_dev_name, rend_dev_name,213 "Device %s opened: format=%s, size=%dx%d @%d:%d fps", 214 dev_name, 258 215 pjmedia_get_video_format_info(NULL, vparam.fmt.id)->name, 259 216 vparam.fmt.det.vid.size.w, vparam.fmt.det.vid.size.h, … … 261 218 262 219 if (vp->dir & PJMEDIA_DIR_CAPTURE) { 263 pjmedia_format_copy(&vp->c ap_conv_param.src, &vparam.fmt);264 pjmedia_format_copy(&vp->c ap_conv_param.dst, &prm->vidparam.fmt);220 pjmedia_format_copy(&vp->conv_param.src, &vparam.fmt); 221 pjmedia_format_copy(&vp->conv_param.dst, &prm->vidparam.fmt); 265 222 } else { 266 pjmedia_format_copy(&vp->c ap_conv_param.src, &prm->vidparam.fmt);267 pjmedia_format_copy(&vp->c ap_conv_param.dst, &vparam.fmt);223 pjmedia_format_copy(&vp->conv_param.src, &prm->vidparam.fmt); 224 pjmedia_format_copy(&vp->conv_param.dst, &vparam.fmt); 268 225 } 269 226 … … 279 236 pjmedia_video_apply_fmt_param vafp; 280 237 281 status = pjmedia_converter_create(NULL, pool, &vp->c ap_conv_param,282 &vp->c ap_conv);238 status = pjmedia_converter_create(NULL, pool, &vp->conv_param, 239 &vp->conv); 283 240 if (status != PJ_SUCCESS) { 284 241 PJ_PERROR(4,(THIS_FILE, status, "Error creating converter")); … … 287 244 288 245 /* Allocate buffer for conversion */ 289 vfi = pjmedia_get_video_format_info(NULL, vp->c ap_conv_param.dst.id);246 vfi = pjmedia_get_video_format_info(NULL, vp->conv_param.dst.id); 290 247 if (!vfi) 291 248 return PJMEDIA_EBADFMT; 292 249 293 250 pj_bzero(&vafp, sizeof(vafp)); 294 vafp.size = vp->c ap_conv_param.dst.det.vid.size;251 vafp.size = vp->conv_param.dst.det.vid.size; 295 252 status = vfi->apply_fmt(vfi, &vafp); 296 253 if (status != PJ_SUCCESS) 297 254 return PJMEDIA_EBADFMT; 298 255 299 vp->c ap_conv_buf = pj_pool_alloc(pool, vafp.framebytes);300 vp->c ap_conv_buf_size = vafp.framebytes;256 vp->conv_buf = pj_pool_alloc(pool, vafp.framebytes); 257 vp->conv_buf_size = vafp.framebytes; 301 258 } 302 259 303 260 if (vp->role==ROLE_ACTIVE && vp->stream_role==ROLE_PASSIVE) { 261 pjmedia_clock_param param; 262 304 263 /* Active role is wanted, but our device is passive, so create 305 264 * master clocks to run the media flow. 306 265 */ 307 266 need_frame_buf = PJ_TRUE; 308 309 if (vp->dir & PJMEDIA_DIR_ENCODING) {310 pjmedia_clock_param param;311 267 312 param.usec_interval = PJMEDIA_PTIME(&vfd->fps); 313 param.clock_rate = prm->vidparam.clock_rate; 314 status = pjmedia_clock_create2(pool, ¶m, 315 PJMEDIA_CLOCK_NO_HIGHEST_PRIO, 316 &enc_clock_cb, vp, &vp->enc_clock); 317 if (status != PJ_SUCCESS) 318 goto on_error; 319 } 320 321 if (vp->dir & PJMEDIA_DIR_DECODING) { 322 pjmedia_clock_param param; 323 324 param.usec_interval = PJMEDIA_PTIME(&vfd->fps); 325 param.clock_rate = prm->vidparam.clock_rate; 326 status = pjmedia_clock_create2(pool, ¶m, 327 PJMEDIA_CLOCK_NO_HIGHEST_PRIO, 328 &dec_clock_cb, vp, &vp->dec_clock); 329 if (status != PJ_SUCCESS) 330 goto on_error; 331 } 268 param.usec_interval = PJMEDIA_PTIME(&vfd->fps); 269 param.clock_rate = prm->vidparam.clock_rate; 270 status = pjmedia_clock_create2(pool, ¶m, 271 PJMEDIA_CLOCK_NO_HIGHEST_PRIO, 272 (vp->dir & PJMEDIA_DIR_ENCODING) ? 273 &enc_clock_cb: &dec_clock_cb, 274 vp, &vp->clock); 275 if (status != PJ_SUCCESS) 276 goto on_error; 332 277 333 278 } else if (vp->role==ROLE_PASSIVE) { … … 343 288 prm->vidparam.dir, &prm->vidparam.fmt); 344 289 345 if (vp->stream_role == ROLE_ACTIVE || vp->cap_conv) {290 if (vp->stream_role == ROLE_ACTIVE) { 346 291 need_frame_buf = PJ_TRUE; 347 292 } … … 352 297 pjmedia_video_apply_fmt_param vafp; 353 298 354 vfi = pjmedia_get_video_format_info(NULL, vp->cap_conv? 355 vp->cap_conv_param.src.id: 356 vparam.fmt.id); 299 vfi = pjmedia_get_video_format_info(NULL, vparam.fmt.id); 357 300 if (!vfi) { 358 301 status = PJ_ENOTFOUND; … … 361 304 362 305 pj_bzero(&vafp, sizeof(vafp)); 363 vafp.size = (vp->cap_conv? vp->cap_conv_param.src.det.vid.size: 364 vparam.fmt.det.vid.size); 306 vafp.size = vparam.fmt.det.vid.size; 365 307 status = vfi->apply_fmt(vfi, &vafp); 366 308 if (status != PJ_SUCCESS) 367 309 goto on_error; 368 310 369 if (vp->dir & PJMEDIA_DIR_ENCODING) { 370 vp->enc_frm_buf = PJ_POOL_ZALLOC_T(pool, pjmedia_frame); 371 if (vp->stream_role == ROLE_ACTIVE && vp->cap_conv) { 372 vp->enc_frm_buf_size = vp->cap_conv_buf_size; 373 vp->enc_frm_buf->buf = vp->cap_conv_buf; 374 } else { 375 vp->enc_frm_buf_size = vafp.framebytes; 376 vp->enc_frm_buf->buf = pj_pool_alloc(pool, vafp.framebytes); 377 } 378 vp->enc_frm_buf->size = vp->enc_frm_buf_size; 379 vp->enc_frm_buf->type = PJMEDIA_FRAME_TYPE_NONE; 380 381 status = pj_mutex_create_simple(pool, vp->dev_name.ptr, 382 &vp->enc_frm_mutex); 383 if (status != PJ_SUCCESS) 384 goto on_error; 385 } 386 387 if (vp->dir & PJMEDIA_DIR_DECODING) { 388 vp->dec_frm_buf = PJ_POOL_ZALLOC_T(pool, pjmedia_frame); 389 vp->dec_frm_buf_size = vafp.framebytes; 390 vp->dec_frm_buf->buf = pj_pool_alloc(pool, vafp.framebytes); 391 vp->dec_frm_buf->size = vafp.framebytes; 392 vp->dec_frm_buf->type = PJMEDIA_FRAME_TYPE_NONE; 393 394 status = pj_mutex_create_simple(pool, vp->dev_name.ptr, 395 &vp->dec_frm_mutex); 396 if (status != PJ_SUCCESS) 397 goto on_error; 398 } 311 vp->frm_buf = PJ_POOL_ZALLOC_T(pool, pjmedia_frame); 312 vp->frm_buf_size = vafp.framebytes; 313 vp->frm_buf->buf = pj_pool_alloc(pool, vafp.framebytes); 314 vp->frm_buf->size = vp->frm_buf_size; 315 vp->frm_buf->type = PJMEDIA_FRAME_TYPE_NONE; 316 317 status = pj_mutex_create_simple(pool, vp->dev_name.ptr, 318 &vp->frm_mutex); 319 if (status != PJ_SUCCESS) 320 goto on_error; 399 321 } 400 322 … … 433 355 434 356 435 436 357 PJ_DEF(pjmedia_clock_src *) 437 358 pjmedia_vid_port_get_clock_src( pjmedia_vid_port *vid_port, 438 359 pjmedia_dir dir ) 439 360 { 440 return (dir == PJMEDIA_DIR_CAPTURE? &vid_port->cap_clocksrc:441 &vid_port->rend_clocksrc);361 PJ_ASSERT_RETURN(vid_port, NULL); 362 return &vid_port->clocksrc; 442 363 } 443 364 … … 447 368 pjmedia_clock_src *clocksrc) 448 369 { 449 pjmedia_clock_src *vclocksrc;450 struct sync_clock_src_t *sync_src;451 452 370 PJ_ASSERT_RETURN(vid_port && clocksrc, PJ_EINVAL); 453 371 454 vclocksrc = (dir == PJMEDIA_DIR_CAPTURE? &vid_port->cap_clocksrc: 455 &vid_port->rend_clocksrc); 456 sync_src = (dir == PJMEDIA_DIR_CAPTURE? &vid_port->cap_sync_clocksrc: 457 &vid_port->rend_sync_clocksrc); 458 sync_src->sync_clocksrc = clocksrc; 459 sync_src->sync_delta = pjmedia_clock_src_get_time_msec(vclocksrc) - 460 pjmedia_clock_src_get_time_msec(clocksrc); 372 vid_port->sync_clocksrc.sync_clocksrc = clocksrc; 373 vid_port->sync_clocksrc.sync_delta = 374 pjmedia_clock_src_get_time_msec(&vid_port->clocksrc) - 375 pjmedia_clock_src_get_time_msec(clocksrc); 461 376 462 377 return PJ_SUCCESS; … … 500 415 goto on_error; 501 416 502 if (vp->enc_clock) { 503 status = pjmedia_clock_start(vp->enc_clock); 504 if (status != PJ_SUCCESS) 505 goto on_error; 506 } 507 508 if (vp->dec_clock) { 509 status = pjmedia_clock_start(vp->dec_clock); 417 if (vp->clock) { 418 status = pjmedia_clock_start(vp->clock); 510 419 if (status != PJ_SUCCESS) 511 420 goto on_error; … … 527 436 status = pjmedia_vid_dev_stream_stop(vp->strm); 528 437 529 if (vp->enc_clock) { 530 status = pjmedia_clock_stop(vp->enc_clock); 531 } 532 533 if (vp->dec_clock) { 534 status = pjmedia_clock_stop(vp->dec_clock); 438 if (vp->clock) { 439 status = pjmedia_clock_stop(vp->clock); 535 440 } 536 441 … … 544 449 PJ_LOG(4,(THIS_FILE, "Closing %s..", vp->dev_name.ptr)); 545 450 546 if (vp->enc_clock) { 547 pjmedia_clock_destroy(vp->enc_clock); 548 vp->enc_clock = NULL; 549 } 550 if (vp->dec_clock) { 551 pjmedia_clock_destroy(vp->dec_clock); 552 vp->dec_clock = NULL; 451 if (vp->clock) { 452 pjmedia_clock_destroy(vp->clock); 453 vp->clock = NULL; 553 454 } 554 455 if (vp->strm) { … … 561 462 vp->client_port = NULL; 562 463 } 563 if (vp->enc_frm_mutex) { 564 pj_mutex_destroy(vp->enc_frm_mutex); 565 vp->enc_frm_mutex = NULL; 566 } 567 if (vp->dec_frm_mutex) { 568 pj_mutex_destroy(vp->dec_frm_mutex); 569 vp->dec_frm_mutex = NULL; 570 } 571 464 if (vp->frm_mutex) { 465 pj_mutex_destroy(vp->frm_mutex); 466 vp->frm_mutex = NULL; 467 } 572 468 } 573 469 … … 601 497 } 602 498 */ 499 500 static pj_status_t vidstream_event_cb(pjmedia_vid_dev_stream *stream, 501 void *user_data, 502 pjmedia_vid_event *event) 503 { 504 pjmedia_vid_port *vp = (pjmedia_vid_port*)user_data; 505 506 if (vp->strm_cb.on_event_cb) 507 return (*vp->strm_cb.on_event_cb)(stream, vp->strm_cb_data, event); 508 return PJ_SUCCESS; 509 } 510 511 static pj_status_t convert_frame(pjmedia_vid_port *vp, 512 pjmedia_frame *src_frame, 513 pjmedia_frame *dst_frame) 514 { 515 pj_status_t status = PJ_SUCCESS; 516 517 if (vp->conv) { 518 dst_frame->buf = vp->conv_buf; 519 dst_frame->size = vp->conv_buf_size; 520 status = pjmedia_converter_convert(vp->conv, 521 src_frame, dst_frame); 522 } 523 524 return status; 525 } 603 526 604 527 static pj_status_t detect_fmt_change(pjmedia_vid_port *vp, … … 619 542 pj_assert(vfd->fps.num); 620 543 621 if (vp->c ap_conv) {544 if (vp->conv) { 622 545 /* Change the destination format to the new format */ 623 pjmedia_format_copy(&vp->c ap_conv_param.src,546 pjmedia_format_copy(&vp->conv_param.src, 624 547 &vp->client_port->info.fmt); 625 548 /* Only copy the size here */ 626 vp->c ap_conv_param.dst.det.vid.size =549 vp->conv_param.dst.det.vid.size = 627 550 vp->client_port->info.fmt.det.vid.size, 628 551 629 552 /* Recreate converter */ 630 pjmedia_converter_destroy(vp->c ap_conv);553 pjmedia_converter_destroy(vp->conv); 631 554 status = pjmedia_converter_create(NULL, vp->pool, 632 &vp->c ap_conv_param,633 &vp->c ap_conv);555 &vp->conv_param, 556 &vp->conv); 634 557 if (status != PJ_SUCCESS) { 635 558 PJ_PERROR(4,(THIS_FILE, status, "Error recreating converter")); … … 637 560 } 638 561 } else { 639 vp->c ap_conv_param.dst = vp->client_port->info.fmt;562 vp->conv_param.dst = vp->client_port->info.fmt; 640 563 } 641 564 … … 643 566 vp->strm, 644 567 PJMEDIA_VID_DEV_CAP_FORMAT, 645 &vp->c ap_conv_param.dst);568 &vp->conv_param.dst); 646 569 if (status != PJ_SUCCESS) { 647 570 PJ_LOG(3, (THIS_FILE, "failure in changing the format of the " … … 658 581 659 582 /** 660 * Initially, dec_frm_buf was allocated the biggest583 * Initially, frm_buf was allocated the biggest 661 584 * supported size, so we do not need to re-allocate 662 585 * the buffer here. … … 666 589 clock_param.usec_interval = PJMEDIA_PTIME(&vfd->fps); 667 590 clock_param.clock_rate = vid_param.clock_rate; 668 pjmedia_clock_modify(vp-> dec_clock, &clock_param);591 pjmedia_clock_modify(vp->clock, &clock_param); 669 592 } 670 593 … … 698 621 return; 699 622 700 vp-> enc_frm_buf->size = vp->enc_frm_buf_size;701 status = pjmedia_vid_dev_stream_get_frame(vp->strm, vp-> enc_frm_buf);623 vp->frm_buf->size = vp->frm_buf_size; 624 status = pjmedia_vid_dev_stream_get_frame(vp->strm, vp->frm_buf); 702 625 if (status != PJ_SUCCESS) 703 626 return; 704 627 705 //save_rgb_frame(vp->cap_size.w, vp->cap_size.h, vp->enc_frm_buf); 706 707 if (vp->cap_conv) { 708 frame.buf = vp->cap_conv_buf; 709 frame.size = vp->cap_conv_buf_size; 710 status = pjmedia_converter_convert(vp->cap_conv, 711 vp->enc_frm_buf, &frame); 712 if (status != PJ_SUCCESS) 713 return; 714 } 715 716 status = pjmedia_port_put_frame(vp->client_port, (vp->cap_conv? 717 &frame: 718 vp->enc_frm_buf)); 628 //save_rgb_frame(vp->cap_size.w, vp->cap_size.h, vp->frm_buf); 629 630 if (convert_frame(vp, vp->frm_buf, &frame) != PJ_SUCCESS) 631 return; 632 633 status = pjmedia_port_put_frame(vp->client_port, 634 (vp->conv? &frame: vp->frm_buf)); 719 635 } 720 636 … … 727 643 pj_status_t status; 728 644 pjmedia_frame frame; 729 unsigned frame_ts = vp-> rend_clocksrc.clock_rate / 1000 *730 vp-> rend_clocksrc.ptime_usec / 1000;645 unsigned frame_ts = vp->clocksrc.clock_rate / 1000 * 646 vp->clocksrc.ptime_usec / 1000; 731 647 732 648 pj_assert(vp->role==ROLE_ACTIVE && vp->stream_role==ROLE_PASSIVE); … … 737 653 return; 738 654 739 if (vp-> rend_sync_clocksrc.sync_clocksrc) {740 pjmedia_clock_src *src = vp-> rend_sync_clocksrc.sync_clocksrc;655 if (vp->sync_clocksrc.sync_clocksrc) { 656 pjmedia_clock_src *src = vp->sync_clocksrc.sync_clocksrc; 741 657 pj_int32_t diff; 742 658 unsigned nsync_frame; … … 744 660 /* Synchronization */ 745 661 /* Calculate the time difference (in ms) with the sync source */ 746 diff = pjmedia_clock_src_get_time_msec(&vp-> rend_clocksrc) -662 diff = pjmedia_clock_src_get_time_msec(&vp->clocksrc) - 747 663 pjmedia_clock_src_get_time_msec(src) - 748 vp-> rend_sync_clocksrc.sync_delta;664 vp->sync_clocksrc.sync_delta; 749 665 750 666 /* Check whether sync source made a large jump */ 751 667 if (diff < 0 && -diff > PJMEDIA_CLOCK_SYNC_MAX_SYNC_MSEC) { 752 pjmedia_clock_src_update(&vp-> rend_clocksrc, NULL);753 vp-> rend_sync_clocksrc.sync_delta =668 pjmedia_clock_src_update(&vp->clocksrc, NULL); 669 vp->sync_clocksrc.sync_delta = 754 670 pjmedia_clock_src_get_time_msec(src) - 755 pjmedia_clock_src_get_time_msec(&vp-> rend_clocksrc);756 vp-> rend_sync_clocksrc.nsync_frame = 0;671 pjmedia_clock_src_get_time_msec(&vp->clocksrc); 672 vp->sync_clocksrc.nsync_frame = 0; 757 673 return; 758 674 } 759 675 760 676 /* Calculate the difference (in frames) with the sync source */ 761 nsync_frame = abs(diff) * 1000 / vp-> rend_clocksrc.ptime_usec;677 nsync_frame = abs(diff) * 1000 / vp->clocksrc.ptime_usec; 762 678 if (nsync_frame == 0) { 763 679 /* Nothing to sync */ 764 vp-> rend_sync_clocksrc.nsync_frame = 0;680 vp->sync_clocksrc.nsync_frame = 0; 765 681 } else { 766 682 pj_int32_t init_sync_frame = nsync_frame; … … 769 685 * the sync 770 686 */ 771 if (vp-> rend_sync_clocksrc.nsync_frame == 0 ||772 (vp-> rend_sync_clocksrc.nsync_frame > 0 &&773 nsync_frame > vp-> rend_sync_clocksrc.nsync_frame))687 if (vp->sync_clocksrc.nsync_frame == 0 || 688 (vp->sync_clocksrc.nsync_frame > 0 && 689 nsync_frame > vp->sync_clocksrc.nsync_frame)) 774 690 { 775 vp-> rend_sync_clocksrc.nsync_frame = nsync_frame;776 vp-> rend_sync_clocksrc.nsync_progress = 0;691 vp->sync_clocksrc.nsync_frame = nsync_frame; 692 vp->sync_clocksrc.nsync_progress = 0; 777 693 } else { 778 init_sync_frame = vp-> rend_sync_clocksrc.nsync_frame;694 init_sync_frame = vp->sync_clocksrc.nsync_frame; 779 695 } 780 696 … … 783 699 784 700 /* We are too fast */ 785 if (vp-> rend_sync_clocksrc.max_sync_ticks > 0) {701 if (vp->sync_clocksrc.max_sync_ticks > 0) { 786 702 skip_mod = init_sync_frame / 787 vp-> rend_sync_clocksrc.max_sync_ticks + 2;703 vp->sync_clocksrc.max_sync_ticks + 2; 788 704 } else 789 705 skip_mod = init_sync_frame + 2; … … 794 710 * a complete pause 795 711 */ 796 if (++vp-> rend_sync_clocksrc.nsync_progress % skip_mod > 0) {797 pjmedia_clock_src_update(&vp-> rend_clocksrc, NULL);712 if (++vp->sync_clocksrc.nsync_progress % skip_mod > 0) { 713 pjmedia_clock_src_update(&vp->clocksrc, NULL); 798 714 return; 799 715 } … … 802 718 803 719 /* We are too late, drop the frame */ 804 if (vp-> rend_sync_clocksrc.max_sync_ticks > 0) {805 ndrop /= vp-> rend_sync_clocksrc.max_sync_ticks;720 if (vp->sync_clocksrc.max_sync_ticks > 0) { 721 ndrop /= vp->sync_clocksrc.max_sync_ticks; 806 722 ndrop++; 807 723 } … … 810 726 811 727 if (ndrop >= nsync_frame) { 812 vp-> rend_sync_clocksrc.nsync_frame = 0;728 vp->sync_clocksrc.nsync_frame = 0; 813 729 ndrop = nsync_frame; 814 730 } else 815 vp-> rend_sync_clocksrc.nsync_progress += ndrop;731 vp->sync_clocksrc.nsync_progress += ndrop; 816 732 817 733 for (i = 0; i < ndrop; i++) { 818 vp-> dec_frm_buf->size = vp->dec_frm_buf_size;734 vp->frm_buf->size = vp->frm_buf_size; 819 735 status = pjmedia_port_get_frame(vp->client_port, 820 vp-> dec_frm_buf);736 vp->frm_buf); 821 737 if (status != PJ_SUCCESS) { 822 pjmedia_clock_src_update(&vp-> rend_clocksrc, NULL);738 pjmedia_clock_src_update(&vp->clocksrc, NULL); 823 739 return; 824 740 } 825 741 826 status = detect_fmt_change(vp, vp-> dec_frm_buf);742 status = detect_fmt_change(vp, vp->frm_buf); 827 743 if (status != PJ_SUCCESS) 828 744 return; 829 745 830 pj_add_timestamp32(&vp-> rend_clocksrc.timestamp,746 pj_add_timestamp32(&vp->clocksrc.timestamp, 831 747 frame_ts); 832 748 } … … 835 751 } 836 752 837 vp-> dec_frm_buf->size = vp->dec_frm_buf_size;838 status = pjmedia_port_get_frame(vp->client_port, vp-> dec_frm_buf);753 vp->frm_buf->size = vp->frm_buf_size; 754 status = pjmedia_port_get_frame(vp->client_port, vp->frm_buf); 839 755 if (status != PJ_SUCCESS) { 840 pjmedia_clock_src_update(&vp-> rend_clocksrc, NULL);756 pjmedia_clock_src_update(&vp->clocksrc, NULL); 841 757 return; 842 758 } 843 pj_add_timestamp32(&vp-> rend_clocksrc.timestamp, frame_ts);844 pjmedia_clock_src_update(&vp-> rend_clocksrc, NULL);845 846 status = detect_fmt_change(vp, vp-> dec_frm_buf);759 pj_add_timestamp32(&vp->clocksrc.timestamp, frame_ts); 760 pjmedia_clock_src_update(&vp->clocksrc, NULL); 761 762 status = detect_fmt_change(vp, vp->frm_buf); 847 763 if (status != PJ_SUCCESS) 848 764 return; 849 765 850 if (vp->cap_conv) { 851 frame.buf = vp->cap_conv_buf; 852 frame.size = vp->cap_conv_buf_size; 853 status = pjmedia_converter_convert(vp->cap_conv, 854 vp->dec_frm_buf, &frame); 855 if (status != PJ_SUCCESS) 856 return; 857 } 858 859 status = pjmedia_vid_dev_stream_put_frame(vp->strm, (vp->cap_conv? 860 &frame: 861 vp->dec_frm_buf)); 766 if (convert_frame(vp, vp->frm_buf, &frame) != PJ_SUCCESS) 767 return; 768 769 status = pjmedia_vid_dev_stream_put_frame(vp->strm, 770 (vp->conv? &frame: vp->frm_buf)); 862 771 } 863 772 … … 867 776 { 868 777 pjmedia_vid_port *vp = (pjmedia_vid_port*)user_data; 869 pjmedia_frame frame_;870 871 if (vp->cap_conv) {872 pj_status_t status;873 874 frame_.buf = vp->cap_conv_buf;875 frame_.size = vp->cap_conv_buf_size;876 status = pjmedia_converter_convert(vp->cap_conv,877 frame, &frame_);878 if (status != PJ_SUCCESS)879 return status;880 frame = &frame_;881 }882 778 883 779 if (vp->role==ROLE_ACTIVE) { 780 pj_status_t status; 781 pjmedia_frame frame_; 782 783 status = convert_frame(vp, frame, &frame_); 784 if (status != PJ_SUCCESS) 785 return status; 786 884 787 if (vp->client_port) 885 return pjmedia_port_put_frame(vp->client_port, frame); 788 return pjmedia_port_put_frame(vp->client_port, 789 (vp->conv? &frame_: frame)); 886 790 } else { 887 if (!vp->cap_conv) { 888 pj_mutex_lock(vp->enc_frm_mutex); 889 pjmedia_frame_copy(vp->enc_frm_buf, frame); 890 pj_mutex_unlock(vp->enc_frm_mutex); 891 } 892 } 791 pj_mutex_lock(vp->frm_mutex); 792 pjmedia_frame_copy(vp->frm_buf, frame); 793 pj_mutex_unlock(vp->frm_mutex); 794 } 795 /* 893 796 if (vp->strm_cb.capture_cb) 894 797 return (*vp->strm_cb.capture_cb)(stream, vp->strm_cb_data, frame); 798 */ 895 799 return PJ_SUCCESS; 896 800 } … … 901 805 { 902 806 pjmedia_vid_port *vp = (pjmedia_vid_port*)user_data; 903 807 pj_status_t status = PJ_SUCCESS; 808 904 809 if (vp->role==ROLE_ACTIVE) { 905 810 if (vp->client_port) { … … 913 818 } 914 819 } else { 915 pj_mutex_lock(vp->dec_frm_mutex); 916 pjmedia_frame_copy(frame, vp->dec_frm_buf); 917 pj_mutex_unlock(vp->dec_frm_mutex); 820 pj_mutex_lock(vp->frm_mutex); 821 if (vp->conv) 822 status = convert_frame(vp, vp->frm_buf, frame); 823 else 824 pjmedia_frame_copy(frame, vp->frm_buf); 825 pj_mutex_unlock(vp->frm_mutex); 918 826 } 919 827 if (vp->strm_cb.render_cb) … … 922 830 } 923 831 924 static pj_status_t vidstream_event_cb(pjmedia_vid_dev_stream *stream,925 void *user_data,926 pjmedia_vid_event *event)927 {928 pjmedia_vid_port *vp = (pjmedia_vid_port*)user_data;929 930 if (vp->strm_cb.on_event_cb)931 return (*vp->strm_cb.on_event_cb)(stream, vp->strm_cb_data, event);932 return PJ_SUCCESS;933 }934 935 832 static pj_status_t vid_pasv_port_put_frame(struct pjmedia_port *this_port, 936 833 pjmedia_frame *frame) … … 938 835 struct vid_pasv_port *vpp = (struct vid_pasv_port*)this_port; 939 836 pjmedia_vid_port *vp = vpp->vp; 940 pjmedia_frame frame_; 941 942 if (vp->cap_conv) { 943 pj_status_t status; 944 945 frame_.buf = vp->cap_conv_buf; 946 frame_.size = vp->cap_conv_buf_size; 947 status = pjmedia_converter_convert(vp->cap_conv, 948 frame, &frame_); 837 838 if (vp->stream_role==ROLE_PASSIVE) { 839 pj_status_t status; 840 pjmedia_frame frame_; 841 842 status = convert_frame(vp, frame, &frame_); 843 if (status != PJ_SUCCESS) 844 return status; 845 846 return pjmedia_vid_dev_stream_put_frame(vp->strm, 847 (vp->conv? &frame_: frame)); 848 } else { 849 pj_mutex_lock(vp->frm_mutex); 850 pjmedia_frame_copy(vp->frm_buf, frame); 851 pj_mutex_unlock(vp->frm_mutex); 852 } 853 854 return PJ_SUCCESS; 855 } 856 857 static pj_status_t vid_pasv_port_get_frame(struct pjmedia_port *this_port, 858 pjmedia_frame *frame) 859 { 860 struct vid_pasv_port *vpp = (struct vid_pasv_port*)this_port; 861 pjmedia_vid_port *vp = vpp->vp; 862 pj_status_t status = PJ_SUCCESS; 863 864 if (vp->stream_role==ROLE_PASSIVE) { 865 status = pjmedia_vid_dev_stream_get_frame(vp->strm, 866 (vp->conv? vp->frm_buf: 867 frame)); 949 868 if (status != PJ_SUCCESS) 950 869 return status; 951 frame = &frame_; 952 } 953 954 if (vp->stream_role==ROLE_PASSIVE) { 955 return pjmedia_vid_dev_stream_put_frame(vp->strm, frame); 870 871 status = convert_frame(vp, vp->frm_buf, frame); 956 872 } else { 957 pj_mutex_lock(vp->dec_frm_mutex); 958 pjmedia_frame_copy(vp->dec_frm_buf, frame); 959 pj_mutex_unlock(vp->dec_frm_mutex); 960 } 961 962 return PJ_SUCCESS; 963 } 964 965 static pj_status_t vid_pasv_port_get_frame(struct pjmedia_port *this_port, 966 pjmedia_frame *frame) 967 { 968 struct vid_pasv_port *vpp = (struct vid_pasv_port*)this_port; 969 pjmedia_vid_port *vp = vpp->vp; 970 pj_status_t status; 971 972 if (vp->stream_role==ROLE_PASSIVE) { 973 if (vp->cap_conv) 974 vp->enc_frm_buf->size = vp->enc_frm_buf_size; 975 status = pjmedia_vid_dev_stream_get_frame(vp->strm, 976 (vp->cap_conv? 977 vp->enc_frm_buf: 978 frame)); 979 if (status != PJ_SUCCESS) 980 return status; 981 982 if (vp->cap_conv) { 983 status = pjmedia_converter_convert(vp->cap_conv, 984 vp->enc_frm_buf, frame); 985 if (status != PJ_SUCCESS) 986 return status; 987 } 988 } else { 989 pj_mutex_lock(vp->enc_frm_mutex); 990 pjmedia_frame_copy(frame, vp->enc_frm_buf); 991 pj_mutex_unlock(vp->enc_frm_mutex); 992 } 993 994 return PJ_SUCCESS; 995 } 996 873 pj_mutex_lock(vp->frm_mutex); 874 if (vp->conv) 875 status = convert_frame(vp, vp->frm_buf, frame); 876 else 877 pjmedia_frame_copy(frame, vp->frm_buf); 878 pj_mutex_unlock(vp->frm_mutex); 879 } 880 881 return status; 882 }
Note: See TracChangeset
for help on using the changeset viewer.