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;
186 /** \brief The class' operator() decides if the given (subtitle) SelectionStream is relevant wrt.
187 * preferred subtitle language and audio language. If the subtitle is relevant <B>false</B> false is returned.
189 * A subtitle is relevant if
190 * - it was previously selected, or
191 * - it's an external sub and "prefer external subs was selected", or
192 * - it's a forced sub and "original stream's language" was selected, or
193 * - it's a forced sub and its language matches the audio's language, or
194 * - it's a default sub, or
195 * - its language matches the preferred subtitle's language (unequal to "original stream's language")
197 PredicateSubtitleFilter(std::string& lang)
199 original(StringUtils::EqualsNoCase(CSettings::Get().GetString("locale.subtitlelanguage"), "original")),
200 preferexternal(CSettings::Get().GetBool("subtitles.preferexternal"))
204 bool operator()(const OMXSelectionStream& ss) const
206 if (ss.type_index == CMediaSettings::Get().GetCurrentVideoSettings().m_SubtitleStream)
211 if(ss.source == STREAM_SOURCE_DEMUX_SUB || ss.source == STREAM_SOURCE_TEXT)
215 if ((ss.flags & CDemuxStream::FLAG_FORCED) && (original || g_LangCodeExpander.CompareLangCodes(ss.language, audiolang)))
218 if ((ss.flags & CDemuxStream::FLAG_DEFAULT))
223 std::string subtitle_language = g_langInfo.GetSubtitleLanguage();
224 if (g_LangCodeExpander.CompareLangCodes(subtitle_language, ss.language))
232 static bool PredicateAudioPriority(const OMXSelectionStream& lh, const OMXSelectionStream& rh)
234 PREDICATE_RETURN(lh.type_index == CMediaSettings::Get().GetCurrentVideoSettings().m_AudioStream
235 , rh.type_index == CMediaSettings::Get().GetCurrentVideoSettings().m_AudioStream);
237 if(!StringUtils::EqualsNoCase(CSettings::Get().GetString("locale.audiolanguage"), "original"))
239 CStdString audio_language = g_langInfo.GetAudioLanguage();
240 PREDICATE_RETURN(g_LangCodeExpander.CompareLangCodes(audio_language, lh.language)
241 , g_LangCodeExpander.CompareLangCodes(audio_language, rh.language));
244 PREDICATE_RETURN(lh.flags & CDemuxStream::FLAG_DEFAULT
245 , rh.flags & CDemuxStream::FLAG_DEFAULT);
247 PREDICATE_RETURN(lh.channels
250 PREDICATE_RETURN(StreamUtils::GetCodecPriority(lh.codec)
251 , StreamUtils::GetCodecPriority(rh.codec));
255 /** \brief The class' operator() decides if the given (subtitle) SelectionStream lh is 'better than' the given (subtitle) SelectionStream rh.
256 * If lh is 'better than' rh the return value is true, false otherwise.
258 * A subtitle lh is 'better than' a subtitle rh (in evaluation order) if
259 * - lh was previously selected, or
260 * - lh is an external sub and "prefer external subs was selected" and rh not, or
261 * - lh is a forced sub and ("original stream's language" was selected or subtitles are off) and rh not, or
262 * - lh is an external sub and its language matches the preferred subtitle's language (unequal to "original stream's language") and rh not, or
263 * - lh is an external sub and rh not, or
264 * - lh is language matches the preferred subtitle's language (unequal to "original stream's language") and rh not, or
265 * - lh is a default sub and rh not
267 class PredicateSubtitlePriority
270 std::string audiolang;
275 PredicateSubtitlePriority(std::string& lang)
277 original(StringUtils::EqualsNoCase(CSettings::Get().GetString("locale.subtitlelanguage"), "original")),
278 preferextsubs(CSettings::Get().GetBool("subtitles.preferexternal")),
279 subson(CMediaSettings::Get().GetCurrentVideoSettings().m_SubtitleOn)
283 bool operator()(const OMXSelectionStream& lh, const OMXSelectionStream& rh) const
285 PREDICATE_RETURN(lh.type_index == CMediaSettings::Get().GetCurrentVideoSettings().m_SubtitleStream
286 , rh.type_index == CMediaSettings::Get().GetCurrentVideoSettings().m_SubtitleStream);
290 PREDICATE_RETURN(lh.source == STREAM_SOURCE_DEMUX_SUB
291 , rh.source == STREAM_SOURCE_DEMUX_SUB);
293 PREDICATE_RETURN(lh.source == STREAM_SOURCE_TEXT
294 , rh.source == STREAM_SOURCE_TEXT);
297 if(!subson || original)
299 PREDICATE_RETURN(lh.flags & CDemuxStream::FLAG_FORCED && g_LangCodeExpander.CompareLangCodes(lh.language, audiolang)
300 , rh.flags & CDemuxStream::FLAG_FORCED && g_LangCodeExpander.CompareLangCodes(rh.language, audiolang));
302 PREDICATE_RETURN(lh.flags & CDemuxStream::FLAG_FORCED
303 , rh.flags & CDemuxStream::FLAG_FORCED);
306 CStdString subtitle_language = g_langInfo.GetSubtitleLanguage();
309 PREDICATE_RETURN((lh.source == STREAM_SOURCE_DEMUX_SUB || lh.source == STREAM_SOURCE_TEXT) && g_LangCodeExpander.CompareLangCodes(subtitle_language, lh.language)
310 , (rh.source == STREAM_SOURCE_DEMUX_SUB || rh.source == STREAM_SOURCE_TEXT) && g_LangCodeExpander.CompareLangCodes(subtitle_language, rh.language));
313 PREDICATE_RETURN(lh.source == STREAM_SOURCE_DEMUX_SUB
314 , rh.source == STREAM_SOURCE_DEMUX_SUB);
316 PREDICATE_RETURN(lh.source == STREAM_SOURCE_TEXT
317 , rh.source == STREAM_SOURCE_TEXT);
321 PREDICATE_RETURN(g_LangCodeExpander.CompareLangCodes(subtitle_language, lh.language)
322 , g_LangCodeExpander.CompareLangCodes(subtitle_language, rh.language));
325 PREDICATE_RETURN(lh.flags & CDemuxStream::FLAG_DEFAULT
326 , rh.flags & CDemuxStream::FLAG_DEFAULT);
332 static bool PredicateVideoPriority(const OMXSelectionStream& lh, const OMXSelectionStream& rh)
334 PREDICATE_RETURN(lh.flags & CDemuxStream::FLAG_DEFAULT
335 , rh.flags & CDemuxStream::FLAG_DEFAULT);
339 bool COMXSelectionStreams::Get(StreamType type, CDemuxStream::EFlags flag, OMXSelectionStream& out)
341 CSingleLock lock(m_section);
342 for(int i=0;i<(int)m_Streams.size();i++)
344 if(m_Streams[i].type != type)
346 if((m_Streams[i].flags & flag) != flag)
354 int COMXSelectionStreams::IndexOf(StreamType type, int source, int id) const
356 CSingleLock lock(m_section);
358 for(int i=0;i<(int)m_Streams.size();i++)
360 if(type && m_Streams[i].type != type)
363 if(source && m_Streams[i].source != source)
367 if(m_Streams[i].id == id)
376 int COMXSelectionStreams::IndexOf(StreamType type, COMXPlayer& p) const
378 if (p.m_pInputStream && p.m_pInputStream->IsStreamType(DVDSTREAM_TYPE_DVD))
381 if(type == STREAM_AUDIO)
382 id = ((CDVDInputStreamNavigator*)p.m_pInputStream)->GetActiveAudioStream();
383 else if(type == STREAM_VIDEO)
384 id = p.m_CurrentVideo.id;
385 else if(type == STREAM_SUBTITLE)
386 id = ((CDVDInputStreamNavigator*)p.m_pInputStream)->GetActiveSubtitleStream();
388 return IndexOf(type, STREAM_SOURCE_NAV, id);
391 if(type == STREAM_AUDIO)
392 return IndexOf(type, p.m_CurrentAudio.source, p.m_CurrentAudio.id);
393 else if(type == STREAM_VIDEO)
394 return IndexOf(type, p.m_CurrentVideo.source, p.m_CurrentVideo.id);
395 else if(type == STREAM_SUBTITLE)
396 return IndexOf(type, p.m_CurrentSubtitle.source, p.m_CurrentSubtitle.id);
397 else if(type == STREAM_TELETEXT)
398 return IndexOf(type, p.m_CurrentTeletext.source, p.m_CurrentTeletext.id);
403 int COMXSelectionStreams::Source(StreamSource source, std::string filename)
405 CSingleLock lock(m_section);
406 int index = source - 1;
407 for(int i=0;i<(int)m_Streams.size();i++)
409 OMXSelectionStream &s = m_Streams[i];
410 if(STREAM_SOURCE_MASK(s.source) != source)
412 // if it already exists, return same
413 if(s.filename == filename)
422 void COMXSelectionStreams::Update(OMXSelectionStream& s)
424 CSingleLock lock(m_section);
425 int index = IndexOf(s.type, s.source, s.id);
428 OMXSelectionStream& o = Get(s.type, index);
429 s.type_index = o.type_index;
434 s.type_index = Count(s.type);
435 m_Streams.push_back(s);
439 void COMXSelectionStreams::Update(CDVDInputStream* input, CDVDDemux* demuxer)
441 if(input && input->IsStreamType(DVDSTREAM_TYPE_DVD))
443 CDVDInputStreamNavigator* nav = (CDVDInputStreamNavigator*)input;
444 string filename = nav->GetFileName();
445 int source = Source(STREAM_SOURCE_NAV, filename);
448 count = nav->GetAudioStreamCount();
449 for(int i=0;i<count;i++)
451 OMXSelectionStream s;
453 s.type = STREAM_AUDIO;
455 s.flags = CDemuxStream::FLAG_NONE;
456 s.filename = filename;
458 DVDNavStreamInfo info;
459 nav->GetAudioStreamInfo(i, info);
461 s.language = g_LangCodeExpander.ConvertToISO6392T(info.language);
462 s.channels = info.channels;
466 count = nav->GetSubTitleStreamCount();
467 for(int i=0;i<count;i++)
469 OMXSelectionStream s;
471 s.type = STREAM_SUBTITLE;
473 s.flags = CDemuxStream::FLAG_NONE;
474 s.filename = filename;
477 DVDNavStreamInfo info;
478 nav->GetSubtitleStreamInfo(i, info);
480 s.language = g_LangCodeExpander.ConvertToISO6392T(info.language);
486 string filename = demuxer->GetFileName();
487 int count = demuxer->GetNrOfStreams();
489 if(input) /* hack to know this is sub decoder */
490 source = Source(STREAM_SOURCE_DEMUX, filename);
492 source = Source(STREAM_SOURCE_DEMUX_SUB, filename);
495 for(int i=0;i<count;i++)
497 CDemuxStream* stream = demuxer->GetStream(i);
498 /* skip streams with no type */
499 if (stream->type == STREAM_NONE)
501 /* make sure stream is marked with right source */
502 stream->source = source;
504 OMXSelectionStream s;
506 s.type = stream->type;
508 s.language = g_LangCodeExpander.ConvertToISO6392T(stream->language);
509 s.flags = stream->flags;
510 s.filename = demuxer->GetFileName();
511 stream->GetStreamName(s.name);
513 demuxer->GetStreamCodecName(stream->iId, codec);
515 s.channels = 0; // Default to 0. Overwrite if STREAM_AUDIO below.
516 if(stream->type == STREAM_AUDIO)
519 ((CDemuxStreamAudio*)stream)->GetStreamType(type);
520 if(type.length() > 0)
522 if(s.name.length() > 0)
526 s.channels = ((CDemuxStreamAudio*)stream)->iChannels;
533 COMXPlayer::COMXPlayer(IPlayerCallback &callback)
535 CThread("OMXPlayer"),
536 m_CurrentAudio(STREAM_AUDIO, DVDPLAYER_AUDIO),
537 m_CurrentVideo(STREAM_VIDEO, DVDPLAYER_VIDEO),
538 m_CurrentSubtitle(STREAM_SUBTITLE, DVDPLAYER_SUBTITLE),
539 m_CurrentTeletext(STREAM_TELETEXT, DVDPLAYER_TELETEXT),
540 m_messenger("player"),
541 m_omxPlayerVideo(&m_av_clock, &m_overlayContainer, m_messenger),
542 m_omxPlayerAudio(&m_av_clock, m_messenger),
543 m_dvdPlayerSubtitle(&m_overlayContainer),
544 m_dvdPlayerTeletext(),
546 m_DemuxerPausePending(false)
549 m_pSubtitleDemuxer = NULL;
550 m_pInputStream = NULL;
554 m_EdlAutoSkipMarkers.Clear();
555 m_UpdateApplication = 0;
557 m_bAbortRequest = false;
560 m_playSpeed = DVD_PLAYSPEED_NORMAL;
561 m_caching = CACHESTATE_DONE;
567 m_last_check_time = 0.0;
570 memset(&m_SpeedState, 0, sizeof(m_SpeedState));
572 #ifdef DVDDEBUG_MESSAGE_TRACKER
573 g_dvdMessageTracker.Init();
577 COMXPlayer::~COMXPlayer()
581 #ifdef DVDDEBUG_MESSAGE_TRACKER
582 g_dvdMessageTracker.DeInit();
586 bool COMXPlayer::OpenFile(const CFileItem &file, const CPlayerOptions &options)
590 CLog::Log(LOGNOTICE, "COMXPlayer: Opening: %s", CURL::GetRedacted(file.GetPath()).c_str());
592 // if playing a file close it first
593 // this has to be changed so we won't have to close it.
597 m_bAbortRequest = false;
599 SetPlaySpeed(DVD_PLAYSPEED_NORMAL);
602 m_UpdateApplication = 0;
605 m_PlayerOptions = options;
607 m_mimetype = file.GetMimeType();
608 m_filename = file.GetPath();
612 #if defined(HAS_VIDEO_PLAYBACK)
613 g_renderManager.PreInit();
617 if(!m_ready.WaitMSec(g_advancedSettings.m_videoBusyDialogDelay_ms))
619 CGUIDialogBusy* dialog = (CGUIDialogBusy*)g_windowManager.GetWindow(WINDOW_DIALOG_BUSY);
623 while(!m_ready.WaitMSec(1))
624 g_windowManager.ProcessRenderLoop(false);
629 // Playback might have been stopped due to some error
630 if (m_bStop || m_bAbortRequest)
637 CLog::Log(LOGERROR, "%s - Exception thrown on open", __FUNCTION__);
642 bool COMXPlayer::CloseFile(bool reopen)
644 CLog::Log(LOGDEBUG, "COMXPlayer::CloseFile");
646 // set the abort request so that other threads can finish up
647 m_bAbortRequest = true;
649 // tell demuxer to abort
653 if(m_pSubtitleDemuxer)
654 m_pSubtitleDemuxer->Abort();
657 m_pInputStream->Abort();
659 CLog::Log(LOGDEBUG, "COMXPlayer: waiting for threads to exit");
661 // wait for the main thread to finish up
662 // since this main thread cleans up all other resources and threads
663 // we are done after the StopThread call
667 m_EdlAutoSkipMarkers.Clear();
672 CLog::Log(LOGNOTICE, "COMXPlayer: finished waiting");
673 #if defined(HAS_VIDEO_PLAYBACK)
674 g_renderManager.UnInit();
679 bool COMXPlayer::IsPlaying() const
684 void COMXPlayer::OnStartup()
686 m_CurrentVideo.Clear();
687 m_CurrentAudio.Clear();
688 m_CurrentSubtitle.Clear();
689 m_CurrentTeletext.Clear();
693 CUtil::ClearTempFonts();
696 bool COMXPlayer::OpenInputStream()
699 SAFE_DELETE(m_pInputStream);
701 CLog::Log(LOGNOTICE, "Creating InputStream");
703 // correct the filename if needed
704 CStdString filename(m_filename);
705 if (StringUtils::StartsWith(filename, "dvd://")
706 || StringUtils::EqualsNoCase(filename, "iso9660://video_ts/video_ts.ifo"))
708 m_filename = g_mediaManager.TranslateDevicePath("");
711 // before creating the input stream, if this is an HLS playlist then get the
712 // most appropriate bitrate based on our network settings
713 // ensure to strip off the url options by using a temp CURL object
714 if (StringUtils::StartsWith(filename, "http://") && StringUtils::EndsWith(CURL(filename).GetFileName(), ".m3u8"))
716 // get the available bandwidth (as per user settings)
717 int maxrate = CSettings::Get().GetInt("network.bandwidth");
721 // determine the most appropriate stream
722 m_filename = PLAYLIST::CPlayListM3U::GetBestBandwidthStream(m_filename, (size_t)maxrate);
724 m_pInputStream = CDVDFactoryInputStream::CreateInputStream(this, m_filename, m_mimetype);
725 if(m_pInputStream == NULL)
727 CLog::Log(LOGERROR, "COMXPlayer::OpenInputStream - unable to create input stream for [%s]", m_filename.c_str());
731 m_pInputStream->SetFileItem(m_item);
733 if (!m_pInputStream->Open(m_filename.c_str(), m_mimetype))
735 CLog::Log(LOGERROR, "COMXPlayer::OpenInputStream - error opening [%s]", m_filename.c_str());
739 if (m_pInputStream->IsStreamType(DVDSTREAM_TYPE_DVD)
740 || m_pInputStream->IsStreamType(DVDSTREAM_TYPE_BLURAY))
742 CLog::Log(LOGINFO, "COMXPlayer::OpenInputStream - DVD/BD not supported - Will try...");
745 // find any available external subtitles for non dvd files
746 if (!m_pInputStream->IsStreamType(DVDSTREAM_TYPE_DVD)
747 && !m_pInputStream->IsStreamType(DVDSTREAM_TYPE_PVRMANAGER)
748 && !m_pInputStream->IsStreamType(DVDSTREAM_TYPE_TV)
749 && !m_pInputStream->IsStreamType(DVDSTREAM_TYPE_HTSP))
751 // find any available external subtitles
752 std::vector<CStdString> filenames;
753 CUtil::ScanForExternalSubtitles( m_filename, filenames );
755 // find any upnp subtitles
756 CStdString key("upnp:subtitle:1");
757 for(unsigned s = 1; m_item.HasProperty(key); key = StringUtils::Format("upnp:subtitle:%u", ++s))
758 filenames.push_back(m_item.GetProperty(key).asString());
760 for(unsigned int i=0;i<filenames.size();i++)
762 // if vobsub subtitle:
763 if (URIUtils::HasExtension(filenames[i], ".idx"))
765 CStdString strSubFile;
766 if ( CUtil::FindVobSubPair( filenames, filenames[i], strSubFile ) )
767 AddSubtitleFile(filenames[i], strSubFile);
771 if ( !CUtil::IsVobSub(filenames, filenames[i] ) )
773 AddSubtitleFile(filenames[i]);
776 } // end loop over all subtitle files
778 CMediaSettings::Get().GetCurrentVideoSettings().m_SubtitleCached = true;
781 SetAVDelay(CMediaSettings::Get().GetCurrentVideoSettings().m_AudioDelay);
782 SetSubTitleDelay(CMediaSettings::Get().GetCurrentVideoSettings().m_SubtitleDelay);
786 m_ChannelEntryTimeOut.SetInfinite();
791 bool COMXPlayer::OpenDemuxStream()
794 SAFE_DELETE(m_pDemuxer);
796 CLog::Log(LOGNOTICE, "Creating Demuxer");
801 while(!m_bStop && attempts-- > 0)
803 m_pDemuxer = CDVDFactoryDemuxer::CreateDemuxer(m_pInputStream);
804 if(!m_pDemuxer && m_pInputStream->IsStreamType(DVDSTREAM_TYPE_PVRMANAGER))
808 else if(!m_pDemuxer && m_pInputStream->NextStream() != CDVDInputStream::NEXTSTREAM_NONE)
810 CLog::Log(LOGDEBUG, "%s - New stream available from input, retry open", __FUNCTION__);
818 CLog::Log(LOGERROR, "%s - Error creating demuxer", __FUNCTION__);
825 CLog::Log(LOGERROR, "%s - Exception thrown when opening demuxer", __FUNCTION__);
829 m_SelectionStreams.Clear(STREAM_NONE, STREAM_SOURCE_DEMUX);
830 m_SelectionStreams.Clear(STREAM_NONE, STREAM_SOURCE_NAV);
831 m_SelectionStreams.Update(m_pInputStream, m_pDemuxer);
833 int64_t len = m_pInputStream->GetLength();
834 int64_t tim = m_pDemuxer->GetStreamLength();
835 if(len > 0 && tim > 0)
836 m_pInputStream->SetReadRate(g_advancedSettings.m_readBufferFactor * len * 1000 / tim);
841 void COMXPlayer::OpenDefaultStreams(bool reset)
843 // if input stream dictate, we will open later
844 if(m_dvd.iSelectedAudioStream >= 0
845 || m_dvd.iSelectedSPUStream >= 0)
848 OMXSelectionStreams streams;
852 streams = m_SelectionStreams.Get(STREAM_VIDEO, PredicateVideoPriority);
854 for(OMXSelectionStreams::iterator it = streams.begin(); it != streams.end() && !valid; ++it)
856 if(OpenVideoStream(it->id, it->source, reset))
860 CloseVideoStream(true);
863 if(m_PlayerOptions.video_only)
866 streams = m_SelectionStreams.Get(STREAM_AUDIO, PredicateAudioPriority);
869 for(OMXSelectionStreams::iterator it = streams.begin(); it != streams.end() && !valid; ++it)
871 if(OpenAudioStream(it->id, it->source, reset))
875 CloseAudioStream(true);
877 // enable or disable subtitles
878 SetSubtitleVisible(CMediaSettings::Get().GetCurrentVideoSettings().m_SubtitleOn);
880 // open subtitle stream
881 OMXSelectionStream as = m_SelectionStreams.Get(STREAM_AUDIO, GetAudioStream());
882 PredicateSubtitleFilter psf(as.language);
883 streams = m_SelectionStreams.RemoveIf(STREAM_SUBTITLE, psf);
884 PredicateSubtitlePriority psp(as.language);
885 std::stable_sort(streams.begin(), streams.end(), psp);
887 for(OMXSelectionStreams::iterator it = streams.begin(); it != streams.end() && !valid; ++it)
889 if(OpenSubtitleStream(it->id, it->source))
892 if(it->flags & CDemuxStream::FLAG_FORCED)
893 m_omxPlayerVideo.EnableSubtitle(true);
898 CloseSubtitleStream(true);
899 if (m_pInputStream && !(m_pInputStream->IsStreamType(DVDSTREAM_TYPE_DVD) || m_pInputStream->IsStreamType(DVDSTREAM_TYPE_BLURAY)))
901 SetSubtitleVisible(false);
902 if (GetSubtitleCount() > 0 && CMediaSettings::Get().GetCurrentVideoSettings().m_SubtitleStream == -1)
903 CMediaSettings::Get().GetCurrentVideoSettings().m_SubtitleStream = 0;
907 // open teletext stream
908 streams = m_SelectionStreams.Get(STREAM_TELETEXT);
910 for(OMXSelectionStreams::iterator it = streams.begin(); it != streams.end() && !valid; ++it)
912 if(OpenTeletextStream(it->id, it->source))
916 CloseTeletextStream(true);
919 bool COMXPlayer::ReadPacket(DemuxPacket*& packet, CDemuxStream*& stream)
922 // check if we should read from subtitle demuxer
923 if( m_pSubtitleDemuxer && m_dvdPlayerSubtitle.AcceptsData() )
925 packet = m_pSubtitleDemuxer->Read();
929 UpdateCorrection(packet, m_offset_pts);
930 if(packet->iStreamId < 0)
933 stream = m_pSubtitleDemuxer->GetStream(packet->iStreamId);
936 CLog::Log(LOGERROR, "%s - Error demux packet doesn't belong to a valid stream", __FUNCTION__);
939 if(stream->source == STREAM_SOURCE_NONE)
941 m_SelectionStreams.Clear(STREAM_NONE, STREAM_SOURCE_DEMUX_SUB);
942 m_SelectionStreams.Update(NULL, m_pSubtitleDemuxer);
948 // read a data frame from stream.
950 packet = m_pDemuxer->Read();
954 // stream changed, update and open defaults
955 if(packet->iStreamId == DMX_SPECIALID_STREAMCHANGE)
957 m_SelectionStreams.Clear(STREAM_NONE, STREAM_SOURCE_DEMUX);
958 m_SelectionStreams.Update(m_pInputStream, m_pDemuxer);
959 OpenDefaultStreams(false);
961 // reevaluate HasVideo/Audio, we may have switched from/to a radio channel
962 if(m_CurrentVideo.id < 0)
964 if(m_CurrentAudio.id < 0)
970 UpdateCorrection(packet, m_offset_pts);
972 if(packet->iStreamId < 0)
977 stream = m_pDemuxer->GetStream(packet->iStreamId);
980 CLog::Log(LOGERROR, "%s - Error demux packet doesn't belong to a valid stream", __FUNCTION__);
983 if(stream->source == STREAM_SOURCE_NONE)
985 m_SelectionStreams.Clear(STREAM_NONE, STREAM_SOURCE_DEMUX);
986 m_SelectionStreams.Update(m_pInputStream, m_pDemuxer);
994 bool COMXPlayer::IsValidStream(COMXCurrentStream& stream)
997 return true; // we consider non selected as valid
999 int source = STREAM_SOURCE_MASK(stream.source);
1000 if(source == STREAM_SOURCE_TEXT)
1002 if(source == STREAM_SOURCE_DEMUX_SUB)
1004 CDemuxStream* st = m_pSubtitleDemuxer->GetStream(stream.id);
1005 if(st == NULL || st->disabled)
1007 if(st->type != stream.type)
1011 if(source == STREAM_SOURCE_DEMUX)
1013 CDemuxStream* st = m_pDemuxer->GetStream(stream.id);
1014 if(st == NULL || st->disabled)
1016 if(st->type != stream.type)
1019 if (m_pInputStream && m_pInputStream->IsStreamType(DVDSTREAM_TYPE_DVD))
1021 if(stream.type == STREAM_AUDIO && st->iPhysicalId != m_dvd.iSelectedAudioStream)
1023 if(stream.type == STREAM_SUBTITLE && st->iPhysicalId != m_dvd.iSelectedSPUStream)
1033 bool COMXPlayer::IsBetterStream(COMXCurrentStream& current, CDemuxStream* stream)
1035 // Do not reopen non-video streams if we're in video-only mode
1036 if(m_PlayerOptions.video_only && current.type != STREAM_VIDEO)
1039 if(stream->disabled)
1042 if (m_pInputStream && ( m_pInputStream->IsStreamType(DVDSTREAM_TYPE_DVD)
1043 || m_pInputStream->IsStreamType(DVDSTREAM_TYPE_BLURAY) ) )
1047 source_type = STREAM_SOURCE_MASK(current.source);
1048 if(source_type != STREAM_SOURCE_DEMUX
1049 && source_type != STREAM_SOURCE_NONE)
1052 source_type = STREAM_SOURCE_MASK(stream->source);
1053 if(source_type != STREAM_SOURCE_DEMUX
1054 || stream->type != current.type
1055 || stream->iId == current.id)
1058 if(current.type == STREAM_AUDIO && stream->iPhysicalId == m_dvd.iSelectedAudioStream)
1060 if(current.type == STREAM_SUBTITLE && stream->iPhysicalId == m_dvd.iSelectedSPUStream)
1062 if(current.type == STREAM_VIDEO && current.id < 0)
1067 if(stream->source == current.source
1068 && stream->iId == current.id)
1071 if(stream->type != current.type)
1074 if(current.type == STREAM_SUBTITLE)
1083 void COMXPlayer::Process()
1085 bool bOmxWaitVideo = false;
1086 bool bOmxWaitAudio = false;
1087 bool bOmxSentEOFs = false;
1088 float m_threshold = 0.2f;
1090 if (!OpenInputStream())
1092 m_bAbortRequest = true;
1096 if (CDVDInputStream::IMenus* ptr = dynamic_cast<CDVDInputStream::IMenus*>(m_pInputStream))
1098 CLog::Log(LOGNOTICE, "OMXPlayer: playing a file with menu's");
1099 m_PlayerOptions.starttime = 0;
1101 if(m_PlayerOptions.state.size() > 0)
1102 ptr->SetState(m_PlayerOptions.state);
1103 else if(CDVDInputStreamNavigator* nav = dynamic_cast<CDVDInputStreamNavigator*>(m_pInputStream))
1104 nav->EnableSubtitleStream(CMediaSettings::Get().GetCurrentVideoSettings().m_SubtitleOn);
1106 CMediaSettings::Get().GetCurrentVideoSettings().m_SubtitleCached = true;
1109 if(!OpenDemuxStream())
1111 m_bAbortRequest = true;
1115 // allow renderer to switch to fullscreen if requested
1116 m_omxPlayerVideo.EnableFullscreen(m_PlayerOptions.fullscreen);
1118 if(!m_av_clock.OMXInitialize(&m_clock))
1120 m_bAbortRequest = true;
1123 if(CSettings::Get().GetBool("videoplayer.adjustrefreshrate"))
1124 m_av_clock.HDMIClockSync();
1125 m_av_clock.OMXStateIdle();
1126 m_av_clock.OMXStop();
1127 m_av_clock.OMXPause();
1129 OpenDefaultStreams();
1131 // look for any EDL files
1133 m_EdlAutoSkipMarkers.Clear();
1134 if (m_CurrentVideo.id >= 0 && m_CurrentVideo.hint.fpsrate > 0 && m_CurrentVideo.hint.fpsscale > 0)
1136 float fFramesPerSecond = (float)m_CurrentVideo.hint.fpsrate / (float)m_CurrentVideo.hint.fpsscale;
1137 m_Edl.ReadEditDecisionLists(m_filename, fFramesPerSecond, m_CurrentVideo.hint.height);
1141 * Check to see if the demuxer should start at something other than time 0. This will be the case
1142 * if there was a start time specified as part of the "Start from where last stopped" (aka
1143 * auto-resume) feature or if there is an EDL cut or commercial break that starts at time 0.
1147 if(m_PlayerOptions.starttime > 0 || m_PlayerOptions.startpercent > 0)
1149 if (m_PlayerOptions.startpercent > 0 && m_pDemuxer)
1151 int64_t playerStartTime = (int64_t) ( ( (float) m_pDemuxer->GetStreamLength() ) * ( m_PlayerOptions.startpercent/(float)100 ) );
1152 starttime = m_Edl.RestoreCutTime(playerStartTime);
1156 starttime = m_Edl.RestoreCutTime((int64_t)m_PlayerOptions.starttime * 1000); // s to ms
1158 CLog::Log(LOGDEBUG, "%s - Start position set to last stopped position: %d", __FUNCTION__, starttime);
1160 else if(m_Edl.InCut(0, &cut)
1161 && (cut.action == CEdl::CUT || cut.action == CEdl::COMM_BREAK))
1163 starttime = cut.end;
1164 CLog::Log(LOGDEBUG, "%s - Start position set to end of first cut or commercial break: %d", __FUNCTION__, starttime);
1165 if(cut.action == CEdl::COMM_BREAK)
1168 * Setup auto skip markers as if the commercial break had been skipped using standard
1171 m_EdlAutoSkipMarkers.commbreak_start = cut.start;
1172 m_EdlAutoSkipMarkers.commbreak_end = cut.end;
1173 m_EdlAutoSkipMarkers.seek_to_start = true;
1178 double startpts = DVD_NOPTS_VALUE;
1181 if (m_pDemuxer->SeekTime(starttime, false, &startpts))
1182 CLog::Log(LOGDEBUG, "%s - starting demuxer from: %d", __FUNCTION__, starttime);
1184 CLog::Log(LOGDEBUG, "%s - failed to start demuxing from: %d", __FUNCTION__, starttime);
1187 if(m_pSubtitleDemuxer)
1189 if(m_pSubtitleDemuxer->SeekTime(starttime, false, &startpts))
1190 CLog::Log(LOGDEBUG, "%s - starting subtitle demuxer from: %d", __FUNCTION__, starttime);
1192 CLog::Log(LOGDEBUG, "%s - failed to start subtitle demuxing from: %d", __FUNCTION__, starttime);
1196 // make sure all selected stream have data on startup
1197 if (CachePVRStream())
1198 SetCaching(CACHESTATE_PVR);
1200 // make sure application know our info
1201 UpdateApplication(0);
1204 if(m_PlayerOptions.identify == false)
1205 m_callback.OnPlayBackStarted();
1207 // we are done initializing now, set the readyevent
1210 if (!CachePVRStream())
1211 SetCaching(CACHESTATE_FLUSH);
1213 EDEINTERLACEMODE current_deinterlace = CMediaSettings::Get().GetCurrentVideoSettings().m_DeinterlaceMode;
1215 while (!m_bAbortRequest)
1217 double now = m_clock.GetAbsoluteClock();
1218 if (m_last_check_time == 0.0 || m_last_check_time + DVD_MSEC_TO_TIME(20) <= now)
1220 m_last_check_time = now;
1221 m_stamp = m_av_clock.OMXMediaTime();
1222 const bool m_Pause = m_playSpeed == DVD_PLAYSPEED_PAUSE;
1223 const bool not_accepts_data = (!m_omxPlayerAudio.AcceptsData() && m_CurrentAudio.id >= 0) ||
1224 (!m_omxPlayerVideo.AcceptsData() && m_CurrentVideo.id >= 0);
1225 /* when the video/audio fifos are low, we pause clock, when high we resume */
1226 double audio_pts = floor(m_omxPlayerAudio.GetCurrentPts());
1227 double video_pts = floor(m_omxPlayerVideo.GetCurrentPts());
1229 float audio_fifo = audio_pts / DVD_TIME_BASE - m_stamp * 1e-6;
1230 float video_fifo = video_pts / DVD_TIME_BASE - m_stamp * 1e-6;
1231 float threshold = 0.1f;
1232 bool audio_fifo_low = false, video_fifo_low = false, audio_fifo_high = false, video_fifo_high = false;
1234 // if deinterlace setting has changed, we should close and open video
1235 if (current_deinterlace != CMediaSettings::Get().GetCurrentVideoSettings().m_DeinterlaceMode)
1237 int iStream = m_CurrentVideo.id, source = m_CurrentVideo.source;
1238 CloseVideoStream(false);
1239 OpenVideoStream(iStream, source);
1240 if (m_State.canseek)
1241 m_messenger.Put(new CDVDMsgPlayerSeek(GetTime(), true, true, true, true, true));
1242 current_deinterlace = CMediaSettings::Get().GetCurrentVideoSettings().m_DeinterlaceMode;
1245 m_video_fifo = (int)(100.0*(m_omxPlayerVideo.GetDecoderBufferSize()-m_omxPlayerVideo.GetDecoderFreeSpace())/m_omxPlayerVideo.GetDecoderBufferSize());
1246 m_audio_fifo = (int)(100.0*audio_fifo/m_omxPlayerAudio.GetCacheTotal());
1249 static unsigned count;
1250 if ((count++ & 7) == 0)
1253 if (m_omxPlayerVideo.GetDecoderBufferSize() && m_omxPlayerAudio.GetCacheTotal())
1254 vc_gencmd(response, sizeof response, "render_bar 4 video_fifo %d %d %d %d",
1256 (int)(100.0*video_fifo/m_omxPlayerAudio.GetCacheTotal()),
1258 if (m_omxPlayerAudio.GetCacheTotal())
1259 vc_gencmd(response, sizeof response, "render_bar 5 audio_fifo %d %d %d %d",
1261 (int)(100.0*m_omxPlayerAudio.GetDelay()/m_omxPlayerAudio.GetCacheTotal()),
1263 vc_gencmd(response, sizeof response, "render_bar 6 video_queue %d %d %d %d",
1264 m_omxPlayerVideo.GetLevel(), 0, 0, 100);
1265 vc_gencmd(response, sizeof response, "render_bar 7 audio_queue %d %d %d %d",
1266 m_omxPlayerAudio.GetLevel(), 0, 0, 100);
1269 if (audio_pts != DVD_NOPTS_VALUE)
1271 audio_fifo_low = m_HasAudio && audio_fifo < threshold;
1272 audio_fifo_high = audio_pts != DVD_NOPTS_VALUE && audio_fifo >= m_threshold;
1274 if (video_pts != DVD_NOPTS_VALUE)
1276 video_fifo_low = m_HasVideo && video_fifo < threshold;
1277 video_fifo_high = video_pts != DVD_NOPTS_VALUE && video_fifo >= m_threshold;
1279 if (!m_HasAudio && m_HasVideo)
1280 audio_fifo_high = true;
1281 if (!m_HasVideo && m_HasAudio)
1282 video_fifo_high = true;
1285 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__,
1286 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),
1287 audio_pts == DVD_NOPTS_VALUE ? 0.0:audio_fifo, video_pts == DVD_NOPTS_VALUE ? 0.0:video_fifo, m_threshold,
1288 audio_fifo_low, audio_fifo_high, video_fifo_low, video_fifo_high,
1289 m_omxPlayerAudio.GetLevel(), m_omxPlayerVideo.GetLevel(), m_omxPlayerAudio.GetDelay(), (float)m_omxPlayerAudio.GetCacheTotal());
1292 if (TP(m_playSpeed))
1294 if (m_CurrentVideo.started)
1296 if (m_stamp == 0.0 && (!m_stepped || m_playSpeed > 0))
1298 /* trickplay modes progress by stepping */
1299 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);
1300 m_av_clock.OMXStep();
1304 m_av_clock.OMXMediaTime(0.0);
1305 m_last_check_time = 0.0;
1310 else if(!m_Pause && (bOmxSentEOFs || not_accepts_data || (audio_fifo_high && video_fifo_high)))
1312 if (m_av_clock.OMXIsPaused())
1314 CLog::Log(LOGDEBUG, "Resume %.2f,%.2f (A:%d%d V:%d%d) EOF:%d FULL:%d T:%.2f\n", audio_fifo, video_fifo,
1315 audio_fifo_low, audio_fifo_high, video_fifo_low, video_fifo_high, bOmxSentEOFs, not_accepts_data, m_threshold);
1316 m_av_clock.OMXStateExecute();
1317 m_av_clock.OMXResume();
1320 else if (m_Pause || audio_fifo_low || video_fifo_low)
1322 if (!m_av_clock.OMXIsPaused() && !TPA(m_playSpeed))
1325 m_threshold = std::min(2.0f*m_threshold, 16.0f);
1326 CLog::Log(LOGDEBUG, "Pause %.2f,%.2f (A:%d%d V:%d%d) EOF:%d FULL:%d T:%.2f\n", audio_fifo, video_fifo,
1327 audio_fifo_low, audio_fifo_high, video_fifo_low, video_fifo_high, bOmxSentEOFs, not_accepts_data, m_threshold);
1328 m_av_clock.OMXPause();
1337 // should we open a new input stream?
1340 if (OpenInputStream() == false)
1342 CLog::Log(LOGERROR, "%s - Closing stream due to OpenInputStream()", __FUNCTION__);
1343 m_bAbortRequest = true;
1348 // should we open a new demuxer?
1351 if (m_pInputStream->NextStream() == CDVDInputStream::NEXTSTREAM_NONE)
1354 if (m_pInputStream->IsEOF())
1357 if (OpenDemuxStream() == false)
1359 CLog::Log(LOGERROR, "%s - Closing stream due to OpenDemuxStream()", __FUNCTION__);
1360 m_bAbortRequest = true;
1364 OpenDefaultStreams();
1366 // never allow first frames after open to be skipped
1367 if( m_omxPlayerVideo.IsInited() )
1368 m_omxPlayerVideo.SendMessage(new CDVDMsg(CDVDMsg::VIDEO_NOSKIP));
1370 if (CachePVRStream())
1371 SetCaching(CACHESTATE_PVR);
1373 UpdateApplication(0);
1377 // handle eventual seeks due to playspeed
1380 // update player state
1381 UpdatePlayState(200);
1383 // update application with our state
1384 UpdateApplication(1000);
1386 // make sure we run subtitle process here
1387 m_dvdPlayerSubtitle.Process(m_clock.GetClock() - m_omxPlayerVideo.GetSubtitleDelay());
1389 // OMX emergency exit
1390 if(HasAudio() && m_omxPlayerAudio.BadState())
1392 CLog::Log(LOGERROR, "%s - Closing stream due to m_omxPlayerAudio.BadState()", __FUNCTION__);
1393 m_bAbortRequest = true;
1397 if (CheckDelayedChannelEntry())
1400 // if the queues are full, no need to read more
1401 if ((!m_omxPlayerAudio.AcceptsData() && m_CurrentAudio.id >= 0) ||
1402 (!m_omxPlayerVideo.AcceptsData() && m_CurrentVideo.id >= 0))
1404 if(m_pDemuxer && m_DemuxerPausePending)
1406 m_DemuxerPausePending = false;
1407 m_pDemuxer->SetSpeed(DVD_PLAYSPEED_PAUSE);
1414 // always yield to players if they have data levels > 50 percent
1415 if((m_omxPlayerAudio.GetLevel() > 50 || m_CurrentAudio.id < 0)
1416 && (m_omxPlayerVideo.GetLevel() > 50 || m_CurrentVideo.id < 0))
1419 DemuxPacket* pPacket = NULL;
1420 CDemuxStream *pStream = NULL;
1421 ReadPacket(pPacket, pStream);
1422 if (pPacket && !pStream)
1424 /* probably a empty packet, just free it and move on */
1425 CDVDDemuxUtils::FreeDemuxPacket(pPacket);
1430 // reset eos state when we get a packet (e.g. for case of seek after eos)
1431 bOmxWaitVideo = false;
1432 bOmxWaitAudio = false;
1433 bOmxSentEOFs = false;
1437 // when paused, demuxer could be be returning empty
1438 if (m_playSpeed == DVD_PLAYSPEED_PAUSE)
1441 // check for a still frame state
1442 if (CDVDInputStream::IMenus* pStream = dynamic_cast<CDVDInputStream::IMenus*>(m_pInputStream))
1444 // stills will be skipped
1445 if(m_dvd.state == DVDSTATE_STILL)
1447 if (m_dvd.iDVDStillTime > 0)
1449 if ((XbmcThreads::SystemClockMillis() - m_dvd.iDVDStillStartTime) >= m_dvd.iDVDStillTime)
1451 m_dvd.iDVDStillTime = 0;
1452 m_dvd.iDVDStillStartTime = 0;
1453 m_dvd.state = DVDSTATE_NORMAL;
1454 pStream->SkipStill();
1461 // if there is another stream available, reopen demuxer
1462 CDVDInputStream::ENextStream next = m_pInputStream->NextStream();
1463 if(next == CDVDInputStream::NEXTSTREAM_OPEN)
1465 SAFE_DELETE(m_pDemuxer);
1466 m_CurrentAudio.stream = NULL;
1467 m_CurrentVideo.stream = NULL;
1468 m_CurrentSubtitle.stream = NULL;
1472 // input stream asked us to just retry
1473 if(next == CDVDInputStream::NEXTSTREAM_RETRY)
1479 // make sure we tell all players to finish it's data
1482 if(m_CurrentAudio.inited)
1484 m_omxPlayerAudio.SendMessage (new CDVDMsg(CDVDMsg::GENERAL_EOF));
1485 bOmxWaitAudio = true;
1487 if(m_CurrentVideo.inited)
1489 m_omxPlayerVideo.SendMessage (new CDVDMsg(CDVDMsg::GENERAL_EOF));
1490 bOmxWaitVideo = true;
1492 if(m_CurrentSubtitle.inited)
1493 m_dvdPlayerSubtitle.SendMessage(new CDVDMsg(CDVDMsg::GENERAL_EOF));
1494 if(m_CurrentTeletext.inited)
1495 m_dvdPlayerTeletext.SendMessage(new CDVDMsg(CDVDMsg::GENERAL_EOF));
1496 m_CurrentAudio.inited = false;
1497 m_CurrentVideo.inited = false;
1498 m_CurrentSubtitle.inited = false;
1499 m_CurrentTeletext.inited = false;
1500 bOmxSentEOFs = true;
1503 // if we are caching, start playing it again
1504 SetCaching(CACHESTATE_DONE);
1506 // while players are still playing, keep going to allow seekbacks
1507 if(m_omxPlayerVideo.HasData()
1508 || m_omxPlayerAudio.HasData())
1514 // wait for omx components to finish
1515 if(bOmxWaitVideo && !m_omxPlayerVideo.IsEOS())
1520 if(bOmxWaitAudio && !m_omxPlayerAudio.IsEOS())
1526 if (!m_pInputStream->IsEOF())
1527 CLog::Log(LOGINFO, "%s - eof reading from demuxer", __FUNCTION__);
1529 m_CurrentAudio.started = false;
1530 m_CurrentVideo.started = false;
1531 m_CurrentSubtitle.started = false;
1532 m_CurrentTeletext.started = false;
1537 // it's a valid data packet, reset error counter
1540 // check so that none of our streams has become invalid
1541 if (!IsValidStream(m_CurrentAudio) && m_omxPlayerAudio.IsStalled()) CloseAudioStream(true);
1542 if (!IsValidStream(m_CurrentVideo) && m_omxPlayerVideo.IsStalled()) CloseVideoStream(true);
1543 if (!IsValidStream(m_CurrentSubtitle) && m_dvdPlayerSubtitle.IsStalled()) CloseSubtitleStream(true);
1544 if (!IsValidStream(m_CurrentTeletext)) CloseTeletextStream(true);
1546 // see if we can find something better to play
1547 if (IsBetterStream(m_CurrentAudio, pStream)) OpenAudioStream (pStream->iId, pStream->source);
1548 if (IsBetterStream(m_CurrentVideo, pStream)) OpenVideoStream (pStream->iId, pStream->source);
1549 if (IsBetterStream(m_CurrentSubtitle, pStream)) OpenSubtitleStream(pStream->iId, pStream->source);
1550 if (IsBetterStream(m_CurrentTeletext, pStream)) OpenTeletextStream(pStream->iId, pStream->source);
1552 // process the packet
1553 ProcessPacket(pStream, pPacket);
1555 // check if in a cut or commercial break that should be automatically skipped
1556 CheckAutoSceneSkip();
1560 bool COMXPlayer::CheckDelayedChannelEntry(void)
1562 bool bReturn(false);
1564 if (m_ChannelEntryTimeOut.IsTimePast())
1566 CFileItem currentFile(g_application.CurrentFileItem());
1567 CPVRChannel *currentChannel = currentFile.GetPVRChannelInfoTag();
1568 SwitchChannel(*currentChannel);
1571 m_ChannelEntryTimeOut.SetInfinite();
1577 void COMXPlayer::ProcessPacket(CDemuxStream* pStream, DemuxPacket* pPacket)
1579 /* process packet if it belongs to selected stream. for dvd's don't allow automatic opening of streams*/
1580 OMXStreamLock lock(this);
1584 if (pPacket->iStreamId == m_CurrentAudio.id && pStream->source == m_CurrentAudio.source && pStream->type == STREAM_AUDIO)
1585 ProcessAudioData(pStream, pPacket);
1586 else if (pPacket->iStreamId == m_CurrentVideo.id && pStream->source == m_CurrentVideo.source && pStream->type == STREAM_VIDEO)
1587 ProcessVideoData(pStream, pPacket);
1588 else if (pPacket->iStreamId == m_CurrentSubtitle.id && pStream->source == m_CurrentSubtitle.source && pStream->type == STREAM_SUBTITLE)
1589 ProcessSubData(pStream, pPacket);
1590 else if (pPacket->iStreamId == m_CurrentTeletext.id && pStream->source == m_CurrentTeletext.source && pStream->type == STREAM_TELETEXT)
1591 ProcessTeletextData(pStream, pPacket);
1594 pStream->SetDiscard(AVDISCARD_ALL);
1595 CDVDDemuxUtils::FreeDemuxPacket(pPacket); // free it since we won't do anything with it
1600 CLog::Log(LOGERROR, "%s - Exception thrown when processing demux packet", __FUNCTION__);
1605 void COMXPlayer::ProcessAudioData(CDemuxStream* pStream, DemuxPacket* pPacket)
1607 if (m_CurrentAudio.stream != (void*)pStream
1608 || m_CurrentAudio.changes != pStream->changes)
1610 /* check so that dmuxer hints or extra data hasn't changed */
1611 /* if they have, reopen stream */
1613 if (m_CurrentAudio.hint != CDVDStreamInfo(*pStream, true))
1614 OpenAudioStream( pPacket->iStreamId, pStream->source );
1616 m_CurrentAudio.stream = (void*)pStream;
1617 m_CurrentAudio.changes = pStream->changes;
1620 // check if we are too slow and need to recache
1621 CheckStartCaching(m_CurrentAudio);
1623 CheckContinuity(m_CurrentAudio, pPacket);
1624 UpdateTimestamps(m_CurrentAudio, pPacket);
1627 if (CheckPlayerInit(m_CurrentAudio, DVDPLAYER_AUDIO))
1631 * If CheckSceneSkip() returns true then demux point is inside an EDL cut and the packets are dropped.
1632 * If not inside a hard cut, but the demux point has reached an EDL mute section then trigger the
1633 * AUDIO_SILENCE state. The AUDIO_SILENCE state is reverted as soon as the demux point is outside
1634 * of any EDL section while EDL mute is still active.
1637 if (CheckSceneSkip(m_CurrentAudio))
1639 else if (m_Edl.InCut(DVD_TIME_TO_MSEC(m_CurrentAudio.dts + m_offset_pts), &cut) && cut.action == CEdl::MUTE // Inside EDL mute
1640 && !m_EdlAutoSkipMarkers.mute) // Mute not already triggered
1642 m_omxPlayerAudio.SendMessage(new CDVDMsgBool(CDVDMsg::AUDIO_SILENCE, true));
1643 m_EdlAutoSkipMarkers.mute = true;
1645 else if (!m_Edl.InCut(DVD_TIME_TO_MSEC(m_CurrentAudio.dts + m_offset_pts), &cut) // Outside of any EDL
1646 && m_EdlAutoSkipMarkers.mute) // But the mute hasn't been removed yet
1648 m_omxPlayerAudio.SendMessage(new CDVDMsgBool(CDVDMsg::AUDIO_SILENCE, false));
1649 m_EdlAutoSkipMarkers.mute = false;
1652 m_omxPlayerAudio.SendMessage(new CDVDMsgDemuxerPacket(pPacket, drop));
1655 void COMXPlayer::ProcessVideoData(CDemuxStream* pStream, DemuxPacket* pPacket)
1657 if (m_CurrentVideo.stream != (void*)pStream
1658 || m_CurrentVideo.changes != pStream->changes)
1660 /* check so that dmuxer hints or extra data hasn't changed */
1661 /* if they have reopen stream */
1663 if (m_CurrentVideo.hint != CDVDStreamInfo(*pStream, true))
1664 OpenVideoStream(pPacket->iStreamId, pStream->source);
1666 m_CurrentVideo.stream = (void*)pStream;
1667 m_CurrentVideo.changes = pStream->changes;
1670 // check if we are too slow and need to recache
1671 CheckStartCaching(m_CurrentVideo);
1673 if( pPacket->iSize != 4) //don't check the EOF_SEQUENCE of stillframes
1675 CheckContinuity(m_CurrentVideo, pPacket);
1676 UpdateTimestamps(m_CurrentVideo, pPacket);
1680 if (CheckPlayerInit(m_CurrentVideo, DVDPLAYER_VIDEO))
1683 if (CheckSceneSkip(m_CurrentVideo))
1686 m_omxPlayerVideo.SendMessage(new CDVDMsgDemuxerPacket(pPacket, drop));
1689 void COMXPlayer::ProcessSubData(CDemuxStream* pStream, DemuxPacket* pPacket)
1691 if (m_CurrentSubtitle.stream != (void*)pStream
1692 || m_CurrentSubtitle.changes != pStream->changes)
1694 /* check so that dmuxer hints or extra data hasn't changed */
1695 /* if they have reopen stream */
1697 if (m_CurrentSubtitle.hint != CDVDStreamInfo(*pStream, true))
1698 OpenSubtitleStream(pPacket->iStreamId, pStream->source);
1700 m_CurrentSubtitle.stream = (void*)pStream;
1701 m_CurrentSubtitle.changes = pStream->changes;
1704 UpdateTimestamps(m_CurrentSubtitle, pPacket);
1707 if (CheckPlayerInit(m_CurrentSubtitle, DVDPLAYER_SUBTITLE))
1710 if (CheckSceneSkip(m_CurrentSubtitle))
1713 m_dvdPlayerSubtitle.SendMessage(new CDVDMsgDemuxerPacket(pPacket, drop));
1715 if(m_pInputStream && m_pInputStream->IsStreamType(DVDSTREAM_TYPE_DVD))
1716 m_dvdPlayerSubtitle.UpdateOverlayInfo((CDVDInputStreamNavigator*)m_pInputStream, LIBDVDNAV_BUTTON_NORMAL);
1719 void COMXPlayer::ProcessTeletextData(CDemuxStream* pStream, DemuxPacket* pPacket)
1721 if (m_CurrentTeletext.stream != (void*)pStream
1722 || m_CurrentTeletext.changes != pStream->changes)
1724 /* check so that dmuxer hints or extra data hasn't changed */
1725 /* if they have, reopen stream */
1726 if (m_CurrentTeletext.hint != CDVDStreamInfo(*pStream, true))
1727 OpenTeletextStream( pPacket->iStreamId, pStream->source );
1729 m_CurrentTeletext.stream = (void*)pStream;
1730 m_CurrentTeletext.changes = pStream->changes;
1732 UpdateTimestamps(m_CurrentTeletext, pPacket);
1735 if (CheckPlayerInit(m_CurrentTeletext, DVDPLAYER_TELETEXT))
1738 if (CheckSceneSkip(m_CurrentTeletext))
1741 m_dvdPlayerTeletext.SendMessage(new CDVDMsgDemuxerPacket(pPacket, drop));
1744 bool COMXPlayer::GetCachingTimes(double& level, double& delay, double& offset)
1746 if(!m_pInputStream || !m_pDemuxer)
1749 XFILE::SCacheStatus status;
1750 if (!m_pInputStream->GetCacheStatus(&status))
1753 int64_t cached = status.forward;
1754 unsigned currate = status.currate;
1755 unsigned maxrate = status.maxrate;
1756 bool full = status.full;
1758 int64_t length = m_pInputStream->GetLength();
1759 int64_t remain = length - m_pInputStream->Seek(0, SEEK_CUR);
1761 if(cached < 0 || length <= 0 || remain < 0)
1764 double play_sbp = DVD_MSEC_TO_TIME(m_pDemuxer->GetStreamLength()) / length;
1765 double queued = 1000.0 * GetQueueTime() / play_sbp;
1769 offset = (double)(cached + queued) / length;
1774 double cache_sbp = 1.1 * (double)DVD_TIME_BASE / currate; /* underestimate by 10 % */
1775 double play_left = play_sbp * (remain + queued); /* time to play out all remaining bytes */
1776 double cache_left = cache_sbp * (remain - cached); /* time to cache the remaining bytes */
1777 double cache_need = std::max(0.0, remain - play_left / cache_sbp); /* bytes needed until play_left == cache_left */
1779 delay = cache_left - play_left;
1781 if (full && (currate < maxrate) )
1782 level = -1.0; /* buffer is full & our read rate is too low */
1784 level = (cached + queued) / (cache_need + queued);
1789 void COMXPlayer::HandlePlaySpeed()
1791 ECacheState caching = m_caching;
1793 if(IsInMenu() && caching != CACHESTATE_DONE)
1794 caching = CACHESTATE_DONE;
1796 if(caching == CACHESTATE_FULL)
1798 double level, delay, offset;
1799 if(GetCachingTimes(level, delay, offset))
1803 CGUIDialogKaiToast::QueueNotification(g_localizeStrings.Get(21454), g_localizeStrings.Get(21455));
1804 caching = CACHESTATE_INIT;
1807 caching = CACHESTATE_INIT;
1811 if ((!m_omxPlayerAudio.AcceptsData() && m_CurrentAudio.id >= 0)
1812 || (!m_omxPlayerVideo.AcceptsData() && m_CurrentVideo.id >= 0))
1813 caching = CACHESTATE_INIT;
1817 if(caching == CACHESTATE_INIT)
1819 // if all enabled streams have been inited we are done
1820 if((m_CurrentVideo.id < 0 || m_CurrentVideo.started)
1821 && (m_CurrentAudio.id < 0 || m_CurrentAudio.started))
1822 caching = CACHESTATE_PLAY;
1824 // handle situation that we get no data on one stream
1825 if(m_CurrentAudio.id >= 0 && m_CurrentVideo.id >= 0)
1827 if ((!m_omxPlayerAudio.AcceptsData() && !m_CurrentVideo.started)
1828 || (!m_omxPlayerVideo.AcceptsData() && !m_CurrentAudio.started))
1830 caching = CACHESTATE_DONE;
1835 if (caching == CACHESTATE_PVR)
1837 bool bGotAudio(m_pDemuxer->GetNrOfAudioStreams() > 0);
1838 bool bGotVideo(m_pDemuxer->GetNrOfVideoStreams() > 0);
1839 bool bAudioLevelOk(m_omxPlayerAudio.GetLevel() > g_advancedSettings.m_iPVRMinAudioCacheLevel);
1840 bool bVideoLevelOk(m_omxPlayerVideo.GetLevel() > g_advancedSettings.m_iPVRMinVideoCacheLevel);
1841 bool bAudioFull(!m_omxPlayerAudio.AcceptsData());
1842 bool bVideoFull(!m_omxPlayerVideo.AcceptsData());
1844 if (/* if all streams got at least g_advancedSettings.m_iPVRMinCacheLevel in their buffers, we're done */
1845 ((bGotVideo || bGotAudio) && (!bGotAudio || bAudioLevelOk) && (!bGotVideo || bVideoLevelOk)) ||
1846 /* or if one of the buffers is full */
1847 (bAudioFull || bVideoFull))
1849 CLog::Log(LOGDEBUG, "set caching from pvr to done. audio (%d) = %d. video (%d) = %d",
1850 bGotAudio, m_omxPlayerAudio.GetLevel(),
1851 bGotVideo, m_omxPlayerVideo.GetLevel());
1853 CFileItem currentItem(g_application.CurrentFileItem());
1854 if (currentItem.HasPVRChannelInfoTag())
1855 g_PVRManager.LoadCurrentChannelSettings();
1857 caching = CACHESTATE_DONE;
1861 /* ensure that automatically started players are stopped while caching */
1862 if (m_CurrentAudio.started)
1863 m_omxPlayerAudio.SetSpeed(DVD_PLAYSPEED_PAUSE);
1864 if (m_CurrentVideo.started)
1865 m_omxPlayerVideo.SetSpeed(DVD_PLAYSPEED_PAUSE);
1869 if(caching == CACHESTATE_PLAY)
1871 // if all enabled streams have started playing we are done
1872 if((m_CurrentVideo.id < 0 || !m_omxPlayerVideo.IsStalled())
1873 && (m_CurrentAudio.id < 0 || !m_omxPlayerAudio.IsStalled()))
1874 caching = CACHESTATE_DONE;
1877 if(m_caching != caching)
1878 SetCaching(caching);
1881 if(GetPlaySpeed() != DVD_PLAYSPEED_NORMAL && GetPlaySpeed() != DVD_PLAYSPEED_PAUSE)
1885 // this can't be done in menu
1886 SetPlaySpeed(DVD_PLAYSPEED_NORMAL);
1889 else if (m_CurrentVideo.id >= 0
1890 && m_CurrentVideo.inited == true
1891 && m_SpeedState.lastpts != m_omxPlayerVideo.GetCurrentPts()
1892 && m_SpeedState.lasttime != GetTime()
1895 m_SpeedState.lastpts = m_omxPlayerVideo.GetCurrentPts();
1896 m_SpeedState.lasttime = GetTime();
1897 // check how much off clock video is when ff/rw:ing
1898 // a problem here is that seeking isn't very accurate
1899 // and since the clock will be resynced after seek
1900 // we might actually not really be playing at the wanted
1901 // speed. we'd need to have some way to not resync the clock
1902 // after a seek to remember timing. still need to handle
1903 // discontinuities somehow
1905 // when seeking, give the player a headstart to make sure
1906 // the time it takes to seek doesn't make a difference.
1908 error = m_clock.GetClock() - m_SpeedState.lastpts;
1909 error *= m_playSpeed / abs(m_playSpeed);
1911 if(error > DVD_MSEC_TO_TIME(1000))
1913 CLog::Log(LOGDEBUG, "COMXPlayer::Process - Seeking to catch up");
1914 int64_t iTime = (int64_t)DVD_TIME_TO_MSEC(m_clock.GetClock() + m_State.time_offset + 500000.0 * m_playSpeed / DVD_PLAYSPEED_NORMAL);
1915 m_messenger.Put(new CDVDMsgPlayerSeek(iTime, (GetPlaySpeed() < 0), true, false, false, true));
1921 bool COMXPlayer::CheckStartCaching(COMXCurrentStream& current)
1923 if(m_caching != CACHESTATE_DONE
1924 || m_playSpeed != DVD_PLAYSPEED_NORMAL)
1930 if((current.type == STREAM_AUDIO && m_omxPlayerAudio.IsStalled())
1931 || (current.type == STREAM_VIDEO && m_omxPlayerVideo.IsStalled()))
1933 if (CachePVRStream())
1935 if ((current.type == STREAM_AUDIO && current.started && m_omxPlayerAudio.GetLevel() == 0) ||
1936 (current.type == STREAM_VIDEO && current.started && m_omxPlayerVideo.GetLevel() == 0))
1938 CLog::Log(LOGDEBUG, "%s stream stalled. start buffering", current.type == STREAM_AUDIO ? "audio" : "video");
1939 SetCaching(CACHESTATE_PVR);
1944 // don't start caching if it's only a single stream that has run dry
1945 if(m_omxPlayerAudio.GetLevel() > 50
1946 || m_omxPlayerVideo.GetLevel() > 50)
1950 SetCaching(CACHESTATE_FULL);
1952 SetCaching(CACHESTATE_INIT);
1958 bool COMXPlayer::CheckPlayerInit(COMXCurrentStream& current, unsigned int source)
1963 if(current.startpts != DVD_NOPTS_VALUE)
1965 if(current.dts == DVD_NOPTS_VALUE)
1967 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((current.startpts - current.dts) > DVD_SEC_TO_TIME(20))
1973 CLog::Log(LOGDEBUG, "%s - too far to decode before finishing seek", __FUNCTION__);
1974 if(m_CurrentAudio.startpts != DVD_NOPTS_VALUE)
1975 m_CurrentAudio.startpts = current.dts;
1976 if(m_CurrentVideo.startpts != DVD_NOPTS_VALUE)
1977 m_CurrentVideo.startpts = current.dts;
1978 if(m_CurrentSubtitle.startpts != DVD_NOPTS_VALUE)
1979 m_CurrentSubtitle.startpts = current.dts;
1980 if(m_CurrentTeletext.startpts != DVD_NOPTS_VALUE)
1981 m_CurrentTeletext.startpts = current.dts;
1984 if(current.dts < current.startpts)
1986 CLog::Log(LOGDEBUG, "%s - dropping packet type:%d dts:%f to get to start point at %f", __FUNCTION__, source, current.dts, current.startpts);
1991 //If this is the first packet after a discontinuity, send it as a resync
1992 if (current.dts != DVD_NOPTS_VALUE)
1994 current.inited = true;
1995 current.startpts = current.dts;
1997 bool setclock = false;
1998 if(m_playSpeed == DVD_PLAYSPEED_NORMAL)
2000 if( source == DVDPLAYER_AUDIO)
2001 setclock = !m_CurrentVideo.inited;
2002 else if(source == DVDPLAYER_VIDEO)
2003 setclock = !m_CurrentAudio.inited;
2007 if(source == DVDPLAYER_VIDEO)
2011 double starttime = current.startpts;
2012 if(m_CurrentAudio.inited
2013 && m_CurrentAudio.startpts != DVD_NOPTS_VALUE
2014 && m_CurrentAudio.startpts < starttime)
2015 starttime = m_CurrentAudio.startpts;
2016 if(m_CurrentVideo.inited
2017 && m_CurrentVideo.startpts != DVD_NOPTS_VALUE
2018 && m_CurrentVideo.startpts < starttime)
2019 starttime = m_CurrentVideo.startpts;
2021 starttime = current.startpts - starttime;
2022 if(starttime > 0 && setclock)
2024 if(starttime > DVD_SEC_TO_TIME(2))
2025 CLog::Log(LOGWARNING, "COMXPlayer::CheckPlayerInit(%d) - Ignoring too large delay of %f", source, starttime);
2027 SendPlayerMessage(new CDVDMsgDouble(CDVDMsg::GENERAL_DELAY, starttime), source);
2030 SendPlayerMessage(new CDVDMsgGeneralResync(current.dts, setclock), source);
2035 void COMXPlayer::UpdateCorrection(DemuxPacket* pkt, double correction)
2037 //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);
2038 if(pkt->dts != DVD_NOPTS_VALUE) pkt->dts -= correction;
2039 if(pkt->pts != DVD_NOPTS_VALUE) pkt->pts -= correction;
2042 void COMXPlayer::UpdateTimestamps(COMXCurrentStream& current, DemuxPacket* pPacket)
2044 double dts = current.dts;
2045 /* update stored values */
2046 if(pPacket->dts != DVD_NOPTS_VALUE)
2048 else if(pPacket->pts != DVD_NOPTS_VALUE)
2051 /* calculate some average duration */
2052 if(pPacket->duration != DVD_NOPTS_VALUE)
2053 current.dur = pPacket->duration;
2054 else if(dts != DVD_NOPTS_VALUE && current.dts != DVD_NOPTS_VALUE)
2055 current.dur = 0.1 * (current.dur * 9 + (dts - current.dts));
2059 /* send a playback state structure periodically */
2060 if(current.dts_state == DVD_NOPTS_VALUE
2061 || abs(current.dts - current.dts_state) > DVD_MSEC_TO_TIME(200))
2063 current.dts_state = current.dts;
2067 // make sure we send no outdated state to a/v players
2069 SendPlayerMessage(new CDVDMsgType<SPlayerState>(CDVDMsg::PLAYER_DISPLAYTIME, m_StateInput), current.player);
2073 CSingleLock lock(m_StateSection);
2074 m_State = m_StateInput;
2079 static void UpdateLimits(double& minimum, double& maximum, double dts)
2081 if(dts == DVD_NOPTS_VALUE)
2083 if(minimum == DVD_NOPTS_VALUE || minimum > dts) minimum = dts;
2084 if(maximum == DVD_NOPTS_VALUE || maximum < dts) maximum = dts;
2087 void COMXPlayer::CheckContinuity(COMXCurrentStream& current, DemuxPacket* pPacket)
2089 if (m_playSpeed < DVD_PLAYSPEED_PAUSE)
2092 if( pPacket->dts == DVD_NOPTS_VALUE || current.dts == DVD_NOPTS_VALUE)
2095 double mindts = DVD_NOPTS_VALUE, maxdts = DVD_NOPTS_VALUE;
2096 UpdateLimits(mindts, maxdts, m_CurrentAudio.dts);
2097 UpdateLimits(mindts, maxdts, m_CurrentVideo.dts);
2098 UpdateLimits(mindts, maxdts, m_CurrentAudio.dts_end());
2099 UpdateLimits(mindts, maxdts, m_CurrentVideo.dts_end());
2101 /* if we don't have max and min, we can't do anything more */
2102 if( mindts == DVD_NOPTS_VALUE || maxdts == DVD_NOPTS_VALUE )
2105 double correction = 0.0;
2106 if( pPacket->dts > maxdts + DVD_MSEC_TO_TIME(1000))
2108 CLog::Log(LOGDEBUG, "COMXPlayer::CheckContinuity - resync forward :%d, prev:%f, curr:%f, diff:%f"
2109 , current.type, current.dts, pPacket->dts, pPacket->dts - maxdts);
2110 correction = pPacket->dts - maxdts;
2113 /* if it's large scale jump, correct for it */
2114 if(pPacket->dts + DVD_MSEC_TO_TIME(100) < current.dts_end())
2116 CLog::Log(LOGDEBUG, "COMXPlayer::CheckContinuity - resync backward :%d, prev:%f, curr:%f, diff:%f"
2117 , current.type, current.dts, pPacket->dts, pPacket->dts - current.dts);
2118 correction = pPacket->dts - current.dts_end();
2120 else if(pPacket->dts < current.dts)
2122 CLog::Log(LOGDEBUG, "COMXPlayer::CheckContinuity - wrapback :%d, prev:%f, curr:%f, diff:%f"
2123 , current.type, current.dts, pPacket->dts, pPacket->dts - current.dts);
2126 if(correction != 0.0)
2128 /* disable detection on next packet on other stream to avoid ping pong-ing */
2129 if(m_CurrentAudio.player != current.player) m_CurrentAudio.dts = DVD_NOPTS_VALUE;
2130 if(m_CurrentVideo.player != current.player) m_CurrentVideo.dts = DVD_NOPTS_VALUE;
2132 m_offset_pts += correction;
2133 UpdateCorrection(pPacket, correction);
2137 bool COMXPlayer::CheckSceneSkip(COMXCurrentStream& current)
2142 if(current.dts == DVD_NOPTS_VALUE)
2145 if(current.inited == false)
2149 return m_Edl.InCut(DVD_TIME_TO_MSEC(current.dts + m_offset_pts), &cut) && cut.action == CEdl::CUT;
2152 void COMXPlayer::CheckAutoSceneSkip()
2158 * Check that there is an audio and video stream.
2160 if(m_CurrentAudio.id < 0
2161 || m_CurrentVideo.id < 0)
2165 * If there is a startpts defined for either the audio or video stream then dvdplayer is still
2166 * still decoding frames to get to the previously requested seek point.
2168 if(m_CurrentAudio.inited == false
2169 || m_CurrentVideo.inited == false)
2172 if(m_CurrentAudio.dts == DVD_NOPTS_VALUE
2173 || m_CurrentVideo.dts == DVD_NOPTS_VALUE)
2176 const int64_t clock = DVD_TIME_TO_MSEC(min(m_CurrentAudio.dts, m_CurrentVideo.dts) + m_offset_pts);
2179 if(!m_Edl.InCut(clock, &cut))
2182 if(cut.action == CEdl::CUT
2183 && !(cut.end == m_EdlAutoSkipMarkers.cut || cut.start == m_EdlAutoSkipMarkers.cut)) // To prevent looping if same cut again
2185 CLog::Log(LOGDEBUG, "%s - Clock in EDL cut [%s - %s]: %s. Automatically skipping over.",
2186 __FUNCTION__, CEdl::MillisecondsToTimeString(cut.start).c_str(),
2187 CEdl::MillisecondsToTimeString(cut.end).c_str(), CEdl::MillisecondsToTimeString(clock).c_str());
2189 * Seeking either goes to the start or the end of the cut depending on the play direction.
2191 int64_t seek = GetPlaySpeed() >= 0 ? cut.end : cut.start;
2193 * Seeking is NOT flushed so any content up to the demux point is retained when playing forwards.
2195 m_messenger.Put(new CDVDMsgPlayerSeek((int)seek, true, true, true, false, true));
2197 * Seek doesn't always work reliably. Last physical seek time is recorded to prevent looping
2198 * if there was an error with seeking and it landed somewhere unexpected, perhaps back in the
2199 * cut. The cut automatic skip marker is reset every 500ms allowing another attempt at the seek.
2201 m_EdlAutoSkipMarkers.cut = GetPlaySpeed() >= 0 ? cut.end : cut.start;
2203 else if(cut.action == CEdl::COMM_BREAK
2204 && GetPlaySpeed() >= 0
2205 && cut.start > m_EdlAutoSkipMarkers.commbreak_end)
2207 CLog::Log(LOGDEBUG, "%s - Clock in commercial break [%s - %s]: %s. Automatically skipping to end of commercial break (only done once per break)",
2208 __FUNCTION__, CEdl::MillisecondsToTimeString(cut.start).c_str(), CEdl::MillisecondsToTimeString(cut.end).c_str(),
2209 CEdl::MillisecondsToTimeString(clock).c_str());
2211 * Seeking is NOT flushed so any content up to the demux point is retained when playing forwards.
2213 m_messenger.Put(new CDVDMsgPlayerSeek(cut.end + 1, true, true, true, false, true));
2215 * Each commercial break is only skipped once so poorly detected commercial breaks can be
2216 * manually re-entered. Start and end are recorded to prevent looping and to allow seeking back
2217 * to the start of the commercial break if incorrectly flagged.
2219 m_EdlAutoSkipMarkers.commbreak_start = cut.start;
2220 m_EdlAutoSkipMarkers.commbreak_end = cut.end;
2221 m_EdlAutoSkipMarkers.seek_to_start = true; // Allow backwards Seek() to go directly to the start
2225 void COMXPlayer::SynchronizeDemuxer(unsigned int timeout)
2227 if(IsCurrentThread())
2229 if(!m_messenger.IsInited())
2232 CDVDMsgGeneralSynchronize* message = new CDVDMsgGeneralSynchronize(timeout, 0);
2233 m_messenger.Put(message->Acquire());
2234 message->Wait(&m_bStop, 0);
2238 void COMXPlayer::SynchronizePlayers(unsigned int sources)
2240 /* we need a big timeout as audio queue is about 8seconds for 2ch ac3 */
2241 const int timeout = 10*1000; // in milliseconds
2243 CDVDMsgGeneralSynchronize* message = new CDVDMsgGeneralSynchronize(timeout, sources);
2244 if (m_CurrentAudio.id >= 0)
2245 m_omxPlayerAudio.SendMessage(message->Acquire());
2247 if (m_CurrentVideo.id >= 0)
2248 m_omxPlayerVideo.SendMessage(message->Acquire());
2249 /* TODO - we have to rewrite the sync class, to not require
2250 all other players waiting for subtitle, should only
2252 if (m_CurrentSubtitle.id >= 0)
2253 m_dvdPlayerSubtitle.SendMessage(message->Acquire());
2258 void COMXPlayer::SendPlayerMessage(CDVDMsg* pMsg, unsigned int target)
2260 if(target == DVDPLAYER_AUDIO)
2261 m_omxPlayerAudio.SendMessage(pMsg);
2262 if(target == DVDPLAYER_VIDEO)
2263 m_omxPlayerVideo.SendMessage(pMsg);
2264 if(target == DVDPLAYER_SUBTITLE)
2265 m_dvdPlayerSubtitle.SendMessage(pMsg);
2266 if(target == DVDPLAYER_TELETEXT)
2267 m_dvdPlayerTeletext.SendMessage(pMsg);
2270 void COMXPlayer::OnExit()
2274 CLog::Log(LOGNOTICE, "COMXPlayer::OnExit()");
2276 m_av_clock.OMXStop();
2277 m_av_clock.OMXStateIdle();
2279 // set event to inform openfile something went wrong in case openfile is still waiting for this event
2280 SetCaching(CACHESTATE_DONE);
2282 // close each stream
2283 if (!m_bAbortRequest) CLog::Log(LOGNOTICE, "OMXPlayer: eof, waiting for queues to empty");
2284 if (m_CurrentAudio.id >= 0)
2286 CLog::Log(LOGNOTICE, "OMXPlayer: closing audio stream");
2287 CloseAudioStream(!m_bAbortRequest);
2289 if (m_CurrentVideo.id >= 0)
2291 CLog::Log(LOGNOTICE, "OMXPlayer: closing video stream");
2292 CloseVideoStream(!m_bAbortRequest);
2294 if (m_CurrentSubtitle.id >= 0)
2296 CLog::Log(LOGNOTICE, "OMXPlayer: closing subtitle stream");
2297 CloseSubtitleStream(!m_bAbortRequest);
2299 if (m_CurrentTeletext.id >= 0)
2301 CLog::Log(LOGNOTICE, "OMXPlayer: closing teletext stream");
2302 CloseTeletextStream(!m_bAbortRequest);
2304 // destroy the demuxer
2307 CLog::Log(LOGNOTICE, "COMXPlayer::OnExit() deleting demuxer");
2312 if (m_pSubtitleDemuxer)
2314 CLog::Log(LOGNOTICE, "COMXPlayer::OnExit() deleting subtitle demuxer");
2315 delete m_pSubtitleDemuxer;
2317 m_pSubtitleDemuxer = NULL;
2319 // destroy the inputstream
2322 CLog::Log(LOGNOTICE, "COMXPlayer::OnExit() deleting input stream");
2323 delete m_pInputStream;
2325 m_pInputStream = NULL;
2327 // clean up all selection streams
2328 m_SelectionStreams.Clear(STREAM_NONE, STREAM_SOURCE_NONE);
2332 m_av_clock.OMXDeinitialize();
2337 CLog::Log(LOGERROR, "%s - Exception thrown when trying to close down player, memory leak will follow", __FUNCTION__);
2338 m_pInputStream = NULL;
2343 // if we didn't stop playing, advance to the next item in xbmc's playlist
2344 if(m_PlayerOptions.identify == false)
2346 if (m_bAbortRequest)
2347 m_callback.OnPlayBackStopped();
2349 m_callback.OnPlayBackEnded();
2352 // set event to inform openfile something went wrong in case openfile is still waiting for this event
2356 void COMXPlayer::HandleMessages()
2359 OMXStreamLock lock(this);
2361 while (m_messenger.Get(&pMsg, 0) == MSGQ_OK)
2366 if (pMsg->IsType(CDVDMsg::PLAYER_SEEK) && m_messenger.GetPacketCount(CDVDMsg::PLAYER_SEEK) == 0
2367 && m_messenger.GetPacketCount(CDVDMsg::PLAYER_SEEK_CHAPTER) == 0)
2369 CDVDMsgPlayerSeek &msg(*((CDVDMsgPlayerSeek*)pMsg));
2371 if (!m_State.canseek)
2377 if(!msg.GetTrickPlay())
2379 g_infoManager.SetDisplayAfterSeek(100000);
2382 SetCaching(CACHESTATE_FLUSH);
2384 double start = DVD_NOPTS_VALUE;
2386 int time = msg.GetRestore() ? (int)m_Edl.RestoreCutTime(msg.GetTime()) : msg.GetTime();
2388 // if input streams doesn't support seektime we must convert back to clock
2389 if(dynamic_cast<CDVDInputStream::ISeekTime*>(m_pInputStream) == NULL)
2390 time -= DVD_TIME_TO_MSEC(m_State.time_offset - m_offset_pts);
2392 CLog::Log(LOGDEBUG, "demuxer seek to: %d", time);
2393 if (m_pDemuxer && m_pDemuxer->SeekTime(time, msg.GetBackward(), &start))
2395 CLog::Log(LOGDEBUG, "demuxer seek to: %.0f, success", start);
2396 if(m_pSubtitleDemuxer)
2398 if(!m_pSubtitleDemuxer->SeekTime(time, msg.GetBackward()))
2399 CLog::Log(LOGDEBUG, "failed to seek subtitle demuxer: %d, success", time);
2401 // dts after successful seek
2402 if (m_StateInput.time_src == ETIMESOURCE_CLOCK && start == DVD_NOPTS_VALUE)
2403 m_StateInput.dts = DVD_MSEC_TO_TIME(time);
2405 m_StateInput.dts = start;
2407 FlushBuffers(!msg.GetFlush(), start, msg.GetAccurate());
2408 // mark mediatime as invalid
2409 m_av_clock.OMXMediaTime(0.0);
2410 m_last_check_time = 0.0;
2413 CLog::Log(LOGWARNING, "error while seeking");
2415 // set flag to indicate we have finished a seeking request
2416 if(!msg.GetTrickPlay())
2417 g_infoManager.SetDisplayAfterSeek();
2419 // dvd's will issue a HOP_CHANNEL that we need to skip
2420 if(m_pInputStream->IsStreamType(DVDSTREAM_TYPE_DVD))
2421 m_dvd.state = DVDSTATE_SEEK;
2423 else if (pMsg->IsType(CDVDMsg::PLAYER_SEEK_CHAPTER) && m_messenger.GetPacketCount(CDVDMsg::PLAYER_SEEK) == 0
2424 && m_messenger.GetPacketCount(CDVDMsg::PLAYER_SEEK_CHAPTER) == 0)
2426 g_infoManager.SetDisplayAfterSeek(100000);
2427 SetCaching(CACHESTATE_FLUSH);
2429 CDVDMsgPlayerSeekChapter &msg(*((CDVDMsgPlayerSeekChapter*)pMsg));
2430 double start = DVD_NOPTS_VALUE;
2432 // This should always be the case.
2433 if(m_pDemuxer && m_pDemuxer->SeekChapter(msg.GetChapter(), &start))
2435 FlushBuffers(false, start, true);
2436 // mark mediatime as invalid
2437 m_av_clock.OMXMediaTime(0.0);
2439 m_callback.OnPlayBackSeekChapter(msg.GetChapter());
2442 g_infoManager.SetDisplayAfterSeek();
2444 else if (pMsg->IsType(CDVDMsg::DEMUXER_RESET))
2446 m_CurrentAudio.stream = NULL;
2447 m_CurrentVideo.stream = NULL;
2448 m_CurrentSubtitle.stream = NULL;
2450 // we need to reset the demuxer, probably because the streams have changed
2452 m_pDemuxer->Reset();
2453 if(m_pSubtitleDemuxer)
2454 m_pSubtitleDemuxer->Reset();
2456 else if (pMsg->IsType(CDVDMsg::PLAYER_SET_AUDIOSTREAM))
2458 CDVDMsgPlayerSetAudioStream* pMsg2 = (CDVDMsgPlayerSetAudioStream*)pMsg;
2460 OMXSelectionStream& st = m_SelectionStreams.Get(STREAM_AUDIO, pMsg2->GetStreamId());
2461 if(st.source != STREAM_SOURCE_NONE)
2463 if(st.source == STREAM_SOURCE_NAV && m_pInputStream && m_pInputStream->IsStreamType(DVDSTREAM_TYPE_DVD))
2465 CDVDInputStreamNavigator* pStream = (CDVDInputStreamNavigator*)m_pInputStream;
2466 if(pStream->SetActiveAudioStream(st.id))
2468 m_dvd.iSelectedAudioStream = -1;
2469 CloseAudioStream(false);
2470 m_messenger.Put(new CDVDMsgPlayerSeek(GetTime(), true, true, true, true, true));
2475 CloseAudioStream(false);
2476 OpenAudioStream(st.id, st.source);
2477 AdaptForcedSubtitles();
2478 m_messenger.Put(new CDVDMsgPlayerSeek(GetTime(), true, true, true, true, true));
2482 else if (pMsg->IsType(CDVDMsg::PLAYER_SET_SUBTITLESTREAM))
2484 CDVDMsgPlayerSetSubtitleStream* pMsg2 = (CDVDMsgPlayerSetSubtitleStream*)pMsg;
2486 OMXSelectionStream& st = m_SelectionStreams.Get(STREAM_SUBTITLE, pMsg2->GetStreamId());
2487 if(st.source != STREAM_SOURCE_NONE)
2489 if(st.source == STREAM_SOURCE_NAV && m_pInputStream && m_pInputStream->IsStreamType(DVDSTREAM_TYPE_DVD))
2491 CDVDInputStreamNavigator* pStream = (CDVDInputStreamNavigator*)m_pInputStream;
2492 if(pStream->SetActiveSubtitleStream(st.id))
2494 m_dvd.iSelectedSPUStream = -1;
2495 CloseSubtitleStream(false);
2500 CloseSubtitleStream(false);
2501 OpenSubtitleStream(st.id, st.source);
2505 else if (pMsg->IsType(CDVDMsg::PLAYER_SET_SUBTITLESTREAM_VISIBLE))
2507 CDVDMsgBool* pValue = (CDVDMsgBool*)pMsg;
2509 m_omxPlayerVideo.EnableSubtitle(pValue->m_value);
2511 if (m_pInputStream && m_pInputStream->IsStreamType(DVDSTREAM_TYPE_DVD))
2512 static_cast<CDVDInputStreamNavigator*>(m_pInputStream)->EnableSubtitleStream(pValue->m_value);
2514 else if (pMsg->IsType(CDVDMsg::PLAYER_SET_STATE))
2516 g_infoManager.SetDisplayAfterSeek(100000);
2517 SetCaching(CACHESTATE_FLUSH);
2519 CDVDMsgPlayerSetState* pMsgPlayerSetState = (CDVDMsgPlayerSetState*)pMsg;
2521 if (CDVDInputStream::IMenus* ptr = dynamic_cast<CDVDInputStream::IMenus*>(m_pInputStream))
2523 if(ptr->SetState(pMsgPlayerSetState->GetState()))
2525 m_dvd.state = DVDSTATE_NORMAL;
2526 m_dvd.iDVDStillStartTime = 0;
2527 m_dvd.iDVDStillTime = 0;
2531 g_infoManager.SetDisplayAfterSeek();
2533 else if (pMsg->IsType(CDVDMsg::PLAYER_SET_RECORD))
2535 CDVDInputStream::IChannel* input = dynamic_cast<CDVDInputStream::IChannel*>(m_pInputStream);
2537 input->Record(*(CDVDMsgBool*)pMsg);
2539 else if (pMsg->IsType(CDVDMsg::GENERAL_FLUSH))
2541 FlushBuffers(false);
2543 else if (pMsg->IsType(CDVDMsg::PLAYER_SETSPEED))
2545 int speed = static_cast<CDVDMsgInt*>(pMsg)->m_value;
2547 // correct our current clock, as it would start going wrong otherwise
2548 if(m_State.timestamp > 0)
2551 offset = m_clock.GetAbsoluteClock() - m_State.timestamp;
2552 offset *= m_playSpeed / DVD_PLAYSPEED_NORMAL;
2553 if(offset > 1000) offset = 1000;
2554 if(offset < -1000) offset = -1000;
2555 m_State.time += DVD_TIME_TO_MSEC(offset);
2556 m_State.timestamp = m_clock.GetAbsoluteClock();
2559 if (speed != DVD_PLAYSPEED_PAUSE && m_playSpeed != DVD_PLAYSPEED_PAUSE && speed != m_playSpeed)
2560 m_callback.OnPlayBackSpeedChanged(speed / DVD_PLAYSPEED_NORMAL);
2562 if (m_pInputStream->IsStreamType(DVDSTREAM_TYPE_PVRMANAGER) && speed != m_playSpeed)
2564 CDVDInputStreamPVRManager* pvrinputstream = static_cast<CDVDInputStreamPVRManager*>(m_pInputStream);
2565 pvrinputstream->Pause( speed == 0 );
2568 // if playspeed is different then DVD_PLAYSPEED_NORMAL or DVD_PLAYSPEED_PAUSE
2569 // audioplayer, stops outputing audio to audiorender, but still tries to
2570 // sleep an correct amount for each packet
2571 // videoplayer just plays faster after the clock speed has been increased
2573 // 2. skip frames and adjust their pts or the clock
2575 // when switching from trickplay to normal, we may not have a full set of reference frames
2576 // in decoder and we may get corrupt frames out. Seeking to current time will avoid this.
2577 if ( TP(speed) || TP(m_playSpeed) ||
2578 ( (speed == DVD_PLAYSPEED_PAUSE || speed == DVD_PLAYSPEED_NORMAL) &&
2579 (m_playSpeed != DVD_PLAYSPEED_PAUSE && m_playSpeed != DVD_PLAYSPEED_NORMAL) ) )
2580 m_messenger.Put(new CDVDMsgPlayerSeek(GetTime(), (speed < 0), true, false, false, true));
2582 m_playSpeed = speed;
2583 m_caching = CACHESTATE_DONE;
2584 m_clock.SetSpeed(speed);
2585 m_av_clock.OMXSetSpeed(speed);
2586 m_av_clock.OMXPause();
2587 m_omxPlayerAudio.SetSpeed(speed);
2588 m_omxPlayerVideo.SetSpeed(speed);
2590 // We can't pause demuxer until our buffers are full. Doing so will result in continued
2591 // calls to Read() which may then block indefinitely (CDVDInputStreamRTMP for example).
2594 m_DemuxerPausePending = (speed == DVD_PLAYSPEED_PAUSE);
2595 if (!m_DemuxerPausePending)
2596 m_pDemuxer->SetSpeed(speed);
2598 CLog::Log(LOGDEBUG, "COMXPlayer - CDVDMsg::PLAYER_SETSPEED speed : %d", speed);
2600 else if (pMsg->IsType(CDVDMsg::PLAYER_CHANNEL_SELECT_NUMBER) && m_messenger.GetPacketCount(CDVDMsg::PLAYER_CHANNEL_SELECT_NUMBER) == 0)
2602 FlushBuffers(false);
2603 CDVDInputStream::IChannel* input = dynamic_cast<CDVDInputStream::IChannel*>(m_pInputStream);
2604 if(input && input->SelectChannelByNumber(static_cast<CDVDMsgInt*>(pMsg)->m_value))
2606 SAFE_DELETE(m_pDemuxer);
2609 CLog::Log(LOGWARNING, "%s - failed to switch channel. playback stopped", __FUNCTION__);
2610 CApplicationMessenger::Get().MediaStop(false);
2613 else if (pMsg->IsType(CDVDMsg::PLAYER_CHANNEL_SELECT) && m_messenger.GetPacketCount(CDVDMsg::PLAYER_CHANNEL_SELECT) == 0)
2615 FlushBuffers(false);
2616 CDVDInputStream::IChannel* input = dynamic_cast<CDVDInputStream::IChannel*>(m_pInputStream);
2617 if(input && input->SelectChannel(static_cast<CDVDMsgType <CPVRChannel> *>(pMsg)->m_value))
2619 SAFE_DELETE(m_pDemuxer);
2622 CLog::Log(LOGWARNING, "%s - failed to switch channel. playback stopped", __FUNCTION__);
2623 CApplicationMessenger::Get().MediaStop(false);
2626 else if (pMsg->IsType(CDVDMsg::PLAYER_CHANNEL_NEXT) || pMsg->IsType(CDVDMsg::PLAYER_CHANNEL_PREV))
2628 CDVDInputStream::IChannel* input = dynamic_cast<CDVDInputStream::IChannel*>(m_pInputStream);
2631 bool bSwitchSuccessful(false);
2632 bool bShowPreview(CSettings::Get().GetInt("pvrplayback.channelentrytimeout") > 0);
2636 g_infoManager.SetDisplayAfterSeek(100000);
2637 FlushBuffers(false);
2640 if(pMsg->IsType(CDVDMsg::PLAYER_CHANNEL_NEXT))
2641 bSwitchSuccessful = input->NextChannel(bShowPreview);
2643 bSwitchSuccessful = input->PrevChannel(bShowPreview);
2645 if(bSwitchSuccessful)
2649 UpdateApplication(0);
2650 m_ChannelEntryTimeOut.Set(CSettings::Get().GetInt("pvrplayback.channelentrytimeout"));
2654 m_ChannelEntryTimeOut.SetInfinite();
2655 SAFE_DELETE(m_pDemuxer);
2657 g_infoManager.SetDisplayAfterSeek();
2662 CLog::Log(LOGWARNING, "%s - failed to switch channel. playback stopped", __FUNCTION__);
2663 CApplicationMessenger::Get().MediaStop(false);
2667 else if (pMsg->IsType(CDVDMsg::GENERAL_GUI_ACTION))
2668 OnAction(((CDVDMsgType<CAction>*)pMsg)->m_value);
2669 else if (pMsg->IsType(CDVDMsg::PLAYER_STARTED))
2671 int player = ((CDVDMsgInt*)pMsg)->m_value;
2672 if(player == DVDPLAYER_AUDIO)
2673 m_CurrentAudio.started = true;
2674 if(player == DVDPLAYER_VIDEO)
2675 m_CurrentVideo.started = true;
2677 if ((player == DVDPLAYER_AUDIO || player == DVDPLAYER_VIDEO) &&
2678 (TPA(m_playSpeed) || !m_HasAudio || m_CurrentAudio.started) &&
2679 (!m_HasVideo || m_CurrentVideo.started))
2681 CLog::Log(LOGDEBUG, "COMXPlayer::HandleMessages - player started RESET");
2682 m_av_clock.OMXReset(m_HasVideo, m_playSpeed != DVD_PLAYSPEED_NORMAL && m_playSpeed != DVD_PLAYSPEED_PAUSE ? false:m_HasAudio);
2685 CLog::Log(LOGDEBUG, "COMXPlayer::HandleMessages - player started %d (tpa:%d,a:%d,v:%d)", player, TPA(m_playSpeed), m_CurrentAudio.started, m_CurrentVideo.started);
2687 else if (pMsg->IsType(CDVDMsg::PLAYER_DISPLAYTIME))
2689 COMXPlayer::SPlayerState& state = ((CDVDMsgType<COMXPlayer::SPlayerState>*)pMsg)->m_value;
2691 CSingleLock lock(m_StateSection);
2692 /* prioritize data from video player, but only accept data *
2693 * after it has been started to avoid race conditions after seeks */
2694 if(m_CurrentVideo.started && !m_omxPlayerVideo.SubmittedEOS())
2696 if(state.player == DVDPLAYER_VIDEO)
2699 else if(m_CurrentAudio.started)
2701 if(state.player == DVDPLAYER_AUDIO)
2708 CLog::Log(LOGERROR, "%s - Exception thrown when handling message", __FUNCTION__);
2716 void COMXPlayer::SetCaching(ECacheState state)
2718 if(state == CACHESTATE_FLUSH)
2720 double level, delay, offset;
2721 if(GetCachingTimes(level, delay, offset))
2722 state = CACHESTATE_FULL;
2724 state = CACHESTATE_INIT;
2727 if(m_caching == state)
2730 CLog::Log(LOGDEBUG, "COMXPlayer::SetCaching - caching state %d", state);
2731 if(state == CACHESTATE_FULL
2732 || state == CACHESTATE_INIT
2733 || state == CACHESTATE_PVR)
2735 m_clock.SetSpeed(DVD_PLAYSPEED_PAUSE);
2736 m_av_clock.OMXPause();
2737 m_omxPlayerAudio.SetSpeed(DVD_PLAYSPEED_PAUSE);
2738 m_omxPlayerAudio.SendMessage(new CDVDMsg(CDVDMsg::PLAYER_STARTED), 1);
2739 m_omxPlayerVideo.SetSpeed(DVD_PLAYSPEED_PAUSE);
2740 m_omxPlayerVideo.SendMessage(new CDVDMsg(CDVDMsg::PLAYER_STARTED), 1);
2742 if (state == CACHESTATE_PVR)
2743 m_pInputStream->ResetScanTimeout((unsigned int) CSettings::Get().GetInt("pvrplayback.scantime") * 1000);
2746 if(state == CACHESTATE_PLAY
2747 ||(state == CACHESTATE_DONE && m_caching != CACHESTATE_PLAY))
2749 m_clock.SetSpeed(m_playSpeed);
2750 m_omxPlayerAudio.SetSpeed(m_playSpeed);
2751 m_omxPlayerVideo.SetSpeed(m_playSpeed);
2752 m_pInputStream->ResetScanTimeout(0);
2757 void COMXPlayer::SetPlaySpeed(int speed)
2759 m_messenger.Put(new CDVDMsgInt(CDVDMsg::PLAYER_SETSPEED, speed));
2760 m_omxPlayerAudio.SetSpeed(speed);
2761 m_omxPlayerVideo.SetSpeed(speed);
2762 SynchronizeDemuxer(100);
2765 bool COMXPlayer::CanPause()
2767 CSingleLock lock(m_StateSection);
2768 return m_State.canpause;
2771 void COMXPlayer::Pause()
2773 CSingleLock lock(m_StateSection);
2774 if (!m_State.canpause)
2778 if(m_playSpeed != DVD_PLAYSPEED_PAUSE && (m_caching == CACHESTATE_FULL || m_caching == CACHESTATE_PVR))
2780 SetCaching(CACHESTATE_DONE);
2784 // return to normal speed if it was paused before, pause otherwise
2785 if (m_playSpeed == DVD_PLAYSPEED_PAUSE)
2787 SetPlaySpeed(DVD_PLAYSPEED_NORMAL);
2788 m_callback.OnPlayBackResumed();
2792 SetPlaySpeed(DVD_PLAYSPEED_PAUSE);
2793 m_callback.OnPlayBackPaused();
2797 bool COMXPlayer::IsPaused() const
2799 return m_playSpeed == DVD_PLAYSPEED_PAUSE || m_caching == CACHESTATE_FULL || m_caching == CACHESTATE_PVR;
2802 bool COMXPlayer::HasVideo() const
2807 bool COMXPlayer::HasAudio() const
2812 bool COMXPlayer::IsPassthrough() const
2814 return m_omxPlayerAudio.Passthrough();
2817 bool COMXPlayer::CanSeek()
2819 CSingleLock lock(m_StateSection);
2820 return m_State.canseek;
2823 void COMXPlayer::Seek(bool bPlus, bool bLargeStep, bool bChapterOverride)
2826 if( m_playSpeed == DVD_PLAYSPEED_PAUSE && bPlus && !bLargeStep)
2828 m_av_clock.OMXStep();
2832 if (!m_State.canseek)
2835 if (bLargeStep && bChapterOverride && GetChapter() > 0)
2839 SeekChapter(GetChapter() - 1);
2842 else if (GetChapter() < GetChapterCount())
2844 SeekChapter(GetChapter() + 1);
2850 if (g_advancedSettings.m_videoUseTimeSeeking && GetTotalTime() > 2000*g_advancedSettings.m_videoTimeSeekForwardBig)
2853 seek = bPlus ? g_advancedSettings.m_videoTimeSeekForwardBig : g_advancedSettings.m_videoTimeSeekBackwardBig;
2855 seek = bPlus ? g_advancedSettings.m_videoTimeSeekForward : g_advancedSettings.m_videoTimeSeekBackward;
2863 percent = bPlus ? g_advancedSettings.m_videoPercentSeekForwardBig : g_advancedSettings.m_videoPercentSeekBackwardBig;
2865 percent = bPlus ? g_advancedSettings.m_videoPercentSeekForward : g_advancedSettings.m_videoPercentSeekBackward;
2866 seek = (int64_t)(GetTotalTimeInMsec()*(GetPercentage()+percent)/100);
2869 bool restore = true;
2873 * Alter the standard seek position based on whether any commercial breaks have been
2874 * automatically skipped.
2876 const int clock = DVD_TIME_TO_MSEC(m_clock.GetClock());
2878 * If a large backwards seek occurs within 10 seconds of the end of the last automated
2879 * commercial skip, then seek back to the start of the commercial break under the assumption
2880 * it was flagged incorrectly. 10 seconds grace period is allowed in case the watcher has to
2881 * fumble around finding the remote. Only happens once per commercial break.
2883 * Small skip does not trigger this in case the start of the commercial break was in fact fine
2884 * but it skipped too far into the program. In that case small skip backwards behaves as normal.
2886 if (!bPlus && bLargeStep
2887 && m_EdlAutoSkipMarkers.seek_to_start
2888 && clock >= m_EdlAutoSkipMarkers.commbreak_end
2889 && clock <= m_EdlAutoSkipMarkers.commbreak_end + 10*1000) // Only if within 10 seconds of the end (in msec)
2891 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).",
2892 __FUNCTION__, CEdl::MillisecondsToTimeString(m_EdlAutoSkipMarkers.commbreak_start).c_str(),
2893 CEdl::MillisecondsToTimeString(m_EdlAutoSkipMarkers.commbreak_end).c_str());
2894 seek = m_EdlAutoSkipMarkers.commbreak_start;
2896 m_EdlAutoSkipMarkers.seek_to_start = false; // So this will only happen within the 10 second grace period once.
2899 * If big skip forward within the last "reverted" commercial break, seek to the end of the
2900 * commercial break under the assumption that the break was incorrectly flagged and playback has
2901 * now reached the actual start of the commercial break. Assume that the end is flagged more
2902 * correctly than the landing point for a standard big skip (ends seem to be flagged more
2903 * accurately than the start).
2905 else if (bPlus && bLargeStep
2906 && clock >= m_EdlAutoSkipMarkers.commbreak_start
2907 && clock <= m_EdlAutoSkipMarkers.commbreak_end)
2909 CLog::Log(LOGDEBUG, "%s - Seeking to end of previously skipped commercial break [%s - %s] as big forwards skip activated within the break.",
2910 __FUNCTION__, CEdl::MillisecondsToTimeString(m_EdlAutoSkipMarkers.commbreak_start).c_str(),
2911 CEdl::MillisecondsToTimeString(m_EdlAutoSkipMarkers.commbreak_end).c_str());
2912 seek = m_EdlAutoSkipMarkers.commbreak_end;
2917 int64_t time = GetTime();
2918 if(g_application.CurrentFileItem().IsStack()
2919 && (seek > GetTotalTimeInMsec() || seek < 0))
2921 g_application.SeekTime((seek - time) * 0.001 + g_application.GetTime());
2922 // warning, don't access any dvdplayer variables here as
2923 // the dvdplayer object may have been destroyed
2927 m_messenger.Put(new CDVDMsgPlayerSeek((int)seek, !bPlus, true, false, restore));
2928 SynchronizeDemuxer(100);
2929 if (seek < 0) seek = 0;
2930 m_callback.OnPlayBackSeek((int)seek, (int)(seek - time));
2933 bool COMXPlayer::SeekScene(bool bPlus)
2935 if (!m_Edl.HasSceneMarker())
2939 * There is a 5 second grace period applied when seeking for scenes backwards. If there is no
2940 * grace period applied it is impossible to go backwards past a scene marker.
2942 int64_t clock = GetTime();
2943 if (!bPlus && clock > 5 * 1000) // 5 seconds
2946 int64_t iScenemarker;
2947 if (m_Edl.GetNextSceneMarker(bPlus, clock, &iScenemarker))
2950 * Seeking is flushed and inaccurate, just like Seek()
2952 m_messenger.Put(new CDVDMsgPlayerSeek((int)iScenemarker, !bPlus, true, false, false));
2953 SynchronizeDemuxer(100);
2959 void COMXPlayer::GetAudioInfo(CStdString &strAudioInfo)
2961 { CSingleLock lock(m_StateSection);
2962 strAudioInfo = StringUtils::Format("D(%s)", m_StateInput.demux_audio.c_str());
2964 strAudioInfo += StringUtils::Format("\nP(%s)", m_omxPlayerAudio.GetPlayerInfo().c_str());
2967 void COMXPlayer::GetVideoInfo(CStdString &strVideoInfo)
2969 { CSingleLock lock(m_StateSection);
2970 strVideoInfo = StringUtils::Format("D(%s)", m_StateInput.demux_video.c_str());
2972 strVideoInfo += StringUtils::Format("\nP(%s)", m_omxPlayerVideo.GetPlayerInfo().c_str());
2975 void COMXPlayer::GetGeneralInfo(CStdString& strGeneralInfo)
2979 double apts = m_omxPlayerAudio.GetCurrentPts();
2980 double vpts = m_omxPlayerVideo.GetCurrentPts();
2983 if( apts != DVD_NOPTS_VALUE && vpts != DVD_NOPTS_VALUE )
2984 dDiff = (apts - vpts) / DVD_TIME_BASE;
2986 CStdString strEDL = StringUtils::Format(", edl:%s", m_Edl.GetInfo().c_str());
2989 CSingleLock lock(m_StateSection);
2990 if(m_StateInput.cache_bytes >= 0)
2992 strBuf += StringUtils::Format(" cache:%s %2.0f%%"
2993 , StringUtils::SizeToString(m_State.cache_bytes).c_str()
2994 , m_State.cache_level * 100);
2995 if(m_playSpeed == 0 || m_caching == CACHESTATE_FULL)
2996 strBuf += StringUtils::Format(" %d sec", DVD_TIME_TO_SEC(m_State.cache_delay));
2999 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 )"
3000 , m_omxPlayerAudio.GetDelay()
3003 , (int)(CThread::GetRelativeUsage()*100)
3004 , (int)(m_omxPlayerAudio.GetRelativeUsage()*100)
3005 , (int)(m_omxPlayerVideo.GetRelativeUsage()*100)
3009 , m_omxPlayerAudio.GetDynamicRangeAmplification());
3014 void COMXPlayer::SeekPercentage(float iPercent)
3016 int64_t iTotalTime = GetTotalTimeInMsec();
3021 SeekTime((int64_t)(iTotalTime * iPercent / 100));
3024 float COMXPlayer::GetPercentage()
3026 int64_t iTotalTime = GetTotalTimeInMsec();
3031 return GetTime() * 100 / (float)iTotalTime;
3034 float COMXPlayer::GetCachePercentage()
3036 CSingleLock lock(m_StateSection);
3037 return m_StateInput.cache_offset * 100; // NOTE: Percentage returned is relative
3040 void COMXPlayer::SetAVDelay(float fValue)
3042 m_omxPlayerVideo.SetDelay(fValue * DVD_TIME_BASE);
3045 float COMXPlayer::GetAVDelay()
3047 return m_omxPlayerVideo.GetDelay() / (float)DVD_TIME_BASE;
3050 void COMXPlayer::SetSubTitleDelay(float fValue)
3052 m_omxPlayerVideo.SetSubtitleDelay(-fValue * DVD_TIME_BASE);
3055 float COMXPlayer::GetSubTitleDelay()
3057 return -m_omxPlayerVideo.GetSubtitleDelay() / DVD_TIME_BASE;
3060 // priority: 1: libdvdnav, 2: external subtitles, 3: muxed subtitles
3061 int COMXPlayer::GetSubtitleCount()
3063 return m_SelectionStreams.Count(STREAM_SUBTITLE);
3066 int COMXPlayer::GetSubtitle()
3068 return m_SelectionStreams.IndexOf(STREAM_SUBTITLE, *this);
3071 void COMXPlayer::GetSubtitleStreamInfo(int index, SPlayerSubtitleStreamInfo &info)
3073 if (index < 0 || index > (int) GetSubtitleCount() - 1)
3076 OMXSelectionStream& s = m_SelectionStreams.Get(STREAM_SUBTITLE, index);
3077 if(s.name.length() > 0)
3080 if(s.type == STREAM_NONE)
3081 info.name += "(Invalid)";
3083 info.language = s.language;
3086 void COMXPlayer::SetSubtitle(int iStream)
3088 CMediaSettings::Get().GetCurrentVideoSettings().m_SubtitleStream = iStream;
3089 m_messenger.Put(new CDVDMsgPlayerSetSubtitleStream(iStream));
3092 bool COMXPlayer::GetSubtitleVisible()
3094 if (m_pInputStream && m_pInputStream->IsStreamType(DVDSTREAM_TYPE_DVD))
3096 CDVDInputStreamNavigator* pStream = (CDVDInputStreamNavigator*)m_pInputStream;
3097 if(pStream->IsInMenu())
3098 return CMediaSettings::Get().GetCurrentVideoSettings().m_SubtitleOn;
3100 return pStream->IsSubtitleStreamEnabled();
3103 return m_omxPlayerVideo.IsSubtitleEnabled();
3106 void COMXPlayer::SetSubtitleVisible(bool bVisible)
3108 CMediaSettings::Get().GetCurrentVideoSettings().m_SubtitleOn = bVisible;
3109 m_messenger.Put(new CDVDMsgBool(CDVDMsg::PLAYER_SET_SUBTITLESTREAM_VISIBLE, bVisible));
3112 int COMXPlayer::GetAudioStreamCount()
3114 return m_SelectionStreams.Count(STREAM_AUDIO);
3117 int COMXPlayer::GetAudioStream()
3119 return m_SelectionStreams.IndexOf(STREAM_AUDIO, *this);
3122 void COMXPlayer::SetAudioStream(int iStream)
3124 CMediaSettings::Get().GetCurrentVideoSettings().m_AudioStream = iStream;
3125 m_messenger.Put(new CDVDMsgPlayerSetAudioStream(iStream));
3126 SynchronizeDemuxer(100);
3129 TextCacheStruct_t* COMXPlayer::GetTeletextCache()
3131 if (m_CurrentTeletext.id < 0)
3134 return m_dvdPlayerTeletext.GetTeletextCache();
3137 void COMXPlayer::LoadPage(int p, int sp, unsigned char* buffer)
3139 if (m_CurrentTeletext.id < 0)
3142 return m_dvdPlayerTeletext.LoadPage(p, sp, buffer);
3145 void COMXPlayer::SeekTime(int64_t iTime)
3147 int seekOffset = (int)(iTime - GetTime());
3148 m_messenger.Put(new CDVDMsgPlayerSeek((int)iTime, true, true, true));
3149 SynchronizeDemuxer(100);
3150 m_callback.OnPlayBackSeek((int)iTime, seekOffset);
3153 // return the time in milliseconds
3154 int64_t COMXPlayer::GetTime()
3156 CSingleLock lock(m_StateSection);
3158 const double limit = DVD_MSEC_TO_TIME(200);
3159 if(m_State.timestamp > 0)
3161 offset = m_clock.GetAbsoluteClock() - m_State.timestamp;
3162 offset *= m_playSpeed / DVD_PLAYSPEED_NORMAL;
3163 if(offset > limit) offset = limit;
3164 if(offset < -limit) offset = -limit;
3166 //{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)));}
3167 return llrint(m_State.time + DVD_TIME_TO_MSEC(offset));
3170 // return length in msec
3171 int64_t COMXPlayer::GetTotalTimeInMsec()
3173 CSingleLock lock(m_StateSection);
3174 return llrint(m_State.time_total);
3177 // return length in seconds.. this should be changed to return in milleseconds throughout xbmc
3178 int64_t COMXPlayer::GetTotalTime()
3180 return GetTotalTimeInMsec();
3183 void COMXPlayer::ToFFRW(int iSpeed)
3185 // can't rewind in menu as seeking isn't possible
3187 if (iSpeed < 0 && IsInMenu()) return;
3188 SetPlaySpeed(iSpeed * DVD_PLAYSPEED_NORMAL);
3191 bool COMXPlayer::OpenAudioStream(int iStream, int source, bool reset)
3193 CLog::Log(LOGNOTICE, "Opening audio stream: %i source: %i", iStream, source);
3197 CLog::Log(LOGWARNING, "Opening audio stream: no demuxer");
3201 CDemuxStream* pStream = m_pDemuxer->GetStream(iStream);
3202 if (!pStream || pStream->disabled)
3204 CLog::Log(LOGWARNING, "Opening audio stream: pStream=%p disabled=%d", pStream, pStream ? pStream->disabled:0);
3208 if( m_CurrentAudio.id < 0 && m_CurrentVideo.id >= 0 )
3210 // up until now we wheren't playing audio, but we did play video
3211 // this will change what is used to sync the dvdclock.
3212 // since the new audio data doesn't have to have any relation
3213 // to the current video data in the packet que, we have to
3214 // wait for it to empty
3216 // this happens if a new cell has audio data, but previous didn't
3217 // and both have video data
3219 SynchronizePlayers(SYNCSOURCE_AUDIO);
3222 CDVDStreamInfo hint(*pStream, true);
3224 if(m_CurrentAudio.id < 0
3225 || m_CurrentAudio.hint != hint)
3227 if(!m_omxPlayerAudio.OpenStream(hint))
3229 /* mark stream as disabled, to disallaw further attempts*/
3230 CLog::Log(LOGWARNING, "%s - Unsupported stream %d. Stream disabled.", __FUNCTION__, iStream);
3231 pStream->disabled = true;
3232 pStream->SetDiscard(AVDISCARD_ALL);
3237 m_omxPlayerAudio.SendMessage(new CDVDMsg(CDVDMsg::GENERAL_RESET));
3239 /* store information about stream */
3240 m_CurrentAudio.id = iStream;
3241 m_CurrentAudio.source = source;
3242 m_CurrentAudio.hint = hint;
3243 m_CurrentAudio.stream = (void*)pStream;
3244 m_CurrentAudio.started = false;
3247 /* we are potentially going to be waiting on this */
3248 m_omxPlayerAudio.SendMessage(new CDVDMsg(CDVDMsg::PLAYER_STARTED), 1);
3250 /* software decoding normaly consumes full cpu time so prio it */
3251 m_omxPlayerAudio.SetPriority(GetPriority()+1);
3252 CMediaSettings::Get().GetCurrentVideoSettings().m_AudioStream = GetAudioStream();
3256 bool COMXPlayer::OpenVideoStream(int iStream, int source, bool reset)
3258 CLog::Log(LOGNOTICE, "Opening video stream: %i source: %i", iStream, source);
3262 CLog::Log(LOGWARNING, "Opening video stream: no demuxer");
3266 CDemuxStream* pStream = m_pDemuxer->GetStream(iStream);
3267 if(!pStream || pStream->disabled)
3269 CLog::Log(LOGWARNING, "Opening video stream: pStream=%p disabled=%d", pStream, pStream ? pStream->disabled:0);
3272 pStream->SetDiscard(AVDISCARD_NONE);
3274 CDVDStreamInfo hint(*pStream, true);
3276 if( m_pInputStream && m_pInputStream->IsStreamType(DVDSTREAM_TYPE_DVD) )
3278 /* set aspect ratio as requested by navigator for dvd's */
3279 float aspect = static_cast<CDVDInputStreamNavigator*>(m_pInputStream)->GetVideoAspectRatio();
3282 hint.aspect = aspect;
3283 hint.forced_aspect = true;
3285 hint.software = true;
3288 boost::shared_ptr<CPVRClient> client;
3289 if(m_pInputStream && m_pInputStream->IsStreamType(DVDSTREAM_TYPE_PVRMANAGER) &&
3290 pStream->type == STREAM_VIDEO &&
3291 g_PVRClients->GetPlayingClient(client) && client->HandlesDemuxing())
3293 // set the fps in hints
3294 const CDemuxStreamVideo *stream = static_cast<const CDemuxStreamVideo*>(pStream);
3295 hint.fpsrate = stream->iFpsRate;
3296 hint.fpsscale = stream->iFpsScale;
3299 CDVDInputStream::IMenus* pMenus = dynamic_cast<CDVDInputStream::IMenus*>(m_pInputStream);
3300 if(pMenus && pMenus->IsInMenu())
3303 if (hint.stereo_mode.empty())
3304 hint.stereo_mode = CStereoscopicsManager::Get().DetectStereoModeByString(m_filename);
3306 if(m_CurrentVideo.id < 0
3307 || m_CurrentVideo.hint != hint)
3309 if (!m_omxPlayerVideo.OpenStream(hint))
3311 /* mark stream as disabled, to disallaw further attempts */
3312 CLog::Log(LOGWARNING, "%s - Unsupported stream %d. Stream disabled.", __FUNCTION__, iStream);
3313 pStream->disabled = true;
3314 pStream->SetDiscard(AVDISCARD_ALL);
3319 m_omxPlayerVideo.SendMessage(new CDVDMsg(CDVDMsg::GENERAL_RESET));
3321 /* store information about stream */
3322 m_CurrentVideo.id = iStream;
3323 m_CurrentVideo.source = source;
3324 m_CurrentVideo.hint = hint;
3325 m_CurrentVideo.stream = (void*)pStream;
3326 m_CurrentVideo.started = false;
3329 /* we are potentially going to be waiting on this */
3330 m_omxPlayerVideo.SendMessage(new CDVDMsg(CDVDMsg::PLAYER_STARTED), 1);
3332 /* use same priority for video thread as demuxing thread, as */
3333 /* otherwise demuxer will starve if video consumes the full cpu */
3334 m_omxPlayerVideo.SetPriority(GetPriority());
3339 bool COMXPlayer::OpenSubtitleStream(int iStream, int source)
3341 CLog::Log(LOGNOTICE, "Opening Subtitle stream: %i source: %i", iStream, source);
3343 CDemuxStream* pStream = NULL;
3344 std::string filename;
3345 CDVDStreamInfo hint;
3347 if(STREAM_SOURCE_MASK(source) == STREAM_SOURCE_DEMUX_SUB)
3349 int index = m_SelectionStreams.IndexOf(STREAM_SUBTITLE, source, iStream);
3352 OMXSelectionStream st = m_SelectionStreams.Get(STREAM_SUBTITLE, index);
3354 if(!m_pSubtitleDemuxer || m_pSubtitleDemuxer->GetFileName() != st.filename)
3356 CLog::Log(LOGNOTICE, "Opening Subtitle file: %s", st.filename.c_str());
3357 auto_ptr<CDVDDemuxVobsub> demux(new CDVDDemuxVobsub());
3358 if(!demux->Open(st.filename, st.filename2))
3360 m_pSubtitleDemuxer = demux.release();
3363 pStream = m_pSubtitleDemuxer->GetStream(iStream);
3364 if(!pStream || pStream->disabled)
3366 pStream->SetDiscard(AVDISCARD_NONE);
3367 double pts = m_omxPlayerVideo.GetCurrentPts();
3368 if(pts == DVD_NOPTS_VALUE)
3369 pts = m_CurrentVideo.dts;
3370 if(pts == DVD_NOPTS_VALUE)
3372 pts += m_offset_pts;
3373 m_pSubtitleDemuxer->SeekTime((int)(1000.0 * pts / (double)DVD_TIME_BASE));
3375 hint.Assign(*pStream, true);
3377 else if(STREAM_SOURCE_MASK(source) == STREAM_SOURCE_TEXT)
3379 int index = m_SelectionStreams.IndexOf(STREAM_SUBTITLE, source, iStream);
3382 filename = m_SelectionStreams.Get(STREAM_SUBTITLE, index).filename;
3385 hint.fpsscale = m_CurrentVideo.hint.fpsscale;
3386 hint.fpsrate = m_CurrentVideo.hint.fpsrate;
3392 pStream = m_pDemuxer->GetStream(iStream);
3393 if(!pStream || pStream->disabled)
3395 pStream->SetDiscard(AVDISCARD_NONE);
3397 hint.Assign(*pStream, true);
3399 if(m_pInputStream && m_pInputStream->IsStreamType(DVDSTREAM_TYPE_DVD))
3403 if(m_CurrentSubtitle.id < 0
3404 || m_CurrentSubtitle.hint != hint)
3406 if(m_CurrentSubtitle.id >= 0)
3408 CLog::Log(LOGDEBUG, " - codecs hints have changed, must close previous stream");
3409 CloseSubtitleStream(false);
3412 if(!m_dvdPlayerSubtitle.OpenStream(hint, filename))
3414 CLog::Log(LOGWARNING, "%s - Unsupported stream %d. Stream disabled.", __FUNCTION__, iStream);
3417 pStream->disabled = true;
3418 pStream->SetDiscard(AVDISCARD_ALL);
3424 m_dvdPlayerSubtitle.SendMessage(new CDVDMsg(CDVDMsg::GENERAL_RESET));
3426 m_CurrentSubtitle.id = iStream;
3427 m_CurrentSubtitle.source = source;
3428 m_CurrentSubtitle.hint = hint;
3429 m_CurrentSubtitle.stream = (void*)pStream;
3430 m_CurrentSubtitle.started = false;
3432 CMediaSettings::Get().GetCurrentVideoSettings().m_SubtitleStream = GetSubtitle();
3436 bool COMXPlayer::AdaptForcedSubtitles()
3439 OMXSelectionStream ss = m_SelectionStreams.Get(STREAM_SUBTITLE, GetSubtitle());
3440 if (ss.flags & CDemuxStream::FLAG_FORCED || !GetSubtitleVisible())
3442 OMXSelectionStream as = m_SelectionStreams.Get(STREAM_AUDIO, GetAudioStream());
3443 OMXSelectionStreams streams = m_SelectionStreams.Get(STREAM_SUBTITLE);
3445 for(OMXSelectionStreams::iterator it = streams.begin(); it != streams.end() && !valid; ++it)
3447 if (it->flags & CDemuxStream::FLAG_FORCED && g_LangCodeExpander.CompareLangCodes(it->language, as.language))
3449 if(OpenSubtitleStream(it->id, it->source))
3452 SetSubtitleVisible(true);
3458 CloseSubtitleStream(true);
3459 SetSubtitleVisible(false);
3465 bool COMXPlayer::OpenTeletextStream(int iStream, int source)
3470 CDemuxStream* pStream = m_pDemuxer->GetStream(iStream);
3471 if(!pStream || pStream->disabled)
3474 CDVDStreamInfo hint(*pStream, true);
3476 if (!m_dvdPlayerTeletext.CheckStream(hint))
3479 CLog::Log(LOGNOTICE, "Opening teletext stream: %i source: %i", iStream, source);
3481 if(m_CurrentTeletext.id < 0
3482 || m_CurrentTeletext.hint != hint)
3484 if(m_CurrentTeletext.id >= 0)
3486 CLog::Log(LOGDEBUG, " - teletext codecs hints have changed, must close previous stream");
3487 CloseTeletextStream(true);
3490 if (!m_dvdPlayerTeletext.OpenStream(hint))
3492 /* mark stream as disabled, to disallaw further attempts*/
3493 CLog::Log(LOGWARNING, "%s - Unsupported teletext stream %d. Stream disabled.", __FUNCTION__, iStream);
3494 pStream->disabled = true;
3495 pStream->SetDiscard(AVDISCARD_ALL);
3500 m_dvdPlayerTeletext.SendMessage(new CDVDMsg(CDVDMsg::GENERAL_RESET));
3502 /* store information about stream */
3503 m_CurrentTeletext.id = iStream;
3504 m_CurrentTeletext.source = source;
3505 m_CurrentTeletext.hint = hint;
3506 m_CurrentTeletext.stream = (void*)pStream;
3507 m_CurrentTeletext.started = false;
3512 bool COMXPlayer::CloseAudioStream(bool bWaitForBuffers)
3514 if (m_CurrentAudio.id < 0)
3517 CLog::Log(LOGNOTICE, "Closing audio stream");
3520 SetCaching(CACHESTATE_DONE);
3522 m_omxPlayerAudio.CloseStream(bWaitForBuffers);
3524 m_CurrentAudio.Clear();
3528 bool COMXPlayer::CloseVideoStream(bool bWaitForBuffers)
3530 if (m_CurrentVideo.id < 0)
3533 CLog::Log(LOGNOTICE, "Closing video stream");
3536 SetCaching(CACHESTATE_DONE);
3538 m_omxPlayerVideo.CloseStream(bWaitForBuffers);
3540 m_CurrentVideo.Clear();
3544 bool COMXPlayer::CloseSubtitleStream(bool bKeepOverlays)
3546 if (m_CurrentSubtitle.id < 0)
3549 CLog::Log(LOGNOTICE, "Closing subtitle stream");
3551 m_dvdPlayerSubtitle.CloseStream(!bKeepOverlays);
3553 m_CurrentSubtitle.Clear();
3557 bool COMXPlayer::CloseTeletextStream(bool bWaitForBuffers)
3559 if (m_CurrentTeletext.id < 0)
3562 CLog::Log(LOGNOTICE, "Closing teletext stream");
3565 SetCaching(CACHESTATE_DONE);
3567 m_dvdPlayerTeletext.CloseStream(bWaitForBuffers);
3569 m_CurrentTeletext.Clear();
3573 void COMXPlayer::FlushBuffers(bool queued, double pts, bool accurate)
3577 CLog::Log(LOGNOTICE, "FlushBuffers: q:%d pts:%.0f a:%d", queued, pts, accurate);
3579 if (!TP(m_playSpeed))
3580 m_av_clock.OMXStop();
3581 m_av_clock.OMXPause();
3584 /* for now, ignore accurate flag as it discards keyframes and causes corrupt frames */
3588 startpts = DVD_NOPTS_VALUE;
3590 /* call with demuxer pts */
3591 if(startpts != DVD_NOPTS_VALUE)
3592 startpts -= m_offset_pts;
3594 m_CurrentAudio.inited = false;
3595 m_CurrentAudio.dts = DVD_NOPTS_VALUE;
3596 m_CurrentAudio.startpts = startpts;
3598 m_CurrentVideo.inited = false;
3599 m_CurrentVideo.dts = DVD_NOPTS_VALUE;
3600 m_CurrentVideo.startpts = startpts;
3602 m_CurrentSubtitle.inited = false;
3603 m_CurrentSubtitle.dts = DVD_NOPTS_VALUE;
3604 m_CurrentSubtitle.startpts = startpts;
3606 m_CurrentTeletext.inited = false;
3607 m_CurrentTeletext.dts = DVD_NOPTS_VALUE;
3608 m_CurrentTeletext.startpts = startpts;
3612 m_omxPlayerAudio.SendMessage(new CDVDMsg(CDVDMsg::GENERAL_RESET));
3613 m_omxPlayerVideo.SendMessage(new CDVDMsg(CDVDMsg::GENERAL_RESET));
3614 m_omxPlayerVideo.SendMessage(new CDVDMsg(CDVDMsg::VIDEO_NOSKIP));
3615 m_dvdPlayerSubtitle.SendMessage(new CDVDMsg(CDVDMsg::GENERAL_RESET));
3616 m_dvdPlayerTeletext.SendMessage(new CDVDMsg(CDVDMsg::GENERAL_RESET));
3617 SynchronizePlayers(SYNCSOURCE_ALL);
3621 m_omxPlayerAudio.Flush();
3622 m_omxPlayerVideo.Flush();
3623 m_dvdPlayerSubtitle.Flush();
3624 m_dvdPlayerTeletext.Flush();
3626 // clear subtitle and menu overlays
3627 m_overlayContainer.Clear();
3629 if(m_playSpeed == DVD_PLAYSPEED_NORMAL
3630 || m_playSpeed == DVD_PLAYSPEED_PAUSE)
3632 // make sure players are properly flushed, should put them in stalled state
3633 CDVDMsgGeneralSynchronize* msg = new CDVDMsgGeneralSynchronize(1000, 0);
3634 m_omxPlayerAudio.SendMessage(msg->Acquire(), 1);
3635 m_omxPlayerVideo.SendMessage(msg->Acquire(), 1);
3636 msg->Wait(&m_bStop, 0);
3639 // purge any pending PLAYER_STARTED messages
3640 m_messenger.Flush(CDVDMsg::PLAYER_STARTED);
3642 // we should now wait for init cache
3643 SetCaching(CACHESTATE_FLUSH);
3644 m_CurrentAudio.started = false;
3645 m_CurrentVideo.started = false;
3646 m_CurrentSubtitle.started = false;
3647 m_CurrentTeletext.started = false;
3650 if(pts != DVD_NOPTS_VALUE)
3651 m_clock.Discontinuity(pts);
3654 // update state, buffers are flushed and it may take some time until
3655 // we get an update from players
3656 CSingleLock lock(m_StateSection);
3657 m_State = m_StateInput;
3661 // since we call ffmpeg functions to decode, this is being called in the same thread as ::Process() is
3662 int COMXPlayer::OnDVDNavResult(void* pData, int iMessage)
3664 if (m_pInputStream->IsStreamType(DVDSTREAM_TYPE_BLURAY))
3667 m_overlayContainer.Add((CDVDOverlay*)pData);
3668 else if(iMessage == 1)
3669 m_messenger.Put(new CDVDMsg(CDVDMsg::GENERAL_FLUSH));
3670 else if(iMessage == 2)
3671 m_dvd.iSelectedAudioStream = *(int*)pData;
3672 else if(iMessage == 3)
3673 m_dvd.iSelectedSPUStream = *(int*)pData;
3674 else if(iMessage == 4)
3675 m_omxPlayerVideo.EnableSubtitle(*(int*)pData ? true: false);
3676 else if(iMessage == 5)
3678 if (m_dvd.state != DVDSTATE_STILL)
3680 // else notify the player we have received a still frame
3682 m_dvd.iDVDStillTime = *(int*)pData;
3683 m_dvd.iDVDStillStartTime = XbmcThreads::SystemClockMillis();
3685 /* adjust for the output delay in the video queue */
3686 unsigned int time = 0;
3687 if( m_CurrentVideo.stream && m_dvd.iDVDStillTime > 0 )
3689 time = (unsigned int)(m_omxPlayerVideo.GetOutputDelay() / ( DVD_TIME_BASE / 1000 ));
3690 if( time < 10000 && time > 0 )
3691 m_dvd.iDVDStillTime += time;
3693 m_dvd.state = DVDSTATE_STILL;
3695 "DVDNAV_STILL_FRAME - waiting %i sec, with delay of %d sec",
3696 m_dvd.iDVDStillTime, time / 1000);
3703 if (m_pInputStream->IsStreamType(DVDSTREAM_TYPE_DVD))
3705 CDVDInputStreamNavigator* pStream = (CDVDInputStreamNavigator*)m_pInputStream;
3709 case DVDNAV_STILL_FRAME:
3711 //CLog::Log(LOGDEBUG, "DVDNAV_STILL_FRAME");
3713 dvdnav_still_event_t *still_event = (dvdnav_still_event_t *)pData;
3714 // should wait the specified time here while we let the player running
3715 // after that call dvdnav_still_skip(m_dvdnav);
3717 if (m_dvd.state != DVDSTATE_STILL)
3719 // else notify the player we have received a still frame
3721 if(still_event->length < 0xff)
3722 m_dvd.iDVDStillTime = still_event->length * 1000;
3724 m_dvd.iDVDStillTime = 0;
3726 m_dvd.iDVDStillStartTime = XbmcThreads::SystemClockMillis();
3728 /* adjust for the output delay in the video queue */
3729 unsigned int time = 0;
3730 if( m_CurrentVideo.stream && m_dvd.iDVDStillTime > 0 )
3732 time = (unsigned int)(m_omxPlayerVideo.GetOutputDelay() / ( DVD_TIME_BASE / 1000 ));
3733 if( time < 10000 && time > 0 )
3734 m_dvd.iDVDStillTime += time;
3736 m_dvd.state = DVDSTATE_STILL;
3738 "DVDNAV_STILL_FRAME - waiting %i sec, with delay of %d sec",
3739 still_event->length, time / 1000);
3741 return NAVRESULT_HOLD;
3744 case DVDNAV_SPU_CLUT_CHANGE:
3746 m_dvdPlayerSubtitle.SendMessage(new CDVDMsgSubtitleClutChange((uint8_t*)pData));
3749 case DVDNAV_SPU_STREAM_CHANGE:
3751 dvdnav_spu_stream_change_event_t* event = (dvdnav_spu_stream_change_event_t*)pData;
3753 int iStream = event->physical_wide;
3754 bool visible = !(iStream & 0x80);
3756 SetSubtitleVisible(visible);
3759 m_dvd.iSelectedSPUStream = (iStream & ~0x80);
3761 m_dvd.iSelectedSPUStream = -1;
3763 m_CurrentSubtitle.stream = NULL;
3766 case DVDNAV_AUDIO_STREAM_CHANGE:
3768 // This should be the correct way i think, however we don't have any streams right now
3769 // since the demuxer hasn't started so it doesn't change. not sure how to do this.
3770 dvdnav_audio_stream_change_event_t* event = (dvdnav_audio_stream_change_event_t*)pData;
3772 // Tell system what audiostream should be opened by default
3773 if (event->logical >= 0)
3774 m_dvd.iSelectedAudioStream = event->physical;
3776 m_dvd.iSelectedAudioStream = -1;
3778 m_CurrentAudio.stream = NULL;
3781 case DVDNAV_HIGHLIGHT:
3783 //dvdnav_highlight_event_t* pInfo = (dvdnav_highlight_event_t*)pData;
3784 int iButton = pStream->GetCurrentButton();
3785 CLog::Log(LOGDEBUG, "DVDNAV_HIGHLIGHT: Highlight button %d\n", iButton);
3786 m_dvdPlayerSubtitle.UpdateOverlayInfo((CDVDInputStreamNavigator*)m_pInputStream, LIBDVDNAV_BUTTON_NORMAL);
3789 case DVDNAV_VTS_CHANGE:
3791 //dvdnav_vts_change_event_t* vts_change_event = (dvdnav_vts_change_event_t*)pData;
3792 CLog::Log(LOGDEBUG, "DVDNAV_VTS_CHANGE");
3794 //Make sure we clear all the old overlays here, or else old forced items are left.
3795 m_overlayContainer.Clear();
3797 //Force an aspect ratio that is set in the dvdheaders if available
3798 m_CurrentVideo.hint.aspect = pStream->GetVideoAspectRatio();
3799 if( m_omxPlayerVideo.IsInited() )
3800 m_omxPlayerVideo.SendMessage(new CDVDMsgDouble(CDVDMsg::VIDEO_SET_ASPECT, m_CurrentVideo.hint.aspect));
3802 m_SelectionStreams.Clear(STREAM_NONE, STREAM_SOURCE_NAV);
3803 m_SelectionStreams.Update(m_pInputStream, m_pDemuxer);
3805 return NAVRESULT_HOLD;
3808 case DVDNAV_CELL_CHANGE:
3810 //dvdnav_cell_change_event_t* cell_change_event = (dvdnav_cell_change_event_t*)pData;
3811 CLog::Log(LOGDEBUG, "DVDNAV_CELL_CHANGE");
3813 m_dvd.state = DVDSTATE_NORMAL;
3815 if( m_omxPlayerVideo.IsInited() )
3816 m_omxPlayerVideo.SendMessage(new CDVDMsg(CDVDMsg::VIDEO_NOSKIP));
3819 case DVDNAV_NAV_PACKET:
3821 //pci_t* pci = (pci_t*)pData;
3823 // this should be possible to use to make sure we get
3824 // seamless transitions over these boundaries
3825 // if we remember the old vobunits boundaries
3826 // when a packet comes out of demuxer that has
3827 // pts values outside that boundary, it belongs
3828 // to the new vobunit, wich has new timestamps
3832 case DVDNAV_HOP_CHANNEL:
3834 // This event is issued whenever a non-seamless operation has been executed.
3835 // Applications with fifos should drop the fifos content to speed up responsiveness.
3836 CLog::Log(LOGDEBUG, "DVDNAV_HOP_CHANNEL");
3837 if(m_dvd.state == DVDSTATE_SEEK)
3838 m_dvd.state = DVDSTATE_NORMAL;
3840 m_messenger.Put(new CDVDMsg(CDVDMsg::GENERAL_FLUSH));
3842 return NAVRESULT_ERROR;
3847 CLog::Log(LOGDEBUG, "DVDNAV_STOP");
3848 m_dvd.state = DVDSTATE_NORMAL;
3856 return NAVRESULT_NOP;
3859 bool COMXPlayer::ShowPVRChannelInfo(void)
3861 bool bReturn(false);
3863 if (CSettings::Get().GetBool("pvrmenu.infoswitch"))
3865 int iTimeout = CSettings::Get().GetBool("pvrmenu.infotimeout") ? CSettings::Get().GetInt("pvrmenu.infotime") : 0;
3866 g_PVRManager.ShowPlayerInfo(iTimeout);
3874 bool COMXPlayer::OnAction(const CAction &action)
3876 #define THREAD_ACTION(action) \
3878 if (!IsCurrentThread()) { \
3879 m_messenger.Put(new CDVDMsgType<CAction>(CDVDMsg::GENERAL_GUI_ACTION, action)); \
3884 CDVDInputStream::IMenus* pMenus = dynamic_cast<CDVDInputStream::IMenus*>(m_pInputStream);
3887 if( m_dvd.state == DVDSTATE_STILL && m_dvd.iDVDStillTime != 0 && pMenus->GetTotalButtons() == 0 )
3889 switch(action.GetID())
3891 case ACTION_NEXT_ITEM:
3892 case ACTION_MOVE_RIGHT:
3893 case ACTION_MOVE_UP:
3894 case ACTION_SELECT_ITEM:
3896 THREAD_ACTION(action);
3897 /* this will force us out of the stillframe */
3898 CLog::Log(LOGDEBUG, "%s - User asked to exit stillframe", __FUNCTION__);
3899 m_dvd.iDVDStillStartTime = 0;
3900 m_dvd.iDVDStillTime = 1;
3907 switch (action.GetID())
3909 /* this code is disabled to allow switching playlist items (dvdimage "stacks") */
3911 case ACTION_PREV_ITEM: // SKIP-:
3913 THREAD_ACTION(action);
3914 CLog::Log(LOGDEBUG, " - pushed prev");
3915 pMenus->OnPrevious();
3916 g_infoManager.SetDisplayAfterSeek();
3920 case ACTION_NEXT_ITEM: // SKIP+:
3922 THREAD_ACTION(action);
3923 CLog::Log(LOGDEBUG, " - pushed next");
3925 g_infoManager.SetDisplayAfterSeek();
3930 case ACTION_SHOW_VIDEOMENU: // start button
3932 THREAD_ACTION(action);
3933 CLog::Log(LOGDEBUG, " - go to menu");
3935 if (m_playSpeed == DVD_PLAYSPEED_PAUSE)
3937 SetPlaySpeed(DVD_PLAYSPEED_NORMAL);
3938 m_callback.OnPlayBackResumed();
3940 // send a message to everyone that we've gone to the menu
3941 CGUIMessage msg(GUI_MSG_VIDEO_MENU_STARTED, 0, 0);
3942 g_windowManager.SendThreadMessage(msg);
3948 if (pMenus->IsInMenu())
3950 switch (action.GetID())
3952 case ACTION_NEXT_ITEM:
3953 THREAD_ACTION(action);
3954 CLog::Log(LOGDEBUG, " - pushed next in menu, stream will decide");
3956 g_infoManager.SetDisplayAfterSeek();
3958 case ACTION_PREV_ITEM:
3959 THREAD_ACTION(action);
3960 CLog::Log(LOGDEBUG, " - pushed prev in menu, stream will decide");
3961 pMenus->OnPrevious();
3962 g_infoManager.SetDisplayAfterSeek();
3964 case ACTION_PREVIOUS_MENU:
3965 case ACTION_NAV_BACK:
3967 THREAD_ACTION(action);
3968 CLog::Log(LOGDEBUG, " - menu back");
3972 case ACTION_MOVE_LEFT:
3974 THREAD_ACTION(action);
3975 CLog::Log(LOGDEBUG, " - move left");
3979 case ACTION_MOVE_RIGHT:
3981 THREAD_ACTION(action);
3982 CLog::Log(LOGDEBUG, " - move right");
3986 case ACTION_MOVE_UP:
3988 THREAD_ACTION(action);
3989 CLog::Log(LOGDEBUG, " - move up");
3993 case ACTION_MOVE_DOWN:
3995 THREAD_ACTION(action);
3996 CLog::Log(LOGDEBUG, " - move down");
4001 case ACTION_MOUSE_MOVE:
4002 case ACTION_MOUSE_LEFT_CLICK:
4005 g_renderManager.GetVideoRect(rs, rd);
4006 CPoint pt(action.GetAmount(), action.GetAmount(1));
4007 if (!rd.PtInRect(pt))
4008 return false; // out of bounds
4009 THREAD_ACTION(action);
4010 // convert to video coords...
4011 pt -= CPoint(rd.x1, rd.y1);
4012 pt.x *= rs.Width() / rd.Width();
4013 pt.y *= rs.Height() / rd.Height();
4014 pt += CPoint(rs.x1, rs.y1);
4015 if (action.GetID() == ACTION_MOUSE_LEFT_CLICK)
4016 return pMenus->OnMouseClick(pt);
4017 return pMenus->OnMouseMove(pt);
4020 case ACTION_SELECT_ITEM:
4022 THREAD_ACTION(action);
4023 CLog::Log(LOGDEBUG, " - button select");
4024 // show button pushed overlay
4025 if(m_pInputStream->IsStreamType(DVDSTREAM_TYPE_DVD))
4026 m_dvdPlayerSubtitle.UpdateOverlayInfo((CDVDInputStreamNavigator*)m_pInputStream, LIBDVDNAV_BUTTON_CLICKED);
4028 pMenus->ActivateButton();
4042 THREAD_ACTION(action);
4043 // Offset from key codes back to button number
4044 int button = action.GetID() - REMOTE_0;
4045 CLog::Log(LOGDEBUG, " - button pressed %d", button);
4046 pMenus->SelectButton(button);
4053 return true; // message is handled
4057 if (dynamic_cast<CDVDInputStream::IChannel*>(m_pInputStream))
4059 switch (action.GetID())
4061 case ACTION_MOVE_UP:
4062 case ACTION_NEXT_ITEM:
4063 case ACTION_CHANNEL_UP:
4064 m_messenger.Put(new CDVDMsg(CDVDMsg::PLAYER_CHANNEL_NEXT));
4065 g_infoManager.SetDisplayAfterSeek();
4066 ShowPVRChannelInfo();
4070 case ACTION_MOVE_DOWN:
4071 case ACTION_PREV_ITEM:
4072 case ACTION_CHANNEL_DOWN:
4073 m_messenger.Put(new CDVDMsg(CDVDMsg::PLAYER_CHANNEL_PREV));
4074 g_infoManager.SetDisplayAfterSeek();
4075 ShowPVRChannelInfo();
4079 case ACTION_CHANNEL_SWITCH:
4081 // Offset from key codes back to button number
4082 int channel = action.GetAmount();
4083 m_messenger.Put(new CDVDMsgInt(CDVDMsg::PLAYER_CHANNEL_SELECT_NUMBER, channel));
4084 g_infoManager.SetDisplayAfterSeek();
4085 ShowPVRChannelInfo();
4092 switch (action.GetID())
4094 case ACTION_NEXT_ITEM:
4095 if (GetChapter() > 0 && GetChapter() < GetChapterCount())
4097 m_messenger.Put(new CDVDMsgPlayerSeekChapter(GetChapter() + 1));
4098 g_infoManager.SetDisplayAfterSeek();
4103 case ACTION_PREV_ITEM:
4104 if (GetChapter() > 0)
4106 m_messenger.Put(new CDVDMsgPlayerSeekChapter(GetChapter() - 1));
4107 g_infoManager.SetDisplayAfterSeek();
4114 // return false to inform the caller we didn't handle the message
4118 bool COMXPlayer::IsInMenu() const
4120 CDVDInputStream::IMenus* pStream = dynamic_cast<CDVDInputStream::IMenus*>(m_pInputStream);
4123 if( m_dvd.state == DVDSTATE_STILL )
4126 return pStream->IsInMenu();
4131 bool COMXPlayer::HasMenu()
4133 CDVDInputStream::IMenus* pStream = dynamic_cast<CDVDInputStream::IMenus*>(m_pInputStream);
4140 CStdString COMXPlayer::GetPlayerState()
4142 CSingleLock lock(m_StateSection);
4143 return m_State.player_state;
4146 bool COMXPlayer::SetPlayerState(CStdString state)
4148 m_messenger.Put(new CDVDMsgPlayerSetState(state));
4152 int COMXPlayer::GetChapterCount()
4154 CSingleLock lock(m_StateSection);
4155 return m_State.chapter_count;
4158 int COMXPlayer::GetChapter()
4160 CSingleLock lock(m_StateSection);
4161 return m_State.chapter;
4164 void COMXPlayer::GetChapterName(CStdString& strChapterName)
4166 CSingleLock lock(m_StateSection);
4167 strChapterName = m_State.chapter_name;
4170 int COMXPlayer::SeekChapter(int iChapter)
4172 if (GetChapter() > 0)
4176 if (iChapter > GetChapterCount())
4179 // Seek to the chapter.
4180 m_messenger.Put(new CDVDMsgPlayerSeekChapter(iChapter));
4181 SynchronizeDemuxer(100);
4187 int COMXPlayer::AddSubtitle(const CStdString& strSubPath)
4189 return AddSubtitleFile(strSubPath);
4192 int COMXPlayer::GetCacheLevel() const
4194 CSingleLock lock(m_StateSection);
4195 return (int)(m_StateInput.cache_level * 100);
4198 double COMXPlayer::GetQueueTime()
4200 int a = m_omxPlayerAudio.GetLevel();
4201 int v = m_omxPlayerVideo.GetLevel();
4202 return max(a, v) * 8000.0 / 100;
4205 void COMXPlayer::GetVideoStreamInfo(SPlayerVideoStreamInfo &info)
4207 info.bitrate = m_omxPlayerVideo.GetVideoBitrate();
4210 if (m_pDemuxer && (m_CurrentVideo.id != -1))
4212 m_pDemuxer->GetStreamCodecName(m_CurrentVideo.id, retVal);
4213 CDemuxStreamVideo* stream = static_cast<CDemuxStreamVideo*>(m_pDemuxer->GetStream(m_CurrentVideo.id));
4216 info.width = stream->iWidth;
4217 info.height = stream->iHeight;
4220 info.videoCodecName = retVal;
4221 info.videoAspectRatio = g_renderManager.GetAspectRatio();
4222 g_renderManager.GetVideoRect(info.SrcRect, info.DestRect);
4223 info.stereoMode = m_omxPlayerVideo.GetStereoMode();
4224 if (info.stereoMode == "mono")
4225 info.stereoMode = "";
4228 int COMXPlayer::GetSourceBitrate()
4231 return (int)m_pInputStream->GetBitstreamStats().GetBitrate();
4236 void COMXPlayer::GetAudioStreamInfo(int index, SPlayerAudioStreamInfo &info)
4238 if (index < 0 || index > GetAudioStreamCount() - 1)
4241 if (index == GetAudioStream())
4242 info.bitrate = m_omxPlayerAudio.GetAudioBitrate();
4243 else if (m_pDemuxer)
4245 CDemuxStreamAudio* stream = m_pDemuxer->GetStreamFromAudioId(index);
4247 info.bitrate = stream->iBitRate;
4250 OMXSelectionStream& s = m_SelectionStreams.Get(STREAM_AUDIO, index);
4251 if(s.language.length() > 0)
4252 info.language = s.language;
4254 if(s.name.length() > 0)
4257 if(s.type == STREAM_NONE)
4258 info.name += " (Invalid)";
4262 CDemuxStreamAudio* stream = static_cast<CDemuxStreamAudio*>(m_pDemuxer->GetStreamFromAudioId(index));
4265 info.channels = stream->iChannels;
4266 CStdString codecName;
4267 m_pDemuxer->GetStreamCodecName(stream->iId, codecName);
4268 info.audioCodecName = codecName;
4273 int COMXPlayer::AddSubtitleFile(const std::string& filename, const std::string& subfilename, CDemuxStream::EFlags flags)
4275 std::string ext = URIUtils::GetExtension(filename);
4276 std::string vobsubfile = subfilename;
4279 if (vobsubfile.empty())
4280 vobsubfile = URIUtils::ReplaceExtension(filename, ".sub");
4283 if(!v.Open(filename, vobsubfile))
4285 m_SelectionStreams.Update(NULL, &v);
4286 int index = m_SelectionStreams.IndexOf(STREAM_SUBTITLE, m_SelectionStreams.Source(STREAM_SOURCE_DEMUX_SUB, filename), 0);
4287 m_SelectionStreams.Get(STREAM_SUBTITLE, index).flags = flags;
4288 m_SelectionStreams.Get(STREAM_SUBTITLE, index).filename2 = vobsubfile;
4289 ExternalStreamInfo info;
4290 CUtil::GetExternalStreamDetailsFromFilename(m_filename, vobsubfile, info);
4291 m_SelectionStreams.Get(STREAM_SUBTITLE, index).name = info.name;
4292 if (m_SelectionStreams.Get(STREAM_SUBTITLE, index).language.empty())
4293 m_SelectionStreams.Get(STREAM_SUBTITLE, index).language = info.language;
4295 if (static_cast<CDemuxStream::EFlags>(info.flag) == CDemuxStream::FLAG_NONE)
4296 m_SelectionStreams.Get(STREAM_SUBTITLE, index).flags = flags;
4298 m_SelectionStreams.Get(STREAM_SUBTITLE, index).flags = static_cast<CDemuxStream::EFlags>(info.flag);
4304 CStdString strReplace(URIUtils::ReplaceExtension(filename,".idx"));
4305 if (XFILE::CFile::Exists(strReplace))
4308 OMXSelectionStream s;
4309 s.source = m_SelectionStreams.Source(STREAM_SOURCE_TEXT, filename);
4310 s.type = STREAM_SUBTITLE;
4312 s.filename = filename;
4313 ExternalStreamInfo info;
4314 CUtil::GetExternalStreamDetailsFromFilename(m_filename, filename, info);
4316 s.language = info.language;
4317 if (static_cast<CDemuxStream::EFlags>(info.flag) == CDemuxStream::FLAG_NONE)
4320 s.flags = static_cast<CDemuxStream::EFlags>(info.flag);
4322 m_SelectionStreams.Update(s);
4323 return m_SelectionStreams.IndexOf(STREAM_SUBTITLE, s.source, s.id);
4326 void COMXPlayer::UpdatePlayState(double timeout)
4328 if(m_StateInput.timestamp != 0
4329 && m_StateInput.timestamp + DVD_MSEC_TO_TIME(timeout) > m_clock.GetAbsoluteClock())
4332 SPlayerState state(m_StateInput);
4334 if (m_CurrentVideo.dts != DVD_NOPTS_VALUE)
4335 state.dts = m_CurrentVideo.dts;
4336 else if(m_CurrentAudio.dts != DVD_NOPTS_VALUE)
4337 state.dts = m_CurrentAudio.dts;
4341 state.chapter = m_pDemuxer->GetChapter();
4342 state.chapter_count = m_pDemuxer->GetChapterCount();
4343 m_pDemuxer->GetChapterName(state.chapter_name);
4345 if(state.dts == DVD_NOPTS_VALUE)
4348 state.time = DVD_TIME_TO_MSEC(state.dts + m_offset_pts);
4349 state.time_total = m_pDemuxer->GetStreamLength();
4350 state.time_src = ETIMESOURCE_CLOCK;
4353 state.canpause = true;
4354 state.canseek = true;
4358 // override from input stream if needed
4359 CDVDInputStream::IChannel* pChannel = dynamic_cast<CDVDInputStream::IChannel*>(m_pInputStream);
4362 state.canrecord = pChannel->CanRecord();
4363 state.recording = pChannel->IsRecording();
4366 CDVDInputStream::IDisplayTime* pDisplayTime = dynamic_cast<CDVDInputStream::IDisplayTime*>(m_pInputStream);
4367 if (pDisplayTime && pDisplayTime->GetTotalTime() > 0)
4369 state.time = pDisplayTime->GetTime();
4370 state.time_total = pDisplayTime->GetTotalTime();
4371 state.time_src = ETIMESOURCE_INPUT;
4374 if (CDVDInputStream::IMenus* ptr = dynamic_cast<CDVDInputStream::IMenus*>(m_pInputStream))
4376 if(!ptr->GetState(state.player_state))
4377 state.player_state = "";
4379 if(m_dvd.state == DVDSTATE_STILL)
4381 state.time = XbmcThreads::SystemClockMillis() - m_dvd.iDVDStillStartTime;
4382 state.time_total = m_dvd.iDVDStillTime;
4383 state.time_src = ETIMESOURCE_MENU;
4387 if (CDVDInputStream::ISeekable* ptr = dynamic_cast<CDVDInputStream::ISeekable*>(m_pInputStream))
4389 state.canpause = ptr->CanPause();
4390 state.canseek = ptr->CanSeek();
4396 state.time = m_Edl.RemoveCutTime(llrint(state.time));
4397 state.time_total = m_Edl.RemoveCutTime(llrint(state.time_total));
4400 if(state.time_total <= 0)
4401 state.canseek = false;
4403 if (state.time_src == ETIMESOURCE_CLOCK)
4404 state.time_offset = m_offset_pts;
4405 else if (state.dts != DVD_NOPTS_VALUE)
4406 state.time_offset = DVD_MSEC_TO_TIME(state.time) - state.dts;
4408 if (m_CurrentAudio.id >= 0 && m_pDemuxer)
4410 CDemuxStream* pStream = m_pDemuxer->GetStream(m_CurrentAudio.id);
4411 if (pStream && pStream->type == STREAM_AUDIO)
4412 ((CDemuxStreamAudio*)pStream)->GetStreamInfo(state.demux_audio);
4415 state.demux_audio = "";
4417 if (m_CurrentVideo.id >= 0 && m_pDemuxer)
4419 CDemuxStream* pStream = m_pDemuxer->GetStream(m_CurrentVideo.id);
4420 if (pStream && pStream->type == STREAM_VIDEO)
4421 ((CDemuxStreamVideo*)pStream)->GetStreamInfo(state.demux_video);
4424 state.demux_video = "";
4426 double level, delay, offset;
4427 if(GetCachingTimes(level, delay, offset))
4429 state.cache_delay = max(0.0, delay);
4430 state.cache_level = max(0.0, min(1.0, level));
4431 state.cache_offset = offset;
4435 state.cache_delay = 0.0;
4436 state.cache_level = min(1.0, GetQueueTime() / 8000.0);
4437 state.cache_offset = GetQueueTime() / state.time_total;
4440 XFILE::SCacheStatus status;
4441 if(m_pInputStream && m_pInputStream->GetCacheStatus(&status))
4443 state.cache_bytes = status.forward;
4444 if(state.time_total)
4445 state.cache_bytes += m_pInputStream->GetLength() * GetQueueTime() / state.time_total;
4448 state.cache_bytes = 0;
4450 state.timestamp = m_clock.GetAbsoluteClock();
4451 //{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)));}
4453 CSingleLock lock(m_StateSection);
4454 m_StateInput = state;
4457 void COMXPlayer::UpdateApplication(double timeout)
4459 if(m_UpdateApplication != 0
4460 && m_UpdateApplication + DVD_MSEC_TO_TIME(timeout) > m_clock.GetAbsoluteClock())
4463 CDVDInputStream::IChannel* pStream = dynamic_cast<CDVDInputStream::IChannel*>(m_pInputStream);
4466 CFileItem item(g_application.CurrentFileItem());
4467 if(pStream->UpdateItem(item))
4469 g_application.CurrentFileItem() = item;
4470 CApplicationMessenger::Get().SetCurrentItem(item);
4473 m_UpdateApplication = m_clock.GetAbsoluteClock();
4476 bool COMXPlayer::CanRecord()
4478 CSingleLock lock(m_StateSection);
4479 return m_State.canrecord;
4482 bool COMXPlayer::IsRecording()
4484 CSingleLock lock(m_StateSection);
4485 return m_State.recording;
4488 bool COMXPlayer::Record(bool bOnOff)
4490 if (m_pInputStream && (m_pInputStream->IsStreamType(DVDSTREAM_TYPE_TV) ||
4491 m_pInputStream->IsStreamType(DVDSTREAM_TYPE_PVRMANAGER)) )
4493 m_messenger.Put(new CDVDMsgBool(CDVDMsg::PLAYER_SET_RECORD, bOnOff));
4499 bool COMXPlayer::GetStreamDetails(CStreamDetails &details)
4503 std::vector<OMXSelectionStream> subs = m_SelectionStreams.Get(STREAM_SUBTITLE);
4504 std::vector<CStreamDetailSubtitle> extSubDetails;
4505 for (unsigned int i = 0; i < subs.size(); i++)
4507 if (subs[i].filename == m_filename)
4510 CStreamDetailSubtitle p;
4511 p.m_strLanguage = subs[i].language;
4512 extSubDetails.push_back(p);
4515 bool result = CDVDFileInfo::DemuxerToStreamDetails(m_pInputStream, m_pDemuxer, extSubDetails, details);
4516 if (result && details.GetStreamCount(CStreamDetail::VIDEO) > 0) // this is more correct (dvds in particular)
4519 * We can only obtain the aspect & duration from dvdplayer when the Process() thread is running
4520 * and UpdatePlayState() has been called at least once. In this case dvdplayer duration/AR will
4521 * return 0 and we'll have to fallback to the (less accurate) info from the demuxer.
4523 float aspect = m_omxPlayerVideo.GetAspectRatio();
4525 ((CStreamDetailVideo*)details.GetNthStream(CStreamDetail::VIDEO,0))->m_fAspect = aspect;
4527 int64_t duration = GetTotalTime() / 1000;
4529 ((CStreamDetailVideo*)details.GetNthStream(CStreamDetail::VIDEO,0))->m_iDuration = duration;
4537 CStdString COMXPlayer::GetPlayingTitle()
4539 /* Currently we support only Title Name from Teletext line 30 */
4540 TextCacheStruct_t* ttcache = m_dvdPlayerTeletext.GetTeletextCache();
4541 if (ttcache && !ttcache->line30.empty())
4542 return ttcache->line30;
4547 bool COMXPlayer::SwitchChannel(const CPVRChannel &channel)
4549 if (!g_PVRManager.CheckParentalLock(channel))
4553 if (!g_PVRManager.PerformChannelSwitch(channel, true))
4556 UpdateApplication(0);
4559 /* make sure the pvr window is updated */
4560 CGUIWindowPVR *pWindow = (CGUIWindowPVR *) g_windowManager.GetWindow(WINDOW_PVR);
4562 pWindow->SetInvalid();
4564 /* select the new channel */
4565 m_messenger.Put(new CDVDMsgType<CPVRChannel>(CDVDMsg::PLAYER_CHANNEL_SELECT, channel));
4570 bool COMXPlayer::CachePVRStream(void) const
4572 return m_pInputStream->IsStreamType(DVDSTREAM_TYPE_PVRMANAGER) &&
4573 !g_PVRManager.IsPlayingRecording() &&
4574 g_advancedSettings.m_bPVRCacheInDvdPlayer;
4577 void COMXPlayer::GetRenderFeatures(std::vector<int> &renderFeatures)
4579 renderFeatures.push_back(RENDERFEATURE_STRETCH);
4580 renderFeatures.push_back(RENDERFEATURE_CROP);
4581 renderFeatures.push_back(RENDERFEATURE_PIXEL_RATIO);
4582 renderFeatures.push_back(RENDERFEATURE_ZOOM);
4585 void COMXPlayer::GetDeinterlaceMethods(std::vector<int> &deinterlaceMethods)
4587 deinterlaceMethods.push_back(VS_INTERLACEMETHOD_DEINTERLACE);
4590 void COMXPlayer::GetDeinterlaceModes(std::vector<int> &deinterlaceModes)
4592 deinterlaceModes.push_back(VS_DEINTERLACEMODE_AUTO);
4593 deinterlaceModes.push_back(VS_DEINTERLACEMODE_OFF);
4594 deinterlaceModes.push_back(VS_DEINTERLACEMODE_FORCE);
4597 void COMXPlayer::GetScalingMethods(std::vector<int> &scalingMethods)
4601 void COMXPlayer::GetAudioCapabilities(std::vector<int> &audioCaps)
4603 audioCaps.push_back(IPC_AUD_OFFSET);
4604 audioCaps.push_back(IPC_AUD_SELECT_STREAM);
4605 audioCaps.push_back(IPC_AUD_SELECT_OUTPUT);
4606 audioCaps.push_back(IPC_AUD_AMP);
4609 void COMXPlayer::GetSubtitleCapabilities(std::vector<int> &subCaps)
4611 subCaps.push_back(IPC_SUBS_ALL);