From 4d65207571e24bca6277597af10c1c270a38f879 Mon Sep 17 00:00:00 2001 From: Nanang Izzuddin Date: Wed, 7 May 2014 08:11:10 +0000 Subject: Re #1762: Support more capture sizes (was only 352x288) and automatically find the closest supported size from the requested size. git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@4838 74dad513-b988-da41-8d7b-12977e46ad98 --- pjmedia/src/pjmedia-videodev/ios_dev.m | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/pjmedia/src/pjmedia-videodev/ios_dev.m b/pjmedia/src/pjmedia-videodev/ios_dev.m index 26fd5615..8fe54437 100644 --- a/pjmedia/src/pjmedia-videodev/ios_dev.m +++ b/pjmedia/src/pjmedia-videodev/ios_dev.m @@ -548,6 +548,18 @@ static pj_status_t ios_factory_create_stream( strm->is_planar = vfi->plane_cnt > 1; if (param->dir & PJMEDIA_DIR_CAPTURE) { + NSString *size_preset_str[] = { + AVCaptureSessionPreset352x288, + AVCaptureSessionPreset640x480, + AVCaptureSessionPreset1280x720, + AVCaptureSessionPreset1920x1080 + }; + pj_size_t supported_size_w[] = { 352, 640, 1280, 1920 }; + pj_size_t supported_size_h[] = { 288, 480, 720, 1080 }; + pj_size_t supported_size[] = { 352*288, 640*480, 1280*720, 1920*1080 }; + pj_size_t requested_size = strm->size.w * strm->size.h; + int i; + /* Create capture stream here */ strm->cap_session = [[AVCaptureSession alloc] init]; if (!strm->cap_session) { @@ -555,10 +567,14 @@ static pj_status_t ios_factory_create_stream( goto on_error; } - /* Just hardcode to always capture 352x288 for now */ - strm->cap_session.sessionPreset = AVCaptureSessionPreset352x288; - vfd->size.w = 352; - vfd->size.h = 288; + /* Find the closest supported size */ + for(i = 0; i < PJ_ARRAY_SIZE(supported_size)-1; ++i) { + if (supported_size[i] >= requested_size) + break; + } + strm->cap_session.sessionPreset = size_preset_str[i]; + vfd->size.w = supported_size_w[i]; + vfd->size.h = supported_size_h[i]; strm->size = vfd->size; strm->bytes_per_row = strm->size.w * vfi->bpp / 8; strm->frame_size = strm->bytes_per_row * strm->size.h; -- cgit v1.2.3