1 /*
2  * Strawberry Music Player
3  * This file was part of Clementine.
4  * Copyright 2010, David Sansome <me@davidsansome.com>
5  * Copyright 2017-2018, Jonas Kvinge <jonas@jkvinge.net>
6  *
7  * Strawberry is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * Strawberry is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with Strawberry.  If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef VLCENGINE_H
23 #define VLCENGINE_H
24 
25 #include "config.h"
26 
27 #include <vlc/vlc.h>
28 
29 #include <QtGlobal>
30 #include <QObject>
31 #include <QString>
32 #include <QUrl>
33 
34 #include "engine_fwd.h"
35 #include "enginebase.h"
36 
37 struct libvlc_event_t;
38 
39 class TaskManager;
40 
41 class VLCEngine : public Engine::Base {
42   Q_OBJECT
43 
44  public:
45   explicit VLCEngine(TaskManager *task_manager, QObject *parent = nullptr);
46   ~VLCEngine() override;
47 
48   bool Init() override;
state()49   Engine::State state() const override { return state_; }
50   bool Load(const QUrl &stream_url, const QUrl &original_url, const Engine::TrackChangeFlags change, const bool force_stop_at_end, const quint64 beginning_nanosec, const qint64 end_nanosec) override;
51   bool Play(const quint64 offset_nanosec) override;
52   void Stop(const bool stop_after = false) override;
53   void Pause() override;
54   void Unpause() override;
55   void Seek(const quint64 offset_nanosec) override;
56 
57  protected:
58   void SetVolumeSW(const uint percent) override;
59 
60  public:
61   qint64 position_nanosec() const override;
62   qint64 length_nanosec() const override;
63 
64   OutputDetailsList GetOutputsList() const override;
65   bool ValidOutput(const QString &output) override;
DefaultOutput()66   QString DefaultOutput() override { return ""; }
67   bool CustomDeviceSupport(const QString &output) override;
68   bool ALSADeviceSupport(const QString &output) override;
69 
70  private:
71   libvlc_instance_t *instance_;
72   libvlc_media_player_t *player_;
73   Engine::State state_;
74 
Initialized()75   bool Initialized() const { return (instance_ && player_); }
76   uint position() const;
77   uint length() const;
78   static bool CanDecode(const QUrl &url);
79   void AttachCallback(libvlc_event_manager_t *em, libvlc_event_type_t type, libvlc_callback_t callback);
80   static void StateChangedCallback(const libvlc_event_t *e, void *data);
81 
82   PluginDetailsList GetPluginList() const;
83   void GetDevicesList(const QString &output) const;
84 
85 };
86 
87 #endif  // VLCENGINE_H
88