~ubuntu-branches/ubuntu/maverick/vlc/maverick

« back to all changes in this revision

Viewing changes to modules/services_discovery/upnp_intel.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Reinhard Tartler
  • Date: 2008-09-17 21:56:14 UTC
  • mfrom: (1.1.17 upstream)
  • Revision ID: james.westby@ubuntu.com-20080917215614-tj0vx8xzd57e52t8
Tags: 0.9.2-1ubuntu1
* New Upstream Release, exception granted by
    - dktrkranz, norsetto, Hobbsee (via irc). LP: #270404

Changes done in ubuntu:

* add libxul-dev to build-depends
* make sure that vlc is build against libxul in configure. This doesn't
  change anything in the package, but makes it more robust if building
  in an 'unclean' chroot or when modifying the package.
* debian/control: make Vcs-* fields point to the motumedia branch
* add libx264-dev and libass-dev to build-depends
  LP: #210354, #199870
* actually enable libass support by passing --enable-libass to configure
* enable libdca: add libdca-dev to build depends and --enable-libdca
* install the x264 plugin.

Changes already in the pkg-multimedia branch in debian:

* don't install usr/share/vlc/mozilla in debian/mozilla-plugin-vlc.install  
* new upstream .desktop file now registers flash video mimetype LP: #261567
* add Xb-Npp-Applications to mozilla-plugin-vlc
* remove duplicate entries in debian/vlc-nox.install

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*****************************************************************************
2
 
 * Upnp_intell.cpp :  UPnP discovery module (Intel SDK)
 
2
 * Upnp_intel.cpp :  UPnP discovery module (Intel SDK)
3
3
 *****************************************************************************
4
 
 * Copyright (C) 2004-2006 the VideoLAN team
5
 
 * $Id: f04fae6902d830abdcb8b18d5b8fe4aa8a010181 $
 
4
 * Copyright (C) 2004-2008 the VideoLAN team
 
5
 * $Id: 0c3f3a59a797bf7ccc34b882bfdbd85789c908ae $
6
6
 *
7
7
 * Authors: Rémi Denis-Courmont <rem # videolan.org> (original plugin)
8
8
 *          Christian Henz <henz # c-lab.de>
27
27
/*
28
28
  \TODO: Debug messages: "__FILE__, __LINE__" ok ???, Wrn/Err ???
29
29
  \TODO: Change names to VLC standard ???
 
30
  \TODO: Rewrite this using the new service discovery API (see sap.c, shout.c).
30
31
*/
31
32
 
32
 
#include <stdlib.h>
33
33
 
34
34
#include <vector>
35
35
#include <string>
38
38
#include <upnp/upnptools.h>
39
39
 
40
40
#undef PACKAGE_NAME
41
 
#include <vlc/vlc.h>
42
 
#include <vlc/intf.h>
 
41
#ifdef HAVE_CONFIG_H
 
42
# include "config.h"
 
43
#endif
43
44
 
44
 
#include "vlc_strings.h"
 
45
#include <vlc_common.h>
 
46
#include <vlc_plugin.h>
 
47
#include <vlc_playlist.h>
45
48
 
46
49
 
47
50
// VLC handle
48
51
 
49
52
struct services_discovery_sys_t
50
53
{
51
 
    playlist_item_t *p_node;
52
54
    playlist_t *p_playlist;
 
55
    playlist_item_t *p_node_cat;
 
56
    playlist_item_t *p_node_one;
53
57
};
54
58
 
55
59
 
84
88
 
85
89
    Lockable( Cookie* c )
86
90
    {
87
 
    vlc_mutex_init( c->serviceDiscovery, &_mutex );
 
91
    vlc_mutex_init( &_mutex );
88
92
    }
89
93
 
90
94
    ~Lockable()
252
256
static int Open( vlc_object_t* );
253
257
static void Close( vlc_object_t* );
254
258
static void Run( services_discovery_t *p_sd );
 
259
static playlist_t *pl_Get( services_discovery_t *p_sd )
 
260
{
 
261
    return p_sd->p_sys->p_playlist;
 
262
}
255
263
 
