chxavplayerstate.cpp
上传用户:dangjiwu
上传日期:2013-07-19
资源大小:42019k
文件大小:9k
- /************************************************************************
- * chxavplayerstate.cpp
- * --------------------
- *
- * Synopsis:
- * Contains the implementation of the CHXAvPlayerState class.
- *
- * Target:
- * Symbian OS
- *
- *
- * (c) 1995-2003 RealNetworks, Inc. Patents pending. All rights reserved.
- *
- *****************************************************************************/
- /*****************************************************************************
- user command hxplayer event player state dispatch
- ------- -------------- ---------------------
- Play
- OnPlayInitiate
- {if non-local url}
- OnNetConnect
-
- OnBegin
- OnResume
- (BeginChangeLayout,
- SitesNeeded,
- DoneChangeLayout for non-smil case)
- OnPresentationOpened
- OnLoadSession
- (BeginChangeLayout,
- SitesNeeded,
- DoneChangeLayout for smil case)
- {if non-local url smil track added}
- OnNetConnect
- OnBuffering (BUFFERING_START_UP)
- (local: 100 once
- network: N - 100; N usually starts at 0)
- OnBeginBuffering (0 and 100)
- OnBuffering
- Stop
- OnStop
- OnPresentationClosed
- OnStop
- StartSeek
- (Pause)
- OnPause
- OnPause
- OnPause
- OnBeginSeek
- SetSeekPoint
- OnNewPos
- EndSeek
- (Seek)
- OnPreSeek (during call to seek)
- (Begin) * pause or stop also possible here
- OnBegin
- OnResume
- OnBuffering (BUFFERING_SEEK)
- OnBuffering
- OnPostSeek
-
- // XXXLCM we really should switch to using state objects (this class is misnamed and
- // is just a poorly-defined helper class)
- //
- **********************************************************************************/
- #include "hxstring.h"
- #include "hxcore.h"
- #include "hxsym_debug.h"
- #include "hxsym_memutil.h"
- #include "chxavplayerstatedispatch.h"
- #include "chxavplayerstate.h"
- CHXAvPlayerState::CHXAvPlayerState()
- : m_state(Stopped)
- , m_bufferState(NotBuffering)
- , m_pDispatch(0)
- , m_lastBufferPercent(100)
- , m_lastTime(-1)
- {
- }
- CHXAvPlayerState::~CHXAvPlayerState()
- {
- HX_DELETE(m_pDispatch);
- }
- void CHXAvPlayerState::ConstructL()
- {
- HX_ASSERT(m_pDispatch == NULL);
- m_pDispatch = new (ELeave) CHXAvPlayerStateDispatch();
- }
- void CHXAvPlayerState::ChangeState(State destState)
- {
- DPRINTF(SYMP_INFO, (" *** PLAYER STATE --> %s ***n", dbg::State(destState)));
- m_state = destState;
- }
- void CHXAvPlayerState::ChangeBufferState(BufferState destState)
- {
- m_bufferState = destState;
- }
- void CHXAvPlayerState::RemoveObserver(IHXSymPlayerStateObserver* observer)
- {
- HX_ASSERT(m_pDispatch != NULL);
- m_pDispatch->RemoveObserver(observer);
- }
- void CHXAvPlayerState::AddObserver(IHXSymPlayerStateObserver* observer)
- {
- HX_ASSERT(m_pDispatch != NULL);
- m_pDispatch->AddObserver(observer);
- }
- // when user play command issued or play auto-starts
- void CHXAvPlayerState::OnPlayInitiate(const char* url)
- {
- // start in Initiating state
- if(m_state != Initiating)
- {
- ChangeState(Initiating);
- m_pDispatch->OnPlayInitiate(url);
- }
- }
- void CHXAvPlayerState::OnNetConnect()
- {
- DPRINTF(SYMP_INFO, ("CHXAvNaviPaneControl::OnNetConnect()n"));
- // sometimes we can get a net connect while paused if we pause a smil pres after open but before first buffer
- if(Connecting != m_state && Paused != m_state)
- {
- ChangeState(Connecting);
- m_pDispatch->OnNetConnect();
- }
- }
- // when open presentation notification received; headers are available and sites ready only for non-smil
- void CHXAvPlayerState::OnLoadSession(IHXRequest *request)
- {
- DPRINTF(SYMP_INFO, ("OnLoadSession(): Memory: System Free = %ld; Heap Free = %ldn", MemUtil::GetSystemFree(), MemUtil::GetHeapFree()));
- m_lastTime = -1;
- m_pDispatch->OnLoadSession(request);
- }
- // when error notification received
- void CHXAvPlayerState::OnError(HX_RESULT code)
- {
- DPRINTF(SYMP_INFO, ("OnError(): System Free = %ld; Heap Free = %ldn", MemUtil::GetSystemFree(), MemUtil::GetHeapFree()));
- m_pDispatch->OnError(code);
- }
- // when user advances playlist; when playlist auto-advances
- void CHXAvPlayerState::OnAdvancePlaylist()
- {
- m_pDispatch->OnAdvancePlaylist();
- }
- // when OnBegin notification or first timer tick received
- void CHXAvPlayerState::OnResume()
- {
- DPRINTF(SYMP_INFO, ("OnResume(): System Free = %ld; Heap Free = %ldn", MemUtil::GetSystemFree(), MemUtil::GetHeapFree()));
- if(m_state != Playing)
- {
- m_lastBufferPercent = 100;
- ChangeBufferState(NotBuffering); // buffering will come next
- ChangeState(Playing);
- m_pDispatch->OnResume();
- }
- }
- // when user stop command issued, or OnStop, after presentation is closed
- void CHXAvPlayerState::OnStop()
- {
- if(m_state != Stopped)
- {
- m_lastBufferPercent = 100;
- ChangeBufferState(NotBuffering); // in case stop while buffering
- ChangeState(Stopped);
- m_pDispatch->OnStop();
- }
- }
- // when user pause command issued, when user begins seek
- void CHXAvPlayerState::OnPause()
- {
- if(m_state != Paused)
- {
- ChangeState(Paused);
- m_pDispatch->OnPause();
- }
- }
- // when buffering occurs; can occur during play, pause (live) and seek state
- void CHXAvPlayerState::OnBuffering(ULONG32 type, UINT16 percent)
- {
- // if first buffer after connect/initiate ensure we are playing state
- if( m_state == Initiating || m_state == Connecting )
- {
- OnResume();
- }
- BufferState dest;
- switch(type)
- {
- case BUFFERING_START_UP:
- dest = BufferLoad; // first buffer
- break;
- case BUFFERING_SEEK:
- dest = BufferSeek; // buffer after seek
- break;
- default:
- dest = BufferPlain; // plain ol' buffering
- break;
- }
- bool bIsNewPercentage = (m_lastBufferPercent != percent);
- m_lastBufferPercent = percent;
- if(dest != m_bufferState)
- {
- //
- // begin transition to new buffering state; this also handles seek during
- // initial buffering, i.e., BUFFERING_START_UP to BUFFERING_CONGESTION
- //
- ChangeBufferState(dest);
- DPRINTF(SYMP_INFO, ("CHXAvPlayerState::OnBuffering(): begin bufferingn"));
- m_pDispatch->OnBeginBuffering(true);
- }
- if(bIsNewPercentage)
- {
- //DPRINTF(SYMP_INFO, ("OnBuffering(): Memory: System Free = %ld; Heap Free = %ldn", MemUtil::GetSystemFree(), MemUtil::GetHeapFree()));
- // forward new buffering position
- m_pDispatch->OnBuffering(percent);
- }
- if(100 == percent)
- {
- // buffering complete; transition out of buffering state
- if(NotBuffering != m_bufferState)
- {
- ChangeBufferState(NotBuffering);
- DPRINTF(SYMP_INFO, ("CHXAvPlayerState::OnBuffering(): end bufferingn"));
- m_pDispatch->OnBeginBuffering(false);
- }
- }
-
- }
- // when user command to begin seek interaction issued
- void CHXAvPlayerState::OnBeginSeek()
- {
- if(m_state != Seeking)
- {
- ChangeState(Seeking);
- m_pDispatch->OnBeginSeek();
- }
- }
- // when user sets new position via some ui control or playback advances to new position in timeline
- void CHXAvPlayerState::OnNewPos(ULONG32 time)
- {
- if( time != m_lastTime)
- {
- m_lastTime = time;
- m_pDispatch->OnNewPos(time);
- }
- }
- // when volume command issued
- void CHXAvPlayerState::OnVolume(unsigned int percentVol)
- {
- m_pDispatch->OnVolume(percentVol);
- }
- // when mute command issued
- void CHXAvPlayerState::OnMute(bool bMute)
- {
- m_pDispatch->OnMute(bMute);
- }