Changeset 0697a96a2cc92d600a66b34f5e1c28e0dbe80c36
- Timestamp:
- 05/01/04 13:59:54
(5 years ago)
- Author:
- Clément Stenac <zorglub@videolan.org>
- git-committer:
- Clément Stenac <zorglub@videolan.org> 1073307594 +0000
- git-parent:
[17557ea64382428560a75ecef753e88f39158834]
- git-author:
- Clément Stenac <zorglub@videolan.org> 1073307594 +0000
- Message:
* modules/misc/sap.c :
- Use the new playlist API
- Track title changes
- Timeout. Delete an item if we haven't heard about it for too long.
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| r0f03eb9 |
r0697a96 |
|
| 3 | 3 | ***************************************************************************** |
|---|
| 4 | 4 | * Copyright (C) 2001 VideoLAN |
|---|
| 5 | | * $Id: sap.c,v 1.43 2003/12/12 15:37:23 zorglub Exp $ |
|---|
| | 5 | * $Id: sap.c,v 1.44 2004/01/05 12:59:54 zorglub Exp $ |
|---|
| 6 | 6 | * |
|---|
| 7 | 7 | * Authors: Arnaud Schauly <gitan@via.ecp.fr> |
|---|
| … | … | |
| 167 | 167 | struct sap_announce_t |
|---|
| 168 | 168 | { |
|---|
| | 169 | mtime_t i_last; |
|---|
| | 170 | int i_id; |
|---|
| 169 | 171 | char *psz_name; |
|---|
| 170 | 172 | char *psz_uri; |
|---|
| … | … | |
| 280 | 282 | psz_scope = strdup( "8" ); |
|---|
| 281 | 283 | } |
|---|
| 282 | | snprintf( psz_address, 100, "[%s%c%s]",IPV6_ADDR_1, psz_scope[0], IPV6_ADDR_2 ); |
|---|
| | 284 | snprintf( psz_address, 100, "[%s%c%s]",IPV6_ADDR_1, |
|---|
| | 285 | psz_scope[0], IPV6_ADDR_2 ); |
|---|
| 283 | 286 | free( psz_scope ); |
|---|
| 284 | 287 | |
|---|
| … | … | |
| 374 | 377 | while( !p_intf->b_die ) |
|---|
| 375 | 378 | { |
|---|
| | 379 | playlist_t *p_playlist= NULL; |
|---|
| | 380 | int i; |
|---|
| 376 | 381 | int i_read = NetRead( p_intf, p_sys->fd, buffer, MAX_SAP_BUFFER ); |
|---|
| 377 | 382 | uint8_t *p_sdp; |
|---|
| … | … | |
| 384 | 389 | unsigned char *p_decompressed_buffer; |
|---|
| 385 | 390 | int i_decompressed_size; |
|---|
| 386 | | |
|---|
| | 391 | |
|---|
| | 392 | /* Check for items that need deletion */ |
|---|
| | 393 | for( i = 0 ; i< p_intf->p_sys->i_announces ; i++ ) |
|---|
| | 394 | { |
|---|
| | 395 | struct sap_announce_t *p_announce; |
|---|
| | 396 | if( mdate() - p_intf->p_sys->pp_announces[i]->i_last > 10000000 ) |
|---|
| | 397 | { |
|---|
| | 398 | msg_Dbg(p_intf,"Time out for %s, deleting (%i/%i)", |
|---|
| | 399 | p_intf->p_sys->pp_announces[i]->psz_name, |
|---|
| | 400 | i , p_intf->p_sys->i_announces ); |
|---|
| | 401 | |
|---|
| | 402 | /* Remove the playlist item */ |
|---|
| | 403 | p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, |
|---|
| | 404 | FIND_ANYWHERE ); |
|---|
| | 405 | if( p_playlist ) |
|---|
| | 406 | { |
|---|
| | 407 | int i_pos = playlist_GetPositionById( p_playlist, |
|---|
| | 408 | p_intf->p_sys->pp_announces[i]->i_id ); |
|---|
| | 409 | playlist_Delete( p_playlist, i_pos ); |
|---|
| | 410 | } |
|---|
| | 411 | |
|---|
| | 412 | vlc_object_release( p_playlist ); |
|---|
| | 413 | |
|---|
| | 414 | /* Free the p_announce */ |
|---|
| | 415 | p_announce = p_intf->p_sys->pp_announces[i]; |
|---|
| | 416 | if( p_announce->psz_name ) |
|---|
| | 417 | free( p_announce->psz_name ); |
|---|
| | 418 | if( p_announce->psz_uri ) |
|---|
| | 419 | free( p_announce->psz_uri ); |
|---|
| | 420 | |
|---|
| | 421 | /* Remove the sap_announce from the array */ |
|---|
| | 422 | REMOVE_ELEM( p_intf->p_sys->pp_announces, |
|---|
| | 423 | p_intf->p_sys->i_announces, |
|---|
| | 424 | i ); |
|---|
| | 425 | |
|---|
| | 426 | free( p_announce ); |
|---|
| | 427 | |
|---|
| | 428 | } |
|---|
| | 429 | } |
|---|
| | 430 | |
|---|
| 387 | 431 | /* Minimum length is > 6 */ |
|---|
| 388 | 432 | if( i_read <= 6 ) |
|---|
| … | … | |
| 468 | 512 | msg_Warn( p_intf, "ditching sap packet" ); |
|---|
| 469 | 513 | } |
|---|
| | 514 | |
|---|
| 470 | 515 | } |
|---|
| 471 | 516 | } |
|---|
| … | … | |
| 588 | 633 | static void sess_toitem( intf_thread_t * p_intf, sess_descr_t * p_sd ) |
|---|
| 589 | 634 | { |
|---|
| 590 | | playlist_item_t * p_item; |
|---|
| 591 | 635 | struct sap_announce_t *p_announce; |
|---|
| 592 | | char *psz_uri, *psz_proto; |
|---|
| | 636 | char *psz_uri, *psz_proto, *psz_item_uri; |
|---|
| 593 | 637 | char *psz_port; |
|---|
| 594 | 638 | char *psz_uri_default; |
|---|
| 595 | | int i_count , i; |
|---|
| | 639 | int i_count , i , i_pos , i_id = 0; |
|---|
| 596 | 640 | vlc_bool_t b_http = VLC_FALSE; |
|---|
| 597 | 641 | char *psz_http_path = NULL; |
|---|
| … | … | |
| 601 | 645 | if( p_sd->i_media > 1 ) |
|---|
| 602 | 646 | { |
|---|
| 603 | | p_item = malloc( sizeof( playlist_item_t ) ); |
|---|
| 604 | | if( p_item == NULL ) |
|---|
| | 647 | psz_uri = malloc( strlen( p_sd->psz_sdp ) + 7 ); |
|---|
| | 648 | if( psz_uri == NULL ) |
|---|
| 605 | 649 | { |
|---|
| 606 | 650 | msg_Warn( p_intf, "out of memory" ); |
|---|
| 607 | 651 | return; |
|---|
| 608 | 652 | } |
|---|
| 609 | | p_item->psz_name = strdup( p_sd->psz_sessionname ); |
|---|
| 610 | | p_item->psz_uri = NULL; |
|---|
| 611 | | p_item->i_duration = -1; |
|---|
| 612 | | p_item->ppsz_options= NULL; |
|---|
| 613 | | p_item->i_options = 0; |
|---|
| 614 | | |
|---|
| 615 | | p_item->i_type = 0; |
|---|
| 616 | | p_item->i_status = 0; |
|---|
| 617 | | p_item->b_autodeletion = VLC_FALSE; |
|---|
| 618 | | p_item->b_enabled = VLC_TRUE; |
|---|
| 619 | | p_item->i_group = p_intf->p_sys->i_group; |
|---|
| 620 | | p_item->psz_author = strdup( "" ); |
|---|
| 621 | | psz_uri = malloc( strlen( p_sd->psz_sdp ) + 7 ); |
|---|
| 622 | | if( psz_uri == NULL ) |
|---|
| 623 | | { |
|---|
| 624 | | msg_Warn( p_intf, "out of memory" ); |
|---|
| 625 | | free( p_item->psz_name ); |
|---|
| 626 | | free( p_item->psz_author ); |
|---|
| 627 | | free( p_item ); |
|---|
| 628 | | return; |
|---|
| 629 | | } |
|---|
| 630 | | p_item->psz_uri = psz_uri; |
|---|
| 631 | 653 | memcpy( psz_uri, "sdp://", 6 ); |
|---|
| 632 | 654 | psz_uri += 6; |
|---|
| 633 | 655 | memcpy( psz_uri, p_sd->psz_sdp, strlen( p_sd->psz_sdp ) + 1 ); |
|---|
| 634 | | /* Enqueueing p_item in the playlist */ |
|---|
| 635 | | |
|---|
| | 656 | |
|---|
| | 657 | /* Check if we have already added the item */ |
|---|
| 636 | 658 | for( i = 0 ; i< p_intf->p_sys->i_announces ; i++ ) |
|---|
| 637 | 659 | { |
|---|
| 638 | 660 | if( !strcmp(p_intf->p_sys->pp_announces[i]->psz_uri, |
|---|
| 639 | | p_item->psz_uri ) ) |
|---|
| 640 | | { |
|---|
| 641 | | return; |
|---|
| 642 | | } |
|---|
| 643 | | } |
|---|
| 644 | | p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE ); |
|---|
| 645 | | playlist_AddItem ( p_playlist, p_item, PLAYLIST_CHECK_INSERT, PLAYLIST_END ); |
|---|
| 646 | | vlc_object_release( p_playlist ); |
|---|
| | 661 | psz_uri ) ) |
|---|
| | 662 | { |
|---|
| | 663 | return; |
|---|
| | 664 | } |
|---|
| | 665 | } |
|---|
| | 666 | /* Add it to the playlist */ |
|---|
| | 667 | p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, |
|---|
| | 668 | FIND_ANYWHERE ); |
|---|
| | 669 | i_id = playlist_Add( p_playlist, psz_uri, p_sd->psz_sessionname , |
|---|
| | 670 | PLAYLIST_CHECK_INSERT, PLAYLIST_END ); |
|---|
| | 671 | |
|---|
| | 672 | i_pos = playlist_GetPositionById( p_playlist, i_id ); |
|---|
| | 673 | playlist_SetGroup( p_playlist, i_pos, p_intf->p_sys->i_group ); |
|---|
| | 674 | |
|---|
| | 675 | /* Remember it */ |
|---|
| 647 | 676 | p_announce = (struct sap_announce_t *)malloc( |
|---|
| 648 | 677 | sizeof(struct sap_announce_t) ); |
|---|
| 649 | | if( p_item->psz_name ) |
|---|
| 650 | | { |
|---|
| 651 | | p_announce->psz_name = strdup( p_item->psz_name ); |
|---|
| | 678 | if( p_sd->psz_sessionname ) |
|---|
| | 679 | { |
|---|
| | 680 | p_announce->psz_name = strdup( p_sd->psz_sessionname ); |
|---|
| 652 | 681 | } |
|---|
| 653 | 682 | else |
|---|
| … | … | |
| 655 | 684 | p_announce->psz_name = strdup( "" ); |
|---|
| 656 | 685 | } |
|---|
| 657 | | if( p_item->psz_uri ) |
|---|
| 658 | | { |
|---|
| 659 | | p_announce->psz_uri = strdup( p_item->psz_uri ); |
|---|
| | 686 | if( psz_uri ) |
|---|
| | 687 | { |
|---|
| | 688 | p_announce->psz_uri = strdup( psz_uri ); |
|---|
| 660 | 689 | } |
|---|
| 661 | 690 | else |
|---|
| … | … | |
| 663 | 692 | p_announce->psz_uri = strdup( "" ); |
|---|
| 664 | 693 | } |
|---|
| | 694 | p_announce->i_id = i_id; |
|---|
| 665 | 695 | |
|---|
| 666 | 696 | INSERT_ELEM( p_intf->p_sys->pp_announces, |
|---|
| … | … | |
| 668 | 698 | p_intf->p_sys->i_announces, |
|---|
| 669 | 699 | p_announce ); |
|---|
| | 700 | |
|---|
| | 701 | vlc_object_release( p_playlist ); |
|---|
| 670 | 702 | return; |
|---|
| 671 | 703 | } |
|---|
| … | … | |
| 675 | 707 | for( i_count = 0 ; i_count < p_sd->i_media ; i_count++ ) |
|---|
| 676 | 708 | { |
|---|
| 677 | | p_item = malloc( sizeof( playlist_item_t ) ); |
|---|
| 678 | | p_item->psz_name = strdup( p_sd->psz_sessionname ); |
|---|
| 679 | | p_item->psz_uri = NULL; |
|---|
| 680 | | p_item->i_duration = -1; |
|---|
| 681 | | p_item->ppsz_options= NULL; |
|---|
| 682 | | p_item->i_options = 0; |
|---|
| 683 | | |
|---|
| 684 | | p_item->i_type = 0; |
|---|
| 685 | | p_item->i_status = 0; |
|---|
| 686 | | p_item->b_autodeletion = VLC_FALSE; |
|---|
| 687 | | p_item->b_enabled = VLC_TRUE; |
|---|
| 688 | | p_item->i_group = p_intf->p_sys->i_group; |
|---|
| 689 | | p_item->psz_author = strdup( "" ); |
|---|
| 690 | | |
|---|
| 691 | | psz_uri = NULL; |
|---|
| 692 | | |
|---|
| 693 | | /* Build what we have to put in p_item->psz_uri, with the m and |
|---|
| 694 | | * c fields */ |
|---|
| | 709 | int i_group = p_intf->p_sys->i_group; |
|---|
| | 710 | |
|---|
| | 711 | /* Build what we have to put in psz_item_uri, with the m and |
|---|
| | 712 | * c fields */ |
|---|
| 695 | 713 | |
|---|
| 696 | 714 | if( !p_sd->pp_media[i_count] ) |
|---|
| … | … | |
| 735 | 753 | if(!strcasecmp( p_sd->pp_attributes[i]->psz_field , "plgroup")) |
|---|
| 736 | 754 | { |
|---|
| 737 | | int i_id; |
|---|
| | 755 | int i_group_id; |
|---|
| 738 | 756 | p_playlist = |
|---|
| 739 | 757 | (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, |
|---|
| … | … | |
| 744 | 762 | } |
|---|
| 745 | 763 | |
|---|
| 746 | | i_id = playlist_GroupToId( p_playlist, |
|---|
| 747 | | p_sd->pp_attributes[i]->psz_value); |
|---|
| 748 | | if( i_id != 0 ) |
|---|
| | 764 | i_group_id = playlist_GroupToId( p_playlist, |
|---|
| | 765 | p_sd->pp_attributes[i]->psz_value); |
|---|
| | 766 | if( i_group_id != 0 ) |
|---|
| 749 | 767 | { |
|---|
| 750 | | p_item->i_group = i_id; |
|---|
| | 768 | i_group = i_group_id; |
|---|
| 751 | 769 | } |
|---|
| 752 | 770 | else |
|---|
| … | … | |
| 755 | 773 | playlist_CreateGroup( p_playlist, |
|---|
| 756 | 774 | p_sd->pp_attributes[i]->psz_value); |
|---|
| 757 | | p_item->i_group = p_group->i_id; |
|---|
| | 775 | i_group = p_group->i_id; |
|---|
| 758 | 776 | } |
|---|
| 759 | 777 | vlc_object_release( p_playlist ); |
|---|
| … | … | |
| 761 | 779 | } |
|---|
| 762 | 780 | |
|---|
| 763 | | /* Filling p_item->psz_uri */ |
|---|
| | 781 | /* Filling psz_uri */ |
|---|
| 764 | 782 | if( b_http == VLC_FALSE ) |
|---|
| 765 | 783 | { |
|---|
| 766 | | p_item->psz_uri = malloc( strlen( psz_proto ) + strlen( psz_uri ) + |
|---|
| 767 | | strlen( psz_port ) + 7 ); |
|---|
| | 784 | psz_item_uri = malloc( strlen( psz_proto ) + strlen( psz_uri ) + |
|---|
| | 785 | strlen( psz_port ) + 7 ); |
|---|
| 768 | 786 | if( ismult( psz_uri ) ) |
|---|
| 769 | 787 | { |
|---|
| 770 | | sprintf( p_item->psz_uri, "%s://@%s:%s", |
|---|
| | 788 | sprintf( psz_item_uri, "%s://@%s:%s", |
|---|
| 771 | 789 | psz_proto, psz_uri, psz_port ); |
|---|
| 772 | 790 | } |
|---|
| 773 | 791 | else |
|---|
| 774 | 792 | { |
|---|
| 775 | | sprintf( p_item->psz_uri, "%s://%s:%s", |
|---|
| | 793 | sprintf( psz_item_uri, "%s://%s:%s", |
|---|
| 776 | 794 | psz_proto, psz_uri, psz_port ); |
|---|
| 777 | 795 | } |
|---|
| … | … | |
| 784 | 802 | } |
|---|
| 785 | 803 | |
|---|
| 786 | | p_item->psz_uri = malloc( strlen( psz_proto ) + strlen( psz_uri ) + |
|---|
| 787 | | strlen( psz_port ) + strlen(psz_http_path) + 5 ); |
|---|
| 788 | | sprintf( p_item->psz_uri, "%s://%s:%s%s", psz_proto, |
|---|
| | 804 | psz_item_uri = malloc( strlen( psz_proto ) + strlen( psz_uri ) + |
|---|
| | 805 | strlen( psz_port ) + strlen(psz_http_path) + |
|---|
| | 806 | 5 ); |
|---|
| | 807 | sprintf( psz_item_uri, "%s://%s:%s%s", psz_proto, |
|---|
| 789 | 808 | psz_uri, psz_port,psz_http_path ); |
|---|
| 790 | 809 | |
|---|
| … | … | |
| 795 | 814 | } |
|---|
| 796 | 815 | |
|---|
| | 816 | /* Check if we already know this item */ |
|---|
| 797 | 817 | for( i = 0 ; i< p_intf->p_sys->i_announces ; i++ ) |
|---|
| 798 | 818 | { |
|---|
| 799 | | if( !strcmp(p_intf->p_sys->pp_announces[i]->psz_uri, |
|---|
| 800 | | p_item->psz_uri ) ) |
|---|
| 801 | | { |
|---|
| | 819 | if( !strcmp( p_intf->p_sys->pp_announces[i]->psz_uri, |
|---|
| | 820 | psz_item_uri ) ) |
|---|
| | 821 | { |
|---|
| | 822 | p_intf->p_sys->pp_announces[i]->i_last = mdate(); |
|---|
| | 823 | |
|---|
| | 824 | /* Check if the name changed */ |
|---|
| | 825 | if( strcmp( p_intf->p_sys->pp_announces[i]->psz_name, |
|---|
| | 826 | p_sd->psz_sessionname ) ) |
|---|
| | 827 | { |
|---|
| | 828 | playlist_item_t *p_item; |
|---|
| | 829 | p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, |
|---|
| | 830 | FIND_ANYWHERE ); |
|---|
| | 831 | |
|---|
| | 832 | msg_Dbg(p_intf, "Name changed (%s -> %s) for %s", |
|---|
| | 833 | p_intf->p_sys->pp_announces[i]->psz_name, |
|---|
| | 834 | p_sd->psz_sessionname, |
|---|
| | 835 | psz_item_uri ); |
|---|
| | 836 | |
|---|
| | 837 | p_item = playlist_GetItemById( p_playlist, |
|---|
| | 838 | p_intf->p_sys->pp_announces[i]->i_id ); |
|---|
| | 839 | |
|---|
| | 840 | /* Change the name in the item */ |
|---|
| | 841 | if( p_item->psz_name ) |
|---|
| | 842 | free( p_item->psz_name ); |
|---|
| | 843 | p_item->psz_name = strdup( p_sd->psz_sessionname); |
|---|
| | 844 | |
|---|
| | 845 | /* Update the stored name */ |
|---|
| | 846 | if( p_intf->p_sys->pp_announces[i]->psz_name ) |
|---|
| | 847 | free( p_intf->p_sys->pp_announces[i]->psz_name ); |
|---|
| | 848 | p_intf->p_sys->pp_announces[i]->psz_name = |
|---|
| | 849 | strdup( p_sd->psz_sessionname ); |
|---|
| | 850 | |
|---|
| | 851 | vlc_object_release( p_playlist ); |
|---|
| | 852 | } |
|---|
| 802 | 853 | return; |
|---|
| 803 | 854 | } |
|---|
| 804 | 855 | } |
|---|
| 805 | 856 | |
|---|
| 806 | | /* Enqueueing p_item in the playlist */ |
|---|
| | 857 | /* Add the item in the playlist */ |
|---|
| 807 | 858 | p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, |
|---|
| 808 | 859 | FIND_ANYWHERE ); |
|---|
| 809 | | playlist_AddItem ( p_playlist, p_item, |
|---|
| 810 | | PLAYLIST_CHECK_INSERT, PLAYLIST_END ); |
|---|
| 811 | | |
|---|
| 812 | | /* Store it in the list */ |
|---|
| | 860 | i_id = playlist_Add ( p_playlist, psz_item_uri , |
|---|
| | 861 | p_sd->psz_sessionname, |
|---|
| | 862 | PLAYLIST_CHECK_INSERT, PLAYLIST_END ); |
|---|
| | 863 | i_pos = playlist_GetPositionById( p_playlist, i_id ); |
|---|
| | 864 | playlist_SetGroup( p_playlist, i_pos, i_group ); |
|---|
| | 865 | |
|---|
| | 866 | /* Then remember it */ |
|---|
| 813 | 867 | p_announce = (struct sap_announce_t *)malloc( |
|---|
| 814 | 868 | sizeof(struct sap_announce_t) ); |
|---|
| 815 | | if( p_item->psz_name ) |
|---|
| 816 | | { |
|---|
| 817 | | p_announce->psz_name = strdup( p_item->psz_name ); |
|---|
| | 869 | if( p_sd->psz_sessionname ) |
|---|
| | 870 | { |
|---|
| | 871 | p_announce->psz_name = strdup( p_sd->psz_sessionname ); |
|---|
| 818 | 872 | } |
|---|
| 819 | 873 | else |
|---|
| … | … | |
| 821 | 875 | p_announce->psz_name = strdup( "" ); |
|---|
| 822 | 876 | } |
|---|
| 823 | | if( p_item->psz_uri ) |
|---|
| 824 | | { |
|---|
| 825 | | p_announce->psz_uri = strdup( p_item->psz_uri ); |
|---|
| | 877 | if( psz_item_uri ) |
|---|
| | 878 | { |
|---|
| | 879 | p_announce->psz_uri = strdup( psz_item_uri ); |
|---|
| 826 | 880 | } |
|---|
| 827 | 881 | else |
|---|
| … | … | |
| 829 | 883 | p_announce->psz_uri = strdup( "" ); |
|---|
| 830 | 884 | } |
|---|
| | 885 | p_announce->i_id = i_id; |
|---|
| | 886 | |
|---|
| | 887 | p_announce->i_last = mdate(); |
|---|
| | 888 | |
|---|
| | 889 | vlc_object_release( p_playlist ); |
|---|
| 831 | 890 | |
|---|
| 832 | 891 | INSERT_ELEM( p_intf->p_sys->pp_announces, |
|---|
| … | … | |
| 834 | 893 | p_intf->p_sys->i_announces, |
|---|
| 835 | 894 | p_announce ); |
|---|
| 836 | | vlc_object_release( p_playlist ); |
|---|
| 837 | 895 | } |
|---|
| 838 | 896 | } |
|---|