1/*
2 Copyright (C) 2011 vlc-phonon AUTHORS <kde-multimedia@kde.org>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public
15 License along with this library. If not, see <http://www.gnu.org/licenses/>.
16*/
17
18#ifndef LIBVLC_H
19#define LIBVLC_H
20
21#include <QtCore/QtGlobal>
22#include <QtCore/QStringList>
23
24#include <vlc/libvlc_version.h>
25
26struct libvlc_instance_t;
27
28/**
29 * Convenience macro accessing the vlc_instance_t via LibVLC::self.
30 * Please note that init() must have been called whenever using this, as no
31 * checking of self is conducted (i.e. can be null).
32 */
33#define pvlc_libvlc LibVLC::self->vlc()
34
35/**
36 * Foreach loop macro for VLC descriptions.
37 *
38 * For this macro to work the type name must be of the form:
39 * \verbatim libvlc_FOO_t \endverbatim
40 * *
41 * \param type the type identifier of VLC (without libvlc and _t)
42 * \param variable the variable name you want to use
43 * \param getter the getter from which to get the iterator
44 * \param releaser, function name to release the list
45 */
46#define VLC_FOREACH(type, variable, getter, releaser) \
47 for (libvlc_##type##_t *__libvlc_first_element = getter, *variable = __libvlc_first_element; \
48 variable; \
49 variable = variable->p_next, !variable ? releaser(__libvlc_first_element) : (void)0)
50
51// This foreach expects only a type and variable because getter and releaser are generic.
52// Also the type is in short form i.e. libvlc_foo_t would be foo.
53#define VLC_FOREACH_LIST(type, variable) VLC_FOREACH(type, variable, libvlc_##type##_list_get(pvlc_libvlc), libvlc_##type##_list_release)
54
55// These foreach expect no type because the type is generic, they do however
56// expect a getter to allow usage with our wrapper classes and since the getter
57// will most likely not be generic.
58// For instance libvlc_audio_get_track_description returns a generic
59// libvlc_track_description_t pointer. So the specific audio_track function
60// relates to the generic track description type.
61#define VLC_FOREACH_TRACK(variable, getter) VLC_FOREACH(track_description, variable, getter, libvlc_track_description_list_release)
62#define VLC_FOREACH_MODULE(variable, getter) VLC_FOREACH(module_description, variable, getter, libvlc_module_description_list_release)
63
64/**
65 * \brief Singleton class containing a libvlc instance.
66 *
67 * This class is a convenience class implementing the singleton pattern to hold
68 * an instance of libvlc. This instance is necessary to call various libvlc
69 * functions (such as creating a new mediaplayer instance).
70 *
71 * To initialize the object call init(), this will create the actually LibVLC
72 * instance and then try to initialize the libvlc instance itself.
73 * init() returns false in case the libvlc instance could not be created.
74 *
75 * For convenience reasons there is also a libvlc macro which gets the LibVLC
76 * instance and then the libvlc_instance_t form that. Note that this macro
77 * does not check whether LibVLC actually got initialized, so it should only
78 * be used when you can be absolutely sure that init() was already called
79 *
80 * \code
81 * LibVLC::init(0); // init LibVLC
82 * if (!LibVLC::self) {
83 * exit(1); // error if self is null
84 * }
85 * libvlc_media_player_new(libvlc); // use libvlc macro
86 * \endcode
87 *
88 * \author Harald Sitter <sitter@kde->org>
89 */
90class LibVLC
91{
92public:
93 /**
94 * The singleton itself. Beware that this returns 0 unless init was called.
95 *
96 * \returns LibVLC instance or 0 if there is none.
97 *
98 * \see init
99 */
100 static LibVLC *self;
101
102 /**
103 * \returns the contained libvlc instance.
104 */
105 libvlc_instance_t *vlc()
106 {
107 return m_vlcInstance;
108 }
109
110 /**
111 * Construct singleton and initialize and launch the VLC library.
112 *
113 * \return VLC initialization result
114 */
115 static bool init();
116
117 /**
118 * \returns the most recent error message of libvlc
119 */
120 static const char *errorMessage();
121
122 /**
123 * Destruct the LibVLC singleton and release the contained libvlc instance.
124 */
125 ~LibVLC();
126
127private:
128 Q_DISABLE_COPY(LibVLC)
129
130 /**
131 * Private default constructor, to create LibVLC call init instead.
132 *
133 * \see init
134 */
135 LibVLC();
136
137 libvlc_instance_t *m_vlcInstance;
138};
139
140#endif // LIBVLC_H
141

source code of phonon-vlc/src/utils/libvlc.h