Changeset 3499
- Timestamp:
- Apr 6, 2011 11:30:18 AM (14 years ago)
- Location:
- pjproject/branches/projects/2.0-dev
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/branches/projects/2.0-dev/aconfigure
r3395 r3499 11462 11462 if test "$ac_pjmedia_video_has_qt" = "yes"; then 11463 11463 ac_qt_cflags="-DPJMEDIA_VIDEO_DEV_HAS_QT=1" 11464 LIBS="$LIBS -framework QTKit -framework Foundation -framework AppKit -framework QuartzCore "11464 LIBS="$LIBS -framework QTKit -framework Foundation -framework AppKit -framework QuartzCore -framework OpenGL" 11465 11465 { echo "$as_me:$LINENO: result: Checking if QTKit framework is available... yes" >&5 11466 11466 echo "${ECHO_T}Checking if QTKit framework is available... yes" >&6; } -
pjproject/branches/projects/2.0-dev/aconfigure.ac
r3395 r3499 604 604 if test "$ac_pjmedia_video_has_qt" = "yes"; then 605 605 ac_qt_cflags="-DPJMEDIA_VIDEO_DEV_HAS_QT=1" 606 LIBS="$LIBS -framework QTKit -framework Foundation -framework AppKit -framework QuartzCore "606 LIBS="$LIBS -framework QTKit -framework Foundation -framework AppKit -framework QuartzCore -framework OpenGL" 607 607 AC_MSG_RESULT([Checking if QTKit framework is available... yes]) 608 608 else -
pjproject/branches/projects/2.0-dev/pjmedia/include/pjmedia-videodev/config.h
r3395 r3499 49 49 #ifndef PJMEDIA_VIDEO_DEV_HAS_SDL 50 50 # define PJMEDIA_VIDEO_DEV_HAS_SDL 0 51 # define PJMEDIA_VIDEO_DEV_SDL_HAS_OPENGL 0 51 52 #endif 52 53 -
pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia-videodev/qt_dev.m
r3489 r3499 24 24 #if PJMEDIA_VIDEO_DEV_HAS_QT 25 25 26 #include <Foundation/NSAutoreleasePool.h> 26 27 #include <QTKit/QTKit.h> 27 28 … … 42 43 static qt_fmt_info qt_fmts[] = 43 44 { 44 {PJMEDIA_FORMAT_YUY2, kCVPixelFormatType_422YpCbCr8_yuvs} , 45 {PJMEDIA_FORMAT_YUY2, kCVPixelFormatType_422YpCbCr8_yuvs}, 46 {PJMEDIA_FORMAT_UYVY, kCVPixelFormatType_422YpCbCr8}, 45 47 }; 46 48 … … 83 85 void *user_data; /**< Application data. */ 84 86 87 pj_bool_t cap_thread_exited; 88 pj_bool_t cap_thread_initialized; 89 pj_thread_desc cap_thread_desc; 90 pj_thread_t *cap_thread; 91 92 NSAutoreleasePool *apool; 85 93 QTCaptureSession *cap_session; 86 94 QTCaptureDeviceInput *dev_input; … … 171 179 struct qt_dev_info *qdi; 172 180 unsigned i, dev_count = 0; 181 NSAutoreleasePool *apool = [[NSAutoreleasePool alloc]init]; 173 182 NSArray *dev_array; 174 183 … … 245 254 } 246 255 256 [apool release]; 257 247 258 PJ_LOG(4, (THIS_FILE, "qt video initialized with %d devices", 248 259 qf->dev_count)); … … 317 328 pjmedia_frame frame; 318 329 330 if (stream->cap_thread_initialized == 0 || !pj_thread_is_registered()) 331 { 332 pj_thread_register("qt_cap", stream->cap_thread_desc, 333 &stream->cap_thread); 334 stream->cap_thread_initialized = 1; 335 PJ_LOG(5,(THIS_FILE, "Capture thread started")); 336 } 337 319 338 if (!videoFrame) 320 339 return; … … 380 399 pj_memcpy(&strm->vid_cb, cb, sizeof(*cb)); 381 400 strm->user_data = user_data; 401 strm->apool = [[NSAutoreleasePool alloc]init]; 382 402 383 403 /* Create player stream here */ … … 447 467 strm->cap_ts_inc = PJMEDIA_SPF2(strm->param.clock_rate, &vfd->fps, 1); 448 468 449 [strm->video_output setMinimumVideoFrameInterval: 450 (1.0f * vfd->fps.denum / (double)vfd->fps.num)]; 451 452 strm->vout_delegate = [VOutDelegate alloc]; 469 if ([strm->video_output 470 respondsToSelector:@selector(setMinimumVideoFrameInterval)]) 471 { 472 [strm->video_output setMinimumVideoFrameInterval: 473 (1.0f * vfd->fps.denum / 474 (double)vfd->fps.num)]; 475 } 476 477 strm->vout_delegate = [[VOutDelegate alloc]init]; 453 478 strm->vout_delegate->stream = strm; 454 479 [strm->video_output setDelegate:strm->vout_delegate]; … … 547 572 if (![stream->cap_session isRunning]) 548 573 return PJ_EUNKNOWN; 549 } 550 551 CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0, false);552 574 575 CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0, false); 576 } 577 553 578 return PJ_SUCCESS; 554 579 } … … 599 624 } 600 625 626 // [stream->apool release]; 601 627 pj_pool_release(stream->pool); 602 628 -
pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia-videodev/sdl_dev.c
r3489 r3499 26 26 27 27 #if defined(PJ_DARWINOS) && PJ_DARWINOS!=0 28 # include <Foundation/ NSAutoreleasePool.h>28 # include <Foundation/Foundation.h> 29 29 #endif 30 30 31 31 #include <SDL.h> 32 #if PJMEDIA_VIDEO_DEV_SDL_HAS_OPENGL 33 # include "SDL_opengl.h" 34 # define OPENGL_DEV_IDX 1 35 #endif 32 36 33 37 #define THIS_FILE "sdl_dev.c" … … 88 92 }; 89 93 94 #if defined(PJ_DARWINOS) && PJ_DARWINOS!=0 95 @interface SDLDelegate: NSObject 96 { 97 @public 98 struct sdl_stream *strm; 99 } 100 101 - (int)sdl_thread; 102 - (int)handle_event; 103 - (pj_status_t)put_frame; 104 @end 105 #endif 106 90 107 /* Video stream. */ 91 108 struct sdl_stream … … 108 125 SDL_Surface *surf; /**< RGB surface. */ 109 126 SDL_Overlay *overlay; /**< YUV overlay. */ 127 #if PJMEDIA_VIDEO_DEV_SDL_HAS_OPENGL 128 GLuint texture; 129 #endif 130 #if defined(PJ_DARWINOS) && PJ_DARWINOS!=0 131 NSAutoreleasePool *apool; 132 SDLDelegate *delegate; 133 const pjmedia_frame *frame; 134 #endif 110 135 111 136 /* For frame conversion */ … … 203 228 204 229 sf->dev_count = 1; 230 #if PJMEDIA_VIDEO_DEV_SDL_HAS_OPENGL 231 sf->dev_count++; 232 #endif 205 233 sf->dev_info = (struct sdl_dev_info*) 206 207 234 pj_pool_calloc(sf->pool, sf->dev_count, 235 sizeof(struct sdl_dev_info)); 208 236 209 237 ddi = &sf->dev_info[0]; … … 216 244 ddi->info.has_callback = PJ_FALSE; 217 245 ddi->info.caps = PJMEDIA_VID_DEV_CAP_FORMAT | 218 246 PJMEDIA_VID_DEV_CAP_OUTPUT_RESIZE; 219 247 220 248 ddi->info.fmt_cnt = PJ_ARRAY_SIZE(sdl_fmts); 221 249 ddi->info.fmt = (pjmedia_format*) 222 223 250 pj_pool_calloc(sf->pool, ddi->info.fmt_cnt, 251 sizeof(pjmedia_format)); 224 252 for (i = 0; i < ddi->info.fmt_cnt; i++) { 225 253 pjmedia_format *fmt = &ddi->info.fmt[i]; … … 228 256 DEFAULT_FPS, 1); 229 257 } 258 259 #if PJMEDIA_VIDEO_DEV_SDL_HAS_OPENGL 260 ddi = &sf->dev_info[OPENGL_DEV_IDX]; 261 pj_bzero(ddi, sizeof(*ddi)); 262 strncpy(ddi->info.name, "SDL openGL renderer", sizeof(ddi->info.name)); 263 ddi->info.name[sizeof(ddi->info.name)-1] = '\0'; 264 strncpy(ddi->info.driver, "SDL", sizeof(ddi->info.driver)); 265 ddi->info.driver[sizeof(ddi->info.driver)-1] = '\0'; 266 ddi->info.dir = PJMEDIA_DIR_RENDER; 267 ddi->info.has_callback = PJ_FALSE; 268 ddi->info.caps = PJMEDIA_VID_DEV_CAP_FORMAT; 269 270 ddi->info.fmt_cnt = PJ_ARRAY_SIZE(sdl_fmts); 271 ddi->info.fmt_cnt = 1; 272 ddi->info.fmt = (pjmedia_format*) 273 pj_pool_calloc(sf->pool, ddi->info.fmt_cnt, 274 sizeof(pjmedia_format)); 275 for (i = 0; i < ddi->info.fmt_cnt; i++) { 276 pjmedia_format *fmt = &ddi->info.fmt[i]; 277 pjmedia_format_init_video(fmt, sdl_fmts[i].fmt_id, 278 DEFAULT_WIDTH, DEFAULT_HEIGHT, 279 DEFAULT_FPS, 1); 280 } 281 #endif 230 282 231 283 PJ_LOG(4, (THIS_FILE, "SDL initialized")); … … 320 372 } 321 373 322 static int create_sdl_thread(void * data) 374 #if defined(PJ_DARWINOS) && PJ_DARWINOS!=0 375 @implementation SDLDelegate 376 - (int)sdl_thread 377 { 378 #else 379 static int sdlthread(void * data) 323 380 { 324 381 struct sdl_stream *strm = (struct sdl_stream*)data; 382 #endif 325 383 sdl_fmt_info *sdl_info = get_sdl_format_info(strm->param.fmt.id); 326 384 const pjmedia_video_format_info *vfi; 327 385 pjmedia_video_format_detail *vfd; 328 386 329 #if defined(PJ_DARWINOS) && PJ_DARWINOS!=0330 NSAutoreleasePool *apool = [[NSAutoreleasePool alloc] init];331 #endif332 333 387 vfi = pjmedia_get_video_format_info(pjmedia_video_format_mgr_instance(), 334 388 strm->param.fmt.id); … … 357 411 strm->rect.h = (Uint16)vfd->size.h; 358 412 413 #if PJMEDIA_VIDEO_DEV_SDL_HAS_OPENGL 414 if (strm->param.rend_id == OPENGL_DEV_IDX) { 415 SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER,1); 416 } 417 #endif 418 359 419 /* Initialize the display, requesting a software surface */ 360 strm->screen = SDL_SetVideoMode(strm->rect.w, strm->rect.h, 361 0, SDL_RESIZABLE | SDL_SWSURFACE); 420 strm->screen = SDL_SetVideoMode(strm->rect.w, strm->rect.h, 0, ( 421 #if PJMEDIA_VIDEO_DEV_SDL_HAS_OPENGL 422 strm->param.rend_id == OPENGL_DEV_IDX? 423 SDL_OPENGL: 424 #endif 425 SDL_RESIZABLE | SDL_SWSURFACE)); 362 426 if (strm->screen == NULL) { 363 427 strm->status = PJMEDIA_EVID_SYSERR; … … 366 430 SDL_WM_SetCaption("pjmedia-SDL video", NULL); 367 431 432 #if PJMEDIA_VIDEO_DEV_SDL_HAS_OPENGL 433 if (strm->param.rend_id == OPENGL_DEV_IDX) { 434 glDisable(GL_DEPTH_TEST); 435 glDisable(GL_CULL_FACE); 436 glEnable(GL_TEXTURE_2D); 437 438 glViewport(0, 0, strm->rect.w, strm->rect.h); 439 glMatrixMode(GL_PROJECTION); 440 glLoadIdentity(); 441 442 glOrtho(0.0, (GLdouble)strm->rect.w, (GLdouble)strm->rect.h, 443 0.0, 0.0, 1.0); 444 445 glMatrixMode(GL_MODELVIEW); 446 glLoadIdentity(); 447 448 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); 449 glGenTextures(1, &strm->texture); 450 } else 451 #endif 368 452 if (vfi->color_model == PJMEDIA_COLOR_MODEL_RGB) { 369 453 strm->surf = SDL_CreateRGBSurface(SDL_SWSURFACE, 370 371 372 373 374 375 454 strm->rect.w, strm->rect.h, 455 vfi->bpp, 456 sdl_info->Rmask, 457 sdl_info->Gmask, 458 sdl_info->Bmask, 459 sdl_info->Amask); 376 460 if (strm->surf == NULL) { 377 461 strm->status = PJMEDIA_EVID_SYSERR; … … 380 464 } else if (vfi->color_model == PJMEDIA_COLOR_MODEL_YUV) { 381 465 strm->overlay = SDL_CreateYUVOverlay(strm->rect.w, strm->rect.h, 382 383 466 sdl_info->sdl_format, 467 strm->screen); 384 468 if (strm->overlay == NULL) { 385 469 strm->status = PJMEDIA_EVID_SYSERR; … … 388 472 } 389 473 390 while(!strm->is_quitting) { 474 #if defined(PJ_DARWINOS) && PJ_DARWINOS!=0 475 on_return: 476 if (strm->status != PJ_SUCCESS) { 477 if (strm->surf) { 478 SDL_FreeSurface(strm->surf); 479 strm->surf = NULL; 480 } 481 482 if (strm->overlay) { 483 SDL_FreeYUVOverlay(strm->overlay); 484 strm->overlay = NULL; 485 } 486 #if PJMEDIA_VIDEO_DEV_SDL_HAS_OPENGL 487 if (strm->texture) { 488 glDeleteTextures(1, &strm->texture); 489 strm->texture = 0; 490 } 491 #endif 492 493 SDL_Quit(); 494 strm->screen = NULL; 495 } 496 497 return strm->status; 498 } 499 500 - (int)handle_event 501 { 502 sdl_fmt_info *sdl_info = get_sdl_format_info(strm->param.fmt.id); 503 const pjmedia_video_format_info *vfi; 504 pjmedia_video_format_detail *vfd; 505 506 vfi = pjmedia_get_video_format_info(pjmedia_video_format_mgr_instance(), 507 strm->param.fmt.id); 508 vfd = pjmedia_format_get_video_format_detail(&strm->param.fmt, PJ_TRUE); 509 #else 510 while(!strm->is_quitting) 511 #endif 512 { 391 513 SDL_Event sevent; 392 514 pjmedia_vid_event pevent; … … 397 519 * SDL_PumpEvents(). 398 520 */ 399 while (SDL_ WaitEvent(&sevent)) {521 while (SDL_PollEvent(&sevent)) { 400 522 pj_bzero(&pevent, sizeof(pevent)); 401 523 … … 405 527 pjmedia_format *fmt; 406 528 407 if (sevent.user.code == PJMEDIA_EVENT_NONE) 529 if (sevent.user.code == PJMEDIA_EVENT_NONE) { 530 strm->is_quitting = PJ_TRUE; 408 531 goto on_return; 532 } 409 533 410 534 pj_assert(sevent.user.code == PJMEDIA_VID_DEV_CAP_FORMAT); 411 535 412 fmt = (pjmedia_format *)sevent.user.data1; 536 PJ_TODO(FIX_THIS_FOR_OPENGL); 537 fmt = (pjmedia_format *)sevent.user.data1; 413 538 vfi = pjmedia_get_video_format_info( 414 415 539 pjmedia_video_format_mgr_instance(), 540 fmt->id); 416 541 if (!vfi || !sdl_info) { 417 542 strm->status = PJMEDIA_EVID_BADFORMAT; … … 466 591 } else if (vfi->color_model == PJMEDIA_COLOR_MODEL_YUV) { 467 592 strm->overlay = SDL_CreateYUVOverlay( 468 469 470 471 593 strm->rect.w, 594 strm->rect.h, 595 sdl_info->sdl_format, 596 strm->screen); 472 597 if (strm->overlay == NULL) { 473 598 strm->status = PJMEDIA_EVID_SYSERR; … … 487 612 if (strm->vid_cb.on_event_cb) 488 613 if ((*strm->vid_cb.on_event_cb)(&strm->base, 489 490 614 strm->user_data, 615 &pevent) != PJ_SUCCESS) 491 616 { 492 617 /* Application wants us to ignore this event */ … … 537 662 strm->is_quitting = PJ_TRUE; 538 663 if ((*strm->vid_cb.on_event_cb)(&strm->base, 539 540 664 strm->user_data, 665 &pevent) != PJ_SUCCESS) 541 666 { 542 667 /* Application wants us to ignore this event */ … … 557 682 */ 558 683 sdl_stream_stop(&strm->base); 559 SDL_Quit();560 strm->screen = NULL;561 684 goto on_return; 562 685 … … 564 687 break; 565 688 } 566 } 567 568 } 569 689 } 690 } 691 692 #if defined(PJ_DARWINOS) && PJ_DARWINOS!=0 693 return 0; 694 #endif 570 695 on_return: 696 if (strm->surf) { 697 SDL_FreeSurface(strm->surf); 698 strm->surf = NULL; 699 } 700 701 if (strm->overlay) { 702 SDL_FreeYUVOverlay(strm->overlay); 703 strm->overlay = NULL; 704 } 705 #if PJMEDIA_VIDEO_DEV_SDL_HAS_OPENGL 706 if (strm->texture) { 707 glDeleteTextures(1, &strm->texture); 708 strm->texture = 0; 709 } 710 #endif 711 712 SDL_Quit(); 713 strm->screen = NULL; 714 715 return strm->status; 716 } 717 571 718 #if defined(PJ_DARWINOS) && PJ_DARWINOS!=0 572 [apool release]; 573 #endif 719 - (pj_status_t)put_frame 720 { 721 const pjmedia_frame *frame = strm->frame; 722 #else 723 /* API: Put frame from stream */ 724 static pj_status_t sdl_stream_put_frame(pjmedia_vid_dev_stream *strm, 725 const pjmedia_frame *frame) 726 { 727 #endif 728 struct sdl_stream *stream = (struct sdl_stream*)strm; 729 pj_status_t status = PJ_SUCCESS; 730 731 if (!stream->is_running) { 732 stream->render_exited = PJ_TRUE; 733 goto on_return; 734 } 735 736 if (frame->size==0 || frame->buf==NULL) 737 goto on_return; 738 739 if (stream->surf) { 740 if (SDL_MUSTLOCK(stream->surf)) { 741 if (SDL_LockSurface(stream->surf) < 0) { 742 PJ_LOG(3, (THIS_FILE, "Unable to lock SDL surface")); 743 status = PJMEDIA_EVID_NOTREADY; 744 goto on_return; 745 } 746 } 747 748 pj_memcpy(stream->surf->pixels, frame->buf, frame->size); 749 750 if (SDL_MUSTLOCK(stream->surf)) { 751 SDL_UnlockSurface(stream->surf); 752 } 753 SDL_BlitSurface(stream->surf, NULL, stream->screen, NULL); 754 SDL_UpdateRect(stream->screen, 0, 0, 0, 0); 755 } else if (stream->overlay) { 756 int i, sz, offset; 757 758 if (SDL_LockYUVOverlay(stream->overlay) < 0) { 759 PJ_LOG(3, (THIS_FILE, "Unable to lock SDL overlay")); 760 status = PJMEDIA_EVID_NOTREADY; 761 goto on_return; 762 } 763 764 for (i = 0, offset = 0; i < stream->overlay->planes; i++) { 765 sz = stream->vafp.plane_bytes[i]; 766 pj_memcpy(stream->overlay->pixels[i], 767 (char *)frame->buf + offset, sz); 768 offset += sz; 769 } 770 771 SDL_UnlockYUVOverlay(stream->overlay); 772 SDL_DisplayYUVOverlay(stream->overlay, &stream->rect); 773 } 774 #if PJMEDIA_VIDEO_DEV_SDL_HAS_OPENGL 775 else if (stream->param.rend_id == OPENGL_DEV_IDX) { 776 if (frame && stream->texture) { 777 glBindTexture(GL_TEXTURE_2D, stream->texture); 778 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, 779 GL_NEAREST); 780 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, 781 GL_NEAREST); 782 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 783 stream->rect.w, stream->rect.h, 0, 784 GL_RGBA, GL_UNSIGNED_BYTE, frame->buf); 785 glBegin(GL_TRIANGLE_STRIP); 786 glTexCoord2f(0, 0); glVertex2i(0, 0); 787 glTexCoord2f(1, 0); glVertex2i(stream->rect.w, 0); 788 glTexCoord2f(0, 1); glVertex2i(0, stream->rect.h); 789 glTexCoord2f(1, 1); 790 glVertex2i(stream->rect.w, stream->rect.h); 791 glEnd(); 792 SDL_GL_SwapBuffers(); 793 } 794 } 795 #endif 796 797 on_return: 798 return status; 799 } 800 #if defined(PJ_DARWINOS) && PJ_DARWINOS!=0 801 @end 802 803 static pj_status_t sdl_stream_put_frame(pjmedia_vid_dev_stream *strm, 804 const pjmedia_frame *frame) 805 { 806 struct sdl_stream *stream = (struct sdl_stream*)strm; 807 stream->frame = frame; 808 [stream->delegate performSelectorOnMainThread:@selector(put_frame) 809 withObject:nil waitUntilDone:YES]; 810 811 return PJ_SUCCESS; 812 } 574 813 575 return strm->status; 576 } 814 static int sdlthread(void * data) 815 { 816 struct sdl_stream *strm = (struct sdl_stream*)data; 817 818 while(!strm->is_quitting) { 819 [strm->delegate performSelectorOnMainThread:@selector(handle_event) 820 withObject:nil waitUntilDone:YES]; 821 } 822 823 return 0; 824 } 825 826 #endif 577 827 578 828 /* API: create stream */ … … 605 855 /* Create render stream here */ 606 856 if (param->dir & PJMEDIA_DIR_RENDER) { 607 strm->status = PJ_SUCCESS; 608 status = pj_thread_create(pool, "sdl_thread", create_sdl_thread, 609 strm, 0, 0, &strm->sdl_thread); 610 if (status != PJ_SUCCESS) { 611 goto on_error; 612 } 613 while (strm->status == PJ_SUCCESS && !strm->surf && !strm->overlay) 614 pj_thread_sleep(10); 615 if ((status = strm->status) != PJ_SUCCESS) { 616 goto on_error; 617 } 618 619 pjmedia_format_copy(&strm->conv_param.src, ¶m->fmt); 620 pjmedia_format_copy(&strm->conv_param.dst, ¶m->fmt); 621 622 status = pjmedia_converter_create(NULL, pool, &strm->conv_param, 623 &strm->conv); 857 strm->status = PJ_SUCCESS; 858 #if defined(PJ_DARWINOS) && PJ_DARWINOS!=0 859 pj_assert(![NSThread isMainThread]); 860 strm->apool = [[NSAutoreleasePool alloc] init]; 861 strm->delegate = [[SDLDelegate alloc]init]; 862 strm->delegate->strm = strm; 863 [strm->delegate performSelectorOnMainThread:@selector(sdl_thread) 864 withObject:nil waitUntilDone:YES]; 865 if ((status = strm->status) != PJ_SUCCESS) { 866 goto on_error; 867 } 868 #endif 869 status = pj_thread_create(pool, "sdl_thread", sdlthread, 870 strm, 0, 0, &strm->sdl_thread); 871 872 if (status != PJ_SUCCESS) { 873 goto on_error; 874 } 875 876 while(strm->status == PJ_SUCCESS && !strm->surf && !strm->overlay 877 #if PJMEDIA_VIDEO_DEV_SDL_HAS_OPENGL 878 && !strm->texture 879 #endif 880 ) 881 { 882 pj_thread_sleep(10); 883 } 884 if ((status = strm->status) != PJ_SUCCESS) { 885 goto on_error; 886 } 887 888 pjmedia_format_copy(&strm->conv_param.src, ¶m->fmt); 889 pjmedia_format_copy(&strm->conv_param.dst, ¶m->fmt); 890 /* 891 status = pjmedia_converter_create(NULL, pool, &strm->conv_param, 892 &strm->conv); 893 */ 624 894 } 625 895 … … 627 897 if (param->flags & PJMEDIA_VID_DEV_CAP_OUTPUT_WINDOW) { 628 898 sdl_stream_set_cap(&strm->base, 629 630 899 PJMEDIA_VID_DEV_CAP_OUTPUT_WINDOW, 900 ¶m->window); 631 901 } 632 902 … … 652 922 pj_memcpy(pi, &strm->param, sizeof(*pi)); 653 923 654 /* if (sdl_stream_get_cap(s, PJMEDIA_VID_DEV_CAP_OUTPUT_WINDOW, 655 &pi->fmt.info_size) == PJ_SUCCESS) 924 /* 925 if (sdl_stream_get_cap(s, PJMEDIA_VID_DEV_CAP_OUTPUT_WINDOW, 926 &pi->fmt.info_size) == PJ_SUCCESS) 656 927 { 657 658 } 659 */928 pi->flags |= PJMEDIA_VID_DEV_CAP_OUTPUT_WINDOW; 929 } 930 */ 660 931 return PJ_SUCCESS; 661 932 } … … 676 947 return PJ_SUCCESS; 677 948 } else if (cap == PJMEDIA_VID_DEV_CAP_FORMAT) { 678 949 return PJ_SUCCESS; 679 950 } else { 680 951 return PJMEDIA_EVID_INVCAP; … … 696 967 return PJ_SUCCESS; 697 968 } else if (cap == PJMEDIA_VID_DEV_CAP_FORMAT) { 698 SDL_Event sevent; 699 700 strm->status = PJ_TRUE; 701 sevent.type = SDL_USEREVENT; 702 sevent.user.code = PJMEDIA_VID_DEV_CAP_FORMAT; 703 sevent.user.data1 = (void *)pval; 704 SDL_PushEvent(&sevent); 705 706 while (strm->status == PJ_TRUE) 707 pj_thread_sleep(10); 708 709 if (strm->status != PJ_SUCCESS) { 710 pj_status_t status = strm->status; 711 712 /** 713 * Failed to change the output format. Try to revert 714 * to its original format. 715 */ 716 strm->status = PJ_TRUE; 717 sevent.user.data1 = &strm->param.fmt; 718 SDL_PushEvent(&sevent); 719 720 while (strm->status == PJ_TRUE) 721 pj_thread_sleep(10); 722 723 if (strm->status != PJ_SUCCESS) 724 /** 725 * This means that we failed to revert to our 726 * original state! 727 */ 728 status = PJMEDIA_EVID_ERR; 729 730 strm->status = status; 731 } else if (strm->status == PJ_SUCCESS) { 732 pj_memcpy(&strm->param.fmt, pval, sizeof(strm->param.fmt)); 733 } 734 735 return strm->status; 969 SDL_Event sevent; 970 971 strm->status = PJ_TRUE; 972 sevent.type = SDL_USEREVENT; 973 sevent.user.code = PJMEDIA_VID_DEV_CAP_FORMAT; 974 sevent.user.data1 = (void *)pval; 975 SDL_PushEvent(&sevent); 976 977 while (strm->status == PJ_TRUE) 978 pj_thread_sleep(10); 979 980 if (strm->status != PJ_SUCCESS) { 981 pj_status_t status = strm->status; 982 983 /** 984 * Failed to change the output format. Try to revert 985 * to its original format. 986 */ 987 strm->status = PJ_TRUE; 988 sevent.user.data1 = &strm->param.fmt; 989 SDL_PushEvent(&sevent); 990 991 while (strm->status == PJ_TRUE) 992 pj_thread_sleep(10); 993 994 if (strm->status != PJ_SUCCESS) { 995 /** 996 * This means that we failed to revert to our 997 * original state! 998 */ 999 status = PJMEDIA_EVID_ERR; 1000 } 1001 1002 strm->status = status; 1003 } else if (strm->status == PJ_SUCCESS) { 1004 pj_memcpy(&strm->param.fmt, pval, sizeof(strm->param.fmt)); 1005 } 1006 1007 return strm->status; 736 1008 } 737 1009 738 1010 return PJMEDIA_EVID_INVCAP; 739 }740 741 /* API: Put frame from stream */742 static pj_status_t sdl_stream_put_frame(pjmedia_vid_dev_stream *strm,743 const pjmedia_frame *frame)744 {745 struct sdl_stream *stream = (struct sdl_stream*)strm;746 pj_status_t status = PJ_SUCCESS;747 #if defined(PJ_DARWINOS) && PJ_DARWINOS!=0748 NSAutoreleasePool *apool = [[NSAutoreleasePool alloc] init];749 #endif750 751 if (!stream->is_running) {752 stream->render_exited = PJ_TRUE;753 goto on_return;754 }755 756 if (frame->size==0 || frame->buf==NULL)757 goto on_return;758 759 if (stream->surf) {760 if (SDL_MUSTLOCK(stream->surf)) {761 if (SDL_LockSurface(stream->surf) < 0) {762 PJ_LOG(3, (THIS_FILE, "Unable to lock SDL surface"));763 status = PJMEDIA_EVID_NOTREADY;764 goto on_return;765 }766 }767 768 pj_memcpy(stream->surf->pixels, frame->buf, frame->size);769 770 if (SDL_MUSTLOCK(stream->surf)) {771 SDL_UnlockSurface(stream->surf);772 }773 SDL_BlitSurface(stream->surf, NULL, stream->screen, NULL);774 SDL_UpdateRect(stream->screen, 0, 0, 0, 0);775 } else if (stream->overlay) {776 int i, sz, offset;777 778 if (SDL_LockYUVOverlay(stream->overlay) < 0) {779 PJ_LOG(3, (THIS_FILE, "Unable to lock SDL overlay"));780 status = PJMEDIA_EVID_NOTREADY;781 goto on_return;782 }783 784 for (i = 0, offset = 0; i < stream->overlay->planes; i++) {785 sz = stream->vafp.plane_bytes[i];786 pj_memcpy(stream->overlay->pixels[i],787 (char *)frame->buf + offset, sz);788 offset += sz;789 }790 791 SDL_UnlockYUVOverlay(stream->overlay);792 SDL_DisplayYUVOverlay(stream->overlay, &stream->rect);793 }794 795 on_return:796 #if defined(PJ_DARWINOS) && PJ_DARWINOS!=0797 [apool release];798 #endif799 800 return status;801 1011 } 802 1012 … … 839 1049 PJ_ASSERT_RETURN(stream != NULL, PJ_EINVAL); 840 1050 1051 sdl_stream_stop(strm); 1052 841 1053 if (!stream->is_quitting) { 842 sevent.type = SDL_USEREVENT; 843 sevent.user.code = PJMEDIA_EVENT_NONE; 844 SDL_PushEvent(&sevent); 845 pj_thread_join(stream->sdl_thread); 846 } 847 848 sdl_stream_stop(strm); 849 850 if (stream->surf) { 851 SDL_FreeSurface(stream->surf); 852 stream->surf = NULL; 853 } 854 855 if (stream->overlay) { 856 SDL_FreeYUVOverlay(stream->overlay); 857 stream->overlay = NULL; 858 } 859 860 SDL_Quit(); 861 stream->screen = NULL; 862 1054 sevent.type = SDL_USEREVENT; 1055 sevent.user.code = PJMEDIA_EVENT_NONE; 1056 SDL_PushEvent(&sevent); 1057 if (stream->sdl_thread) 1058 pj_thread_join(stream->sdl_thread); 1059 } 1060 1061 #if defined(PJ_DARWINOS) && PJ_DARWINOS!=0 1062 if (stream->delegate) 1063 [stream->delegate release]; 1064 if (stream->apool) 1065 [stream->apool release]; 1066 #endif 863 1067 pj_pool_release(stream->pool); 1068 864 1069 865 1070 return PJ_SUCCESS; … … 868 1073 #ifdef _MSC_VER 869 1074 # pragma comment( lib, "sdl.lib") 1075 # if PJMEDIA_VIDEO_DEV_SDL_HAS_OPENGL 1076 # pragma comment(lib, "OpenGL32.lib") 1077 # endif 870 1078 #endif 871 1079 -
pjproject/branches/projects/2.0-dev/pjmedia/src/test/test.c
r3395 r3499 20 20 #include "test.h" 21 21 22 #if defined(PJ_DARWINOS) && PJ_DARWINOS!=0 23 # include <CoreFoundation/CFRunLoop.h> 24 #endif 25 22 26 #define THIS_FILE "test.c" 23 27 … … 33 37 34 38 pj_pool_factory *mem; 35 39 pj_bool_t is_quit = PJ_FALSE; 40 pj_thread_t *thread; 41 pj_caching_pool caching_pool; 42 pj_pool_t *pool; 36 43 37 44 void app_perror(pj_status_t status, const char *msg) … … 44 51 } 45 52 46 int test_main(void)53 static int test_func(void *data) 47 54 { 48 55 int rc = 0; 49 pj_caching_pool caching_pool;50 pj_pool_t *pool;51 52 pj_init();53 pj_caching_pool_init(&caching_pool, &pj_pool_factory_default_policy, 0);54 pool = pj_pool_create(&caching_pool.factory, "test", 1000, 512, NULL);55 56 56 pj_log_set_decor(PJ_LOG_HAS_NEWLINE);57 pj_log_set_level(3);58 59 mem = &caching_pool.factory;60 61 pjmedia_video_format_mgr_create(pool, 64, 0, NULL);62 pjmedia_converter_mgr_create(pool, NULL);63 pjmedia_vid_codec_mgr_create(pool, NULL);64 65 57 #if HAS_VID_DEV_TEST 66 58 DO_TEST(vid_dev_test()); 67 59 #endif 68 60 69 61 #if HAS_VID_CODEC_TEST 70 62 DO_TEST(vid_codec_test()); 71 63 #endif 72 64 73 65 #if HAS_SDP_NEG_TEST 74 66 DO_TEST(sdp_neg_test()); … … 86 78 DO_TEST(codec_test_vectors()); 87 79 #endif 88 80 89 81 PJ_LOG(3,(THIS_FILE," ")); 90 82 91 83 on_return: 92 84 if (rc != 0) { … … 95 87 PJ_LOG(3,(THIS_FILE,"Looks like everything is okay!")); 96 88 } 89 90 is_quit = PJ_TRUE; 91 return rc; 92 } 93 94 int test_main(void) 95 { 96 int rc = 0; 97 98 pj_init(); 99 pj_caching_pool_init(&caching_pool, &pj_pool_factory_default_policy, 0); 100 pool = pj_pool_create(&caching_pool.factory, "test", 1000, 512, NULL); 101 102 pj_log_set_decor(PJ_LOG_HAS_NEWLINE); 103 pj_log_set_level(3); 104 105 mem = &caching_pool.factory; 106 107 pjmedia_video_format_mgr_create(pool, 64, 0, NULL); 108 pjmedia_converter_mgr_create(pool, NULL); 109 pjmedia_vid_codec_mgr_create(pool, NULL); 110 111 #if defined(PJ_DARWINOS) && PJ_DARWINOS!=0 112 { 113 if (pj_thread_create(pool, "test_func", test_func, NULL, 0, 0, 114 &thread) == PJ_SUCCESS) { 115 while (!is_quit) { 116 CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0, false); 117 } 118 } 119 return 0; 120 } 121 #else 122 rc = test_func(NULL); 123 #endif 97 124 98 125 pjmedia_video_format_mgr_destroy(pjmedia_video_format_mgr_instance()); -
pjproject/branches/projects/2.0-dev/pjmedia/src/test/vid_dev_test.c
r3488 r3499 186 186 /* Sleep while the webcam is being displayed... */ 187 187 for (i = 0; i < LOOP_DURATION*10 && (!is_quitting); i++) { 188 #if VID_DEV_TEST_MAC_OS189 CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0, false);190 #endif191 188 pj_thread_sleep(100); 192 189 }
Note: See TracChangeset
for help on using the changeset viewer.