256
264
// Module descriptor
257
265
 
258
266
vlc_module_begin();
259
267
set_shortname( "UPnP" );
260
 
set_description( _( "Universal Plug'n'Play discovery ( Intel SDK )" ) );
 
268
set_description( N_( "Universal Plug'n'Play discovery ( Intel SDK )" ) );
261
269
set_category( CAT_PLAYLIST );
262
270
set_subcategory( SUBCAT_PLAYLIST_SD );
263
271
set_capability( "services_discovery", 0 );
282
290
    services_discovery_sys_t *p_sys  = ( services_discovery_sys_t * )
283
291
    malloc( sizeof( services_discovery_sys_t ) );
284
292
 
285
 
    playlist_view_t *p_view;
286
 
    vlc_value_t val;
287
 
 
288
293
    p_sd->pf_run = Run;
289
294
    p_sd->p_sys = p_sys;
 
295
    p_sys->p_playlist = pl_Yield( p_sd );
290
296
 
291
297
    /* Create our playlist node */
292
 
    p_sys->p_playlist = ( playlist_t * )vlc_object_find( p_sd,
293
 
                             VLC_OBJECT_PLAYLIST,
294
 
                             FIND_ANYWHERE );
295
 
    if( !p_sys->p_playlist )
296
 
    {
297
 
    msg_Warn( p_sd, "unable to find playlist, cancelling UPnP listening" );
298
 
    return VLC_EGENERIC;
299
 
    }
300
 
 
301
 
    p_view = playlist_ViewFind( p_sys->p_playlist, VIEW_CATEGORY );
302
 
    p_sys->p_node = playlist_NodeCreate( p_sys->p_playlist, VIEW_CATEGORY,
303
 
                                         "UPnP", p_view->p_root );
304
 
    p_sys->p_node->i_flags |= PLAYLIST_RO_FLAG;
305
 
    p_sys->p_node->i_flags &= ~PLAYLIST_SKIP_FLAG;
306
 
    val.b_bool = VLC_TRUE;
307
 
    var_Set( p_sys->p_playlist, "intf-change", val );
 
298
    vlc_object_lock( p_sys->p_playlist );
 
299
    playlist_NodesPairCreate( pl_Get( p_sd ), _("Devices"),
 
300
                              &p_sys->p_node_cat, &p_sys->p_node_one,
 
301
                              true );
 
302
    vlc_object_unlock( p_sys->p_playlist );
308
303
 
309
304
    return VLC_SUCCESS;
310
305
}
314
309
    services_discovery_t *p_sd = ( services_discovery_t* )p_this;
315
310
    services_discovery_sys_t *p_sys = p_sd->p_sys;
316
311
 
317
 
    if( p_sys->p_playlist )
318
 
    {
319
 
    playlist_NodeDelete( p_sys->p_playlist, p_sys->p_node, VLC_TRUE,
320
 
                 VLC_TRUE );
321
 
    vlc_object_release( p_sys->p_playlist );
322
 
    }
323
 
 
 
312
    vlc_object_lock( p_sys->p_playlist );
 
313
    playlist_NodeDelete( pl_Get( p_sd ), p_sys->p_node_one, true,
 
314
                         true );
 
315
    playlist_NodeDelete( pl_Get( p_sd ), p_sys->p_node_cat, true,
 
316
                         true );
 
317
    vlc_object_unlock( p_sys->p_playlist );
 
318
    pl_Release( p_sd );
324
319
    free( p_sys );
325
320
}
326
321
 
331
326
    res = UpnpInit( 0, 0 );
332
327
    if( res != UPNP_E_SUCCESS )
333
328
    {
334
 
    msg_Err( p_sd, "%s", UpnpGetErrorMessage( res ) );
335
 
    return;
 
329
        msg_Err( p_sd, "%s", UpnpGetErrorMessage( res ) );
 
330
        return;
336
331
    }
337
332
 
338
333
    Cookie cookie;
344
339
    res = UpnpRegisterClient( Callback, &cookie, &cookie.clientHandle );
