コード例 #1
0
ファイル: Movie.cpp プロジェクト: nicholaskell/sfeMovie
	void Movie::pause(void)
	{
		if (m_status == Playing)
		{
			// Prevent audio from being late compared to video
			// (audio usually gets a bit later each time you pause and resume
			// the movie playback, thus fix the video timing according
			// to the audio's one)
			// NB: Calling Pause()/Play() is the only way to resynchronize
			// audio and video when audio gets late for now.
			if (hasAudioTrack())
			{
				m_progressAtPause = m_audio->getPlayingOffset();
				//std::cout << "synch according to audio track=" << m_progressAtPause << std::endl;
			}
			else
			{
				//std::cout << "synch according to progrAtPse=" << m_progressAtPause << " + elapsdTme=" << m_overallTimer.GetElapsedTime() << std::endl;
				m_progressAtPause += m_overallTimer.getElapsedTime();
			}
			
			m_status = Paused;
			IFAUDIO(m_audio->pause());
			IFVIDEO(m_video->pause());
		}
	}
コード例 #2
0
ファイル: Movie.cpp プロジェクト: nicholaskell/sfeMovie
	void Movie::starvation(void)
	{
		bool audioStarvation = true;
		bool videoStarvation = true;
		
		IFAUDIO(audioStarvation = m_audio->isStarving());
		IFVIDEO(videoStarvation = m_video->isStarving());
		
		// No mode audio or video data to read
		if (audioStarvation && videoStarvation)
		{
			*m_shouldStopCond = 1;
		}
	}
コード例 #3
0
ファイル: Movie.cpp プロジェクト: nicholaskell/sfeMovie
	void Movie::close(void)
	{
		IFVIDEO(m_video->close());
		IFAUDIO(m_audio->close());

		if (m_avFormatCtx)
			avformat_close_input(&m_avFormatCtx);
		m_hasAudio = false;
		m_hasVideo = false;
		m_eofReached = false;
		m_status = Stopped;
		m_duration = sf::Time::Zero;
		m_progressAtPause = sf::Time::Zero;
	}
コード例 #4
0
ファイル: Movie.cpp プロジェクト: nicholaskell/sfeMovie
	void Movie::internalStop(bool calledFromWatchThread)
	{
		// prevent Stop() from being executed while already stopping from another thread
		sf::Lock l(m_stopMutex);
		
		if (m_status != Stopped)
		{
			m_status = Stopped;
			IFAUDIO(m_audio->stop());
			IFVIDEO(m_video->stop());
			
			m_progressAtPause = sf::Time::Zero;
			setEofReached(false);
			m_shouldStopCond->invalidate();
			
			if (!calledFromWatchThread)
				m_watchThread.wait();
		}
	}
コード例 #5
0
ファイル: Movie.cpp プロジェクト: nicholaskell/sfeMovie
	void Movie::play(void)
	{
		if (m_status != Playing)
		{
			m_overallTimer.restart();
			IFAUDIO(m_audio->play());
			IFVIDEO(m_video->play());
			
			// Don't restart watch thread if we're resuming
			if (m_status != Paused)
			{
				*m_shouldStopCond = 0;
				m_shouldStopCond->restore();
				m_watchThread.launch();
			}
			
			m_status = Playing;
		}
	}
コード例 #6
0
ファイル: Movie.cpp プロジェクト: Dahlqvist/sfeMovie
	void Movie::play(void)
	{
		if (m_status != Playing)
		{
			if (m_hasAudio)
			{
				sf::Time startOffset = m_audio->getPlayingOffset();
				sf::Clock timer;
				m_audio->play();
				
				timer.restart();
				while (startOffset == m_audio->getPlayingOffset() && timer.getElapsedTime() < sf::seconds(5))
					sf::sleep(sf::milliseconds(1));
				
				// Note: this is a workaround for SFML issue #201
				// Audio initialization may silently fail and audio won't start playing
				if (timer.getElapsedTime() >= sf::seconds(5))
					std::cerr << "*** warning: Movie::play() - no audio progress for 5 sec, giving up on syncing" << std::endl;
				
				m_progressAtPause = m_audio->getPlayingOffset();
			}
			
			m_overallTimer.restart();
			IFVIDEO(m_video->play());
			
			if (usesDebugMessages())
				printWithTime("did start movie timer");
			
			// Don't restart watch thread if we're resuming
			if (m_status != Paused)
			{
				*m_shouldStopCond = 0;
				m_shouldStopCond->restore();
				m_watchThread.launch();
			}
			
			m_status = Playing;
		}
	}