~ubuntu-branches/ubuntu/natty/vlc/natty

« back to all changes in this revision

Viewing changes to src/playlist/engine.c

  • Committer: Bazaar Package Importer
  • Author(s): Benjamin Drung
  • Date: 2010-06-25 01:09:16 UTC
  • mfrom: (1.1.30 upstream)
  • Revision ID: james.westby@ubuntu.com-20100625010916-asxhep2mutg6g6pd
Tags: 1.1.0-1ubuntu1
* Merge from Debian unstable, remaining changes:
  - build and install the libx264 plugin
  - add Xb-Npp header to vlc package
  - Add apport hook to include more vlc dependencies in bug reports
* Drop xulrunner patches.
* Drop 502_xulrunner_191.diff.

Show diffs side-by-side

added added

removed removed

Lines of Context:
38
38
 * Local prototypes
39
39
 *****************************************************************************/
40
40
static void VariablesInit( playlist_t *p_playlist );
41
 
static void playlist_Destructor( vlc_object_t * p_this );
42
41
 
43
42
static int RandomCallback( vlc_object_t *p_this, char const *psz_cmd,
44
43
                           vlc_value_t oldval, vlc_value_t newval, void *a )
76
75
 
77
76
    assert( offsetof( playlist_private_t, public_data ) == 0 );
78
77
    p_playlist = &p->public_data;
 
78
    vlc_object_attach( p_playlist, p_parent );
79
79
    TAB_INIT( pl_priv(p_playlist)->i_sds, pl_priv(p_playlist)->pp_sds );
80
80
 
81
81
    libvlc_priv(p_parent->p_libvlc)->p_playlist = p_playlist;
97
97
    pl_priv(p_playlist)->b_reset_currently_playing = true;
98
98
    pl_priv(p_playlist)->last_rebuild_date = 0;
99
99
 
100
 
    pl_priv(p_playlist)->b_tree = var_CreateGetBool( p_playlist, "playlist-tree" );
 
100
    pl_priv(p_playlist)->b_tree = var_InheritBool( p_parent, "playlist-tree" );
101
101
 
102
102
    pl_priv(p_playlist)->b_doing_ml = false;
103
103
 
104
 
    const bool b_auto_preparse = var_CreateGetBool( p_playlist, "auto-preparse" );
105
 
    pl_priv(p_playlist)->b_auto_preparse = b_auto_preparse;
106
 
 
107
 
    PL_LOCK; /* playlist_NodeCreate will check for it */
108
 
    p_playlist->p_root_category = playlist_NodeCreate( p_playlist, NULL, NULL,
109
 
                                    0, NULL );
110
 
    p_playlist->p_root_onelevel = playlist_NodeCreate( p_playlist, NULL, NULL,
111
 
                                    0, p_playlist->p_root_category->p_input );
112
 
    PL_UNLOCK;
113
 
 
114
 
    if( !p_playlist->p_root_category || !p_playlist->p_root_onelevel )
115
 
        return NULL;
116
 
 
117
 
    /* Create playlist and media library */
118
 
    PL_LOCK; /* playlist_NodesPairCreate will check for it */
119
 
    playlist_NodesPairCreate( p_playlist, _( "Playlist" ),
120
 
                            &p_playlist->p_local_category,
121
 
                            &p_playlist->p_local_onelevel, false );
122
 
    PL_UNLOCK;
123
 
 
124
 
    p_playlist->p_local_category->i_flags |= PLAYLIST_RO_FLAG;
125
 
    p_playlist->p_local_onelevel->i_flags |= PLAYLIST_RO_FLAG;
126
 
 
127
 
    if( !p_playlist->p_local_category || !p_playlist->p_local_onelevel ||
128
 
        !p_playlist->p_local_category->p_input ||
129
 
        !p_playlist->p_local_onelevel->p_input )
130
 
        return NULL;
131
 
 
132
 
    if( config_GetInt( p_playlist, "media-library") )
