- Timestamp:
- Mar 1, 2011 3:55:34 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia-videodev/sdl_dev.c
r3420 r3431 392 392 pjmedia_vid_event pevent; 393 393 394 /** 395 * The event polling must be placed in the same thread that 396 * call SDL_SetVideoMode(). Please consult the official doc of 397 * SDL_PumpEvents(). 398 */ 394 399 while (SDL_WaitEvent(&sevent)) { 395 400 pj_bzero(&pevent, sizeof(pevent)); … … 397 402 switch(sevent.type) { 398 403 case SDL_USEREVENT: 399 goto on_return; 404 { 405 pjmedia_format *fmt; 406 407 if (sevent.user.code == PJMEDIA_EVENT_NONE) 408 goto on_return; 409 410 pj_assert(sevent.user.code == PJMEDIA_VID_DEV_CAP_FORMAT); 411 412 fmt = (pjmedia_format *)sevent.user.data1; 413 vfi = pjmedia_get_video_format_info( 414 pjmedia_video_format_mgr_instance(), 415 fmt->id); 416 if (!vfi || !sdl_info) { 417 strm->status = PJMEDIA_EVID_BADFORMAT; 418 break; 419 } 420 421 vfd = pjmedia_format_get_video_format_detail(fmt, PJ_TRUE); 422 strm->vafp.size = vfd->size; 423 strm->vafp.buffer = NULL; 424 if (vfi->apply_fmt(vfi, &strm->vafp) != PJ_SUCCESS) { 425 strm->status = PJMEDIA_EVID_BADFORMAT; 426 break; 427 } 428 429 strm->rect.w = (Uint16)vfd->size.w; 430 strm->rect.h = (Uint16)vfd->size.h; 431 432 /* Stop the stream */ 433 sdl_stream_stop((pjmedia_vid_dev_stream *)strm); 434 435 /* Initialize the display, requesting a software surface */ 436 strm->screen = SDL_SetVideoMode(strm->rect.w, 437 strm->rect.h, 0, 438 SDL_RESIZABLE | 439 SDL_SWSURFACE); 440 if (strm->screen == NULL) { 441 strm->status = PJMEDIA_EVID_SYSERR; 442 break; 443 } 444 445 if (strm->surf) 446 SDL_FreeSurface(strm->surf); 447 if (strm->overlay) 448 SDL_FreeYUVOverlay(strm->overlay); 449 450 if (vfi->color_model == PJMEDIA_COLOR_MODEL_RGB) { 451 strm->surf = SDL_CreateRGBSurface(SDL_SWSURFACE, 452 strm->rect.w, 453 strm->rect.h, 454 vfi->bpp, 455 sdl_info->Rmask, 456 sdl_info->Gmask, 457 sdl_info->Bmask, 458 sdl_info->Amask); 459 if (strm->surf == NULL) { 460 strm->status = PJMEDIA_EVID_SYSERR; 461 break; 462 } 463 } else if (vfi->color_model == PJMEDIA_COLOR_MODEL_YUV) { 464 strm->overlay = SDL_CreateYUVOverlay( 465 strm->rect.w, 466 strm->rect.h, 467 sdl_info->sdl_format, 468 strm->screen); 469 if (strm->overlay == NULL) { 470 strm->status = PJMEDIA_EVID_SYSERR; 471 break; 472 } 473 } 474 475 /* Restart the stream */ 476 sdl_stream_start((pjmedia_vid_dev_stream *)strm); 477 478 strm->status = PJ_SUCCESS; 479 break; 480 } 481 400 482 case SDL_MOUSEBUTTONDOWN: 401 483 pevent.event_type = PJMEDIA_EVENT_MOUSEBUTTONDOWN; … … 413 495 pjmedia_vid_dev_stream_start(&strm->base); 414 496 break; 497 415 498 case SDL_VIDEORESIZE: 416 499 pevent.event_type = PJMEDIA_EVENT_WINDOW_RESIZE; 417 if (strm->vid_cb.on_event_cb) 418 if ((*strm->vid_cb.on_event_cb)(&strm->base, 419 strm->user_data, 420 &pevent) != PJ_SUCCESS) 421 { 422 /* Application wants us to ignore this event */ 423 break; 424 } 425 /* TODO: move this to OUTPUT_RESIZE cap 426 strm->screen = SDL_SetVideoMode(sevent.resize.w, 427 sevent.resize.h, 428 0, SDL_RESIZABLE | 429 SDL_SWSURFACE); 430 */ 500 pevent.event_desc.resize.new_size.w = sevent.resize.w; 501 pevent.event_desc.resize.new_size.h = sevent.resize.h; 502 if (strm->vid_cb.on_event_cb) { 503 /** 504 * To process PJMEDIA_EVENT_WINDOW_RESIZE event, 505 * application should do this in the on_event_cb 506 * callback: 507 * 1. change the input frame size given to SDL 508 * to the new size. 509 * 2. call pjmedia_vid_dev_stream_set_cap() 510 * using PJMEDIA_VID_DEV_CAP_FORMAT capability 511 * and the new format size 512 */ 513 (*strm->vid_cb.on_event_cb)(&strm->base, 514 strm->user_data, 515 &pevent); 516 } 431 517 break; 518 432 519 case SDL_QUIT: 433 520 pevent.event_type = PJMEDIA_EVENT_WINDOW_CLOSE; … … 470 557 strm->screen = NULL; 471 558 goto on_return; 559 472 560 default: 473 561 break; … … 581 669 PJ_ASSERT_RETURN(s && pval, PJ_EINVAL); 582 670 583 if (cap ==PJMEDIA_VID_DEV_CAP_OUTPUT_WINDOW)671 if (cap == PJMEDIA_VID_DEV_CAP_OUTPUT_WINDOW) 584 672 { 585 673 return PJ_SUCCESS; 674 } else if (cap == PJMEDIA_VID_DEV_CAP_FORMAT) { 675 return PJ_SUCCESS; 586 676 } else { 587 677 return PJMEDIA_EVID_INVCAP; … … 600 690 PJ_ASSERT_RETURN(s && pval, PJ_EINVAL); 601 691 602 if (cap==PJMEDIA_VID_DEV_CAP_OUTPUT_WINDOW) 603 { 692 if (cap == PJMEDIA_VID_DEV_CAP_OUTPUT_WINDOW) { 604 693 return PJ_SUCCESS; 694 } else if (cap == PJMEDIA_VID_DEV_CAP_FORMAT) { 695 SDL_Event sevent; 696 697 strm->status = PJ_TRUE; 698 sevent.type = SDL_USEREVENT; 699 sevent.user.code = PJMEDIA_VID_DEV_CAP_FORMAT; 700 sevent.user.data1 = (void *)pval; 701 SDL_PushEvent(&sevent); 702 703 while (strm->status == PJ_TRUE) 704 pj_thread_sleep(10); 705 706 if (strm->status != PJ_SUCCESS) { 707 pj_status_t status = strm->status; 708 709 /** 710 * Failed to change the output format. Try to revert 711 * to its original format. 712 */ 713 strm->status = PJ_TRUE; 714 sevent.user.data1 = &strm->param.fmt; 715 SDL_PushEvent(&sevent); 716 717 while (strm->status == PJ_TRUE) 718 pj_thread_sleep(10); 719 720 if (strm->status != PJ_SUCCESS) 721 /** 722 * This means that we failed to revert to our 723 * original state! 724 */ 725 status = PJMEDIA_EVID_ERR; 726 727 strm->status = status; 728 } else if (strm->status == PJ_SUCCESS) { 729 pj_memcpy(&strm->param.fmt, pval, sizeof(strm->param.fmt)); 730 } 731 732 return strm->status; 605 733 } 606 734 … … 707 835 if (!stream->is_quitting) { 708 836 sevent.type = SDL_USEREVENT; 837 sevent.user.code = PJMEDIA_EVENT_NONE; 709 838 SDL_PushEvent(&sevent); 710 839 pj_thread_join(stream->sdl_thread);
Note: See TracChangeset
for help on using the changeset viewer.