| 1 | /* |
| 2 | * Copyright (C) 2012-2018 Team Kodi |
| 3 | * This file is part of Kodi - https://kodi.tv |
| 4 | * |
| 5 | * SPDX-License-Identifier: GPL-2.0-or-later |
| 6 | * See LICENSES/README.md for more information. |
| 7 | */ |
| 8 | |
| 9 | #include "guilib/guiinfo/PlayerGUIInfo.h" |
| 10 | |
| 11 | #include "FileItem.h" |
| 12 | #include "PlayListPlayer.h" |
| 13 | #include "ServiceBroker.h" |
| 14 | #include "URL.h" |
| 15 | #include "Util.h" |
| 16 | #include "application/Application.h" |
| 17 | #include "application/ApplicationComponents.h" |
| 18 | #include "application/ApplicationPlayer.h" |
| 19 | #include "application/ApplicationVolumeHandling.h" |
| 20 | #include "cores/AudioEngine/Utils/AEUtil.h" |
| 21 | #include "cores/DataCacheCore.h" |
| 22 | #include "cores/EdlEdit.h" |
| 23 | #include "guilib/GUIComponent.h" |
| 24 | #include "guilib/GUIDialog.h" |
| 25 | #include "guilib/GUIWindowManager.h" |
| 26 | #include "guilib/guiinfo/GUIInfo.h" |
| 27 | #include "guilib/guiinfo/GUIInfoHelper.h" |
| 28 | #include "guilib/guiinfo/GUIInfoLabels.h" |
| 29 | #include "utils/StringUtils.h" |
| 30 | #include "utils/URIUtils.h" |
| 31 | #include "utils/Variant.h" |
| 32 | #include "utils/log.h" |
| 33 | |
| 34 | #include <charconv> |
| 35 | #include <cmath> |
| 36 | #include <memory> |
| 37 | |
| 38 | using namespace KODI::GUILIB::GUIINFO; |
| 39 | |
| 40 | CPlayerGUIInfo::CPlayerGUIInfo() |
| 41 | : m_appPlayer(CServiceBroker::GetAppComponents().GetComponent<CApplicationPlayer>()), |
| 42 | m_appVolume(CServiceBroker::GetAppComponents().GetComponent<CApplicationVolumeHandling>()) |
| 43 | { |
| 44 | } |
| 45 | |
| 46 | CPlayerGUIInfo::~CPlayerGUIInfo() = default; |
| 47 | |
| 48 | int CPlayerGUIInfo::GetTotalPlayTime() const |
| 49 | { |
| 50 | return std::lrint(g_application.GetTotalTime()); |
| 51 | } |
| 52 | |
| 53 | int CPlayerGUIInfo::GetPlayTime() const |
| 54 | { |
| 55 | return std::lrint(g_application.GetTime()); |
| 56 | } |
| 57 | |
| 58 | int CPlayerGUIInfo::GetPlayTimeRemaining() const |
| 59 | { |
| 60 | int iReverse = GetTotalPlayTime() - std::lrint(g_application.GetTime()); |
| 61 | return iReverse > 0 ? iReverse : 0; |
| 62 | } |
| 63 | |
| 64 | float CPlayerGUIInfo::GetSeekPercent() const |
| 65 | { |
| 66 | int iTotal = GetTotalPlayTime(); |
| 67 | if (iTotal == 0) |
| 68 | return 0.0f; |
| 69 | |
| 70 | float fPercentPlayTime = static_cast<float>(GetPlayTime() * 1000) / iTotal * 0.1f; |
| 71 | float fPercentPerSecond = 100.0f / static_cast<float>(iTotal); |
| 72 | float fPercent = |
| 73 | fPercentPlayTime + fPercentPerSecond * m_appPlayer->GetSeekHandler().GetSeekSize(); |
| 74 | fPercent = std::max(0.0f, std::min(fPercent, 100.0f)); |
| 75 | return fPercent; |
| 76 | } |
| 77 | |
| 78 | std::string CPlayerGUIInfo::GetCurrentPlayTime(TIME_FORMAT format) const |
| 79 | { |
| 80 | if (format == TIME_FORMAT_GUESS && GetTotalPlayTime() >= 3600) |
| 81 | format = TIME_FORMAT_HH_MM_SS; |
| 82 | |
| 83 | return StringUtils::SecondsToTimeString(std::lrint(GetPlayTime()), format); |
| 84 | } |
| 85 | |
| 86 | std::string CPlayerGUIInfo::GetCurrentPlayTimeRemaining(TIME_FORMAT format) const |
| 87 | { |
| 88 | if (format == TIME_FORMAT_GUESS && GetTotalPlayTime() >= 3600) |
| 89 | format = TIME_FORMAT_HH_MM_SS; |
| 90 | |
| 91 | int iTimeRemaining = GetPlayTimeRemaining(); |
| 92 | if (iTimeRemaining) |
| 93 | return StringUtils::SecondsToTimeString(iTimeRemaining, format); |
| 94 | |
| 95 | return std::string(); |
| 96 | } |
| 97 | |
| 98 | std::string CPlayerGUIInfo::GetDuration(TIME_FORMAT format) const |
| 99 | { |
| 100 | int iTotal = GetTotalPlayTime(); |
| 101 | if (iTotal > 0) |
| 102 | { |
| 103 | if (format == TIME_FORMAT_GUESS && iTotal >= 3600) |
| 104 | format = TIME_FORMAT_HH_MM_SS; |
| 105 | return StringUtils::SecondsToTimeString(iTotal, format); |
| 106 | } |
| 107 | return std::string(); |
| 108 | } |
| 109 | |
| 110 | std::string CPlayerGUIInfo::GetCurrentSeekTime(TIME_FORMAT format) const |
| 111 | { |
| 112 | if (format == TIME_FORMAT_GUESS && GetTotalPlayTime() >= 3600) |
| 113 | format = TIME_FORMAT_HH_MM_SS; |
| 114 | |
| 115 | return StringUtils::SecondsToTimeString( |
| 116 | g_application.GetTime() + m_appPlayer->GetSeekHandler().GetSeekSize(), format); |
| 117 | } |
| 118 | |
| 119 | std::string CPlayerGUIInfo::GetSeekTime(TIME_FORMAT format) const |
| 120 | { |
| 121 | if (!m_appPlayer->GetSeekHandler().HasTimeCode()) |
| 122 | return std::string(); |
| 123 | |
| 124 | int iSeekTimeCode = m_appPlayer->GetSeekHandler().GetTimeCodeSeconds(); |
| 125 | if (format == TIME_FORMAT_GUESS && iSeekTimeCode >= 3600) |
| 126 | format = TIME_FORMAT_HH_MM_SS; |
| 127 | |
| 128 | return StringUtils::SecondsToTimeString(iSeekTimeCode, format); |
| 129 | } |
| 130 | |
| 131 | void CPlayerGUIInfo::SetShowInfo(bool showinfo) |
| 132 | { |
| 133 | if (showinfo != m_playerShowInfo) |
| 134 | { |
| 135 | m_playerShowInfo = showinfo; |
| 136 | m_events.Publish(PlayerShowInfoChangedEvent(m_playerShowInfo)); |
| 137 | } |
| 138 | } |
| 139 | |
| 140 | bool CPlayerGUIInfo::ToggleShowInfo() |
| 141 | { |
| 142 | SetShowInfo(!m_playerShowInfo); |
| 143 | return m_playerShowInfo; |
| 144 | } |
| 145 | |
| 146 | bool CPlayerGUIInfo::InitCurrentItem(CFileItem *item) |
| 147 | { |
| 148 | if (item && m_appPlayer->IsPlaying()) |
| 149 | { |
| 150 | CLog::Log(LOGDEBUG, "CPlayerGUIInfo::InitCurrentItem({})", CURL::GetRedacted(item->GetPath())); |
| 151 | m_currentItem = std::make_unique<CFileItem>(*item); |
| 152 | } |
| 153 | else |
| 154 | { |
| 155 | m_currentItem.reset(); |
| 156 | } |
| 157 | return false; |
| 158 | } |
| 159 | |
| 160 | bool CPlayerGUIInfo::GetLabel(std::string& value, const CFileItem *item, int contextWindow, const CGUIInfo &info, std::string *fallback) const |
| 161 | { |
| 162 | switch (info.m_info) |
| 163 | { |
| 164 | /////////////////////////////////////////////////////////////////////////////////////////////// |
| 165 | // PLAYER_* |
| 166 | /////////////////////////////////////////////////////////////////////////////////////////////// |
| 167 | case PLAYER_SEEKOFFSET: |
| 168 | { |
| 169 | int lastSeekOffset = CServiceBroker::GetDataCacheCore().GetSeekOffSet(); |
| 170 | std::string seekOffset = StringUtils::SecondsToTimeString( |
| 171 | std::abs(lastSeekOffset / 1000), static_cast<TIME_FORMAT>(info.GetData1())); |
| 172 | if (lastSeekOffset < 0) |
| 173 | value = "-" + seekOffset; |
| 174 | else if (lastSeekOffset > 0) |
| 175 | value = "+" + seekOffset; |
| 176 | return true; |
| 177 | } |
| 178 | case PLAYER_PROGRESS: |
| 179 | value = std::to_string(std::lrintf(g_application.GetPercentage())); |
| 180 | return true; |
| 181 | case PLAYER_PROGRESS_CACHE: |
| 182 | value = std::to_string(std::lrintf(g_application.GetCachePercentage())); |
| 183 | return true; |
| 184 | case PLAYER_VOLUME: |
| 185 | value = |
| 186 | StringUtils::Format("{:2.1f} dB", CAEUtil::PercentToGain(m_appVolume->GetVolumeRatio())); |
| 187 | return true; |
| 188 | case PLAYER_SUBTITLE_DELAY: |
| 189 | value = StringUtils::Format("{:2.3f} s", m_appPlayer->GetVideoSettings().m_SubtitleDelay); |
| 190 | return true; |
| 191 | case PLAYER_AUDIO_DELAY: |
| 192 | value = StringUtils::Format("{:2.3f} s", m_appPlayer->GetVideoSettings().m_AudioDelay); |
| 193 | return true; |
| 194 | case PLAYER_CHAPTER: |
| 195 | value = StringUtils::Format("{:02}", m_appPlayer->GetChapter()); |
| 196 | return true; |
| 197 | case PLAYER_CHAPTERCOUNT: |
| 198 | value = StringUtils::Format("{:02}", m_appPlayer->GetChapterCount()); |
| 199 | return true; |
| 200 | case PLAYER_CHAPTERNAME: |
| 201 | m_appPlayer->GetChapterName(value); |
| 202 | return true; |
| 203 | case PLAYER_PATH: |
| 204 | case PLAYER_FILENAME: |
| 205 | case PLAYER_FILEPATH: |
| 206 | value = GUIINFO::GetFileInfoLabelValueFromPath(info.m_info, item->GetPath()); |
| 207 | return true; |
| 208 | case PLAYER_TITLE: |
| 209 | // use label or drop down to title from path |
| 210 | value = item->GetLabel(); |
| 211 | if (value.empty()) |
| 212 | value = CUtil::GetTitleFromPath(item->GetPath()); |
| 213 | return true; |
| 214 | case PLAYER_PLAYSPEED: |
| 215 | { |
| 216 | float speed = m_appPlayer->GetPlaySpeed(); |
| 217 | if (speed == 1.0f) |
| 218 | speed = m_appPlayer->GetPlayTempo(); |
| 219 | value = StringUtils::Format("{:.2f}", speed); |
| 220 | return true; |
| 221 | } |
| 222 | case PLAYER_TIME: |
| 223 | value = GetCurrentPlayTime(static_cast<TIME_FORMAT>(info.GetData1())); |
| 224 | return true; |
| 225 | case PLAYER_START_TIME: |
| 226 | { |
| 227 | const CDateTime time(m_appPlayer->GetStartTime()); |
| 228 | value = time.GetAsLocalizedTime(static_cast<TIME_FORMAT>(info.GetData1())); |
| 229 | return true; |
| 230 | } |
| 231 | case PLAYER_DURATION: |
| 232 | value = GetDuration(static_cast<TIME_FORMAT>(info.GetData1())); |
| 233 | return true; |
| 234 | case PLAYER_TIME_REMAINING: |
| 235 | value = GetCurrentPlayTimeRemaining(static_cast<TIME_FORMAT>(info.GetData1())); |
| 236 | return true; |
| 237 | case PLAYER_FINISH_TIME: |
| 238 | { |
| 239 | CDateTime time(CDateTime::GetCurrentDateTime()); |
| 240 | int playTimeRemaining = GetPlayTimeRemaining(); |
| 241 | float speed = m_appPlayer->GetPlaySpeed(); |
| 242 | float tempo = m_appPlayer->GetPlayTempo(); |
| 243 | if (speed == 1.0f) |
| 244 | playTimeRemaining /= tempo; |
| 245 | time += CDateTimeSpan(0, 0, 0, playTimeRemaining); |
| 246 | value = time.GetAsLocalizedTime(static_cast<TIME_FORMAT>(info.GetData1())); |
| 247 | return true; |
| 248 | } |
| 249 | case PLAYER_TIME_SPEED: |
| 250 | { |
| 251 | float speed = m_appPlayer->GetPlaySpeed(); |
| 252 | if (speed != 1.0f) |
| 253 | value = StringUtils::Format("{} ({}x)", |
| 254 | GetCurrentPlayTime(static_cast<TIME_FORMAT>(info.GetData1())), |
| 255 | static_cast<int>(speed)); |
| 256 | else |
| 257 | value = GetCurrentPlayTime(TIME_FORMAT_GUESS); |
| 258 | return true; |
| 259 | } |
| 260 | case PLAYER_SEEKTIME: |
| 261 | value = GetCurrentSeekTime(static_cast<TIME_FORMAT>(info.GetData1())); |
| 262 | return true; |
| 263 | case PLAYER_SEEKSTEPSIZE: |
| 264 | { |
| 265 | int seekSize = m_appPlayer->GetSeekHandler().GetSeekSize(); |
| 266 | std::string strSeekSize = StringUtils::SecondsToTimeString(abs(seekSize), static_cast<TIME_FORMAT>(info.GetData1())); |
| 267 | if (seekSize < 0) |
| 268 | value = "-" + strSeekSize; |
| 269 | if (seekSize > 0) |
| 270 | value = "+" + strSeekSize; |
| 271 | return true; |
| 272 | } |
| 273 | case PLAYER_SEEKNUMERIC: |
| 274 | value = GetSeekTime(static_cast<TIME_FORMAT>(info.GetData1())); |
| 275 | return !value.empty(); |
| 276 | case PLAYER_CACHELEVEL: |
| 277 | { |
| 278 | int iLevel = m_appPlayer->GetCacheLevel(); |
| 279 | if (iLevel >= 0) |
| 280 | { |
| 281 | value = std::to_string(iLevel); |
| 282 | return true; |
| 283 | } |
| 284 | break; |
| 285 | } |
| 286 | case PLAYER_ITEM_ART: |
| 287 | value = item->GetArt(info.GetData3()); |
| 288 | return true; |
| 289 | case PLAYER_ICON: |
| 290 | value = item->GetArt("thumb"); |
| 291 | if (value.empty()) |
| 292 | value = item->GetArt("icon"); |
| 293 | if (fallback) |
| 294 | *fallback = item->GetArt("icon"); |
| 295 | return true; |
| 296 | case PLAYER_EDITLIST: |
| 297 | case PLAYER_CUTS: |
| 298 | case PLAYER_SCENE_MARKERS: |
| 299 | case PLAYER_CUTLIST: |
| 300 | case PLAYER_CHAPTERS: |
| 301 | value = GetContentRanges(info.m_info); |
| 302 | return true; |
| 303 | |
| 304 | /////////////////////////////////////////////////////////////////////////////////////////////// |
| 305 | // PLAYER_PROCESS_* |
| 306 | /////////////////////////////////////////////////////////////////////////////////////////////// |
| 307 | case PLAYER_PROCESS_VIDEODECODER: |
| 308 | value = CServiceBroker::GetDataCacheCore().GetVideoDecoderName(); |
| 309 | return true; |
| 310 | case PLAYER_PROCESS_DEINTMETHOD: |
| 311 | value = CServiceBroker::GetDataCacheCore().GetVideoDeintMethod(); |
| 312 | return true; |
| 313 | case PLAYER_PROCESS_PIXELFORMAT: |
| 314 | value = CServiceBroker::GetDataCacheCore().GetVideoPixelFormat(); |
| 315 | return true; |
| 316 | case PLAYER_PROCESS_VIDEOFPS: |
| 317 | value = StringUtils::Format("{:.3f}", CServiceBroker::GetDataCacheCore().GetVideoFps()); |
| 318 | return true; |
| 319 | case PLAYER_PROCESS_VIDEODAR: |
| 320 | value = StringUtils::Format("{:.2f}", CServiceBroker::GetDataCacheCore().GetVideoDAR()); |
| 321 | return true; |
| 322 | case PLAYER_PROCESS_VIDEOWIDTH: |
| 323 | value = StringUtils::FormatNumber(CServiceBroker::GetDataCacheCore().GetVideoWidth()); |
| 324 | return true; |
| 325 | case PLAYER_PROCESS_VIDEOHEIGHT: |
| 326 | value = StringUtils::FormatNumber(CServiceBroker::GetDataCacheCore().GetVideoHeight()); |
| 327 | return true; |
| 328 | case PLAYER_PROCESS_VIDEOSCANTYPE: |
| 329 | value = CServiceBroker::GetDataCacheCore().IsVideoInterlaced() ? "i" : "p"; |
| 330 | return true; |
| 331 | case PLAYER_PROCESS_AUDIODECODER: |
| 332 | value = CServiceBroker::GetDataCacheCore().GetAudioDecoderName(); |
| 333 | return true; |
| 334 | case PLAYER_PROCESS_AUDIOCHANNELS: |
| 335 | value = CServiceBroker::GetDataCacheCore().GetAudioChannels(); |
| 336 | return true; |
| 337 | case PLAYER_PROCESS_AUDIOSAMPLERATE: |
| 338 | value = StringUtils::FormatNumber(CServiceBroker::GetDataCacheCore().GetAudioSampleRate()); |
| 339 | return true; |
| 340 | case PLAYER_PROCESS_AUDIOBITSPERSAMPLE: |
| 341 | value = StringUtils::FormatNumber(CServiceBroker::GetDataCacheCore().GetAudioBitsPerSample()); |
| 342 | return true; |
| 343 | |
| 344 | /////////////////////////////////////////////////////////////////////////////////////////////// |
| 345 | // PLAYLIST_* |
| 346 | /////////////////////////////////////////////////////////////////////////////////////////////// |
| 347 | case PLAYLIST_LENGTH: |
| 348 | case PLAYLIST_POSITION: |
| 349 | case PLAYLIST_RANDOM: |
| 350 | case PLAYLIST_REPEAT: |
| 351 | value = GUIINFO::GetPlaylistLabel(info.m_info, info.GetData1()); |
| 352 | return true; |
| 353 | } |
| 354 | |
| 355 | return false; |
| 356 | } |
| 357 | |
| 358 | bool CPlayerGUIInfo::GetInt(int& value, const CGUIListItem *gitem, int contextWindow, const CGUIInfo &info) const |
| 359 | { |
| 360 | switch (info.m_info) |
| 361 | { |
| 362 | /////////////////////////////////////////////////////////////////////////////////////////////// |
| 363 | // PLAYER_* |
| 364 | /////////////////////////////////////////////////////////////////////////////////////////////// |
| 365 | case PLAYER_VOLUME: |
| 366 | value = static_cast<int>(m_appVolume->GetVolumePercent()); |
| 367 | return true; |
| 368 | case PLAYER_PROGRESS: |
| 369 | value = std::lrintf(g_application.GetPercentage()); |
| 370 | return true; |
| 371 | case PLAYER_PROGRESS_CACHE: |
| 372 | value = std::lrintf(g_application.GetCachePercentage()); |
| 373 | return true; |
| 374 | case PLAYER_SEEKBAR: |
| 375 | value = std::lrintf(GetSeekPercent()); |
| 376 | return true; |
| 377 | case PLAYER_CACHELEVEL: |
| 378 | value = m_appPlayer->GetCacheLevel(); |
| 379 | return true; |
| 380 | case PLAYER_CHAPTER: |
| 381 | value = m_appPlayer->GetChapter(); |
| 382 | return true; |
| 383 | case PLAYER_CHAPTERCOUNT: |
| 384 | value = m_appPlayer->GetChapterCount(); |
| 385 | return true; |
| 386 | case PLAYER_SUBTITLE_DELAY: |
| 387 | value = m_appPlayer->GetSubtitleDelay(); |
| 388 | return true; |
| 389 | case PLAYER_AUDIO_DELAY: |
| 390 | value = m_appPlayer->GetAudioDelay(); |
| 391 | return true; |
| 392 | } |
| 393 | |
| 394 | return false; |
| 395 | } |
| 396 | |
| 397 | bool CPlayerGUIInfo::GetBool(bool& value, const CGUIListItem *gitem, int contextWindow, const CGUIInfo &info) const |
| 398 | { |
| 399 | const CFileItem *item = nullptr; |
| 400 | if (gitem->IsFileItem()) |
| 401 | item = static_cast<const CFileItem*>(gitem); |
| 402 | |
| 403 | switch (info.m_info) |
| 404 | { |
| 405 | /////////////////////////////////////////////////////////////////////////////////////////////// |
| 406 | // PLAYER_* |
| 407 | /////////////////////////////////////////////////////////////////////////////////////////////// |
| 408 | case PLAYER_SHOWINFO: |
| 409 | value = m_playerShowInfo; |
| 410 | return true; |
| 411 | case PLAYER_SHOWTIME: |
| 412 | value = m_playerShowTime; |
| 413 | return true; |
| 414 | case PLAYER_MUTED: |
| 415 | value = (m_appVolume->IsMuted() || |
| 416 | m_appVolume->GetVolumeRatio() <= CApplicationVolumeHandling::VOLUME_MINIMUM); |
| 417 | return true; |
| 418 | case PLAYER_HAS_MEDIA: |
| 419 | value = m_appPlayer->IsPlaying(); |
| 420 | return true; |
| 421 | case PLAYER_HAS_AUDIO: |
| 422 | value = m_appPlayer->IsPlayingAudio(); |
| 423 | return true; |
| 424 | case PLAYER_HAS_VIDEO: |
| 425 | value = m_appPlayer->IsPlayingVideo(); |
| 426 | return true; |
| 427 | case PLAYER_HAS_GAME: |
| 428 | value = m_appPlayer->IsPlayingGame(); |
| 429 | return true; |
| 430 | case PLAYER_IS_REMOTE: |
| 431 | value = m_appPlayer->IsRemotePlaying(); |
| 432 | return true; |
| 433 | case PLAYER_IS_EXTERNAL: |
| 434 | value = m_appPlayer->IsExternalPlaying(); |
| 435 | return true; |
| 436 | case PLAYER_PLAYING: |
| 437 | value = m_appPlayer->GetPlaySpeed() == 1.0f; |
| 438 | return true; |
| 439 | case PLAYER_PAUSED: |
| 440 | value = m_appPlayer->IsPausedPlayback(); |
| 441 | return true; |
| 442 | case PLAYER_REWINDING: |
| 443 | value = m_appPlayer->GetPlaySpeed() < 0.0f; |
| 444 | return true; |
| 445 | case PLAYER_FORWARDING: |
| 446 | value = m_appPlayer->GetPlaySpeed() > 1.5f; |
| 447 | return true; |
| 448 | case PLAYER_REWINDING_2x: |
| 449 | value = m_appPlayer->GetPlaySpeed() == -2; |
| 450 | return true; |
| 451 | case PLAYER_REWINDING_4x: |
| 452 | value = m_appPlayer->GetPlaySpeed() == -4; |
| 453 | return true; |
| 454 | case PLAYER_REWINDING_8x: |
| 455 | value = m_appPlayer->GetPlaySpeed() == -8; |
| 456 | return true; |
| 457 | case PLAYER_REWINDING_16x: |
| 458 | value = m_appPlayer->GetPlaySpeed() == -16; |
| 459 | return true; |
| 460 | case PLAYER_REWINDING_32x: |
| 461 | value = m_appPlayer->GetPlaySpeed() == -32; |
| 462 | return true; |
| 463 | case PLAYER_FORWARDING_2x: |
| 464 | value = m_appPlayer->GetPlaySpeed() == 2; |
| 465 | return true; |
| 466 | case PLAYER_FORWARDING_4x: |
| 467 | value = m_appPlayer->GetPlaySpeed() == 4; |
| 468 | return true; |
| 469 | case PLAYER_FORWARDING_8x: |
| 470 | value = m_appPlayer->GetPlaySpeed() == 8; |
| 471 | return true; |
| 472 | case PLAYER_FORWARDING_16x: |
| 473 | value = m_appPlayer->GetPlaySpeed() == 16; |
| 474 | return true; |
| 475 | case PLAYER_FORWARDING_32x: |
| 476 | value = m_appPlayer->GetPlaySpeed() == 32; |
| 477 | return true; |
| 478 | case PLAYER_CAN_PAUSE: |
| 479 | value = m_appPlayer->CanPause(); |
| 480 | return true; |
| 481 | case PLAYER_CAN_SEEK: |
| 482 | value = m_appPlayer->CanSeek(); |
| 483 | return true; |
| 484 | case PLAYER_SUPPORTS_TEMPO: |
| 485 | value = m_appPlayer->SupportsTempo(); |
| 486 | return true; |
| 487 | case PLAYER_IS_TEMPO: |
| 488 | value = (m_appPlayer->GetPlayTempo() != 1.0f && m_appPlayer->GetPlaySpeed() == 1.0f); |
| 489 | return true; |
| 490 | case PLAYER_CACHING: |
| 491 | value = m_appPlayer->IsCaching(); |
| 492 | return true; |
| 493 | case PLAYER_SEEKBAR: |
| 494 | { |
| 495 | CGUIDialog *seekBar = CServiceBroker::GetGUI()->GetWindowManager().GetDialog(WINDOW_DIALOG_SEEK_BAR); |
| 496 | value = seekBar ? seekBar->IsDialogRunning() : false; |
| 497 | return true; |
| 498 | } |
| 499 | case PLAYER_SEEKING: |
| 500 | value = m_appPlayer->GetSeekHandler().InProgress(); |
| 501 | return true; |
| 502 | case PLAYER_HASPERFORMEDSEEK: |
| 503 | { |
| 504 | int requestedLastSecondInterval{0}; |
| 505 | std::from_chars_result result = |
| 506 | std::from_chars(info.GetData3().data(), info.GetData3().data() + info.GetData3().size(), |
| 507 | requestedLastSecondInterval); |
| 508 | if (result.ec == std::errc::invalid_argument) |
| 509 | { |
| 510 | value = false; |
| 511 | return false; |
| 512 | } |
| 513 | |
| 514 | value = CServiceBroker::GetDataCacheCore().HasPerformedSeek(requestedLastSecondInterval); |
| 515 | return true; |
| 516 | } |
| 517 | case PLAYER_PASSTHROUGH: |
| 518 | value = m_appPlayer->IsPassthrough(); |
| 519 | return true; |
| 520 | case PLAYER_ISINTERNETSTREAM: |
| 521 | if (item) |
| 522 | { |
| 523 | value = URIUtils::IsInternetStream(item->GetDynPath()); |
| 524 | return true; |
| 525 | } |
| 526 | break; |
| 527 | case PLAYER_HAS_PROGRAMS: |
| 528 | value = (m_appPlayer->GetProgramsCount() > 1) ? true : false; |
| 529 | return true; |
| 530 | case PLAYER_HAS_RESOLUTIONS: |
| 531 | value = CServiceBroker::GetWinSystem()->GetGfxContext().IsFullScreenRoot() && |
| 532 | CResolutionUtils::HasWhitelist(); |
| 533 | return true; |
| 534 | case PLAYER_HASDURATION: |
| 535 | value = g_application.GetTotalTime() > 0; |
| 536 | return true; |
| 537 | case PLAYER_FRAMEADVANCE: |
| 538 | value = CServiceBroker::GetDataCacheCore().IsFrameAdvance(); |
| 539 | return true; |
| 540 | case PLAYER_HAS_SCENE_MARKERS: |
| 541 | value = !CServiceBroker::GetDataCacheCore().GetSceneMarkers().empty(); |
| 542 | return true; |
| 543 | |
| 544 | /////////////////////////////////////////////////////////////////////////////////////////////// |
| 545 | // PLAYLIST_* |
| 546 | /////////////////////////////////////////////////////////////////////////////////////////////// |
| 547 | case PLAYLIST_ISRANDOM: |
| 548 | { |
| 549 | PLAYLIST::CPlayListPlayer& player = CServiceBroker::GetPlaylistPlayer(); |
| 550 | PLAYLIST::Id playlistid = info.GetData1(); |
| 551 | if (info.GetData2() > 0 && playlistid != PLAYLIST::TYPE_NONE) |
| 552 | value = player.IsShuffled(playlistid); |
| 553 | else |
| 554 | value = player.IsShuffled(player.GetCurrentPlaylist()); |
| 555 | return true; |
| 556 | } |
| 557 | case PLAYLIST_ISREPEAT: |
| 558 | { |
| 559 | PLAYLIST::CPlayListPlayer& player = CServiceBroker::GetPlaylistPlayer(); |
| 560 | PLAYLIST::Id playlistid = info.GetData1(); |
| 561 | if (info.GetData2() > 0 && playlistid != PLAYLIST::TYPE_NONE) |
| 562 | value = (player.GetRepeat(playlistid) == PLAYLIST::RepeatState::ALL); |
| 563 | else |
| 564 | value = player.GetRepeat(player.GetCurrentPlaylist()) == PLAYLIST::RepeatState::ALL; |
| 565 | return true; |
| 566 | } |
| 567 | case PLAYLIST_ISREPEATONE: |
| 568 | { |
| 569 | PLAYLIST::CPlayListPlayer& player = CServiceBroker::GetPlaylistPlayer(); |
| 570 | PLAYLIST::Id playlistid = info.GetData1(); |
| 571 | if (info.GetData2() > 0 && playlistid != PLAYLIST::TYPE_NONE) |
| 572 | value = (player.GetRepeat(playlistid) == PLAYLIST::RepeatState::ONE); |
| 573 | else |
| 574 | value = player.GetRepeat(player.GetCurrentPlaylist()) == PLAYLIST::RepeatState::ONE; |
| 575 | return true; |
| 576 | } |
| 577 | |
| 578 | /////////////////////////////////////////////////////////////////////////////////////////////// |
| 579 | // PLAYER_PROCESS_* |
| 580 | /////////////////////////////////////////////////////////////////////////////////////////////// |
| 581 | case PLAYER_PROCESS_VIDEOHWDECODER: |
| 582 | value = CServiceBroker::GetDataCacheCore().IsVideoHwDecoder(); |
| 583 | return true; |
| 584 | |
| 585 | /////////////////////////////////////////////////////////////////////////////////////////////// |
| 586 | // LISTITEM_* |
| 587 | /////////////////////////////////////////////////////////////////////////////////////////////// |
| 588 | case LISTITEM_ISPLAYING: |
| 589 | { |
| 590 | if (item) |
| 591 | { |
| 592 | if (item->HasProperty("playlistposition")) |
| 593 | { |
| 594 | value = static_cast<int>(item->GetProperty("playlisttype").asInteger()) == |
| 595 | CServiceBroker::GetPlaylistPlayer().GetCurrentPlaylist() && |
| 596 | static_cast<int>(item->GetProperty("playlistposition").asInteger()) == |
| 597 | CServiceBroker::GetPlaylistPlayer().GetCurrentItemIdx(); |
| 598 | return true; |
| 599 | } |
| 600 | else if (m_currentItem && !m_currentItem->GetPath().empty()) |
| 601 | { |
| 602 | if (!g_application.m_strPlayListFile.empty()) |
| 603 | { |
| 604 | //playlist file that is currently playing or the playlistitem that is currently playing. |
| 605 | value = item->IsPath(g_application.m_strPlayListFile) || m_currentItem->IsSamePath(item); |
| 606 | } |
| 607 | else |
| 608 | { |
| 609 | value = m_currentItem->IsSamePath(item); |
| 610 | } |
| 611 | return true; |
| 612 | } |
| 613 | } |
| 614 | break; |
| 615 | } |
| 616 | } |
| 617 | |
| 618 | return false; |
| 619 | } |
| 620 | |
| 621 | std::string CPlayerGUIInfo::GetContentRanges(int iInfo) const |
| 622 | { |
| 623 | std::string values; |
| 624 | |
| 625 | CDataCacheCore& data = CServiceBroker::GetDataCacheCore(); |
| 626 | std::vector<std::pair<float, float>> ranges; |
| 627 | |
| 628 | std::time_t start; |
| 629 | int64_t current; |
| 630 | int64_t min; |
| 631 | int64_t max; |
| 632 | data.GetPlayTimes(start, current, min, max); |
| 633 | |
| 634 | std::time_t duration = max - start * 1000; |
| 635 | if (duration > 0) |
| 636 | { |
| 637 | switch (iInfo) |
| 638 | { |
| 639 | case PLAYER_EDITLIST: |
| 640 | case PLAYER_CUTLIST: |
| 641 | ranges = GetEditList(data, duration); |
| 642 | break; |
| 643 | case PLAYER_CUTS: |
| 644 | ranges = GetCuts(data, duration); |
| 645 | break; |
| 646 | case PLAYER_SCENE_MARKERS: |
| 647 | ranges = GetSceneMarkers(data, duration); |
| 648 | break; |
| 649 | case PLAYER_CHAPTERS: |
| 650 | ranges = GetChapters(data, duration); |
| 651 | break; |
| 652 | default: |
| 653 | CLog::Log(LOGERROR, "CPlayerGUIInfo::GetContentRanges({}) - unhandled guiinfo", iInfo); |
| 654 | break; |
| 655 | } |
| 656 | |
| 657 | // create csv string from ranges |
| 658 | for (const auto& range : ranges) |
| 659 | values += StringUtils::Format("{:.5f},{:.5f},", range.first, range.second); |
| 660 | |
| 661 | if (!values.empty()) |
| 662 | values.pop_back(); // remove trailing comma |
| 663 | } |
| 664 | |
| 665 | return values; |
| 666 | } |
| 667 | |
| 668 | std::vector<std::pair<float, float>> CPlayerGUIInfo::GetEditList(const CDataCacheCore& data, |
| 669 | std::time_t duration) const |
| 670 | { |
| 671 | std::vector<std::pair<float, float>> ranges; |
| 672 | |
| 673 | const std::vector<EDL::Edit>& edits = data.GetEditList(); |
| 674 | for (const auto& edit : edits) |
| 675 | { |
| 676 | float editStart = edit.start * 100.0f / duration; |
| 677 | float editEnd = edit.end * 100.0f / duration; |
| 678 | ranges.emplace_back(editStart, editEnd); |
| 679 | } |
| 680 | return ranges; |
| 681 | } |
| 682 | |
| 683 | std::vector<std::pair<float, float>> CPlayerGUIInfo::GetCuts(const CDataCacheCore& data, |
| 684 | std::time_t duration) const |
| 685 | { |
| 686 | std::vector<std::pair<float, float>> ranges; |
| 687 | |
| 688 | const std::vector<int64_t>& cuts = data.GetCuts(); |
| 689 | float lastMarker = 0.0f; |
| 690 | for (const auto& cut : cuts) |
| 691 | { |
| 692 | float marker = cut * 100.0f / duration; |
| 693 | if (marker != 0) |
| 694 | ranges.emplace_back(lastMarker, marker); |
| 695 | |
| 696 | lastMarker = marker; |
| 697 | } |
| 698 | return ranges; |
| 699 | } |
| 700 | |
| 701 | std::vector<std::pair<float, float>> CPlayerGUIInfo::GetSceneMarkers(const CDataCacheCore& data, |
| 702 | std::time_t duration) const |
| 703 | { |
| 704 | std::vector<std::pair<float, float>> ranges; |
| 705 | |
| 706 | const std::vector<int64_t>& scenes = data.GetSceneMarkers(); |
| 707 | float lastMarker = 0.0f; |
| 708 | for (const auto& scene : scenes) |
| 709 | { |
| 710 | float marker = scene * 100.0f / duration; |
| 711 | if (marker != 0) |
| 712 | ranges.emplace_back(lastMarker, marker); |
| 713 | |
| 714 | lastMarker = marker; |
| 715 | } |
| 716 | return ranges; |
| 717 | } |
| 718 | |
| 719 | std::vector<std::pair<float, float>> CPlayerGUIInfo::GetChapters(const CDataCacheCore& data, |
| 720 | std::time_t duration) const |
| 721 | { |
| 722 | std::vector<std::pair<float, float>> ranges; |
| 723 | |
| 724 | const std::vector<std::pair<std::string, int64_t>>& chapters = data.GetChapters(); |
| 725 | float lastMarker = 0.0f; |
| 726 | for (const auto& chapter : chapters) |
| 727 | { |
| 728 | float marker = chapter.second * 1000 * 100.0f / duration; |
| 729 | if (marker != 0) |
| 730 | ranges.emplace_back(lastMarker, marker); |
| 731 | |
| 732 | lastMarker = marker; |
| 733 | } |
| 734 | return ranges; |
| 735 | } |