]> git.sesse.net Git - vlc/blob - modules/services_discovery/freebox.c
macosx/framework: Build a fat framework (x86_64 and i386) in Release mode.
[vlc] / modules / services_discovery / freebox.c
1 /*****************************************************************************
2  * freebox.c:  Shoutcast services discovery module
3  *****************************************************************************
4  * Copyright (C) 2005-2007 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Sigmund Augdal Helberg <dnumgis@videolan.org>
8  *          Antoine Cellerier <dionoea -@T- videolan -d.t- org>
9  *          Pierre d'Herbemont <pdherbemont # videolan.org>
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
24  *****************************************************************************/
25
26 /*****************************************************************************
27  * Includes
28  *****************************************************************************/
29
30 #ifdef HAVE_CONFIG_H
31 # include "config.h"
32 #endif
33
34 #include <vlc_common.h>
35 #include <vlc_plugin.h>
36 #include <vlc_services_discovery.h>
37
38 /*****************************************************************************
39  * Module descriptor
40  *****************************************************************************/
41
42 static int  Open( vlc_object_t * );
43 static void Close( vlc_object_t * );
44
45 VLC_SD_PROBE_HELPER("freebox", "Freebox TV", SD_CAT_INTERNET)
46
47 vlc_module_begin ()
48     set_category( CAT_PLAYLIST )
49     set_subcategory( SUBCAT_PLAYLIST_SD )
50
51     set_shortname( "Freebox")
52     set_description( N_("Freebox TV") )
53     set_capability( "services_discovery", 0 )
54     set_callbacks( Open, Close )
55     add_shortcut( "freebox" )
56
57     VLC_SD_PROBE_SUBMODULE
58 vlc_module_end ()
59
60
61 /*****************************************************************************
62  * Local prototypes
63  *****************************************************************************/
64
65 static void *Run( void * );
66 struct services_discovery_sys_t
67 {
68     vlc_thread_t thread;
69 };
70
71 /*****************************************************************************
72  * Open: initialize and create stuff
73  *****************************************************************************/
74 static int Open(vlc_object_t *this)
75 {
76     services_discovery_t *sd = (services_discovery_t *)this;
77     sd->p_sys = malloc(sizeof(*(sd->p_sys)));
78     if (sd->p_sys == NULL)
79         return VLC_ENOMEM;
80
81     if (vlc_clone(&sd->p_sys->thread, Run, sd, VLC_THREAD_PRIORITY_LOW))
82     {
83         free(sd->p_sys);
84         return VLC_EGENERIC;
85     }
86     return VLC_SUCCESS;
87 }
88
89 /*****************************************************************************
90  * ItemAdded:
91  *****************************************************************************/
92 static void ItemAdded(const vlc_event_t * event, void *user_data)
93 {
94     services_discovery_t *sd = user_data;
95     input_item_t *child = event->u.input_item_subitem_added.p_new_child;
96     input_item_AddOption(child, "deinterlace=1", VLC_INPUT_OPTION_TRUSTED);
97     services_discovery_AddItem(sd, child, NULL);
98 }
99
100
101 /*****************************************************************************
102  * Run:
103  *****************************************************************************/
104 static void *Run(void *data)
105 {
106     services_discovery_t *sd = data;
107     int canc = vlc_savecancel();
108
109     const char * const name = "Freebox TV";
110     const char * const url = "http://mafreebox.freebox.fr/freeboxtv/playlist.m3u";
111     input_item_t *input = input_item_New(sd, url, vlc_gettext(name));
112     input_item_AddOption(input, "no-playlist-autostart", VLC_INPUT_OPTION_TRUSTED);
113
114     /* Read every subitems, and add them in ItemAdded */
115     vlc_event_manager_t *em = &input->event_manager;
116     vlc_event_attach(em, vlc_InputItemSubItemAdded, ItemAdded, sd);
117     input_Read(sd, input);
118     vlc_event_detach(em, vlc_InputItemSubItemAdded, ItemAdded, sd);
119
120     vlc_gc_decref(input);
121
122     vlc_restorecancel(canc);
123     return NULL;
124 }
125
126 /*****************************************************************************
127  * Close:
128  *****************************************************************************/
129 static void Close(vlc_object_t *this)
130 {
131     services_discovery_t *sd = (services_discovery_t *)this;
132     services_discovery_sys_t *sys = sd->p_sys;
133     vlc_join(sys->thread, NULL);
134     free(sys);
135 }
136