Changeset 3488
- Timestamp:
- Mar 25, 2011 8:23:12 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/branches/projects/2.0-dev/pjmedia/src/test/vid_dev_test.c
r3484 r3488 24 24 #include <pjmedia_videodev.h> 25 25 26 #define THIS_FILE "vid_dev_test.c" 26 #define THIS_FILE "vid_dev_test.c" 27 #define LOOP_DURATION 10 27 28 28 29 static pj_bool_t is_quitting = PJ_FALSE; 29 30 31 static const char *vid_dir_name(pjmedia_dir dir) 32 { 33 switch (dir) { 34 case PJMEDIA_DIR_CAPTURE: 35 return "capture"; 36 case PJMEDIA_DIR_RENDER: 37 return "render"; 38 case PJMEDIA_DIR_CAPTURE_RENDER: 39 return "capture & render"; 40 default: 41 return "unknown"; 42 } 43 } 44 30 45 static int enum_devs(void) 31 46 { … … 33 48 pj_status_t status; 34 49 35 PJ_LOG(3, (THIS_FILE, " device enums"));50 PJ_LOG(3, (THIS_FILE, " Enum video devices:")); 36 51 dev_cnt = pjmedia_vid_dev_count(); 37 52 for (i = 0; i < dev_cnt; ++i) { 38 pjmedia_vid_dev_info info;39 status = pjmedia_vid_dev_get_info(i, & info);53 pjmedia_vid_dev_info di; 54 status = pjmedia_vid_dev_get_info(i, &di); 40 55 if (status == PJ_SUCCESS) { 41 PJ_LOG(3, (THIS_FILE, "%3d: %s - %s", i, info.driver, info.name)); 56 unsigned j; 57 58 PJ_LOG(3, (THIS_FILE, " %3d: %s (%s) - %s", i, di.name, di.driver, 59 vid_dir_name(di.dir))); 60 61 PJ_LOG(3,(THIS_FILE, " Supported formats:")); 62 for (j=0; j<di.fmt_cnt; ++j) { 63 const pjmedia_video_format_info *vfi; 64 65 vfi = pjmedia_get_video_format_info(NULL, di.fmt[j].id); 66 PJ_LOG(3,(THIS_FILE, " %s", 67 (vfi ? vfi->name : "unknown"))); 68 } 42 69 } 43 70 } … … 60 87 } 61 88 62 static int loopback_test(pj_pool_t *pool) 63 { 89 static int capture_render_loopback(int cap_dev_id, int rend_dev_id, 90 const pjmedia_format *fmt) 91 { 92 pj_pool_t *pool; 64 93 pjmedia_vid_port *capture=NULL, *renderer=NULL; 94 pjmedia_vid_dev_info cdi, rdi; 65 95 pjmedia_vid_port_param param; 66 96 pjmedia_video_format_detail *vfd; … … 69 99 int rc = 0, i; 70 100 71 PJ_LOG(3, (THIS_FILE, " loopback test")); 101 pool = pj_pool_create(mem, "vidloop", 1000, 1000, NULL); 102 103 status = pjmedia_vid_dev_get_info(cap_dev_id, &cdi); 104 if (status != PJ_SUCCESS) 105 goto on_return; 106 107 status = pjmedia_vid_dev_get_info(rend_dev_id, &rdi); 108 if (status != PJ_SUCCESS) 109 goto on_return; 110 111 PJ_LOG(3,(THIS_FILE, 112 " %s (%s) ===> %s (%s)\t%s\t%dx%d\t@%d:%d fps", 113 cdi.name, cdi.driver, rdi.name, rdi.driver, 114 pjmedia_get_video_format_info(NULL, fmt->id)->name, 115 fmt->det.vid.size.w, fmt->det.vid.size.h, 116 fmt->det.vid.fps.num, fmt->det.vid.fps.denum)); 72 117 73 118 pjmedia_vid_port_param_default(¶m); 74 119 75 120 /* Create capture, set it to active (master) */ 76 status = pjmedia_vid_dev_default_param(pool, 77 PJMEDIA_VID_DEFAULT_CAPTURE_DEV, 121 status = pjmedia_vid_dev_default_param(pool, cap_dev_id, 78 122 ¶m.vidparam); 79 123 if (status != PJ_SUCCESS) { … … 81 125 } 82 126 param.vidparam.dir = PJMEDIA_DIR_CAPTURE; 127 param.vidparam.fmt = *fmt; 83 128 param.active = PJ_TRUE; 84 129 … … 98 143 99 144 /* Create renderer, set it to passive (slave) */ 145 status = pjmedia_vid_dev_default_param(pool, rend_dev_id, 146 ¶m.vidparam); 147 if (status != PJ_SUCCESS) { 148 rc = 120; goto on_return; 149 } 150 100 151 param.active = PJ_FALSE; 101 152 param.vidparam.dir = PJMEDIA_DIR_RENDER; 102 param.vidparam.rend_id = PJMEDIA_VID_DEFAULT_RENDER_DEV; 153 param.vidparam.rend_id = rend_dev_id; 154 param.vidparam.fmt = *fmt; 103 155 param.vidparam.disp_size = vfd->size; 104 156 … … 108 160 } 109 161 162 /* Set event handler */ 110 163 pj_bzero(&cb, sizeof(cb)); 111 164 cb.on_event_cb = vid_event_cb; … … 132 185 133 186 /* Sleep while the webcam is being displayed... */ 134 for (i = 0; i < 25 && (!is_quitting); i++) { 187 for (i = 0; i < LOOP_DURATION*10 && (!is_quitting); i++) { 188 #if VID_DEV_TEST_MAC_OS 189 CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0, false); 190 #endif 135 191 pj_thread_sleep(100); 136 192 } 137 193 138 /**139 * Test the renderer's format capability if the device140 * supports it.141 */142 if (pjmedia_vid_dev_stream_get_cap(pjmedia_vid_port_get_stream(renderer),143 PJMEDIA_VID_DEV_CAP_FORMAT,144 ¶m.vidparam.fmt) == PJ_SUCCESS)145 {146 status = pjmedia_vid_port_stop(capture);147 if (status != PJ_SUCCESS) {148 rc = 170; goto on_return;149 }150 status = pjmedia_vid_port_disconnect(capture);151 if (status != PJ_SUCCESS) {152 rc = 180; goto on_return;153 }154 pjmedia_vid_port_destroy(capture);155 156 param.vidparam.dir = PJMEDIA_DIR_CAPTURE;157 param.active = PJ_TRUE;158 pjmedia_format_init_video(¶m.vidparam.fmt, param.vidparam.fmt.id,159 640, 480,160 vfd->fps.num, vfd->fps.denum);161 vfd = pjmedia_format_get_video_format_detail(¶m.vidparam.fmt,162 PJ_TRUE);163 if (vfd == NULL) {164 rc = 185; goto on_return;165 }166 167 status = pjmedia_vid_port_create(pool, ¶m, &capture);168 if (status != PJ_SUCCESS) {169 rc = 190; goto on_return;170 }171 172 status = pjmedia_vid_port_connect(173 capture,174 pjmedia_vid_port_get_passive_port(renderer),175 PJ_FALSE);176 if (status != PJ_SUCCESS) {177 rc = 200; goto on_return;178 }179 180 status = pjmedia_vid_dev_stream_set_cap(181 pjmedia_vid_port_get_stream(renderer),182 PJMEDIA_VID_DEV_CAP_FORMAT,183 ¶m.vidparam.fmt);184 if (status != PJ_SUCCESS) {185 rc = 205; goto on_return;186 }187 188 status = pjmedia_vid_port_start(capture);189 if (status != PJ_SUCCESS) {190 rc = 210; goto on_return;191 }192 }193 194 for (i = 0; i < 35 && (!is_quitting); i++) {195 pj_thread_sleep(100);196 }197 198 194 on_return: 199 PJ_PERROR(3, (THIS_FILE, status, " error")); 195 if (status != PJ_SUCCESS) 196 PJ_PERROR(3, (THIS_FILE, status, " error")); 197 200 198 if (capture) 201 199 pjmedia_vid_port_destroy(capture); … … 203 201 pjmedia_vid_port_destroy(renderer); 204 202 203 pj_pool_release(pool); 205 204 return rc; 206 205 } 207 206 207 static int loopback_test(void) 208 { 209 unsigned count, i; 210 pjmedia_format_id test_fmts[] = { 211 PJMEDIA_FORMAT_YUY2 212 }; 213 pjmedia_rect_size test_sizes[] = { 214 {176,144}, /* QCIF */ 215 {352,288}, /* CIF */ 216 {704,576} /* 4CIF */ 217 }; 218 pjmedia_ratio test_fpses[] = { 219 {25, 1}, 220 {30, 1}, 221 }; 222 pj_status_t status; 223 224 PJ_LOG(3, (THIS_FILE, " Loopback tests (prepare you webcams):")); 225 226 count = pjmedia_vid_dev_count(); 227 for (i=0; i<count; ++i) { 228 pjmedia_vid_dev_info cdi; 229 unsigned j; 230 231 status = pjmedia_vid_dev_get_info(i, &cdi); 232 if (status != PJ_SUCCESS) 233 return -300; 234 235 /* Only interested with capture device */ 236 if ((cdi.dir & PJMEDIA_DIR_CAPTURE) == 0) 237 continue; 238 239 for (j=i+1; j<count; ++j) { 240 pjmedia_vid_dev_info rdi; 241 unsigned k; 242 243 status = pjmedia_vid_dev_get_info(j, &rdi); 244 if (status != PJ_SUCCESS) 245 return -310; 246 247 /* Only interested with render device */ 248 if ((rdi.dir & PJMEDIA_DIR_RENDER) == 0) 249 continue; 250 251 /* Test with the format, size, and fps combinations */ 252 for (k=0; k<PJ_ARRAY_SIZE(test_fmts); ++k) { 253 unsigned l; 254 255 for (l=0; l<PJ_ARRAY_SIZE(test_sizes); ++l) { 256 unsigned m; 257 258 for (m=0; m<PJ_ARRAY_SIZE(test_fpses); ++m) { 259 pjmedia_format fmt; 260 261 pjmedia_format_init_video(&fmt, test_fmts[k], 262 test_sizes[l].w, 263 test_sizes[l].h, 264 test_fpses[m].num, 265 test_fpses[m].denum); 266 267 capture_render_loopback(i, j, &fmt); 268 } 269 } 270 } /* k */ 271 272 } 273 } 274 275 return 0; 276 } 277 208 278 int vid_dev_test(void) 209 279 { 210 pj_pool_t *pool;211 280 int rc = 0; 212 281 pj_status_t status; 213 282 214 PJ_LOG(3, (THIS_FILE, "Video device tests.."));215 216 pool = pj_pool_create(mem, "Viddev test", 256, 256, 0);217 218 283 status = pjmedia_vid_subsys_init(mem); 219 284 if (status != PJ_SUCCESS) … … 224 289 goto on_return; 225 290 226 rc = loopback_test( pool);291 rc = loopback_test(); 227 292 if (rc != 0) 228 293 goto on_return; … … 230 295 on_return: 231 296 pjmedia_vid_subsys_shutdown(); 232 pj_pool_release(pool);233 297 234 298 return rc;
Note: See TracChangeset
for help on using the changeset viewer.