File indexing completed on 2024-05-12 04:44:37

0001 /*
0002     Copyright (C) 2011 vlc-phonon AUTHORS <kde-multimedia@kde.org>
0003 
0004     This library is free software; you can redistribute it and/or
0005     modify it under the terms of the GNU Lesser General Public
0006     License as published by the Free Software Foundation; either
0007     version 2.1 of the License, or (at your option) any later version.
0008 
0009     This library is distributed in the hope that it will be useful,
0010     but WITHOUT ANY WARRANTY; without even the implied warranty of
0011     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0012     Lesser General Public License for more details.
0013 
0014     You should have received a copy of the GNU Lesser General Public
0015     License along with this library.  If not, see <http://www.gnu.org/licenses/>.
0016 */
0017 
0018 #ifndef LIBVLC_H
0019 #define LIBVLC_H
0020 
0021 #include <QtCore/QtGlobal>
0022 #include <QtCore/QStringList>
0023 
0024 #include <vlc/libvlc_version.h>
0025 
0026 struct libvlc_instance_t;
0027 
0028 /**
0029  * Convenience macro accessing the vlc_instance_t via LibVLC::self.
0030  * Please note that init() must have been called whenever using this, as no
0031  * checking of self is conducted (i.e. can be null).
0032  */
0033 #define pvlc_libvlc LibVLC::self->vlc()
0034 
0035 /**
0036  * Foreach loop macro for VLC descriptions.
0037  *
0038  * For this macro to work the type name must be of the form:
0039  * \verbatim libvlc_FOO_t \endverbatim
0040  * *
0041  * \param type the type identifier of VLC (without libvlc and _t)
0042  * \param variable the variable name you want to use
0043  * \param getter the getter from which to get the iterator
0044  * \param releaser, function name to release the list
0045  */
0046 #define VLC_FOREACH(type, variable, getter, releaser) \
0047     for (libvlc_##type##_t *__libvlc_first_element = getter, *variable = __libvlc_first_element; \
0048         variable; \
0049         variable = variable->p_next, !variable ? releaser(__libvlc_first_element) : (void)0)
0050 
0051 // This foreach expects only a type and variable because getter and releaser are generic.
0052 // Also the type is in short form i.e. libvlc_foo_t would be foo.
0053 #define VLC_FOREACH_LIST(type, variable) VLC_FOREACH(type, variable, libvlc_##type##_list_get(pvlc_libvlc), libvlc_##type##_list_release)
0054 
0055 // These foreach expect no type because the type is generic, they do however
0056 // expect a getter to allow usage with our wrapper classes and since the getter
0057 // will most likely not be generic.
0058 // For instance libvlc_audio_get_track_description returns a generic
0059 // libvlc_track_description_t pointer. So the specific audio_track function
0060 // relates to the generic track description type.
0061 #define VLC_FOREACH_TRACK(variable, getter) VLC_FOREACH(track_description, variable, getter, libvlc_track_description_list_release)
0062 #define VLC_FOREACH_MODULE(variable, getter) VLC_FOREACH(module_description, variable, getter, libvlc_module_description_list_release)
0063 
0064 /**
0065  * \brief Singleton class containing a libvlc instance.
0066  *
0067  * This class is a convenience class implementing the singleton pattern to hold
0068  * an instance of libvlc. This instance is necessary to call various libvlc
0069  * functions (such as creating a new mediaplayer instance).
0070  *
0071  * To initialize the object call init(), this will create the actually LibVLC
0072  * instance and then try to initialize the libvlc instance itself.
0073  * init() returns false in case the libvlc instance could not be created.
0074  *
0075  * For convenience reasons there is also a libvlc macro which gets the LibVLC
0076  * instance and then the libvlc_instance_t form that. Note that this macro
0077  * does not check whether LibVLC actually got initialized, so it should only
0078  * be used when you can be absolutely sure that init() was already called
0079  *
0080  * \code
0081  * LibVLC::init(0); // init LibVLC
0082  * if (!LibVLC::self) {
0083  *     exit(1); // error if self is null
0084  * }
0085  * libvlc_media_player_new(libvlc); // use libvlc macro
0086  * \endcode
0087  *
0088  * \author Harald Sitter <sitter@kde->org>
0089  */
0090 class LibVLC
0091 {
0092 public:
0093     /**
0094      * The singleton itself. Beware that this returns 0 unless init was called.
0095      *
0096      * \returns LibVLC instance or 0 if there is none.
0097      *
0098      * \see init
0099      */
0100     static LibVLC *self;
0101 
0102     /**
0103      * \returns the contained libvlc instance.
0104      */
0105     libvlc_instance_t *vlc()
0106     {
0107         return m_vlcInstance;
0108     }
0109 
0110     /**
0111      * Construct singleton and initialize and launch the VLC library.
0112      *
0113      * \return VLC initialization result
0114      */
0115     static bool init();
0116 
0117     /**
0118      * \returns the most recent error message of libvlc
0119      */
0120     static const char *errorMessage();
0121 
0122     /**
0123      * Destruct the LibVLC singleton and release the contained libvlc instance.
0124      */
0125     ~LibVLC();
0126 
0127 private:
0128     Q_DISABLE_COPY(LibVLC)
0129 
0130     /**
0131      * Private default constructor, to create LibVLC call init instead.
0132      *
0133      * \see init
0134      */
0135     LibVLC();
0136 
0137     libvlc_instance_t *m_vlcInstance;
0138 };
0139 
0140 #endif // LIBVLC_H