2 * Copyright (C) 2011-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/>.
23 #if defined (HAS_OMXPLAYER)
28 #include "OMXPlayerAudio.h"
29 #include "OMXPlayerVideo.h"
30 #include "OMXPlayer.h"
31 #include "Application.h"
32 #include "ApplicationMessenger.h"
33 #include "GUIInfoManager.h"
34 #include "cores/VideoRenderers/RenderManager.h"
35 #include "cores/VideoRenderers/RenderFlags.h"
37 #include "filesystem/File.h"
38 #include "filesystem/SpecialProtocol.h"
39 #include "guilib/GUIWindowManager.h"
40 #include "settings/AdvancedSettings.h"
41 #include "settings/MediaSettings.h"
42 #include "settings/Settings.h"
43 #include "threads/SingleLock.h"
44 #include "windowing/WindowingFactory.h"
46 #include "utils/log.h"
47 #include "utils/TimeUtils.h"
48 #include "utils/URIUtils.h"
49 #include "utils/Variant.h"
50 #include "utils/StreamDetails.h"
51 #include "xbmc/playlists/PlayListM3U.h"
53 #include "utils/LangCodeExpander.h"
54 #include "guilib/LocalizeStrings.h"
55 #include "guilib/Key.h"
57 #include "storage/MediaManager.h"
58 #include "GUIUserMessages.h"
59 #include "utils/StreamUtils.h"
61 #include "DVDInputStreams/DVDFactoryInputStream.h"
62 #include "DVDInputStreams/DVDInputStreamNavigator.h"
63 #include "DVDInputStreams/DVDInputStreamTV.h"
64 #include "DVDInputStreams/DVDInputStreamPVRManager.h"
66 #include "DVDDemuxers/DVDDemux.h"
67 #include "DVDDemuxers/DVDDemuxUtils.h"
68 #include "DVDDemuxers/DVDDemuxVobsub.h"
69 #include "DVDDemuxers/DVDFactoryDemuxer.h"
70 #include "DVDDemuxers/DVDDemuxFFmpeg.h"
72 #include "DVDCodecs/DVDCodecs.h"
73 #include "DVDCodecs/DVDFactoryCodec.h"
75 #include "DVDFileInfo.h"
77 #include "utils/LangCodeExpander.h"
78 #include "guilib/Key.h"
79 #include "guilib/LocalizeStrings.h"
81 #include "utils/URIUtils.h"
82 #include "GUIInfoManager.h"
83 #include "guilib/GUIWindowManager.h"
84 #include "guilib/StereoscopicsManager.h"
85 #include "Application.h"
86 #include "ApplicationMessenger.h"
87 #include "filesystem/File.h"
88 #include "pictures/Picture.h"
89 #include "DllSwScale.h"
90 #ifdef HAS_VIDEO_PLAYBACK
91 #include "cores/VideoRenderers/RenderManager.h"
93 #ifdef HAS_PERFORMANCE_SAMPLE
94 #include "xbmc/utils/PerformanceSample.h"
96 #define MEASURE_FUNCTION
98 #include "settings/AdvancedSettings.h"
100 #include "GUIUserMessages.h"
101 #include "settings/Settings.h"
102 #include "settings/MediaSettings.h"
103 #include "utils/log.h"
104 #include "utils/TimeUtils.h"
105 #include "utils/StreamDetails.h"
106 #include "pvr/PVRManager.h"
107 #include "pvr/channels/PVRChannel.h"
108 #include "pvr/windows/GUIWindowPVR.h"
109 #include "pvr/addons/PVRClients.h"
110 #include "filesystem/PVRFile.h"
111 #include "video/dialogs/GUIDialogFullScreenInfo.h"
112 #include "utils/StreamUtils.h"
113 #include "utils/Variant.h"
114 #include "storage/MediaManager.h"
115 #include "dialogs/GUIDialogBusy.h"
116 #include "dialogs/GUIDialogKaiToast.h"
117 #include "xbmc/playlists/PlayListM3U.h"
118 #include "utils/StringUtils.h"
120 #include "LangInfo.h"
122 #include "utils/LangCodeExpander.h"
124 // video not playing from clock, but stepped
125 #define TP(speed) ((speed) < 0 || (speed) > 4*DVD_PLAYSPEED_NORMAL)
127 #define TPA(speed) ((speed) != DVD_PLAYSPEED_PAUSE && (speed) != DVD_PLAYSPEED_NORMAL)
132 void COMXSelectionStreams::Clear(StreamType type, StreamSource source)
134 CSingleLock lock(m_section);
135 for(int i=m_Streams.size()-1;i>=0;i--)
137 if(type && m_Streams[i].type != type)
140 if(source && m_Streams[i].source != source)
143 m_Streams.erase(m_Streams.begin() + i);
147 OMXSelectionStream& COMXSelectionStreams::Get(StreamType type, int index)
149 CSingleLock lock(m_section);
151 for(int i=0;i<(int)m_Streams.size();i++)
153 if(m_Streams[i].type != type)
159 CLog::Log(LOGERROR, "%s - failed to get stream", __FUNCTION__);
163 std::vector<OMXSelectionStream> COMXSelectionStreams::Get(StreamType type)
165 std::vector<OMXSelectionStream> streams;
166 int count = Count(type);
167 for(int index = 0; index < count; ++index){
168 streams.push_back(Get(type, index));
173 #define PREDICATE_RETURN(lh, rh) \
176 return (lh) > (rh); \
179 class PredicateSubtitleFilter
182 std::string audiolang;
185 /** \brief The class' operator() decides if the given (subtitle) SelectionStream is relevant wrt.
186 * preferred subtitle language and audio language. If the subtitle is relevant <B>false</B> false is returned.
188 * A subtitle is relevant if
189 * - it was previously selected, or
190 * - it's an external sub, or
191 * - it's a forced sub and "original stream's language" was selected, or
192 * - it's a forced sub and its language matches the audio's language, or
193 * - it's a default sub, or
194 * - its language matches the preferred subtitle's language (unequal to "original stream's language")
196 PredicateSubtitleFilter(std::string& lang)
198 original(StringUtils::EqualsNoCase(CSettings::Get().GetString("locale.subtitlelanguage"), "original"))
202 bool operator()(const OMXSelectionStream& ss) const
204 if (ss.type_index == CMediaSettings::Get().GetCurrentVideoSettings().m_SubtitleStream)
207 if(STREAM_SOURCE_MASK(ss.source) == STREAM_SOURCE_DEMUX_SUB || STREAM_SOURCE_MASK(ss.source) == STREAM_SOURCE_TEXT)
210 if ((ss.flags & CDemuxStream::FLAG_FORCED) && (original || g_LangCodeExpander.CompareLangCodes(ss.language, audiolang)))
213 if ((ss.flags & CDemuxStream::FLAG_DEFAULT))
218 std::string subtitle_language = g_langInfo.GetSubtitleLanguage();
219 if (g_LangCodeExpander.CompareLangCodes(subtitle_language, ss.language))
227 static bool PredicateAudioPriority(const OMXSelectionStream& lh, const OMXSelectionStream& rh)
229 PREDICATE_RETURN(lh.type_index == CMediaSettings::Get().GetCurrentVideoSettings().m_AudioStream
230 , rh.type_index == CMediaSettings::Get().GetCurrentVideoSettings().m_AudioStream);
232 // TrueHD never has enough cpu to decode on Pi, so prefer to avoid that
233 PREDICATE_RETURN(lh.codec != "truehd"
234 , rh.codec != "truehd");
236 if(!StringUtils::EqualsNoCase(CSettings::Get().GetString("locale.audiolanguage"), "original"))
238 CStdString audio_language = g_langInfo.GetAudioLanguage();
239 PREDICATE_RETURN(g_LangCodeExpander.CompareLangCodes(audio_language, lh.language)
240 , g_LangCodeExpander.CompareLangCodes(audio_language, rh.language));
243 PREDICATE_RETURN(lh.flags & CDemuxStream::FLAG_DEFAULT
244 , rh.flags & CDemuxStream::FLAG_DEFAULT);
246 PREDICATE_RETURN(lh.channels
249 PREDICATE_RETURN(StreamUtils::GetCodecPriority(lh.codec)
250 , StreamUtils::GetCodecPriority(rh.codec));
254 /** \brief The class' operator() decides if the given (subtitle) SelectionStream lh is 'better than' the given (subtitle) SelectionStream rh.
255 * If lh is 'better than' rh the return value is true, false otherwise.
257 * A subtitle lh is 'better than' a subtitle rh (in evaluation order) if
258 * - lh was previously selected, or
259 * - lh is an external sub and rh not, or
260 * - lh is a forced sub and ("original stream's language" was selected or subtitles are off) and rh not, or
261 * - lh is an external sub and its language matches the preferred subtitle's language (unequal to "original stream's language") and rh not, or
262 * - lh is language matches the preferred subtitle's language (unequal to "original stream's language") and rh not, or
263 * - lh is a default sub and rh not
265 class PredicateSubtitlePriority
268 std::string audiolang;
271 PredicateSubtitleFilter filter;
273 PredicateSubtitlePriority(std::string& lang)
275 original(StringUtils::EqualsNoCase(CSettings::Get().GetString("locale.subtitlelanguage"), "original")),
276 subson(CMediaSettings::Get().GetCurrentVideoSettings().m_SubtitleOn),
281 bool relevant(const OMXSelectionStream& ss) const
286 bool operator()(const OMXSelectionStream& lh, const OMXSelectionStream& rh) const
288 PREDICATE_RETURN(relevant(lh)
291 PREDICATE_RETURN(lh.type_index == CMediaSettings::Get().GetCurrentVideoSettings().m_SubtitleStream
292 , rh.type_index == CMediaSettings::Get().GetCurrentVideoSettings().m_SubtitleStream);
294 // prefer external subs
295 PREDICATE_RETURN(STREAM_SOURCE_MASK(lh.source) == STREAM_SOURCE_DEMUX_SUB
296 , STREAM_SOURCE_MASK(rh.source) == STREAM_SOURCE_DEMUX_SUB);
298 PREDICATE_RETURN(STREAM_SOURCE_MASK(lh.source) == STREAM_SOURCE_TEXT
299 , STREAM_SOURCE_MASK(rh.source) == STREAM_SOURCE_TEXT);
301 if(!subson || original)
303 PREDICATE_RETURN(lh.flags & CDemuxStream::FLAG_FORCED && g_LangCodeExpander.CompareLangCodes(lh.language, audiolang)
304 , rh.flags & CDemuxStream::FLAG_FORCED && g_LangCodeExpander.CompareLangCodes(rh.language, audiolang));
306 PREDICATE_RETURN(lh.flags & CDemuxStream::FLAG_FORCED
307 , rh.flags & CDemuxStream::FLAG_FORCED);
310 CStdString subtitle_language = g_langInfo.GetSubtitleLanguage();
313 PREDICATE_RETURN((STREAM_SOURCE_MASK(lh.source) == STREAM_SOURCE_DEMUX_SUB || STREAM_SOURCE_MASK(lh.source) == STREAM_SOURCE_TEXT) && g_LangCodeExpander.CompareLangCodes(subtitle_language, lh.language)
314 , (STREAM_SOURCE_MASK(rh.source) == STREAM_SOURCE_DEMUX_SUB || STREAM_SOURCE_MASK(rh.source) == STREAM_SOURCE_TEXT) && g_LangCodeExpander.CompareLangCodes(subtitle_language, rh.language));
319 PREDICATE_RETURN(g_LangCodeExpander.CompareLangCodes(subtitle_language, lh.language)
320 , g_LangCodeExpander.CompareLangCodes(subtitle_language, rh.language));
323 PREDICATE_RETURN(lh.flags & CDemuxStream::FLAG_DEFAULT
324 , rh.flags & CDemuxStream::FLAG_DEFAULT);
330 static bool PredicateVideoPriority(const OMXSelectionStream& lh, const OMXSelectionStream& rh)
332 PREDICATE_RETURN(lh.flags & CDemuxStream::FLAG_DEFAULT
333 , rh.flags & CDemuxStream::FLAG_DEFAULT);
337 bool COMXSelectionStreams::Get(StreamType type, CDemuxStream::EFlags flag, OMXSelectionStream& out)
339 CSingleLock lock(m_section);
340 for(int i=0;i<(int)m_Streams.size();i++)
342 if(m_Streams[i].type != type)
344 if((m_Streams[i].flags & flag) != flag)
352 int COMXSelectionStreams::IndexOf(StreamType type, int source, int id) const
354 CSingleLock lock(m_section);
356 for(int i=0;i<(int)m_Streams.size();i++)
358 if(type && m_Streams[i].type != type)
361 if(source && m_Streams[i].source != source)
365 if(m_Streams[i].id == id)
374 int COMXSelectionStreams::IndexOf(StreamType type, COMXPlayer& p) const
376 if (p.m_pInputStream && p.m_pInputStream->IsStreamType(DVDSTREAM_TYPE_DVD))
379 if(type == STREAM_AUDIO)
380 id = ((CDVDInputStreamNavigator*)p.m_pInputStream)->GetActiveAudioStream();
381 else if(type == STREAM_VIDEO)
382 id = p.m_CurrentVideo.id;
383 else if(type == STREAM_SUBTITLE)
384 id = ((CDVDInputStreamNavigator*)p.m_pInputStream)->GetActiveSubtitleStream();
386 return IndexOf(type, STREAM_SOURCE_NAV, id);
389 if(type == STREAM_AUDIO)
390 return IndexOf(type, p.m_CurrentAudio.source, p.m_CurrentAudio.id);
391 else if(type == STREAM_VIDEO)
392 return IndexOf(type, p.m_CurrentVideo.source, p.m_CurrentVideo.id);
393 else if(type == STREAM_SUBTITLE)
394 return IndexOf(type, p.m_CurrentSubtitle.source, p.m_CurrentSubtitle.id);
395 else if(type == STREAM_TELETEXT)
396 return IndexOf(type, p.m_CurrentTeletext.source, p.m_CurrentTeletext.id);
401 int COMXSelectionStreams::Source(StreamSource source, std::string filename)
403 CSingleLock lock(m_section);
404 int index = source - 1;
405 for(int i=0;i<(int)m_Streams.size();i++)
407 OMXSelectionStream &s = m_Streams[i];
408 if(STREAM_SOURCE_MASK(s.source) != source)
410 // if it already exists, return same
411 if(s.filename == filename)
420 void COMXSelectionStreams::Update(OMXSelectionStream& s)
422 CSingleLock lock(m_section);
423 int index = IndexOf(s.type, s.source, s.id);
426 OMXSelectionStream& o = Get(s.type, index);
427 s.type_index = o.type_index;
432 s.type_index = Count(s.type);
433 m_Streams.push_back(s);
437 void COMXSelectionStreams::Update(CDVDInputStream* input, CDVDDemux* demuxer)
439 if(input && input->IsStreamType(DVDSTREAM_TYPE_DVD))
441 CDVDInputStreamNavigator* nav = (CDVDInputStreamNavigator*)input;
442 string filename = nav->GetFileName();
443 int source = Source(STREAM_SOURCE_NAV, filename);
446 count = nav->GetAudioStreamCount();
447 for(int i=0;i<count;i++)
449 OMXSelectionStream s;
451 s.type = STREAM_AUDIO;
453 s.flags = CDemuxStream::FLAG_NONE;
454 s.filename = filename;
456 DVDNavStreamInfo info;
457 nav->GetAudioStreamInfo(i, info);
459 s.language = g_LangCodeExpander.ConvertToISO6392T(info.language);
460 s.channels = info.channels;
464 count = nav->GetSubTitleStreamCount();
465 for(int i=0;i<count;i++)
467 OMXSelectionStream s;
469 s.type = STREAM_SUBTITLE;
471 s.flags = CDemuxStream::FLAG_NONE;
472 s.filename = filename;
475 DVDNavStreamInfo info;
476 nav->GetSubtitleStreamInfo(i, info);
478 s.language = g_LangCodeExpander.ConvertToISO6392T(info.language);
484 string filename = demuxer->GetFileName();
485 int count = demuxer->GetNrOfStreams();
487 if(input) /* hack to know this is sub decoder */
488 source = Source(STREAM_SOURCE_DEMUX, filename);
490 source = Source(STREAM_SOURCE_DEMUX_SUB, filename);
493 for(int i=0;i<count;i++)
495 CDemuxStream* stream = demuxer->GetStream(i);
496 /* skip streams with no type */
497 if (stream->type == STREAM_NONE)
499 /* make sure stream is marked with right source */
500 stream->source = source;
502 OMXSelectionStream s;
504 s.type = stream->type;
506 s.language = g_LangCodeExpander.ConvertToISO6392T(stream->language);
507 s.flags = stream->flags;
508 s.filename = demuxer->GetFileName();
509 stream->GetStreamName(s.name);
511 demuxer->GetStreamCodecName(stream->iId, codec);
513 s.channels = 0; // Default to 0. Overwrite if STREAM_AUDIO below.
514 if(stream->type == STREAM_AUDIO)
517 ((CDemuxStreamAudio*)stream)->GetStreamType(type);
518 if(type.length() > 0)
520 if(s.name.length() > 0)
524 s.channels = ((CDemuxStreamAudio*)stream)->iChannels;
531 COMXPlayer::COMXPlayer(IPlayerCallback &callback)
533 CThread("OMXPlayer"),
534 m_CurrentAudio(STREAM_AUDIO, DVDPLAYER_AUDIO),
535 m_CurrentVideo(STREAM_VIDEO, DVDPLAYER_VIDEO),
536 m_CurrentSubtitle(STREAM_SUBTITLE, DVDPLAYER_SUBTITLE),
537 m_CurrentTeletext(STREAM_TELETEXT, DVDPLAYER_TELETEXT),
538 m_messenger("player"),
539 m_omxPlayerVideo(&m_av_clock, &m_overlayContainer, m_messenger),
540 m_omxPlayerAudio(&m_av_clock, m_messenger),
541 m_dvdPlayerSubtitle(&m_overlayContainer),
542 m_dvdPlayerTeletext(),
544 m_DemuxerPausePending(false)
547 m_pSubtitleDemuxer = NULL;
548 m_pInputStream = NULL;
552 m_EdlAutoSkipMarkers.Clear();
553 m_UpdateApplication = 0;
555 m_bAbortRequest = false;
558 m_playSpeed = DVD_PLAYSPEED_NORMAL;
559 m_caching = CACHESTATE_DONE;
565 m_last_check_time = 0.0;
568 memset(&m_SpeedState, 0, sizeof(m_SpeedState));
570 #ifdef DVDDEBUG_MESSAGE_TRACKER
571 g_dvdMessageTracker.Init();
575 COMXPlayer::~COMXPlayer()
579 #ifdef DVDDEBUG_MESSAGE_TRACKER
580 g_dvdMessageTracker.DeInit();
584 bool COMXPlayer::OpenFile(const CFileItem &file, const CPlayerOptions &options)
588 CLog::Log(LOGNOTICE, "COMXPlayer: Opening: %s", CURL::GetRedacted(file.GetPath()).c_str());
590 // if playing a file close it first
591 // this has to be changed so we won't have to close it.
595 m_bAbortRequest = false;
597 SetPlaySpeed(DVD_PLAYSPEED_NORMAL);
600 m_UpdateApplication = 0;
603 m_PlayerOptions = options;
605 m_mimetype = file.GetMimeType();
606 m_filename = file.GetPath();
610 #if defined(HAS_VIDEO_PLAYBACK)
611 g_renderManager.PreInit();
615 if(!m_ready.WaitMSec(g_advancedSettings.m_videoBusyDialogDelay_ms))
617 CGUIDialogBusy* dialog = (CGUIDialogBusy*)g_windowManager.GetWindow(WINDOW_DIALOG_BUSY);
621 while(!m_ready.WaitMSec(1))
622 g_windowManager.ProcessRenderLoop(false);
627 // Playback might have been stopped due to some error
628 if (m_bStop || m_bAbortRequest)
635 CLog::Log(LOGERROR, "%s - Exception thrown on open", __FUNCTION__);
640 bool COMXPlayer::CloseFile(bool reopen)
642 CLog::Log(LOGDEBUG, "COMXPlayer::CloseFile");
644 // set the abort request so that other threads can finish up
645 m_bAbortRequest = true;
647 // tell demuxer to abort
651 if(m_pSubtitleDemuxer)
652 m_pSubtitleDemuxer->Abort();
655 m_pInputStream->Abort();
657 CLog::Log(LOGDEBUG, "COMXPlayer: waiting for threads to exit");
659 // wait for the main thread to finish up
660 // since this main thread cleans up all other resources and threads
661 // we are done after the StopThread call
665 m_EdlAutoSkipMarkers.Clear();
670 CLog::Log(LOGNOTICE, "COMXPlayer: finished waiting");
671 #if defined(HAS_VIDEO_PLAYBACK)
672 g_renderManager.UnInit();
677 bool COMXPlayer::IsPlaying() const
682 void COMXPlayer::OnStartup()
684 m_CurrentVideo.Clear();
685 m_CurrentAudio.Clear();
686 m_CurrentSubtitle.Clear();
687 m_CurrentTeletext.Clear();
691 CUtil::ClearTempFonts();
694 bool COMXPlayer::OpenInputStream()
697 SAFE_DELETE(m_pInputStream);
699 CLog::Log(LOGNOTICE, "Creating InputStream");
701 // correct the filename if needed
702 CStdString filename(m_filename);
703 if (StringUtils::StartsWith(filename, "dvd://")
704 || StringUtils::EqualsNoCase(filename, "iso9660://video_ts/video_ts.ifo"))
706 m_filename = g_mediaManager.TranslateDevicePath("");
709 m_pInputStream = CDVDFactoryInputStream::CreateInputStream(this, m_filename, m_mimetype);
710 if(m_pInputStream == NULL)
712 CLog::Log(LOGERROR, "COMXPlayer::OpenInputStream - unable to create input stream for [%s]", m_filename.c_str());
716 m_pInputStream->SetFileItem(m_item);
718 if (!m_pInputStream->Open(m_filename.c_str(), m_mimetype))
720 CLog::Log(LOGERROR, "COMXPlayer::OpenInputStream - error opening [%s]", m_filename.c_str());
724 if (m_pInputStream->IsStreamType(DVDSTREAM_TYPE_DVD)
725 || m_pInputStream->IsStreamType(DVDSTREAM_TYPE_BLURAY))
727 CLog::Log(LOGINFO, "COMXPlayer::OpenInputStream - DVD/BD not supported - Will try...");
730 // find any available external subtitles for non dvd files
731 if (!m_pInputStream->IsStreamType(DVDSTREAM_TYPE_DVD)
732 && !m_pInputStream->IsStreamType(DVDSTREAM_TYPE_PVRMANAGER)
733 && !m_pInputStream->IsStreamType(DVDSTREAM_TYPE_TV)
734 && !m_pInputStream->IsStreamType(DVDSTREAM_TYPE_HTSP))
736 // find any available external subtitles
737 std::vector<CStdString> filenames;
738 CUtil::ScanForExternalSubtitles( m_filename, filenames );
740 // find any upnp subtitles
741 CStdString key("upnp:subtitle:1");
742 for(unsigned s = 1; m_item.HasProperty(key); key = StringUtils::Format("upnp:subtitle:%u", ++s))
743 filenames.push_back(m_item.GetProperty(key).asString());
745 for(unsigned int i=0;i<filenames.size();i++)
747 // if vobsub subtitle:
748 if (URIUtils::HasExtension(filenames[i], ".idx"))
750 CStdString strSubFile;
751 if ( CUtil::FindVobSubPair( filenames, filenames[i], strSubFile ) )
752 AddSubtitleFile(filenames[i], strSubFile);
756 if ( !CUtil::IsVobSub(filenames, filenames[i] ) )
758 AddSubtitleFile(filenames[i]);
761 } // end loop over all subtitle files
763 CMediaSettings::Get().GetCurrentVideoSettings().m_SubtitleCached = true;
766 SetAVDelay(CMediaSettings::Get().GetCurrentVideoSettings().m_AudioDelay);
767 SetSubTitleDelay(CMediaSettings::Get().GetCurrentVideoSettings().m_SubtitleDelay);
771 m_ChannelEntryTimeOut.SetInfinite();
776 bool COMXPlayer::OpenDemuxStream()
779 SAFE_DELETE(m_pDemuxer);
781 CLog::Log(LOGNOTICE, "Creating Demuxer");
786 while(!m_bStop && attempts-- > 0)
788 m_pDemuxer = CDVDFactoryDemuxer::CreateDemuxer(m_pInputStream);
789 if(!m_pDemuxer && m_pInputStream->IsStreamType(DVDSTREAM_TYPE_PVRMANAGER))
793 else if(!m_pDemuxer && m_pInputStream->NextStream() != CDVDInputStream::NEXTSTREAM_NONE)
795 CLog::Log(LOGDEBUG, "%s - New stream available from input, retry open", __FUNCTION__);
803 CLog::Log(LOGERROR, "%s - Error creating demuxer", __FUNCTION__);
810 CLog::Log(LOGERROR, "%s - Exception thrown when opening demuxer", __FUNCTION__);
814 m_SelectionStreams.Clear(STREAM_NONE, STREAM_SOURCE_DEMUX);
815 m_SelectionStreams.Clear(STREAM_NONE, STREAM_SOURCE_NAV);
816 m_SelectionStreams.Update(m_pInputStream, m_pDemuxer);
818 int64_t len = m_pInputStream->GetLength();
819 int64_t tim = m_pDemuxer->GetStreamLength();
820 if(len > 0 && tim > 0)
821 m_pInputStream->SetReadRate(g_advancedSettings.m_readBufferFactor * len * 1000 / tim);
826 void COMXPlayer::OpenDefaultStreams(bool reset)
828 // if input stream dictate, we will open later
829 if(m_dvd.iSelectedAudioStream >= 0
830 || m_dvd.iSelectedSPUStream >= 0)
833 OMXSelectionStreams streams;
837 streams = m_SelectionStreams.Get(STREAM_VIDEO, PredicateVideoPriority);
839 for(OMXSelectionStreams::iterator it = streams.begin(); it != streams.end() && !valid; ++it)
841 if(OpenVideoStream(it->id, it->source, reset))
845 CloseVideoStream(true);
848 if(m_PlayerOptions.video_only)
851 streams = m_SelectionStreams.Get(STREAM_AUDIO, PredicateAudioPriority);
854 for(OMXSelectionStreams::iterator it = streams.begin(); it != streams.end() && !valid; ++it)
856 if(OpenAudioStream(it->id, it->source, reset))
860 CloseAudioStream(true);
862 // enable or disable subtitles
863 bool visible = CMediaSettings::Get().GetCurrentVideoSettings().m_SubtitleOn;
865 // open subtitle stream
866 OMXSelectionStream as = m_SelectionStreams.Get(STREAM_AUDIO, GetAudioStream());
867 PredicateSubtitlePriority psp(as.language);
868 streams = m_SelectionStreams.Get(STREAM_SUBTITLE, psp);
870 for(OMXSelectionStreams::iterator it = streams.begin(); it != streams.end() && !valid; ++it)
872 if(OpenSubtitleStream(it->id, it->source))
875 if(!psp.relevant(*it))
877 else if(it->flags & CDemuxStream::FLAG_FORCED)
882 CloseSubtitleStream(true);
884 SetSubtitleVisibleInternal(visible);
886 // open teletext stream
887 streams = m_SelectionStreams.Get(STREAM_TELETEXT);
889 for(OMXSelectionStreams::iterator it = streams.begin(); it != streams.end() && !valid; ++it)
891 if(OpenTeletextStream(it->id, it->source))
895 CloseTeletextStream(true);
898 bool COMXPlayer::ReadPacket(DemuxPacket*& packet, CDemuxStream*& stream)
901 // check if we should read from subtitle demuxer
902 if( m_pSubtitleDemuxer && m_dvdPlayerSubtitle.AcceptsData() )
904 packet = m_pSubtitleDemuxer->Read();
908 UpdateCorrection(packet, m_offset_pts);
909 if(packet->iStreamId < 0)
912 stream = m_pSubtitleDemuxer->GetStream(packet->iStreamId);
915 CLog::Log(LOGERROR, "%s - Error demux packet doesn't belong to a valid stream", __FUNCTION__);
918 if(stream->source == STREAM_SOURCE_NONE)
920 m_SelectionStreams.Clear(STREAM_NONE, STREAM_SOURCE_DEMUX_SUB);
921 m_SelectionStreams.Update(NULL, m_pSubtitleDemuxer);
927 // read a data frame from stream.
929 packet = m_pDemuxer->Read();
933 // stream changed, update and open defaults
934 if(packet->iStreamId == DMX_SPECIALID_STREAMCHANGE)
936 m_SelectionStreams.Clear(STREAM_NONE, STREAM_SOURCE_DEMUX);
937 m_SelectionStreams.Update(m_pInputStream, m_pDemuxer);
938 OpenDefaultStreams(false);
940 // reevaluate HasVideo/Audio, we may have switched from/to a radio channel
941 if(m_CurrentVideo.id < 0)
943 if(m_CurrentAudio.id < 0)
949 UpdateCorrection(packet, m_offset_pts);
951 if(packet->iStreamId < 0)
956 stream = m_pDemuxer->GetStream(packet->iStreamId);
959 CLog::Log(LOGERROR, "%s - Error demux packet doesn't belong to a valid stream", __FUNCTION__);
962 if(stream->source == STREAM_SOURCE_NONE)
964 m_SelectionStreams.Clear(STREAM_NONE, STREAM_SOURCE_DEMUX);
965 m_SelectionStreams.Update(m_pInputStream, m_pDemuxer);
973 bool COMXPlayer::IsValidStream(COMXCurrentStream& stream)
976 return true; // we consider non selected as valid
978 int source = STREAM_SOURCE_MASK(stream.source);
979 if(source == STREAM_SOURCE_TEXT)
981 if(source == STREAM_SOURCE_DEMUX_SUB)
983 CDemuxStream* st = m_pSubtitleDemuxer->GetStream(stream.id);
984 if(st == NULL || st->disabled)
986 if(st->type != stream.type)
990 if(source == STREAM_SOURCE_DEMUX)
992 CDemuxStream* st = m_pDemuxer->GetStream(stream.id);
993 if(st == NULL || st->disabled)
995 if(st->type != stream.type)
998 if (m_pInputStream && m_pInputStream->IsStreamType(DVDSTREAM_TYPE_DVD))
1000 if(stream.type == STREAM_AUDIO && st->iPhysicalId != m_dvd.iSelectedAudioStream)
1002 if(stream.type == STREAM_SUBTITLE && st->iPhysicalId != m_dvd.iSelectedSPUStream)
1012 bool COMXPlayer::IsBetterStream(COMXCurrentStream& current, CDemuxStream* stream)
1014 // Do not reopen non-video streams if we're in video-only mode
1015 if(m_PlayerOptions.video_only && current.type != STREAM_VIDEO)
1018 if(stream->disabled)
1021 if (m_pInputStream && ( m_pInputStream->IsStreamType(DVDSTREAM_TYPE_DVD)
1022 || m_pInputStream->IsStreamType(DVDSTREAM_TYPE_BLURAY) ) )
1026 source_type = STREAM_SOURCE_MASK(current.source);
1027 if(source_type != STREAM_SOURCE_DEMUX
1028 && source_type != STREAM_SOURCE_NONE)
1031 source_type = STREAM_SOURCE_MASK(stream->source);
1032 if(source_type != STREAM_SOURCE_DEMUX
1033 || stream->type != current.type
1034 || stream->iId == current.id)
1037 if(current.type == STREAM_AUDIO && stream->iPhysicalId == m_dvd.iSelectedAudioStream)
1039 if(current.type == STREAM_SUBTITLE && stream->iPhysicalId == m_dvd.iSelectedSPUStream)
1041 if(current.type == STREAM_VIDEO && current.id < 0)
1046 if(stream->source == current.source
1047 && stream->iId == current.id)
1050 if(stream->type != current.type)
1053 if(current.type == STREAM_SUBTITLE)
1062 void COMXPlayer::Process()
1064 bool bOmxWaitVideo = false;
1065 bool bOmxWaitAudio = false;
1066 bool bOmxSentEOFs = false;
1067 float m_threshold = 0.2f;
1069 if (!OpenInputStream())
1071 m_bAbortRequest = true;
1075 if (CDVDInputStream::IMenus* ptr = dynamic_cast<CDVDInputStream::IMenus*>(m_pInputStream))
1077 CLog::Log(LOGNOTICE, "OMXPlayer: playing a file with menu's");
1078 if(CDVDInputStreamNavigator* nav = dynamic_cast<CDVDInputStreamNavigator*>(m_pInputStream))
1079 m_PlayerOptions.starttime = 0;
1081 if(m_PlayerOptions.state.size() > 0)
1082 ptr->SetState(m_PlayerOptions.state);
1083 else if(CDVDInputStreamNavigator* nav = dynamic_cast<CDVDInputStreamNavigator*>(m_pInputStream))
1084 nav->EnableSubtitleStream(CMediaSettings::Get().GetCurrentVideoSettings().m_SubtitleOn);
1086 CMediaSettings::Get().GetCurrentVideoSettings().m_SubtitleCached = true;
1089 if(!OpenDemuxStream())
1091 m_bAbortRequest = true;
1095 // allow renderer to switch to fullscreen if requested
1096 m_omxPlayerVideo.EnableFullscreen(m_PlayerOptions.fullscreen);
1098 if(!m_av_clock.OMXInitialize(&m_clock))
1100 m_bAbortRequest = true;
1103 if(CSettings::Get().GetBool("videoplayer.adjustrefreshrate"))
1104 m_av_clock.HDMIClockSync();
1105 m_av_clock.OMXStateIdle();
1106 m_av_clock.OMXStop();
1107 m_av_clock.OMXPause();
1109 OpenDefaultStreams();
1111 // look for any EDL files
1113 m_EdlAutoSkipMarkers.Clear();
1114 if (m_CurrentVideo.id >= 0 && m_CurrentVideo.hint.fpsrate > 0 && m_CurrentVideo.hint.fpsscale > 0)
1116 float fFramesPerSecond = (float)m_CurrentVideo.hint.fpsrate / (float)m_CurrentVideo.hint.fpsscale;
1117 m_Edl.ReadEditDecisionLists(m_filename, fFramesPerSecond, m_CurrentVideo.hint.height);
1121 * Check to see if the demuxer should start at something other than time 0. This will be the case
1122 * if there was a start time specified as part of the "Start from where last stopped" (aka
1123 * auto-resume) feature or if there is an EDL cut or commercial break that starts at time 0.
1127 if(m_PlayerOptions.starttime > 0 || m_PlayerOptions.startpercent > 0)
1129 if (m_PlayerOptions.startpercent > 0 && m_pDemuxer)
1131 int64_t playerStartTime = (int64_t) ( ( (float) m_pDemuxer->GetStreamLength() ) * ( m_PlayerOptions.startpercent/(float)100 ) );
1132 starttime = m_Edl.RestoreCutTime(playerStartTime);
1136 starttime = m_Edl.RestoreCutTime((int64_t)m_PlayerOptions.starttime * 1000); // s to ms
1138 CLog::Log(LOGDEBUG, "%s - Start position set to last stopped position: %d", __FUNCTION__, starttime);
1140 else if(m_Edl.InCut(0, &cut)
1141 && (cut.action == CEdl::CUT || cut.action == CEdl::COMM_BREAK))
1143 starttime = cut.end;
1144 CLog::Log(LOGDEBUG, "%s - Start position set to end of first cut or commercial break: %d", __FUNCTION__, starttime);
1145 if(cut.action == CEdl::COMM_BREAK)
1148 * Setup auto skip markers as if the commercial break had been skipped using standard
1151 m_EdlAutoSkipMarkers.commbreak_start = cut.start;
1152 m_EdlAutoSkipMarkers.commbreak_end = cut.end;
1153 m_EdlAutoSkipMarkers.seek_to_start = true;
1158 double startpts = DVD_NOPTS_VALUE;
1161 if (m_pDemuxer->SeekTime(starttime, false, &startpts))
1162 CLog::Log(LOGDEBUG, "%s - starting demuxer from: %d", __FUNCTION__, starttime);
1164 CLog::Log(LOGDEBUG, "%s - failed to start demuxing from: %d", __FUNCTION__, starttime);
1167 if(m_pSubtitleDemuxer)
1169 if(m_pSubtitleDemuxer->SeekTime(starttime, false, &startpts))
1170 CLog::Log(LOGDEBUG, "%s - starting subtitle demuxer from: %d", __FUNCTION__, starttime);
1172 CLog::Log(LOGDEBUG, "%s - failed to start subtitle demuxing from: %d", __FUNCTION__, starttime);
1176 // make sure all selected stream have data on startup
1177 if (CachePVRStream())
1178 SetCaching(CACHESTATE_PVR);
1180 // make sure application know our info
1181 UpdateApplication(0);
1184 if(m_PlayerOptions.identify == false)
1185 m_callback.OnPlayBackStarted();
1187 // we are done initializing now, set the readyevent
1190 if (!CachePVRStream())
1191 SetCaching(CACHESTATE_FLUSH);
1193 EDEINTERLACEMODE current_deinterlace = CMediaSettings::Get().GetCurrentVideoSettings().m_DeinterlaceMode;
1195 while (!m_bAbortRequest)
1197 double now = m_clock.GetAbsoluteClock();
1198 if (m_last_check_time == 0.0 || m_last_check_time + DVD_MSEC_TO_TIME(20) <= now)
1200 m_last_check_time = now;
1201 m_stamp = m_av_clock.OMXMediaTime();
1202 const bool m_Pause = m_playSpeed == DVD_PLAYSPEED_PAUSE;
1203 const bool not_accepts_data = (!m_omxPlayerAudio.AcceptsData() && m_CurrentAudio.id >= 0) ||
1204 (!m_omxPlayerVideo.AcceptsData() && m_CurrentVideo.id >= 0);
1205 /* when the video/audio fifos are low, we pause clock, when high we resume */
1206 double audio_pts = floor(m_omxPlayerAudio.GetCurrentPts());
1207 double video_pts = floor(m_omxPlayerVideo.GetCurrentPts());
1209 float audio_fifo = audio_pts / DVD_TIME_BASE - m_stamp * 1e-6;
1210 float video_fifo = video_pts / DVD_TIME_BASE - m_stamp * 1e-6;
1211 float threshold = 0.1f;
1212 bool audio_fifo_low = false, video_fifo_low = false, audio_fifo_high = false, video_fifo_high = false;
1214 // if deinterlace setting has changed, we should close and open video
1215 if (current_deinterlace != CMediaSettings::Get().GetCurrentVideoSettings().m_DeinterlaceMode)
1217 int iStream = m_CurrentVideo.id, source = m_CurrentVideo.source;
1218 CloseVideoStream(false);
1219 OpenVideoStream(iStream, source);
1220 if (m_State.canseek)
1221 m_messenger.Put(new CDVDMsgPlayerSeek(GetTime(), true, true, true, true, true));
1222 current_deinterlace = CMediaSettings::Get().GetCurrentVideoSettings().m_DeinterlaceMode;
1225 m_video_fifo = (int)(100.0*(m_omxPlayerVideo.GetDecoderBufferSize()-m_omxPlayerVideo.GetDecoderFreeSpace())/m_omxPlayerVideo.GetDecoderBufferSize());
1226 m_audio_fifo = (int)(100.0*audio_fifo/m_omxPlayerAudio.GetCacheTotal());
1229 static unsigned count;
1230 if ((count++ & 7) == 0)
1233 if (m_omxPlayerVideo.GetDecoderBufferSize() && m_omxPlayerAudio.GetCacheTotal())
1234 vc_gencmd(response, sizeof response, "render_bar 4 video_fifo %d %d %d %d",
1236 (int)(100.0*video_fifo/m_omxPlayerAudio.GetCacheTotal()),
1238 if (m_omxPlayerAudio.GetCacheTotal())
1239 vc_gencmd(response, sizeof response, "render_bar 5 audio_fifo %d %d %d %d",
1241 (int)(100.0*m_omxPlayerAudio.GetDelay()/m_omxPlayerAudio.GetCacheTotal()),
1243 vc_gencmd(response, sizeof response, "render_bar 6 video_queue %d %d %d %d",
1244 m_omxPlayerVideo.GetLevel(), 0, 0, 100);
1245 vc_gencmd(response, sizeof response, "render_bar 7 audio_queue %d %d %d %d",
1246 m_omxPlayerAudio.GetLevel(), 0, 0, 100);
1249 if (audio_pts != DVD_NOPTS_VALUE)
1251 audio_fifo_low = m_HasAudio && audio_fifo < threshold;
1252 audio_fifo_high = audio_pts != DVD_NOPTS_VALUE && audio_fifo >= m_threshold;
1254 if (video_pts != DVD_NOPTS_VALUE)
1256 video_fifo_low = m_HasVideo && video_fifo < threshold;
1257 video_fifo_high = video_pts != DVD_NOPTS_VALUE && video_fifo >= m_threshold;
1259 if (!m_HasAudio && m_HasVideo)
1260 audio_fifo_high = true;
1261 if (!m_HasVideo && m_HasAudio)
1262 video_fifo_high = true;
1265 CLog::Log(LOGDEBUG, "%s - M:%.6f-%.6f (A:%.6f V:%.6f) PEF:%d%d%d S:%.2f A:%.2f V:%.2f/T:%.2f (A:%d%d V:%d%d) A:%d%% V:%d%% (%.2f,%.2f)", __FUNCTION__,
1266 m_stamp*1e-6, m_av_clock.OMXClockAdjustment()*1e-6, audio_pts*1e-6, video_pts*1e-6, m_av_clock.OMXIsPaused(), bOmxSentEOFs, not_accepts_data, m_playSpeed * (1.0f/DVD_PLAYSPEED_NORMAL),
1267 audio_pts == DVD_NOPTS_VALUE ? 0.0:audio_fifo, video_pts == DVD_NOPTS_VALUE ? 0.0:video_fifo, m_threshold,
1268 audio_fifo_low, audio_fifo_high, video_fifo_low, video_fifo_high,
1269 m_omxPlayerAudio.GetLevel(), m_omxPlayerVideo.GetLevel(), m_omxPlayerAudio.GetDelay(), (float)m_omxPlayerAudio.GetCacheTotal());
1272 if (TP(m_playSpeed))
1274 if (m_CurrentVideo.started)
1276 if (m_stamp == 0.0 && (!m_stepped || m_playSpeed > 0))
1278 /* trickplay modes progress by stepping */
1279 CLog::Log(LOGDEBUG, "COMXPlayer::Process - Seeking step speed:%.2f last:%.2f v:%.2f", (double)m_playSpeed / DVD_PLAYSPEED_NORMAL, m_SpeedState.lastpts*1e-6, video_pts*1e-6);
1280 m_av_clock.OMXStep();
1284 m_av_clock.OMXMediaTime(0.0);
1285 m_last_check_time = 0.0;
1290 else if(!m_Pause && (bOmxSentEOFs || not_accepts_data || (audio_fifo_high && video_fifo_high)))
1292 if (m_av_clock.OMXIsPaused())
1294 CLog::Log(LOGDEBUG, "Resume %.2f,%.2f (A:%d%d V:%d%d) EOF:%d FULL:%d T:%.2f\n", audio_fifo, video_fifo,
1295 audio_fifo_low, audio_fifo_high, video_fifo_low, video_fifo_high, bOmxSentEOFs, not_accepts_data, m_threshold);
1296 m_av_clock.OMXStateExecute();
1297 m_av_clock.OMXResume();
1300 else if (m_Pause || audio_fifo_low || video_fifo_low)
1302 if (!m_av_clock.OMXIsPaused() && !TPA(m_playSpeed))
1305 m_threshold = std::min(2.0f*m_threshold, 16.0f);
1306 CLog::Log(LOGDEBUG, "Pause %.2f,%.2f (A:%d%d V:%d%d) EOF:%d FULL:%d T:%.2f\n", audio_fifo, video_fifo,
1307 audio_fifo_low, audio_fifo_high, video_fifo_low, video_fifo_high, bOmxSentEOFs, not_accepts_data, m_threshold);
1308 m_av_clock.OMXPause();
1317 // should we open a new input stream?
1320 if (OpenInputStream() == false)
1322 CLog::Log(LOGERROR, "%s - Closing stream due to OpenInputStream()", __FUNCTION__);
1323 m_bAbortRequest = true;
1328 // should we open a new demuxer?
1331 if (m_pInputStream->NextStream() == CDVDInputStream::NEXTSTREAM_NONE)
1334 if (m_pInputStream->IsEOF())
1337 if (OpenDemuxStream() == false)
1339 CLog::Log(LOGERROR, "%s - Closing stream due to OpenDemuxStream()", __FUNCTION__);
1340 m_bAbortRequest = true;
1344 OpenDefaultStreams();
1346 // never allow first frames after open to be skipped
1347 if( m_omxPlayerVideo.IsInited() )
1348 m_omxPlayerVideo.SendMessage(new CDVDMsg(CDVDMsg::VIDEO_NOSKIP));
1350 if (CachePVRStream())
1351 SetCaching(CACHESTATE_PVR);
1353 UpdateApplication(0);
1357 // handle eventual seeks due to playspeed
1360 // update player state
1361 UpdatePlayState(200);
1363 // update application with our state
1364 UpdateApplication(1000);
1366 // make sure we run subtitle process here
1367 m_dvdPlayerSubtitle.Process(m_clock.GetClock() + m_State.time_offset - m_omxPlayerVideo.GetSubtitleDelay(), m_State.time_offset);
1369 // OMX emergency exit
1370 if(HasAudio() && m_omxPlayerAudio.BadState())
1372 CLog::Log(LOGERROR, "%s - Closing stream due to m_omxPlayerAudio.BadState()", __FUNCTION__);
1373 m_bAbortRequest = true;
1377 if (CheckDelayedChannelEntry())
1380 // if the queues are full, no need to read more
1381 if ((!m_omxPlayerAudio.AcceptsData() && m_CurrentAudio.id >= 0) ||
1382 (!m_omxPlayerVideo.AcceptsData() && m_CurrentVideo.id >= 0))
1384 if(m_pDemuxer && m_DemuxerPausePending)
1386 m_DemuxerPausePending = false;
1387 m_pDemuxer->SetSpeed(DVD_PLAYSPEED_PAUSE);
1394 // always yield to players if they have data levels > 50 percent
1395 if((m_omxPlayerAudio.GetLevel() > 50 || m_CurrentAudio.id < 0)
1396 && (m_omxPlayerVideo.GetLevel() > 50 || m_CurrentVideo.id < 0))
1399 DemuxPacket* pPacket = NULL;
1400 CDemuxStream *pStream = NULL;
1401 ReadPacket(pPacket, pStream);
1402 if (pPacket && !pStream)
1404 /* probably a empty packet, just free it and move on */
1405 CDVDDemuxUtils::FreeDemuxPacket(pPacket);
1410 // reset eos state when we get a packet (e.g. for case of seek after eos)
1411 bOmxWaitVideo = false;
1412 bOmxWaitAudio = false;
1413 bOmxSentEOFs = false;
1417 // when paused, demuxer could be be returning empty
1418 if (m_playSpeed == DVD_PLAYSPEED_PAUSE)
1421 // check for a still frame state
1422 if (CDVDInputStream::IMenus* pStream = dynamic_cast<CDVDInputStream::IMenus*>(m_pInputStream))
1424 // stills will be skipped
1425 if(m_dvd.state == DVDSTATE_STILL)
1427 if (m_dvd.iDVDStillTime > 0)
1429 if ((XbmcThreads::SystemClockMillis() - m_dvd.iDVDStillStartTime) >= m_dvd.iDVDStillTime)
1431 m_dvd.iDVDStillTime = 0;
1432 m_dvd.iDVDStillStartTime = 0;
1433 m_dvd.state = DVDSTATE_NORMAL;
1434 pStream->SkipStill();
1441 // if there is another stream available, reopen demuxer
1442 CDVDInputStream::ENextStream next = m_pInputStream->NextStream();
1443 if(next == CDVDInputStream::NEXTSTREAM_OPEN)
1445 SAFE_DELETE(m_pDemuxer);
1446 m_CurrentAudio.stream = NULL;
1447 m_CurrentVideo.stream = NULL;
1448 m_CurrentSubtitle.stream = NULL;
1452 // input stream asked us to just retry
1453 if(next == CDVDInputStream::NEXTSTREAM_RETRY)
1459 // make sure we tell all players to finish it's data
1462 if(m_CurrentAudio.inited)
1464 m_omxPlayerAudio.SendMessage (new CDVDMsg(CDVDMsg::GENERAL_EOF));
1465 bOmxWaitAudio = true;
1467 if(m_CurrentVideo.inited)
1469 m_omxPlayerVideo.SendMessage (new CDVDMsg(CDVDMsg::GENERAL_EOF));
1470 bOmxWaitVideo = true;
1472 if(m_CurrentSubtitle.inited)
1473 m_dvdPlayerSubtitle.SendMessage(new CDVDMsg(CDVDMsg::GENERAL_EOF));
1474 if(m_CurrentTeletext.inited)
1475 m_dvdPlayerTeletext.SendMessage(new CDVDMsg(CDVDMsg::GENERAL_EOF));
1476 m_CurrentAudio.inited = false;
1477 m_CurrentVideo.inited = false;
1478 m_CurrentSubtitle.inited = false;
1479 m_CurrentTeletext.inited = false;
1480 bOmxSentEOFs = true;
1483 // if we are caching, start playing it again
1484 SetCaching(CACHESTATE_DONE);
1486 // while players are still playing, keep going to allow seekbacks
1487 if(m_omxPlayerVideo.HasData()
1488 || m_omxPlayerAudio.HasData())
1494 // wait for omx components to finish
1495 if(bOmxWaitVideo && !m_omxPlayerVideo.IsEOS())
1500 if(bOmxWaitAudio && !m_omxPlayerAudio.IsEOS())
1506 if (!m_pInputStream->IsEOF())
1507 CLog::Log(LOGINFO, "%s - eof reading from demuxer", __FUNCTION__);
1509 m_CurrentAudio.started = false;
1510 m_CurrentVideo.started = false;
1511 m_CurrentSubtitle.started = false;
1512 m_CurrentTeletext.started = false;
1517 // it's a valid data packet, reset error counter
1520 // check so that none of our streams has become invalid
1521 if (!IsValidStream(m_CurrentAudio) && m_omxPlayerAudio.IsStalled()) CloseAudioStream(true);
1522 if (!IsValidStream(m_CurrentVideo) && m_omxPlayerVideo.IsStalled()) CloseVideoStream(true);
1523 if (!IsValidStream(m_CurrentSubtitle) && m_dvdPlayerSubtitle.IsStalled()) CloseSubtitleStream(true);
1524 if (!IsValidStream(m_CurrentTeletext)) CloseTeletextStream(true);
1526 // see if we can find something better to play
1527 if (IsBetterStream(m_CurrentAudio, pStream)) OpenAudioStream (pStream->iId, pStream->source);
1528 if (IsBetterStream(m_CurrentVideo, pStream)) OpenVideoStream (pStream->iId, pStream->source);
1529 if (IsBetterStream(m_CurrentSubtitle, pStream)) OpenSubtitleStream(pStream->iId, pStream->source);
1530 if (IsBetterStream(m_CurrentTeletext, pStream)) OpenTeletextStream(pStream->iId, pStream->source);
1532 // process the packet
1533 ProcessPacket(pStream, pPacket);
1535 // check if in a cut or commercial break that should be automatically skipped
1536 CheckAutoSceneSkip();
1540 bool COMXPlayer::CheckDelayedChannelEntry(void)
1542 bool bReturn(false);
1544 if (m_ChannelEntryTimeOut.IsTimePast())
1546 CFileItem currentFile(g_application.CurrentFileItem());
1547 CPVRChannel *currentChannel = currentFile.GetPVRChannelInfoTag();
1548 SwitchChannel(*currentChannel);
1551 m_ChannelEntryTimeOut.SetInfinite();
1557 void COMXPlayer::ProcessPacket(CDemuxStream* pStream, DemuxPacket* pPacket)
1559 /* process packet if it belongs to selected stream. for dvd's don't allow automatic opening of streams*/
1560 OMXStreamLock lock(this);
1564 if (pPacket->iStreamId == m_CurrentAudio.id && pStream->source == m_CurrentAudio.source && pStream->type == STREAM_AUDIO)
1565 ProcessAudioData(pStream, pPacket);
1566 else if (pPacket->iStreamId == m_CurrentVideo.id && pStream->source == m_CurrentVideo.source && pStream->type == STREAM_VIDEO)
1567 ProcessVideoData(pStream, pPacket);
1568 else if (pPacket->iStreamId == m_CurrentSubtitle.id && pStream->source == m_CurrentSubtitle.source && pStream->type == STREAM_SUBTITLE)
1569 ProcessSubData(pStream, pPacket);
1570 else if (pPacket->iStreamId == m_CurrentTeletext.id && pStream->source == m_CurrentTeletext.source && pStream->type == STREAM_TELETEXT)
1571 ProcessTeletextData(pStream, pPacket);
1574 pStream->SetDiscard(AVDISCARD_ALL);
1575 CDVDDemuxUtils::FreeDemuxPacket(pPacket); // free it since we won't do anything with it
1580 CLog::Log(LOGERROR, "%s - Exception thrown when processing demux packet", __FUNCTION__);
1585 void COMXPlayer::ProcessAudioData(CDemuxStream* pStream, DemuxPacket* pPacket)
1587 if (m_CurrentAudio.stream != (void*)pStream
1588 || m_CurrentAudio.changes != pStream->changes)
1590 /* check so that dmuxer hints or extra data hasn't changed */
1591 /* if they have, reopen stream */
1593 if (m_CurrentAudio.hint != CDVDStreamInfo(*pStream, true))
1594 OpenAudioStream( pPacket->iStreamId, pStream->source );
1596 m_CurrentAudio.stream = (void*)pStream;
1597 m_CurrentAudio.changes = pStream->changes;
1600 // check if we are too slow and need to recache
1601 CheckStartCaching(m_CurrentAudio);
1603 CheckContinuity(m_CurrentAudio, pPacket);
1604 UpdateTimestamps(m_CurrentAudio, pPacket);
1607 if (CheckPlayerInit(m_CurrentAudio, DVDPLAYER_AUDIO))
1611 * If CheckSceneSkip() returns true then demux point is inside an EDL cut and the packets are dropped.
1612 * If not inside a hard cut, but the demux point has reached an EDL mute section then trigger the
1613 * AUDIO_SILENCE state. The AUDIO_SILENCE state is reverted as soon as the demux point is outside
1614 * of any EDL section while EDL mute is still active.
1617 if (CheckSceneSkip(m_CurrentAudio))
1619 else if (m_Edl.InCut(DVD_TIME_TO_MSEC(m_CurrentAudio.dts + m_offset_pts), &cut) && cut.action == CEdl::MUTE // Inside EDL mute
1620 && !m_EdlAutoSkipMarkers.mute) // Mute not already triggered
1622 m_omxPlayerAudio.SendMessage(new CDVDMsgBool(CDVDMsg::AUDIO_SILENCE, true));
1623 m_EdlAutoSkipMarkers.mute = true;
1625 else if (!m_Edl.InCut(DVD_TIME_TO_MSEC(m_CurrentAudio.dts + m_offset_pts), &cut) // Outside of any EDL
1626 && m_EdlAutoSkipMarkers.mute) // But the mute hasn't been removed yet
1628 m_omxPlayerAudio.SendMessage(new CDVDMsgBool(CDVDMsg::AUDIO_SILENCE, false));
1629 m_EdlAutoSkipMarkers.mute = false;
1632 m_omxPlayerAudio.SendMessage(new CDVDMsgDemuxerPacket(pPacket, drop));
1635 void COMXPlayer::ProcessVideoData(CDemuxStream* pStream, DemuxPacket* pPacket)
1637 if (m_CurrentVideo.stream != (void*)pStream
1638 || m_CurrentVideo.changes != pStream->changes)
1640 /* check so that dmuxer hints or extra data hasn't changed */
1641 /* if they have reopen stream */
1643 if (m_CurrentVideo.hint != CDVDStreamInfo(*pStream, true))
1644 OpenVideoStream(pPacket->iStreamId, pStream->source);
1646 m_CurrentVideo.stream = (void*)pStream;
1647 m_CurrentVideo.changes = pStream->changes;
1650 // check if we are too slow and need to recache
1651 CheckStartCaching(m_CurrentVideo);
1653 if( pPacket->iSize != 4) //don't check the EOF_SEQUENCE of stillframes
1655 CheckContinuity(m_CurrentVideo, pPacket);
1656 UpdateTimestamps(m_CurrentVideo, pPacket);
1660 if (CheckPlayerInit(m_CurrentVideo, DVDPLAYER_VIDEO))
1663 if (CheckSceneSkip(m_CurrentVideo))
1666 m_omxPlayerVideo.SendMessage(new CDVDMsgDemuxerPacket(pPacket, drop));
1669 void COMXPlayer::ProcessSubData(CDemuxStream* pStream, DemuxPacket* pPacket)
1671 if (m_CurrentSubtitle.stream != (void*)pStream
1672 || m_CurrentSubtitle.changes != pStream->changes)
1674 /* check so that dmuxer hints or extra data hasn't changed */
1675 /* if they have reopen stream */
1677 if (m_CurrentSubtitle.hint != CDVDStreamInfo(*pStream, true))
1678 OpenSubtitleStream(pPacket->iStreamId, pStream->source);
1680 m_CurrentSubtitle.stream = (void*)pStream;
1681 m_CurrentSubtitle.changes = pStream->changes;
1684 UpdateTimestamps(m_CurrentSubtitle, pPacket);
1687 if (CheckPlayerInit(m_CurrentSubtitle, DVDPLAYER_SUBTITLE))
1690 if (CheckSceneSkip(m_CurrentSubtitle))
1693 m_dvdPlayerSubtitle.SendMessage(new CDVDMsgDemuxerPacket(pPacket, drop));
1695 if(m_pInputStream && m_pInputStream->IsStreamType(DVDSTREAM_TYPE_DVD))
1696 m_dvdPlayerSubtitle.UpdateOverlayInfo((CDVDInputStreamNavigator*)m_pInputStream, LIBDVDNAV_BUTTON_NORMAL);
1699 void COMXPlayer::ProcessTeletextData(CDemuxStream* pStream, DemuxPacket* pPacket)
1701 if (m_CurrentTeletext.stream != (void*)pStream
1702 || m_CurrentTeletext.changes != pStream->changes)
1704 /* check so that dmuxer hints or extra data hasn't changed */
1705 /* if they have, reopen stream */
1706 if (m_CurrentTeletext.hint != CDVDStreamInfo(*pStream, true))
1707 OpenTeletextStream( pPacket->iStreamId, pStream->source );
1709 m_CurrentTeletext.stream = (void*)pStream;
1710 m_CurrentTeletext.changes = pStream->changes;
1712 UpdateTimestamps(m_CurrentTeletext, pPacket);
1715 if (CheckPlayerInit(m_CurrentTeletext, DVDPLAYER_TELETEXT))
1718 if (CheckSceneSkip(m_CurrentTeletext))
1721 m_dvdPlayerTeletext.SendMessage(new CDVDMsgDemuxerPacket(pPacket, drop));
1724 bool COMXPlayer::GetCachingTimes(double& level, double& delay, double& offset)
1726 if(!m_pInputStream || !m_pDemuxer)
1729 XFILE::SCacheStatus status;
1730 if (!m_pInputStream->GetCacheStatus(&status))
1733 int64_t cached = status.forward;
1734 unsigned currate = status.currate;
1735 unsigned maxrate = status.maxrate;
1736 bool full = status.full;
1738 int64_t length = m_pInputStream->GetLength();
1739 int64_t remain = length - m_pInputStream->Seek(0, SEEK_CUR);
1741 if(cached < 0 || length <= 0 || remain < 0)
1744 double play_sbp = DVD_MSEC_TO_TIME(m_pDemuxer->GetStreamLength()) / length;
1745 double queued = 1000.0 * GetQueueTime() / play_sbp;
1749 offset = (double)(cached + queued) / length;
1754 double cache_sbp = 1.1 * (double)DVD_TIME_BASE / currate; /* underestimate by 10 % */
1755 double play_left = play_sbp * (remain + queued); /* time to play out all remaining bytes */
1756 double cache_left = cache_sbp * (remain - cached); /* time to cache the remaining bytes */
1757 double cache_need = std::max(0.0, remain - play_left / cache_sbp); /* bytes needed until play_left == cache_left */
1759 delay = cache_left - play_left;
1761 if (full && (currate < maxrate) )
1762 level = -1.0; /* buffer is full & our read rate is too low */
1764 level = (cached + queued) / (cache_need + queued);
1769 void COMXPlayer::HandlePlaySpeed()
1771 ECacheState caching = m_caching;
1773 if(IsInMenu() && caching != CACHESTATE_DONE)
1774 caching = CACHESTATE_DONE;
1776 if(caching == CACHESTATE_FULL)
1778 double level, delay, offset;
1779 if(GetCachingTimes(level, delay, offset))
1783 CGUIDialogKaiToast::QueueNotification(g_localizeStrings.Get(21454), g_localizeStrings.Get(21455));
1784 caching = CACHESTATE_INIT;
1787 caching = CACHESTATE_INIT;
1791 if ((!m_omxPlayerAudio.AcceptsData() && m_CurrentAudio.id >= 0)
1792 || (!m_omxPlayerVideo.AcceptsData() && m_CurrentVideo.id >= 0))
1793 caching = CACHESTATE_INIT;
1797 if(caching == CACHESTATE_INIT)
1799 // if all enabled streams have been inited we are done
1800 if((m_CurrentVideo.id < 0 || m_CurrentVideo.started)
1801 && (m_CurrentAudio.id < 0 || m_CurrentAudio.started))
1802 caching = CACHESTATE_PLAY;
1804 // handle situation that we get no data on one stream
1805 if(m_CurrentAudio.id >= 0 && m_CurrentVideo.id >= 0)
1807 if ((!m_omxPlayerAudio.AcceptsData() && !m_CurrentVideo.started)
1808 || (!m_omxPlayerVideo.AcceptsData() && !m_CurrentAudio.started))
1810 caching = CACHESTATE_DONE;
1815 if (caching == CACHESTATE_PVR)
1817 bool bGotAudio(m_pDemuxer->GetNrOfAudioStreams() > 0);
1818 bool bGotVideo(m_pDemuxer->GetNrOfVideoStreams() > 0);
1819 bool bAudioLevelOk(m_omxPlayerAudio.GetLevel() > g_advancedSettings.m_iPVRMinAudioCacheLevel);
1820 bool bVideoLevelOk(m_omxPlayerVideo.GetLevel() > g_advancedSettings.m_iPVRMinVideoCacheLevel);
1821 bool bAudioFull(!m_omxPlayerAudio.AcceptsData());
1822 bool bVideoFull(!m_omxPlayerVideo.AcceptsData());
1824 if (/* if all streams got at least g_advancedSettings.m_iPVRMinCacheLevel in their buffers, we're done */
1825 ((bGotVideo || bGotAudio) && (!bGotAudio || bAudioLevelOk) && (!bGotVideo || bVideoLevelOk)) ||
1826 /* or if one of the buffers is full */
1827 (bAudioFull || bVideoFull))
1829 CLog::Log(LOGDEBUG, "set caching from pvr to done. audio (%d) = %d. video (%d) = %d",
1830 bGotAudio, m_omxPlayerAudio.GetLevel(),
1831 bGotVideo, m_omxPlayerVideo.GetLevel());
1833 CFileItem currentItem(g_application.CurrentFileItem());
1834 if (currentItem.HasPVRChannelInfoTag())
1835 g_PVRManager.LoadCurrentChannelSettings();
1837 caching = CACHESTATE_DONE;
1841 /* ensure that automatically started players are stopped while caching */
1842 if (m_CurrentAudio.started)
1843 m_omxPlayerAudio.SetSpeed(DVD_PLAYSPEED_PAUSE);
1844 if (m_CurrentVideo.started)
1845 m_omxPlayerVideo.SetSpeed(DVD_PLAYSPEED_PAUSE);
1849 if(caching == CACHESTATE_PLAY)
1851 // if all enabled streams have started playing we are done
1852 if((m_CurrentVideo.id < 0 || !m_omxPlayerVideo.IsStalled())
1853 && (m_CurrentAudio.id < 0 || !m_omxPlayerAudio.IsStalled()))
1854 caching = CACHESTATE_DONE;
1857 if(m_caching != caching)
1858 SetCaching(caching);
1861 if(GetPlaySpeed() != DVD_PLAYSPEED_NORMAL && GetPlaySpeed() != DVD_PLAYSPEED_PAUSE)
1865 // this can't be done in menu
1866 SetPlaySpeed(DVD_PLAYSPEED_NORMAL);
1869 else if (m_CurrentVideo.id >= 0
1870 && m_CurrentVideo.inited == true
1871 && m_SpeedState.lastpts != m_omxPlayerVideo.GetCurrentPts()
1872 && m_SpeedState.lasttime != GetTime()
1875 m_SpeedState.lastpts = m_omxPlayerVideo.GetCurrentPts();
1876 m_SpeedState.lasttime = GetTime();
1877 // check how much off clock video is when ff/rw:ing
1878 // a problem here is that seeking isn't very accurate
1879 // and since the clock will be resynced after seek
1880 // we might actually not really be playing at the wanted
1881 // speed. we'd need to have some way to not resync the clock
1882 // after a seek to remember timing. still need to handle
1883 // discontinuities somehow
1885 // when seeking, give the player a headstart to make sure
1886 // the time it takes to seek doesn't make a difference.
1888 error = m_clock.GetClock() - m_SpeedState.lastpts;
1889 error *= m_playSpeed / abs(m_playSpeed);
1891 if(error > DVD_MSEC_TO_TIME(1000))
1893 CLog::Log(LOGDEBUG, "COMXPlayer::Process - Seeking to catch up");
1894 int64_t iTime = (int64_t)DVD_TIME_TO_MSEC(m_clock.GetClock() + m_State.time_offset + 500000.0 * m_playSpeed / DVD_PLAYSPEED_NORMAL);
1895 m_messenger.Put(new CDVDMsgPlayerSeek(iTime, (GetPlaySpeed() < 0), true, false, false, true));
1901 bool COMXPlayer::CheckStartCaching(COMXCurrentStream& current)
1903 if(m_caching != CACHESTATE_DONE
1904 || m_playSpeed != DVD_PLAYSPEED_NORMAL)
1910 if((current.type == STREAM_AUDIO && m_omxPlayerAudio.IsStalled())
1911 || (current.type == STREAM_VIDEO && m_omxPlayerVideo.IsStalled()))
1913 if (CachePVRStream())
1915 if ((current.type == STREAM_AUDIO && current.started && m_omxPlayerAudio.GetLevel() == 0) ||
1916 (current.type == STREAM_VIDEO && current.started && m_omxPlayerVideo.GetLevel() == 0))
1918 CLog::Log(LOGDEBUG, "%s stream stalled. start buffering", current.type == STREAM_AUDIO ? "audio" : "video");
1919 SetCaching(CACHESTATE_PVR);
1924 // don't start caching if it's only a single stream that has run dry
1925 if(m_omxPlayerAudio.GetLevel() > 50
1926 || m_omxPlayerVideo.GetLevel() > 50)
1930 SetCaching(CACHESTATE_FULL);
1932 SetCaching(CACHESTATE_INIT);
1938 bool COMXPlayer::CheckPlayerInit(COMXCurrentStream& current, unsigned int source)
1943 if(current.startpts != DVD_NOPTS_VALUE)
1945 if(current.dts == DVD_NOPTS_VALUE)
1947 CLog::Log(LOGDEBUG, "%s - dropping packet type:%d dts:%f to get to start point at %f", __FUNCTION__, source, current.dts, current.startpts);
1951 if((current.startpts - current.dts) > DVD_SEC_TO_TIME(20))
1953 CLog::Log(LOGDEBUG, "%s - too far to decode before finishing seek", __FUNCTION__);
1954 if(m_CurrentAudio.startpts != DVD_NOPTS_VALUE)
1955 m_CurrentAudio.startpts = current.dts;
1956 if(m_CurrentVideo.startpts != DVD_NOPTS_VALUE)
1957 m_CurrentVideo.startpts = current.dts;
1958 if(m_CurrentSubtitle.startpts != DVD_NOPTS_VALUE)
1959 m_CurrentSubtitle.startpts = current.dts;
1960 if(m_CurrentTeletext.startpts != DVD_NOPTS_VALUE)
1961 m_CurrentTeletext.startpts = current.dts;
1964 if(current.dts < current.startpts)
1966 CLog::Log(LOGDEBUG, "%s - dropping packet type:%d dts:%f to get to start point at %f", __FUNCTION__, source, current.dts, current.startpts);
1971 //If this is the first packet after a discontinuity, send it as a resync
1972 if (current.dts != DVD_NOPTS_VALUE)
1974 current.inited = true;
1975 current.startpts = current.dts;
1977 bool setclock = false;
1978 if(m_playSpeed == DVD_PLAYSPEED_NORMAL)
1980 if( source == DVDPLAYER_AUDIO)
1981 setclock = !m_CurrentVideo.inited;
1982 else if(source == DVDPLAYER_VIDEO)
1983 setclock = !m_CurrentAudio.inited;
1987 if(source == DVDPLAYER_VIDEO)
1991 double starttime = current.startpts;
1992 if(m_CurrentAudio.inited
1993 && m_CurrentAudio.startpts != DVD_NOPTS_VALUE
1994 && m_CurrentAudio.startpts < starttime)
1995 starttime = m_CurrentAudio.startpts;
1996 if(m_CurrentVideo.inited
1997 && m_CurrentVideo.startpts != DVD_NOPTS_VALUE
1998 && m_CurrentVideo.startpts < starttime)
1999 starttime = m_CurrentVideo.startpts;
2001 starttime = current.startpts - starttime;
2002 if(starttime > 0 && setclock)
2004 if(starttime > DVD_SEC_TO_TIME(2))
2005 CLog::Log(LOGWARNING, "COMXPlayer::CheckPlayerInit(%d) - Ignoring too large delay of %f", source, starttime);
2007 SendPlayerMessage(new CDVDMsgDouble(CDVDMsg::GENERAL_DELAY, starttime), source);
2010 SendPlayerMessage(new CDVDMsgGeneralResync(current.dts, setclock), source);
2015 void COMXPlayer::UpdateCorrection(DemuxPacket* pkt, double correction)
2017 //CLog::Log(LOGINFO,"%s: %d dts:%.0f pts:%.0f s:%d c:%.0f (%d,%d)", __func__, (int)pkt->iStreamId, pkt->dts, pkt->pts, pkt->iSize, correction, pkt->dts==DVD_NOPTS_VALUE, pkt->pts==DVD_NOPTS_VALUE);
2018 if(pkt->dts != DVD_NOPTS_VALUE) pkt->dts -= correction;
2019 if(pkt->pts != DVD_NOPTS_VALUE) pkt->pts -= correction;
2022 void COMXPlayer::UpdateTimestamps(COMXCurrentStream& current, DemuxPacket* pPacket)
2024 double dts = current.dts;
2025 /* update stored values */
2026 if(pPacket->dts != DVD_NOPTS_VALUE)
2028 else if(pPacket->pts != DVD_NOPTS_VALUE)
2031 /* calculate some average duration */
2032 if(pPacket->duration != DVD_NOPTS_VALUE)
2033 current.dur = pPacket->duration;
2034 else if(dts != DVD_NOPTS_VALUE && current.dts != DVD_NOPTS_VALUE)
2035 current.dur = 0.1 * (current.dur * 9 + (dts - current.dts));
2039 /* send a playback state structure periodically */
2040 if(current.dts_state == DVD_NOPTS_VALUE
2041 || abs(current.dts - current.dts_state) > DVD_MSEC_TO_TIME(200))
2043 current.dts_state = current.dts;
2047 // make sure we send no outdated state to a/v players
2049 SendPlayerMessage(new CDVDMsgType<SPlayerState>(CDVDMsg::PLAYER_DISPLAYTIME, m_StateInput), current.player);
2053 CSingleLock lock(m_StateSection);
2054 m_State = m_StateInput;
2059 static void UpdateLimits(double& minimum, double& maximum, double dts)
2061 if(dts == DVD_NOPTS_VALUE)
2063 if(minimum == DVD_NOPTS_VALUE || minimum > dts) minimum = dts;
2064 if(maximum == DVD_NOPTS_VALUE || maximum < dts) maximum = dts;
2067 void COMXPlayer::CheckContinuity(COMXCurrentStream& current, DemuxPacket* pPacket)
2069 if (m_playSpeed < DVD_PLAYSPEED_PAUSE)
2072 if( pPacket->dts == DVD_NOPTS_VALUE || current.dts == DVD_NOPTS_VALUE)
2075 double mindts = DVD_NOPTS_VALUE, maxdts = DVD_NOPTS_VALUE;
2076 UpdateLimits(mindts, maxdts, m_CurrentAudio.dts);
2077 UpdateLimits(mindts, maxdts, m_CurrentVideo.dts);
2078 UpdateLimits(mindts, maxdts, m_CurrentAudio.dts_end());
2079 UpdateLimits(mindts, maxdts, m_CurrentVideo.dts_end());
2081 /* if we don't have max and min, we can't do anything more */
2082 if( mindts == DVD_NOPTS_VALUE || maxdts == DVD_NOPTS_VALUE )
2085 double correction = 0.0;
2086 if( pPacket->dts > maxdts + DVD_MSEC_TO_TIME(1000))
2088 CLog::Log(LOGDEBUG, "COMXPlayer::CheckContinuity - resync forward :%d, prev:%f, curr:%f, diff:%f"
2089 , current.type, current.dts, pPacket->dts, pPacket->dts - maxdts);
2090 correction = pPacket->dts - maxdts;
2093 /* if it's large scale jump, correct for it */
2094 if(pPacket->dts + DVD_MSEC_TO_TIME(100) < current.dts_end())
2096 CLog::Log(LOGDEBUG, "COMXPlayer::CheckContinuity - resync backward :%d, prev:%f, curr:%f, diff:%f"
2097 , current.type, current.dts, pPacket->dts, pPacket->dts - current.dts);
2098 correction = pPacket->dts - current.dts_end();
2100 else if(pPacket->dts < current.dts)
2102 CLog::Log(LOGDEBUG, "COMXPlayer::CheckContinuity - wrapback :%d, prev:%f, curr:%f, diff:%f"
2103 , current.type, current.dts, pPacket->dts, pPacket->dts - current.dts);
2106 if(correction != 0.0)
2108 /* disable detection on next packet on other stream to avoid ping pong-ing */
2109 if(m_CurrentAudio.player != current.player) m_CurrentAudio.dts = DVD_NOPTS_VALUE;
2110 if(m_CurrentVideo.player != current.player) m_CurrentVideo.dts = DVD_NOPTS_VALUE;
2112 m_offset_pts += correction;
2113 UpdateCorrection(pPacket, correction);
2117 bool COMXPlayer::CheckSceneSkip(COMXCurrentStream& current)
2122 if(current.dts == DVD_NOPTS_VALUE)
2125 if(current.inited == false)
2129 return m_Edl.InCut(DVD_TIME_TO_MSEC(current.dts + m_offset_pts), &cut) && cut.action == CEdl::CUT;
2132 void COMXPlayer::CheckAutoSceneSkip()
2138 * Check that there is an audio and video stream.
2140 if(m_CurrentAudio.id < 0
2141 || m_CurrentVideo.id < 0)
2145 * If there is a startpts defined for either the audio or video stream then dvdplayer is still
2146 * still decoding frames to get to the previously requested seek point.
2148 if(m_CurrentAudio.inited == false
2149 || m_CurrentVideo.inited == false)
2152 if(m_CurrentAudio.dts == DVD_NOPTS_VALUE
2153 || m_CurrentVideo.dts == DVD_NOPTS_VALUE)
2156 const int64_t clock = GetTime();
2159 if(!m_Edl.InCut(clock, &cut))
2162 if(cut.action == CEdl::CUT
2163 && !(cut.end == m_EdlAutoSkipMarkers.cut || cut.start == m_EdlAutoSkipMarkers.cut)) // To prevent looping if same cut again
2165 CLog::Log(LOGDEBUG, "%s - Clock in EDL cut [%s - %s]: %s. Automatically skipping over.",
2166 __FUNCTION__, CEdl::MillisecondsToTimeString(cut.start).c_str(),
2167 CEdl::MillisecondsToTimeString(cut.end).c_str(), CEdl::MillisecondsToTimeString(clock).c_str());
2169 * Seeking either goes to the start or the end of the cut depending on the play direction.
2171 int64_t seek = GetPlaySpeed() >= 0 ? cut.end : cut.start;
2173 * Seeking is NOT flushed so any content up to the demux point is retained when playing forwards.
2175 m_messenger.Put(new CDVDMsgPlayerSeek((int)seek, true, true, true, false, true));
2177 * Seek doesn't always work reliably. Last physical seek time is recorded to prevent looping
2178 * if there was an error with seeking and it landed somewhere unexpected, perhaps back in the
2179 * cut. The cut automatic skip marker is reset every 500ms allowing another attempt at the seek.
2181 m_EdlAutoSkipMarkers.cut = GetPlaySpeed() >= 0 ? cut.end : cut.start;
2183 else if(cut.action == CEdl::COMM_BREAK
2184 && GetPlaySpeed() >= 0
2185 && cut.start > m_EdlAutoSkipMarkers.commbreak_end)
2187 CLog::Log(LOGDEBUG, "%s - Clock in commercial break [%s - %s]: %s. Automatically skipping to end of commercial break (only done once per break)",
2188 __FUNCTION__, CEdl::MillisecondsToTimeString(cut.start).c_str(), CEdl::MillisecondsToTimeString(cut.end).c_str(),
2189 CEdl::MillisecondsToTimeString(clock).c_str());
2191 * Seeking is NOT flushed so any content up to the demux point is retained when playing forwards.
2193 m_messenger.Put(new CDVDMsgPlayerSeek(cut.end + 1, true, true, true, false, true));
2195 * Each commercial break is only skipped once so poorly detected commercial breaks can be
2196 * manually re-entered. Start and end are recorded to prevent looping and to allow seeking back
2197 * to the start of the commercial break if incorrectly flagged.
2199 m_EdlAutoSkipMarkers.commbreak_start = cut.start;
2200 m_EdlAutoSkipMarkers.commbreak_end = cut.end;
2201 m_EdlAutoSkipMarkers.seek_to_start = true; // Allow backwards Seek() to go directly to the start
2205 void COMXPlayer::SynchronizeDemuxer(unsigned int timeout)
2207 if(IsCurrentThread())
2209 if(!m_messenger.IsInited())
2212 CDVDMsgGeneralSynchronize* message = new CDVDMsgGeneralSynchronize(timeout, 0);
2213 m_messenger.Put(message->Acquire());
2214 message->Wait(&m_bStop, 0);
2218 void COMXPlayer::SynchronizePlayers(unsigned int sources)
2220 /* we need a big timeout as audio queue is about 8seconds for 2ch ac3 */
2221 const int timeout = 10*1000; // in milliseconds
2223 CDVDMsgGeneralSynchronize* message = new CDVDMsgGeneralSynchronize(timeout, sources);
2224 if (m_CurrentAudio.id >= 0)
2225 m_omxPlayerAudio.SendMessage(message->Acquire());
2227 if (m_CurrentVideo.id >= 0)
2228 m_omxPlayerVideo.SendMessage(message->Acquire());
2229 /* TODO - we have to rewrite the sync class, to not require
2230 all other players waiting for subtitle, should only
2232 if (m_CurrentSubtitle.id >= 0)
2233 m_dvdPlayerSubtitle.SendMessage(message->Acquire());
2238 void COMXPlayer::SendPlayerMessage(CDVDMsg* pMsg, unsigned int target)
2240 if(target == DVDPLAYER_AUDIO)
2241 m_omxPlayerAudio.SendMessage(pMsg);
2242 if(target == DVDPLAYER_VIDEO)
2243 m_omxPlayerVideo.SendMessage(pMsg);
2244 if(target == DVDPLAYER_SUBTITLE)
2245 m_dvdPlayerSubtitle.SendMessage(pMsg);
2246 if(target == DVDPLAYER_TELETEXT)
2247 m_dvdPlayerTeletext.SendMessage(pMsg);
2250 void COMXPlayer::OnExit()
2254 CLog::Log(LOGNOTICE, "COMXPlayer::OnExit()");
2256 m_av_clock.OMXStop();
2257 m_av_clock.OMXStateIdle();
2259 // set event to inform openfile something went wrong in case openfile is still waiting for this event
2260 SetCaching(CACHESTATE_DONE);
2262 // close each stream
2263 if (!m_bAbortRequest) CLog::Log(LOGNOTICE, "OMXPlayer: eof, waiting for queues to empty");
2264 if (m_CurrentAudio.id >= 0)
2266 CLog::Log(LOGNOTICE, "OMXPlayer: closing audio stream");
2267 CloseAudioStream(!m_bAbortRequest);
2269 if (m_CurrentVideo.id >= 0)
2271 CLog::Log(LOGNOTICE, "OMXPlayer: closing video stream");
2272 CloseVideoStream(!m_bAbortRequest);
2274 if (m_CurrentSubtitle.id >= 0)
2276 CLog::Log(LOGNOTICE, "OMXPlayer: closing subtitle stream");
2277 CloseSubtitleStream(!m_bAbortRequest);
2279 if (m_CurrentTeletext.id >= 0)
2281 CLog::Log(LOGNOTICE, "OMXPlayer: closing teletext stream");
2282 CloseTeletextStream(!m_bAbortRequest);
2284 // destroy the demuxer
2287 CLog::Log(LOGNOTICE, "COMXPlayer::OnExit() deleting demuxer");
2292 if (m_pSubtitleDemuxer)
2294 CLog::Log(LOGNOTICE, "COMXPlayer::OnExit() deleting subtitle demuxer");
2295 delete m_pSubtitleDemuxer;
2297 m_pSubtitleDemuxer = NULL;
2299 // destroy the inputstream
2302 CLog::Log(LOGNOTICE, "COMXPlayer::OnExit() deleting input stream");
2303 delete m_pInputStream;
2305 m_pInputStream = NULL;
2307 // clean up all selection streams
2308 m_SelectionStreams.Clear(STREAM_NONE, STREAM_SOURCE_NONE);
2312 m_av_clock.OMXDeinitialize();
2317 CLog::Log(LOGERROR, "%s - Exception thrown when trying to close down player, memory leak will follow", __FUNCTION__);
2318 m_pInputStream = NULL;
2323 // if we didn't stop playing, advance to the next item in xbmc's playlist
2324 if(m_PlayerOptions.identify == false)
2326 if (m_bAbortRequest)
2327 m_callback.OnPlayBackStopped();
2329 m_callback.OnPlayBackEnded();
2332 // set event to inform openfile something went wrong in case openfile is still waiting for this event
2336 void COMXPlayer::HandleMessages()
2339 OMXStreamLock lock(this);
2341 while (m_messenger.Get(&pMsg, 0) == MSGQ_OK)
2346 if (pMsg->IsType(CDVDMsg::PLAYER_SEEK) && m_messenger.GetPacketCount(CDVDMsg::PLAYER_SEEK) == 0
2347 && m_messenger.GetPacketCount(CDVDMsg::PLAYER_SEEK_CHAPTER) == 0)
2349 CDVDMsgPlayerSeek &msg(*((CDVDMsgPlayerSeek*)pMsg));
2351 if (!m_State.canseek)
2357 if(!msg.GetTrickPlay())
2359 g_infoManager.SetDisplayAfterSeek(100000);
2362 SetCaching(CACHESTATE_FLUSH);
2364 double start = DVD_NOPTS_VALUE;
2366 int time = msg.GetRestore() ? (int)m_Edl.RestoreCutTime(msg.GetTime()) : msg.GetTime();
2368 // if input streams doesn't support seektime we must convert back to clock
2369 if(dynamic_cast<CDVDInputStream::ISeekTime*>(m_pInputStream) == NULL)
2370 time -= DVD_TIME_TO_MSEC(m_State.time_offset - m_offset_pts);
2372 CLog::Log(LOGDEBUG, "demuxer seek to: %d", time);
2373 if (m_pDemuxer && m_pDemuxer->SeekTime(time, msg.GetBackward(), &start))
2375 CLog::Log(LOGDEBUG, "demuxer seek to: %.0f, success", start);
2376 if(m_pSubtitleDemuxer)
2378 if(!m_pSubtitleDemuxer->SeekTime(time, msg.GetBackward()))
2379 CLog::Log(LOGDEBUG, "failed to seek subtitle demuxer: %d, success", time);
2381 // dts after successful seek
2382 if (m_StateInput.time_src == ETIMESOURCE_CLOCK && start == DVD_NOPTS_VALUE)
2383 m_StateInput.dts = DVD_MSEC_TO_TIME(time);
2385 m_StateInput.dts = start;
2387 FlushBuffers(!msg.GetFlush(), start, msg.GetAccurate());
2388 // mark mediatime as invalid
2389 m_av_clock.OMXMediaTime(0.0);
2390 m_last_check_time = 0.0;
2393 CLog::Log(LOGWARNING, "error while seeking");
2395 // set flag to indicate we have finished a seeking request
2396 if(!msg.GetTrickPlay())
2397 g_infoManager.SetDisplayAfterSeek();
2399 // dvd's will issue a HOP_CHANNEL that we need to skip
2400 if(m_pInputStream->IsStreamType(DVDSTREAM_TYPE_DVD))
2401 m_dvd.state = DVDSTATE_SEEK;
2403 else if (pMsg->IsType(CDVDMsg::PLAYER_SEEK_CHAPTER) && m_messenger.GetPacketCount(CDVDMsg::PLAYER_SEEK) == 0
2404 && m_messenger.GetPacketCount(CDVDMsg::PLAYER_SEEK_CHAPTER) == 0)
2406 g_infoManager.SetDisplayAfterSeek(100000);
2407 SetCaching(CACHESTATE_FLUSH);
2409 CDVDMsgPlayerSeekChapter &msg(*((CDVDMsgPlayerSeekChapter*)pMsg));
2410 double start = DVD_NOPTS_VALUE;
2412 // This should always be the case.
2413 if(m_pDemuxer && m_pDemuxer->SeekChapter(msg.GetChapter(), &start))
2415 FlushBuffers(false, start, true);
2416 // mark mediatime as invalid
2417 m_av_clock.OMXMediaTime(0.0);
2419 m_callback.OnPlayBackSeekChapter(msg.GetChapter());
2422 g_infoManager.SetDisplayAfterSeek();
2424 else if (pMsg->IsType(CDVDMsg::DEMUXER_RESET))
2426 m_CurrentAudio.stream = NULL;
2427 m_CurrentVideo.stream = NULL;
2428 m_CurrentSubtitle.stream = NULL;
2430 // we need to reset the demuxer, probably because the streams have changed
2432 m_pDemuxer->Reset();
2433 if(m_pSubtitleDemuxer)
2434 m_pSubtitleDemuxer->Reset();
2436 else if (pMsg->IsType(CDVDMsg::PLAYER_SET_AUDIOSTREAM))
2438 CDVDMsgPlayerSetAudioStream* pMsg2 = (CDVDMsgPlayerSetAudioStream*)pMsg;
2440 OMXSelectionStream& st = m_SelectionStreams.Get(STREAM_AUDIO, pMsg2->GetStreamId());
2441 if(st.source != STREAM_SOURCE_NONE)
2443 if(st.source == STREAM_SOURCE_NAV && m_pInputStream && m_pInputStream->IsStreamType(DVDSTREAM_TYPE_DVD))
2445 CDVDInputStreamNavigator* pStream = (CDVDInputStreamNavigator*)m_pInputStream;
2446 if(pStream->SetActiveAudioStream(st.id))
2448 m_dvd.iSelectedAudioStream = -1;
2449 CloseAudioStream(false);
2450 m_messenger.Put(new CDVDMsgPlayerSeek(GetTime(), true, true, true, true, true));
2455 CloseAudioStream(false);
2456 OpenAudioStream(st.id, st.source);
2457 AdaptForcedSubtitles();
2458 m_messenger.Put(new CDVDMsgPlayerSeek(GetTime(), true, true, true, true, true));
2462 else if (pMsg->IsType(CDVDMsg::PLAYER_SET_SUBTITLESTREAM))
2464 CDVDMsgPlayerSetSubtitleStream* pMsg2 = (CDVDMsgPlayerSetSubtitleStream*)pMsg;
2466 OMXSelectionStream& st = m_SelectionStreams.Get(STREAM_SUBTITLE, pMsg2->GetStreamId());
2467 if(st.source != STREAM_SOURCE_NONE)
2469 if(st.source == STREAM_SOURCE_NAV && m_pInputStream && m_pInputStream->IsStreamType(DVDSTREAM_TYPE_DVD))
2471 CDVDInputStreamNavigator* pStream = (CDVDInputStreamNavigator*)m_pInputStream;
2472 if(pStream->SetActiveSubtitleStream(st.id))
2474 m_dvd.iSelectedSPUStream = -1;
2475 CloseSubtitleStream(false);
2480 CloseSubtitleStream(false);
2481 OpenSubtitleStream(st.id, st.source);
2485 else if (pMsg->IsType(CDVDMsg::PLAYER_SET_SUBTITLESTREAM_VISIBLE))
2487 CDVDMsgBool* pValue = (CDVDMsgBool*)pMsg;
2488 SetSubtitleVisibleInternal(pValue->m_value);
2490 else if (pMsg->IsType(CDVDMsg::PLAYER_SET_STATE))
2492 g_infoManager.SetDisplayAfterSeek(100000);
2493 SetCaching(CACHESTATE_FLUSH);
2495 CDVDMsgPlayerSetState* pMsgPlayerSetState = (CDVDMsgPlayerSetState*)pMsg;
2497 if (CDVDInputStream::IMenus* ptr = dynamic_cast<CDVDInputStream::IMenus*>(m_pInputStream))
2499 if(ptr->SetState(pMsgPlayerSetState->GetState()))
2501 m_dvd.state = DVDSTATE_NORMAL;
2502 m_dvd.iDVDStillStartTime = 0;
2503 m_dvd.iDVDStillTime = 0;
2507 g_infoManager.SetDisplayAfterSeek();
2509 else if (pMsg->IsType(CDVDMsg::PLAYER_SET_RECORD))
2511 CDVDInputStream::IChannel* input = dynamic_cast<CDVDInputStream::IChannel*>(m_pInputStream);
2513 input->Record(*(CDVDMsgBool*)pMsg);
2515 else if (pMsg->IsType(CDVDMsg::GENERAL_FLUSH))
2517 FlushBuffers(false);
2519 else if (pMsg->IsType(CDVDMsg::PLAYER_SETSPEED))
2521 int speed = static_cast<CDVDMsgInt*>(pMsg)->m_value;
2523 // correct our current clock, as it would start going wrong otherwise
2524 if(m_State.timestamp > 0)
2527 offset = m_clock.GetAbsoluteClock() - m_State.timestamp;
2528 offset *= m_playSpeed / DVD_PLAYSPEED_NORMAL;
2529 if(offset > 1000) offset = 1000;
2530 if(offset < -1000) offset = -1000;
2531 m_State.time += DVD_TIME_TO_MSEC(offset);
2532 m_State.timestamp = m_clock.GetAbsoluteClock();
2535 if (speed != DVD_PLAYSPEED_PAUSE && m_playSpeed != DVD_PLAYSPEED_PAUSE && speed != m_playSpeed)
2536 m_callback.OnPlayBackSpeedChanged(speed / DVD_PLAYSPEED_NORMAL);
2538 if (m_pInputStream->IsStreamType(DVDSTREAM_TYPE_PVRMANAGER) && speed != m_playSpeed)
2540 CDVDInputStreamPVRManager* pvrinputstream = static_cast<CDVDInputStreamPVRManager*>(m_pInputStream);
2541 pvrinputstream->Pause( speed == 0 );
2544 // if playspeed is different then DVD_PLAYSPEED_NORMAL or DVD_PLAYSPEED_PAUSE
2545 // audioplayer, stops outputing audio to audiorender, but still tries to
2546 // sleep an correct amount for each packet
2547 // videoplayer just plays faster after the clock speed has been increased
2549 // 2. skip frames and adjust their pts or the clock
2551 // when switching from trickplay to normal, we may not have a full set of reference frames
2552 // in decoder and we may get corrupt frames out. Seeking to current time will avoid this.
2553 if ( TP(speed) || TP(m_playSpeed) ||
2554 ( (speed == DVD_PLAYSPEED_PAUSE || speed == DVD_PLAYSPEED_NORMAL) &&
2555 (m_playSpeed != DVD_PLAYSPEED_PAUSE && m_playSpeed != DVD_PLAYSPEED_NORMAL) ) )
2556 m_messenger.Put(new CDVDMsgPlayerSeek(GetTime(), (speed < 0), true, false, false, true));
2558 m_playSpeed = speed;
2559 m_caching = CACHESTATE_DONE;
2560 m_clock.SetSpeed(speed);
2561 m_av_clock.OMXSetSpeed(speed);
2562 m_av_clock.OMXPause();
2563 m_omxPlayerAudio.SetSpeed(speed);
2564 m_omxPlayerVideo.SetSpeed(speed);
2566 // We can't pause demuxer until our buffers are full. Doing so will result in continued
2567 // calls to Read() which may then block indefinitely (CDVDInputStreamRTMP for example).
2570 m_DemuxerPausePending = (speed == DVD_PLAYSPEED_PAUSE);
2571 if (!m_DemuxerPausePending)
2572 m_pDemuxer->SetSpeed(speed);
2574 CLog::Log(LOGDEBUG, "COMXPlayer - CDVDMsg::PLAYER_SETSPEED speed : %d", speed);
2576 else if (pMsg->IsType(CDVDMsg::PLAYER_CHANNEL_SELECT_NUMBER) && m_messenger.GetPacketCount(CDVDMsg::PLAYER_CHANNEL_SELECT_NUMBER) == 0)
2578 FlushBuffers(false);
2579 CDVDInputStream::IChannel* input = dynamic_cast<CDVDInputStream::IChannel*>(m_pInputStream);
2580 if(input && input->SelectChannelByNumber(static_cast<CDVDMsgInt*>(pMsg)->m_value))
2582 SAFE_DELETE(m_pDemuxer);
2585 CLog::Log(LOGWARNING, "%s - failed to switch channel. playback stopped", __FUNCTION__);
2586 CApplicationMessenger::Get().MediaStop(false);
2589 else if (pMsg->IsType(CDVDMsg::PLAYER_CHANNEL_SELECT) && m_messenger.GetPacketCount(CDVDMsg::PLAYER_CHANNEL_SELECT) == 0)
2591 FlushBuffers(false);
2592 CDVDInputStream::IChannel* input = dynamic_cast<CDVDInputStream::IChannel*>(m_pInputStream);
2593 if(input && input->SelectChannel(static_cast<CDVDMsgType <CPVRChannel> *>(pMsg)->m_value))
2595 SAFE_DELETE(m_pDemuxer);
2598 CLog::Log(LOGWARNING, "%s - failed to switch channel. playback stopped", __FUNCTION__);
2599 CApplicationMessenger::Get().MediaStop(false);
2602 else if (pMsg->IsType(CDVDMsg::PLAYER_CHANNEL_NEXT) || pMsg->IsType(CDVDMsg::PLAYER_CHANNEL_PREV))
2604 CDVDInputStream::IChannel* input = dynamic_cast<CDVDInputStream::IChannel*>(m_pInputStream);
2607 bool bSwitchSuccessful(false);
2608 bool bShowPreview(CSettings::Get().GetInt("pvrplayback.channelentrytimeout") > 0);
2612 g_infoManager.SetDisplayAfterSeek(100000);
2613 FlushBuffers(false);
2616 if(pMsg->IsType(CDVDMsg::PLAYER_CHANNEL_NEXT))
2617 bSwitchSuccessful = input->NextChannel(bShowPreview);
2619 bSwitchSuccessful = input->PrevChannel(bShowPreview);
2621 if(bSwitchSuccessful)
2625 UpdateApplication(0);
2626 m_ChannelEntryTimeOut.Set(CSettings::Get().GetInt("pvrplayback.channelentrytimeout"));
2630 m_ChannelEntryTimeOut.SetInfinite();
2631 SAFE_DELETE(m_pDemuxer);
2633 g_infoManager.SetDisplayAfterSeek();
2638 CLog::Log(LOGWARNING, "%s - failed to switch channel. playback stopped", __FUNCTION__);
2639 CApplicationMessenger::Get().MediaStop(false);
2643 else if (pMsg->IsType(CDVDMsg::GENERAL_GUI_ACTION))
2644 OnAction(((CDVDMsgType<CAction>*)pMsg)->m_value);
2645 else if (pMsg->IsType(CDVDMsg::PLAYER_STARTED))
2647 int player = ((CDVDMsgInt*)pMsg)->m_value;
2648 if(player == DVDPLAYER_AUDIO)
2649 m_CurrentAudio.started = true;
2650 if(player == DVDPLAYER_VIDEO)
2651 m_CurrentVideo.started = true;
2653 if ((player == DVDPLAYER_AUDIO || player == DVDPLAYER_VIDEO) &&
2654 (TPA(m_playSpeed) || !m_HasAudio || m_CurrentAudio.started) &&
2655 (!m_HasVideo || m_CurrentVideo.started))
2657 CLog::Log(LOGDEBUG, "COMXPlayer::HandleMessages - player started RESET");
2658 m_av_clock.OMXReset(m_HasVideo, m_playSpeed != DVD_PLAYSPEED_NORMAL && m_playSpeed != DVD_PLAYSPEED_PAUSE ? false:m_HasAudio);
2661 CLog::Log(LOGDEBUG, "COMXPlayer::HandleMessages - player started %d (tpa:%d,a:%d,v:%d)", player, TPA(m_playSpeed), m_CurrentAudio.started, m_CurrentVideo.started);
2663 else if (pMsg->IsType(CDVDMsg::PLAYER_DISPLAYTIME))
2665 COMXPlayer::SPlayerState& state = ((CDVDMsgType<COMXPlayer::SPlayerState>*)pMsg)->m_value;
2667 CSingleLock lock(m_StateSection);
2668 /* prioritize data from video player, but only accept data *
2669 * after it has been started to avoid race conditions after seeks */
2670 if(m_CurrentVideo.started && !m_omxPlayerVideo.SubmittedEOS())
2672 if(state.player == DVDPLAYER_VIDEO)
2675 else if(m_CurrentAudio.started)
2677 if(state.player == DVDPLAYER_AUDIO)
2684 CLog::Log(LOGERROR, "%s - Exception thrown when handling message", __FUNCTION__);
2692 void COMXPlayer::SetCaching(ECacheState state)
2694 if(state == CACHESTATE_FLUSH)
2696 double level, delay, offset;
2697 if(GetCachingTimes(level, delay, offset))
2698 state = CACHESTATE_FULL;
2700 state = CACHESTATE_INIT;
2703 if(m_caching == state)
2706 CLog::Log(LOGDEBUG, "COMXPlayer::SetCaching - caching state %d", state);
2707 if(state == CACHESTATE_FULL
2708 || state == CACHESTATE_INIT
2709 || state == CACHESTATE_PVR)
2711 m_clock.SetSpeed(DVD_PLAYSPEED_PAUSE);
2712 m_av_clock.OMXPause();
2713 m_omxPlayerAudio.SetSpeed(DVD_PLAYSPEED_PAUSE);
2714 m_omxPlayerAudio.SendMessage(new CDVDMsg(CDVDMsg::PLAYER_STARTED), 1);
2715 m_omxPlayerVideo.SetSpeed(DVD_PLAYSPEED_PAUSE);
2716 m_omxPlayerVideo.SendMessage(new CDVDMsg(CDVDMsg::PLAYER_STARTED), 1);
2718 if (state == CACHESTATE_PVR)
2719 m_pInputStream->ResetScanTimeout((unsigned int) CSettings::Get().GetInt("pvrplayback.scantime") * 1000);
2722 if(state == CACHESTATE_PLAY
2723 ||(state == CACHESTATE_DONE && m_caching != CACHESTATE_PLAY))
2725 m_clock.SetSpeed(m_playSpeed);
2726 m_omxPlayerAudio.SetSpeed(m_playSpeed);
2727 m_omxPlayerVideo.SetSpeed(m_playSpeed);
2728 m_pInputStream->ResetScanTimeout(0);
2733 void COMXPlayer::SetPlaySpeed(int speed)
2735 m_messenger.Put(new CDVDMsgInt(CDVDMsg::PLAYER_SETSPEED, speed));
2736 m_omxPlayerAudio.SetSpeed(speed);
2737 m_omxPlayerVideo.SetSpeed(speed);
2738 SynchronizeDemuxer(100);
2741 bool COMXPlayer::CanPause()
2743 CSingleLock lock(m_StateSection);
2744 return m_State.canpause;
2747 void COMXPlayer::Pause()
2749 CSingleLock lock(m_StateSection);
2750 if (!m_State.canpause)
2754 if(m_playSpeed != DVD_PLAYSPEED_PAUSE && (m_caching == CACHESTATE_FULL || m_caching == CACHESTATE_PVR))
2756 SetCaching(CACHESTATE_DONE);
2760 // return to normal speed if it was paused before, pause otherwise
2761 if (m_playSpeed == DVD_PLAYSPEED_PAUSE)
2763 SetPlaySpeed(DVD_PLAYSPEED_NORMAL);
2764 m_callback.OnPlayBackResumed();
2768 SetPlaySpeed(DVD_PLAYSPEED_PAUSE);
2769 m_callback.OnPlayBackPaused();
2773 bool COMXPlayer::IsPaused() const
2775 return m_playSpeed == DVD_PLAYSPEED_PAUSE || m_caching == CACHESTATE_FULL || m_caching == CACHESTATE_PVR;
2778 bool COMXPlayer::HasVideo() const
2783 bool COMXPlayer::HasAudio() const
2788 bool COMXPlayer::IsPassthrough() const
2790 return m_omxPlayerAudio.Passthrough();
2793 bool COMXPlayer::CanSeek()
2795 CSingleLock lock(m_StateSection);
2796 return m_State.canseek;
2799 void COMXPlayer::Seek(bool bPlus, bool bLargeStep, bool bChapterOverride)
2802 if( m_playSpeed == DVD_PLAYSPEED_PAUSE && bPlus && !bLargeStep)
2804 m_av_clock.OMXStep();
2808 if (!m_State.canseek)
2811 if (bLargeStep && bChapterOverride && GetChapter() > 0)
2815 SeekChapter(GetChapter() - 1);
2818 else if (GetChapter() < GetChapterCount())
2820 SeekChapter(GetChapter() + 1);
2826 if (g_advancedSettings.m_videoUseTimeSeeking && GetTotalTime() > 2000*g_advancedSettings.m_videoTimeSeekForwardBig)
2829 seek = bPlus ? g_advancedSettings.m_videoTimeSeekForwardBig : g_advancedSettings.m_videoTimeSeekBackwardBig;
2831 seek = bPlus ? g_advancedSettings.m_videoTimeSeekForward : g_advancedSettings.m_videoTimeSeekBackward;
2839 percent = bPlus ? g_advancedSettings.m_videoPercentSeekForwardBig : g_advancedSettings.m_videoPercentSeekBackwardBig;
2841 percent = bPlus ? g_advancedSettings.m_videoPercentSeekForward : g_advancedSettings.m_videoPercentSeekBackward;
2842 seek = (int64_t)(GetTotalTimeInMsec()*(GetPercentage()+percent)/100);
2845 bool restore = true;
2849 * Alter the standard seek position based on whether any commercial breaks have been
2850 * automatically skipped.
2852 const int clock = DVD_TIME_TO_MSEC(m_clock.GetClock());
2854 * If a large backwards seek occurs within 10 seconds of the end of the last automated
2855 * commercial skip, then seek back to the start of the commercial break under the assumption
2856 * it was flagged incorrectly. 10 seconds grace period is allowed in case the watcher has to
2857 * fumble around finding the remote. Only happens once per commercial break.
2859 * Small skip does not trigger this in case the start of the commercial break was in fact fine
2860 * but it skipped too far into the program. In that case small skip backwards behaves as normal.
2862 if (!bPlus && bLargeStep
2863 && m_EdlAutoSkipMarkers.seek_to_start
2864 && clock >= m_EdlAutoSkipMarkers.commbreak_end
2865 && clock <= m_EdlAutoSkipMarkers.commbreak_end + 10*1000) // Only if within 10 seconds of the end (in msec)
2867 CLog::Log(LOGDEBUG, "%s - Seeking back to start of commercial break [%s - %s] as large backwards skip activated within 10 seconds of the automatic commercial skip (only done once per break).",
2868 __FUNCTION__, CEdl::MillisecondsToTimeString(m_EdlAutoSkipMarkers.commbreak_start).c_str(),
2869 CEdl::MillisecondsToTimeString(m_EdlAutoSkipMarkers.commbreak_end).c_str());
2870 seek = m_EdlAutoSkipMarkers.commbreak_start;
2872 m_EdlAutoSkipMarkers.seek_to_start = false; // So this will only happen within the 10 second grace period once.
2875 * If big skip forward within the last "reverted" commercial break, seek to the end of the
2876 * commercial break under the assumption that the break was incorrectly flagged and playback has
2877 * now reached the actual start of the commercial break. Assume that the end is flagged more
2878 * correctly than the landing point for a standard big skip (ends seem to be flagged more
2879 * accurately than the start).
2881 else if (bPlus && bLargeStep
2882 && clock >= m_EdlAutoSkipMarkers.commbreak_start
2883 && clock <= m_EdlAutoSkipMarkers.commbreak_end)
2885 CLog::Log(LOGDEBUG, "%s - Seeking to end of previously skipped commercial break [%s - %s] as big forwards skip activated within the break.",
2886 __FUNCTION__, CEdl::MillisecondsToTimeString(m_EdlAutoSkipMarkers.commbreak_start).c_str(),
2887 CEdl::MillisecondsToTimeString(m_EdlAutoSkipMarkers.commbreak_end).c_str());
2888 seek = m_EdlAutoSkipMarkers.commbreak_end;
2893 int64_t time = GetTime();
2894 if(g_application.CurrentFileItem().IsStack()
2895 && (seek > GetTotalTimeInMsec() || seek < 0))
2897 g_application.SeekTime((seek - time) * 0.001 + g_application.GetTime());
2898 // warning, don't access any dvdplayer variables here as
2899 // the dvdplayer object may have been destroyed
2903 m_messenger.Put(new CDVDMsgPlayerSeek((int)seek, !bPlus, true, false, restore));
2904 SynchronizeDemuxer(100);
2905 if (seek < 0) seek = 0;
2906 m_callback.OnPlayBackSeek((int)seek, (int)(seek - time));
2909 bool COMXPlayer::SeekScene(bool bPlus)
2911 if (!m_Edl.HasSceneMarker())
2915 * There is a 5 second grace period applied when seeking for scenes backwards. If there is no
2916 * grace period applied it is impossible to go backwards past a scene marker.
2918 int64_t clock = GetTime();
2919 if (!bPlus && clock > 5 * 1000) // 5 seconds
2922 int64_t iScenemarker;
2923 if (m_Edl.GetNextSceneMarker(bPlus, clock, &iScenemarker))
2926 * Seeking is flushed and inaccurate, just like Seek()
2928 m_messenger.Put(new CDVDMsgPlayerSeek((int)iScenemarker, !bPlus, true, false, false));
2929 SynchronizeDemuxer(100);
2935 void COMXPlayer::GetAudioInfo(CStdString &strAudioInfo)
2937 { CSingleLock lock(m_StateSection);
2938 strAudioInfo = StringUtils::Format("D(%s)", m_StateInput.demux_audio.c_str());
2940 strAudioInfo += StringUtils::Format("\nP(%s)", m_omxPlayerAudio.GetPlayerInfo().c_str());
2943 void COMXPlayer::GetVideoInfo(CStdString &strVideoInfo)
2945 { CSingleLock lock(m_StateSection);
2946 strVideoInfo = StringUtils::Format("D(%s)", m_StateInput.demux_video.c_str());
2948 strVideoInfo += StringUtils::Format("\nP(%s)", m_omxPlayerVideo.GetPlayerInfo().c_str());
2951 void COMXPlayer::GetGeneralInfo(CStdString& strGeneralInfo)
2955 double apts = m_omxPlayerAudio.GetCurrentPts();
2956 double vpts = m_omxPlayerVideo.GetCurrentPts();
2959 if( apts != DVD_NOPTS_VALUE && vpts != DVD_NOPTS_VALUE )
2960 dDiff = (apts - vpts) / DVD_TIME_BASE;
2962 CStdString strEDL = StringUtils::Format(", edl:%s", m_Edl.GetInfo().c_str());
2965 CSingleLock lock(m_StateSection);
2966 if(m_StateInput.cache_bytes >= 0)
2968 strBuf += StringUtils::Format(" cache:%s %2.0f%%"
2969 , StringUtils::SizeToString(m_State.cache_bytes).c_str()
2970 , m_State.cache_level * 100);
2971 if(m_playSpeed == 0 || m_caching == CACHESTATE_FULL)
2972 strBuf += StringUtils::Format(" %d sec", DVD_TIME_TO_SEC(m_State.cache_delay));
2975 strGeneralInfo = StringUtils::Format("C( ad:% 6.3f a/v:% 6.3f%s, dcpu:%2i%% acpu:%2i%% vcpu:%2i%%%s af:%d%% vf:%d%% amp:% 5.2f )"
2976 , m_omxPlayerAudio.GetDelay()
2979 , (int)(CThread::GetRelativeUsage()*100)
2980 , (int)(m_omxPlayerAudio.GetRelativeUsage()*100)
2981 , (int)(m_omxPlayerVideo.GetRelativeUsage()*100)
2985 , m_omxPlayerAudio.GetDynamicRangeAmplification());
2990 void COMXPlayer::SeekPercentage(float iPercent)
2992 int64_t iTotalTime = GetTotalTimeInMsec();
2997 SeekTime((int64_t)(iTotalTime * iPercent / 100));
3000 float COMXPlayer::GetPercentage()
3002 int64_t iTotalTime = GetTotalTimeInMsec();
3007 return GetTime() * 100 / (float)iTotalTime;
3010 float COMXPlayer::GetCachePercentage()
3012 CSingleLock lock(m_StateSection);
3013 return m_StateInput.cache_offset * 100; // NOTE: Percentage returned is relative
3016 void COMXPlayer::SetAVDelay(float fValue)
3018 m_omxPlayerVideo.SetDelay(fValue * DVD_TIME_BASE);
3021 float COMXPlayer::GetAVDelay()
3023 return m_omxPlayerVideo.GetDelay() / (float)DVD_TIME_BASE;
3026 void COMXPlayer::SetSubTitleDelay(float fValue)
3028 m_omxPlayerVideo.SetSubtitleDelay(-fValue * DVD_TIME_BASE);
3031 float COMXPlayer::GetSubTitleDelay()
3033 return -m_omxPlayerVideo.GetSubtitleDelay() / DVD_TIME_BASE;
3036 // priority: 1: libdvdnav, 2: external subtitles, 3: muxed subtitles
3037 int COMXPlayer::GetSubtitleCount()
3039 return m_SelectionStreams.Count(STREAM_SUBTITLE);
3042 int COMXPlayer::GetSubtitle()
3044 return m_SelectionStreams.IndexOf(STREAM_SUBTITLE, *this);
3047 void COMXPlayer::GetSubtitleStreamInfo(int index, SPlayerSubtitleStreamInfo &info)
3049 if (index < 0 || index > (int) GetSubtitleCount() - 1)
3052 OMXSelectionStream& s = m_SelectionStreams.Get(STREAM_SUBTITLE, index);
3053 if(s.name.length() > 0)
3056 if(s.type == STREAM_NONE)
3057 info.name += "(Invalid)";
3059 info.language = s.language;
3062 void COMXPlayer::SetSubtitle(int iStream)
3064 CMediaSettings::Get().GetCurrentVideoSettings().m_SubtitleStream = iStream;
3065 m_messenger.Put(new CDVDMsgPlayerSetSubtitleStream(iStream));
3068 bool COMXPlayer::GetSubtitleVisible()
3070 if (m_pInputStream && m_pInputStream->IsStreamType(DVDSTREAM_TYPE_DVD))
3072 CDVDInputStreamNavigator* pStream = (CDVDInputStreamNavigator*)m_pInputStream;
3073 if(pStream->IsInMenu())
3074 return CMediaSettings::Get().GetCurrentVideoSettings().m_SubtitleOn;
3076 return pStream->IsSubtitleStreamEnabled();
3079 return m_omxPlayerVideo.IsSubtitleEnabled();
3082 void COMXPlayer::SetSubtitleVisible(bool bVisible)
3084 CMediaSettings::Get().GetCurrentVideoSettings().m_SubtitleOn = bVisible;
3085 m_messenger.Put(new CDVDMsgBool(CDVDMsg::PLAYER_SET_SUBTITLESTREAM_VISIBLE, bVisible));
3088 void COMXPlayer::SetSubtitleVisibleInternal(bool bVisible)
3090 CMediaSettings::Get().GetCurrentVideoSettings().m_SubtitleOn = bVisible;
3091 m_omxPlayerVideo.EnableSubtitle(bVisible);
3093 if (m_pInputStream && m_pInputStream->IsStreamType(DVDSTREAM_TYPE_DVD))
3094 static_cast<CDVDInputStreamNavigator*>(m_pInputStream)->EnableSubtitleStream(bVisible);
3097 int COMXPlayer::GetAudioStreamCount()
3099 return m_SelectionStreams.Count(STREAM_AUDIO);
3102 int COMXPlayer::GetAudioStream()
3104 return m_SelectionStreams.IndexOf(STREAM_AUDIO, *this);
3107 void COMXPlayer::SetAudioStream(int iStream)
3109 CMediaSettings::Get().GetCurrentVideoSettings().m_AudioStream = iStream;
3110 m_messenger.Put(new CDVDMsgPlayerSetAudioStream(iStream));
3111 SynchronizeDemuxer(100);
3114 TextCacheStruct_t* COMXPlayer::GetTeletextCache()
3116 if (m_CurrentTeletext.id < 0)
3119 return m_dvdPlayerTeletext.GetTeletextCache();
3122 void COMXPlayer::LoadPage(int p, int sp, unsigned char* buffer)
3124 if (m_CurrentTeletext.id < 0)
3127 return m_dvdPlayerTeletext.LoadPage(p, sp, buffer);
3130 void COMXPlayer::SeekTime(int64_t iTime)
3132 int seekOffset = (int)(iTime - GetTime());
3133 m_messenger.Put(new CDVDMsgPlayerSeek((int)iTime, true, true, true));
3134 SynchronizeDemuxer(100);
3135 m_callback.OnPlayBackSeek((int)iTime, seekOffset);
3138 // return the time in milliseconds
3139 int64_t COMXPlayer::GetTime()
3141 CSingleLock lock(m_StateSection);
3143 const double limit = DVD_MSEC_TO_TIME(200);
3144 if(m_State.timestamp > 0)
3146 offset = m_clock.GetAbsoluteClock() - m_State.timestamp;
3147 offset *= m_playSpeed / DVD_PLAYSPEED_NORMAL;
3148 if(offset > limit) offset = limit;
3149 if(offset < -limit) offset = -limit;
3151 //{CLog::Log(LOGINFO, "%s: time:%.2f stamp:%.2f dts:%d m:%d (p:%d,c:%d) =%llu", __func__, (double)m_State.time, (double)m_State.timestamp, (int)DVD_TIME_TO_MSEC(m_State.dts + m_offset_pts), (int)DVD_TIME_TO_MSEC(m_stamp), (int)m_playSpeed, (int)m_caching, llrint(m_State.time + DVD_TIME_TO_MSEC(offset)));}
3152 return llrint(m_State.time + DVD_TIME_TO_MSEC(offset));
3155 // return length in msec
3156 int64_t COMXPlayer::GetTotalTimeInMsec()
3158 CSingleLock lock(m_StateSection);
3159 return llrint(m_State.time_total);
3162 // return length in seconds.. this should be changed to return in milleseconds throughout xbmc
3163 int64_t COMXPlayer::GetTotalTime()
3165 return GetTotalTimeInMsec();
3168 void COMXPlayer::ToFFRW(int iSpeed)
3170 // can't rewind in menu as seeking isn't possible
3172 if (iSpeed < 0 && IsInMenu()) return;
3173 SetPlaySpeed(iSpeed * DVD_PLAYSPEED_NORMAL);
3176 bool COMXPlayer::OpenAudioStream(int iStream, int source, bool reset)
3178 CLog::Log(LOGNOTICE, "Opening audio stream: %i source: %i", iStream, source);
3182 CLog::Log(LOGWARNING, "Opening audio stream: no demuxer");
3186 CDemuxStream* pStream = m_pDemuxer->GetStream(iStream);
3187 if (!pStream || pStream->disabled)
3189 CLog::Log(LOGWARNING, "Opening audio stream: pStream=%p disabled=%d", pStream, pStream ? pStream->disabled:0);
3193 if( m_CurrentAudio.id < 0 && m_CurrentVideo.id >= 0 )
3195 // up until now we wheren't playing audio, but we did play video
3196 // this will change what is used to sync the dvdclock.
3197 // since the new audio data doesn't have to have any relation
3198 // to the current video data in the packet que, we have to
3199 // wait for it to empty
3201 // this happens if a new cell has audio data, but previous didn't
3202 // and both have video data
3204 SynchronizePlayers(SYNCSOURCE_AUDIO);
3207 CDVDStreamInfo hint(*pStream, true);
3209 if(m_CurrentAudio.id < 0
3210 || m_CurrentAudio.hint != hint)
3212 if(!m_omxPlayerAudio.OpenStream(hint))
3214 /* mark stream as disabled, to disallaw further attempts*/
3215 CLog::Log(LOGWARNING, "%s - Unsupported stream %d. Stream disabled.", __FUNCTION__, iStream);
3216 pStream->disabled = true;
3217 pStream->SetDiscard(AVDISCARD_ALL);
3222 m_omxPlayerAudio.SendMessage(new CDVDMsg(CDVDMsg::GENERAL_RESET));
3224 /* store information about stream */
3225 m_CurrentAudio.id = iStream;
3226 m_CurrentAudio.source = source;
3227 m_CurrentAudio.hint = hint;
3228 m_CurrentAudio.stream = (void*)pStream;
3229 m_CurrentAudio.started = false;
3232 /* we are potentially going to be waiting on this */
3233 m_omxPlayerAudio.SendMessage(new CDVDMsg(CDVDMsg::PLAYER_STARTED), 1);
3235 /* software decoding normaly consumes full cpu time so prio it */
3236 m_omxPlayerAudio.SetPriority(GetPriority()+1);
3237 CMediaSettings::Get().GetCurrentVideoSettings().m_AudioStream = GetAudioStream();
3241 bool COMXPlayer::OpenVideoStream(int iStream, int source, bool reset)
3243 CLog::Log(LOGNOTICE, "Opening video stream: %i source: %i", iStream, source);
3247 CLog::Log(LOGWARNING, "Opening video stream: no demuxer");
3251 CDemuxStream* pStream = m_pDemuxer->GetStream(iStream);
3252 if(!pStream || pStream->disabled)
3254 CLog::Log(LOGWARNING, "Opening video stream: pStream=%p disabled=%d", pStream, pStream ? pStream->disabled:0);
3257 pStream->SetDiscard(AVDISCARD_NONE);
3259 CDVDStreamInfo hint(*pStream, true);
3261 if( m_pInputStream && m_pInputStream->IsStreamType(DVDSTREAM_TYPE_DVD) )
3263 /* set aspect ratio as requested by navigator for dvd's */
3264 float aspect = static_cast<CDVDInputStreamNavigator*>(m_pInputStream)->GetVideoAspectRatio();
3267 hint.aspect = aspect;
3268 hint.forced_aspect = true;
3270 hint.software = true;
3273 boost::shared_ptr<CPVRClient> client;
3274 if(m_pInputStream && m_pInputStream->IsStreamType(DVDSTREAM_TYPE_PVRMANAGER) &&
3275 pStream->type == STREAM_VIDEO &&
3276 g_PVRClients->GetPlayingClient(client) && client->HandlesDemuxing())
3278 // set the fps in hints
3279 const CDemuxStreamVideo *stream = static_cast<const CDemuxStreamVideo*>(pStream);
3280 hint.fpsrate = stream->iFpsRate;
3281 hint.fpsscale = stream->iFpsScale;
3284 CDVDInputStream::IMenus* pMenus = dynamic_cast<CDVDInputStream::IMenus*>(m_pInputStream);
3285 if(pMenus && pMenus->IsInMenu())
3288 if (hint.stereo_mode.empty())
3289 hint.stereo_mode = CStereoscopicsManager::Get().DetectStereoModeByString(m_filename);
3291 if(m_CurrentVideo.id < 0
3292 || m_CurrentVideo.hint != hint)
3294 if (!m_omxPlayerVideo.OpenStream(hint))
3296 /* mark stream as disabled, to disallaw further attempts */
3297 CLog::Log(LOGWARNING, "%s - Unsupported stream %d. Stream disabled.", __FUNCTION__, iStream);
3298 pStream->disabled = true;
3299 pStream->SetDiscard(AVDISCARD_ALL);
3304 m_omxPlayerVideo.SendMessage(new CDVDMsg(CDVDMsg::GENERAL_RESET));
3306 /* store information about stream */
3307 m_CurrentVideo.id = iStream;
3308 m_CurrentVideo.source = source;
3309 m_CurrentVideo.hint = hint;
3310 m_CurrentVideo.stream = (void*)pStream;
3311 m_CurrentVideo.started = false;
3314 /* we are potentially going to be waiting on this */
3315 m_omxPlayerVideo.SendMessage(new CDVDMsg(CDVDMsg::PLAYER_STARTED), 1);
3317 /* use same priority for video thread as demuxing thread, as */
3318 /* otherwise demuxer will starve if video consumes the full cpu */
3319 m_omxPlayerVideo.SetPriority(GetPriority());
3324 bool COMXPlayer::OpenSubtitleStream(int iStream, int source)
3326 CLog::Log(LOGNOTICE, "Opening Subtitle stream: %i source: %i", iStream, source);
3328 CDemuxStream* pStream = NULL;
3329 std::string filename;
3330 CDVDStreamInfo hint;
3332 if(STREAM_SOURCE_MASK(source) == STREAM_SOURCE_DEMUX_SUB)
3334 int index = m_SelectionStreams.IndexOf(STREAM_SUBTITLE, source, iStream);
3337 OMXSelectionStream st = m_SelectionStreams.Get(STREAM_SUBTITLE, index);
3339 if(!m_pSubtitleDemuxer || m_pSubtitleDemuxer->GetFileName() != st.filename)
3341 CLog::Log(LOGNOTICE, "Opening Subtitle file: %s", st.filename.c_str());
3342 auto_ptr<CDVDDemuxVobsub> demux(new CDVDDemuxVobsub());
3343 if(!demux->Open(st.filename, st.filename2))
3345 m_pSubtitleDemuxer = demux.release();
3348 pStream = m_pSubtitleDemuxer->GetStream(iStream);
3349 if(!pStream || pStream->disabled)
3351 pStream->SetDiscard(AVDISCARD_NONE);
3352 double pts = m_omxPlayerVideo.GetCurrentPts();
3353 if(pts == DVD_NOPTS_VALUE)
3354 pts = m_CurrentVideo.dts;
3355 if(pts == DVD_NOPTS_VALUE)
3357 pts += m_offset_pts;
3358 m_pSubtitleDemuxer->SeekTime((int)(1000.0 * pts / (double)DVD_TIME_BASE));
3360 hint.Assign(*pStream, true);
3362 else if(STREAM_SOURCE_MASK(source) == STREAM_SOURCE_TEXT)
3364 int index = m_SelectionStreams.IndexOf(STREAM_SUBTITLE, source, iStream);
3367 filename = m_SelectionStreams.Get(STREAM_SUBTITLE, index).filename;
3370 hint.fpsscale = m_CurrentVideo.hint.fpsscale;
3371 hint.fpsrate = m_CurrentVideo.hint.fpsrate;
3377 pStream = m_pDemuxer->GetStream(iStream);
3378 if(!pStream || pStream->disabled)
3380 pStream->SetDiscard(AVDISCARD_NONE);
3382 hint.Assign(*pStream, true);
3384 if(m_pInputStream && m_pInputStream->IsStreamType(DVDSTREAM_TYPE_DVD))
3388 if(m_CurrentSubtitle.id < 0
3389 || m_CurrentSubtitle.hint != hint)
3391 if(m_CurrentSubtitle.id >= 0)
3393 CLog::Log(LOGDEBUG, " - codecs hints have changed, must close previous stream");
3394 CloseSubtitleStream(false);
3397 if(!m_dvdPlayerSubtitle.OpenStream(hint, filename))
3399 CLog::Log(LOGWARNING, "%s - Unsupported stream %d. Stream disabled.", __FUNCTION__, iStream);
3402 pStream->disabled = true;
3403 pStream->SetDiscard(AVDISCARD_ALL);
3409 m_dvdPlayerSubtitle.SendMessage(new CDVDMsg(CDVDMsg::GENERAL_RESET));
3411 m_CurrentSubtitle.id = iStream;
3412 m_CurrentSubtitle.source = source;
3413 m_CurrentSubtitle.hint = hint;
3414 m_CurrentSubtitle.stream = (void*)pStream;
3415 m_CurrentSubtitle.started = false;
3417 CMediaSettings::Get().GetCurrentVideoSettings().m_SubtitleStream = GetSubtitle();
3421 bool COMXPlayer::AdaptForcedSubtitles()
3424 OMXSelectionStream ss = m_SelectionStreams.Get(STREAM_SUBTITLE, GetSubtitle());
3425 if (ss.flags & CDemuxStream::FLAG_FORCED || !GetSubtitleVisible())
3427 OMXSelectionStream as = m_SelectionStreams.Get(STREAM_AUDIO, GetAudioStream());
3428 OMXSelectionStreams streams = m_SelectionStreams.Get(STREAM_SUBTITLE);
3430 for(OMXSelectionStreams::iterator it = streams.begin(); it != streams.end() && !valid; ++it)
3432 if (it->flags & CDemuxStream::FLAG_FORCED && g_LangCodeExpander.CompareLangCodes(it->language, as.language))
3434 if(OpenSubtitleStream(it->id, it->source))
3437 SetSubtitleVisibleInternal(true);
3443 CloseSubtitleStream(true);
3444 SetSubtitleVisibleInternal(false);
3450 bool COMXPlayer::OpenTeletextStream(int iStream, int source)
3455 CDemuxStream* pStream = m_pDemuxer->GetStream(iStream);
3456 if(!pStream || pStream->disabled)
3459 CDVDStreamInfo hint(*pStream, true);
3461 if (!m_dvdPlayerTeletext.CheckStream(hint))
3464 CLog::Log(LOGNOTICE, "Opening teletext stream: %i source: %i", iStream, source);
3466 if(m_CurrentTeletext.id < 0
3467 || m_CurrentTeletext.hint != hint)
3469 if(m_CurrentTeletext.id >= 0)
3471 CLog::Log(LOGDEBUG, " - teletext codecs hints have changed, must close previous stream");
3472 CloseTeletextStream(true);
3475 if (!m_dvdPlayerTeletext.OpenStream(hint))
3477 /* mark stream as disabled, to disallaw further attempts*/
3478 CLog::Log(LOGWARNING, "%s - Unsupported teletext stream %d. Stream disabled.", __FUNCTION__, iStream);
3479 pStream->disabled = true;
3480 pStream->SetDiscard(AVDISCARD_ALL);
3485 m_dvdPlayerTeletext.SendMessage(new CDVDMsg(CDVDMsg::GENERAL_RESET));
3487 /* store information about stream */
3488 m_CurrentTeletext.id = iStream;
3489 m_CurrentTeletext.source = source;
3490 m_CurrentTeletext.hint = hint;
3491 m_CurrentTeletext.stream = (void*)pStream;
3492 m_CurrentTeletext.started = false;
3497 bool COMXPlayer::CloseAudioStream(bool bWaitForBuffers)
3499 if (m_CurrentAudio.id < 0)
3502 CLog::Log(LOGNOTICE, "Closing audio stream");
3505 SetCaching(CACHESTATE_DONE);
3507 m_omxPlayerAudio.CloseStream(bWaitForBuffers);
3509 m_CurrentAudio.Clear();
3513 bool COMXPlayer::CloseVideoStream(bool bWaitForBuffers)
3515 if (m_CurrentVideo.id < 0)
3518 CLog::Log(LOGNOTICE, "Closing video stream");
3521 SetCaching(CACHESTATE_DONE);
3523 m_omxPlayerVideo.CloseStream(bWaitForBuffers);
3525 m_CurrentVideo.Clear();
3529 bool COMXPlayer::CloseSubtitleStream(bool bKeepOverlays)
3531 if (m_CurrentSubtitle.id < 0)
3534 CLog::Log(LOGNOTICE, "Closing subtitle stream");
3536 m_dvdPlayerSubtitle.CloseStream(!bKeepOverlays);
3538 m_CurrentSubtitle.Clear();
3542 bool COMXPlayer::CloseTeletextStream(bool bWaitForBuffers)
3544 if (m_CurrentTeletext.id < 0)
3547 CLog::Log(LOGNOTICE, "Closing teletext stream");
3550 SetCaching(CACHESTATE_DONE);
3552 m_dvdPlayerTeletext.CloseStream(bWaitForBuffers);
3554 m_CurrentTeletext.Clear();
3558 void COMXPlayer::FlushBuffers(bool queued, double pts, bool accurate)
3562 CLog::Log(LOGNOTICE, "FlushBuffers: q:%d pts:%.0f a:%d", queued, pts, accurate);
3564 if (!TP(m_playSpeed))
3565 m_av_clock.OMXStop();
3566 m_av_clock.OMXPause();
3569 /* for now, ignore accurate flag as it discards keyframes and causes corrupt frames */
3573 startpts = DVD_NOPTS_VALUE;
3575 /* call with demuxer pts */
3576 if(startpts != DVD_NOPTS_VALUE)
3577 startpts -= m_offset_pts;
3579 m_CurrentAudio.inited = false;
3580 m_CurrentAudio.dts = DVD_NOPTS_VALUE;
3581 m_CurrentAudio.startpts = startpts;
3583 m_CurrentVideo.inited = false;
3584 m_CurrentVideo.dts = DVD_NOPTS_VALUE;
3585 m_CurrentVideo.startpts = startpts;
3587 m_CurrentSubtitle.inited = false;
3588 m_CurrentSubtitle.dts = DVD_NOPTS_VALUE;
3589 m_CurrentSubtitle.startpts = startpts;
3591 m_CurrentTeletext.inited = false;
3592 m_CurrentTeletext.dts = DVD_NOPTS_VALUE;
3593 m_CurrentTeletext.startpts = startpts;
3597 m_omxPlayerAudio.SendMessage(new CDVDMsg(CDVDMsg::GENERAL_RESET));
3598 m_omxPlayerVideo.SendMessage(new CDVDMsg(CDVDMsg::GENERAL_RESET));
3599 m_omxPlayerVideo.SendMessage(new CDVDMsg(CDVDMsg::VIDEO_NOSKIP));
3600 m_dvdPlayerSubtitle.SendMessage(new CDVDMsg(CDVDMsg::GENERAL_RESET));
3601 m_dvdPlayerTeletext.SendMessage(new CDVDMsg(CDVDMsg::GENERAL_RESET));
3602 SynchronizePlayers(SYNCSOURCE_ALL);
3606 m_omxPlayerAudio.Flush();
3607 m_omxPlayerVideo.Flush();
3608 m_dvdPlayerSubtitle.Flush();
3609 m_dvdPlayerTeletext.Flush();
3611 // clear subtitle and menu overlays
3612 m_overlayContainer.Clear();
3614 if(m_playSpeed == DVD_PLAYSPEED_NORMAL
3615 || m_playSpeed == DVD_PLAYSPEED_PAUSE)
3617 // make sure players are properly flushed, should put them in stalled state
3618 CDVDMsgGeneralSynchronize* msg = new CDVDMsgGeneralSynchronize(1000, 0);
3619 m_omxPlayerAudio.SendMessage(msg->Acquire(), 1);
3620 m_omxPlayerVideo.SendMessage(msg->Acquire(), 1);
3621 msg->Wait(&m_bStop, 0);
3624 // purge any pending PLAYER_STARTED messages
3625 m_messenger.Flush(CDVDMsg::PLAYER_STARTED);
3627 // we should now wait for init cache
3628 SetCaching(CACHESTATE_FLUSH);
3629 m_CurrentAudio.started = false;
3630 m_CurrentVideo.started = false;
3631 m_CurrentSubtitle.started = false;
3632 m_CurrentTeletext.started = false;
3635 if(pts != DVD_NOPTS_VALUE)
3636 m_clock.Discontinuity(pts);
3639 // update state, buffers are flushed and it may take some time until
3640 // we get an update from players
3641 CSingleLock lock(m_StateSection);
3642 m_State = m_StateInput;
3646 // since we call ffmpeg functions to decode, this is being called in the same thread as ::Process() is
3647 int COMXPlayer::OnDVDNavResult(void* pData, int iMessage)
3649 if (m_pInputStream->IsStreamType(DVDSTREAM_TYPE_BLURAY))
3652 m_overlayContainer.Add((CDVDOverlay*)pData);
3653 else if(iMessage == 1)
3654 m_messenger.Put(new CDVDMsg(CDVDMsg::GENERAL_FLUSH));
3655 else if(iMessage == 2)
3656 m_dvd.iSelectedAudioStream = *(int*)pData;
3657 else if(iMessage == 3)
3658 m_dvd.iSelectedSPUStream = *(int*)pData;
3659 else if(iMessage == 4)
3660 m_omxPlayerVideo.EnableSubtitle(*(int*)pData ? true: false);
3661 else if(iMessage == 5)
3663 if (m_dvd.state != DVDSTATE_STILL)
3665 // else notify the player we have received a still frame
3667 m_dvd.iDVDStillTime = *(int*)pData;
3668 m_dvd.iDVDStillStartTime = XbmcThreads::SystemClockMillis();
3670 /* adjust for the output delay in the video queue */
3671 unsigned int time = 0;
3672 if( m_CurrentVideo.stream && m_dvd.iDVDStillTime > 0 )
3674 time = (unsigned int)(m_omxPlayerVideo.GetOutputDelay() / ( DVD_TIME_BASE / 1000 ));
3675 if( time < 10000 && time > 0 )
3676 m_dvd.iDVDStillTime += time;
3678 m_dvd.state = DVDSTATE_STILL;
3680 "DVDNAV_STILL_FRAME - waiting %i sec, with delay of %d sec",
3681 m_dvd.iDVDStillTime, time / 1000);
3688 if (m_pInputStream->IsStreamType(DVDSTREAM_TYPE_DVD))
3690 CDVDInputStreamNavigator* pStream = (CDVDInputStreamNavigator*)m_pInputStream;
3694 case DVDNAV_STILL_FRAME:
3696 //CLog::Log(LOGDEBUG, "DVDNAV_STILL_FRAME");
3698 dvdnav_still_event_t *still_event = (dvdnav_still_event_t *)pData;
3699 // should wait the specified time here while we let the player running
3700 // after that call dvdnav_still_skip(m_dvdnav);
3702 if (m_dvd.state != DVDSTATE_STILL)
3704 // else notify the player we have received a still frame
3706 if(still_event->length < 0xff)
3707 m_dvd.iDVDStillTime = still_event->length * 1000;
3709 m_dvd.iDVDStillTime = 0;
3711 m_dvd.iDVDStillStartTime = XbmcThreads::SystemClockMillis();
3713 /* adjust for the output delay in the video queue */
3714 unsigned int time = 0;
3715 if( m_CurrentVideo.stream && m_dvd.iDVDStillTime > 0 )
3717 time = (unsigned int)(m_omxPlayerVideo.GetOutputDelay() / ( DVD_TIME_BASE / 1000 ));
3718 if( time < 10000 && time > 0 )
3719 m_dvd.iDVDStillTime += time;
3721 m_dvd.state = DVDSTATE_STILL;
3723 "DVDNAV_STILL_FRAME - waiting %i sec, with delay of %d sec",
3724 still_event->length, time / 1000);
3726 return NAVRESULT_HOLD;
3729 case DVDNAV_SPU_CLUT_CHANGE:
3731 m_dvdPlayerSubtitle.SendMessage(new CDVDMsgSubtitleClutChange((uint8_t*)pData));
3734 case DVDNAV_SPU_STREAM_CHANGE:
3736 dvdnav_spu_stream_change_event_t* event = (dvdnav_spu_stream_change_event_t*)pData;
3738 int iStream = event->physical_wide;
3739 bool visible = !(iStream & 0x80);
3741 SetSubtitleVisibleInternal(visible);
3744 m_dvd.iSelectedSPUStream = (iStream & ~0x80);
3746 m_dvd.iSelectedSPUStream = -1;
3748 m_CurrentSubtitle.stream = NULL;
3751 case DVDNAV_AUDIO_STREAM_CHANGE:
3753 // This should be the correct way i think, however we don't have any streams right now
3754 // since the demuxer hasn't started so it doesn't change. not sure how to do this.
3755 dvdnav_audio_stream_change_event_t* event = (dvdnav_audio_stream_change_event_t*)pData;
3757 // Tell system what audiostream should be opened by default
3758 if (event->logical >= 0)
3759 m_dvd.iSelectedAudioStream = event->physical;
3761 m_dvd.iSelectedAudioStream = -1;
3763 m_CurrentAudio.stream = NULL;
3766 case DVDNAV_HIGHLIGHT:
3768 //dvdnav_highlight_event_t* pInfo = (dvdnav_highlight_event_t*)pData;
3769 int iButton = pStream->GetCurrentButton();
3770 CLog::Log(LOGDEBUG, "DVDNAV_HIGHLIGHT: Highlight button %d\n", iButton);
3771 m_dvdPlayerSubtitle.UpdateOverlayInfo((CDVDInputStreamNavigator*)m_pInputStream, LIBDVDNAV_BUTTON_NORMAL);
3774 case DVDNAV_VTS_CHANGE:
3776 //dvdnav_vts_change_event_t* vts_change_event = (dvdnav_vts_change_event_t*)pData;
3777 CLog::Log(LOGDEBUG, "DVDNAV_VTS_CHANGE");
3779 //Make sure we clear all the old overlays here, or else old forced items are left.
3780 m_overlayContainer.Clear();
3782 //Force an aspect ratio that is set in the dvdheaders if available
3783 m_CurrentVideo.hint.aspect = pStream->GetVideoAspectRatio();
3784 if( m_omxPlayerVideo.IsInited() )
3785 m_omxPlayerVideo.SendMessage(new CDVDMsgDouble(CDVDMsg::VIDEO_SET_ASPECT, m_CurrentVideo.hint.aspect));
3787 m_SelectionStreams.Clear(STREAM_NONE, STREAM_SOURCE_NAV);
3788 m_SelectionStreams.Update(m_pInputStream, m_pDemuxer);
3790 return NAVRESULT_HOLD;
3793 case DVDNAV_CELL_CHANGE:
3795 //dvdnav_cell_change_event_t* cell_change_event = (dvdnav_cell_change_event_t*)pData;
3796 CLog::Log(LOGDEBUG, "DVDNAV_CELL_CHANGE");
3798 m_dvd.state = DVDSTATE_NORMAL;
3800 if( m_omxPlayerVideo.IsInited() )
3801 m_omxPlayerVideo.SendMessage(new CDVDMsg(CDVDMsg::VIDEO_NOSKIP));
3804 case DVDNAV_NAV_PACKET:
3806 //pci_t* pci = (pci_t*)pData;
3808 // this should be possible to use to make sure we get
3809 // seamless transitions over these boundaries
3810 // if we remember the old vobunits boundaries
3811 // when a packet comes out of demuxer that has
3812 // pts values outside that boundary, it belongs
3813 // to the new vobunit, wich has new timestamps
3817 case DVDNAV_HOP_CHANNEL:
3819 // This event is issued whenever a non-seamless operation has been executed.
3820 // Applications with fifos should drop the fifos content to speed up responsiveness.
3821 CLog::Log(LOGDEBUG, "DVDNAV_HOP_CHANNEL");
3822 if(m_dvd.state == DVDSTATE_SEEK)
3823 m_dvd.state = DVDSTATE_NORMAL;
3825 m_messenger.Put(new CDVDMsg(CDVDMsg::GENERAL_FLUSH));
3827 return NAVRESULT_ERROR;
3832 CLog::Log(LOGDEBUG, "DVDNAV_STOP");
3833 m_dvd.state = DVDSTATE_NORMAL;
3841 return NAVRESULT_NOP;
3844 bool COMXPlayer::ShowPVRChannelInfo(void)
3846 bool bReturn(false);
3848 if (CSettings::Get().GetBool("pvrmenu.infoswitch"))
3850 int iTimeout = CSettings::Get().GetBool("pvrmenu.infotimeout") ? CSettings::Get().GetInt("pvrmenu.infotime") : 0;
3851 g_PVRManager.ShowPlayerInfo(iTimeout);
3859 bool COMXPlayer::OnAction(const CAction &action)
3861 #define THREAD_ACTION(action) \
3863 if (!IsCurrentThread()) { \
3864 m_messenger.Put(new CDVDMsgType<CAction>(CDVDMsg::GENERAL_GUI_ACTION, action)); \
3869 CDVDInputStream::IMenus* pMenus = dynamic_cast<CDVDInputStream::IMenus*>(m_pInputStream);
3872 if( m_dvd.state == DVDSTATE_STILL && m_dvd.iDVDStillTime != 0 && pMenus->GetTotalButtons() == 0 )
3874 switch(action.GetID())
3876 case ACTION_NEXT_ITEM:
3877 case ACTION_MOVE_RIGHT:
3878 case ACTION_MOVE_UP:
3879 case ACTION_SELECT_ITEM:
3881 THREAD_ACTION(action);
3882 /* this will force us out of the stillframe */
3883 CLog::Log(LOGDEBUG, "%s - User asked to exit stillframe", __FUNCTION__);
3884 m_dvd.iDVDStillStartTime = 0;
3885 m_dvd.iDVDStillTime = 1;
3892 switch (action.GetID())
3894 /* this code is disabled to allow switching playlist items (dvdimage "stacks") */
3896 case ACTION_PREV_ITEM: // SKIP-:
3898 THREAD_ACTION(action);
3899 CLog::Log(LOGDEBUG, " - pushed prev");
3900 pMenus->OnPrevious();
3901 g_infoManager.SetDisplayAfterSeek();
3905 case ACTION_NEXT_ITEM: // SKIP+:
3907 THREAD_ACTION(action);
3908 CLog::Log(LOGDEBUG, " - pushed next");
3910 g_infoManager.SetDisplayAfterSeek();
3915 case ACTION_SHOW_VIDEOMENU: // start button
3917 THREAD_ACTION(action);
3918 CLog::Log(LOGDEBUG, " - go to menu");
3920 if (m_playSpeed == DVD_PLAYSPEED_PAUSE)
3922 SetPlaySpeed(DVD_PLAYSPEED_NORMAL);
3923 m_callback.OnPlayBackResumed();
3925 // send a message to everyone that we've gone to the menu
3926 CGUIMessage msg(GUI_MSG_VIDEO_MENU_STARTED, 0, 0);
3927 g_windowManager.SendThreadMessage(msg);
3933 if (pMenus->IsInMenu())
3935 switch (action.GetID())
3937 case ACTION_NEXT_ITEM:
3938 THREAD_ACTION(action);
3939 CLog::Log(LOGDEBUG, " - pushed next in menu, stream will decide");
3941 g_infoManager.SetDisplayAfterSeek();
3943 case ACTION_PREV_ITEM:
3944 THREAD_ACTION(action);
3945 CLog::Log(LOGDEBUG, " - pushed prev in menu, stream will decide");
3946 pMenus->OnPrevious();
3947 g_infoManager.SetDisplayAfterSeek();
3949 case ACTION_PREVIOUS_MENU:
3950 case ACTION_NAV_BACK:
3952 THREAD_ACTION(action);
3953 CLog::Log(LOGDEBUG, " - menu back");
3957 case ACTION_MOVE_LEFT:
3959 THREAD_ACTION(action);
3960 CLog::Log(LOGDEBUG, " - move left");
3964 case ACTION_MOVE_RIGHT:
3966 THREAD_ACTION(action);
3967 CLog::Log(LOGDEBUG, " - move right");
3971 case ACTION_MOVE_UP:
3973 THREAD_ACTION(action);
3974 CLog::Log(LOGDEBUG, " - move up");
3978 case ACTION_MOVE_DOWN:
3980 THREAD_ACTION(action);
3981 CLog::Log(LOGDEBUG, " - move down");
3986 case ACTION_MOUSE_MOVE:
3987 case ACTION_MOUSE_LEFT_CLICK:
3990 g_renderManager.GetVideoRect(rs, rd);
3991 CPoint pt(action.GetAmount(), action.GetAmount(1));
3992 if (!rd.PtInRect(pt))
3993 return false; // out of bounds
3994 THREAD_ACTION(action);
3995 // convert to video coords...
3996 pt -= CPoint(rd.x1, rd.y1);
3997 pt.x *= rs.Width() / rd.Width();
3998 pt.y *= rs.Height() / rd.Height();
3999 pt += CPoint(rs.x1, rs.y1);
4000 if (action.GetID() == ACTION_MOUSE_LEFT_CLICK)
4001 return pMenus->OnMouseClick(pt);
4002 return pMenus->OnMouseMove(pt);
4005 case ACTION_SELECT_ITEM:
4007 THREAD_ACTION(action);
4008 CLog::Log(LOGDEBUG, " - button select");
4009 // show button pushed overlay
4010 if(m_pInputStream->IsStreamType(DVDSTREAM_TYPE_DVD))
4011 m_dvdPlayerSubtitle.UpdateOverlayInfo((CDVDInputStreamNavigator*)m_pInputStream, LIBDVDNAV_BUTTON_CLICKED);
4013 pMenus->ActivateButton();
4027 THREAD_ACTION(action);
4028 // Offset from key codes back to button number
4029 int button = action.GetID() - REMOTE_0;
4030 CLog::Log(LOGDEBUG, " - button pressed %d", button);
4031 pMenus->SelectButton(button);
4038 return true; // message is handled
4042 if (dynamic_cast<CDVDInputStream::IChannel*>(m_pInputStream))
4044 switch (action.GetID())
4046 case ACTION_MOVE_UP:
4047 case ACTION_NEXT_ITEM:
4048 case ACTION_CHANNEL_UP:
4049 m_messenger.Put(new CDVDMsg(CDVDMsg::PLAYER_CHANNEL_NEXT));
4050 g_infoManager.SetDisplayAfterSeek();
4051 ShowPVRChannelInfo();
4055 case ACTION_MOVE_DOWN:
4056 case ACTION_PREV_ITEM:
4057 case ACTION_CHANNEL_DOWN:
4058 m_messenger.Put(new CDVDMsg(CDVDMsg::PLAYER_CHANNEL_PREV));
4059 g_infoManager.SetDisplayAfterSeek();
4060 ShowPVRChannelInfo();
4064 case ACTION_CHANNEL_SWITCH:
4066 // Offset from key codes back to button number
4067 int channel = action.GetAmount();
4068 m_messenger.Put(new CDVDMsgInt(CDVDMsg::PLAYER_CHANNEL_SELECT_NUMBER, channel));
4069 g_infoManager.SetDisplayAfterSeek();
4070 ShowPVRChannelInfo();
4077 switch (action.GetID())
4079 case ACTION_NEXT_ITEM:
4080 if (GetChapter() > 0 && GetChapter() < GetChapterCount())
4082 m_messenger.Put(new CDVDMsgPlayerSeekChapter(GetChapter() + 1));
4083 g_infoManager.SetDisplayAfterSeek();
4088 case ACTION_PREV_ITEM:
4089 if (GetChapter() > 0)
4091 m_messenger.Put(new CDVDMsgPlayerSeekChapter(GetChapter() - 1));
4092 g_infoManager.SetDisplayAfterSeek();
4099 // return false to inform the caller we didn't handle the message
4103 bool COMXPlayer::IsInMenu() const
4105 CDVDInputStream::IMenus* pStream = dynamic_cast<CDVDInputStream::IMenus*>(m_pInputStream);
4108 if( m_dvd.state == DVDSTATE_STILL )
4111 return pStream->IsInMenu();
4116 bool COMXPlayer::HasMenu()
4118 CDVDInputStream::IMenus* pStream = dynamic_cast<CDVDInputStream::IMenus*>(m_pInputStream);
4125 CStdString COMXPlayer::GetPlayerState()
4127 CSingleLock lock(m_StateSection);
4128 return m_State.player_state;
4131 bool COMXPlayer::SetPlayerState(CStdString state)
4133 m_messenger.Put(new CDVDMsgPlayerSetState(state));
4137 int COMXPlayer::GetChapterCount()
4139 CSingleLock lock(m_StateSection);
4140 return m_State.chapter_count;
4143 int COMXPlayer::GetChapter()
4145 CSingleLock lock(m_StateSection);
4146 return m_State.chapter;
4149 void COMXPlayer::GetChapterName(CStdString& strChapterName)
4151 CSingleLock lock(m_StateSection);
4152 strChapterName = m_State.chapter_name;
4155 int COMXPlayer::SeekChapter(int iChapter)
4157 if (GetChapter() > 0)
4161 if (iChapter > GetChapterCount())
4164 // Seek to the chapter.
4165 m_messenger.Put(new CDVDMsgPlayerSeekChapter(iChapter));
4166 SynchronizeDemuxer(100);
4172 int COMXPlayer::AddSubtitle(const CStdString& strSubPath)
4174 return AddSubtitleFile(strSubPath);
4177 int COMXPlayer::GetCacheLevel() const
4179 CSingleLock lock(m_StateSection);
4180 return (int)(m_StateInput.cache_level * 100);
4183 double COMXPlayer::GetQueueTime()
4185 int a = m_omxPlayerAudio.GetLevel();
4186 int v = m_omxPlayerVideo.GetLevel();
4187 return max(a, v) * 8000.0 / 100;
4190 void COMXPlayer::GetVideoStreamInfo(SPlayerVideoStreamInfo &info)
4192 info.bitrate = m_omxPlayerVideo.GetVideoBitrate();
4195 if (m_pDemuxer && (m_CurrentVideo.id != -1))
4197 m_pDemuxer->GetStreamCodecName(m_CurrentVideo.id, retVal);
4198 CDemuxStreamVideo* stream = static_cast<CDemuxStreamVideo*>(m_pDemuxer->GetStream(m_CurrentVideo.id));
4201 info.width = stream->iWidth;
4202 info.height = stream->iHeight;
4205 info.videoCodecName = retVal;
4206 info.videoAspectRatio = g_renderManager.GetAspectRatio();
4207 g_renderManager.GetVideoRect(info.SrcRect, info.DestRect);
4208 info.stereoMode = m_omxPlayerVideo.GetStereoMode();
4209 if (info.stereoMode == "mono")
4210 info.stereoMode = "";
4213 int COMXPlayer::GetSourceBitrate()
4216 return (int)m_pInputStream->GetBitstreamStats().GetBitrate();
4221 void COMXPlayer::GetAudioStreamInfo(int index, SPlayerAudioStreamInfo &info)
4223 if (index < 0 || index > GetAudioStreamCount() - 1)
4226 if (index == GetAudioStream())
4227 info.bitrate = m_omxPlayerAudio.GetAudioBitrate();
4228 else if (m_pDemuxer)
4230 CDemuxStreamAudio* stream = m_pDemuxer->GetStreamFromAudioId(index);
4232 info.bitrate = stream->iBitRate;
4235 OMXSelectionStream& s = m_SelectionStreams.Get(STREAM_AUDIO, index);
4236 if(s.language.length() > 0)
4237 info.language = s.language;
4239 if(s.name.length() > 0)
4242 if(s.type == STREAM_NONE)
4243 info.name += " (Invalid)";
4247 CDemuxStreamAudio* stream = static_cast<CDemuxStreamAudio*>(m_pDemuxer->GetStreamFromAudioId(index));
4250 info.channels = stream->iChannels;
4251 CStdString codecName;
4252 m_pDemuxer->GetStreamCodecName(stream->iId, codecName);
4253 info.audioCodecName = codecName;
4258 int COMXPlayer::AddSubtitleFile(const std::string& filename, const std::string& subfilename, CDemuxStream::EFlags flags)
4260 std::string ext = URIUtils::GetExtension(filename);
4261 std::string vobsubfile = subfilename;
4264 if (vobsubfile.empty())
4265 vobsubfile = URIUtils::ReplaceExtension(filename, ".sub");
4268 if(!v.Open(filename, vobsubfile))
4270 m_SelectionStreams.Update(NULL, &v);
4271 int index = m_SelectionStreams.IndexOf(STREAM_SUBTITLE, m_SelectionStreams.Source(STREAM_SOURCE_DEMUX_SUB, filename), 0);
4272 m_SelectionStreams.Get(STREAM_SUBTITLE, index).flags = flags;
4273 m_SelectionStreams.Get(STREAM_SUBTITLE, index).filename2 = vobsubfile;
4274 ExternalStreamInfo info;
4275 CUtil::GetExternalStreamDetailsFromFilename(m_filename, vobsubfile, info);
4276 m_SelectionStreams.Get(STREAM_SUBTITLE, index).name = info.name;
4277 if (m_SelectionStreams.Get(STREAM_SUBTITLE, index).language.empty())
4278 m_SelectionStreams.Get(STREAM_SUBTITLE, index).language = info.language;
4280 if (static_cast<CDemuxStream::EFlags>(info.flag) == CDemuxStream::FLAG_NONE)
4281 m_SelectionStreams.Get(STREAM_SUBTITLE, index).flags = flags;
4283 m_SelectionStreams.Get(STREAM_SUBTITLE, index).flags = static_cast<CDemuxStream::EFlags>(info.flag);
4289 CStdString strReplace(URIUtils::ReplaceExtension(filename,".idx"));
4290 if (XFILE::CFile::Exists(strReplace))
4293 OMXSelectionStream s;
4294 s.source = m_SelectionStreams.Source(STREAM_SOURCE_TEXT, filename);
4295 s.type = STREAM_SUBTITLE;
4297 s.filename = filename;
4298 ExternalStreamInfo info;
4299 CUtil::GetExternalStreamDetailsFromFilename(m_filename, filename, info);
4301 s.language = info.language;
4302 if (static_cast<CDemuxStream::EFlags>(info.flag) == CDemuxStream::FLAG_NONE)
4305 s.flags = static_cast<CDemuxStream::EFlags>(info.flag);
4307 m_SelectionStreams.Update(s);
4308 return m_SelectionStreams.IndexOf(STREAM_SUBTITLE, s.source, s.id);
4311 void COMXPlayer::UpdatePlayState(double timeout)
4313 if(m_StateInput.timestamp != 0
4314 && m_StateInput.timestamp + DVD_MSEC_TO_TIME(timeout) > m_clock.GetAbsoluteClock())
4317 SPlayerState state(m_StateInput);
4319 if (m_CurrentVideo.dts != DVD_NOPTS_VALUE)
4320 state.dts = m_CurrentVideo.dts;
4321 else if(m_CurrentAudio.dts != DVD_NOPTS_VALUE)
4322 state.dts = m_CurrentAudio.dts;
4326 state.chapter = m_pDemuxer->GetChapter();
4327 state.chapter_count = m_pDemuxer->GetChapterCount();
4328 m_pDemuxer->GetChapterName(state.chapter_name);
4330 if(state.dts == DVD_NOPTS_VALUE)
4333 state.time = DVD_TIME_TO_MSEC(state.dts + m_offset_pts);
4334 state.time_total = m_pDemuxer->GetStreamLength();
4335 state.time_src = ETIMESOURCE_CLOCK;
4338 state.canpause = true;
4339 state.canseek = true;
4343 // override from input stream if needed
4344 CDVDInputStream::IChannel* pChannel = dynamic_cast<CDVDInputStream::IChannel*>(m_pInputStream);
4347 state.canrecord = pChannel->CanRecord();
4348 state.recording = pChannel->IsRecording();
4351 CDVDInputStream::IDisplayTime* pDisplayTime = dynamic_cast<CDVDInputStream::IDisplayTime*>(m_pInputStream);
4352 if (pDisplayTime && pDisplayTime->GetTotalTime() > 0)
4354 state.time = pDisplayTime->GetTime();
4355 state.time_total = pDisplayTime->GetTotalTime();
4356 state.time_src = ETIMESOURCE_INPUT;
4359 if (CDVDInputStream::IMenus* ptr = dynamic_cast<CDVDInputStream::IMenus*>(m_pInputStream))
4361 if(!ptr->GetState(state.player_state))
4362 state.player_state = "";
4364 if(m_dvd.state == DVDSTATE_STILL)
4366 state.time = XbmcThreads::SystemClockMillis() - m_dvd.iDVDStillStartTime;
4367 state.time_total = m_dvd.iDVDStillTime;
4368 state.time_src = ETIMESOURCE_MENU;
4372 if (CDVDInputStream::ISeekable* ptr = dynamic_cast<CDVDInputStream::ISeekable*>(m_pInputStream))
4374 state.canpause = ptr->CanPause();
4375 state.canseek = ptr->CanSeek();
4381 state.time = m_Edl.RemoveCutTime(llrint(state.time));
4382 state.time_total = m_Edl.RemoveCutTime(llrint(state.time_total));
4385 if(state.time_total <= 0)
4386 state.canseek = false;
4388 if (state.time_src == ETIMESOURCE_CLOCK)
4389 state.time_offset = m_offset_pts;
4390 else if (state.dts != DVD_NOPTS_VALUE)
4391 state.time_offset = DVD_MSEC_TO_TIME(state.time) - state.dts;
4393 if (m_CurrentAudio.id >= 0 && m_pDemuxer)
4395 CDemuxStream* pStream = m_pDemuxer->GetStream(m_CurrentAudio.id);
4396 if (pStream && pStream->type == STREAM_AUDIO)
4397 ((CDemuxStreamAudio*)pStream)->GetStreamInfo(state.demux_audio);
4400 state.demux_audio = "";
4402 if (m_CurrentVideo.id >= 0 && m_pDemuxer)
4404 CDemuxStream* pStream = m_pDemuxer->GetStream(m_CurrentVideo.id);
4405 if (pStream && pStream->type == STREAM_VIDEO)
4406 ((CDemuxStreamVideo*)pStream)->GetStreamInfo(state.demux_video);
4409 state.demux_video = "";
4411 double level, delay, offset;
4412 if(GetCachingTimes(level, delay, offset))
4414 state.cache_delay = max(0.0, delay);
4415 state.cache_level = max(0.0, min(1.0, level));
4416 state.cache_offset = offset;
4420 state.cache_delay = 0.0;
4421 state.cache_level = min(1.0, GetQueueTime() / 8000.0);
4422 state.cache_offset = GetQueueTime() / state.time_total;
4425 XFILE::SCacheStatus status;
4426 if(m_pInputStream && m_pInputStream->GetCacheStatus(&status))
4428 state.cache_bytes = status.forward;
4429 if(state.time_total)
4430 state.cache_bytes += m_pInputStream->GetLength() * GetQueueTime() / state.time_total;
4433 state.cache_bytes = 0;
4435 state.timestamp = m_clock.GetAbsoluteClock();
4436 //{CLog::Log(LOGINFO, "%s: time:%.2f stamp:%.2f dts:%d m:%d (p:%d,c:%d) =%llu", __func__, (double)state.time, (double)state.timestamp, (int)DVD_TIME_TO_MSEC(state.dts + m_offset_pts), (int)DVD_TIME_TO_MSEC(m_stamp), (int)m_playSpeed, (int)m_caching, llrint(state.time + DVD_TIME_TO_MSEC(offset)));}
4438 CSingleLock lock(m_StateSection);
4439 m_StateInput = state;
4442 void COMXPlayer::UpdateApplication(double timeout)
4444 if(m_UpdateApplication != 0
4445 && m_UpdateApplication + DVD_MSEC_TO_TIME(timeout) > m_clock.GetAbsoluteClock())
4448 CDVDInputStream::IChannel* pStream = dynamic_cast<CDVDInputStream::IChannel*>(m_pInputStream);
4451 CFileItem item(g_application.CurrentFileItem());
4452 if(pStream->UpdateItem(item))
4454 g_application.CurrentFileItem() = item;
4455 CApplicationMessenger::Get().SetCurrentItem(item);
4458 m_UpdateApplication = m_clock.GetAbsoluteClock();
4461 bool COMXPlayer::CanRecord()
4463 CSingleLock lock(m_StateSection);
4464 return m_State.canrecord;
4467 bool COMXPlayer::IsRecording()
4469 CSingleLock lock(m_StateSection);
4470 return m_State.recording;
4473 bool COMXPlayer::Record(bool bOnOff)
4475 if (m_pInputStream && (m_pInputStream->IsStreamType(DVDSTREAM_TYPE_TV) ||
4476 m_pInputStream->IsStreamType(DVDSTREAM_TYPE_PVRMANAGER)) )
4478 m_messenger.Put(new CDVDMsgBool(CDVDMsg::PLAYER_SET_RECORD, bOnOff));
4484 bool COMXPlayer::GetStreamDetails(CStreamDetails &details)
4488 std::vector<OMXSelectionStream> subs = m_SelectionStreams.Get(STREAM_SUBTITLE);
4489 std::vector<CStreamDetailSubtitle> extSubDetails;
4490 for (unsigned int i = 0; i < subs.size(); i++)
4492 if (subs[i].filename == m_filename)
4495 CStreamDetailSubtitle p;
4496 p.m_strLanguage = subs[i].language;
4497 extSubDetails.push_back(p);
4500 bool result = CDVDFileInfo::DemuxerToStreamDetails(m_pInputStream, m_pDemuxer, extSubDetails, details);
4501 if (result && details.GetStreamCount(CStreamDetail::VIDEO) > 0) // this is more correct (dvds in particular)
4504 * We can only obtain the aspect & duration from dvdplayer when the Process() thread is running
4505 * and UpdatePlayState() has been called at least once. In this case dvdplayer duration/AR will
4506 * return 0 and we'll have to fallback to the (less accurate) info from the demuxer.
4508 float aspect = m_omxPlayerVideo.GetAspectRatio();
4510 ((CStreamDetailVideo*)details.GetNthStream(CStreamDetail::VIDEO,0))->m_fAspect = aspect;
4512 int64_t duration = GetTotalTime() / 1000;
4514 ((CStreamDetailVideo*)details.GetNthStream(CStreamDetail::VIDEO,0))->m_iDuration = duration;
4522 CStdString COMXPlayer::GetPlayingTitle()
4524 /* Currently we support only Title Name from Teletext line 30 */
4525 TextCacheStruct_t* ttcache = m_dvdPlayerTeletext.GetTeletextCache();
4526 if (ttcache && !ttcache->line30.empty())
4527 return ttcache->line30;
4532 bool COMXPlayer::SwitchChannel(const CPVRChannel &channel)
4534 if (!g_PVRManager.CheckParentalLock(channel))
4538 if (!g_PVRManager.PerformChannelSwitch(channel, true))
4541 UpdateApplication(0);
4544 /* make sure the pvr window is updated */
4545 CGUIWindowPVR *pWindow = (CGUIWindowPVR *) g_windowManager.GetWindow(WINDOW_PVR);
4547 pWindow->SetInvalid();
4549 /* select the new channel */
4550 m_messenger.Put(new CDVDMsgType<CPVRChannel>(CDVDMsg::PLAYER_CHANNEL_SELECT, channel));
4555 bool COMXPlayer::CachePVRStream(void) const
4557 return m_pInputStream->IsStreamType(DVDSTREAM_TYPE_PVRMANAGER) &&
4558 !g_PVRManager.IsPlayingRecording() &&
4559 g_advancedSettings.m_bPVRCacheInDvdPlayer;
4562 void COMXPlayer::GetRenderFeatures(std::vector<int> &renderFeatures)
4564 renderFeatures.push_back(RENDERFEATURE_STRETCH);
4565 renderFeatures.push_back(RENDERFEATURE_CROP);
4566 renderFeatures.push_back(RENDERFEATURE_PIXEL_RATIO);
4567 renderFeatures.push_back(RENDERFEATURE_ZOOM);
4570 void COMXPlayer::GetDeinterlaceMethods(std::vector<int> &deinterlaceMethods)
4572 deinterlaceMethods.push_back(VS_INTERLACEMETHOD_DEINTERLACE);
4575 void COMXPlayer::GetDeinterlaceModes(std::vector<int> &deinterlaceModes)
4577 deinterlaceModes.push_back(VS_DEINTERLACEMODE_AUTO);
4578 deinterlaceModes.push_back(VS_DEINTERLACEMODE_OFF);
4579 deinterlaceModes.push_back(VS_DEINTERLACEMODE_FORCE);
4582 void COMXPlayer::GetScalingMethods(std::vector<int> &scalingMethods)
4586 void COMXPlayer::GetAudioCapabilities(std::vector<int> &audioCaps)
4588 audioCaps.push_back(IPC_AUD_OFFSET);
4589 audioCaps.push_back(IPC_AUD_SELECT_STREAM);
4590 audioCaps.push_back(IPC_AUD_SELECT_OUTPUT);
4591 audioCaps.push_back(IPC_AUD_AMP);
4594 void COMXPlayer::GetSubtitleCapabilities(std::vector<int> &subCaps)
4596 subCaps.push_back(IPC_SUBS_ALL);