1 /*****************************************************************************
2 * VLC backend for the Phonon library *
3 * Copyright (C) 2007-2008 Tanguy Krotoff <tkrotoff@gmail.com> *
4 * Copyright (C) 2008 Lukas Durfina <lukas.durfina@gmail.com> *
5 * Copyright (C) 2009 Fathi Boudra <fabo@kde.org> *
7 * This program is free software; you can redistribute it and/or *
8 * modify it under the terms of the GNU Lesser General Public *
9 * License as published by the Free Software Foundation; either *
10 * version 3 of the License, or (at your option) any later version. *
12 * This program 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 GNU *
15 * Lesser General Public License for more details. *
17 * You should have received a copy of the GNU Lesser General Public *
18 * License along with this package; if not, write to the Free Software *
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA *
20 *****************************************************************************/
22 #include "vlcmediacontroller.h"
24 #include "vlcloader.h"
30 VLCMediaController::VLCMediaController()
33 p_vlc_media_player = 0;
36 VLCMediaController::~VLCMediaController()
40 void VLCMediaController::clearMediaController()
42 current_audio_channel = Phonon::AudioChannelDescription();
43 available_audio_channels.clear();
45 current_subtitle = Phonon::SubtitleDescription();
46 available_subtitles.clear();
49 i_available_angles = 0;
51 // current_chapter = Phonon::ChapterDescription();
52 // available_chapters.clear();
54 available_chapters = 0;
56 // current_title = Phonon::TitleDescription();
57 // available_titles.clear();
61 b_autoplay_titles = false;
63 emit availableAudioChannelsChanged();
64 emit availableSubtitlesChanged();
65 emit availableTitlesChanged(0);
66 emit availableChaptersChanged(0);
69 // Add audio channel -> in libvlc it is track, it means audio in another language
70 void VLCMediaController::audioChannelAdded(int id, const QString & lang)
72 QHash<QByteArray, QVariant> properties;
73 properties.insert("name", lang);
74 properties.insert("description", "");
76 available_audio_channels << Phonon::AudioChannelDescription(id, properties);
77 emit availableAudioChannelsChanged();
81 void VLCMediaController::subtitleAdded(int id, const QString & lang, const QString & type)
83 QHash<QByteArray, QVariant> properties;
84 properties.insert("name", lang);
85 properties.insert("description", "");
86 properties.insert("type", type);
88 available_subtitles << Phonon::SubtitleDescription(id, properties);
89 emit availableSubtitlesChanged();
93 void VLCMediaController::titleAdded(int id, const QString & name)
95 // QHash<QByteArray, QVariant> properties;
96 // properties.insert("name", name);
97 // properties.insert("description", "");
99 // available_titles << Phonon::TitleDescription(id, properties);
101 emit availableTitlesChanged(available_titles);
105 void VLCMediaController::chapterAdded(int titleId, const QString & name)
107 // QHash<QByteArray, QVariant> properties;
108 // properties.insert("name", name);
109 // properties.insert("description", "");
111 // available_chapters << Phonon::ChapterDescription(titleId, properties);
112 available_chapters++;
113 emit availableChaptersChanged(available_chapters);
118 void VLCMediaController::setCurrentAudioChannel(const Phonon::AudioChannelDescription & audioChannel)
120 current_audio_channel = audioChannel;
121 libvlc_audio_set_track(p_vlc_media_player, audioChannel.index(), vlc_exception);
122 vlcExceptionRaised();
125 QList<Phonon::AudioChannelDescription> VLCMediaController::availableAudioChannels() const
127 return available_audio_channels;
130 Phonon::AudioChannelDescription VLCMediaController::currentAudioChannel() const
132 return current_audio_channel;
135 void VLCMediaController::refreshAudioChannels()
137 current_audio_channel = Phonon::AudioChannelDescription();
138 available_audio_channels.clear();
140 libvlc_track_description_t * p_info = libvlc_audio_get_track_description(
141 p_vlc_media_player, vlc_exception);
142 vlcExceptionRaised();
144 audioChannelAdded(p_info->i_id, p_info->psz_name);
145 p_info = p_info->p_next;
147 libvlc_track_description_release(p_info);
152 void VLCMediaController::setCurrentSubtitle(const Phonon::SubtitleDescription & subtitle)
154 current_subtitle = subtitle;
155 // int id = current_subtitle.index();
156 QString type = current_subtitle.property("type").toString();
158 if (type == "file") {
159 QString filename = current_subtitle.property("name").toString();
160 if (!filename.isEmpty()) {
161 libvlc_video_set_subtitle_file(p_vlc_media_player,
162 filename.toAscii().data(),
164 vlcExceptionRaised();
166 // There is no subtitle event inside libvlc so let's send our own event...
167 available_subtitles << current_subtitle;
168 emit availableSubtitlesChanged();
171 libvlc_video_set_spu(p_vlc_media_player, subtitle.index(), vlc_exception);
172 vlcExceptionRaised();
176 QList<Phonon::SubtitleDescription> VLCMediaController::availableSubtitles() const
178 return available_subtitles;
181 Phonon::SubtitleDescription VLCMediaController::currentSubtitle() const
183 return current_subtitle;
186 void VLCMediaController::refreshSubtitles()
188 current_subtitle = Phonon::SubtitleDescription();
189 available_subtitles.clear();
191 libvlc_track_description_t *p_info = libvlc_video_get_spu_description(
192 p_vlc_media_player, vlc_exception);
193 vlcExceptionRaised();
195 subtitleAdded(p_info->i_id, p_info->psz_name, "");
196 p_info = p_info->p_next;
198 libvlc_track_description_release(p_info);
203 //void VLCMediaController::setCurrentTitle( const Phonon::TitleDescription & title )
204 void VLCMediaController::setCurrentTitle(int title)
206 current_title = title;
208 // libvlc_media_player_set_title(p_vlc_media_player, title.index(), vlc_exception);
209 libvlc_media_player_set_title(p_vlc_media_player, title, vlc_exception);
210 vlcExceptionRaised();
213 //QList<Phonon::TitleDescription> VLCMediaController::availableTitles() const
214 int VLCMediaController::availableTitles() const
216 return available_titles;
219 //Phonon::TitleDescription VLCMediaController::currentTitle() const
220 int VLCMediaController::currentTitle() const
222 return current_title;
225 void VLCMediaController::setAutoplayTitles(bool autoplay)
227 b_autoplay_titles = autoplay;
230 bool VLCMediaController::autoplayTitles() const
232 return b_autoplay_titles;
237 //void VLCMediaController::setCurrentChapter(const Phonon::ChapterDescription &chapter)
238 void VLCMediaController::setCurrentChapter(int chapter)
240 current_chapter = chapter;
241 // libvlc_media_player_set_chapter(p_vlc_media_player, chapter.index(), vlc_exception);
242 libvlc_media_player_set_chapter(p_vlc_media_player, chapter, vlc_exception);
243 vlcExceptionRaised();
246 //QList<Phonon::ChapterDescription> VLCMediaController::availableChapters() const
247 int VLCMediaController::availableChapters() const
249 return available_chapters;
252 //Phonon::ChapterDescription VLCMediaController::currentChapter() const
253 int VLCMediaController::currentChapter() const
255 return current_chapter;
258 // We need to rebuild available chapters when title is changed
259 void VLCMediaController::refreshChapters(int i_title)
261 // current_chapter = Phonon::ChapterDescription();
262 // available_chapters.clear();
264 available_chapters = 0;
266 // Get the description of available chapters for specific title
267 libvlc_track_description_t *p_info = libvlc_video_get_chapter_description(
268 p_vlc_media_player, i_title, vlc_exception);
269 vlcExceptionRaised();
271 chapterAdded(p_info->i_id, p_info->psz_name);
272 p_info = p_info->p_next;
274 libvlc_track_description_release(p_info);
279 void VLCMediaController::setCurrentAngle(int angleNumber)
281 i_current_angle = angleNumber;
284 int VLCMediaController::availableAngles() const
286 return i_available_angles;
289 int VLCMediaController::currentAngle() const
291 return i_current_angle;
295 } // Namespace Phonon::VLC