345
340
    if( res != UPNP_E_SUCCESS )
346
341
    {
347
 
    msg_Err( p_sd, "%s", UpnpGetErrorMessage( res ) );
348
 
    goto shutDown;
 
342
        msg_Err( p_sd, "%s", UpnpGetErrorMessage( res ) );
 
343
        goto shutDown;
349
344
    }
350
345
 
351
346
    res = UpnpSearchAsync( cookie.clientHandle, 5, MEDIA_SERVER_DEVICE_TYPE, &cookie );
352
347
    if( res != UPNP_E_SUCCESS )
353
348
    {
354
 
    msg_Err( p_sd, "%s", UpnpGetErrorMessage( res ) );
355
 
    goto shutDown;
 
349
        msg_Err( p_sd, "%s", UpnpGetErrorMessage( res ) );
 
350
        goto shutDown;
356
351
    }
357
352
 
358
353
    msg_Dbg( p_sd, "UPnP discovery started" );
359
 
    while( !p_sd->b_die )
 
354
    while( vlc_object_alive (p_sd) )
360
355
    {
361
 
    msleep( 500 );
 
356
        msleep( 500 );
362
357
    }
363
358
 
364
359
    msg_Dbg( p_sd, "UPnP discovery stopped" );
412
407
 
413
408
    const char* resultString = ixmlNode_getNodeValue( textNode );
414
409
    char* resultXML = strdup( resultString );
415
 
    
416
 
    resolve_xml_special_chars( resultXML );
417
410
 
418
411
    IXML_Document* browseDoc = ixmlParseBuffer( resultXML );
419
412
 
482
475
    }
483
476
    break;
484
477
 
 
478
    case UPNP_EVENT_SUBSCRIBE_COMPLETE:
 
479
        msg_Warn( cookie->serviceDiscovery, "subscription complete" );
 
480
        break;
 
481
 
 
482
    case UPNP_DISCOVERY_SEARCH_TIMEOUT:
 
483
        msg_Warn( cookie->serviceDiscovery, "search timeout" );
 
484
        break;
 
485
 
485
486
    default:
486
487
    msg_Dbg( cookie->serviceDiscovery, "%s:%d: DEBUG: UNHANDLED EVENT ( TYPE=%d )", __FILE__, __LINE__, eventType );
487
488
    break;