133
 
    {
134
 
        PL_LOCK; /* playlist_NodesPairCreate will check for it */
135
 
        playlist_NodesPairCreate( p_playlist, _( "Media Library" ),
136
 
                            &p_playlist->p_ml_category,
137
 
                            &p_playlist->p_ml_onelevel, false );
 
104
    pl_priv(p_playlist)->b_auto_preparse =
 
105
        var_InheritBool( p_parent, "auto-preparse" );
 
106
 
 
107
    /* Fetcher */
 
108
    p->p_fetcher = playlist_fetcher_New( p_playlist );
 
109
    if( unlikely(p->p_fetcher == NULL) )
 
110
    {
 
111
        msg_Err( p_playlist, "cannot create fetcher" );
 
112
        p->p_preparser = NULL;
 
113
    }
 
114
    else
 
115
    {   /* Preparse */
 
116
        p->p_preparser = playlist_preparser_New( p_playlist, p->p_fetcher );
 
117
        if( unlikely(p->p_preparser == NULL) )
 
118
            msg_Err( p_playlist, "cannot create preparser" );
 
119
    }
 
120
 
 
121
    /* Create the root node */
 
122
    PL_LOCK;
 
123
    p_playlist->p_root = playlist_NodeCreate( p_playlist, NULL, NULL,
 
124
                                    PLAYLIST_END, 0, NULL );
 
125
    PL_UNLOCK;
 
126
    if( !p_playlist->p_root ) return NULL;
 
127
 
 
128
    /* Create currently playing items node */
 
129
    PL_LOCK;
 
130
    p_playlist->p_playing = playlist_NodeCreate(
 
131
        p_playlist, _( "Playlist" ), p_playlist->p_root,
 
132
        PLAYLIST_END, PLAYLIST_RO_FLAG, NULL );
 
133
 
 
134
    PL_UNLOCK;
 
135
 
 
136
    if( !p_playlist->p_playing ) return NULL;
 
137
 
 
138
    /* Create media library node */
 
139
    const bool b_ml = var_InheritBool( p_parent, "media-library");
 
140
    if( b_ml )
 
141
    {
 
142
        PL_LOCK;
 
143
        p_playlist->p_media_library = playlist_NodeCreate(
 
144
            p_playlist, _( "Media Library" ), p_playlist->p_root,
 
145
            PLAYLIST_END, PLAYLIST_RO_FLAG, NULL );
138
146
        PL_UNLOCK;
139
147
 
140
 
        if(!p_playlist->p_ml_category || !p_playlist->p_ml_onelevel)
141
 
            return NULL;
142
 
 
143
 
        p_playlist->p_ml_category->i_flags |= PLAYLIST_RO_FLAG;
144
 
        p_playlist->p_ml_onelevel->i_flags |= PLAYLIST_RO_FLAG;
 
148
        if(!p_playlist->p_media_library ) return NULL;
145
149
    }
146
150
    else
147
151
    {
148
 
        p_playlist->p_ml_category = p_playlist->p_ml_onelevel = NULL;
 
152
        p_playlist->p_media_library = NULL;
149
153
    }
150
154
 
 
155
    p_playlist->p_root_category = p_playlist->p_root;
 
156
    p_playlist->p_root_onelevel = p_playlist->p_root;
 
157
    p_playlist->p_local_category = p_playlist->p_playing;
 
158
    p_playlist->p_local_onelevel = p_playlist->p_playing;
 
159
    p_playlist->p_ml_category = p_playlist->p_media_library;
 
160
    p_playlist->p_ml_onelevel = p_playlist->p_media_library;;
 
161
 
151
162
    /* Initial status */
152
163
    pl_priv(p_playlist)->status.p_item = NULL;
153
 
    pl_priv(p_playlist)->status.p_node = p_playlist->p_local_onelevel;
 
164
    pl_priv(p_playlist)->status.p_node = p_playlist->p_playing;
154
165
    pl_priv(p_playlist)->request.b_request = false;
155
166
    pl_priv(p_playlist)->status.i_status = PLAYLIST_STOPPED;
156
167
 
157
 
    pl_priv(p_playlist)->b_auto_preparse = false;
158
 
    playlist_MLLoad( p_playlist );
159
 
    pl_priv(p_playlist)->b_auto_preparse = b_auto_preparse;
160
 
 
161
 
    vlc_object_set_destructor( p_playlist, playlist_Destructor );
 
168
    if(b_ml)
 
169
    {
 
170
        const bool b_auto_preparse = pl_priv(p_playlist)->b_auto_preparse;
 
171
        pl_priv(p_playlist)->b_auto_preparse = false;
 
172
        playlist_MLLoad( p_playlist );
 
173
        pl_priv(p_playlist)->b_auto_preparse = b_auto_preparse;
 
174
    }
162
175
 
163
176
    return p_playlist;
164
177
}
165
178
 
166
179
/**
167
 
 * Destroy playlist
 
180
 * Destroy playlist.
 
181
 * This is not thread-safe. Any reference to the playlist is assumed gone.
 
182
 * (In particular, all interface and services threads must have been joined).
168
183
 *
169
 
 * Destroy a playlist structure.
170
184
 * \param p_playlist the playlist object
171
 
 * \return nothing
172
185
 */
