2 * Copyright (C) 2012-2013 Team XBMC
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, or (at your option)
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.
15 * You should have received a copy of the GNU General Public License
16 * along with XBMC; see the file COPYING. If not, see
17 * <http://www.gnu.org/licenses/>.
21 #include "PlayerController.h"
22 #include "utils/StdString.h"
23 #include "settings/AdvancedSettings.h"
24 #include "settings/DisplaySettings.h"
25 #include "settings/MediaSettings.h"
26 #include "settings/Settings.h"
27 #include "cores/IPlayer.h"
28 #include "guilib/Key.h"
29 #include "guilib/LocalizeStrings.h"
30 #include "guilib/GUISliderControl.h"
31 #include "dialogs/GUIDialogKaiToast.h"
32 #include "video/dialogs/GUIDialogAudioSubtitleSettings.h"
33 #include "video/windows/GUIWindowFullScreen.h"
34 #ifdef HAS_VIDEO_PLAYBACK
35 #include "cores/VideoRenderers/RenderManager.h"
36 #include "cores/VideoRenderers/OverlayRendererGUI.h"
38 #include "Application.h"
39 #include "utils/LangCodeExpander.h"
40 #include "utils/StringUtils.h"
42 CPlayerController::CPlayerController()
47 CPlayerController::~CPlayerController()
51 bool CPlayerController::OnAction(const CAction &action)
53 const unsigned int MsgTime = 300;
54 const unsigned int DisplTime = 2000;
56 if (g_application.m_pPlayer->IsPlayingVideo())
58 switch (action.GetID())
60 case ACTION_SHOW_SUBTITLES:
62 if (g_application.m_pPlayer->GetSubtitleCount() == 0)
65 CMediaSettings::Get().GetCurrentVideoSettings().m_SubtitleOn = !CMediaSettings::Get().GetCurrentVideoSettings().m_SubtitleOn;
66 g_application.m_pPlayer->SetSubtitleVisible(CMediaSettings::Get().GetCurrentVideoSettings().m_SubtitleOn);
68 if (CMediaSettings::Get().GetCurrentVideoSettings().m_SubtitleOn)
70 SPlayerSubtitleStreamInfo info;
71 g_application.m_pPlayer->GetSubtitleStreamInfo(CMediaSettings::Get().GetCurrentVideoSettings().m_SubtitleStream, info);
72 if (!g_LangCodeExpander.Lookup(lang, info.language))
73 lang = g_localizeStrings.Get(13205); // Unknown
75 if (info.name.length() == 0)
78 sub = StringUtils::Format("%s - %s", lang.c_str(), info.name.c_str());
81 sub = g_localizeStrings.Get(1223);
82 CGUIDialogKaiToast::QueueNotification(CGUIDialogKaiToast::Info,
83 g_localizeStrings.Get(287), sub, DisplTime, false, MsgTime);
87 case ACTION_NEXT_SUBTITLE:
89 if (g_application.m_pPlayer->GetSubtitleCount() == 0)
92 if(CMediaSettings::Get().GetCurrentVideoSettings().m_SubtitleStream < 0)
93 CMediaSettings::Get().GetCurrentVideoSettings().m_SubtitleStream = g_application.m_pPlayer->GetSubtitle();
95 if (CMediaSettings::Get().GetCurrentVideoSettings().m_SubtitleOn)
97 CMediaSettings::Get().GetCurrentVideoSettings().m_SubtitleStream++;
98 if (CMediaSettings::Get().GetCurrentVideoSettings().m_SubtitleStream >= g_application.m_pPlayer->GetSubtitleCount())
100 CMediaSettings::Get().GetCurrentVideoSettings().m_SubtitleStream = 0;
101 CMediaSettings::Get().GetCurrentVideoSettings().m_SubtitleOn = false;
102 g_application.m_pPlayer->SetSubtitleVisible(false);
104 g_application.m_pPlayer->SetSubtitle(CMediaSettings::Get().GetCurrentVideoSettings().m_SubtitleStream);
108 CMediaSettings::Get().GetCurrentVideoSettings().m_SubtitleOn = true;
109 g_application.m_pPlayer->SetSubtitleVisible(true);
112 CStdString sub, lang;
113 if (CMediaSettings::Get().GetCurrentVideoSettings().m_SubtitleOn)
115 SPlayerSubtitleStreamInfo info;
116 g_application.m_pPlayer->GetSubtitleStreamInfo(CMediaSettings::Get().GetCurrentVideoSettings().m_SubtitleStream, info);
117 if (!g_LangCodeExpander.Lookup(lang, info.language))
118 lang = g_localizeStrings.Get(13205); // Unknown
120 if (info.name.length() == 0)
123 sub = StringUtils::Format("%s - %s", lang.c_str(), info.name.c_str());
126 sub = g_localizeStrings.Get(1223);
127 CGUIDialogKaiToast::QueueNotification(CGUIDialogKaiToast::Info, g_localizeStrings.Get(287), sub, DisplTime, false, MsgTime);
131 case ACTION_SUBTITLE_DELAY_MIN:
133 CMediaSettings::Get().GetCurrentVideoSettings().m_SubtitleDelay -= 0.1f;
134 if (CMediaSettings::Get().GetCurrentVideoSettings().m_SubtitleDelay < -g_advancedSettings.m_videoSubsDelayRange)
135 CMediaSettings::Get().GetCurrentVideoSettings().m_SubtitleDelay = -g_advancedSettings.m_videoSubsDelayRange;
136 g_application.m_pPlayer->SetSubTitleDelay(CMediaSettings::Get().GetCurrentVideoSettings().m_SubtitleDelay);
138 ShowSlider(action.GetID(), 22006, CMediaSettings::Get().GetCurrentVideoSettings().m_SubtitleDelay,
139 -g_advancedSettings.m_videoSubsDelayRange, 0.1f,
140 g_advancedSettings.m_videoSubsDelayRange);
144 case ACTION_SUBTITLE_DELAY_PLUS:
146 CMediaSettings::Get().GetCurrentVideoSettings().m_SubtitleDelay += 0.1f;
147 if (CMediaSettings::Get().GetCurrentVideoSettings().m_SubtitleDelay > g_advancedSettings.m_videoSubsDelayRange)
148 CMediaSettings::Get().GetCurrentVideoSettings().m_SubtitleDelay = g_advancedSettings.m_videoSubsDelayRange;
149 g_application.m_pPlayer->SetSubTitleDelay(CMediaSettings::Get().GetCurrentVideoSettings().m_SubtitleDelay);
151 ShowSlider(action.GetID(), 22006, CMediaSettings::Get().GetCurrentVideoSettings().m_SubtitleDelay,
152 -g_advancedSettings.m_videoSubsDelayRange, 0.1f,
153 g_advancedSettings.m_videoSubsDelayRange);
157 case ACTION_SUBTITLE_DELAY:
159 ShowSlider(action.GetID(), 22006, CMediaSettings::Get().GetCurrentVideoSettings().m_SubtitleDelay,
160 -g_advancedSettings.m_videoSubsDelayRange, 0.1f,
161 g_advancedSettings.m_videoSubsDelayRange, true);
165 case ACTION_AUDIO_DELAY:
167 ShowSlider(action.GetID(), 297, CMediaSettings::Get().GetCurrentVideoSettings().m_AudioDelay,
168 -g_advancedSettings.m_videoAudioDelayRange, 0.025f,
169 g_advancedSettings.m_videoAudioDelayRange, true);
173 case ACTION_AUDIO_DELAY_MIN:
175 CMediaSettings::Get().GetCurrentVideoSettings().m_AudioDelay -= 0.025f;
176 if (CMediaSettings::Get().GetCurrentVideoSettings().m_AudioDelay < -g_advancedSettings.m_videoAudioDelayRange)
177 CMediaSettings::Get().GetCurrentVideoSettings().m_AudioDelay = -g_advancedSettings.m_videoAudioDelayRange;
178 g_application.m_pPlayer->SetAVDelay(CMediaSettings::Get().GetCurrentVideoSettings().m_AudioDelay);
180 ShowSlider(action.GetID(), 297, CMediaSettings::Get().GetCurrentVideoSettings().m_AudioDelay,
181 -g_advancedSettings.m_videoAudioDelayRange, 0.025f,
182 g_advancedSettings.m_videoAudioDelayRange);
186 case ACTION_AUDIO_DELAY_PLUS:
188 CMediaSettings::Get().GetCurrentVideoSettings().m_AudioDelay += 0.025f;
189 if (CMediaSettings::Get().GetCurrentVideoSettings().m_AudioDelay > g_advancedSettings.m_videoAudioDelayRange)
190 CMediaSettings::Get().GetCurrentVideoSettings().m_AudioDelay = g_advancedSettings.m_videoAudioDelayRange;
191 g_application.m_pPlayer->SetAVDelay(CMediaSettings::Get().GetCurrentVideoSettings().m_AudioDelay);
193 ShowSlider(action.GetID(), 297, CMediaSettings::Get().GetCurrentVideoSettings().m_AudioDelay,
194 -g_advancedSettings.m_videoAudioDelayRange, 0.025f,
195 g_advancedSettings.m_videoAudioDelayRange);
199 case ACTION_AUDIO_NEXT_LANGUAGE:
201 if (g_application.m_pPlayer->GetAudioStreamCount() == 1)
204 if(CMediaSettings::Get().GetCurrentVideoSettings().m_AudioStream < 0)
205 CMediaSettings::Get().GetCurrentVideoSettings().m_AudioStream = g_application.m_pPlayer->GetAudioStream();
207 CMediaSettings::Get().GetCurrentVideoSettings().m_AudioStream++;
208 if (CMediaSettings::Get().GetCurrentVideoSettings().m_AudioStream >= g_application.m_pPlayer->GetAudioStreamCount())
209 CMediaSettings::Get().GetCurrentVideoSettings().m_AudioStream = 0;
210 g_application.m_pPlayer->SetAudioStream(CMediaSettings::Get().GetCurrentVideoSettings().m_AudioStream); // Set the audio stream to the one selected
213 SPlayerAudioStreamInfo info;
214 g_application.m_pPlayer->GetAudioStreamInfo(CMediaSettings::Get().GetCurrentVideoSettings().m_AudioStream, info);
215 if (!g_LangCodeExpander.Lookup(lan, info.language))
216 lan = g_localizeStrings.Get(13205); // Unknown
217 if (info.name.empty())
220 aud = StringUtils::Format("%s - %s", lan.c_str(), info.name.c_str());
221 CGUIDialogKaiToast::QueueNotification(CGUIDialogKaiToast::Info, g_localizeStrings.Get(460), aud, DisplTime, false, MsgTime);
227 CMediaSettings::Get().GetCurrentVideoSettings().m_CustomZoomAmount += 0.01f;
228 if (CMediaSettings::Get().GetCurrentVideoSettings().m_CustomZoomAmount > 2.f)
229 CMediaSettings::Get().GetCurrentVideoSettings().m_CustomZoomAmount = 2.f;
230 CMediaSettings::Get().GetCurrentVideoSettings().m_ViewMode = ViewModeCustom;
231 g_renderManager.SetViewMode(ViewModeCustom);
232 ShowSlider(action.GetID(), 216, CMediaSettings::Get().GetCurrentVideoSettings().m_CustomZoomAmount, 0.5f, 0.1f, 2.0f);
236 case ACTION_ZOOM_OUT:
238 CMediaSettings::Get().GetCurrentVideoSettings().m_CustomZoomAmount -= 0.01f;
239 if (CMediaSettings::Get().GetCurrentVideoSettings().m_CustomZoomAmount < 0.5f)
240 CMediaSettings::Get().GetCurrentVideoSettings().m_CustomZoomAmount = 0.5f;
241 CMediaSettings::Get().GetCurrentVideoSettings().m_ViewMode = ViewModeCustom;
242 g_renderManager.SetViewMode(ViewModeCustom);
243 ShowSlider(action.GetID(), 216, CMediaSettings::Get().GetCurrentVideoSettings().m_CustomZoomAmount, 0.5f, 0.1f, 2.0f);
247 case ACTION_INCREASE_PAR:
249 CMediaSettings::Get().GetCurrentVideoSettings().m_CustomPixelRatio += 0.01f;
250 if (CMediaSettings::Get().GetCurrentVideoSettings().m_CustomPixelRatio > 2.f)
251 CMediaSettings::Get().GetCurrentVideoSettings().m_CustomZoomAmount = 2.f;
252 CMediaSettings::Get().GetCurrentVideoSettings().m_ViewMode = ViewModeCustom;
253 g_renderManager.SetViewMode(ViewModeCustom);
254 ShowSlider(action.GetID(), 217, CMediaSettings::Get().GetCurrentVideoSettings().m_CustomPixelRatio, 0.5f, 0.1f, 2.0f);
258 case ACTION_DECREASE_PAR:
260 CMediaSettings::Get().GetCurrentVideoSettings().m_CustomPixelRatio -= 0.01f;
261 if (CMediaSettings::Get().GetCurrentVideoSettings().m_CustomZoomAmount < 0.5f)
262 CMediaSettings::Get().GetCurrentVideoSettings().m_CustomPixelRatio = 0.5f;
263 CMediaSettings::Get().GetCurrentVideoSettings().m_ViewMode = ViewModeCustom;
264 g_renderManager.SetViewMode(ViewModeCustom);
265 ShowSlider(action.GetID(), 217, CMediaSettings::Get().GetCurrentVideoSettings().m_CustomPixelRatio, 0.5f, 0.1f, 2.0f);
269 case ACTION_VSHIFT_UP:
271 CMediaSettings::Get().GetCurrentVideoSettings().m_CustomVerticalShift -= 0.01f;
272 if (CMediaSettings::Get().GetCurrentVideoSettings().m_CustomVerticalShift < -2.0f)
273 CMediaSettings::Get().GetCurrentVideoSettings().m_CustomVerticalShift = -2.0f;
274 CMediaSettings::Get().GetCurrentVideoSettings().m_ViewMode = ViewModeCustom;
275 g_renderManager.SetViewMode(ViewModeCustom);
276 ShowSlider(action.GetID(), 225, CMediaSettings::Get().GetCurrentVideoSettings().m_CustomVerticalShift, -2.0f, 0.1f, 2.0f);
280 case ACTION_VSHIFT_DOWN:
282 CMediaSettings::Get().GetCurrentVideoSettings().m_CustomVerticalShift += 0.01f;
283 if (CMediaSettings::Get().GetCurrentVideoSettings().m_CustomVerticalShift > 2.0f)
284 CMediaSettings::Get().GetCurrentVideoSettings().m_CustomVerticalShift = 2.0f;
285 CMediaSettings::Get().GetCurrentVideoSettings().m_ViewMode = ViewModeCustom;
286 g_renderManager.SetViewMode(ViewModeCustom);
287 ShowSlider(action.GetID(), 225, CMediaSettings::Get().GetCurrentVideoSettings().m_CustomVerticalShift, -2.0f, 0.1f, 2.0f);
291 case ACTION_SUBTITLE_VSHIFT_UP:
293 RESOLUTION_INFO res_info = g_graphicsContext.GetResInfo();
294 int subalign = CSettings::Get().GetInt("subtitles.align");
295 if ((subalign == SUBTITLE_ALIGN_BOTTOM_OUTSIDE) || (subalign == SUBTITLE_ALIGN_TOP_INSIDE))
297 res_info.iSubtitles ++;
298 if (res_info.iSubtitles >= res_info.iHeight)
299 res_info.iSubtitles = res_info.iHeight - 1;
301 ShowSlider(action.GetID(), 274, (float) res_info.iHeight - res_info.iSubtitles, 0.0f, 1.0f, (float) res_info.iHeight);
305 res_info.iSubtitles --;
306 if (res_info.iSubtitles < 0)
307 res_info.iSubtitles = 0;
309 if (subalign == SUBTITLE_ALIGN_MANUAL)
310 ShowSlider(action.GetID(), 274, (float) res_info.iSubtitles, 0.0f, 1.0f, (float) res_info.iHeight);
312 ShowSlider(action.GetID(), 274, (float) res_info.iSubtitles - res_info.iHeight, (float) -res_info.iHeight, -1.0f, 0.0f);
314 g_graphicsContext.SetResInfo(g_graphicsContext.GetVideoResolution(), res_info);
318 case ACTION_SUBTITLE_VSHIFT_DOWN:
320 RESOLUTION_INFO res_info = g_graphicsContext.GetResInfo();
321 int subalign = CSettings::Get().GetInt("subtitles.align");
322 if ((subalign == SUBTITLE_ALIGN_BOTTOM_OUTSIDE) || (subalign == SUBTITLE_ALIGN_TOP_INSIDE))
324 res_info.iSubtitles--;
325 if (res_info.iSubtitles < 0)
326 res_info.iSubtitles = 0;
328 ShowSlider(action.GetID(), 274, (float) res_info.iHeight - res_info.iSubtitles, 0.0f, 1.0f, (float) res_info.iHeight);
332 res_info.iSubtitles++;
333 if (res_info.iSubtitles >= res_info.iHeight)
334 res_info.iSubtitles = res_info.iHeight - 1;
336 if (subalign == SUBTITLE_ALIGN_MANUAL)
337 ShowSlider(action.GetID(), 274, (float) res_info.iSubtitles, 0.0f, 1.0f, (float) res_info.iHeight);
339 ShowSlider(action.GetID(), 274, (float) res_info.iSubtitles - res_info.iHeight, (float) -res_info.iHeight, -1.0f, 0.0f);
341 g_graphicsContext.SetResInfo(g_graphicsContext.GetVideoResolution(), res_info);
345 case ACTION_SUBTITLE_ALIGN:
347 RESOLUTION_INFO res_info = g_graphicsContext.GetResInfo();
348 int subalign = CSettings::Get().GetInt("subtitles.align");
351 if (subalign > SUBTITLE_ALIGN_TOP_OUTSIDE)
352 subalign = SUBTITLE_ALIGN_MANUAL;
354 res_info.iSubtitles = res_info.iHeight - 1;
356 CSettings::Get().SetInt("subtitles.align", subalign);
357 CGUIDialogKaiToast::QueueNotification(CGUIDialogKaiToast::Info,
358 g_localizeStrings.Get(21460),
359 g_localizeStrings.Get(21461 + subalign),
360 TOAST_DISPLAY_TIME, false);
361 g_graphicsContext.SetResInfo(g_graphicsContext.GetVideoResolution(), res_info);
365 case ACTION_VOLAMP_UP:
366 case ACTION_VOLAMP_DOWN:
368 // Don't allow change with passthrough audio
369 if (g_application.m_pPlayer->IsPassthrough())
371 CGUIDialogKaiToast::QueueNotification(CGUIDialogKaiToast::Warning,
372 g_localizeStrings.Get(660),
373 g_localizeStrings.Get(29802),
374 TOAST_DISPLAY_TIME, false);
378 float sliderMax = VOLUME_DRC_MAXIMUM / 100.0f;
379 float sliderMin = VOLUME_DRC_MINIMUM / 100.0f;
381 if (action.GetID() == ACTION_VOLAMP_UP)
382 CMediaSettings::Get().GetCurrentVideoSettings().m_VolumeAmplification += 1.0f;
384 CMediaSettings::Get().GetCurrentVideoSettings().m_VolumeAmplification -= 1.0f;
386 CMediaSettings::Get().GetCurrentVideoSettings().m_VolumeAmplification =
387 std::max(std::min(CMediaSettings::Get().GetCurrentVideoSettings().m_VolumeAmplification, sliderMax), sliderMin);
389 g_application.m_pPlayer->SetDynamicRangeCompression((long)(CMediaSettings::Get().GetCurrentVideoSettings().m_VolumeAmplification * 100));
391 ShowSlider(action.GetID(), 660, CMediaSettings::Get().GetCurrentVideoSettings().m_VolumeAmplification, sliderMin, 1.0f, sliderMax);
402 void CPlayerController::ShowSlider(int action, int label, float value, float min, float delta, float max, bool modal)
404 m_sliderAction = action;
406 CGUIDialogSlider::ShowAndGetInput(g_localizeStrings.Get(label), value, min, delta, max, this);
408 CGUIDialogSlider::Display(label, value, min, delta, max, this);
411 void CPlayerController::OnSliderChange(void *data, CGUISliderControl *slider)
416 if (m_sliderAction == ACTION_ZOOM_OUT || m_sliderAction == ACTION_ZOOM_IN ||
417 m_sliderAction == ACTION_INCREASE_PAR || m_sliderAction == ACTION_DECREASE_PAR ||
418 m_sliderAction == ACTION_VSHIFT_UP || m_sliderAction == ACTION_VSHIFT_DOWN ||
419 m_sliderAction == ACTION_SUBTITLE_VSHIFT_UP || m_sliderAction == ACTION_SUBTITLE_VSHIFT_DOWN)
421 CStdString strValue = StringUtils::Format("%1.2f",slider->GetFloatValue());
422 slider->SetTextValue(strValue);
424 else if (m_sliderAction == ACTION_VOLAMP_UP || m_sliderAction == ACTION_VOLAMP_DOWN)
425 slider->SetTextValue(CGUIDialogAudioSubtitleSettings::FormatDecibel(slider->GetFloatValue(), 1.0f));
427 slider->SetTextValue(CGUIDialogAudioSubtitleSettings::FormatDelay(slider->GetFloatValue(), 0.025f));
429 if (g_application.m_pPlayer->HasPlayer())
431 if (m_sliderAction == ACTION_AUDIO_DELAY)
433 CMediaSettings::Get().GetCurrentVideoSettings().m_AudioDelay = slider->GetFloatValue();
434 g_application.m_pPlayer->SetAVDelay(CMediaSettings::Get().GetCurrentVideoSettings().m_AudioDelay);
436 else if (m_sliderAction == ACTION_SUBTITLE_DELAY)
438 CMediaSettings::Get().GetCurrentVideoSettings().m_SubtitleDelay = slider->GetFloatValue();
439 g_application.m_pPlayer->SetSubTitleDelay(CMediaSettings::Get().GetCurrentVideoSettings().m_SubtitleDelay);