Changeset 3578
- Timestamp:
- Jun 6, 2011 11:11:35 AM (13 years ago)
- Location:
- pjproject/branches/projects/2.0-dev/pjmedia/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia-videodev/sdl_dev.c
r3577 r3578 43 43 #define DEFAULT_FPS 25 44 44 45 #if !(SDL_VERSION_ATLEAST(1,3,0)) 46 # define SDL_PIXELFORMAT_RGBA8888 0 47 # define SDL_PIXELFORMAT_RGB24 0 48 # define SDL_PIXELFORMAT_BGRA8888 0 49 # define SDL_PIXELFORMAT_ABGR8888 0 50 # define SDL_PIXELFORMAT_BGR24 0 51 # define SDL_PIXELFORMAT_ARGB8888 0 52 # define SDL_PIXELFORMAT_RGB24 0 53 #endif 45 54 46 55 typedef struct sdl_fmt_info … … 57 66 { 58 67 #if PJ_IS_BIG_ENDIAN 59 {PJMEDIA_FORMAT_RGBA, SDL_PIXELFORMAT_RGBA8888,68 {PJMEDIA_FORMAT_RGBA, (Uint32)SDL_PIXELFORMAT_RGBA8888, 60 69 0xFF000000, 0xFF0000, 0xFF00, 0xFF} , 61 {PJMEDIA_FORMAT_RGB24, SDL_PIXELFORMAT_RGB24,70 {PJMEDIA_FORMAT_RGB24, (Uint32)SDL_PIXELFORMAT_RGB24, 62 71 0xFF0000, 0xFF00, 0xFF, 0} , 63 {PJMEDIA_FORMAT_BGRA, SDL_PIXELFORMAT_BGRA8888,72 {PJMEDIA_FORMAT_BGRA, (Uint32)SDL_PIXELFORMAT_BGRA8888, 64 73 0xFF00, 0xFF0000, 0xFF000000, 0xFF} , 65 74 #else 66 {PJMEDIA_FORMAT_RGBA, SDL_PIXELFORMAT_ABGR8888,75 {PJMEDIA_FORMAT_RGBA, (Uint32)SDL_PIXELFORMAT_ABGR8888, 67 76 0xFF, 0xFF00, 0xFF0000, 0xFF000000} , 68 {PJMEDIA_FORMAT_RGB24, SDL_PIXELFORMAT_BGR24,77 {PJMEDIA_FORMAT_RGB24, (Uint32)SDL_PIXELFORMAT_BGR24, 69 78 0xFF, 0xFF00, 0xFF0000, 0} , 70 {PJMEDIA_FORMAT_BGRA, SDL_PIXELFORMAT_ARGB8888,79 {PJMEDIA_FORMAT_BGRA, (Uint32)SDL_PIXELFORMAT_ARGB8888, 71 80 0xFF0000, 0xFF00, 0xFF, 0xFF000000} , 72 81 #endif 73 82 74 {PJMEDIA_FORMAT_DIB ,SDL_PIXELFORMAT_RGB24,83 {PJMEDIA_FORMAT_DIB , (Uint32)SDL_PIXELFORMAT_RGB24, 75 84 0xFF0000, 0xFF00, 0xFF, 0} , 76 85 … … 138 147 pj_status_t status; 139 148 pjmedia_format *new_fmt; 149 pjmedia_rect_size *new_disp_size; 140 150 141 151 #if SDL_VERSION_ATLEAST(1,3,0) … … 145 155 int pitch; /**< Pitch value. */ 146 156 #endif 147 SDL_Rect rect; /**< Display rectangle. */ 157 SDL_Rect rect; /**< Frame rectangle. */ 158 SDL_Rect dstrect; /**< Display rectangle. */ 148 159 SDL_Surface *screen; /**< Display screen. */ 149 160 SDL_Surface *surf; /**< RGB surface. */ … … 260 271 unsigned i, j; 261 272 273 #if SDL_VERSION_ATLEAST(1,3,0) 262 274 #if defined(PJ_DARWINOS) && PJ_DARWINOS!=0 263 275 sf->apool = [[NSAutoreleasePool alloc] init]; … … 267 279 #else 268 280 /* Initialize the SDL library */ 269 if (SDL_Init(SDL_INIT_VIDEO)) { 270 PJ_LOG(4, (THIS_FILE, "Cannot initialize SDL")); 281 if (SDL_Init(SDL_INIT_VIDEO)) 271 282 return PJMEDIA_EVID_INIT; 272 } 283 #endif 273 284 #endif 274 285 … … 332 343 pj_pool_release(pool); 333 344 345 #if SDL_VERSION_ATLEAST(1,3,0) 334 346 #if defined(PJ_DARWINOS) && PJ_DARWINOS!=0 335 347 [sf->delegate performSelectorOnMainThread:@selector(sdl_quit) … … 339 351 #else 340 352 SDL_Quit(); 353 #endif 341 354 #endif 342 355 … … 420 433 static void destroy_sdl(struct sdl_stream *strm, pj_bool_t destroy_win) 421 434 { 435 PJ_UNUSED_ARG(destroy_win); 436 422 437 if (strm->surf) { 423 438 SDL_FreeSurface(strm->surf); … … 482 497 strm->rect.w = (Uint16)vfd->size.w; 483 498 strm->rect.h = (Uint16)vfd->size.h; 499 if (strm->param.disp_size.w == 0) 500 strm->param.disp_size.w = strm->rect.w; 501 if (strm->param.disp_size.h == 0) 502 strm->param.disp_size.h = strm->rect.h; 503 strm->dstrect.x = strm->dstrect.y = 0; 504 strm->dstrect.w = (Uint16)strm->param.disp_size.w; 505 strm->dstrect.h = (Uint16)strm->param.disp_size.h; 484 506 485 507 destroy_sdl(strm, PJ_FALSE); … … 500 522 SDL_WINDOWPOS_CENTERED, 501 523 SDL_WINDOWPOS_CENTERED, 502 strm->rect.w, strm->rect.h, 524 strm->param.disp_size.w, 525 strm->param.disp_size.h, 503 526 flags); 504 527 } … … 507 530 } 508 531 509 SDL_SetWindowSize(strm->window, strm->rect.w, strm->rect.h); 532 SDL_SetWindowSize(strm->window, strm->param.disp_size.w, 533 strm->param.disp_size.h); 510 534 511 535 /** … … 529 553 530 554 #else 531 532 555 /* Initialize the display */ 533 strm->screen = SDL_SetVideoMode(strm->rect.w, strm->rect.h, 0, ( 556 strm->screen = SDL_SetVideoMode(strm->param.disp_size.w, 557 strm->param.disp_size.h, 0, ( 534 558 #if PJMEDIA_VIDEO_DEV_SDL_HAS_OPENGL 535 559 strm->param.rend_id == OPENGL_DEV_IDX? … … 552 576 553 577 /* Init the viewport */ 554 glViewport(0, 0, strm-> rect.w, strm->rect.h);578 glViewport(0, 0, strm->param.disp_size.w, strm->param.disp_size.h); 555 579 glMatrixMode(GL_PROJECTION); 556 580 glLoadIdentity(); 557 581 558 glOrtho(0.0, (GLdouble)strm-> rect.w, (GLdouble)strm->rect.h,559 582 glOrtho(0.0, (GLdouble)strm->param.disp_size.w, 583 (GLdouble)strm->param.disp_size.h, 0.0, 0.0, 1.0); 560 584 561 585 glMatrixMode(GL_MODELVIEW); … … 617 641 static void detect_fmt_change(struct sdl_stream *strm) 618 642 { 619 if (strm->new_fmt ) {643 if (strm->new_fmt || strm->new_disp_size) { 620 644 /* Stop the stream */ 621 645 sdl_stream_stop((pjmedia_vid_dev_stream *)strm); 622 646 647 if (strm->new_disp_size) 648 pj_memcpy(&strm->param.disp_size, strm->new_disp_size, 649 sizeof(strm->param.disp_size)); 650 623 651 /* Re-initialize SDL */ 624 strm->status = init_sdl(strm, strm->new_fmt); 652 strm->status = init_sdl(strm, (strm->new_fmt? strm->new_fmt : 653 &strm->param.fmt)); 625 654 626 655 if (strm->status == PJ_SUCCESS) { 627 pjmedia_format_copy(&strm->param.fmt, strm->new_fmt); 656 if (strm->new_fmt) 657 pjmedia_format_copy(&strm->param.fmt, strm->new_fmt); 628 658 /* Restart the stream */ 629 659 sdl_stream_start((pjmedia_vid_dev_stream *)strm); 630 660 } 631 661 strm->new_fmt = NULL; 662 strm->new_disp_size = NULL; 632 663 } 633 664 } … … 658 689 { 659 690 struct sdl_stream *strm = (struct sdl_stream*)data; 691 #endif 692 693 #if !(SDL_VERSION_ATLEAST(1,3,0)) 694 if (SDL_Init(SDL_INIT_VIDEO)) { 695 strm->status = PJMEDIA_EVID_INIT; 696 goto on_return; 697 } 660 698 #endif 661 699 … … 674 712 if (strm->status != PJ_SUCCESS) { 675 713 destroy_sdl(strm, PJ_TRUE); 714 #if !(SDL_VERSION_ATLEAST(1,3,0)) 715 SDL_Quit(); 716 #endif 676 717 strm->screen = NULL; 677 718 } … … 721 762 case SDL_MOUSEBUTTONDOWN: 722 763 pevent.event_type = PJMEDIA_EVENT_MOUSEBUTTONDOWN; 764 break; 765 #if SDL_VERSION_ATLEAST(1,3,0) 766 case SDL_WINDOWEVENT: 767 switch (sevent.window.event) { 768 case SDL_WINDOWEVENT_RESIZED: 769 pevent.event_type = PJMEDIA_EVENT_WINDOW_RESIZE; 770 pevent.event_desc.resize.new_size.w = 771 sevent.window.data1; 772 pevent.event_desc.resize.new_size.h = 773 sevent.window.data2; 774 break; 775 } 776 break; 777 #else 778 case SDL_VIDEORESIZE: 779 pevent.event_type = PJMEDIA_EVENT_WINDOW_RESIZE; 780 pevent.event_desc.resize.new_size.w = sevent.resize.w; 781 pevent.event_desc.resize.new_size.h = sevent.resize.h; 782 break; 783 case SDL_QUIT: 784 pevent.event_type = PJMEDIA_EVENT_WINDOW_CLOSE; 785 #endif 786 } 787 788 switch (pevent.event_type) { 789 case PJMEDIA_EVENT_MOUSEBUTTONDOWN: 723 790 if (strm->vid_cb.on_event_cb) 724 791 if ((*strm->vid_cb.on_event_cb)(&strm->base, … … 729 796 break; 730 797 } 731 if (strm->is_running)732 pjmedia_vid_dev_stream_stop(&strm->base);733 else734 pjmedia_vid_dev_stream_start(&strm->base);735 798 break; 736 799 737 case SDL_VIDEORESIZE: 738 pevent.event_type = PJMEDIA_EVENT_WINDOW_RESIZE; 739 pevent.event_desc.resize.new_size.w = sevent.resize.w; 740 pevent.event_desc.resize.new_size.h = sevent.resize.h; 800 case PJMEDIA_EVENT_WINDOW_RESIZE: 741 801 if (strm->vid_cb.on_event_cb) { 742 /** 743 * To process PJMEDIA_EVENT_WINDOW_RESIZE event, 744 * application should do this in the on_event_cb 745 * callback: 746 * 1. change the input frame size given to SDL 747 * to the new size. 748 * 2. call pjmedia_vid_dev_stream_set_cap() 749 * using PJMEDIA_VID_DEV_CAP_FORMAT capability 750 * and the new format size 751 */ 752 (*strm->vid_cb.on_event_cb)(&strm->base, 753 strm->user_data, 754 &pevent); 802 if ((*strm->vid_cb.on_event_cb)(&strm->base, 803 strm->user_data, 804 &pevent) != PJ_SUCCESS) 805 { 806 break; 807 } 755 808 } 809 strm->new_disp_size = &pevent.event_desc.resize.new_size; 810 detect_fmt_change(strm); 756 811 break; 757 812 758 case SDL_QUIT: 759 pevent.event_type = PJMEDIA_EVENT_WINDOW_CLOSE; 813 case PJMEDIA_EVENT_WINDOW_CLOSE: 760 814 /** 761 815 * To process PJMEDIA_EVENT_WINDOW_CLOSE event, … … 806 860 on_return: 807 861 destroy_sdl(strm, PJ_TRUE); 862 #if !(SDL_VERSION_ATLEAST(1,3,0)) 863 SDL_Quit(); 864 #endif 808 865 strm->screen = NULL; 809 866 … … 823 880 glBegin(GL_TRIANGLE_STRIP); 824 881 glTexCoord2f(0, 0); glVertex2i(0, 0); 825 glTexCoord2f(1, 0); glVertex2i(stream->rect.w, 0); 826 glTexCoord2f(0, 1); glVertex2i(0, stream->rect.h); 827 glTexCoord2f(1, 1); glVertex2i(stream->rect.w, stream->rect.h); 882 glTexCoord2f(1, 0); glVertex2i(stream->param.disp_size.w, 0); 883 glTexCoord2f(0, 1); glVertex2i(0, stream->param.disp_size.h); 884 glTexCoord2f(1, 1); 885 glVertex2i(stream->param.disp_size.w, stream->param.disp_size.h); 828 886 glEnd(); 829 887 #if SDL_VERSION_ATLEAST(1,3,0) … … 873 931 SDL_UnlockSurface(stream->surf); 874 932 } 875 SDL_BlitSurface(stream->surf, NULL, stream->screen, NULL);933 SDL_BlitSurface(stream->surf, NULL, stream->screen, &stream->dstrect); 876 934 #if SDL_VERSION_ATLEAST(1,3,0) 877 935 SDL_UpdateWindowSurface(stream->window); … … 896 954 897 955 SDL_UnlockYUVOverlay(stream->overlay); 898 SDL_DisplayYUVOverlay(stream->overlay, &stream-> rect);956 SDL_DisplayYUVOverlay(stream->overlay, &stream->dstrect); 899 957 } 900 958 #if SDL_VERSION_ATLEAST(1,3,0) … … 1108 1166 strm->new_fmt = &strm->param.fmt; 1109 1167 #if defined(PJ_DARWINOS) && PJ_DARWINOS!=0 1110 [strm->delegate performSelectorOnMainThread:@selector(detect_new_fmt) 1168 [strm->delegate performSelectorOnMainThread: 1169 @selector(detect_new_fmt) 1111 1170 withObject:nil waitUntilDone:YES]; 1112 1171 #endif … … 1126 1185 1127 1186 return strm->status; 1187 } else if (cap == PJMEDIA_VID_DEV_CAP_OUTPUT_RESIZE) { 1188 strm->new_disp_size = (pjmedia_rect_size *)pval; 1189 #if defined(PJ_DARWINOS) && PJ_DARWINOS!=0 1190 [strm->delegate performSelectorOnMainThread: 1191 @selector(detect_new_fmt) 1192 withObject:nil waitUntilDone:YES]; 1193 #endif 1194 while (strm->new_disp_size) 1195 pj_thread_sleep(10); 1196 1197 return strm->status; 1128 1198 } 1129 1199 -
pjproject/branches/projects/2.0-dev/pjmedia/src/test/vid_dev_test.c
r3499 r3578 83 83 is_quitting = PJ_TRUE; 84 84 85 /* We will handle the event on our own, so return non-PJ_SUCCESS here */ 86 return -1; 85 return PJ_SUCCESS; 87 86 } 88 87
Note: See TracChangeset
for help on using the changeset viewer.