173
 
 
174
 
static void playlist_Destructor( vlc_object_t * p_this )
 
186
void playlist_Destroy( playlist_t *p_playlist )
175
187
{
176
 
    playlist_t *p_playlist = (playlist_t *)p_this;
177
188
    playlist_private_t *p_sys = pl_priv(p_playlist);
178
189
 
 
190
    msg_Dbg( p_playlist, "destroying" );
 
191
    if( p_sys->p_preparser )
 
192
        playlist_preparser_Delete( p_sys->p_preparser );
 
193
    if( p_sys->p_fetcher )
 
194
        playlist_fetcher_Delete( p_sys->p_fetcher );
 
195
 
 
196
    /* Already cleared when deactivating (if activated anyway) */
179
197
    assert( !p_sys->p_input );
180
198
    assert( !p_sys->p_input_resource );
181
 
    assert( !p_sys->p_preparser );
182
 
    assert( !p_sys->p_fetcher );
183
199
 
184
200
    vlc_cond_destroy( &p_sys->signal );
185
201
    vlc_mutex_destroy( &p_sys->lock );
201
217
    ARRAY_RESET( p_playlist->items );
202
218
    ARRAY_RESET( p_playlist->current );
203
219
 
204
 
    msg_Dbg( p_this, "Destroyed" );
 
220
    vlc_object_release( p_playlist );
205
221
}
206
222
 
207
223
/** Get current playing input.
266
282
    pl_priv(p_playlist)->status.p_node = p_node;
267
283
}
268
284
 
 
285
static input_thread_t *playlist_FindInput( vlc_object_t *object )
 
286
{
 
287
    assert( object == VLC_OBJECT(pl_Get(object)) );
 
288
    return playlist_CurrentInput( (playlist_t *)object );
 
289
}
 
290
 
269
291
static void VariablesInit( playlist_t *p_playlist )
270
292
{
271
293
    /* These variables control updates */
272
294
    var_Create( p_playlist, "intf-change", VLC_VAR_BOOL );
273
295
    var_SetBool( p_playlist, "intf-change", true );
274
296
 
275
 
    var_Create( p_playlist, "item-change", VLC_VAR_INTEGER );
276
 
    var_SetInteger( p_playlist, "item-change", -1 );
 
297
    var_Create( p_playlist, "item-change", VLC_VAR_ADDRESS );
 
298
    var_Create( p_playlist, "leaf-to-parent", VLC_VAR_ADDRESS );
277
299
 
278
300
    var_Create( p_playlist, "playlist-item-deleted", VLC_VAR_INTEGER );
279
301
    var_SetInteger( p_playlist, "playlist-item-deleted", -1 );
280
302
 
281
303
    var_Create( p_playlist, "playlist-item-append", VLC_VAR_ADDRESS );
282
304
 
283
 
    var_Create( p_playlist, "item-current", VLC_VAR_INTEGER );
284
 
    var_SetInteger( p_playlist, "item-current", -1 );
 
305
    var_Create( p_playlist, "item-current", VLC_VAR_ADDRESS );
 
306
    var_Create( p_playlist, "input-current", VLC_VAR_ADDRESS );
285
307
 
286
308
    var_Create( p_playlist, "activity", VLC_VAR_INTEGER );
287
309
    var_SetInteger( p_playlist, "activity", 0 );
297
319
 
298
320
    /* */
299
321
    var_Create( p_playlist, "album-art", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
 
322
 
 
323
    /* Variables to preserve video output parameters */
 
324
    var_Create( p_playlist, "fullscreen", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
 
325
    var_Create( p_playlist, "video-on-top", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
 
326
 
 
327
    /* Audio output parameters */
 
328
    var_Create( p_playlist, "volume-muted", VLC_VAR_BOOL );
 
329
    var_Create( p_playlist, "saved-volume", VLC_VAR_INTEGER );
 
330
    var_Create( p_playlist, "volume-change", VLC_VAR_VOID );
 
331
    /* FIXME: horrible hack for audio output interface code */
 
332
    var_Create( p_playlist, "find-input-callback", VLC_VAR_ADDRESS );
 
333
    var_SetAddress( p_playlist, "find-input-callback", playlist_FindInput );
300
334
}
301
335
 
302
336
playlist_item_t * playlist_CurrentPlayingItem( playlist_t * p_playlist )