630
631
{
631
632
    if ( _contents )
632
633
    {
633
 
    playlist_NodeDelete( _cookie->serviceDiscovery->p_sys->p_playlist,
634
 
                _playlistNode,
635
 
                true,
636
 
                true );
 
634
        vlc_object_lock( _cookie->serviceDiscovery->p_sys->p_playlist );
 
635
        playlist_NodeDelete( pl_Get( _cookie->serviceDiscovery ) ,
 
636
                             _playlistNode, true, true );
 
637
        vlc_object_unlock( _cookie->serviceDiscovery->p_sys->p_playlist );
637
638
    }
638
639
 
639
640
    delete _contents;
766
767
void MediaServer::fetchContents()
767
768
{
768
769
    Container* root = new Container( 0, "0", getFriendlyName() );
 
770
    playlist_t * p_playlist = pl_Get( _cookie->serviceDiscovery );
769
771
    _fetchContents( root );
770
772
 
771
773
    if ( _contents )
772
774
    {
773
 
    vlc_mutex_lock( &_cookie->serviceDiscovery->p_sys->p_playlist->object_lock );
774
 
 
775
 
    playlist_NodeEmpty( _cookie->serviceDiscovery->p_sys->p_playlist,
776
 
               _playlistNode,
777
 
               true );
778
 
 
779
 
    vlc_mutex_unlock( &_cookie->serviceDiscovery->p_sys->p_playlist->object_lock );
780
 
 
781
 
    delete _contents;
 
775
        PL_LOCK;
 
776
        playlist_NodeEmpty( p_playlist, _playlistNode, true );
 
777
        PL_UNLOCK;
 
778
        delete _contents;
782
779
    }
783
780
 
784
781
    _contents = root;
864
861
 
865
862
void MediaServer::_buildPlaylist( Container* parent )
866
863
{
 
864
    playlist_t *p_playlist = pl_Get( _cookie->serviceDiscovery );
867
865
    for ( unsigned int i = 0; i < parent->getNumContainers(); i++ )
868
866
    {
869
 
    Container* container = parent->getContainer( i );
870
 
    playlist_item_t* parentNode = parent->getPlaylistNode();
871
 
 
872
 
    char* title = strdup( container->getTitle() );
873
 
    playlist_item_t* node = playlist_NodeCreate( _cookie->serviceDiscovery->p_sys->p_playlist,
874
 
                             VIEW_CATEGORY,
875
 
                             title,
876
 
                             parentNode );
877
 
    free( title );
878
 
 
879
 
    container->setPlaylistNode( node );
880
 
    _buildPlaylist( container );
 
867
        Container* container = parent->getContainer( i );
 
868
        playlist_item_t* parentNode = parent->getPlaylistNode();
 
869
 
 
870
        char* title = strdup( container->getTitle() );
 
871
        playlist_item_t* node = playlist_NodeCreate( p_playlist, title, parentNode, 0, NULL );
 
872
        free( title );
 
873
 
 
874
        container->setPlaylistNode( node );
 
875
        _buildPlaylist( container );
881
876
    }
882
877
 
883
878
    for ( unsigned int i = 0; i < parent->getNumItems(); i++ )
884
879
    {
885
 
    Item* item = parent->getItem( i );
886
 
    playlist_item_t* parentNode = parent->getPlaylistNode();
887
 
 
888
 
    playlist_item_t* node = playlist_ItemNew( _cookie->serviceDiscovery,
889
 
                         item->getResource(),
890
 
                         item->getTitle() );
891
 
 
892
 
    playlist_NodeAddItem( _cookie->serviceDiscovery->p_sys->p_playlist,
893
 
                 node,
894
 
                 VIEW_CATEGORY,
895
 
                 parentNode, PLAYLIST_APPEND, PLAYLIST_END );
896
 
 
897
 
    item->setPlaylistNode( node );
 
880
        Item* item = parent->getItem( i );
 
881
        playlist_item_t* parentNode = parent->getPlaylistNode();
 
882
 
 
883
        input_item_t* p_input = input_item_New( _cookie->serviceDiscovery,
 
884
                                               item->getResource(),
 
885
                                               item->getTitle() );
 
886
        int i_cat;
 
887
        /* FIXME: playlist_AddInput() can fail */
 
888
        playlist_BothAddInput( p_playlist, p_input, parentNode,
 
889
                               PLAYLIST_APPEND, PLAYLIST_END, &i_cat, NULL,
 
890
                               pl_Unlocked );
 
891
        vlc_gc_decref( p_input );
 
892
        /* TODO: do this better by storing ids */
 
893
        playlist_item_t *p_node = playlist_ItemGetById( p_playlist, i_cat, false );
 
894
        assert( p_node );
 
895
        item->setPlaylistNode( p_node );
898
896
    }
899
897
}
900
898
 
933
931
    _list.push_back( s );
934
932
 
935
933
    char* name = strdup( s->getFriendlyName() );
936
 
    playlist_item_t* node = playlist_NodeCreate( _cookie->serviceDiscovery->p_sys->p_playlist,
937
 
                        VIEW_CATEGORY,
938
 
                        name,
939
 
                        _cookie->serviceDiscovery->p_sys->p_node );
 
934
    vlc_object_lock( _cookie->serviceDiscovery->p_sys->p_playlist );
 
935
    playlist_item_t* node = playlist_NodeCreate(
 
936
                                pl_Get( _cookie->serviceDiscovery ), name,
 
937
                                _cookie->serviceDiscovery->p_sys->p_node_cat,
 
938
                                0, NULL );
 
939
    vlc_object_unlock( _cookie->serviceDiscovery->p_sys->p_playlist );
940
940
    free( name );
941
941
    s->setPlaylistNode( node );
942
942