]> git.sesse.net Git - vlc/blob - src/control/media_discoverer.c
Removes trailing spaces. Removes tabs.
[vlc] / src / control / media_discoverer.c
1 /*****************************************************************************
2  * media_discoverer.c: libvlc new API media discoverer functions
3  *****************************************************************************
4  * Copyright (C) 2007 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Pierre d'Herbemont <pdherbemont # videolan.org>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22  *****************************************************************************/
23
24 #include "libvlc_internal.h"
25 #include <vlc/libvlc.h>
26 #include <assert.h>
27 #include "vlc_playlist.h"
28
29 /*
30  * Private functions
31  */
32  
33 /**************************************************************************
34  *       services_discovery_item_added (Private) (VLC event callback)
35  **************************************************************************/
36
37 static void services_discovery_item_added( const vlc_event_t * p_event,
38                                            void * user_data )
39 {
40     input_item_t * p_item = p_event->u.services_discovery_item_added.p_new_item;
41     libvlc_media_descriptor_t * p_md;
42     libvlc_media_discoverer_t * p_mdis = user_data;
43
44     p_md = libvlc_media_descriptor_new_from_input_item(
45             p_mdis->p_libvlc_instance,
46             p_item, NULL );
47
48     libvlc_media_list_lock( p_mdis->p_mlist );
49     libvlc_media_list_add_media_descriptor( p_mdis->p_mlist, p_md, NULL );
50     libvlc_media_list_unlock( p_mdis->p_mlist );
51 }
52
53 /**************************************************************************
54  *       services_discovery_item_removed (Private) (VLC event callback)
55  **************************************************************************/
56
57 static void services_discovery_item_removed( const vlc_event_t * p_event,
58                                              void * user_data )
59 {
60     /* Not handled */
61 }
62
63 /*
64  * Public libvlc functions
65  */
66
67 /**************************************************************************
68  *       new (Public)
69  *
70  * Init an object.
71  **************************************************************************/
72 libvlc_media_discoverer_t *
73 libvlc_media_discoverer_new_from_name( libvlc_instance_t * p_inst,
74                                        const char * psz_name,
75                                        libvlc_exception_t * p_e )
76 {
77     libvlc_media_discoverer_t * p_mdis;
78  
79     p_mdis = malloc(sizeof(libvlc_media_discoverer_t));
80     if( !p_mdis )
81     {
82         libvlc_exception_raise( p_e, "Not enough memory" );
83         return NULL;
84     }
85
86     p_mdis->p_libvlc_instance = p_inst;
87     p_mdis->p_mlist = libvlc_media_list_new( p_inst, NULL );
88     p_mdis->p_sd = services_discovery_Create( (vlc_object_t*)p_inst->p_libvlc_int, psz_name );
89
90     if( !p_mdis->p_sd )
91     {
92         free( p_mdis );
93         libvlc_exception_raise( p_e, "Can't find the services_discovery module named '%s'", psz_name );
94         return NULL;
95     }
96
97     vlc_event_attach( services_discovery_EventManager( p_mdis->p_sd ),
98                       vlc_ServicesDiscoveryItemAdded,
99                       services_discovery_item_added,
100                       p_mdis );
101     vlc_event_attach( services_discovery_EventManager( p_mdis->p_sd ),
102                       vlc_ServicesDiscoveryItemRemoved,
103                       services_discovery_item_removed,
104                       p_mdis );
105  
106     services_discovery_Start( p_mdis->p_sd );
107
108     /* Here we go */
109
110     return p_mdis;
111 }
112
113 /**************************************************************************
114  * release (Public)
115  **************************************************************************/
116 void
117 libvlc_media_discoverer_release( libvlc_media_discoverer_t * p_mdis )
118 {
119     libvlc_media_list_release( p_mdis->p_mlist );
120     services_discovery_Destroy( p_mdis->p_sd );
121     free( p_mdis );
122 }
123
124 /**************************************************************************
125  * localized_name (Public)
126  **************************************************************************/
127 char *
128 libvlc_media_discoverer_localized_name( libvlc_media_discoverer_t * p_mdis )
129 {
130     return services_discovery_GetLocalizedName( p_mdis->p_sd );
131 }
132
133 /**************************************************************************
134  * media_list (Public)
135  **************************************************************************/
136 libvlc_media_list_t *
137 libvlc_media_discoverer_media_list( libvlc_media_discoverer_t * p_mdis )
138 {
139     libvlc_media_list_retain( p_mdis->p_mlist );
140     return p_mdis->p_mlist;
141 }
142