Changeset 5054 for pjproject/trunk
- Timestamp:
- Apr 8, 2015 10:09:37 AM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjmedia/src/pjmedia-videodev/ios_dev.m
r5051 r5054 107 107 unsigned frame_size; /**< Frame size (bytes)*/ 108 108 pj_bool_t is_planar; 109 NSLock *frame_lock; 110 void *capture_buf; 109 111 110 112 AVCaptureSession *cap_session; … … 113 115 VOutDelegate *vout_delegate; 114 116 dispatch_queue_t queue; 115 void *capture_buf;116 117 AVCaptureVideoPreviewLayer *prev_layer; 117 118 … … 123 124 pj_timestamp frame_ts; 124 125 unsigned ts_inc; 125 126 pj_bool_t thread_initialized;127 pj_thread_desc thread_desc;128 pj_thread_t *thread;129 126 }; 130 127 … … 158 155 const void *value); 159 156 static pj_status_t ios_stream_start(pjmedia_vid_dev_stream *strm); 157 static pj_status_t ios_stream_get_frame(pjmedia_vid_dev_stream *strm, 158 pjmedia_frame *frame); 160 159 static pj_status_t ios_stream_put_frame(pjmedia_vid_dev_stream *strm, 161 160 const pjmedia_frame *frame); … … 181 180 &ios_stream_set_cap, 182 181 &ios_stream_start, 183 NULL,182 &ios_stream_get_frame, 184 183 &ios_stream_put_frame, 185 184 &ios_stream_stop, … … 262 261 pj_ansi_strncpy(qdi->info.driver, "iOS", sizeof(qdi->info.driver)); 263 262 qdi->info.dir = PJMEDIA_DIR_CAPTURE; 264 qdi->info.has_callback = PJ_ TRUE;263 qdi->info.has_callback = PJ_FALSE; 265 264 qdi->info.caps = PJMEDIA_VID_DEV_CAP_INPUT_PREVIEW | 266 265 PJMEDIA_VID_DEV_CAP_SWITCH; … … 436 435 fromConnection:(AVCaptureConnection *)connection 437 436 { 438 pjmedia_frame frame = {0};439 437 CVImageBufferRef img; 438 439 /* Refrain from calling pjlib functions which require thread registration 440 * here, since according to the doc, dispatch queue cannot guarantee 441 * the reliability of underlying functions required by PJSIP to perform 442 * the registration, such as pthread_self() and pthread_getspecific()/ 443 * pthread_setspecific(). 444 */ 440 445 441 446 if (!sampleBuffer) … … 448 453 CVPixelBufferLockBaseAddress(img, kCVPixelBufferLock_ReadOnly); 449 454 450 frame.type = PJMEDIA_FRAME_TYPE_VIDEO; 451 frame.size = stream->frame_size; 452 frame.timestamp.u64 = stream->frame_ts.u64; 453 455 456 [stream->frame_lock lock]; 454 457 if (stream->is_planar && stream->capture_buf) { 455 458 if (stream->param.fmt.id == PJMEDIA_FORMAT_I420) { … … 499 502 } 500 503 } 501 502 frame.buf = stream->capture_buf;503 504 } 504 505 } else { 505 frame.buf = CVPixelBufferGetBaseAddress(img); 506 } 507 508 if (stream->vid_cb.capture_cb) { 509 if (stream->thread_initialized == 0 || !pj_thread_is_registered()) 510 { 511 pj_bzero(stream->thread_desc, sizeof(pj_thread_desc)); 512 pj_thread_register("ios_vdev", stream->thread_desc, 513 &stream->thread); 514 stream->thread_initialized = 1; 515 } 516 517 (*stream->vid_cb.capture_cb)(&stream->base, stream->user_data, &frame); 506 pj_memcpy(stream->capture_buf, CVPixelBufferGetBaseAddress(img), 507 stream->frame_size); 518 508 } 519 509 520 510 stream->frame_ts.u64 += stream->ts_inc; 511 [stream->frame_lock unlock]; 521 512 522 513 /* Unlock the pixel buffer */ … … 524 515 } 525 516 @end 517 518 static pj_status_t ios_stream_get_frame(pjmedia_vid_dev_stream *strm, 519 pjmedia_frame *frame) 520 { 521 struct ios_stream *stream = (struct ios_stream *)strm; 522 523 frame->type = PJMEDIA_FRAME_TYPE_VIDEO; 524 frame->bit_info = 0; 525 pj_assert(frame->size >= stream->frame_size); 526 frame->size = stream->frame_size; 527 frame->timestamp.u64 = stream->frame_ts.u64; 528 529 [stream->frame_lock lock]; 530 pj_memcpy(frame->buf, stream->capture_buf, stream->frame_size); 531 [stream->frame_lock unlock]; 532 533 return PJ_SUCCESS; 534 } 535 526 536 527 537 static ios_fmt_info* get_ios_format_info(pjmedia_format_id id) … … 713 723 } 714 724 715 /* Prepare capture buffer if it's planar format */ 716 if (strm->is_planar) 717 strm->capture_buf = pj_pool_alloc(strm->pool, strm->frame_size); 718 725 strm->capture_buf = pj_pool_alloc(strm->pool, strm->frame_size); 726 strm->frame_lock = [[NSLock alloc]init]; 727 719 728 /* Native preview */ 720 729 if (param->flags & PJMEDIA_VID_DEV_CAP_INPUT_PREVIEW) { … … 1127 1136 stream->queue = nil; 1128 1137 } 1138 1139 if (stream->frame_lock) { 1140 [stream->frame_lock release]; 1141 stream->frame_lock = nil; 1142 } 1129 1143 1130 1144 pj_pool_release(stream->pool);
Note: See TracChangeset
for help on using the changeset viewer.