~ubuntu-branches/ubuntu/utopic/mpd/utopic-proposed

« back to all changes in this revision

Viewing changes to src/playlist_queue.c

  • Committer: Package Import Robot
  • Author(s): Steve Kowalik
  • Date: 2013-11-12 18:17:40 UTC
  • mfrom: (2.2.36 sid)
  • Revision ID: package-import@ubuntu.com-20131112181740-72aa4zihehoobedp
Tags: 0.18.3-1ubuntu1
* Merge from Debian unstable.  Remaining changes:
  - Add libmp3lame-dev to Build-Depends, and enable LAME.
  - Read the user for the daemon from the config file in the init script.
  - Move avahi-daemon from Suggests to Recommends.
  - Added apport hook to include user configuration file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright (C) 2003-2011 The Music Player Daemon Project
3
 
 * http://www.musicpd.org
4
 
 *
5
 
 * This program is free software; you can redistribute it and/or modify
6
 
 * it under the terms of the GNU General Public License as published by
7
 
 * the Free Software Foundation; either version 2 of the License, or
8
 
 * (at your option) any later version.
9
 
 *
10
 
 * This program is distributed in the hope that it will be useful,
11
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 
 * GNU General Public License for more details.
14
 
 *
15
 
 * You should have received a copy of the GNU General Public License along
16
 
 * with this program; if not, write to the Free Software Foundation, Inc.,
17
 
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18
 
 */
19
 
 
20
 
#include "config.h"
21
 
#include "playlist_queue.h"
22
 
#include "playlist_plugin.h"
23
 
#include "playlist_any.h"
24
 
#include "playlist_song.h"
25
 
#include "playlist.h"
26
 
#include "song.h"
27
 
#include "input_stream.h"
28
 
 
29
 
enum playlist_result
30
 
playlist_load_into_queue(const char *uri, struct playlist_provider *source,
31
 
                         unsigned start_index, unsigned end_index,
32
 
                         struct playlist *dest, struct player_control *pc,
33
 
                         bool secure)
34
 
{
35
 
        enum playlist_result result;
36
 
        struct song *song;
37
 
        char *base_uri = uri != NULL ? g_path_get_dirname(uri) : NULL;
38
 
 
39
 
        for (unsigned i = 0;
40
 
             i < end_index && (song = playlist_plugin_read(source)) != NULL;
41
 
             ++i) {
42
 
                if (i < start_index) {
43
 
                        /* skip songs before the start index */
44
 
                        if (!song_in_database(song))
45
 
                                song_free(song);
46
 
                        continue;
47
 
                }
48
 
 
49
 
                song = playlist_check_translate_song(song, base_uri, secure);
50
 
                if (song == NULL)
51
 
                        continue;
52
 
 
53
 
                result = playlist_append_song(dest, pc, song, NULL);
54
 
                if (result != PLAYLIST_RESULT_SUCCESS) {
55
 
                        if (!song_in_database(song))
56
 
                                song_free(song);
57
 
                        g_free(base_uri);
58
 
                        return result;
59
 
                }
60
 
        }
61
 
 
62
 
        g_free(base_uri);
63
 
 
64
 
        return PLAYLIST_RESULT_SUCCESS;
65
 
}
66
 
 
67
 
enum playlist_result
68
 
playlist_open_into_queue(const char *uri,
69
 
                         unsigned start_index, unsigned end_index,
70
 
                         struct playlist *dest, struct player_control *pc,
71
 
                         bool secure)
72
 
{
73
 
        GMutex *mutex = g_mutex_new();
74
 
        GCond *cond = g_cond_new();
75
 
 
76
 
        struct input_stream *is;
77
 
        struct playlist_provider *playlist =
78
 
                playlist_open_any(uri, mutex, cond, &is);
79
 
        if (playlist == NULL) {
80
 
                g_cond_free(cond);
81
 
                g_mutex_free(mutex);
82
 
                return PLAYLIST_RESULT_NO_SUCH_LIST;
83
 
        }
84
 
 
85
 
        enum playlist_result result =
86
 
                playlist_load_into_queue(uri, playlist, start_index, end_index,
87
 
                                         dest, pc, secure);
88
 
        playlist_plugin_close(playlist);
89
 
 
90
 
        if (is != NULL)
91
 
                input_stream_close(is);
92
 
 
93
 
        g_cond_free(cond);
94
 
        g_mutex_free(mutex);
95
 
 
96
 
        return result;
97
 
}