| | 379 | |
|---|
| | 380 | /***************************************************************************** |
|---|
| | 381 | * Destroy: destroy FB video thread output method |
|---|
| | 382 | ***************************************************************************** |
|---|
| | 383 | * Terminate an output method created by Create |
|---|
| | 384 | *****************************************************************************/ |
|---|
| | 385 | static void Destroy( vlc_object_t *p_this ) |
|---|
| | 386 | { |
|---|
| | 387 | vout_thread_t *p_vout = (vout_thread_t *)p_this; |
|---|
| | 388 | |
|---|
| | 389 | CloseDisplay( p_vout ); |
|---|
| | 390 | |
|---|
| | 391 | if( p_vout->p_sys->b_tty ) |
|---|
| | 392 | { |
|---|
| | 393 | /* Reset the terminal */ |
|---|
| | 394 | ioctl( p_vout->p_sys->i_tty, VT_SETMODE, &p_vout->p_sys->vt_mode ); |
|---|
| | 395 | |
|---|
| | 396 | /* Remove signal handlers */ |
|---|
| | 397 | sigaction( SIGUSR1, &p_vout->p_sys->sig_usr1, NULL ); |
|---|
| | 398 | sigaction( SIGUSR2, &p_vout->p_sys->sig_usr2, NULL ); |
|---|
| | 399 | |
|---|
| | 400 | /* Reset the keyboard state */ |
|---|
| | 401 | tcsetattr( 0, 0, &p_vout->p_sys->old_termios ); |
|---|
| | 402 | |
|---|
| | 403 | /* Return to text mode */ |
|---|
| | 404 | TextMode( p_vout->p_sys->i_tty ); |
|---|
| | 405 | } |
|---|
| | 406 | |
|---|
| | 407 | /* Destroy structure */ |
|---|
| | 408 | free( p_vout->p_sys ); |
|---|
| | 409 | } |
|---|
| | 410 | |
|---|
| | 411 | /***************************************************************************** |
|---|
| | 412 | * NewPicture: allocate a picture |
|---|
| | 413 | ***************************************************************************** |
|---|
| | 414 | * Returns 0 on success, -1 otherwise |
|---|
| | 415 | *****************************************************************************/ |
|---|
| | 416 | static int NewPicture( vout_thread_t *p_vout, picture_t *p_pic ) |
|---|
| | 417 | { |
|---|
| | 418 | /* We know the chroma, allocate a buffer which will be used |
|---|
| | 419 | * directly by the decoder */ |
|---|
| | 420 | p_pic->p_sys = malloc( sizeof( picture_sys_t ) ); |
|---|
| | 421 | if( p_pic->p_sys == NULL ) |
|---|
| | 422 | { |
|---|
| | 423 | return VLC_ENOMEM; |
|---|
| | 424 | } |
|---|
| | 425 | |
|---|
| | 426 | /* Fill in picture_t fields */ |
|---|
| | 427 | vout_InitPicture( VLC_OBJECT(p_vout), p_pic, p_vout->output.i_chroma, |
|---|
| | 428 | p_vout->output.i_width, p_vout->output.i_height, |
|---|
| | 429 | p_vout->output.i_aspect ); |
|---|
| | 430 | |
|---|
| | 431 | p_pic->p_sys->p_data = malloc( p_vout->p_sys->i_page_size ); |
|---|
| | 432 | if( !p_pic->p_sys->p_data ) |
|---|
| | 433 | { |
|---|
| | 434 | free( p_pic->p_sys ); |
|---|
| | 435 | p_pic->p_sys = NULL; |
|---|
| | 436 | return VLC_ENOMEM; |
|---|
| | 437 | } |
|---|
| | 438 | |
|---|
| | 439 | p_pic->p->p_pixels = (uint8_t*) p_pic->p_sys->p_data; |
|---|
| | 440 | |
|---|
| | 441 | p_pic->p->i_pixel_pitch = p_vout->p_sys->i_bytes_per_pixel; |
|---|
| | 442 | p_pic->p->i_lines = p_vout->p_sys->var_info.yres; |
|---|
| | 443 | p_pic->p->i_visible_lines = p_vout->p_sys->var_info.yres; |
|---|
| | 444 | |
|---|
| | 445 | if( p_vout->p_sys->var_info.xres_virtual ) |
|---|
| | 446 | { |
|---|
| | 447 | p_pic->p->i_pitch = p_vout->p_sys->var_info.xres_virtual |
|---|
| | 448 | * p_vout->p_sys->i_bytes_per_pixel; |
|---|
| | 449 | } |
|---|
| | 450 | else |
|---|
| | 451 | { |
|---|
| | 452 | p_pic->p->i_pitch = p_vout->p_sys->var_info.xres |
|---|
| | 453 | * p_vout->p_sys->i_bytes_per_pixel; |
|---|
| | 454 | } |
|---|
| | 455 | |
|---|
| | 456 | p_pic->p->i_visible_pitch = p_vout->p_sys->var_info.xres |
|---|
| | 457 | * p_vout->p_sys->i_bytes_per_pixel; |
|---|
| | 458 | p_pic->i_planes = 1; |
|---|
| | 459 | |
|---|
| | 460 | return VLC_SUCCESS; |
|---|
| | 461 | } |
|---|
| | 462 | |
|---|
| | 463 | /***************************************************************************** |
|---|
| | 464 | * FreePicture: destroy a picture allocated with NewPicture |
|---|
| | 465 | ***************************************************************************** |
|---|
| | 466 | * Destroy Image AND associated data. |
|---|
| | 467 | *****************************************************************************/ |
|---|
| | 468 | static void FreePicture( vout_thread_t *p_vout, picture_t *p_pic ) |
|---|
| | 469 | { |
|---|
| | 470 | free( p_pic->p_sys->p_data ); |
|---|
| | 471 | free( p_pic->p_sys ); |
|---|
| | 472 | p_pic->p_sys = NULL; |
|---|
| | 473 | } |
|---|
| | 474 | |
|---|
| 428 | | /* Try to initialize 1 direct buffer */ |
|---|
| 429 | | p_pic = NULL; |
|---|
| 430 | | |
|---|
| 431 | | /* Find an empty picture slot */ |
|---|
| 432 | | for( i_index = 0 ; i_index < VOUT_MAX_PICTURES ; i_index++ ) |
|---|
| 433 | | { |
|---|
| 434 | | if( p_vout->p_picture[ i_index ].i_status == FREE_PICTURE ) |
|---|
| 435 | | { |
|---|
| 436 | | p_pic = p_vout->p_picture + i_index; |
|---|
| 437 | | break; |
|---|
| 438 | | } |
|---|
| 439 | | } |
|---|
| 440 | | |
|---|
| 441 | | /* Allocate the picture */ |
|---|
| 442 | | if( p_pic == NULL ) |
|---|
| 443 | | { |
|---|
| 444 | | return VLC_EGENERIC; |
|---|
| 445 | | } |
|---|
| 446 | | |
|---|
| 447 | | /* We know the chroma, allocate a buffer which will be used |
|---|
| 448 | | * directly by the decoder */ |
|---|
| 449 | | p_pic->p->p_pixels = p_vout->p_sys->p_video; |
|---|
| 450 | | p_pic->p->i_pixel_pitch = p_vout->p_sys->i_bytes_per_pixel; |
|---|
| 451 | | p_pic->p->i_lines = p_vout->p_sys->var_info.yres; |
|---|
| 452 | | p_pic->p->i_visible_lines = p_vout->p_sys->var_info.yres; |
|---|
| 453 | | |
|---|
| 454 | | if( p_vout->p_sys->var_info.xres_virtual ) |
|---|
| 455 | | { |
|---|
| 456 | | p_pic->p->i_pitch = p_vout->p_sys->var_info.xres_virtual |
|---|
| 457 | | * p_vout->p_sys->i_bytes_per_pixel; |
|---|
| | 546 | if( !p_sys->b_hw_accel ) |
|---|
| | 547 | { |
|---|
| | 548 | /* Try to initialize up to MAX_DIRECTBUFFERS direct buffers */ |
|---|
| | 549 | while( I_OUTPUTPICTURES < MAX_DIRECTBUFFERS ) |
|---|
| | 550 | { |
|---|
| | 551 | p_pic = NULL; |
|---|
| | 552 | |
|---|
| | 553 | /* Find an empty picture slot */ |
|---|
| | 554 | for( i_index = 0 ; i_index < VOUT_MAX_PICTURES ; i_index++ ) |
|---|
| | 555 | { |
|---|
| | 556 | if( p_vout->p_picture[ i_index ].i_status == FREE_PICTURE ) |
|---|
| | 557 | { |
|---|
| | 558 | p_pic = p_vout->p_picture + i_index; |
|---|
| | 559 | break; |
|---|
| | 560 | } |
|---|
| | 561 | } |
|---|
| | 562 | |
|---|
| | 563 | /* Allocate the picture */ |
|---|
| | 564 | if( p_pic == NULL || NewPicture( p_vout, p_pic ) ) |
|---|
| | 565 | { |
|---|
| | 566 | break; |
|---|
| | 567 | } |
|---|
| | 568 | |
|---|
| | 569 | p_pic->i_status = DESTROYED_PICTURE; |
|---|
| | 570 | p_pic->i_type = DIRECT_PICTURE; |
|---|
| | 571 | |
|---|
| | 572 | PP_OUTPUTPICTURE[ I_OUTPUTPICTURES ] = p_pic; |
|---|
| | 573 | |
|---|
| | 574 | I_OUTPUTPICTURES++; |
|---|
| | 575 | } |
|---|
| 461 | | p_pic->p->i_pitch = p_vout->p_sys->var_info.xres |
|---|
| 462 | | * p_vout->p_sys->i_bytes_per_pixel; |
|---|
| 463 | | } |
|---|
| 464 | | |
|---|
| 465 | | p_pic->p->i_visible_pitch = p_vout->p_sys->var_info.xres |
|---|
| 466 | | * p_vout->p_sys->i_bytes_per_pixel; |
|---|
| 467 | | p_pic->i_planes = 1; |
|---|
| 468 | | p_pic->i_status = DESTROYED_PICTURE; |
|---|
| 469 | | p_pic->i_type = DIRECT_PICTURE; |
|---|
| 470 | | |
|---|
| 471 | | PP_OUTPUTPICTURE[ I_OUTPUTPICTURES ] = p_pic; |
|---|
| 472 | | |
|---|
| 473 | | I_OUTPUTPICTURES++; |
|---|
| | 579 | /* Try to initialize 1 direct buffer */ |
|---|
| | 580 | p_pic = NULL; |
|---|
| | 581 | |
|---|
| | 582 | /* Find an empty picture slot */ |
|---|
| | 583 | for( i_index = 0 ; i_index < VOUT_MAX_PICTURES ; i_index++ ) |
|---|
| | 584 | { |
|---|
| | 585 | if( p_vout->p_picture[ i_index ].i_status == FREE_PICTURE ) |
|---|
| | 586 | { |
|---|
| | 587 | p_pic = p_vout->p_picture + i_index; |
|---|
| | 588 | break; |
|---|
| | 589 | } |
|---|
| | 590 | } |
|---|
| | 591 | |
|---|
| | 592 | /* Allocate the picture */ |
|---|
| | 593 | if( p_pic == NULL ) |
|---|
| | 594 | { |
|---|
| | 595 | return VLC_EGENERIC; |
|---|
| | 596 | } |
|---|
| | 597 | |
|---|
| | 598 | /* We know the chroma, allocate a buffer which will be used |
|---|
| | 599 | * directly by the decoder */ |
|---|
| | 600 | p_pic->p->p_pixels = p_vout->p_sys->p_video; |
|---|
| | 601 | p_pic->p->i_pixel_pitch = p_vout->p_sys->i_bytes_per_pixel; |
|---|
| | 602 | p_pic->p->i_lines = p_vout->p_sys->var_info.yres; |
|---|
| | 603 | p_pic->p->i_visible_lines = p_vout->p_sys->var_info.yres; |
|---|
| | 604 | |
|---|
| | 605 | if( p_vout->p_sys->var_info.xres_virtual ) |
|---|
| | 606 | { |
|---|
| | 607 | p_pic->p->i_pitch = p_vout->p_sys->var_info.xres_virtual |
|---|
| | 608 | * p_vout->p_sys->i_bytes_per_pixel; |
|---|
| | 609 | } |
|---|
| | 610 | else |
|---|
| | 611 | { |
|---|
| | 612 | p_pic->p->i_pitch = p_vout->p_sys->var_info.xres |
|---|
| | 613 | * p_vout->p_sys->i_bytes_per_pixel; |
|---|
| | 614 | } |
|---|
| | 615 | |
|---|
| | 616 | p_pic->p->i_visible_pitch = p_vout->p_sys->var_info.xres |
|---|
| | 617 | * p_vout->p_sys->i_bytes_per_pixel; |
|---|
| | 618 | p_pic->i_planes = 1; |
|---|
| | 619 | p_pic->i_status = DESTROYED_PICTURE; |
|---|
| | 620 | p_pic->i_type = DIRECT_PICTURE; |
|---|
| | 621 | |
|---|
| | 622 | PP_OUTPUTPICTURE[ I_OUTPUTPICTURES ] = p_pic; |
|---|
| | 623 | |
|---|
| | 624 | I_OUTPUTPICTURES++; |
|---|
| | 625 | } |
|---|
| 485 | | } |
|---|
| 486 | | |
|---|
| 487 | | /***************************************************************************** |
|---|
| 488 | | * Destroy: destroy FB video thread output method |
|---|
| 489 | | ***************************************************************************** |
|---|
| 490 | | * Terminate an output method created by Create |
|---|
| 491 | | *****************************************************************************/ |
|---|
| 492 | | static void Destroy( vlc_object_t *p_this ) |
|---|
| 493 | | { |
|---|
| 494 | | vout_thread_t *p_vout = (vout_thread_t *)p_this; |
|---|
| 495 | | |
|---|
| 496 | | CloseDisplay( p_vout ); |
|---|
| 497 | | |
|---|
| 498 | | if( p_vout->p_sys->b_tty ) |
|---|
| 499 | | { |
|---|
| 500 | | /* Reset the terminal */ |
|---|
| 501 | | ioctl( p_vout->p_sys->i_tty, VT_SETMODE, &p_vout->p_sys->vt_mode ); |
|---|
| 502 | | |
|---|
| 503 | | /* Remove signal handlers */ |
|---|
| 504 | | sigaction( SIGUSR1, &p_vout->p_sys->sig_usr1, NULL ); |
|---|
| 505 | | sigaction( SIGUSR2, &p_vout->p_sys->sig_usr2, NULL ); |
|---|
| 506 | | |
|---|
| 507 | | /* Reset the keyboard state */ |
|---|
| 508 | | tcsetattr( 0, 0, &p_vout->p_sys->old_termios ); |
|---|
| 509 | | |
|---|
| 510 | | /* Return to text mode */ |
|---|
| 511 | | TextMode( p_vout->p_sys->i_tty ); |
|---|
| 512 | | } |
|---|
| 513 | | |
|---|
| 514 | | /* Destroy structure */ |
|---|
| 515 | | free( p_vout->p_sys ); |
|---|